5 #include <TClonesArray.h>
7 #include <TG4PrimaryParticle.hxx>
8 #include <TG4PrimaryVertex.hxx>
9 #include <TGeometryId.hxx>
11 #include <TGeomInfo.hxx>
12 #include <TP0DGeom.hxx>
21 $Id: eventAnalysis TTruthVerticesModule.cxx,2024/03/20:09:46:11,Alexander_J_Finch,lapw.lancs.ac.uk $"
37 fNVtxRestOfOffAxis(0),
40 fVertices(new TClonesArray(
"ND::TTruthVerticesModule::TTruthVertex",
44 fDescription =
"Module storing the truth information for primary vertices";
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");
71 fOutputTree->Branch(
"Vertices",
"TClonesArray", &fVertices, fBufferSize,
72 fSplitLevel)->SetTitle(
"The TClonesArray storing the TTruthVertex objects holding the information relating to each vertex.");
76 bool IsDataFile =
event.GetContext().IsDetector();
78 throw ND::EDataFile();
84 if (!event.GetContext().IsMC()) {
86 "Event Context reports event is non-MC. Assuming entire file is "
103 fNVtxRestOfOffAxis = 0;
108 if (!event.Has<ND::TG4PrimaryVertexContainer>(
"truth/G4PrimVertex00")) {
109 ND280Warn(
"No vertices container found, skipping event.");
113 const ND::THandle<ND::TG4PrimaryVertexContainer>& vertices =
114 event.Get<ND::TG4PrimaryVertexContainer>(
"truth/G4PrimVertex00");
116 std::vector<ND::TG4PrimaryVertex>::const_iterator vertices_it =
118 std::vector<ND::TG4PrimaryVertex>::const_iterator vertices_end;
120 if (vertices->size() <= fMaxNVertices) {
121 vertices_end = vertices->end();
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;
130 for (; vertices_it != vertices_end; ++vertices_it) {
138 vtxToFill->
ID = vertices_it->GetInteractionNumber();
139 vtxToFill->
Position = vertices_it->GetPosition();
140 vtxToFill->
Generator = vertices_it->GetGeneratorName();
143 TLorentzVector pos = vertices_it->GetPosition();
145 gGeoManager->FindNode(pos.X(), pos.Y(), pos.Z());
146 std::string path = gGeoManager->GetPath();
167 TGeomInfo::P0D().WaterFiducialDistance(pos.X(), pos.Y(), pos.Z()) *
205 ++fNVtxRestOfOffAxis;
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();
229 for (; primaries_it != primaries_end; ++primaries_it) {
243 bool found_neutrino =
false;
244 bool found_target =
false;
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();
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();
259 for (; particles_it != particles_end; ++particles_it) {
260 if (particles_it->GetTrackId() ==
263 temp_pdg = particles_it->GetPDGCode();
273 found_neutrino =
true;
281 if (found_neutrino && found_target)
break;
284 if (found_neutrino && found_target)
break;
302 Position(-999999.9, -999999.9, -999999.9, -999999.9),
303 Generator(
"Not Set"),
304 ReactionCode(
"Not Set"),
309 NeutrinoMomentum(-999999.9, -999999.9, -999999.9, -999999.9),
311 TargetMomentum(-999999.9, -999999.9, -999999.9, -999999.9) {}
321 static_cast<const ND::TTruthVerticesModule::TTruthVertex*>(obj)->ID) {
323 }
else if (this->ID >
324 static_cast<const ND::TTruthVerticesModule::TTruthVertex*>(obj)
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)
std::string Generator
The generator that created the vertex. eg: "genie:mean@free-spill".
Int_t NeutrinoPDG
The PDG number of the incoming neutrino. Set to 0 in the absence of a neutrino.
virtual ~TTruthVerticesModule()
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.
Bool_t IsGeantinoVtx(ND::TG4PrimaryVertex vtx)
std::string ReactionCode
The Reaction code according to the generator For Genie this will be of the form: "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...
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' 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'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.