eventAnalysis  7.0-49-g0ac7482
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TGRooTrackerVtxModule.cxx
Go to the documentation of this file.
1 #include <cassert>
2 #include <cmath>
3 
4 #include "TG4PrimaryParticle.hxx"
5 #include "TG4PrimaryVertex.hxx"
7 #include "TGeomInfo.hxx"
8 #include "TJNuBeamFlux.hxx"
9 #include "TND280Log.hxx"
10 #include "TOADatabase.hxx"
11 #include "TP0DGeom.hxx"
12 
14  const char *title) {
15  fVtx = new TClonesArray("ND::GRooTrackerVtx", 100);
16  SetNameTitle(name, title);
17  ///< Enable this module by default:
18  fIsEnabled = kTRUE;
19  fDescription = "Genie specific module which fills mc-truth vertex info";
21  // ND::TND280Log::Configure();
22 }
23 
25 
27  std::string name2compare(name);
28  bool is_genie1 = (name2compare.find("genie") != name2compare.npos);
29  bool is_genie2 = (name2compare.find("gRooTracker") != name2compare.npos);
30  bool is_genie = (is_genie1 || is_genie2);
31  ND280Debug("Returning is generator = " << is_genie
32  << " for generator name = " << name);
33  return is_genie;
34 }
35 
36 Bool_t ND::TGRooTrackerVtxModule::CheckMismatch(ND::TG4PrimaryVertex vtx) {
37  if (fCurrGenieVtx == NULL) {
38  ND280Debug("Could not compare pass-through to G4 primary vertex as"
39  << " there is no passed through vertex to compare to!");
40  return false;
41  }
42 
43  ///< Compare the event codes.
44  bool evtcode =
45  (fCurrGenieVtx->EvtCode->GetString().CompareTo(vtx.GetReaction()) == 0);
46  ND280Debug("Comparing " << fCurrGenieVtx->EvtCode->GetString().Data()
47  << " and " << vtx.GetReaction());
48  ///< And the vertex position.
49  double smallnum = 0.000001;
50  bool position =
51  (std::abs(fCurrGenieVtx->EvtVtx[0] - vtx.GetPosition().X()) < smallnum) &&
52  (std::abs(fCurrGenieVtx->EvtVtx[1] - vtx.GetPosition().Y()) < smallnum) &&
53  (std::abs(fCurrGenieVtx->EvtVtx[2] - vtx.GetPosition().Z()) < smallnum);
54  ND280Debug("Pass through vertex position check bool passed = " << position);
55  ///< In future can add more but for now this should suffice along
56  ///< with the validation scripts.
57  if (position && evtcode) {
58  ND280Debug("Passed through vertex passed mismatch test!");
59  return true;
60  }
61  if (ND::TGRooTrackerVtxModule::IsGeantinoVtx(vtx)) return true;
62  ND280Error("SEVERE ERROR! Mismatch between G4Vertex and pass-through info!");
63  return false;
64 }
65 
66 Bool_t ND::TGRooTrackerVtxModule::IsGeantinoVtx(ND::TG4PrimaryVertex vtx) {
67  if (vtx.GetPrimaryParticles().size() == 1 &&
68  vtx.GetInteractionNumber() == 0 && vtx.GetProbability() == 0 &&
69  vtx.GetCrossSection() == 0 && vtx.GetDiffCrossSection() == 0 &&
70  vtx.GetPrimaryParticles().begin()->GetPDGCode() == 0)
71  return true;
72 
73  return false;
74 }
75 
77  ND280Verbose(
78  "Filling fCurrGenieVtx with OrigEvtNum = " << fOrigTreeEntryNumber);
79 
80  fCurrGenieVtx->Reset();
81  fRooTrackerTree->GetEntry(entry);
82 
83  ///< first fill up all the book-keeping info
84  fCurrGenieVtx->OrigFileName->SetString(fOrigInputFileName.c_str());
85  fCurrGenieVtx->OrigTreeName->SetString(fInputTreeName.c_str());
86  fCurrGenieVtx->OrigEvtNum = fOrigTreeEntryNumber;
87  fCurrGenieVtx->OrigTreePOT = fOrigInputTreePOT;
88  fCurrGenieVtx->OrigTreeEntries = fOrigInputTreeEntries;
89  fCurrGenieVtx->TimeInSpill = fTimeInSpill;
90  fCurrGenieVtx->TruthVertexID = fTruthVertexID;
91 
92  ///< Need to convert to the nd280 length units
93  fCurrGenieVtx->EvtVtx[0] *= 1000.0;
94  fCurrGenieVtx->EvtVtx[1] *= 1000.0;
95  fCurrGenieVtx->EvtVtx[2] *= 1000.0;
96 
97  ///< Fill in the geometry path for the current vertex.
98  gGeoManager->FindNode(fCurrGenieVtx->EvtVtx[0], fCurrGenieVtx->EvtVtx[1],
99  fCurrGenieVtx->EvtVtx[2]);
100 
101  ///< Get the name of the generator that generated this event.
102  fCurrGenieVtx->GeneratorName->SetString(fGeneratorName.c_str());
103 
104  ///< Get the geometry path for this event.
105  fCurrGenieVtx->GeomPath->SetString(gGeoManager->GetPath());
106 
107  ///< Now create another fRooTracker vtx to add to the vertex
108  ///< container.
109  GRooTrackerVtx *fGRooTrackerVtx;
110  fGRooTrackerVtx = new ((*fVtx)[fNVtx++]) GRooTrackerVtx();
111 
112  ///< Copy the current genie event. Make sure this is done last so we copy a
113  ///< complete event.
114  fGRooTrackerVtx->Copy(fCurrGenieVtx);
115 }
116 
118  // Set the flux branch addresses common to both generators
119  ND::JNuBeamFlux *flux = (ND::JNuBeamFlux *)fCurrGenieVtx;
121 
122  // Now set the generator specific branch addresses
123  fRooTrackerTree->SetBranchAddress("G2NeutEvtCode",
124  &(fCurrGenieVtx->G2NeutEvtCode));
125  fRooTrackerTree->SetBranchAddress("EvtCode", &(fCurrGenieVtx->EvtCode));
126  fRooTrackerTree->SetBranchAddress("EvtNum", &(fCurrGenieVtx->EvtNum));
127  fRooTrackerTree->SetBranchAddress("EvtXSec", &(fCurrGenieVtx->EvtXSec));
128  fRooTrackerTree->SetBranchAddress("EvtDXSec", &(fCurrGenieVtx->EvtDXSec));
129  fRooTrackerTree->SetBranchAddress("EvtWght", &(fCurrGenieVtx->EvtWght));
130  fRooTrackerTree->SetBranchAddress("EvtProb", &(fCurrGenieVtx->EvtProb));
131  fRooTrackerTree->SetBranchAddress("EvtVtx", (fCurrGenieVtx->EvtVtx));
132  fRooTrackerTree->SetBranchAddress("StdHepN", &(fCurrGenieVtx->StdHepN));
133  fRooTrackerTree->SetBranchAddress("StdHepPdg",
134  &(fCurrGenieVtx->StdHepPdgTemp));
135  fRooTrackerTree->SetBranchAddress("StdHepRescat",
136  &(fCurrGenieVtx->StdHepRescatTemp));
137  fRooTrackerTree->SetBranchAddress("StdHepStatus",
138  &(fCurrGenieVtx->StdHepStatusTemp));
139  fRooTrackerTree->SetBranchAddress("StdHepX4", (fCurrGenieVtx->StdHepX4));
140  fRooTrackerTree->SetBranchAddress("StdHepP4", (fCurrGenieVtx->StdHepP4));
141  fRooTrackerTree->SetBranchAddress("StdHepPolz", (fCurrGenieVtx->StdHepPolz));
142  fRooTrackerTree->SetBranchAddress("StdHepFd", (fCurrGenieVtx->StdHepFdTemp));
143  fRooTrackerTree->SetBranchAddress("StdHepLd", (fCurrGenieVtx->StdHepLdTemp));
144  fRooTrackerTree->SetBranchAddress("StdHepFm", (fCurrGenieVtx->StdHepFmTemp));
145  fRooTrackerTree->SetBranchAddress("StdHepLm", (fCurrGenieVtx->StdHepLmTemp));
146 }
147 
148 
150 
151  if(fFilledConfigTree){
152  ND280NamedWarn("TGRooTrackerVtxModule", "Module: " << this->GetName()
153  << " has already written the config tree this run.");
154  }
155 
156  int kGStdHepNPmax_hldr = kGStdHepNPmax;
157  int kGStdHepIdxPx_hldr = kGStdHepIdxPx;
158  int kGStdHepIdxPy_hldr = kGStdHepIdxPy;
159  int kGStdHepIdxPz_hldr = kGStdHepIdxPz;
160  int kGStdHepIdxE_hldr = kGStdHepIdxE;
161  int kGStdHepIdxX_hldr = kGStdHepIdxX;
162  int kGStdHepIdxY_hldr = kGStdHepIdxY;
163  int kGStdHepIdxZ_hldr = kGStdHepIdxZ;
164  int kGStdHepIdxT_hldr = kGStdHepIdxT;
165 
166  configTree->Branch("kGStdHepNPmax", &kGStdHepNPmax_hldr, "kGStdHepNPmax/I");
167  configTree->Branch("kGStdHepIdxPx", &kGStdHepIdxPx_hldr, "kGStdHepIdxPx/I");
168  configTree->Branch("kGStdHepIdxPy", &kGStdHepIdxPy_hldr, "kGStdHepIdxPy/I");
169  configTree->Branch("kGStdHepIdxPz", &kGStdHepIdxPz_hldr, "kGStdHepIdxPz/I");
170  configTree->Branch("kGStdHepIdxE", &kGStdHepIdxE_hldr, "kGStdHepIdxE/I");
171  configTree->Branch("kGStdHepIdxX", &kGStdHepIdxX_hldr, "kGStdHepIdxX/I");
172  configTree->Branch("kGStdHepIdxY", &kGStdHepIdxY_hldr, "kGStdHepIdxY/I");
173  configTree->Branch("kGStdHepIdxZ", &kGStdHepIdxZ_hldr, "kGStdHepIdxZ/I");
174  configTree->Branch("kGStdHepIdxT", &kGStdHepIdxT_hldr, "kGStdHepIdxT/I");
175 
177 }
void SetFluxTreeAddresses(ND::JNuBeamFlux *flux)
const int kGStdHepIdxY
const int kGStdHepIdxE
std::string fDescription
A longish descrition of the analysis.
TClonesArray * fVtx
TClonesArray of vertex objects.
void FillConfigTree(TTree *configTree)
const int kGStdHepIdxX
void FillConfigTree(TTree *configTree)
Bool_t CheckMismatch(ND::TG4PrimaryVertex vtx)
void SetNameTitle(char const *name, char const *title)
void Copy(const GRooTrackerVtx *event)
const int kGStdHepNPmax
const int kGStdHepIdxT
const int kGStdHepIdxPy
Bool_t IsGeantinoVtx(ND::TG4PrimaryVertex vtx)
const int kGStdHepIdxPx
const int kGStdHepIdxPz
Bool_t IsKnownGenerator(const char *)
const int kGStdHepIdxZ
TGRooTrackerVtxModule(const char *name="GRooTrackerVtx", const char *title="Complete truth info for GENIE primary vertices ""from the gRooTracker pass-through tree")

Package Summary
Package Name: eventAnalysis
Package Version: 7.0-49-g0ac7482
Package Manager:

Generated on Mon Mar 25 2024 14:43:59 for eventAnalysis by doxygen 1.8.5