MaCh3 DUNE 1.0.0
Reference Guide
Loading...
Searching...
No Matches
samplePDFDUNEBeamFD.cpp
Go to the documentation of this file.
1#include <TROOT.h>
2
4#include "TString.h"
5#include <assert.h>
6#include <stdexcept>
7#include "TMath.h"
8#include "manager/manager.h"
9
10samplePDFDUNEBeamFD::samplePDFDUNEBeamFD(std::string mc_version_, covarianceXsec* xsec_cov_, covarianceOsc* osc_cov_) : samplePDFFDBase(mc_version_, xsec_cov_, osc_cov_) {
11 //Call insitialise in samplePDFFD
12 Initialise();
13}
14
17
19 dunemcSamples.resize(nSamples,dunemc_base());
20
21 if (CheckNodeExists(SampleManager->raw(), "DUNESampleBools", "iselike" )) {
22 iselike = SampleManager->raw()["DUNESampleBools"]["iselike"].as<bool>();
23 } else{
24 MACH3LOG_ERROR("Did not find DUNESampleBools:iselike in {}, please add this", SampleManager->GetFileName());
25 throw MaCh3Exception(__FILE__, __LINE__);
26 }
27
28 if (CheckNodeExists(SampleManager->raw(), "DUNESampleBools", "isfhc" )) {
29 _isFHC = SampleManager->raw()["DUNESampleBools"]["isfhc"].as<int>();
30 } else{
31 MACH3LOG_ERROR("Did not find DUNESampleBools:isfhc in {}, please add this", SampleManager->GetFileName());
32 throw MaCh3Exception(__FILE__, __LINE__);
33 }
34
35 if (CheckNodeExists(SampleManager->raw(), "POT")) {
36 pot = SampleManager->raw()["POT"].as<double>();
37 } else{
38 MACH3LOG_ERROR("POT not defined in {}, please add this!", SampleManager->GetFileName());
39 throw MaCh3Exception(__FILE__, __LINE__);
40 }
41
42 tot_escale_fd_pos = -999;
45 had_escale_fd_pos = -999;
48 mu_escale_fd_pos = -999;
51 n_escale_fd_pos = -999;
54 em_escale_fd_pos = -999;
57 had_res_fd_pos = -999;
58 mu_res_fd_pos = -999;
59 n_res_fd_pos = -999;
60 em_res_fd_pos = -999;
61 cvn_numu_fd_pos = -999;
62 cvn_nue_fd_pos = -999;
63
64 /*
65 nFDDetectorSystPointers = funcParsIndex.size();
66 std::unordered_map<std::string, const double*> FDDetectorSystPointersMap;
67 FDDetectorSystPointers = std::vector<const double*>(nFDDetectorSystPointers);
68
69 for(auto FuncPar_i = 0 ; FuncPar_i < funcParsIndex.size() ; ++FuncPar_i){
70 FDDetectorSystPointersMap.insert(std::pair<std::string, const double*>(funcParsNames.at(FuncPar_i), XsecCov->retPointer(funcParsIndex.at(FuncPar_i))));
71 }
72
73 int func_it = 0;
74 for (std::vector<int>::iterator it = funcParsIndex.begin(); it != funcParsIndex.end(); ++it, ++func_it) {
75 std::string name = funcParsNames.at(func_it);
76
77 if (name == "TotalEScaleFD") {
78 tot_escale_fd_pos = *it;
79 FDDetectorSystPointers[func_it] = XsecCov->retPointer(tot_escale_fd_pos);
80 }
81 else if (name == "TotalEScaleSqrtFD") {
82 tot_escale_sqrt_fd_pos = *it;
83 FDDetectorSystPointers[func_it] = XsecCov->retPointer(tot_escale_sqrt_fd_pos);
84 }
85 else if (name == "TotalEScaleInvSqrtFD") {
86 tot_escale_invsqrt_fd_pos = *it;
87 FDDetectorSystPointers[func_it] = XsecCov->retPointer(tot_escale_invsqrt_fd_pos);
88 }
89 else if (name == "HadEScaleFD") {
90 had_escale_fd_pos = *it;
91 FDDetectorSystPointers[func_it] = XsecCov->retPointer(had_escale_fd_pos);
92 }
93 else if (name == "HadEScaleSqrtFD") {
94 had_escale_sqrt_fd_pos = *it;
95 FDDetectorSystPointers[func_it] = XsecCov->retPointer(had_escale_sqrt_fd_pos);
96 }
97 else if (name == "HadEScaleInvSqrtFD") {
98 had_escale_invsqrt_fd_pos = *it;
99 FDDetectorSystPointers[func_it] = XsecCov->retPointer(had_escale_invsqrt_fd_pos);
100 }
101 else if (name == "MuEScaleFD") {
102 mu_escale_fd_pos = *it;
103 FDDetectorSystPointers[func_it] = XsecCov->retPointer(mu_escale_fd_pos);
104 }
105 else if (name == "MuEScaleSqrtFD") {
106 mu_escale_sqrt_fd_pos = *it;
107 FDDetectorSystPointers[func_it] = XsecCov->retPointer(mu_escale_sqrt_fd_pos);
108 }
109 else if (name == "MuEScaleInvSqrtFD") {
110 mu_escale_invsqrt_fd_pos = *it;
111 FDDetectorSystPointers[func_it] = XsecCov->retPointer(mu_escale_invsqrt_fd_pos);
112 }
113 else if (name == "NEScaleFD") {
114 n_escale_fd_pos = *it;
115 FDDetectorSystPointers[func_it] = XsecCov->retPointer(n_escale_fd_pos);
116 }
117 else if (name == "NEScaleSqrtFD") {
118 n_escale_sqrt_fd_pos = *it;
119 FDDetectorSystPointers[func_it] = XsecCov->retPointer(n_escale_sqrt_fd_pos);
120 }
121 else if (name == "NEScaleInvSqrtFD") {
122 n_escale_invsqrt_fd_pos = *it;
123 FDDetectorSystPointers[func_it] = XsecCov->retPointer(n_escale_invsqrt_fd_pos);
124 }
125 else if (name == "EMEScaleFD") {
126 em_escale_fd_pos = *it;
127 FDDetectorSystPointers[func_it] = XsecCov->retPointer(em_escale_fd_pos);
128 }
129 else if (name == "EMEScaleSqrtFD") {
130 em_escale_sqrt_fd_pos = *it;
131 FDDetectorSystPointers[func_it] = XsecCov->retPointer(em_escale_sqrt_fd_pos);
132 }
133 else if (name == "EMEScaleInvSqrtFD") {
134 em_escale_invsqrt_fd_pos = *it;
135 FDDetectorSystPointers[func_it] = XsecCov->retPointer(em_escale_invsqrt_fd_pos);
136 }
137 else if (name == "HadResFD") {
138 had_res_fd_pos = *it;
139 FDDetectorSystPointers[func_it] = XsecCov->retPointer(had_res_fd_pos);
140 }
141 else if (name == "MuResFD") {
142 mu_res_fd_pos = *it;
143 FDDetectorSystPointers[func_it] = XsecCov->retPointer(mu_res_fd_pos);
144 }
145 else if (name == "NResFD") {
146 n_res_fd_pos = *it;
147 FDDetectorSystPointers[func_it] = XsecCov->retPointer(n_res_fd_pos);
148 }
149 else if (name == "EMResFD") {
150 em_res_fd_pos = *it;
151 FDDetectorSystPointers[func_it] = XsecCov->retPointer(em_res_fd_pos);
152 }
153 else if (name == "CVNNumuFD") {
154 cvn_numu_fd_pos = *it;
155 FDDetectorSystPointers[func_it] = XsecCov->retPointer(cvn_numu_fd_pos);
156 }
157 else if (name == "CVNNueFD") {
158 cvn_nue_fd_pos = *it;
159 FDDetectorSystPointers[func_it] = XsecCov->retPointer(cvn_nue_fd_pos);
160 }
161
162 else {
163 std::cerr << "Found a functional parameter which wasn't specified in the xml | samplePDFDUNEBeamFD:" << name << std::endl;
164 throw;
165 }
166 }
167 */
168
169 MACH3LOG_INFO("-------------------------------------------------------------------");
170}
171
173
175 if(XsecCov->GetNumParamsFromDetID(SampleDetID, kSpline) > 0){
176 MACH3LOG_INFO("Found {} splines for this sample so I will create a spline object", XsecCov->GetNumParamsFromDetID(SampleDetID, kSpline));
177 SplineHandler = std::unique_ptr<splineFDBase>(new splinesDUNE(XsecCov));
178 InitialiseSplineObject();
179 }
180 else{
181 MACH3LOG_INFO("Found {} splines for this sample so I will not load or evaluate splines", XsecCov->GetNumParamsFromDetID(SampleDetID, kSpline));
182 SplineHandler = nullptr;
183 }
184
185 return;
186}
187
189 for (int i = 0; i < (int)dunemcSamples.size(); ++i) {
190 for (int j = 0; j < dunemcSamples[i].nEvents; ++j) {
191 MCSamples[i].ntotal_weight_pointers[j] = 6;
192 MCSamples[i].total_weight_pointers[j].resize(MCSamples[i].ntotal_weight_pointers[j]);
193 MCSamples[i].total_weight_pointers[j][0] = &(dunemcSamples[i].pot_s);
194 MCSamples[i].total_weight_pointers[j][1] = &(dunemcSamples[i].norm_s);
195 MCSamples[i].total_weight_pointers[j][2] = MCSamples[i].osc_w_pointer[j];
196 MCSamples[i].total_weight_pointers[j][3] = &(dunemcSamples[i].rw_berpaacvwgt[j]);
197 MCSamples[i].total_weight_pointers[j][4] = &(dunemcSamples[i].flux_w[j]);
198 MCSamples[i].total_weight_pointers[j][5] = &(MCSamples[i].xsec_w[j]);
199 }
200 }
201}
202
203
205
206 dunemc_base *duneobj = &(dunemcSamples[iSample]);
207 int nupdgUnosc = sample_nupdgunosc[iSample];
208 int nupdg = sample_nupdg[iSample];
209
210 MACH3LOG_INFO("-------------------------------------------------------------------");
211 MACH3LOG_INFO("input file: {}", mc_files[iSample]);
212
213 _sampleFile = TFile::Open(mc_files[iSample].c_str(), "READ");
214 _data = (TTree*)_sampleFile->Get("caf");
215
216 if(_data){
217 MACH3LOG_INFO("Found \"caf\" tree in {}", mc_files[iSample]);
218 MACH3LOG_INFO("With number of entries: {}", _data->GetEntries());
219 }
220 else{
221 MACH3LOG_ERROR("Could not find \"caf\" tree in {}", mc_files[iSample]);
222 throw MaCh3Exception(__FILE__, __LINE__);
223 }
224
225 _data->SetBranchStatus("*", 0);
226 _data->SetBranchStatus("Ev", 1);
227 _data->SetBranchAddress("Ev", &_ev);
228 _data->SetBranchStatus("Ev_reco_numu", 1);
229 _data->SetBranchAddress("Ev_reco_numu", &_erec);
230 _data->SetBranchStatus("Ev_reco_nue", 1);
231 _data->SetBranchAddress("Ev_reco_nue", &_erec_nue);
232 _data->SetBranchStatus("RecoHadEnNumu", 1);
233 _data->SetBranchAddress("RecoHadEnNumu", &_erec_had);
234 _data->SetBranchStatus("RecoHadEnNue", 1);
235 _data->SetBranchAddress("RecoHadEnNue", &_erec_had_nue);
236 _data->SetBranchStatus("RecoLepEnNumu", 1);
237 _data->SetBranchAddress("RecoLepEnNumu", &_erec_lep);
238 _data->SetBranchStatus("RecoLepEnNue", 1);
239 _data->SetBranchAddress("RecoLepEnNue", &_erec_lep_nue);
240
241 _data->SetBranchStatus("eRecoP", 1);
242 _data->SetBranchAddress("eRecoP", &_eRecoP);
243 _data->SetBranchStatus("eRecoPip", 1);
244 _data->SetBranchAddress("eRecoPip", &_eRecoPip);
245 _data->SetBranchStatus("eRecoPim", 1);
246 _data->SetBranchAddress("eRecoPim", &_eRecoPim);
247 _data->SetBranchStatus("eRecoPi0", 1);
248 _data->SetBranchAddress("eRecoPi0", &_eRecoPi0);
249 _data->SetBranchStatus("eRecoN", 1);
250 _data->SetBranchAddress("eRecoN", &_eRecoN);
251
252 _data->SetBranchStatus("LepE", 1);
253 _data->SetBranchAddress("LepE", &_LepE);
254 _data->SetBranchStatus("eP", 1);
255 _data->SetBranchAddress("eP", &_eP);
256 _data->SetBranchStatus("ePip", 1);
257 _data->SetBranchAddress("ePip", &_ePip);
258 _data->SetBranchStatus("ePim", 1);
259 _data->SetBranchAddress("ePim", &_ePim);
260 _data->SetBranchStatus("ePi0", 1);
261 _data->SetBranchAddress("ePi0", &_ePi0);
262 _data->SetBranchStatus("eN", 1);
263 _data->SetBranchAddress("eN", &_eN);
264
265 _data->SetBranchStatus("mode",1);
266 _data->SetBranchAddress("mode",&_mode);
267 _data->SetBranchStatus("cvnnumu",1);
268 _data->SetBranchAddress("cvnnumu", &_cvnnumu);
269 _data->SetBranchStatus("cvnnue",1);
270 _data->SetBranchAddress("cvnnue", &_cvnnue);
271 _data->SetBranchStatus("isCC", 1);
272 _data->SetBranchAddress("isCC", &_isCC);
273 _data->SetBranchStatus("nuPDGunosc", 1);
274 _data->SetBranchAddress("nuPDGunosc", &_nuPDGunosc);
275 _data->SetBranchStatus("nuPDG", 1);
276 _data->SetBranchAddress("nuPDG", &_nuPDG);
277 _data->SetBranchStatus("BeRPA_A_cvwgt", 1);
278 _data->SetBranchAddress("BeRPA_A_cvwgt", &_BeRPA_cvwgt);
279 _data->SetBranchStatus("vtx_x", 1);
280 _data->SetBranchAddress("vtx_x", &_vtx_x);
281 _data->SetBranchStatus("vtx_y", 1);
282 _data->SetBranchAddress("vtx_y", &_vtx_y);
283 _data->SetBranchStatus("vtx_z", 1);
284 _data->SetBranchAddress("vtx_z", &_vtx_z);
285
286 TH1D* norm = (TH1D*)_sampleFile->Get("norm");
287 if(!norm){
288 MACH3LOG_ERROR("Add a norm KEY to the root file using MakeNormHists.cxx");
289 throw MaCh3Exception(__FILE__, __LINE__);
290 }
291
292 // now fill the actual variables
293 duneobj->norm_s = norm->GetBinContent(1);
294 duneobj->pot_s = pot/norm->GetBinContent(2);
295
296 duneobj->nEvents = _data->GetEntries();
297
298 // allocate memory for dunemc variables
299 duneobj->rw_cvnnumu = new double[duneobj->nEvents];
300 duneobj->rw_cvnnue = new double[duneobj->nEvents];
301 duneobj->rw_cvnnumu_shifted = new double[duneobj->nEvents];
302 duneobj->rw_cvnnue_shifted = new double[duneobj->nEvents];
303 duneobj->rw_etru = new double[duneobj->nEvents];
304 duneobj->rw_erec = new double[duneobj->nEvents];
305 duneobj->rw_erec_shifted = new double[duneobj->nEvents];
306 duneobj->rw_erec_had = new double[duneobj->nEvents];
307 duneobj->rw_erec_lep = new double[duneobj->nEvents];
308
309 duneobj->rw_eRecoP = new double[duneobj->nEvents];
310 duneobj->rw_eRecoPip = new double[duneobj->nEvents];
311 duneobj->rw_eRecoPim = new double[duneobj->nEvents];
312 duneobj->rw_eRecoPi0 = new double[duneobj->nEvents];
313 duneobj->rw_eRecoN = new double[duneobj->nEvents];
314
315 duneobj->rw_LepE = new double[duneobj->nEvents];
316 duneobj->rw_eP = new double[duneobj->nEvents];
317 duneobj->rw_ePip = new double[duneobj->nEvents];
318 duneobj->rw_ePim = new double[duneobj->nEvents];
319 duneobj->rw_ePi0 = new double[duneobj->nEvents];
320 duneobj->rw_eN = new double[duneobj->nEvents];
321
322 duneobj->rw_theta = new double[duneobj->nEvents];
323 duneobj->flux_w = new double[duneobj->nEvents];
324 duneobj->rw_isCC = new int[duneobj->nEvents];
325 duneobj->rw_nuPDGunosc = new int[duneobj->nEvents];
326 duneobj->rw_nuPDG = new int[duneobj->nEvents];
327 duneobj->rw_berpaacvwgt = new double[duneobj->nEvents];
328 duneobj->rw_vtx_x = new double[duneobj->nEvents];
329 duneobj->rw_vtx_y = new double[duneobj->nEvents];
330 duneobj->rw_vtx_z = new double[duneobj->nEvents];
331
332 duneobj->nupdgUnosc = new int[duneobj->nEvents];
333 duneobj->nupdg = new int[duneobj->nEvents];
334 duneobj->mode = new double[duneobj->nEvents];
335 duneobj->Target = new int[duneobj->nEvents];
336
337 _data->GetEntry(0);
338
339 //FILL DUNE STRUCT
340 for (int i = 0; i < duneobj->nEvents; ++i) { // Loop through tree
341 _data->GetEntry(i);
342
343 duneobj->nupdg[i] = sample_nupdg[iSample];
344 duneobj->nupdgUnosc[i] = sample_nupdgunosc[iSample];
345
346 duneobj->rw_cvnnumu[i] = (double)_cvnnumu;
347 duneobj->rw_cvnnue[i] = (double)_cvnnue;
348 duneobj->rw_cvnnumu_shifted[i] = (double)_cvnnumu;
349 duneobj->rw_cvnnue_shifted[i] = (double)_cvnnue;
350 if (iselike) {
351 duneobj->rw_erec[i] = (double)_erec_nue;
352 duneobj->rw_erec_shifted[i] = (double)_erec_nue;
353 duneobj->rw_erec_had[i] = (double)_erec_had_nue;
354 duneobj->rw_erec_lep[i] = (double)_erec_lep_nue;
355 } else {
356 duneobj->rw_erec[i] = (double)_erec;
357 duneobj->rw_erec_shifted[i] = (double)_erec;
358 duneobj->rw_erec_had[i] = (double)_erec_had;
359 duneobj->rw_erec_lep[i] = (double)_erec_lep;
360 }
361
362 duneobj->rw_eRecoP[i] = (double)_eRecoP;
363 duneobj->rw_eRecoPip[i] = (double)_eRecoPip;
364 duneobj->rw_eRecoPim[i] = (double)_eRecoPim;
365 duneobj->rw_eRecoPi0[i] = (double)_eRecoPi0;
366 duneobj->rw_eRecoN[i] = (double)_eRecoN;
367
368 duneobj->rw_LepE[i] = (double)_LepE;
369 duneobj->rw_eP[i] = (double)_eP;
370 duneobj->rw_ePip[i] = (double)_ePip;
371 duneobj->rw_ePim[i] = (double)_ePim;
372 duneobj->rw_ePi0[i] = (double)_ePi0;
373 duneobj->rw_eN[i] = (double)_eN;
374
375 duneobj->rw_etru[i] = (double)_ev;
376 duneobj->rw_theta[i] = (double)_LepNuAngle;
377 duneobj->rw_isCC[i] = _isCC;
378 duneobj->rw_nuPDGunosc[i] = _nuPDGunosc;
379 duneobj->rw_nuPDG[i] = _nuPDG;
380 duneobj->rw_berpaacvwgt[i] = (double)_BeRPA_cvwgt;
381 duneobj->rw_vtx_x[i] = (double)_vtx_x;
382 duneobj->rw_vtx_y[i] = (double)_vtx_y;
383 duneobj->rw_vtx_z[i] = (double)_vtx_z;
384
385 //Assume everything is on Argon for now....
386 duneobj->Target[i] = 40;
387
388 int mode= TMath::Abs(_mode);
389 duneobj->mode[i]=(double)SIMBMode_ToMaCh3Mode(mode, _isCC);
390
391 duneobj->flux_w[i] = 1.0;
392 }
393
394 _sampleFile->Close();
395 return duneobj->nEvents;
396}
397
398TH1D* samplePDFDUNEBeamFD::get1DVarHist(KinematicTypes Var1, int kModeToFill, int kChannelToFill, int WeightStyle, TAxis* Axis) {
399 bool fChannel;
400 bool fMode;
401
402 if (kChannelToFill!=-1) {
403 if (kChannelToFill>dunemcSamples.size()) {
404 MACH3LOG_ERROR("Required channel is not available. kChannelToFill should be between 0 and {}",dunemcSamples.size());
405 MACH3LOG_ERROR("kChannelToFill given: {}",kChannelToFill);
406 throw MaCh3Exception(__FILE__, __LINE__);
407 }
408 fChannel = true;
409 } else {
410 fChannel = false;
411 }
412
413 if (kModeToFill!=-1) {
414 if (kModeToFill>kMaCh3_nModes) {
415 MACH3LOG_ERROR("Required mode is not available. kModeToFill should be between 0 and {}",kMaCh3_nModes);
416 MACH3LOG_ERROR("kModeToFill given: {}",kModeToFill);
417 throw MaCh3Exception(__FILE__, __LINE__);
418 }
419 fMode = true;
420 } else {
421 fMode = false;
422 }
423
424 std::vector< std::vector<double> > SelectionVec;
425
426 if (fMode) {
427 std::vector<double> SelecMode(3);
428 SelecMode[0] = kM3Mode;
429 SelecMode[1] = kModeToFill;
430 SelecMode[2] = kModeToFill+1;
431 SelectionVec.push_back(SelecMode);
432 }
433
434 if (fChannel) {
435 std::vector<double> SelecChannel(3);
436 SelecChannel[0] = kOscChannel;
437 SelecChannel[1] = kChannelToFill;
438 SelecChannel[2] = kChannelToFill+1;
439 SelectionVec.push_back(SelecChannel);
440 }
441
442 return get1DVarHist(Var1,SelectionVec,WeightStyle,Axis);
443}
444
449TH1D* samplePDFDUNEBeamFD::get1DVarHist(KinematicTypes Var1,std::vector< std::vector<double> > SelectionVec, int WeightStyle, TAxis* Axis) {
450
451 Selection = SelectionVec;
452
453 for (unsigned int iStoredSelection=0;iStoredSelection<StoredSelection.size();iStoredSelection++) {
454 Selection.push_back(StoredSelection[iStoredSelection]);
455 }
456
457 for (unsigned int iSelection=0;iSelection<Selection.size();iSelection++) {
458 if (Selection[iSelection].size()!=3) {
459 MACH3LOG_ERROR("Selection Vector[{}] is not formed correctly. Expect size == 3, given: {}",iSelection,Selection[iSelection].size());
460 throw MaCh3Exception(__FILE__, __LINE__);
461 }
462 }
463
464 //DB Cut on OscChannel in this function due to speed increase from considering duneSamples structure (ie. Array of length NChannels)
465 bool fChannel = false;
466 int kChannelToFill = -1;
467 for (unsigned int iSelection=0;iSelection<Selection.size();iSelection++) {
468 if (Selection[iSelection][0] == kOscChannel) {
469 fChannel = true;
470 kChannelToFill = Selection[iSelection][1];
471 }
472 }
473
474 if (fChannel && kChannelToFill>dunemcSamples.size()) {
475 MACH3LOG_ERROR("Required channel is not available. kChannelToFill should be between 0 and {}",dunemcSamples.size());
476 MACH3LOG_ERROR("kChannelToFill given: {}",kChannelToFill);
477 throw MaCh3Exception(__FILE__, __LINE__);
478 }
479
480 TH1D* _h1DVar;
481 std::vector<double> xBinEdges = ReturnKinematicParameterBinning(ReturnStringFromKinematicParameter(Var1));
482 _h1DVar = new TH1D("", "", xBinEdges.size()-1, xBinEdges.data());
483
484 //This should be the same as FillArray in core basically, except that
485 //events will end up in different bins
486 for (int i=0;i<dunemcSamples.size();i++) {
487 if (fChannel && (i!=kChannelToFill)) {
488 continue;
489 }
490 for(int j=0;j<dunemcSamples[i].nEvents;j++) {
491
492 //DB Determine which events pass selection
493 if (!IsEventSelected(i,j)) {
494 continue;
495 }
496
497 double Weight = GetEventWeight(i,j);
498 if (WeightStyle==1) {
499 Weight = *(MCSamples[i].osc_w_pointer[j]) * dunemcSamples[i].pot_s * dunemcSamples[i].norm_s * dunemcSamples[i].flux_w[j];
500 }
501
502 //ETA - not sure about this
503 if (MCSamples[i].xsec_w[j] == 0.) continue;
504
505 double Var1_Val;
506
507 Var1_Val = ReturnKinematicParameter(Var1,i,j);
508 if (Var1_Val!=_DEFAULT_RETURN_VAL_) {
509 _h1DVar->Fill(Var1_Val,Weight);
510 }
511 }
512 }
513
514 /* DB: This is commented out be default
515 // This code shifts the histogram meaning to Events/Bin Width but this affects the overall integral of the histogram so it should not be used anywhere we care about event rates
516 // We could use Hist->Integral("width") but it would require a lot of modification throughout the code
517
518 if (Var1!=kPDFBinning) {
519 //_h1DVar->SetBinContent(1,_h1DVar->GetBinContent(0)+_h1DVar->GetBinContent(1));
520 //_h1DVar->SetBinContent(_h1DVar->GetNbinsX(),_h1DVar->GetBinContent(_h1DVar->GetNbinsX())+_h1DVar->GetBinContent(_h1DVar->GetNbinsX()+1));
521
522 for (int x=1;x<=_h1DVar->GetNbinsX();x++) {
523 _h1DVar->SetBinContent(x,_h1DVar->GetBinContent(x)/_h1DVar->GetXaxis()->GetBinWidth(x));
524 }
525
526 _h1DVar->GetYaxis()->SetTitle("Events/Bin Width");
527 }
528 */
529
530 return _h1DVar;
531}
532
533double samplePDFDUNEBeamFD::ReturnKinematicParameter(double KinematicVariable, int iSample, int iEvent) {
534 KinematicTypes KinPar = (KinematicTypes) std::round(KinematicVariable);
535 double KinematicValue = -999;
536
537 switch(KinPar){
539 KinematicValue = dunemcSamples[iSample].rw_etru[iEvent];
540 break;
542 KinematicValue = dunemcSamples[iSample].rw_erec_shifted[iEvent];
543 break;
544 case kTrueXPos:
545 KinematicValue = dunemcSamples[iSample].rw_vtx_x[iEvent];
546 break;
547 case kTrueYPos:
548 KinematicValue = dunemcSamples[iSample].rw_vtx_y[iEvent];
549 break;
550 case kTrueZPos:
551 KinematicValue = dunemcSamples[iSample].rw_vtx_z[iEvent];
552 break;
553 case kCVNNumu:
554 KinematicValue = dunemcSamples[iSample].rw_cvnnumu_shifted[iEvent];
555 break;
556 case kCVNNue:
557 KinematicValue = dunemcSamples[iSample].rw_cvnnue_shifted[iEvent];
558 break;
559 case kM3Mode:
560 KinematicValue = dunemcSamples[iSample].mode[iEvent];
561 break;
562 case kIsFHC:
563 KinematicValue = _isFHC;
564 break;
565 default:
566 MACH3LOG_ERROR("Did not recognise Kinematic Parameter type");
567 MACH3LOG_ERROR("Was given a Kinematic Variable of {}", KinematicVariable);
568 throw MaCh3Exception(__FILE__, __LINE__);
569 }
570
571 return KinematicValue;
572}
573
574double samplePDFDUNEBeamFD::ReturnKinematicParameter(std::string KinematicParameter, int iSample, int iEvent) {
575 KinematicTypes KinPar = static_cast<KinematicTypes>(ReturnKinematicParameterFromString(KinematicParameter));
576 double KinematicValue = -999;
577
578 switch(KinPar){
580 KinematicValue = dunemcSamples[iSample].rw_etru[iEvent];
581 break;
583 KinematicValue = dunemcSamples[iSample].rw_erec_shifted[iEvent];
584 break;
585 case kTrueXPos:
586 KinematicValue = dunemcSamples[iSample].rw_vtx_x[iEvent];
587 break;
588 case kTrueYPos:
589 KinematicValue = dunemcSamples[iSample].rw_vtx_y[iEvent];
590 break;
591 case kTrueZPos:
592 KinematicValue = dunemcSamples[iSample].rw_vtx_z[iEvent];
593 break;
594 case kCVNNumu:
595 KinematicValue = dunemcSamples[iSample].rw_cvnnumu_shifted[iEvent];
596 break;
597 case kCVNNue:
598 KinematicValue = dunemcSamples[iSample].rw_cvnnue_shifted[iEvent];
599 break;
600 case kIsFHC:
601 KinematicValue = _isFHC;
602 break;
603 default:
604 MACH3LOG_ERROR("Did not recognise Kinematic Parameter type... {}", KinematicParameter);
605 throw MaCh3Exception(__FILE__, __LINE__);
606 }
607
608 return KinematicValue;
609}
610
611
612const double* samplePDFDUNEBeamFD::GetPointerToKinematicParameter(std::string KinematicParameter, int iSample, int iEvent) {
613 KinematicTypes KinPar = static_cast<KinematicTypes>(ReturnKinematicParameterFromString(KinematicParameter));
614 double* KinematicValue = nullptr;
615
616 switch(KinPar){
618 KinematicValue = &dunemcSamples[iSample].rw_etru[iEvent];
619 break;
621 KinematicValue = &dunemcSamples[iSample].rw_erec_shifted[iEvent];
622 break;
623 case kTrueXPos:
624 KinematicValue = &dunemcSamples[iSample].rw_vtx_x[iEvent];
625 break;
626 case kTrueYPos:
627 KinematicValue = &dunemcSamples[iSample].rw_vtx_y[iEvent];
628 break;
629 case kTrueZPos:
630 KinematicValue = &dunemcSamples[iSample].rw_vtx_z[iEvent];
631 break;
632 case kCVNNumu:
633 KinematicValue = &dunemcSamples[iSample].rw_cvnnumu_shifted[iEvent];
634 break;
635 case kCVNNue:
636 KinematicValue = &dunemcSamples[iSample].rw_cvnnue_shifted[iEvent];
637 break;
638 default:
639 MACH3LOG_ERROR("Did not recognise Kinematic Parameter type...");
640 throw MaCh3Exception(__FILE__, __LINE__);
641 }
642
643 return KinematicValue;
644}
645
646int samplePDFDUNEBeamFD::ReturnKinematicParameterFromString(std::string KinematicParameterStr){
647 if (KinematicParameterStr.find("TrueNeutrinoEnergy") != std::string::npos) {return kTrueNeutrinoEnergy;}
648 if (KinematicParameterStr.find("RecoNeutrinoEnergy") != std::string::npos) {return kRecoNeutrinoEnergy;}
649 if (KinematicParameterStr.find("TrueXPos") != std::string::npos) {return kTrueXPos;}
650 if (KinematicParameterStr.find("TrueYPos") != std::string::npos) {return kTrueYPos;}
651 if (KinematicParameterStr.find("TrueZPos") != std::string::npos) {return kTrueZPos;}
652 if (KinematicParameterStr.find("CVNNumu") != std::string::npos) {return kCVNNumu;}
653 if (KinematicParameterStr.find("CVNNue") != std::string::npos) {return kCVNNue;}
654 if (KinematicParameterStr.find("M3Mode") != std::string::npos) {return kM3Mode;}
655 if (KinematicParameterStr.find("IsFHC") != std::string::npos) {return kIsFHC;}
656}
657
658const double* samplePDFDUNEBeamFD::GetPointerToKinematicParameter(double KinematicVariable, int iSample, int iEvent) {
659 KinematicTypes KinPar = (KinematicTypes) std::round(KinematicVariable);
660 double* KinematicValue = nullptr;
661
662 switch(KinPar){
664 KinematicValue = &dunemcSamples[iSample].rw_etru[iEvent];
665 break;
667 KinematicValue = &dunemcSamples[iSample].rw_erec_shifted[iEvent];
668 break;
669 case kTrueXPos:
670 KinematicValue = &dunemcSamples[iSample].rw_vtx_x[iEvent];
671 break;
672 case kTrueYPos:
673 KinematicValue = &dunemcSamples[iSample].rw_vtx_y[iEvent];
674 break;
675 case kTrueZPos:
676 KinematicValue = &dunemcSamples[iSample].rw_vtx_z[iEvent];
677 break;
678 case kCVNNumu:
679 KinematicValue = &dunemcSamples[iSample].rw_cvnnumu_shifted[iEvent];
680 break;
681 case kCVNNue:
682 KinematicValue = &dunemcSamples[iSample].rw_cvnnue_shifted[iEvent];
683 break;
684 default:
685 MACH3LOG_ERROR("Did not recognise Kinematic Parameter type...");
686 throw MaCh3Exception(__FILE__, __LINE__);
687 }
688
689 return KinematicValue;
690}
691
692inline std::string samplePDFDUNEBeamFD::ReturnStringFromKinematicParameter(int KinematicParameter) {
693 std::string KinematicString = "";
694
695 switch(KinematicParameter){
697 KinematicString = "RecoNeutrinoEnergy";
698 break;
700 KinematicString = "RecoNeutrinoEnergy";
701 break;
702 case kTrueXPos:
703 KinematicString= "TrueXPos";
704 break;
705 case kTrueYPos:
706 KinematicString= "TrueYPos";
707 break;
708 case kTrueZPos:
709 KinematicString= "TrueZPos";
710 break;
711 case kCVNNumu:
712 KinematicString = "CVNNumu";
713 break;
714 case kCVNNue:
715 KinematicString = "CVNNue";
716 break;
717 case kM3Mode:
718 KinematicString = "M3Mode";
719 break;
720 default:
721 break;
722 }
723
724 return KinematicString;
725}
726
728 dunemc_base *duneobj = &(dunemcSamples[iSample]);
729 FarDetectorCoreInfo *fdobj = &(MCSamples[iSample]);
730
731 for(int iEvent = 0 ;iEvent < fdobj->nEvents ; ++iEvent) {
732 fdobj->rw_etru[iEvent] = &(duneobj->rw_etru[iEvent]);
733 fdobj->mode[iEvent] = &(duneobj->mode[iEvent]);
734 fdobj->Target[iEvent] = &(duneobj->Target[iEvent]);
735 fdobj->isNC[iEvent] = !(duneobj->rw_isCC[iEvent]);
736 fdobj->nupdg[iEvent] = &(duneobj->nupdg[iEvent]);
737 fdobj->nupdgUnosc[iEvent] = &(duneobj->nupdgUnosc[iEvent]);
738 }
739
740}
741
742void samplePDFDUNEBeamFD::applyShifts(int iSample, int iEvent) {
743
744 //ETA - this is pretty horrific... we need to think of a nicer way to do this.
745 //Don't want to add in hard checks on which systematics are defined but also don't want to hard-code
746 //the order in which the systematics are specified. All of these functions should have access to the
747 //dunemc struct so they only need to have iSample and iEvent passed to them. Can probably loop over
748 //a vector of std::function objects and pass each of them iSample and iEvent.
749 /*
750 // reset erec back to original value
751 dunemcSamples[iSample].rw_erec_shifted[iEvent] = dunemcSamples[iSample].rw_erec[iEvent];
752
753 // reset cvnnumu back to original value
754 dunemcSamples[iSample].rw_cvnnumu_shifted[iEvent] = dunemcSamples[iSample].rw_cvnnumu[iEvent];
755
756 // reset cvnnue back to original value
757 dunemcSamples[iSample].rw_cvnnue_shifted[iEvent] = dunemcSamples[iSample].rw_cvnnue[iEvent];
758
759 //Calculate values needed
760 double sqrtErecHad = sqrt(dunemcSamples[iSample].rw_erec_had[iEvent]);
761 double sqrtErecLep = sqrt(dunemcSamples[iSample].rw_erec_lep[iEvent]);
762 double sqrteRecoPi0 = sqrt(dunemcSamples[iSample].rw_eRecoPi0[iEvent]);
763 double sqrteRecoN = sqrt(dunemcSamples[iSample].rw_eRecoN[iEvent]);
764 double sumEhad = dunemcSamples[iSample].rw_eRecoP[iEvent] + dunemcSamples[iSample].rw_eRecoPip[iEvent] + dunemcSamples[iSample].rw_eRecoPim[iEvent];
765 double sqrtSumEhad = sqrt(sumEhad);
766
767 double invSqrtErecHad = 1/(sqrtErecHad+0.1);
768 double invSqrtErecLep = 1/(sqrtErecLep+0.1);
769 double invSqrteRecoPi0 = 1/(sqrteRecoPi0+0.1);
770 double invSqrteRecoN = 1/(sqrteRecoN+0.1);
771 double invSqrtSumEhad = 1/(sqrtSumEhad+0.1);
772
773 bool CCnumu {dunemcSamples[iSample].rw_isCC[iEvent]==1 && abs(dunemcSamples[iSample].rw_nuPDG[iEvent]==14) && dunemcSamples[iSample].nupdgUnosc==2};
774 bool CCnue {dunemcSamples[iSample].rw_isCC[iEvent]==1 && abs(dunemcSamples[iSample].rw_nuPDG[iEvent]==12) && dunemcSamples[iSample].nupdgUnosc==1};
775 bool NotCCnumu {!(dunemcSamples[iSample].rw_isCC[iEvent]==1 && abs(dunemcSamples[iSample].rw_nuPDG[iEvent]==14)) && dunemcSamples[iSample].nupdgUnosc==2};
776
777
778 TotalEScaleFD(FDDetectorSystPointers[0], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_erec_had[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], NotCCnumu);
779
780 TotalEScaleSqrtFD(FDDetectorSystPointers[1], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_erec_had[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], sqrtErecHad, sqrtErecLep, NotCCnumu);
781
782 TotalEScaleInvSqrtFD(FDDetectorSystPointers[2], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_erec_had[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], invSqrtErecHad, invSqrtErecLep, NotCCnumu);
783
784 HadEScaleFD(FDDetectorSystPointers[3], &dunemcSamples[iSample].rw_erec_shifted[iEvent], sumEhad);
785
786 HadEScaleSqrtFD(FDDetectorSystPointers[4], &dunemcSamples[iSample].rw_erec_shifted[iEvent], sumEhad, sqrtSumEhad);
787
788 HadEScaleInvSqrtFD(FDDetectorSystPointers[5], &dunemcSamples[iSample].rw_erec_shifted[iEvent], sumEhad, invSqrtSumEhad);
789
790 MuEScaleFD(FDDetectorSystPointers[6], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], CCnumu);
791
792 MuEScaleSqrtFD(FDDetectorSystPointers[7], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], sqrtErecLep, CCnumu);
793
794 MuEScaleInvSqrtFD(FDDetectorSystPointers[8], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], invSqrtErecLep, CCnumu);
795
796 NEScaleFD(FDDetectorSystPointers[9], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_eRecoN[iEvent]);
797
798 NEScaleSqrtFD(FDDetectorSystPointers[10], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_eRecoN[iEvent], sqrteRecoN);
799
800 NEScaleInvSqrtFD(FDDetectorSystPointers[11], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_eRecoN[iEvent], invSqrteRecoN);
801
802 EMEScaleFD(FDDetectorSystPointers[12], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_eRecoPi0[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], CCnue);
803
804 EMEScaleSqrtFD(FDDetectorSystPointers[13], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_eRecoPi0[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], sqrtErecLep, sqrteRecoPi0, CCnue);
805
806 EMEScaleInvSqrtFD(FDDetectorSystPointers[14], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_eRecoPi0[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], invSqrtErecLep, invSqrteRecoPi0, CCnue);
807
808 HadResFD(FDDetectorSystPointers[15], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_eRecoP[iEvent], dunemcSamples[iSample].rw_eRecoPip[iEvent], dunemcSamples[iSample].rw_eRecoPim[iEvent], dunemcSamples[iSample].rw_eP[iEvent], dunemcSamples[iSample].rw_ePip[iEvent], dunemcSamples[iSample].rw_ePim[iEvent]);
809
810 MuResFD(FDDetectorSystPointers[16], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], dunemcSamples[iSample].rw_LepE[iEvent], CCnumu);
811
812 NResFD(FDDetectorSystPointers[17], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_eRecoN[iEvent], dunemcSamples[iSample].rw_eN[iEvent]);
813
814 EMResFD(FDDetectorSystPointers[18], &dunemcSamples[iSample].rw_erec_shifted[iEvent], dunemcSamples[iSample].rw_eRecoPi0[iEvent], dunemcSamples[iSample].rw_ePi0[iEvent], dunemcSamples[iSample].rw_erec_lep[iEvent], dunemcSamples[iSample].rw_LepE[iEvent], CCnue);
815
816 CVNNumuFD(FDDetectorSystPointers[19], &dunemcSamples[iSample].rw_cvnnumu_shifted[iEvent]);
817
818 CVNNueFD(FDDetectorSystPointers[20], &dunemcSamples[iSample].rw_cvnnue_shifted[iEvent]);
819 */
820}
821
822std::vector<double> samplePDFDUNEBeamFD::ReturnKinematicParameterBinning(std::string KinematicParameterStr) {
823 std::vector<double> binningVector;
824 KinematicTypes KinematicParameter = static_cast<KinematicTypes>(ReturnKinematicParameterFromString(KinematicParameterStr));
825
826 int nBins = 0;
827 double bin_width = 0;
828 switch(KinematicParameter){
830 nBins = 20;
831 bin_width = 0.5; //GeV
832 break;
834 nBins = 20;
835 bin_width = 0.5; //GeV
836 break;
837 default:
838 nBins = 10;
839 bin_width = 1.0;
840 break;
841 }
842
843 for(int bin_i = 0 ; bin_i < nBins ; bin_i++){
844 binningVector.push_back(bin_i*bin_width);
845 }
846
847 return binningVector;
848}
@ kMaCh3_nModes
int SIMBMode_ToMaCh3Mode(int SIMB_mode, int isCC)
void SetupSplines()
Setup our spline file, this calls InitialseSplineObject() under the hood.
void applyShifts(int iSample, int iEvent)
Apply kinematic shifts.
TFile * _sampleFile
File containing sample objects.
samplePDFDUNEBeamFD(std::string mc_version, covarianceXsec *xsec_cov, covarianceOsc *osc_cov)
samplePDFDUNE FD beam Constructor
std::vector< struct dunemc_base > dunemcSamples
DUNE MC sampels.
std::string ReturnStringFromKinematicParameter(int KinematicParameterStr)
TTree * _data
TTree containing sample Data.
TH1D * get1DVarHist(KinematicTypes Var1, int fModeToFill=-1, int fSampleToFill=-1, int WeightStyle=0, TAxis *Axis=0)
Getter to make plots in different variables, mode, osc channel, systematic weighting and with bin ran...
const double * GetPointerToKinematicParameter(std::string KinematicParameter, int iSample, int iEvent)
Returns pointer to kinemtatic parameter for event in Structs DUNE.
int ReturnKinematicParameterFromString(std::string KinematicParameterStr)
void SetupWeightPointers()
Sets up pointers weights for each event (oscillation/xsec/etc.)
double pot
Value of POT used for sample.
int setupExperimentMC(int iSample)
Function to setup MC from file.
void setupFDMC(int iSample)
Tells FD base which variables to point to/be set to.
double ReturnKinematicParameter(double KinematicVariable, int iSample, int iEvent)
Returns pointer to kinemtatic parameter for event in Structs DUNE.
void Init()
Initialises object.
std::vector< double > ReturnKinematicParameterBinning(std::string KinematicParameter)
Specialisation of FD (binned) spline class.
Definition splinesDUNE.h:8
double * rw_eRecoP
Definition StructsDUNE.h:22
double * rw_erec_had
Definition StructsDUNE.h:19
double * rw_eRecoPim
Definition StructsDUNE.h:24
int * nupdgUnosc
Definition StructsDUNE.h:15
double * rw_cvnnue_shifted
Definition StructsDUNE.h:43
double * rw_erec_lep
Definition StructsDUNE.h:20
double * rw_vtx_x
Definition StructsDUNE.h:52
double * rw_vtx_y
Definition StructsDUNE.h:53
double * rw_cvnnumu_shifted
Definition StructsDUNE.h:42
double * mode
Definition StructsDUNE.h:65
double * rw_berpaacvwgt
Definition StructsDUNE.h:46
double * rw_erec_shifted
Definition StructsDUNE.h:18
double * rw_ePip
Definition StructsDUNE.h:30
double pot_s
Definition StructsDUNE.h:59
double * rw_erec
Definition StructsDUNE.h:17
int * rw_isCC
Definition StructsDUNE.h:47
double * rw_eP
Definition StructsDUNE.h:29
double * rw_ePim
Definition StructsDUNE.h:31
double * flux_w
Definition StructsDUNE.h:63
double * rw_eRecoN
Definition StructsDUNE.h:26
double * rw_eN
Definition StructsDUNE.h:33
double * rw_cvnnumu
Definition StructsDUNE.h:40
double * rw_etru
Definition StructsDUNE.h:35
int * rw_nuPDGunosc
Definition StructsDUNE.h:48
double * rw_theta
Definition StructsDUNE.h:37
double * rw_eRecoPi0
Definition StructsDUNE.h:25
double * rw_cvnnue
Definition StructsDUNE.h:41
double norm_s
Definition StructsDUNE.h:60
double * rw_eRecoPip
Definition StructsDUNE.h:23
double * rw_LepE
Definition StructsDUNE.h:28
double * rw_vtx_z
Definition StructsDUNE.h:54
int * rw_nuPDG
Definition StructsDUNE.h:49
double * rw_ePi0
Definition StructsDUNE.h:32