1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
24
#include "Utils/Squeak.hh"
26
#include "src/common_cpp/Utils/JsonWrapper.hh"
27
#include "src/common_cpp/Utils/CppErrorHandler.hh"
28
#include "src/common_cpp/Utils/Exception.hh"
29
#include "src/legacy/Interface/dataCards.hh"
30
#include "src/common_cpp/API/PyWrapMapBase.hh"
31
#include "src/map/MapCppReconCuts/MapCppReconCuts.hh"
32
#include "src/map/MapCppReconCuts/ReconCutBase.hh"
33
#include "src/map/MapCppReconCuts/ReconTOFCuts.hh"
34
#include "src/map/MapCppReconCuts/ReconTrackerCuts.hh"
35
#include "src/map/MapCppReconCuts/ReconMiscCuts.hh"
39
std::string class_docstring =
40
std::string("MapCppReconCuts is the mapper for the MAUS Cuts class.\n");
42
std::string birth_docstring =
43
std::string("Checks if the right configuration is passed to the processor.\n");
45
std::string process_docstring =
46
std::string("Set up event(s) with some cut_event data and\n")+
47
std::string("check if mapper sets the correct cut values.\n");
49
std::string death_docstring =
50
std::string("Does nothing.\n");
52
PyMODINIT_FUNC init_MapCppReconCuts(void) {
53
PyWrapMapBase<MapCppReconCuts>::PyWrapMapBaseModInit
54
("MapCppReconCuts", class_docstring, birth_docstring, process_docstring, death_docstring);
57
MapCppReconCuts::MapCppReconCuts()
58
: MapBase<Data>("MapCppReconCuts") {
59
_cuts_list = new ReconCutBasePArray();
62
MapCppReconCuts::~MapCppReconCuts() {
63
if (_cuts_list != NULL) {
64
for (size_t i = 0; i < _cuts_list->size(); ++i) {
65
delete (*_cuts_list)[i];
71
void MapCppReconCuts::_birth(const std::string& argJsonConfigDocument) {
72
// Called at the beginning of each run.
73
// Check if the JSON document can be parsed, else return error
75
_configJSON = JsonWrapper::StringToJson(argJsonConfigDocument);
78
JsonWrapper::GetProperty(_configJSON, "recon_cuts", JsonWrapper::objectValue);
80
// Squeak::mout(Squeak::debug) << "in MapCppReconCuts::_birth" << std::endl;
81
// Squeak::mout(Squeak::warning) << "in MapCppReconCuts::_birth" << std::endl;
83
// Initialise cuts from cuts_parameters
84
Json::Value tof_config;
88
tof_config = JsonWrapper::GetProperty(_set_Cut_params,
89
"TOF_cuts", JsonWrapper::objectValue);
91
catch (const MAUS::Exceptions::Exception& e) {
92
Squeak::mout(Squeak::warning)
93
<< "MapCppReconCuts::_birth Error finding TOF_cuts" << std::endl;
95
ReconTOFCuts* tof_cuts = new ReconTOFCuts(tof_config);
96
_cuts_list->push_back(tof_cuts);
100
Json::Value tracker_config;
102
tracker_config = JsonWrapper::GetProperty(_set_Cut_params,
103
"Tracker_cuts", JsonWrapper::objectValue);
105
catch (const MAUS::Exceptions::Exception& e) {
106
Squeak::mout(Squeak::warning)
107
<< "MapCppReconCuts::_birth Error finding Tracker_cuts" << std::endl;
109
ReconTrackerCuts* tracker_cuts = new ReconTrackerCuts(tracker_config);
110
_cuts_list->push_back(tracker_cuts);
113
Json::Value misc_config;
115
misc_config = JsonWrapper::GetProperty(_set_Cut_params,
116
"Misc_cuts", JsonWrapper::objectValue);
118
catch (const MAUS::Exceptions::Exception& e) {
119
Squeak::mout(Squeak::warning)
120
<< "MapCppReconCuts::_birth Error finding Misc_cuts" << std::endl;
122
ReconMiscCuts* misc_cuts = new ReconMiscCuts(misc_config);
123
_cuts_list->push_back(misc_cuts);
126
void MapCppReconCuts::_process(MAUS::Data *data) const {
128
// Squeak::mout(Squeak::warning) << "in MapCppReconCuts::_process" << std::endl;
131
throw MAUS::Exceptions::Exception(Exceptions::recoverable,
132
"data was NULL", "MapCppReconCuts::_process");
135
// Get spill, return if there's no DAQ data or not a physics event
136
Spill *spill = data->GetSpill();
137
if (spill->GetDAQData() == NULL || (spill->GetDaqEventType() != "physics_event"))
140
// Squeak::mout(Squeak::warning) << "get recon events" << std::endl;
141
ReconEventPArray *events = spill->GetReconEvents();
143
// Squeak::mout(Squeak::warning) << "events->size() " << events->size() << std::endl;
144
for (size_t j = 0; j < events->size(); ++j) {
145
// Squeak::mout(Squeak::warning) << "in event loop " << j << std::endl;
147
// If Cuts list does not exist create a new one
148
if (events->at(j)->GetCutsList() == NULL) {
149
events->at(j)->SetCutsList(new ReconCutDataBasePArray());
152
for (size_t i = 0; i < _cuts_list->size(); ++i) {
153
// Squeak::mout(Squeak::warning) << "in cuts loop " << i << std::endl;
155
(*_cuts_list)[i]->DoCuts(events->at(j));
158
// Compare Cuts and ReconCuts
159
std::vector<bool> all_cut_values = events->at(j)->GetCutEvent()->GetCutStore();
160
MAUS::ReconCutBasePArray* cutsList=events->at(j)->GetCutsList();
162
if (cutsList->at(0)->GetCutPass()!= all_cut_values[0]){
163
Squeak::mout(Squeak::warning) << "TOF0 cut does not match for recon event " << j << std::endl;
166
if (cutsList->at(1)->GetCutPass()!= all_cut_values[1]){
167
Squeak::mout(Squeak::warning) << "TOF1 cut does not match for recon event " << j << std::endl;
170
if (cutsList->at(2)->GetCutPass()!= all_cut_values[2]){
171
Squeak::mout(Squeak::warning) << "TOFDT cut does not match for recon event " << j << std::endl;
174
if (cutsList->at(3)->GetCutPass()!= all_cut_values[3]){
175
Squeak::mout(Squeak::warning) << "Single track cut does not match for recon event " << j << std::endl;
178
if (cutsList->at(4)->GetCutPass()!= all_cut_values[7]){
179
Squeak::mout(Squeak::warning) << "Track p-value cut does not match for recon event " << j << std::endl;
180
Squeak::mout(Squeak::warning) << cutsList->at(4)->GetCutPass() << " " << all_cut_values[7] << " " << cutsList->at(4)->GetCutValue() << std::endl;
183
if (cutsList->at(5)->GetCutPass()!= all_cut_values[4]){
184
Squeak::mout(Squeak::warning) << "TKU hits cut does not match for recon event " << j << std::endl;
186
if (cutsList->at(6)->GetCutPass()!= all_cut_values[10]){
187
Squeak::mout(Squeak::warning) << "TKD hits cut does not match for recon event " << j << std::endl;
190
if (cutsList->at(7)->GetCutPass()!= all_cut_values[5]){
191
Squeak::mout(Squeak::warning) << "TKU mom cut " << cutsList->at(7)->GetCutDescription() << " does not match for recon event " << j << std::endl;
192
Squeak::mout(Squeak::warning) << cutsList->at(7)->GetCutPass() << " " << all_cut_values[5] << " " << cutsList->at(7)->GetCutValue() << std::endl;
194
if (cutsList->at(8)->GetCutPass()!= all_cut_values[11]){
195
Squeak::mout(Squeak::warning) << "TKD mom cut " << cutsList->at(8)->GetCutDescription() << " does not match for recon event " << j << std::endl;
196
Squeak::mout(Squeak::warning) << cutsList->at(8)->GetCutPass() << " " << all_cut_values[11] << " " << cutsList->at(8)->GetCutValue() << std::endl;
199
if (cutsList->at(9)->GetCutPass()!= all_cut_values[6]){
200
Squeak::mout(Squeak::warning) << "Mom loss cut does not match for recon event " << j << std::endl;
202
if (cutsList->at(10)->GetCutPass()!= all_cut_values[8]){
203
Squeak::mout(Squeak::warning) << "Mass cut does not match for recon event " << j << std::endl;
204
Squeak::mout(Squeak::warning) << cutsList->at(10)->GetCutPass() << " " << all_cut_values[8] << " " << cutsList->at(10)->GetCutValue() << std::endl;
206
if (cutsList->at(11)->GetCutPass()!= all_cut_values[9]){
207
Squeak::mout(Squeak::warning) << "Good particle cut does not match for recon event " << j << std::endl;
214
void MapCppReconCuts::_death() {