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);
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();
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);
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)