16 double minval,
double maxval,
bool doNegativeReco,
int doSyst,
20 TFile *
file =
new TFile(filename.c_str(),
"READ");
21 TTree *defaultTree = (TTree*)file->Get(treename.c_str());
24 int reco_beam_nTrackDaughters, reco_beam_nShowerDaughters;
25 double reco_beam_len, reco_beam_vtxX, reco_beam_vtxY, reco_beam_vtxZ,
26 reco_beam_startX, reco_beam_startY, reco_beam_startZ, reco_beam_trackDirZ,
27 reco_beam_interactingEnergy, reco_beam_Chi2_proton;
31 bool reco_beam_true_byHits_matched;
34 int reco_beam_true_byHits_origin, reco_beam_true_byHits_PDG;
36 double true_beam_endZ;
37 double true_beam_interactingEnergy;
40 std::vector<double> *reco_beam_incidentEnergies = 0;
42 int true_chexSignal, true_absSignal, true_backGround, true_nPi0Signal;
45 int interaction_topology;
46 defaultTree->SetBranchAddress(
"interaction_topology", &interaction_topology);
48 defaultTree->SetBranchAddress(
"reco_beam_type", &reco_beam_type);
49 defaultTree->SetBranchAddress(
"reco_beam_len", &reco_beam_len);
50 defaultTree->SetBranchAddress(
"reco_beam_vtxX", &reco_beam_vtxX);
51 defaultTree->SetBranchAddress(
"reco_beam_vtxY", &reco_beam_vtxY);
52 defaultTree->SetBranchAddress(
"reco_beam_vtxZ", &reco_beam_vtxZ);
53 defaultTree->SetBranchAddress(
"reco_beam_startX", &reco_beam_startX);
54 defaultTree->SetBranchAddress(
"reco_beam_startY", &reco_beam_startY);
55 defaultTree->SetBranchAddress(
"reco_beam_startZ", &reco_beam_startZ);
56 defaultTree->SetBranchAddress(
"reco_beam_trackDirZ", &reco_beam_trackDirZ);
57 defaultTree->SetBranchAddress(
"reco_beam_nTrackDaughters", &reco_beam_nTrackDaughters);
58 defaultTree->SetBranchAddress(
"reco_beam_nShowerDaughters", &reco_beam_nShowerDaughters);
59 defaultTree->SetBranchAddress(
"reco_beam_interactingEnergy", &reco_beam_interactingEnergy);
60 defaultTree->SetBranchAddress(
"reco_beam_Chi2_proton", &reco_beam_Chi2_proton);
61 defaultTree->SetBranchAddress(
"reco_beam_incidentEnergies", &reco_beam_incidentEnergies);
63 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_matched", &reco_beam_true_byHits_matched);
64 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_origin", &reco_beam_true_byHits_origin);
65 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_PDG", &reco_beam_true_byHits_PDG);
66 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_endProcess", &reco_beam_true_byHits_endProcess);
68 defaultTree->SetBranchAddress(
"true_beam_interactingEnergy", &true_beam_interactingEnergy);
69 defaultTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG);
70 defaultTree->SetBranchAddress(
"true_beam_endZ", &true_beam_endZ);
71 defaultTree->SetBranchAddress(
"true_beam_endProcess", &true_beam_endProcess);
73 defaultTree->SetBranchAddress(
"true_chexSignal", &true_chexSignal);
74 defaultTree->SetBranchAddress(
"true_nPi0Signal", &true_nPi0Signal);
75 defaultTree->SetBranchAddress(
"true_absSignal", &true_absSignal);
76 defaultTree->SetBranchAddress(
"true_backGround", &true_backGround);
79 std::vector<double> * reco_beam_calibrated_dEdX = 0x0;
80 defaultTree->SetBranchAddress(
"reco_beam_calibrated_dEdX", &reco_beam_calibrated_dEdX);
81 std::vector<double> * reco_beam_TrkPitch = 0x0;
82 defaultTree->SetBranchAddress(
"reco_beam_TrkPitch", &reco_beam_TrkPitch);
84 double reco_beam_endX, reco_beam_endY, reco_beam_endZ;
85 defaultTree->SetBranchAddress(
"reco_beam_endX", &reco_beam_endX);
86 defaultTree->SetBranchAddress(
"reco_beam_endY", &reco_beam_endY);
87 defaultTree->SetBranchAddress(
"reco_beam_endZ", &reco_beam_endZ);
90 defaultTree->SetBranchAddress(
"event", &event);
91 defaultTree->SetBranchAddress(
"run", &run);
94 std::vector<int> * reco_beam_hit_true_origin = 0x0;
95 std::vector<int> * reco_beam_hit_true_ID = 0x0;
96 std::vector<int> * true_beam_daughter_ID = 0x0;
97 std::vector<int> * true_beam_grand_daughter_ID = 0x0;
99 int true_daughter_nPiPlus, true_daughter_nPiMinus, true_daughter_nPi0;
100 defaultTree->SetBranchAddress(
"reco_beam_hit_true_origin", &reco_beam_hit_true_origin );
101 defaultTree->SetBranchAddress(
"reco_beam_hit_true_ID", &reco_beam_hit_true_ID );
102 defaultTree->SetBranchAddress(
"true_beam_ID", &true_beam_ID );
103 defaultTree->SetBranchAddress(
"true_daughter_nPiPlus", &true_daughter_nPiPlus );
104 defaultTree->SetBranchAddress(
"true_daughter_nPiMinus", &true_daughter_nPiMinus );
105 defaultTree->SetBranchAddress(
"true_daughter_nPi0", &true_daughter_nPi0 );
106 defaultTree->SetBranchAddress(
"true_beam_daughter_ID", &true_beam_daughter_ID );
107 defaultTree->SetBranchAddress(
"true_beam_grand_daughter_ID", &true_beam_grand_daughter_ID );
110 std::vector< std::string > * true_beam_processes = 0x0;
111 defaultTree->SetBranchAddress(
"true_beam_processes", &true_beam_processes );
118 std::vector<double> * g4rw_primary_plus_sigma_weight = 0x0;
119 std::vector<double> * g4rw_primary_minus_sigma_weight = 0x0;
120 std::vector<std::string> * g4rw_primary_var = 0x0;
122 defaultTree->SetBranchAddress(
"g4rw_primary_plus_sigma_weight", &g4rw_primary_plus_sigma_weight);
123 defaultTree->SetBranchAddress(
"g4rw_primary_minus_sigma_weight", &g4rw_primary_minus_sigma_weight);
124 defaultTree->SetBranchAddress(
"g4rw_primary_var", &g4rw_primary_var);
127 channel.erase(
std::remove(channel.begin(), channel.end(),
'.'), channel.end());
128 channel.erase(
std::remove(channel.begin(), channel.end(),
' '), channel.end());
129 topo.erase(
std::remove(topo.begin(), topo.end(),
'.'), topo.end());
130 topo.erase(
std::remove(topo.begin(), topo.end(),
' '), topo.end());
132 const int nrecobins = recoBins.size();
133 std::string hist_name =
"MC_Channel" + channel +
"_" + topo +
"_Histo";
134 std::string hist_title =
"MC Background for channel " + channel +
135 " and topology " + topo;
138 hist_name +=
"_high_" + systName;
139 hist_title +=
" +1 sigma";
141 else if (doSyst == -1) {
142 hist_name +=
"_low_" + systName;
143 hist_title +=
" -1 sigma";
146 TH1D* mchisto =
new TH1D(hist_name.c_str(), hist_title.c_str(),
147 (doNegativeReco ? nrecobins : (nrecobins-1)),
148 (doNegativeReco ? -1 : 0), nrecobins-1);
150 mchisto->SetDirectory(0);
153 "Filling MC background histogram " << mchisto->GetName() <<
154 " from file " << filename.c_str() <<
" for channel " <<
155 channel.c_str() <<
" with topology " << topo.c_str();
157 bool done_check =
false;
158 for(Int_t
k=0;
k < defaultTree->GetEntries();
k++){
160 defaultTree->GetEntry(
k);
162 if (!done_check && doSyst != 0) {
163 if (g4rw_primary_var->size() > 0) {
165 auto syst_check = std::find(g4rw_primary_var->begin(),
166 g4rw_primary_var->end(), systName);
167 if (syst_check == g4rw_primary_var->end()) {
168 std::cout <<
"Error! Could not find syst named " << systName <<
std::endl;
176 double syst_weight = 1.;
177 std::map<std::string, double> weights;
179 for (
size_t i = 0; i < g4rw_primary_var->size(); ++i) {
180 weights[(*g4rw_primary_var)[i]] = (*g4rw_primary_plus_sigma_weight)[i];
183 else if (doSyst == -1) {
184 for (
size_t i = 0; i < g4rw_primary_var->size(); ++i) {
185 weights[(*g4rw_primary_var)[i]] = (*g4rw_primary_minus_sigma_weight)[i];
194 if (true_backGround == 0 && (true_chexSignal == 1 || true_absSignal == 1 ||
195 true_nPi0Signal == 1)){
196 if (true_beam_interactingEnergy < minval &&
197 reco_beam_interactingEnergy > recoBins[0]){
201 if (true_beam_interactingEnergy > maxval &&
202 reco_beam_interactingEnergy < recoBins[nrecobins-1]){
209 if (!reco_beam_hit_true_ID->size()) {
214 if (true_beam_PDG == 211) {
215 if (!reco_beam_hit_true_ID->size()) {
218 if (doSyst == 1 || doSyst == -1) {
219 syst_weight = weights[systName];
298 if (interaction_topology == -1)
299 std::cout <<
"Warning: Interaction topo -1" <<
std::endl;
301 if (interaction_topology != toponum)
304 double total_weight = weight*syst_weight;
305 if (true_beam_PDG == 211) {
306 total_weight *= PiMuScale.first;
308 else if (true_beam_PDG == -13) {
309 total_weight *= PiMuScale.second;
312 if (doNegativeReco) {
313 if (reco_beam_interactingEnergy < 0.) {
314 mchisto->AddBinContent(1, total_weight);
317 for (
int l = 1;
l < nrecobins; ++
l) {
318 if (reco_beam_interactingEnergy > recoBins[
l-1] &&
319 reco_beam_interactingEnergy <= recoBins[
l]) {
321 mchisto->AddBinContent(l+1, total_weight);
329 if (reco_beam_interactingEnergy < 0.0)
continue;
331 for (
int l = 1;
l < nrecobins; ++
l) {
332 if (reco_beam_interactingEnergy > recoBins[
l-1] &&
333 reco_beam_interactingEnergy <= recoBins[
l]) {
334 mchisto->AddBinContent(l, total_weight);
351 double maxval,
double endZ_cut,
bool doNegativeReco,
int doSyst,
355 TFile *
file =
new TFile(filename.c_str(),
"READ");
356 TTree *defaultTree = (TTree*)file->Get(treename.c_str());
359 int reco_beam_nTrackDaughters, reco_beam_nShowerDaughters;
360 double reco_beam_len, reco_beam_vtxX, reco_beam_vtxY, reco_beam_vtxZ, reco_beam_startX, reco_beam_startY, reco_beam_startZ, reco_beam_trackDirZ, reco_beam_interactingEnergy, reco_beam_Chi2_proton;
361 bool reco_beam_true_byHits_matched;
362 int reco_beam_true_byHits_origin, reco_beam_true_byHits_PDG;
364 double true_beam_endZ;
365 double true_beam_interactingEnergy;
368 std::vector<double> *reco_beam_incidentEnergies = 0;
369 int true_chexSignal, true_absSignal, true_backGround, true_nPi0Signal;
373 defaultTree->SetBranchAddress(
"reco_beam_type", &reco_beam_type);
374 defaultTree->SetBranchAddress(
"reco_beam_len", &reco_beam_len);
375 defaultTree->SetBranchAddress(
"reco_beam_vtxX", &reco_beam_vtxX);
376 defaultTree->SetBranchAddress(
"reco_beam_vtxY", &reco_beam_vtxY);
377 defaultTree->SetBranchAddress(
"reco_beam_vtxZ", &reco_beam_vtxZ);
378 defaultTree->SetBranchAddress(
"reco_beam_startX", &reco_beam_startX);
379 defaultTree->SetBranchAddress(
"reco_beam_startY", &reco_beam_startY);
380 defaultTree->SetBranchAddress(
"reco_beam_startZ", &reco_beam_startZ);
381 defaultTree->SetBranchAddress(
"reco_beam_trackDirZ", &reco_beam_trackDirZ);
382 defaultTree->SetBranchAddress(
"reco_beam_nTrackDaughters", &reco_beam_nTrackDaughters);
383 defaultTree->SetBranchAddress(
"reco_beam_nShowerDaughters", &reco_beam_nShowerDaughters);
384 defaultTree->SetBranchAddress(
"reco_beam_interactingEnergy", &reco_beam_interactingEnergy);
385 defaultTree->SetBranchAddress(
"reco_beam_Chi2_proton", &reco_beam_Chi2_proton);
386 defaultTree->SetBranchAddress(
"reco_beam_incidentEnergies", &reco_beam_incidentEnergies);
388 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_matched", &reco_beam_true_byHits_matched);
389 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_origin", &reco_beam_true_byHits_origin);
390 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_PDG", &reco_beam_true_byHits_PDG);
391 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_endProcess", &reco_beam_true_byHits_endProcess);
393 defaultTree->SetBranchAddress(
"true_beam_interactingEnergy", &true_beam_interactingEnergy);
394 defaultTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG);
395 defaultTree->SetBranchAddress(
"true_beam_endZ", &true_beam_endZ);
396 defaultTree->SetBranchAddress(
"true_beam_endProcess", &true_beam_endProcess);
398 defaultTree->SetBranchAddress(
"true_chexSignal", &true_chexSignal);
399 defaultTree->SetBranchAddress(
"true_nPi0Signal", &true_nPi0Signal);
400 defaultTree->SetBranchAddress(
"true_absSignal", &true_absSignal);
401 defaultTree->SetBranchAddress(
"true_backGround", &true_backGround);
403 defaultTree->SetBranchAddress(
"event", &event);
404 defaultTree->SetBranchAddress(
"run", &run);
406 int interaction_topology;
407 defaultTree->SetBranchAddress(
"interaction_topology", &interaction_topology);
410 std::vector<double> * reco_beam_calibrated_dEdX = 0x0;
411 defaultTree->SetBranchAddress(
"reco_beam_calibrated_dEdX", &reco_beam_calibrated_dEdX);
412 std::vector<double> * reco_beam_TrkPitch = 0x0;
413 defaultTree->SetBranchAddress(
"reco_beam_TrkPitch", &reco_beam_TrkPitch);
418 int true_daughter_nPiPlus, true_daughter_nPiMinus, true_daughter_nPi0, true_beam_ID;
419 std::vector< std::string > * true_beam_processes = 0x0;
420 std::vector< int > * reco_beam_hit_true_ID = 0x0;
422 defaultTree->SetBranchAddress(
"true_daughter_nPiPlus", &true_daughter_nPiPlus );
423 defaultTree->SetBranchAddress(
"true_daughter_nPiMinus", &true_daughter_nPiMinus );
424 defaultTree->SetBranchAddress(
"true_daughter_nPi0", &true_daughter_nPi0 );
425 defaultTree->SetBranchAddress(
"true_beam_ID", &true_beam_ID );
426 defaultTree->SetBranchAddress(
"true_beam_processes", &true_beam_processes );
427 defaultTree->SetBranchAddress(
"reco_beam_hit_true_ID", &reco_beam_hit_true_ID );
437 std::vector<double> * g4rw_primary_plus_sigma_weight = 0x0;
438 std::vector<double> * g4rw_primary_minus_sigma_weight = 0x0;
439 std::vector<std::string> * g4rw_primary_var = 0x0;
441 defaultTree->SetBranchAddress(
"g4rw_primary_plus_sigma_weight", &g4rw_primary_plus_sigma_weight);
442 defaultTree->SetBranchAddress(
"g4rw_primary_minus_sigma_weight", &g4rw_primary_minus_sigma_weight);
443 defaultTree->SetBranchAddress(
"g4rw_primary_var", &g4rw_primary_var);
446 channel.erase(
std::remove(channel.begin(), channel.end(),
'.'), channel.end());
447 channel.erase(
std::remove(channel.begin(), channel.end(),
' '), channel.end());
448 topo.erase(
std::remove(topo.begin(), topo.end(),
'.'), topo.end());
449 topo.erase(
std::remove(topo.begin(), topo.end(),
' '), topo.end());
451 const int nrecobins = recoBins.size();
452 TString hist_name = Form(
"MC_Channel%s_%s_%.1f-%.1f_Histo",
453 channel.c_str(), topo.c_str(), minval,
maxval);
454 TString hist_title = Form(
"MC Signal for channel %s and topology %s and true region %.1f-%.1f",
455 channel.c_str(), topo.c_str(), minval,
maxval);
458 hist_name +=
"_high_" + systName;
459 hist_title +=
" +1 sigma";
461 else if (doSyst == -1) {
462 hist_name +=
"_low_" + systName;
463 hist_title +=
" -1 sigma";
466 TH1D* mchisto =
new TH1D(hist_name, hist_title,
467 (doNegativeReco ? nrecobins : (nrecobins-1)),
468 (doNegativeReco ? -1 : 0), nrecobins-1);
469 mchisto->SetDirectory(0);
471 mf::LogInfo(
"FillMCSignalHistogram_Pions") <<
"Filling MC signal histogram " <<
472 mchisto->GetName() <<
" from file " << filename.c_str() <<
473 " for channel " << channel.c_str() <<
" with topology " <<
474 topo.c_str() <<
" in the true region " << minval <<
"-" <<
maxval;
476 bool done_check =
false;
477 for (
int k=0;
k < defaultTree->GetEntries();
k++) {
479 defaultTree->GetEntry(
k);
481 if (!done_check && doSyst != 0) {
482 if (g4rw_primary_var->size() > 0) {
483 auto syst_check = std::find(g4rw_primary_var->begin(), g4rw_primary_var->end(), systName);
484 if (syst_check == g4rw_primary_var->end()) {
485 std::cout <<
"Error! Could not find syst named " << systName <<
std::endl;
493 double syst_weight = 1.;
494 std::map<std::string, double> weights;
496 for (
size_t i = 0; i < g4rw_primary_var->size(); ++i) {
497 weights[(*g4rw_primary_var)[i]] = (*g4rw_primary_plus_sigma_weight)[i];
500 else if (doSyst == -1) {
501 for (
size_t i = 0; i < g4rw_primary_var->size(); ++i) {
502 weights[(*g4rw_primary_var)[i]] = (*g4rw_primary_minus_sigma_weight)[i];
506 if ( reco_beam_true_byHits_origin == 2 )
541 if (interaction_topology == -1)
542 std::cout <<
"Warning: Interaction topo -1" <<
std::endl;
544 if (interaction_topology == 1 || interaction_topology ==2) {
546 if ( !reco_beam_hit_true_ID->size() ) {
552 if (doSyst == 1 || doSyst == -1 ) {
553 syst_weight = weights[systName];
565 if(interaction_topology != toponum)
continue;
567 double total_weight = weight*syst_weight;
568 if (true_beam_PDG == 211) {
569 total_weight *= PiMuScale.first;
571 else if (true_beam_PDG == -13) {
572 total_weight *= PiMuScale.second;
578 if (true_beam_interactingEnergy < minval ||
579 true_beam_interactingEnergy >= maxval)
continue;
581 if (doNegativeReco) {
582 if (reco_beam_interactingEnergy < 0.0){
583 mchisto->AddBinContent(1, total_weight);
586 for (
int l = 1;
l < nrecobins;
l++) {
587 if (reco_beam_interactingEnergy > recoBins[
l-1] &&
588 reco_beam_interactingEnergy <= recoBins[
l]) {
589 mchisto->AddBinContent(l+1, total_weight);
597 if (reco_beam_interactingEnergy < 0.0)
continue;
600 for (
int l = 1;
l < nrecobins;
l++) {
601 if (reco_beam_interactingEnergy > recoBins[
l-1] &&
602 reco_beam_interactingEnergy <= recoBins[
l]) {
603 mchisto->AddBinContent(l, total_weight);
620 bool doNegativeReco,
bool IsIncidentHisto) {
623 TFile *
file =
new TFile(filename.c_str(),
"READ");
624 TTree *defaultTree = (TTree*)file->Get(treename.c_str());
626 Int_t reco_beam_type;
627 Int_t reco_beam_nTrackDaughters, reco_beam_nShowerDaughters;
628 Double_t reco_beam_len, reco_beam_vtxX, reco_beam_vtxY, reco_beam_vtxZ, reco_beam_startX, reco_beam_startY, reco_beam_startZ, reco_beam_trackDirZ, reco_beam_interactingEnergy, reco_beam_Chi2_proton;
629 bool reco_beam_true_byHits_matched;
630 Int_t reco_beam_true_byHits_origin, reco_beam_true_byHits_PDG;
632 Double_t true_beam_interactingEnergy;
635 std::vector<double> *reco_beam_incidentEnergies = 0;
639 defaultTree->SetBranchAddress(
"reco_beam_type", &reco_beam_type);
640 defaultTree->SetBranchAddress(
"reco_beam_len", &reco_beam_len);
641 defaultTree->SetBranchAddress(
"reco_beam_vtxX", &reco_beam_vtxX);
642 defaultTree->SetBranchAddress(
"reco_beam_vtxY", &reco_beam_vtxY);
643 defaultTree->SetBranchAddress(
"reco_beam_vtxZ", &reco_beam_vtxZ);
644 defaultTree->SetBranchAddress(
"reco_beam_startX", &reco_beam_startX);
645 defaultTree->SetBranchAddress(
"reco_beam_startY", &reco_beam_startY);
646 defaultTree->SetBranchAddress(
"reco_beam_startZ", &reco_beam_startZ);
647 double reco_beam_endZ;
648 defaultTree->SetBranchAddress(
"reco_beam_endZ", &reco_beam_endZ);
649 defaultTree->SetBranchAddress(
"reco_beam_trackDirZ", &reco_beam_trackDirZ);
650 defaultTree->SetBranchAddress(
"reco_beam_nTrackDaughters", &reco_beam_nTrackDaughters);
651 defaultTree->SetBranchAddress(
"reco_beam_nShowerDaughters", &reco_beam_nShowerDaughters);
652 defaultTree->SetBranchAddress(
"reco_beam_interactingEnergy", &reco_beam_interactingEnergy);
653 defaultTree->SetBranchAddress(
"reco_beam_Chi2_proton", &reco_beam_Chi2_proton);
654 defaultTree->SetBranchAddress(
"reco_beam_incidentEnergies", &reco_beam_incidentEnergies);
656 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_matched", &reco_beam_true_byHits_matched);
657 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_origin", &reco_beam_true_byHits_origin);
658 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_PDG", &reco_beam_true_byHits_PDG);
659 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_endProcess", &reco_beam_true_byHits_endProcess);
661 defaultTree->SetBranchAddress(
"true_beam_interactingEnergy", &true_beam_interactingEnergy);
662 defaultTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG);
663 defaultTree->SetBranchAddress(
"true_beam_endProcess", &true_beam_endProcess);
664 std::vector<double> *reco_beam_calo_wire = 0;
665 defaultTree->SetBranchAddress(
"reco_beam_calo_wire", &reco_beam_calo_wire);
667 channel.erase(
std::remove(channel.begin(), channel.end(),
'.'), channel.end());
668 channel.erase(
std::remove(channel.begin(), channel.end(),
' '), channel.end());
670 const int nrecobins = recoBins.size();
671 TString hist_name = Form(
"Data_Channel%s_Histo",channel.c_str());
672 TString hist_title = Form(
"Data for channel %s",channel.c_str());
673 TH1D* datahisto =
new TH1D(hist_name, hist_title,
674 (doNegativeReco ? nrecobins : nrecobins-1),
675 (doNegativeReco ? -1 : 0),
678 datahisto->SetNameTitle(
"Data_ChannelIncident_Histo",
"Incident Data");
679 datahisto->SetDirectory(0);
681 mf::LogInfo(
"FillDataHistogram_Pions") <<
"Filling data histogram " << datahisto->GetName() <<
" from file " << filename.c_str() <<
" for channel " << channel.c_str();
683 double pitch = 0.4792;
685 int slice_cut = std::floor((reco_beam_endZ_cut - (z0 - pitch/2.)) / pitch);
686 for(Int_t
k=0;
k < defaultTree->GetEntries();
k++){
687 defaultTree->GetEntry(
k);
690 if (!doNegativeReco && reco_beam_interactingEnergy < 0.0)
continue;
692 if (reco_beam_interactingEnergy == -999.)
continue;
694 if (IsIncidentHisto) {
696 for (
size_t l = 0;
l < reco_beam_incidentEnergies->size(); ++
l) {
701 if ((*reco_beam_calo_wire)[
l] > slice_cut)
704 double energy = (*reco_beam_incidentEnergies)[
l];
705 if (doNegativeReco) {
707 datahisto->AddBinContent(1, 1.);
710 for (
int m = 1;
m < nrecobins;
m++) {
711 if (energy > recoBins[
m-1] &&
712 energy <= recoBins[
m]) {
713 datahisto->AddBinContent(m+1, 1.);
720 for (
int m = 1;
m < nrecobins;
m++) {
721 if (energy > recoBins[
m-1] && energy <= recoBins[
m]) {
722 datahisto->AddBinContent(m, 1);
732 if (doNegativeReco) {
733 if (reco_beam_interactingEnergy < 0.) {
734 datahisto->AddBinContent(1, 1);
737 for (
int l = 1;
l < nrecobins;
l++) {
738 if (reco_beam_interactingEnergy > recoBins[
l-1] &&
739 reco_beam_interactingEnergy <= recoBins[
l]) {
740 datahisto->AddBinContent(l+1, 1);
747 for (
int l = 1;
l < nrecobins;
l++) {
748 if (reco_beam_interactingEnergy > recoBins[
l-1] &&
749 reco_beam_interactingEnergy <= recoBins[
l]) {
750 datahisto->AddBinContent(l, 1);
769 double reco_beam_endZ_cut,
double minval,
double maxval,
771 std::pair<double, double> PiMuScale) {
774 TFile *
file =
new TFile(filename.c_str(),
"READ");
775 TTree *defaultTree = (TTree*)file->Get(treename.c_str());
777 Int_t reco_beam_type;
778 Int_t reco_beam_nTrackDaughters, reco_beam_nShowerDaughters;
779 Double_t reco_beam_len, reco_beam_vtxX, reco_beam_vtxY, reco_beam_vtxZ, reco_beam_startX, reco_beam_startY, reco_beam_startZ, reco_beam_trackDirZ, reco_beam_interactingEnergy, reco_beam_Chi2_proton;
780 bool reco_beam_true_byHits_matched;
781 Int_t reco_beam_true_byHits_origin, reco_beam_true_byHits_PDG;
782 Int_t true_beam_PDG, true_beam_ID;
783 double true_beam_endZ;
784 Double_t true_beam_interactingEnergy;
787 std::vector<double> *reco_beam_incidentEnergies = 0;
788 std::vector<double> *reco_beam_calo_wire = 0;
792 defaultTree->SetBranchAddress(
"reco_beam_type", &reco_beam_type);
793 defaultTree->SetBranchAddress(
"reco_beam_len", &reco_beam_len);
794 defaultTree->SetBranchAddress(
"reco_beam_vtxX", &reco_beam_vtxX);
795 defaultTree->SetBranchAddress(
"reco_beam_vtxY", &reco_beam_vtxY);
796 defaultTree->SetBranchAddress(
"reco_beam_vtxZ", &reco_beam_vtxZ);
797 defaultTree->SetBranchAddress(
"reco_beam_startX", &reco_beam_startX);
798 defaultTree->SetBranchAddress(
"reco_beam_startY", &reco_beam_startY);
799 defaultTree->SetBranchAddress(
"reco_beam_startZ", &reco_beam_startZ);
800 double reco_beam_endZ;
801 defaultTree->SetBranchAddress(
"reco_beam_endZ", &reco_beam_endZ);
802 defaultTree->SetBranchAddress(
"reco_beam_trackDirZ", &reco_beam_trackDirZ);
803 defaultTree->SetBranchAddress(
"reco_beam_nTrackDaughters", &reco_beam_nTrackDaughters);
804 defaultTree->SetBranchAddress(
"reco_beam_nShowerDaughters", &reco_beam_nShowerDaughters);
805 defaultTree->SetBranchAddress(
"reco_beam_interactingEnergy", &reco_beam_interactingEnergy);
806 defaultTree->SetBranchAddress(
"reco_beam_Chi2_proton", &reco_beam_Chi2_proton);
807 defaultTree->SetBranchAddress(
"reco_beam_incidentEnergies", &reco_beam_incidentEnergies);
808 defaultTree->SetBranchAddress(
"reco_beam_calo_wire", &reco_beam_calo_wire);
810 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_matched", &reco_beam_true_byHits_matched);
811 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_origin", &reco_beam_true_byHits_origin);
812 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_PDG", &reco_beam_true_byHits_PDG);
813 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_endProcess", &reco_beam_true_byHits_endProcess);
815 defaultTree->SetBranchAddress(
"true_beam_interactingEnergy", &true_beam_interactingEnergy);
816 defaultTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG);
817 defaultTree->SetBranchAddress(
"true_beam_endZ", &true_beam_endZ);
818 defaultTree->SetBranchAddress(
"true_beam_ID", &true_beam_ID);
819 defaultTree->SetBranchAddress(
"true_beam_endProcess", &true_beam_endProcess);
825 std::vector< int > * reco_beam_hit_true_ID = 0x0;
826 std::vector< int > * reco_beam_hit_true_origin = 0x0;
827 std::vector< int > * reco_beam_hit_true_slice = 0x0;
829 defaultTree->SetBranchAddress(
"reco_beam_hit_true_ID", &reco_beam_hit_true_ID);
830 defaultTree->SetBranchAddress(
"reco_beam_hit_true_slice", &reco_beam_hit_true_slice);
831 defaultTree->SetBranchAddress(
"reco_beam_hit_true_origin", &reco_beam_hit_true_origin);
833 std::vector< std::string > * true_beam_processes = 0x0;
834 defaultTree->SetBranchAddress(
"true_beam_processes", &true_beam_processes);
836 std::vector< int > * true_beam_daughter_ID = 0x0;
837 std::vector< int > * true_beam_grand_daughter_ID = 0x0;
838 defaultTree->SetBranchAddress(
"true_beam_daughter_ID", &true_beam_daughter_ID );
839 defaultTree->SetBranchAddress(
"true_beam_grand_daughter_ID", &true_beam_grand_daughter_ID );
846 std::vector<double> * g4rw_primary_plus_sigma_weight = 0x0;
847 std::vector<double> * g4rw_primary_minus_sigma_weight = 0x0;
848 std::vector<std::string> * g4rw_primary_var = 0x0;
850 defaultTree->SetBranchAddress(
"g4rw_primary_plus_sigma_weight", &g4rw_primary_plus_sigma_weight);
851 defaultTree->SetBranchAddress(
"g4rw_primary_minus_sigma_weight", &g4rw_primary_minus_sigma_weight);
852 defaultTree->SetBranchAddress(
"g4rw_primary_var", &g4rw_primary_var);
856 std::vector<int> * true_beam_slices = 0x0;
857 std::vector<double> * true_beam_incidentEnergies = 0x0;
858 defaultTree->SetBranchAddress(
"true_beam_slices", &true_beam_slices );
859 defaultTree->SetBranchAddress(
"true_beam_incidentEnergies",
860 &true_beam_incidentEnergies);
866 topo.erase(
std::remove(topo.begin(), topo.end(),
'.'), topo.end());
867 topo.erase(
std::remove(topo.begin(), topo.end(),
' '), topo.end());
869 size_t nrecobins = recoBins.size();
871 TString hist_name = Form(
"MC_ChannelIncident_%s_Histo", topo.c_str());
874 TString hist_title = Form(
"Incident MC for topology %s", topo.c_str());
879 hist_name +=
"_high_" + systName;
880 hist_title +=
" +1 sigma";
882 else if (doSyst == -1) {
883 hist_name +=
"_low_" + systName;
884 hist_title +=
" -1 sigma";
888 TH1D* mchisto =
new TH1D(hist_name, hist_title,
889 (doNegativeReco ? nrecobins : (nrecobins-1)),
890 (doNegativeReco ? -1 : 0), nrecobins-1);
891 mchisto->SetDirectory(0);
894 "Filling MC incident histogram " << mchisto->GetName() <<
895 " from file " << filename.c_str() <<
896 " with topology " << topo.c_str();
898 double pitch = 0.4792;
900 int slice_cut = std::floor((reco_beam_endZ_cut - (z0 - pitch/2.)) / pitch);
902 bool done_check =
false;
903 for(Int_t
k=0;
k < defaultTree->GetEntries();
k++){
905 defaultTree->GetEntry(
k);
908 if (!done_check && doSyst != 0) {
909 if (g4rw_primary_var->size() > 0) {
911 auto syst_check = std::find(g4rw_primary_var->begin(), g4rw_primary_var->end(), systName);
912 if (syst_check == g4rw_primary_var->end()) {
913 std::cout <<
"Error! Could not find syst named " << systName <<
std::endl;
921 double syst_weight = 1.;
922 std::map<std::string, double> weights;
924 for (
size_t i = 0; i < g4rw_primary_var->size(); ++i) {
925 weights[(*g4rw_primary_var)[i]] = (*g4rw_primary_plus_sigma_weight)[i];
928 else if (doSyst == -1) {
929 for (
size_t i = 0; i < g4rw_primary_var->size(); ++i) {
930 weights[(*g4rw_primary_var)[i]] = (*g4rw_primary_minus_sigma_weight)[i];
939 if (!doNegativeReco && reco_beam_interactingEnergy < 0.0)
continue;
941 if (reco_beam_interactingEnergy == -999.)
continue;
946 for(
size_t l = 0;
l < reco_beam_incidentEnergies->size(); ++
l){
951 if ((*reco_beam_calo_wire)[
l] > slice_cut)
955 int true_id = (*reco_beam_hit_true_ID)[
l];
956 int true_origin = (*reco_beam_hit_true_origin)[
l];
957 int true_slice = (*reco_beam_hit_true_slice)[
l];
965 double true_energy = 0.;
968 if( true_origin == 2 ){
972 if( true_id != true_beam_ID ){
973 if ( true_id == -999 )
977 if ( true_beam_endZ < 0. )
982 auto daughter_ID_check = std::find(
983 true_beam_daughter_ID->begin(), true_beam_daughter_ID->end(),
986 auto g_daughter_ID_check = std::find(
987 true_beam_grand_daughter_ID->begin(),
988 true_beam_grand_daughter_ID->end(),
991 if (daughter_ID_check != true_beam_daughter_ID->end()) {
994 else if (g_daughter_ID_check != true_beam_grand_daughter_ID->end()){
1007 if (true_slice == -999) {
1011 if (true_beam_PDG == 211) {
1012 if (true_slice > slice_cut) {
1020 bool found_true_slice =
false;
1021 for (
size_t i = 0; i < true_beam_slices->size(); ++i) {
1022 int check_slice = (*true_beam_slices)[i];
1023 true_energy = (*true_beam_incidentEnergies)[i];
1024 if (true_slice == check_slice) {
1029 found_true_slice =
true;
1033 if (!found_true_slice) {
1034 std::cout <<
"Could not find true slice" <<
std::endl;
1038 else if (true_beam_PDG == -13) {
1042 if (doSyst == 1 || doSyst == -1) {
1043 syst_weight = weights[systName];
1051 std::cout <<
"Warning: incident topology == -1" <<
std::endl;
1052 if (topology != toponum) {
1056 double total_weight = weight*syst_weight;
1057 if (true_beam_PDG == 211) {
1058 total_weight *= PiMuScale.first;
1060 else if (true_beam_PDG == -13) {
1061 total_weight *= PiMuScale.second;
1067 if (true_energy < minval || true_energy >= maxval) {
1083 double energy = (*reco_beam_incidentEnergies)[
l];
1084 if (doNegativeReco) {
1086 mchisto->AddBinContent(1, total_weight);
1089 for (
size_t m = 1;
m < nrecobins; ++
m) {
1090 if (energy > recoBins[
m-1] &&
1091 energy <= recoBins[
m]) {
1093 mchisto->AddBinContent(m+1, total_weight);
1101 if (energy < 0.0)
continue;
1103 for (
size_t m = 1;
m < nrecobins; ++
m) {
1104 if (energy > recoBins[
m-1] &&
1105 energy <= recoBins[
m]) {
1106 mchisto->AddBinContent(m, total_weight);
1125 TFile *
file =
new TFile(filename.c_str(),
"READ");
1126 TTree *truthTree = (TTree*)file->Get(treename.c_str());
1128 Int_t true_beam_PDG;
1129 Double_t true_beam_interactingEnergy, true_beam_endZ;
1132 truthTree->SetBranchAddress(
"true_beam_interactingEnergy", &true_beam_interactingEnergy);
1133 truthTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG);
1134 truthTree->SetBranchAddress(
"true_beam_endZ", &true_beam_endZ);
1135 truthTree->SetBranchAddress(
"true_beam_endProcess", &true_beam_endProcess);
1137 channel.erase(
std::remove(channel.begin(), channel.end(),
'.'), channel.end());
1138 channel.erase(
std::remove(channel.begin(), channel.end(),
' '), channel.end());
1140 const int ntruthbins = truthBins.size();
1141 TH1D* mchisto =
new TH1D(Form(
"MC_Channel%s_TruthSig_Histo",channel.c_str()), Form(
"MC Truth Signal for channel %s",channel.c_str()), ntruthbins-1, 0, ntruthbins-1);
1142 mchisto->SetDirectory(0);
1144 mf::LogInfo(
"FillMCTruthSignalHistogram_Pions") <<
"Filling MC truth signal histogram " << mchisto->GetName() <<
" from file " << filename.c_str() <<
" for channel " << channel.c_str();
1146 for(Int_t
k=0;
k < truthTree->GetEntries();
k++){
1147 truthTree->GetEntry(
k);
1150 if(true_beam_PDG != 211)
continue;
1153 if(true_beam_endZ < 0.0)
continue;
1159 for(Int_t
l = 1;
l < ntruthbins;
l++){
1160 if(true_beam_interactingEnergy > truthBins[
l-1] && true_beam_interactingEnergy <= truthBins[
l]){
1161 mchisto->AddBinContent(l, weight);
1176 TFile *
file =
new TFile(filename.c_str(),
"READ");
1177 TTree *truthTree = (TTree*)file->Get(treename.c_str());
1179 Int_t reco_beam_type;
1180 Double_t reco_beam_len, reco_beam_startX, reco_beam_startY, reco_beam_startZ, reco_beam_trackDirZ, reco_beam_interactingEnergy, reco_beam_Chi2_proton;
1181 Int_t true_beam_PDG, reco_beam_true_byHits_origin, reco_beam_true_byHits_PDG, reco_beam_nTrackDaughters, reco_beam_nShowerDaughters;
1182 Double_t true_beam_interactingEnergy, true_beam_endZ;
1183 std::vector<double> *true_beam_incidentEnergies = 0; std::vector<double> *reco_beam_incidentEnergies = 0;
1185 truthTree->SetBranchAddress(
"reco_beam_type", &reco_beam_type);
1186 truthTree->SetBranchAddress(
"reco_beam_len", &reco_beam_len);
1187 truthTree->SetBranchAddress(
"reco_beam_startX", &reco_beam_startX);
1188 truthTree->SetBranchAddress(
"reco_beam_startY", &reco_beam_startY);
1189 truthTree->SetBranchAddress(
"reco_beam_startZ", &reco_beam_startZ);
1190 truthTree->SetBranchAddress(
"reco_beam_trackDirZ", &reco_beam_trackDirZ);
1191 truthTree->SetBranchAddress(
"reco_beam_interactingEnergy", &reco_beam_interactingEnergy);
1192 truthTree->SetBranchAddress(
"reco_beam_Chi2_proton", &reco_beam_Chi2_proton);
1193 truthTree->SetBranchAddress(
"reco_beam_true_byHits_origin", &reco_beam_true_byHits_origin);
1194 truthTree->SetBranchAddress(
"reco_beam_true_byHits_PDG", &reco_beam_true_byHits_PDG);
1195 truthTree->SetBranchAddress(
"reco_beam_incidentEnergies", &reco_beam_incidentEnergies);
1196 truthTree->SetBranchAddress(
"reco_beam_nTrackDaughters", &reco_beam_nTrackDaughters);
1197 truthTree->SetBranchAddress(
"reco_beam_nShowerDaughters", &reco_beam_nShowerDaughters);
1199 truthTree->SetBranchAddress(
"true_beam_interactingEnergy", &true_beam_interactingEnergy);
1200 truthTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG);
1201 truthTree->SetBranchAddress(
"true_beam_endZ", &true_beam_endZ);
1202 truthTree->SetBranchAddress(
"true_beam_incidentEnergies", &true_beam_incidentEnergies);
1204 const int nbins = Bins.size();
1205 TH1D* mchisto =
new TH1D(Form(
"MC_PionFlux%i_Histo",mode), Form(
"MC Pion Flux - %i",mode), nbins-1, 0, nbins-1);
1206 mchisto->SetDirectory(0);
1208 mf::LogInfo(
"FillMCFlux_Pions") <<
"Filling MC pion flux histogram " << mchisto->GetName() <<
" from file " << filename.c_str() <<
" for mode " << mode;
1210 for(Int_t
k=0;
k < truthTree->GetEntries();
k++){
1211 truthTree->GetEntry(
k);
1214 if(true_beam_PDG != 211)
continue;
1217 if(true_beam_endZ < 0.0)
continue;
1219 if(true_beam_incidentEnergies->size() == 0 && reco_beam_incidentEnergies->size() == 0)
continue;
1222 for(UInt_t
l = 0;
l < true_beam_incidentEnergies->size();
l++){
1224 if(true_beam_incidentEnergies->at(
l) > Bins[
m-1] && true_beam_incidentEnergies->at(
l) <= Bins[
m]){
1225 mchisto->SetBinContent(
m, mchisto->GetBinContent(
m) +
weight);
1232 if(reco_beam_true_byHits_origin != 4)
continue;
1233 if(reco_beam_true_byHits_PDG != 211)
continue;
1234 if(reco_beam_incidentEnergies->size() == 0)
continue;
1237 if(reco_beam_type != 13)
continue;
1240 if(reco_beam_startZ < 28.0 || reco_beam_startZ > 32.0)
continue;
1241 if(reco_beam_startY < 410.0 || reco_beam_startY > 445.0)
continue;
1242 if(reco_beam_startX < -45.0 || reco_beam_startX > 0.0)
continue;
1245 if(reco_beam_trackDirZ < 0.9)
continue;
1248 if(reco_beam_Chi2_proton < 450.0)
continue;
1251 if(reco_beam_len < 5.0 || reco_beam_len > 270.0)
continue;
1254 if(reco_beam_interactingEnergy < 0.0)
continue;
1258 Int_t allDaughters = reco_beam_nTrackDaughters + reco_beam_nShowerDaughters;
1259 if(allDaughters <= 0)
continue;
1262 for(UInt_t
l = 0;
l < true_beam_incidentEnergies->size();
l++){
1264 if(true_beam_incidentEnergies->at(
l) > Bins[
m-1] && true_beam_incidentEnergies->at(
l) <= Bins[
m]){
1265 mchisto->SetBinContent(
m, mchisto->GetBinContent(
m) +
weight);
1272 for(UInt_t
l = 0;
l < reco_beam_incidentEnergies->size();
l++){
1274 if(reco_beam_incidentEnergies->at(
l) > Bins[
m-1] && reco_beam_incidentEnergies->at(
l) <= Bins[
m]){
1275 mchisto->SetBinContent(
m, mchisto->GetBinContent(
m) +
weight);
1294 TFile *
file =
new TFile(filename.c_str(),
"READ");
1295 TTree *defaultTree = (TTree*)file->Get(treename.c_str());
1299 Int_t true_beam_PDG, reco_beam_true_byHits_origin;
1301 defaultTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG);
1302 defaultTree->SetBranchAddress(
"reco_beam_true_byHits_origin", &reco_beam_true_byHits_origin);
1304 for(Int_t
k=0;
k < defaultTree->GetEntries();
k++){
1305 defaultTree->GetEntry(
k);
1307 if(true_beam_PDG != 211)
continue;
1308 if(reco_beam_true_byHits_origin != 4)
continue;
1318 std::pair< TH1 *, TH1 * >
1321 std::vector<double> bins,
double reco_beam_endZ_cut,
1322 int doSyst,
double weight) {
1325 TFile *
file =
new TFile(fileName.c_str(),
"READ");
1326 TTree * defaultTree = (TTree*)file->Get(treeName.c_str());
1329 const size_t nBins = bins.size();
1330 TString hist_name =
"MC_Incident_Efficiency_Denominator";
1331 TString hist_title =
"Incident MC Efficiency Denominator";
1334 hist_name +=
"_high";
1335 hist_title +=
" +1 sigma";
1337 else if (doSyst == -1) {
1338 hist_name +=
"_low";
1339 hist_title +=
" -1 sigma";
1342 TH1D * denominator =
new TH1D(hist_name, hist_title, nBins-1, 0, nBins-1 );
1343 denominator->SetDirectory(0);
1345 hist_name =
"MC_Incident_Efficiency_Numerator";
1346 hist_title =
"Incident MC Efficiency Numerator";
1349 hist_name +=
"_high";
1350 hist_title +=
" +1 sigma";
1352 else if (doSyst == -1) {
1353 hist_name +=
"_low";
1354 hist_title +=
" -1 sigma";
1357 TH1D * numerator =
new TH1D(hist_name, hist_title, nBins-1, 0, nBins-1 );
1358 numerator->SetDirectory(0);
1361 double reco_beam_interactingEnergy, true_beam_endZ;
1362 int true_beam_ID, true_beam_PDG;
1363 std::vector< int > * reco_beam_hit_true_ID = 0x0;
1364 std::vector< int > * reco_beam_hit_true_slice = 0x0;
1366 std::vector< std::string > * true_beam_processes = 0x0;
1367 std::vector< int > * true_beam_slices = 0x0;
1368 std::vector< double > * true_beam_incidentEnergies = 0x0;
1370 defaultTree->SetBranchAddress(
"reco_beam_interactingEnergy", &reco_beam_interactingEnergy );
1371 defaultTree->SetBranchAddress(
"reco_beam_hit_true_ID", &reco_beam_hit_true_ID );
1372 defaultTree->SetBranchAddress(
"reco_beam_hit_true_slice", &reco_beam_hit_true_slice );
1373 defaultTree->SetBranchAddress(
"true_beam_processes", &true_beam_processes );
1374 defaultTree->SetBranchAddress(
"true_beam_slices", &true_beam_slices );
1375 defaultTree->SetBranchAddress(
"true_beam_ID", &true_beam_ID );
1376 defaultTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG );
1377 defaultTree->SetBranchAddress(
"true_beam_endZ", &true_beam_endZ );
1378 defaultTree->SetBranchAddress(
"true_beam_incidentEnergies", &true_beam_incidentEnergies );
1385 double g4rw_primary_plus_sigma_weight, g4rw_primary_minus_sigma_weight;
1387 defaultTree->SetBranchAddress(
"g4rw_primary_plus_sigma_weight", &g4rw_primary_plus_sigma_weight);
1388 defaultTree->SetBranchAddress(
"g4rw_primary_minus_sigma_weight", &g4rw_primary_minus_sigma_weight);
1391 for(
int k=0;
k < defaultTree->GetEntries(); ++
k ){
1392 double syst_weight = 1.;
1393 defaultTree->GetEntry(
k);
1395 if ( true_beam_PDG != 211 )
1399 syst_weight = g4rw_primary_plus_sigma_weight;
1401 else if (doSyst == -1) {
1402 syst_weight = g4rw_primary_minus_sigma_weight;
1412 if ((true_beam_incidentEnergies->size() && !true_beam_slices->size()) ||
1413 (!true_beam_incidentEnergies->size() && true_beam_slices->size())) {
1414 std::cout <<
"NOTICE! Energies: " <<
1415 true_beam_incidentEnergies->size() <<
" slices: " <<
1419 double pitch = 0.4792;
1420 double z0 = 0.56035;
1421 int slice_cut = std::floor((reco_beam_endZ_cut - (z0 - pitch/2.)) / pitch);
1423 std::vector< int > denom_slices;
1427 for (
size_t i = 0; i < true_beam_incidentEnergies->size(); ++i) {
1429 int the_slice = (*true_beam_slices)[i];
1430 if (the_slice > slice_cut)
continue;
1432 for (
size_t j = 1; j <
nBins; ++j ) {
1433 if ( true_beam_incidentEnergies->at(i) > bins[j-1] &&
1434 true_beam_incidentEnergies->at(i) <= bins[j] ) {
1435 denominator->AddBinContent(j, weight*syst_weight);
1439 denom_slices.push_back(the_slice);
1444 for (
size_t i = 0; i < reco_beam_hit_true_ID->size(); ++i ) {
1447 int true_id = (*reco_beam_hit_true_ID)[i];
1448 int true_slice = (*reco_beam_hit_true_slice)[i];
1450 if ( true_id == true_beam_ID ) {
1451 if (true_slice > slice_cut)
continue;
1454 for (
size_t j = 0; j < true_beam_slices->size(); ++j ) {
1455 if ( true_slice == (*true_beam_slices)[j] ) {
1457 auto slice_check = std::find(denom_slices.begin(),
1461 if ( slice_check == denom_slices.end() ) {
1462 std::cout <<
"Warning found true slice from hit" 1463 <<
"that was not in denominator" <<
std::endl;
1465 for (
size_t m = 1;
m <
nBins; ++
m ) {
1466 if ( (*true_beam_incidentEnergies)[j] > bins[
m-1]
1467 && (*true_beam_incidentEnergies)[j] <= bins[
m] ) {
1468 numerator->AddBinContent(
m, weight*syst_weight);
1478 for (
size_t i = 1; i < bins.size(); ++i) {
1479 TString
label = Form(
"%.1f-%.1f", bins[i-1], bins[i]);
1480 numerator->GetXaxis()->SetBinLabel(i, label.Data());
1481 denominator->GetXaxis()->SetBinLabel(i, label.Data());
1483 numerator->SetTitle(
";E_{True} (MeV)");
1484 denominator->SetTitle(
";E_{True} (MeV)");
1488 return {numerator, denominator};
1492 std::pair< TH1 *, TH1 *>
1496 std::string topo,
int toponum,
double endZ_cut,
int doSyst,
1500 TFile *
file =
new TFile(fileName.c_str(),
"READ");
1501 TTree * defaultTree = (TTree*)file->Get(treeName.c_str());
1504 const size_t nBins = bins.size();
1505 TString hist_name = Form(
"MC_Channel%s_%s_Interacting_Denominator",channel.c_str(),topo.c_str());
1506 TString hist_title = Form(
"Interacting MC Efficiency Denominator for channel %s and topology %s", channel.c_str(), topo.c_str());
1509 hist_name +=
"_high";
1510 hist_title +=
" +1 sigma";
1512 else if (doSyst == -1) {
1513 hist_name +=
"_low";
1514 hist_title +=
" -1 sigma";
1517 TH1D * denominator =
new TH1D(hist_name, hist_title, nBins-1, 0, nBins-1);
1518 denominator->SetDirectory(0);
1520 hist_name = Form(
"MC_Channel%s_%s_Interacting_Numerator",channel.c_str(),topo.c_str());
1521 hist_title = Form(
"Interacting MC Efficiency Numerator for channel %s and topology %s", channel.c_str(), topo.c_str());
1524 hist_name +=
"_high";
1525 hist_title +=
" +1 sigma";
1527 else if (doSyst == -1) {
1528 hist_name +=
"_low";
1529 hist_title +=
" -1 sigma";
1533 TH1D * numerator =
new TH1D(hist_name, hist_title, nBins-1, 0, nBins-1 );
1534 numerator->SetDirectory(0);
1537 int true_beam_PDG, true_daughter_nPiPlus, true_daughter_nPiMinus, true_daughter_nPi0;
1539 std::vector< std::string > * true_beam_processes = 0x0;
1540 double true_beam_interactingEnergy, true_beam_endZ;
1541 bool has_noPion_daughter, has_shower_nHits_distance;
1543 std::vector< int > * true_beam_slices = 0x0;
1544 defaultTree->SetBranchAddress(
"true_beam_slices", &true_beam_slices );
1546 defaultTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG );
1547 defaultTree->SetBranchAddress(
"true_beam_endZ", &true_beam_endZ );
1548 defaultTree->SetBranchAddress(
"true_beam_endProcess", &true_beam_endProcess );
1549 defaultTree->SetBranchAddress(
"true_daughter_nPiPlus", &true_daughter_nPiPlus );
1550 defaultTree->SetBranchAddress(
"true_daughter_nPiMinus", &true_daughter_nPiMinus );
1551 defaultTree->SetBranchAddress(
"true_daughter_nPi0", &true_daughter_nPi0 );
1552 defaultTree->SetBranchAddress(
"true_beam_processes", &true_beam_processes );
1553 defaultTree->SetBranchAddress(
"true_beam_interactingEnergy", &true_beam_interactingEnergy );
1554 defaultTree->SetBranchAddress(
"has_noPion_daughter", &has_noPion_daughter );
1555 defaultTree->SetBranchAddress(
"has_shower_nHits_distance", &has_shower_nHits_distance );
1562 double g4rw_primary_plus_sigma_weight, g4rw_primary_minus_sigma_weight;
1564 defaultTree->SetBranchAddress(
"g4rw_primary_plus_sigma_weight", &g4rw_primary_plus_sigma_weight);
1565 defaultTree->SetBranchAddress(
"g4rw_primary_minus_sigma_weight", &g4rw_primary_minus_sigma_weight);
1570 for(
int k=0;
k < defaultTree->GetEntries(); ++
k ){
1571 double syst_weight = 1.;
1572 defaultTree->GetEntry(
k);
1575 if ( true_beam_PDG != 211 )
1578 if (!true_beam_slices->size())
1582 if (!(*true_beam_endProcess ==
"pi+Inelastic" &&
1583 true_daughter_nPiPlus == 0 && true_daughter_nPiMinus == 0 &&
1584 true_beam_endZ < endZ_cut)){
1589 if (true_daughter_nPi0 == 0) {
1597 if (topology != toponum){
1602 syst_weight = g4rw_primary_plus_sigma_weight;
1604 else if (doSyst == -1) {
1605 syst_weight = g4rw_primary_minus_sigma_weight;
1609 for (
size_t i = 1; i <
nBins; ++i ) {
1610 if (true_beam_interactingEnergy > bins[i-1]
1611 && true_beam_interactingEnergy <= bins[i]){
1612 denominator->AddBinContent(i, weight*syst_weight);
1614 if ( has_noPion_daughter ) {
1615 if (topology == 1 && !has_shower_nHits_distance) {
1616 numerator->AddBinContent(i, weight*syst_weight);
1618 else if (topology == 2 && has_shower_nHits_distance) {
1619 numerator->AddBinContent(i, weight*syst_weight);
1628 for (
size_t i = 1; i < bins.size(); ++i) {
1629 TString
label = Form(
"%.1f-%.1f", bins[i-1], bins[i]);
1630 numerator->GetXaxis()->SetBinLabel(i, label.Data());
1631 denominator->GetXaxis()->SetBinLabel(i, label.Data());
1634 numerator->SetTitle(
";E_{True} (MeV)");
1635 denominator->SetTitle(
";E_{True} (MeV)");
1638 return {numerator, denominator};
1646 std::vector<double> binning,
double weight) {
1649 TFile *
file =
new TFile(filename.c_str(),
"READ");
1650 TTree *defaultTree = (TTree*)file->Get(treename.c_str());
1653 int reco_beam_nTrackDaughters, reco_beam_nShowerDaughters;
1654 double reco_beam_len, reco_beam_vtxX, reco_beam_vtxY, reco_beam_vtxZ,
1655 reco_beam_startX, reco_beam_startY, reco_beam_startZ, reco_beam_trackDirZ,
1656 reco_beam_interactingEnergy, reco_beam_Chi2_proton;
1660 double true_beam_endZ;
1661 double true_beam_interactingEnergy;
1663 std::vector<double> *reco_beam_incidentEnergies = 0;
1665 defaultTree->SetBranchAddress(
"reco_beam_type", &reco_beam_type);
1666 defaultTree->SetBranchAddress(
"reco_beam_len", &reco_beam_len);
1667 defaultTree->SetBranchAddress(
"reco_beam_vtxX", &reco_beam_vtxX);
1668 defaultTree->SetBranchAddress(
"reco_beam_vtxY", &reco_beam_vtxY);
1669 defaultTree->SetBranchAddress(
"reco_beam_vtxZ", &reco_beam_vtxZ);
1670 defaultTree->SetBranchAddress(
"reco_beam_startX", &reco_beam_startX);
1671 defaultTree->SetBranchAddress(
"reco_beam_startY", &reco_beam_startY);
1672 defaultTree->SetBranchAddress(
"reco_beam_startZ", &reco_beam_startZ);
1673 defaultTree->SetBranchAddress(
"reco_beam_trackDirZ", &reco_beam_trackDirZ);
1674 defaultTree->SetBranchAddress(
"reco_beam_nTrackDaughters", &reco_beam_nTrackDaughters);
1675 defaultTree->SetBranchAddress(
"reco_beam_nShowerDaughters", &reco_beam_nShowerDaughters);
1676 defaultTree->SetBranchAddress(
"reco_beam_interactingEnergy", &reco_beam_interactingEnergy);
1677 defaultTree->SetBranchAddress(
"reco_beam_Chi2_proton", &reco_beam_Chi2_proton);
1678 defaultTree->SetBranchAddress(
"reco_beam_incidentEnergies", &reco_beam_incidentEnergies);
1680 defaultTree->SetBranchAddress(
"true_beam_interactingEnergy", &true_beam_interactingEnergy);
1681 defaultTree->SetBranchAddress(
"true_beam_PDG", &true_beam_PDG);
1682 defaultTree->SetBranchAddress(
"true_beam_endZ", &true_beam_endZ);
1683 defaultTree->SetBranchAddress(
"true_beam_endProcess", &true_beam_endProcess);
1685 std::vector<int> * reco_beam_hit_true_origin = 0x0;
1686 std::vector<int> * reco_beam_hit_true_ID = 0x0;
1688 defaultTree->SetBranchAddress(
"true_beam_ID", &true_beam_ID );
1689 defaultTree->SetBranchAddress(
"reco_beam_hit_true_origin", &reco_beam_hit_true_origin );
1690 defaultTree->SetBranchAddress(
"reco_beam_hit_true_ID", &reco_beam_hit_true_ID );
1692 std::vector<int> * true_beam_daughter_ID = 0, * true_beam_daughter_PDG = 0;
1693 std::vector<int> * true_beam_grand_daughter_ID = 0x0;
1694 std::vector<double> *reco_beam_calo_wire = 0, *reco_beam_calo_wire_z = 0;
1695 defaultTree->SetBranchAddress(
"reco_beam_calo_wire", &reco_beam_calo_wire);
1696 defaultTree->SetBranchAddress(
"true_beam_daughter_ID",
1697 &true_beam_daughter_ID);
1698 defaultTree->SetBranchAddress(
"true_beam_daughter_PDG",
1699 &true_beam_daughter_PDG);
1700 defaultTree->SetBranchAddress(
"true_beam_grand_daughter_ID",
1701 &true_beam_grand_daughter_ID);
1702 defaultTree->SetBranchAddress(
"reco_beam_calo_wire_z",
1703 &reco_beam_calo_wire_z);
1706 std::string hist_name =
"MC_SidebandChannel" + channel +
"_" + topo +
"_Histo";
1707 std::string hist_title =
"MC Sideband Channel " + channel +
1708 " topology " + topo;
1710 TH1D*
hist =
new TH1D(hist_name.c_str(), hist_title.c_str(), binning.size()-1, 0., binning.size()-1);
1711 hist->SetDirectory(0);
1718 double pitch = 0.4792;
1719 double z0 = 0.56035;
1720 int slice_cut = std::floor((endZ_cut - (z0 - pitch/2.)) / pitch);
1722 for (
int i = 0; i < defaultTree->GetEntries(); ++i) {
1724 defaultTree->GetEntry(i);
1725 if (reco_beam_interactingEnergy == -999.)
continue;
1727 for (
size_t j = 0; j < reco_beam_incidentEnergies->size(); ++j) {
1729 if ((*reco_beam_calo_wire)[j] <= slice_cut)
1735 int true_id = (*reco_beam_hit_true_ID)[j];
1738 auto daughter_find = std::find(true_beam_daughter_ID->begin(),
1739 true_beam_daughter_ID->end(), true_id);
1740 int daughter_index = daughter_find - true_beam_daughter_ID->begin();
1741 if (true_id == true_beam_ID &&
abs(true_beam_PDG) == 13) {
1744 else if (true_id == true_beam_ID &&
abs(true_beam_PDG) == 211) {
1747 else if (daughter_find != true_beam_daughter_ID->end()) {
1748 int daughter_PDG = (*true_beam_daughter_PDG)[daughter_index];
1749 if (
abs(daughter_PDG) == 13) {
1756 else if (std::find(true_beam_grand_daughter_ID->begin(),
1757 true_beam_grand_daughter_ID->end(), true_id) !=
1758 true_beam_grand_daughter_ID->end()) {
1765 if (topology == toponum) {
1767 int bin =
FindBin((*reco_beam_calo_wire_z)[j], binning);
1769 hist->AddBinContent(bin, weight);
1782 std::vector<double> binning,
double weight) {
1785 TFile *
file =
new TFile(filename.c_str(),
"READ");
1786 TTree *defaultTree = (TTree*)file->Get(treename.c_str());
1788 std::vector<double> *reco_beam_calo_wire = 0, *reco_beam_calo_wire_z = 0, *reco_beam_incidentEnergies = 0;
1789 double reco_beam_interactingEnergy;
1790 defaultTree->SetBranchAddress(
"reco_beam_calo_wire", &reco_beam_calo_wire);
1791 defaultTree->SetBranchAddress(
"reco_beam_calo_wire_z", &reco_beam_calo_wire_z);
1792 defaultTree->SetBranchAddress(
"reco_beam_interactingEnergy", &reco_beam_interactingEnergy);
1793 defaultTree->SetBranchAddress(
"reco_beam_incidentEnergies", &reco_beam_incidentEnergies);
1795 std::string hist_name =
"Data_SidebandChannel" + channel +
"_Histo";
1798 TH1D*
hist =
new TH1D(hist_name.c_str(), hist_title.c_str(), binning.size()-1, 0., binning.size()-1);
1799 hist->SetDirectory(0);
1801 double pitch = 0.4792;
1802 double z0 = 0.56035;
1803 int slice_cut = std::floor((endZ_cut - (z0 - pitch/2.)) / pitch);
1805 for (
int i = 0; i < defaultTree->GetEntries(); ++i) {
1807 defaultTree->GetEntry(i);
1808 if (reco_beam_interactingEnergy == -999.)
continue;
1810 for (
size_t j = 0; j < reco_beam_incidentEnergies->size(); ++j) {
1812 if ((*reco_beam_calo_wire)[j] <= slice_cut)
1816 int bin =
FindBin((*reco_beam_calo_wire_z)[j], binning);
1818 hist->AddBinContent(bin, weight);
1827 if (binning.size() < 2)
1830 for (
size_t i = 1; i < binning.size(); ++i) {
1831 if ((binning[i-1] < value) && (value < binning[i])) {
TH1 * FillMCFlux_Pions(std::string filename, std::string treename, std::vector< double > Bins, int mode=1, double weight=1.0)
TH1 * FillMCIncidentHistogram_Pions(std::string filename, std::string treename, std::vector< double > recoBins, std::string topo, int toponum, double reco_beam_endZ_cut, double minval=0., double maxval=100000., bool doNegativeReco=false, int doSyst=0, std::string systName="", double weight=1.0, std::pair< double, double > PiMuScale={1., 1.})
TH1 * FillMCBackgroundHistogram_Pions(std::string filename, std::string treename, std::vector< double > recoBins, std::string channel, std::string topo, int toponum, double endZ_cut, double minval=0.0, double maxval=100000.0, bool doNegativeReco=false, int doSyst=0, std::string systName="", double weight=1.0, std::pair< double, double > PiMuScale={1., 1.})
TH1 * FillDataHistogram_Pions(std::string filename, std::string treename, std::vector< double > recoBins, std::string channel, double reco_beam_endZ_cut, bool doNegativeReco=false, bool IsIncidentHisto=false)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
int FindBin(double value, std::vector< double > binning)
std::pair< TH1 *, TH1 * > GetMCIncidentEfficiency(std::string fileName, std::string treeName, std::vector< double > bins, double reco_beam_endZ_cut, int doSyst=0, double weight=1.)
TH1 * FillMCTruthSignalHistogram_Pions(std::string filename, std::string treename, std::vector< double > truthBins, std::string channel, double weight=1.0)
TH1 * FillDataSidebandHistogram_Pions(std::string filename, std::string treename, std::string channel, double endZ_cut, std::vector< double > binning, double weight=1.)
QTextStream & bin(QTextStream &s)
std::pair< TH1 *, TH1 * > GetMCInteractingEfficiency(std::string fileName, std::string treeName, std::vector< double > bins, std::string channel, std::string topo, int toponum, double endZ_cut, int doSyst=0, double weight=1.)
TH1 * FillMCSignalHistogram_Pions(std::string filename, std::string treename, std::vector< double > recoBins, std::string channel, std::string topo, int toponum, double minval, double maxval, double endZ_cut, bool doNegativeReco=false, int doSyst=0, std::string systName="", double weight=1.0, std::pair< double, double > PiMuScale={1., 1.})
TH1 * FillMCSidebandHistogram_Pions(std::string filename, std::string treename, std::string channel, std::string topo, int toponum, double endZ_cut, std::vector< double > binning, double weight=1.)
int GetNTriggers_Pions(std::string filename, std::string treename, bool IsMC=true)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)