29 {
30
31 std::cout << "Starting neutrino filter" << std::endl;
32
33 if (argc != 4) {
34 std::cout << "Two arguments required: input file name (or reg exp), output file name, cut set (0: stage 1 selection, 1: no veto or scifi 1st layer, 2: FV sideband, 3: include walls 2 and 5, 4: nue filter (no DS selection, allow walls 1 to 4." << std::endl;
35 exit(-1);
36 }
37
38
40 TChain *
ch =
new TChain(
"rawConv");
42 if (
ch->GetEntries() == 0){
44 ch =
new TChain(
"cbmsim");
46 if (
ch->GetEntries() > 0) {
48 ch->SetBranchStatus(
"EventHeader", 0);
49 ch->SetBranchStatus(
"EventHeader.", 0);
50 } else {
51 std::cout << "Didn't find rawConv or cbmsim in input file" << std::endl;
52 exit(-1);
53 }
54 }
55 std::cout << "Got input tree" << std::endl;
56
57
58 TClonesArray *
MCTracks =
new TClonesArray(
"ShipMCTrack", 5000);
59 if (isMC)
ch->SetBranchAddress(
"MCTrack", &MCTracks);
60
61
62 TFile *
outFile =
new TFile(argv[2],
"RECREATE");
63 std::cout << "Got output file" << std::endl;
64
66 ch->GetFile()->Get(
"BranchList")->Write(
"BranchList", TObject::kSingleKey);
67 ch->GetFile()->Get(
"TimeBasedBranchList")->Write(
"TimeBasedBranchList", TObject::kSingleKey);
68 if (
ch->GetFile()->Get(
"FileHeader"))
ch->GetFile()->Get(
"FileHeader")->Write();
69 if (
ch->GetFile()->Get(
"FileHeaderHeader"))
ch->GetFile()->Get(
"FileHeaderHeader")->Write();
70
71
72 TTree * outTree =
ch->CloneTree(0);
73 std::cout << "Got output tree" << std::endl;
74
75
76 std::cout << "Starting cut set up" << std::endl;
77
78 std::vector< snd::analysis_cuts::baseCut * > cutFlow;
79
80 int selected_cutset = std::atoi(argv[3]);
81
92
103
111
121
129
130 }
else if (selected_cutset ==
nueFilter) {
136 } else {
137 std::cout << "Unrecognized cutset. Exitting" << std::endl;
138 exit(-1);
139 }
140 std::cout << "Done initializing cuts" << std::endl;
141
142 int n_cuts = (
int) cutFlow.size();
143
144
145
146
148 for (int i_cut = -1; i_cut < n_cuts; i_cut++){
151 for(int i_dim = 0; i_dim < cut->getNbins().size(); i_dim++){
152 this_cut_by_cut_var_histos.push_back(
new TH1D((std::to_string(i_cut)+
"_"+cut->getShortName()+
"_"+std::to_string(i_dim)).c_str(),
153 cut->getShortName().c_str(),
154 cut->getNbins()[i_dim], cut->getRangeStart()[i_dim], cut->getRangeEnd()[i_dim]));
155 }
156 }
158 }
159
160 std::vector<std::vector<std::vector<TH1D*> > >
cut_by_cut_truth_histos = std::vector<std::vector<std::vector<TH1D*> > >();
161 if (isMC) {
162 for (int i_species = 0; i_species < 5; i_species++){
164 std::string species_suffix;
165 switch (i_species) {
166 case 0:
167 species_suffix = "nueCC";
168 break;
169 case 1:
170 species_suffix = "numuCC";
171 break;
172 case 2:
173 species_suffix = "nutauCC";
174 break;
175 case 3:
176 species_suffix = "NC";
177 break;
178 case 4:
179 species_suffix = "Other";
180 break;
182 std::cerr << "MC truth histograms initialization error! Unknown species" << std::endl;
183 exit(-1);
184 }
185
186 for (int i_cut = -1; i_cut < n_cuts; i_cut++){
187
195
197 }
199 }
200 }
201
204 for(int i_dim = 0; i_dim < cut->getNbins().size(); i_dim++){
205 n_minus_1_var_histos.push_back(
new TH1D((
"n_minus_1_"+cut->getShortName()+
"_"+std::to_string(i_dim)).c_str(),
206 cut->getShortName().c_str(),
207 cut->getNbins()[i_dim], cut->getRangeStart()[i_dim], cut->getRangeEnd()[i_dim]));
208 }
209 }
210
211 std::cout << "Done initializing histograms" << std::endl;
212
213
214 TH1D * cutFlowHistogram = new TH1D("cutFlow", "Cut flow;;Number of events passing cut", n_cuts+1, 0, n_cuts+1);
215 for (
int i = 2;
i <= cutFlowHistogram->GetNbinsX();
i++){
216 cutFlowHistogram->GetXaxis()->SetBinLabel(i, cutFlow.at(i-2)->getName().c_str());
217 }
218
219 std::cout << "Done initializing cut flow histogram" << std::endl;
220
221
222 unsigned long int n_entries =
ch->GetEntries();
223
224
225 std::vector<bool>
passes_cut = std::vector<bool>(n_cuts,
false);
226
227 std::cout << "Starting event loop" << std::endl;
228 for (unsigned long int i_entry = 0; i_entry < n_entries; i_entry++){
229 ch->GetEntry(i_entry);
230 if (i_entry%10000 == 0) std::cout << "Reading entry " << i_entry << std::endl;
231
232 cutFlowHistogram->Fill(0);
233
234
237 int i_cut = 0;
239 if (cut->passCut()){
240 if (accept_event) cutFlowHistogram->Fill(1 + i_cut);
243 } else {
246 }
247 i_cut++;
248 }
249 if (accept_event) outTree->Fill();
250
251
252
253 std::vector<TH1D*>::iterator hist_it;
254
255 for (
int seq_cut = -1; seq_cut < ((
int)
passes_cut.size()); seq_cut++){
256 if (seq_cut >= 0){
257 if (not passes_cut[seq_cut]) break;
258 }
261 for (int i_dim = 0; i_dim < cut->getPlotVar().size(); i_dim++){
262 (*hist_it)->Fill(cut->getPlotVar()[i_dim]);
263 hist_it++;
264 }
265 }
266 if (isMC) {
267
271 } else {
272
275
276 if (pdgIn == (pdgOut+1)){
277
281 } else if (pdgIn == pdgOut) {
282
284 } else {
285
287 }
288 }
290 if (this_species < 4) {
293 }
297 }
298 }
299
300
301 int current_cut = 0;
304 for (int i_dim = 0; i_dim < cut->getPlotVar().size(); i_dim++){
305 if (((not passes_cut[current_cut]) and (n_cuts_passed == (cutFlow.size()-1)))
306 or (n_cuts_passed == cutFlow.size()) ) (*hist_it)->Fill(cut->getPlotVar()[i_dim]);
307 hist_it++;
308 }
309 current_cut++;
310 }
311 }
312
314
315 return 0;
316}
list this_cut_by_cut_truth_histos
list cut_by_cut_var_histos
list this_cut_by_cut_var_histos
list n_minus_1_var_histos
list cut_by_cut_truth_histos