3 #include "TGeomInfo.hxx"
4 #include "TND280Log.hxx"
5 #include "TOADatabase.hxx"
6 #include "TP0DGeom.hxx"
19 if (fInputKinemTree != NULL) {
20 delete fInputKinemTree;
21 fInputKinemTree = NULL;
23 if (fInputFileTree != NULL) {
24 delete fInputFileTree;
25 fInputFileTree = NULL;
30 if (fFilledConfigTree) {
32 "TRooTrackerVtxModuleBase",
33 "Module: " << this->GetName()
34 <<
" has already written the config tree this run.");
37 configTree->Branch(
"PassThroughPresent", &fPassThroughPresent,
38 "PassThroughPresent/O");
49 if (!event.Has<ND::TG4PrimaryVertexContainer>(
"truth/G4PrimVertex00")) {
50 ND280NamedVerbose(
"TRooTrackerVtxModuleBase",
51 "Skipping event (filling with TClonesArray of size 0)"
52 <<
" as can not find any primary vertices!");
56 ND::THandle<ND::TG4PrimaryVertexContainer> g4PrimVertex00 =
57 event.Get<ND::TG4PrimaryVertexContainer>(
"truth/G4PrimVertex00");
61 for (std::vector<ND::TG4PrimaryVertex>::const_iterator v_iter =
62 g4PrimVertex00->begin();
63 v_iter != g4PrimVertex00->end(); ++v_iter) {
67 "TRooTrackerVtxModuleBase",
68 "\nGot G4Vertex - filename: "
69 << this->GetFileName((*v_iter))
70 <<
"\n - treename: " << this->GetTreeName((*v_iter))
71 <<
"\n - origentry: " << this->GetEntryNum((*v_iter))
72 <<
"\n - currentry: " << v_iter->GetInteractionNumber()
73 <<
"\n - genname: " << v_iter->GetGeneratorName()
74 <<
" - ND280Time: " << v_iter->GetPosition().T());
77 if (this->LoadPassThroughInput((*v_iter)) ==
false) {
78 throw ND::ENoKinematicsPassThroughTrees();
84 if (this->UpdateBookKeepingInfo((*v_iter)) ==
false) {
85 throw ND::ENoKinematicsPassThroughTrees();
91 if (this->IsGeantinoVtx((*v_iter))) {
96 this->FillVtx(fInputTreeEntryNumber);
99 if (this->CheckMismatch((*v_iter)) ==
false) {
100 throw ND::EPassThroughMismatch();
108 const ND::TG4PrimaryVertex& vtx) {
110 if (this->AreTreesLoaded(vtx)) {
111 ND280Debug(
"No need to load the pass-through trees again");
114 ND280Debug(
"Pass-through trees are not loaded for this vertex. Trying to load"
117 this->ResetVtxInfo();
120 if (this->GetTreesFromFile(vtx)) {
121 ND280Debug(
"Loaded pass-through input trees from ND280GEANT4SIM pass-through"
126 else if (this->GetTreesFromDirectory(vtx)) {
127 ND280Debug(
"Loaded input trees from user defined or current working "
132 "TRooTrackerVtxModuleBase",
133 "Unable to load pass-through input trees. The module will be "
134 <<
"disabled and there will be no pass-through information in the"
135 <<
" analysis output file!");
140 this->SetGeneratorTreeAddresses();
145 const ND::TG4PrimaryVertex& vtx) {
147 fOrigTreeEntryNumber = this->GetEntryNum(vtx);
148 fInputTreeEntryNumber = fOrigTreeEntryNumber;
149 fInputTreeName = this->GetTreeName(vtx);
150 fOrigInputFileName = this->GetFileName(vtx);
151 fGeneratorName = string(vtx.GetGeneratorName());
152 fTimeInSpill = vtx.GetPosition().T();
153 fTruthVertexID = vtx.GetInteractionNumber();
160 if (fPassThroughPresent ==
true) {
161 int input_file_number = -1;
162 fInputKinemTree->SetBranchAddress(
"inputEntryNum", &fOrigTreeEntryNumber);
163 fInputKinemTree->SetBranchAddress(
"inputFileNum", &input_file_number);
164 fInputFileTree->SetBranchAddress(
"filePOT", &fOrigInputTreePOT);
165 fInputFileTree->SetBranchAddress(
"fileEntries", &fOrigInputTreeEntries);
166 fInputTreeEntryNumber = vtx.GetInteractionNumber();
167 fInputKinemTree->GetEntry(fInputTreeEntryNumber);
168 fInputFileTree->GetEntry(input_file_number);
172 fOrigInputTreePOT = fRooTrackerTree->GetWeight();
173 fOrigInputTreeEntries = fRooTrackerTree->GetEntries();
179 const ND::TG4PrimaryVertex& vtx) {
181 bool inputfile = (fCurrInputFile != NULL);
182 bool rootracker_tree = (fRooTrackerTree != NULL);
183 if (!inputfile || !rootracker_tree) {
184 ND280Debug(
"Trees are not loaded yet!");
188 bool same_name =
false;
190 if (fPassThroughPresent && fCurrInputFile) {
191 TFile* curr_inputfile =
193 same_name = this->ComparePaths(fCurrInputFile->GetName(),
194 curr_inputfile->GetName());
198 else if (fCurrInputFile) {
199 string filename_vtx = this->GetFileName(vtx);
201 this->ComparePaths(fCurrInputFile->GetName(), filename_vtx.c_str());
205 this->ResetVtxInfo();
211 const ND::TG4PrimaryVertex& vtx) {
212 this->ResetFileInfo();
213 fPassThroughPresent =
false;
217 if (curr_infile != NULL) {
218 if (!curr_infile->IsZombie()) {
223 TTree* tmpKinemTree = (TTree*)curr_infile->Get(
"ND280GEANT4SIM/InputKinem");
224 TTree* tmpFileTree = (TTree*)curr_infile->Get(
"ND280GEANT4SIM/InputFiles");
225 if (!tmpKinemTree || !tmpFileTree) {
229 fInputKinemTree = (TTree*)tmpKinemTree->CloneTree();
230 fInputFileTree = (TTree*)tmpFileTree->CloneTree();
235 if (fInputKinemTree == NULL || fInputFileTree == NULL) {
239 fCurrInputFile = curr_infile;
240 fPassThroughPresent =
true;
242 string generator_name = vtx.GetGeneratorName();
243 string tree_name = this->GetTreeName(vtx);
249 if (!this->IsKnownGenerator(generator_name.c_str()) &&
250 !this->IsKnownGenerator(tree_name.c_str())) {
251 throw ND::EIncorrectInputGenerator();
256 std::string tree_path = string(
"ND280GEANT4SIM/") + tree_name;
257 fRooTrackerTree = (TTree*)fCurrInputFile->Get(tree_path.c_str());
258 ND280Debug(
"Looking for pass-through info in file:"
259 << fCurrInputFile->GetName());
260 if (fRooTrackerTree == NULL) {
261 this->ClearInputTrees();
262 ND280Debug(
"Could not get pass-through tree "
264 <<
" from file:" << fCurrInputFile->GetName());
265 throw ND::ENoKinematicsPassThroughTrees();
268 ND280Debug(
"Successfully found pass-through tree from "
270 <<
"in nd280 output file: " << fCurrInputFile->GetName());
278 const ND::TG4PrimaryVertex& vtx) {
279 this->ResetFileInfo();
283 std::string directorytosearch(gSystem->WorkingDirectory());
284 if (fInputDirectory.size() != 0) {
285 directorytosearch = std::string(fInputDirectory.c_str());
289 TString filename(this->GetFileName(vtx));
290 ND280Debug(
"Looking for input rootracker file: "
291 << filename.Data() <<
"\nIn path: \n"
292 << directorytosearch.c_str());
293 const char* filepath = gSystem->FindFile(directorytosearch.c_str(), filename);
295 ND280Debug(
"Could not find pass-through file in directory!");
299 ND280Debug(
"Found filepath: " << filepath);
301 TFile* infile =
new TFile(filepath,
"OPEN");
303 ND280Debug(
"Could not open pass-through file!");
308 fCurrInputFile = infile;
309 fPassThroughPresent =
false;
311 string generator_name = vtx.GetGeneratorName();
312 string tree_name = this->GetTreeName(vtx);
316 if (!this->IsKnownGenerator(generator_name.c_str()) &&
317 !this->IsKnownGenerator(tree_name.c_str())) {
318 throw ND::EIncorrectInputGenerator();
323 std::string tree_path = tree_name;
324 fRooTrackerTree = (TTree*)fCurrInputFile->Get(tree_path.c_str());
326 "Looking for pass-through info in file:" << fCurrInputFile->GetName());
327 if (fRooTrackerTree == NULL) {
328 this->ClearInputTrees();
329 ND280Debug(
"Could not get pass-through tree "
331 <<
" from file:" << fCurrInputFile->GetName());
332 throw ND::ENoKinematicsPassThroughTrees();
335 ND280Debug(
"Successfully found input tree from external directory in file: "
336 << fCurrInputFile->GetName());
341 if (fInputKinemTree != NULL) {
342 delete fInputKinemTree;
343 fInputKinemTree = NULL;
345 if (fInputFileTree != NULL) {
346 delete fInputFileTree;
347 fInputFileTree = NULL;
349 if (fRooTrackerTree != NULL) {
350 delete fRooTrackerTree;
351 fRooTrackerTree = NULL;
356 fOutputTree->Branch(
"NVtx", &fNVtx,
"NVtx/I", fBufferSize);
357 fOutputTree->Branch(
"Vtx",
"TClonesArray", &fVtx, fBufferSize, 1);
361 const ND::TG4PrimaryVertex& prim_vtx) {
362 std::string name(prim_vtx.GetFilename());
363 std::string::size_type start_pos = name.rfind(
"/");
364 std::string::size_type finish_pos = name.find(
":");
365 if (start_pos == std::string::npos)
369 std::string filename(name, start_pos, finish_pos - start_pos);
370 ND280NamedVerbose(
"TRooTrackerVtxModuleBase",
371 "Got filename " << filename.c_str()
372 <<
" from filestring: " << name.c_str());
377 const ND::TG4PrimaryVertex& prim_vtx) {
378 std::string name(prim_vtx.GetFilename());
379 std::string::size_type start_pos = name.find(
":");
380 std::string::size_type finish_pos = name.rfind(
":");
381 if (start_pos == std::string::npos)
385 std::string treename(name, start_pos, finish_pos - start_pos);
386 ND280NamedVerbose(
"TRooTrackerVtxModuleBase",
387 "Got treename " << treename.c_str()
388 <<
" from filestring: " << name.c_str());
393 const ND::TG4PrimaryVertex& prim_vtx) {
395 std::string name(prim_vtx.GetFilename());
396 std::string::size_type start_pos = name.rfind(
":");
397 if (start_pos == std::string::npos)
401 std::string filename(name, start_pos);
402 entrynum = std::atoi(filename.c_str());
403 ND280NamedVerbose(
"TRooTrackerVtxModuleBase",
404 "Got entry " << entrynum
405 <<
" from filestring: " << name.c_str());
410 string pathstr(path);
411 std::string::size_type start_pos = pathstr.rfind(
"/");
412 if (start_pos == std::string::npos)
416 string substring(pathstr, start_pos);
422 string file1name = this->GetFileFromPath(path1);
423 string file2name = this->GetFileFromPath(path2);
424 return (file1name.find(file2name) != file1name.npos);
428 fCurrInputFile = NULL;
429 fPassThroughPresent =
false;
430 this->ResetVtxInfo();
434 fOrigInputFileName = string(
"");
435 fOrigTreeEntryNumber = -1;
436 fOrigInputTreeEntries = -1;
437 fOrigInputTreePOT = -1.0;
438 fInputTreeName = string(
"");
439 fGeneratorName = string(
"");
440 fInputTreeEntryNumber = -1;
446 bool IsDataFile =
event.GetContext().IsDetector();
448 throw ND::EDataFile();
458 if (!fRooTrackerTree) {
459 ND280Warn(
"Cannot set flux tree addresses as no rootracker tree loaded!");
464 if ((fBr = fRooTrackerTree->GetBranch(
"NuFluxEntry"))) {
467 if ((fBr = fRooTrackerTree->GetBranch(
"NuFileName"))) {
470 if ((fBr = fRooTrackerTree->GetBranch(
"NuParentPdg"))) {
473 if ((fBr = fRooTrackerTree->GetBranch(
"NuParentDecMode"))) {
476 if ((fBr = fRooTrackerTree->GetBranch(
"NuParentDecX4"))) {
479 if ((fBr = fRooTrackerTree->GetBranch(
"NuParentDecP4"))) {
482 if ((fBr = fRooTrackerTree->GetBranch(
"NuCospibm"))) {
485 if ((fBr = fRooTrackerTree->GetBranch(
"NuNorm"))) {
486 fBr->SetAddress(&flux->
NuNorm);
488 if ((fBr = fRooTrackerTree->GetBranch(
"NuParentProP4"))) {
491 if ((fBr = fRooTrackerTree->GetBranch(
"NuParentProX4"))) {
494 if ((fBr = fRooTrackerTree->GetBranch(
"NuCospi0bm"))) {
497 if ((fBr = fRooTrackerTree->GetBranch(
"NuRnu"))) {
498 fBr->SetAddress(&flux->
NuRnu);
500 if ((fBr = fRooTrackerTree->GetBranch(
"NuXnu"))) {
501 fBr->SetAddress(flux->
NuXnu);
503 if ((fBr = fRooTrackerTree->GetBranch(
"NuIdfd"))) {
504 fBr->SetAddress(&flux->
NuIdfd);
506 if ((fBr = fRooTrackerTree->GetBranch(
"NuGipart"))) {
509 if ((fBr = fRooTrackerTree->GetBranch(
"NuGpos0"))) {
510 fBr->SetAddress(flux->
NuGpos0);
512 if ((fBr = fRooTrackerTree->GetBranch(
"NuGvec0"))) {
513 fBr->SetAddress(flux->
NuGvec0);
515 if ((fBr = fRooTrackerTree->GetBranch(
"NuGamom0"))) {
518 if ((fBr = fRooTrackerTree->GetBranch(
"NuNg"))) {
519 fBr->SetAddress(&flux->
NuNg);
521 if ((fBr = fRooTrackerTree->GetBranch(
"NuGp"))) {
522 fBr->SetAddress(flux->
NuGp);
524 if ((fBr = fRooTrackerTree->GetBranch(
"NuGcosbm"))) {
527 if ((fBr = fRooTrackerTree->GetBranch(
"NuGv"))) {
528 fBr->SetAddress(flux->
NuGv);
530 if ((fBr = fRooTrackerTree->GetBranch(
"NuGpid"))) {
531 fBr->SetAddress(flux->
NuGpid);
533 if ((fBr = fRooTrackerTree->GetBranch(
"NuGmec"))) {
534 fBr->SetAddress(flux->
NuGmec);
536 if ((fBr = fRooTrackerTree->GetBranch(
"NuEnusk"))) {
537 fBr->SetAddress(&flux->
NuEnusk);
539 if ((fBr = fRooTrackerTree->GetBranch(
"NuNormsk"))) {
542 if ((fBr = fRooTrackerTree->GetBranch(
"NuAnorm"))) {
543 fBr->SetAddress(&flux->
NuAnorm);
545 if ((fBr = fRooTrackerTree->GetBranch(
"NuGmat"))) {
546 fBr->SetAddress(flux->
NuGmat);
548 if ((fBr = fRooTrackerTree->GetBranch(
"NuGdistc"))) {
551 if ((fBr = fRooTrackerTree->GetBranch(
"NuGdistal"))) {
554 if ((fBr = fRooTrackerTree->GetBranch(
"NuGdistti"))) {
557 if ((fBr = fRooTrackerTree->GetBranch(
"NuGdistfe"))) {
560 if ((fBr = fRooTrackerTree->GetBranch(
"NuVersion"))) {
563 if ((fBr = fRooTrackerTree->GetBranch(
"NuTuneid"))) {
566 if ((fBr = fRooTrackerTree->GetBranch(
"NuNtrig"))) {
567 fBr->SetAddress(&flux->
NuNtrig);
569 if ((fBr = fRooTrackerTree->GetBranch(
"NuPint"))) {
570 fBr->SetAddress(&flux->
NuPint);
572 if ((fBr = fRooTrackerTree->GetBranch(
"NuBpos"))) {
573 fBr->SetAddress(flux->
NuBpos);
575 if ((fBr = fRooTrackerTree->GetBranch(
"NuBtilt"))) {
576 fBr->SetAddress(flux->
NuBtilt);
578 if ((fBr = fRooTrackerTree->GetBranch(
"NuBrms"))) {
579 fBr->SetAddress(flux->
NuBrms);
581 if ((fBr = fRooTrackerTree->GetBranch(
"NuEmit"))) {
582 fBr->SetAddress(flux->
NuEmit);
584 if ((fBr = fRooTrackerTree->GetBranch(
"NuAlpha"))) {
585 fBr->SetAddress(flux->
NuAlpha);
587 if ((fBr = fRooTrackerTree->GetBranch(
"NuHcur"))) {
588 fBr->SetAddress(flux->
NuHcur);
590 if ((fBr = fRooTrackerTree->GetBranch(
"NuRand"))) {
591 fBr->SetAddress(&flux->
NuRand);
void SetFluxTreeAddresses(ND::JNuBeamFlux *flux)
bool FillTree(ND::TND280Event &)
Fill all the stuff that goes in the output tree.
float NuGdistti[kNgmax]
distance traveled through titanium
float NuGpos0[3]
primary particle starting point
float NuBtilt[2]
Beam angle.
double NuParentProP4[4]
parent hadron 4-momentum at production
TTree * fInputFileTree
Pass-through book keeping trees.
TRooTrackerVtxModuleBase()
TTree * fRooTrackerTree
Current loaded rootracker file.
float NuGdistc[kNgmax]
distance traveled through carbon
float NuAnorm
ND Acceptance Weight Out-of-target Secondary Interactions.
Bool_t ProcessFirstEvent(ND::TND280Event &event)
Is called after the first event is loaded in.
int GetEntryNum(const ND::TG4PrimaryVertex &vtx)
float NuRnu
neutrino r position at ND5/6 plane
float NuGp[kNgmax][3]
Momentum of ancestor particle.
float NuBpos[2]
Beam center position.
int NuParentPdg
parent hadron pdg code
float NuEmit[2]
Beam Emittance.
bool UpdateBookKeepingInfo(const ND::TG4PrimaryVertex &vtx)
bool GetTreesFromFile(const ND::TG4PrimaryVertex &vtx)
void FillConfigTree(TTree *configTree)
int NuNg
Number of interaction steps.
float NuCospibm
parent hadron cos(theta) relative to beam at decay
long NuFluxEntry
corresponding entry in orig flux file
int NuIdfd
Detector ID primary particle information.
float NuGvec0[3]
primary particle direction at starting point
std::string GetFileFromPath(const char *path)
bool GetTreesFromDirectory(const ND::TG4PrimaryVertex &vtx)
int NuGipart
primary particle ID
float NuHcur[3]
Horn currents.
bool ComparePaths(const char *path1, const char *path2)
bool AreTreesLoaded(const ND::TG4PrimaryVertex &vtx)
int NuTuneid
beam tune ID #
float NuXnu[2]
neutrino (x,y) position at ND5/6 plane
double NuParentDecX4[4]
parent hadron 4-position at decay
double NuParentProX4[4]
parent hadron 4-position at production
int NuParentDecMode
parent hadron decay mode
void InitializeBranches()
Initialize Branches. Don't do anything else in this function.
float NuGamom0
momentum of the primary particle at the starting point Interation History Information ...
float NuEnusk
Neutrino Energy at SK.
float NuVersion
jnubeam flux version
float NuNorm
Normalization weight.
int NuGpid[kNgmax]
PDG ancestor particle ID.
float NuAlpha[2]
Beam Alpha.
std::string GetFileName(const ND::TG4PrimaryVertex &vtx)
float NuGdistfe[kNgmax]
distance traveled through iron Beam parameter information
float NuGv[kNgmax][3]
Position of ancestor particle.
float NuGcosbm[kNgmax]
Ancestor particle cos(theta) relative to beam.
int NuGmec[kNgmax]
particle production mechanism of ancestor particle Normalization and Transfer Matrix Information ...
int NuNtrig
Number of triggers.
float NuCospi0bm
parent hadron cos(theta) relative to beam at production
float NuBrms[2]
Beam RMS width.
float NuNormsk
Normalization weight at SK.
TObjString * NuFileName
orig flux file name neutrino parent info
std::string GetTreeName(const ND::TG4PrimaryVertex &vtx)
double NuParentDecP4[4]
parent hadron 4-momentum at decay
float NuGdistal[kNgmax]
distance traveled through aluminum
bool LoadPassThroughInput(const ND::TG4PrimaryVertex &vtx)
int NuGmat[kNgmax]
material in which the particle originates
virtual ~TRooTrackerVtxModuleBase()
int NuPint
Interaction model ID.
virtual void FillConfigTree(TTree *)