MaCh3 DUNE 1.0.0
Reference Guide
Loading...
Searching...
No Matches
samplePDFDUNEAtm.cpp
Go to the documentation of this file.
1#include "samplePDFDUNEAtm.h"
2
3//Standard Record includes
4#include "duneanaobj/StandardRecord/StandardRecord.h"
5
6//ROOT includes
7#include "TError.h"
8
9//
10#include <assert.h>
11#include <manager/MaCh3Exception.h>
12#include <manager/MaCh3Logger.h>
13#include <manager/YamlHelper.h>
14
15samplePDFDUNEAtm::samplePDFDUNEAtm(std::string mc_version_, covarianceXsec* xsec_cov_, covarianceOsc* osc_cov_) : samplePDFFDBase(mc_version_, xsec_cov_, osc_cov_) {
16 Initialise();
17}
18
21
23 dunemcSamples.resize(nSamples,dunemc_base());
24
25 IsELike = SampleManager->raw()["SampleBools"]["IsELike"].as<bool>();
26}
27
29 SplineHandler = nullptr;
30}
31
33 for (int i = 0; i < (int)dunemcSamples.size(); ++i) {
34 for (int j = 0; j < dunemcSamples[i].nEvents; ++j) {
35 MCSamples[i].ntotal_weight_pointers[j] = 3;
36 MCSamples[i].total_weight_pointers[j].resize(MCSamples[i].ntotal_weight_pointers[j]);
37 MCSamples[i].total_weight_pointers[j][0] = &(dunemcSamples[i].flux_w[j]);
38 MCSamples[i].total_weight_pointers[j][1] = MCSamples[i].osc_w_pointer[j];
39 MCSamples[i].total_weight_pointers[j][2] = &(MCSamples[i].xsec_w[j]);
40 }
41 }
42}
43
45 int CurrErrorLevel = gErrorIgnoreLevel;
46 gErrorIgnoreLevel = kFatal;
47
48 caf::StandardRecord* sr = new caf::StandardRecord();
49 dunemc_base* duneobj = &dunemcSamples[iSample];
50
51 std::string FileName = mc_files[iSample];
52 MACH3LOG_INFO("Reading File: {}",FileName);
53 TFile* File = TFile::Open(FileName.c_str());
54 if (!File || File->IsZombie()) {
55 MACH3LOG_ERROR("Did not find File: {}",FileName);
56 throw MaCh3Exception(__FILE__, __LINE__);
57 }
58 TTree* Tree = File->Get<TTree>("cafTree");
59 if (!Tree){
60 MACH3LOG_ERROR("Did not find Tree::cafTree in File: {}",FileName);
61 throw MaCh3Exception(__FILE__, __LINE__);
62 }
63
64 Tree->SetBranchStatus("*", 1);
65 Tree->SetBranchAddress("rec", &sr);
66
67 duneobj->nEvents = Tree->GetEntries();
68 duneobj->norm_s = 1;
69 duneobj->pot_s = 1;
70
71 duneobj->nupdg = new int[duneobj->nEvents];
72 duneobj->nupdgUnosc = new int[duneobj->nEvents];
73
74 duneobj->mode = new double[duneobj->nEvents];
75 duneobj->rw_isCC = new int[duneobj->nEvents];
76 duneobj->Target = new int[duneobj->nEvents];
77
78 duneobj->rw_etru = new double[duneobj->nEvents];
79 duneobj->rw_truecz = new double[duneobj->nEvents];
80 duneobj->flux_w = new double[duneobj->nEvents];
81 duneobj->rw_erec = new double[duneobj->nEvents];
82 duneobj->rw_theta = new double[duneobj->nEvents];
83
84 for (int iEvent=0;iEvent<duneobj->nEvents;iEvent++) {
85 Tree->GetEntry(iEvent);
86
87 if ((iEvent % (duneobj->nEvents/10))==0) {
88 MACH3LOG_INFO("\tProcessing event: {}/{}",iEvent,duneobj->nEvents);
89 }
90
91 duneobj->nupdg[iEvent] = sample_nupdg[iSample];
92 duneobj->nupdgUnosc[iEvent] = sample_nupdgunosc[iSample];
93
94 duneobj->mode[iEvent] = (double)SIMBMode_ToMaCh3Mode(TMath::Abs(sr->mc.nu[0].mode),(int)sr->mc.nu[0].iscc);
95 duneobj->rw_isCC[iEvent] = sr->mc.nu[0].iscc;
96 duneobj->Target[iEvent] = 40;
97
98 duneobj->rw_etru[iEvent] = (double)(sr->mc.nu[0].E);
99
100 TVector3 TrueNuMomentumVector = (TVector3(sr->mc.nu[0].momentum.X(),sr->mc.nu[0].momentum.Y(),sr->mc.nu[0].momentum.Z())).Unit();
101 duneobj->rw_truecz[iEvent] = TrueNuMomentumVector.Y();
102
103 duneobj->flux_w[iEvent] = sr->mc.nu[0].genweight;
104
105 TVector3 RecoNuMomentumVector;
106 if (IsELike) {
107 duneobj->rw_erec[iEvent] = sr->common.ixn.pandora[0].Enu.e_calo;
108 RecoNuMomentumVector = (TVector3(sr->common.ixn.pandora[0].dir.heshw.X(),sr->common.ixn.pandora[0].dir.heshw.Y(),sr->common.ixn.pandora[0].dir.heshw.Z())).Unit();
109 } else {
110 duneobj->rw_erec[iEvent] = sr->common.ixn.pandora[0].Enu.lep_calo;
111 RecoNuMomentumVector = (TVector3(sr->common.ixn.pandora[0].dir.lngtrk.X(),sr->common.ixn.pandora[0].dir.lngtrk.Y(),sr->common.ixn.pandora[0].dir.lngtrk.Z())).Unit();
112 }
113 duneobj->rw_theta[iEvent] = RecoNuMomentumVector.Y();
114
115 }
116
117 delete Tree;
118 delete File;
119
120 gErrorIgnoreLevel = CurrErrorLevel;
121
122 return duneobj->nEvents;
123}
124
126 dunemc_base *duneobj = &(dunemcSamples[iSample]);
127 FarDetectorCoreInfo *fdobj = &(MCSamples[iSample]);
128
129 //Make sure that this is only set if you're an atmoshperic object
130 fdobj->rw_truecz.resize(fdobj->nEvents);
131
132 for(int iEvent = 0 ;iEvent < fdobj->nEvents ; ++iEvent) {
133 fdobj->rw_etru[iEvent] = &(duneobj->rw_etru[iEvent]);
134 fdobj->mode[iEvent] = &(duneobj->mode[iEvent]);
135 fdobj->Target[iEvent] = &(duneobj->Target[iEvent]);
136 fdobj->isNC[iEvent] = !duneobj->rw_isCC[iEvent];
137 fdobj->nupdg[iEvent] = &(duneobj->nupdg[iEvent]);
138 fdobj->nupdgUnosc[iEvent] = &(duneobj->nupdgUnosc[iEvent]);
139
140 fdobj->rw_truecz[iEvent] = &(duneobj->rw_truecz[iEvent]);
141 }
142}
143
144const double* samplePDFDUNEAtm::GetPointerToKinematicParameter(KinematicTypes KinPar, int iSample, int iEvent) {
145 double* KinematicValue;
146
147 switch (KinPar) {
149 KinematicValue = &(dunemcSamples[iSample].rw_etru[iEvent]);
150 break;
152 KinematicValue = &(dunemcSamples[iSample].rw_erec[iEvent]);
153 break;
154 case kTrueCosZ:
155 KinematicValue = &(dunemcSamples[iSample].rw_truecz[iEvent]);
156 break;
157 case kRecoCosZ:
158 KinematicValue = &(dunemcSamples[iSample].rw_theta[iEvent]);
159 break;
160 case kOscChannel:
161 KinematicValue = &(MCSamples[iSample].ChannelIndex);
162 break;
163 case kMode:
164 KinematicValue = &(dunemcSamples[iSample].mode[iEvent]);
165 break;
166 default:
167 MACH3LOG_ERROR("Unknown KinPar: {}",KinPar);
168 throw MaCh3Exception(__FILE__, __LINE__);
169 }
170
171 return KinematicValue;
172}
173
174const double* samplePDFDUNEAtm::GetPointerToKinematicParameter(double KinematicVariable, int iSample, int iEvent) {
175 KinematicTypes KinPar = (KinematicTypes) std::round(KinematicVariable);
176 return GetPointerToKinematicParameter(KinPar,iSample,iEvent);
177}
178
179const double* samplePDFDUNEAtm::GetPointerToKinematicParameter(std::string KinematicParameter, int iSample, int iEvent) {
180 KinematicTypes KinPar = static_cast<KinematicTypes>(ReturnKinematicParameterFromString(KinematicParameter));
181 return GetPointerToKinematicParameter(KinPar,iSample,iEvent);
182}
183
184double samplePDFDUNEAtm::ReturnKinematicParameter(double KinematicVariable, int iSample, int iEvent) {
185 return *GetPointerToKinematicParameter(KinematicVariable, iSample, iEvent);
186}
187
188double samplePDFDUNEAtm::ReturnKinematicParameter(std::string KinematicParameter, int iSample, int iEvent) {
189 return *GetPointerToKinematicParameter(KinematicParameter, iSample, iEvent);
190}
191
192std::vector<double> samplePDFDUNEAtm::ReturnKinematicParameterBinning(std::string KinematicParameterStr) {
193 KinematicTypes KinPar = static_cast<KinematicTypes>(ReturnKinematicParameterFromString(KinematicParameterStr));
194 return ReturnKinematicParameterBinning(KinPar);
195}
196
198 std::vector<double> binningVector;
199
200 switch (KinPar) {
201
204 for (int i=0;i<20;i++) {
205 binningVector.emplace_back((double)i);
206 }
207 binningVector.emplace_back(100.);
208 binningVector.emplace_back(1000.);
209 break;
210
211 default:
212 MACH3LOG_ERROR("Unknown KinPar: {}",KinPar);
213 throw MaCh3Exception(__FILE__, __LINE__);
214 }
215
216 return binningVector;
217}
218
219int samplePDFDUNEAtm::ReturnKinematicParameterFromString(std::string KinematicParameterStr) {
220 int ReturnVal;
221
222 if (KinematicParameterStr == "TrueNeutrinoEnergy") {ReturnVal = kTrueNeutrinoEnergy;}
223 else if (KinematicParameterStr == "RecoNeutrinoEnergy") {ReturnVal = kRecoNeutrinoEnergy;}
224 else if (KinematicParameterStr == "TrueCosineZ") {ReturnVal = kTrueCosZ;}
225 else if (KinematicParameterStr == "RecoCosineZ") {ReturnVal = kRecoCosZ;}
226 else if (KinematicParameterStr == "OscChannel") {ReturnVal = kOscChannel;}
227 else if (KinematicParameterStr == "Mode") {ReturnVal = kMode;}
228 else {
229 MACH3LOG_ERROR("KinematicParameterStr: {} not found",KinematicParameterStr);
230 throw MaCh3Exception(__FILE__, __LINE__);
231 }
232
233 return ReturnVal;
234}
235
236std::string samplePDFDUNEAtm::ReturnStringFromKinematicParameter(int KinematicParameter) {
237 return "";
238}
int SIMBMode_ToMaCh3Mode(int SIMB_mode, int isCC)
std::vector< struct dunemc_base > dunemcSamples
Array filled with MC samples for each oscillation channel.
void SetupWeightPointers()
Sets up pointers weights for each event (oscillation/xsec/etc.)
KinematicTypes
Enum to identify kinematics.
std::string ReturnStringFromKinematicParameter(int KinematicVariable)
Get kinematic parameter name from ID.
~samplePDFDUNEAtm()
destructor
void SetupSplines()
Sets up splines.
int ReturnKinematicParameterFromString(std::string KinematicStr)
Get kinematic parameter ID from string name.
void setupFDMC(int iSample)
Tells FD base which variables to point to/be set to.
const double * GetPointerToKinematicParameter(KinematicTypes KinPar, int iSample, int iEvent)
Returns pointer to kinemtatic parameter for event in Structs DUNE.
double ReturnKinematicParameter(double KinematicVariable, int iSample, int iEvent)
Returns pointer to kinemtatic parameter for event in Structs DUNE.
int setupExperimentMC(int iSample)
Function to setup MC from file.
bool IsELike
Is the sample e-like.
void Init()
Initialises object.
samplePDFDUNEAtm(std::string mc_version, covarianceXsec *xsec_cov, covarianceOsc *osc_cov)
Constructor.
std::vector< double > ReturnKinematicParameterBinning(std::string KinematicParameterStr)
Gets binning for a given parameter.
int * nupdgUnosc
Definition StructsDUNE.h:15
double * mode
Definition StructsDUNE.h:65
double pot_s
Definition StructsDUNE.h:59
double * rw_erec
Definition StructsDUNE.h:17
int * rw_isCC
Definition StructsDUNE.h:47
double * flux_w
Definition StructsDUNE.h:63
double * rw_etru
Definition StructsDUNE.h:35
double * rw_theta
Definition StructsDUNE.h:37
double * rw_truecz
Definition StructsDUNE.h:68
double norm_s
Definition StructsDUNE.h:60