eventAnalysis  7.0-49-g0ac7482
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TTruthVerticesModule.cxx
Go to the documentation of this file.
2 
3 #include <sstream>
4 // Root
5 #include <TClonesArray.h>
6 // oaEvent
7 #include <TG4PrimaryParticle.hxx>
8 #include <TG4PrimaryVertex.hxx>
9 #include <TGeometryId.hxx>
10 // oaGeomInfo
11 #include <TGeomInfo.hxx>
12 #include <TP0DGeom.hxx>
13 
15 
16 #define CVSTAG \
17  "\
18  $Name: 7.0$"
19 #define CVSID \
20  "\
21  $Id: eventAnalysis TTruthVerticesModule.cxx,2024/03/20:09:46:11,Alexander_J_Finch,lapw.lancs.ac.uk $"
22 
24  const char* title)
25  : fMaxNVertices(500),
26  fNVtx(0),
27  fNVtxFGD1(0),
28  fNVtxFGD2(0),
29  fNVtxP0D(0),
30  fNVtxDsECal(0),
31  fNVtxBrlECal(0),
32  fNVtxP0DECal(0),
33  fNVtxTPC1(0),
34  fNVtxTPC2(0),
35  fNVtxTPC3(0),
36  fNVtxSMRD(0),
37  fNVtxRestOfOffAxis(0),
38  fNVtxINGRID(0),
39  fNVtxOther(0),
40  fVertices(new TClonesArray("ND::TTruthVerticesModule::TTruthVertex",
41  fMaxNVertices)) {
42  SetNameTitle(name, title);
43  fIsEnabled = kTRUE;
44  fDescription = "Module storing the truth information for primary vertices";
46  fCVSID = CVSID;
47 }
48 
50 
52  fOutputTree->Branch("NVtx", &fNVtx, "NVtx/I", fBufferSize)->SetTitle("The total number of vertices recorded");
53  fOutputTree->Branch("NVtxFGD1", &fNVtxFGD1, "NVtxFGD1/I", fBufferSize)->SetTitle("The number of vertices recorded in FGD 1");
54  fOutputTree->Branch("NVtxFGD2", &fNVtxFGD2, "NVtxFGD2/I", fBufferSize)->SetTitle("The number of vertices recorded in FGD 2");
55  fOutputTree->Branch("NVtxSFG", &fNVtxSFG, "NVtxSFG/I", fBufferSize)->SetTitle("The number of vertices recorded in SFG");
56  fOutputTree->Branch("NVtxP0D", &fNVtxP0D, "NVtxP0D/I", fBufferSize)->SetTitle("The number of vertices recorded in the P0D");
57  fOutputTree->Branch("NVtxDsECal", &fNVtxDsECal, "NVtxDsECal/I", fBufferSize)->SetTitle("The number of vertices recorded in the Downstream ECal");
58  fOutputTree->Branch("NVtxBrlECal", &fNVtxBrlECal, "NVtxBrlECal/I",
59  fBufferSize)->SetTitle("The number of vertices recorded in the Barrel ECal");
60  fOutputTree->Branch("NVtxP0DECal", &fNVtxP0DECal, "NVtxP0DECal/I",
61  fBufferSize)->SetTitle("The number of vertices recorded in the P0D ECal");
62  fOutputTree->Branch("NVtxTPC1", &fNVtxTPC1, "NVtxTPC1/I", fBufferSize)->SetTitle("The number of vertices recorded in TPC 1");
63  fOutputTree->Branch("NVtxTPC2", &fNVtxTPC2, "NVtxTPC2/I", fBufferSize)->SetTitle("The number of vertices recorded in TPC 2");
64  fOutputTree->Branch("NVtxTPC3", &fNVtxTPC3, "NVtxTPC3/I", fBufferSize)->SetTitle(" The number of vertices recorded in TPC 3");
65  fOutputTree->Branch("NVtxSMRD", &fNVtxSMRD, "NVtxSMRD/I", fBufferSize)->SetTitle("The number of vertices recorded in the SMRD");
66  fOutputTree->Branch("NVtxRestOfOffAxis", &fNVtxRestOfOffAxis,
67  "NVtxRestOfOffAxis/I", fBufferSize)->SetTitle(" The number of vertices recorded in the rest of the off-axis detector");
68  fOutputTree->Branch("NVtxINGRID", &fNVtxINGRID, "NVtxINGRID/I", fBufferSize)->SetTitle("The number of vertices recorded in INGRID");
69  fOutputTree->Branch("NVtxOther", &fNVtxOther, "NVtxOther/I", fBufferSize)->SetTitle("The number of vertices recorded anywhere which does not fall into the other available categories");
70 
71  fOutputTree->Branch("Vertices", "TClonesArray", &fVertices, fBufferSize,
72  fSplitLevel)->SetTitle("The TClonesArray storing the TTruthVertex objects holding the information relating to each vertex.");
73 }
74 
75 Bool_t ND::TTruthVerticesModule::ProcessFirstEvent(ND::TND280Event& event) {
76  bool IsDataFile = event.GetContext().IsDetector();
77  if (IsDataFile) {
78  throw ND::EDataFile();
79  }
80  return true;
81 }
82 
83 bool ND::TTruthVerticesModule::FillTree(ND::TND280Event& event) {
84  if (!event.GetContext().IsMC()) {
85  ND280Error(
86  "Event Context reports event is non-MC. Assuming entire file is "
87  "non-MC.");
88  return false; // disable module
89  }
90 
91  fNVtx = 0;
92  fNVtxFGD1 = 0;
93  fNVtxFGD2 = 0;
94  fNVtxSFG = 0;
95  fNVtxP0D = 0;
96  fNVtxDsECal = 0;
97  fNVtxBrlECal = 0;
98  fNVtxP0DECal = 0;
99  fNVtxTPC1 = 0;
100  fNVtxTPC2 = 0;
101  fNVtxTPC3 = 0;
102  fNVtxSMRD = 0;
103  fNVtxRestOfOffAxis = 0;
104  fNVtxINGRID = 0;
105  fNVtxOther = 0;
106  fVertices->Clear();
107 
108  if (!event.Has<ND::TG4PrimaryVertexContainer>("truth/G4PrimVertex00")) {
109  ND280Warn("No vertices container found, skipping event.");
110  return true; // this happens occasionally, so don't disable the module
111  }
112 
113  const ND::THandle<ND::TG4PrimaryVertexContainer>& vertices =
114  event.Get<ND::TG4PrimaryVertexContainer>("truth/G4PrimVertex00");
115 
116  std::vector<ND::TG4PrimaryVertex>::const_iterator vertices_it =
117  vertices->begin();
118  std::vector<ND::TG4PrimaryVertex>::const_iterator vertices_end;
119 
120  if (vertices->size() <= fMaxNVertices) {
121  vertices_end = vertices->end();
122  } else {
123  ND280Warn("Event contains " << vertices->size() << " vertices."
124  << " Only the first " << fMaxNVertices
125  << " will be saved.");
126  vertices_end = vertices->begin();
127  vertices_end += fMaxNVertices;
128  }
129 
130  for (; vertices_it != vertices_end; ++vertices_it) {
131  // Firstly, check if the vertex is the geantino vertex, if it is, don't
132  // bother with it!
133  if (ND::TTruthVerticesModule::IsGeantinoVtx((*vertices_it))) continue;
134 
135  TTruthVertex* vtxToFill = new ((*fVertices)[fNVtx]) TTruthVertex();
136  ++fNVtx;
137 
138  vtxToFill->ID = vertices_it->GetInteractionNumber();
139  vtxToFill->Position = vertices_it->GetPosition();
140  vtxToFill->Generator = vertices_it->GetGeneratorName();
141  vtxToFill->ReactionCode = vertices_it->GetReaction();
142 
143  TLorentzVector pos = vertices_it->GetPosition();
144 
145  gGeoManager->FindNode(pos.X(), pos.Y(), pos.Z());
146  std::string path = gGeoManager->GetPath();
148 
149  // Fill vertex's fiducial distance and increment the relevant
150  // vertex counter
151  switch (vtxToFill->Subdetector) {
153  ++fNVtxFGD1;
154  vtxToFill->Fiducial = -1.0;
155  break;
157  ++fNVtxFGD2;
158  vtxToFill->Fiducial = -1.0;
159  break;
161  ++fNVtxSFG;
162  vtxToFill->Fiducial = -1.0;
163  break;
165  ++fNVtxP0D;
166  vtxToFill->Fiducial =
167  TGeomInfo::P0D().WaterFiducialDistance(pos.X(), pos.Y(), pos.Z()) *
168  unit::mm;
169  break;
171  ++fNVtxDsECal;
172  vtxToFill->Fiducial = -1.0;
173  break;
178  ++fNVtxBrlECal;
179  vtxToFill->Fiducial = -1.0;
180  break;
185  ++fNVtxP0DECal;
186  vtxToFill->Fiducial = -1.0;
187  break;
189  ++fNVtxTPC1;
190  vtxToFill->Fiducial = -1.0;
191  break;
193  ++fNVtxTPC2;
194  vtxToFill->Fiducial = -1.0;
195  break;
197  ++fNVtxTPC3;
198  vtxToFill->Fiducial = -1.0;
199  break;
201  ++fNVtxSMRD;
202  vtxToFill->Fiducial = -1.0;
203  break;
205  ++fNVtxRestOfOffAxis;
206  vtxToFill->Fiducial = -1.0;
207  break;
209  ++fNVtxINGRID;
210  vtxToFill->Fiducial = -1.0;
211  break;
212  default:
213  ++fNVtxOther;
214  vtxToFill->Fiducial = -1.0;
215  break;
216  }
217  // END SWITCH ON SUBDETECTOR
218 
219  ///
220  /// Fill primary particle trajectory information.
221  /// These are particles leaving the vertex.
222 
223  std::vector<ND::TG4PrimaryParticle>::const_iterator primaries_it =
224  vertices_it->GetPrimaryParticles().begin();
225  std::vector<ND::TG4PrimaryParticle>::const_iterator primaries_end =
226  vertices_it->GetPrimaryParticles().end();
227  vtxToFill->NPrimaryTraj = 0;
228 
229  for (; primaries_it != primaries_end; ++primaries_it) {
230  vtxToFill->PrimaryTrajIDs.push_back(primaries_it->GetTrackId());
231  ++(vtxToFill->NPrimaryTraj);
232  }
233 
234  // For the info particles, it is a bit hard to specify the
235  // behaviour without knowing exactly what the generator is
236  // giving us.
237  // For now, just look at particles with Id == -1 (-2 means
238  // stuff going on inside the nucleus). Look for neutrinos and
239  // non-neutrinos, assuming the latter are targets.
240  // Loop through all info vertices and their particles until both
241  // neutrino and target have been seen, then stop.
242 
243  bool found_neutrino = false;
244  bool found_target = false;
245 
246  std::vector<ND::TG4PrimaryVertex>::const_iterator info_it =
247  vertices_it->GetInfoVertex().begin();
248  std::vector<ND::TG4PrimaryVertex>::const_iterator info_end =
249  vertices_it->GetInfoVertex().end();
250 
251  for (; info_it != info_end; ++info_it) {
252  std::vector<ND::TG4PrimaryParticle>::const_iterator particles_it =
253  info_it->GetPrimaryParticles().begin();
254  std::vector<ND::TG4PrimaryParticle>::const_iterator particles_end =
255  info_it->GetPrimaryParticles().end();
256 
257  Int_t temp_pdg;
258 
259  for (; particles_it != particles_end; ++particles_it) {
260  if (particles_it->GetTrackId() ==
261  -1) // is an incoming particle (including target)
262  {
263  temp_pdg = particles_it->GetPDGCode();
264  switch (temp_pdg) {
265  case 12: // fall through
266  case 14: // fall through
267  case 16: // fall through
268  case -12: // fall through
269  case -14: // fall through
270  case -16:
271  vtxToFill->NeutrinoPDG = temp_pdg;
272  vtxToFill->NeutrinoMomentum = particles_it->GetMomentum();
273  found_neutrino = true;
274  break;
275  default:
276  vtxToFill->TargetPDG = temp_pdg;
277  vtxToFill->TargetMomentum = particles_it->GetMomentum();
278  found_target = true;
279  break;
280  }
281  if (found_neutrino && found_target) break;
282  }
283  }
284  if (found_neutrino && found_target) break;
285  }
286  // END LOOP OVER INFO VERTICES
287  }
288  // END LOOP OVER VERTICES
289 
290  fVertices->Sort();
291 
292  return true;
293 }
294 
295 //
296 // Truth Vertex
297 // =====================================================================
298 //
299 
301  : ID(-1),
302  Position(-999999.9, -999999.9, -999999.9, -999999.9),
303  Generator("Not Set"),
304  ReactionCode("Not Set"),
305  Subdetector(eventAnalysisEnums::kNSubdetectors),
306  Fiducial(-999999.9),
307  NPrimaryTraj(-1),
308  NeutrinoPDG(-1),
309  NeutrinoMomentum(-999999.9, -999999.9, -999999.9, -999999.9),
310  TargetPDG(-1),
311  TargetMomentum(-999999.9, -999999.9, -999999.9, -999999.9) {}
312 
314  const TObject* obj) const {
315  // Sorry about the casting, but I don't want to slow down sorting
316  // by checking that everything compared with is of the correct
317  // type. In any case, you get what you ask for if you try and
318  // use this with anything other than another vertex.
319 
320  if (this->ID <
321  static_cast<const ND::TTruthVerticesModule::TTruthVertex*>(obj)->ID) {
322  return -1;
323  } else if (this->ID >
324  static_cast<const ND::TTruthVerticesModule::TTruthVertex*>(obj)
325  ->ID) {
326  return 1;
327  } else // they must be equal
328  {
329  return 0;
330  }
331 }
332 
333 Bool_t ND::TTruthVerticesModule::IsGeantinoVtx(ND::TG4PrimaryVertex vtx) {
334  if (vtx.GetPrimaryParticles().size() == 1 &&
335  vtx.GetInteractionNumber() == 0 && vtx.GetProbability() == 0 &&
336  vtx.GetCrossSection() == 0 && vtx.GetDiffCrossSection() == 0 &&
337  vtx.GetPrimaryParticles().begin()->GetPDGCode() == 0)
338  return true;
339 
340  return false;
341 }
std::string Generator
The generator that created the vertex. eg: &quot;genie:mean@free-spill&quot;.
Int_t NeutrinoPDG
The PDG number of the incoming neutrino. Set to 0 in the absence of a neutrino.
the rest of the off-axis detector
ClassImp(ND::TBeamSummaryDataModule::TBeamSummaryData)
TLorentzVector TargetMomentum
The four-momentum of the target. Set to (-999999.9, -999999.9, -999999.9, -999999.9) in the absence of a target.
std::string fDescription
A longish descrition of the analysis.
#define CVSID
Bool_t IsGeantinoVtx(ND::TG4PrimaryVertex vtx)
std::string ReactionCode
The Reaction code according to the generator For Genie this will be of the form: &quot;nu:14;tgt:100026056...
Int_t TargetPDG
The (extended for nuclei) PDG number of the target. Set to 0 in the absence of a target.
Class used by the Truth Vertices Module to store information relating to an individual true primary v...
#define CVSTAG
std::string fCVSID
Defined if an official tagged version.
void SetNameTitle(char const *name, char const *title)
Int_t Compare(const TObject *obj) const
Compare the values of the vertices&#39; IDs so that a TClonesArray can be sorted in order of increasing I...
TLorentzVector NeutrinoMomentum
The four-momentum of the incoming neutrino. Set to (-999999.9, -999999.9, -999999.9, -999999.9) in the absence of a neutrino.
virtual void InitializeBranches()
Initialize Branches. Don&#39;t do anything else in this function.
Int_t Subdetector
Subdetector which the vertex occurs in.
std::vector< Int_t > PrimaryTrajIDs
ID numbers which uniquely identify the trajectories of the primary particles of the vertex within the...
virtual Bool_t ProcessFirstEvent(ND::TND280Event &)
Is called after the first event is loaded in.
std::string fCVSTagName
Defined if an official tagged version.
ESubdetector PathToSubdetector(const std::string path)
Int_t ID
A number which uniquely identifies this vertex within the event. This ID is the interface between the...
Double_t Fiducial
The distance inside the local fiducial volume [mm]. Not currently set for any detector other than the...
TLorentzVector Position
Position and time of the vertex.
TTruthVerticesModule(const char *name="Vertices", const char *title="True Primary Vertex information")
Int_t NPrimaryTraj
The number of primary trajectories (ie: the number of primary particles exiting the interaction verte...
virtual bool FillTree(ND::TND280Event &)
Fill all the stuff that goes in the output 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