~maus-release/maus/release

« back to all changes in this revision

Viewing changes to src/map/MapCppReconCuts/MapCppReconCuts.cc

  • Committer: Paolo Franchini
  • Date: 2018-06-24 14:27:26 UTC
  • mfrom: (659.2.80 release-candidate)
  • Revision ID: p.franchini@warwick.ac.uk-20180624142726-nbxxyjyer146dr1t
Tags: MAUS-v3.2.0
MAUS-v3.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
2
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 */
 
17
 
 
18
#include <string>
 
19
#include <vector>
 
20
#include <cfloat>
 
21
 
 
22
#include <sstream>
 
23
 
 
24
#include "Utils/Squeak.hh"
 
25
 
 
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"
 
36
 
 
37
namespace MAUS {
 
38
 
 
39
    std::string class_docstring =
 
40
    std::string("MapCppReconCuts is the mapper for the MAUS Cuts class.\n");
 
41
 
 
42
    std::string birth_docstring =
 
43
    std::string("Checks if the right configuration is passed to the processor.\n");
 
44
 
 
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");
 
48
 
 
49
    std::string death_docstring =
 
50
    std::string("Does nothing.\n");
 
51
 
 
52
    PyMODINIT_FUNC init_MapCppReconCuts(void) {
 
53
        PyWrapMapBase<MapCppReconCuts>::PyWrapMapBaseModInit
 
54
        ("MapCppReconCuts", class_docstring, birth_docstring, process_docstring, death_docstring);
 
55
    }
 
56
 
 
57
    MapCppReconCuts::MapCppReconCuts()
 
58
    : MapBase<Data>("MapCppReconCuts") {
 
59
                _cuts_list = new ReconCutBasePArray();
 
60
    }
 
61
 
 
62
    MapCppReconCuts::~MapCppReconCuts() {
 
63
                if (_cuts_list != NULL) {
 
64
                        for (size_t i = 0; i < _cuts_list->size(); ++i) {
 
65
                                delete (*_cuts_list)[i];
 
66
                        }
 
67
                        delete _cuts_list;
 
68
                }
 
69
    }
 
70
 
 
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
 
74
// JsonCpp setup
 
75
    _configJSON = JsonWrapper::StringToJson(argJsonConfigDocument);
 
76
 
 
77
    _set_Cut_params =
 
78
        JsonWrapper::GetProperty(_configJSON, "recon_cuts", JsonWrapper::objectValue);
 
79
 
 
80
        // Squeak::mout(Squeak::debug) << "in MapCppReconCuts::_birth" << std::endl;
 
81
        // Squeak::mout(Squeak::warning) << "in MapCppReconCuts::_birth" << std::endl;
 
82
 
 
83
    // Initialise cuts from cuts_parameters
 
84
    Json::Value tof_config;
 
85
 
 
86
        // TOF cuts
 
87
    try {
 
88
        tof_config = JsonWrapper::GetProperty(_set_Cut_params,
 
89
                "TOF_cuts", JsonWrapper::objectValue);
 
90
    }
 
91
    catch (const MAUS::Exceptions::Exception& e) {
 
92
                Squeak::mout(Squeak::warning)
 
93
                << "MapCppReconCuts::_birth Error finding TOF_cuts" << std::endl;
 
94
    }
 
95
        ReconTOFCuts* tof_cuts = new ReconTOFCuts(tof_config);
 
96
        _cuts_list->push_back(tof_cuts);
 
97
 
 
98
 
 
99
        // Tracker cuts
 
100
    Json::Value tracker_config;
 
101
    try {
 
102
        tracker_config = JsonWrapper::GetProperty(_set_Cut_params,
 
103
                        "Tracker_cuts", JsonWrapper::objectValue);
 
104
    }
 
105
    catch (const MAUS::Exceptions::Exception& e) {
 
106
                Squeak::mout(Squeak::warning)
 
107
                << "MapCppReconCuts::_birth Error finding Tracker_cuts" << std::endl;
 
108
    }
 
109
        ReconTrackerCuts* tracker_cuts = new ReconTrackerCuts(tracker_config);
 
110
        _cuts_list->push_back(tracker_cuts);
 
111
 
 
112
        // Misc cuts
 
113
    Json::Value misc_config;
 
114
    try {
 
115
        misc_config = JsonWrapper::GetProperty(_set_Cut_params,
 
116
                "Misc_cuts", JsonWrapper::objectValue);
 
117
    }
 
118
    catch (const MAUS::Exceptions::Exception& e) {
 
119
                Squeak::mout(Squeak::warning)
 
120
                << "MapCppReconCuts::_birth Error finding Misc_cuts" << std::endl;
 
121
    }
 
122
        ReconMiscCuts* misc_cuts = new ReconMiscCuts(misc_config);
 
123
        _cuts_list->push_back(misc_cuts);
 
124
}
 
125
 
 
126
void MapCppReconCuts::_process(MAUS::Data *data) const {
 
127
 
 
128
        // Squeak::mout(Squeak::warning) << "in MapCppReconCuts::_process" << std::endl;
 
129
 
 
130
        if (!data) {
 
131
        throw MAUS::Exceptions::Exception(Exceptions::recoverable,
 
132
                "data was NULL", "MapCppReconCuts::_process");
 
133
    }
 
134
 
 
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"))
 
138
        return;
 
139
 
 
140
        // Squeak::mout(Squeak::warning) << "get recon events" << std::endl;
 
141
    ReconEventPArray *events = spill->GetReconEvents();
 
142
 
 
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;
 
146
 
 
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());
 
150
                }
 
151
 
 
152
                for (size_t i = 0; i < _cuts_list->size(); ++i) {
 
153
                        // Squeak::mout(Squeak::warning) << "in cuts loop " << i << std::endl;
 
154
 
 
155
                        (*_cuts_list)[i]->DoCuts(events->at(j));
 
156
                }
 
157
/*              
 
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();
 
161
 
 
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;
 
164
                }
 
165
                
 
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;
 
168
                }
 
169
                
 
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;
 
172
                }
 
173
                
 
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;
 
176
                }
 
177
                
 
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;
 
181
                }
 
182
                
 
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;
 
185
                }
 
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;
 
188
                }
 
189
 
 
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;
 
193
                }
 
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;
 
197
                }
 
198
 
 
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;
 
201
                }
 
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;
 
205
                }
 
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;
 
208
                }
 
209
 
 
210
*/
 
211
    } // fetching events
 
212
} // process
 
213
 
 
214
void MapCppReconCuts::_death() {
 
215
        }
 
216
} // namespace MAUS