10 #include <top/modules/TOPNtuple/TOPNtupleModule.h>
12 #include <top/geometry/TOPGeometryPar.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/datastore/StoreObjPtr.h>
19 #include <framework/gearbox/Const.h>
20 #include <framework/logging/Logger.h>
23 #include <framework/dataobjects/EventMetaData.h>
24 #include <framework/dataobjects/MCInitialParticles.h>
25 #include <mdst/dataobjects/Track.h>
26 #include <mdst/dataobjects/MCParticle.h>
27 #include <top/dataobjects/TOPLikelihood.h>
28 #include <top/dataobjects/TOPBarHit.h>
29 #include <tracking/dataobjects/ExtHit.h>
32 #include <TDirectory.h>
57 setDescription(
"Writes ntuple of TOPLikelihoods with tracking info into a root file");
60 addParam(
"outputFileName", m_outputFileName,
"Output file name",
61 string(
"TOPNtuple.root"));
65 TOPNtupleModule::~TOPNtupleModule()
69 void TOPNtupleModule::initialize()
71 TDirectory::TContext context;
72 m_file = TFile::Open(m_outputFileName.c_str(),
"RECREATE");
73 if (m_file->IsZombie()) {
74 B2FATAL(
"Couldn't open file '" << m_outputFileName <<
"' for writing!");
78 m_tree =
new TTree(
"top",
"TOP validation ntuple");
80 m_tree->Branch(
"evt", &m_top.evt,
"evt/I");
81 m_tree->Branch(
"run", &m_top.run,
"run/I");
83 m_tree->Branch(
"p", &m_top.p,
"p/F");
84 m_tree->Branch(
"cth", &m_top.cth,
"cth/F");
85 m_tree->Branch(
"phi", &m_top.phi,
"phi/F");
86 m_tree->Branch(
"pValue", &m_top.pValue,
"pValue/F");
88 m_tree->Branch(
"PDG", &m_top.PDG,
"PDG/I");
89 m_tree->Branch(
"motherPDG", &m_top.motherPDG,
"motherPDG/I");
90 m_tree->Branch(
"primary", &m_top.primary,
"primary/S");
91 m_tree->Branch(
"seen", &m_top.seen,
"seen/S");
92 m_tree->Branch(
"rhoProd", &m_top.rhoProd,
"rhoProd/F");
93 m_tree->Branch(
"zProd", &m_top.zProd,
"zProd/F");
94 m_tree->Branch(
"phiProd", &m_top.phiProd,
"phiProd/F");
95 m_tree->Branch(
"rhoDec", &m_top.rhoDec,
"rhoDec/F");
96 m_tree->Branch(
"zDec", &m_top.zDec,
"zDec/F");
97 m_tree->Branch(
"phiDec", &m_top.phiDec,
"phiDec/F");
99 m_tree->Branch(
"numPhot", &m_top.numPhot,
"numPhot/I");
100 m_tree->Branch(
"numBkg", &m_top.numBkg,
"numBkg/F");
101 m_tree->Branch(
"phot", &m_top.phot,
"e/F:mu:pi:K:p:d");
102 m_tree->Branch(
"logL", &m_top.logL,
"e/F:mu:pi:K:p:d");
104 m_tree->Branch(
"extHit", &m_top.extHit,
"moduleID/I:PDG:x/F:y:z:p:theta:phi:time");
105 m_tree->Branch(
"barHit", &m_top.barHit,
"moduleID/I:PDG:x/F:y:z:p:theta:phi:time");
121 void TOPNtupleModule::beginRun()
125 void TOPNtupleModule::event()
131 double trueEventT0 = 0;
132 if (mcInitialParticles.
isValid()) trueEventT0 = mcInitialParticles->getTime();
134 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
136 for (
const auto& track : tracks) {
137 const auto* trackFit = track.getTrackFitResultWithClosestMass(Const::pion);
138 if (!trackFit)
continue;
141 if (top->getFlag() != 1)
continue;
147 if (mcParticle) mother = mcParticle->getMother();
151 m_top.evt = evtMetaData->getEvent();
152 m_top.run = evtMetaData->getRun();
154 TVector3 mom = trackFit->getMomentum();
156 m_top.cth = mom.CosTheta();
157 m_top.phi = mom.Phi();
158 m_top.pValue = trackFit->getPValue();
161 m_top.PDG = mcParticle->getPDG();
162 if (mother) m_top.motherPDG = mother->getPDG();
163 m_top.primary = mcParticle->getStatus(MCParticle::c_PrimaryParticle);
164 m_top.seen = mcParticle->hasSeenInDetector(Const::TOP);
165 TVector3 prodVertex = mcParticle->getProductionVertex();
166 m_top.rhoProd = prodVertex.Perp();
167 m_top.zProd = prodVertex.Z();
168 m_top.phiProd = prodVertex.Phi();
169 TVector3 decVertex = mcParticle->getDecayVertex();
170 m_top.rhoDec = decVertex.Perp();
171 m_top.zDec = decVertex.Z();
172 m_top.phiDec = decVertex.Phi();
175 m_top.numPhot = top->getNphot();
176 m_top.numBkg = top->getEstBkg();
177 m_top.phot.e = top->getEstPhot(Const::electron);
178 m_top.phot.mu = top->getEstPhot(Const::muon);
179 m_top.phot.pi = top->getEstPhot(Const::pion);
180 m_top.phot.K = top->getEstPhot(Const::kaon);
181 m_top.phot.p = top->getEstPhot(Const::proton);
182 m_top.phot.d = top->getEstPhot(Const::deuteron);
184 m_top.logL.e = top->getLogL(Const::electron);
185 m_top.logL.mu = top->getLogL(Const::muon);
186 m_top.logL.pi = top->getLogL(Const::pion);
187 m_top.logL.K = top->getLogL(Const::kaon);
188 m_top.logL.p = top->getLogL(Const::proton);
189 m_top.logL.d = top->getLogL(Const::deuteron);
195 if (geo->isModuleIDValid(moduleID)) {
196 const auto& module = geo->getModule(moduleID);
197 position = module.pointToLocal(position);
198 momentum = module.momentumToLocal(momentum);
200 m_top.extHit.moduleID = moduleID;
202 m_top.extHit.x = position.X();
203 m_top.extHit.y = position.Y();
204 m_top.extHit.z = position.Z();
205 m_top.extHit.p = momentum.Mag();
206 m_top.extHit.theta = momentum.Theta();
207 m_top.extHit.phi = momentum.Phi();
208 m_top.extHit.time = extHit->
getTOF();
212 int moduleID = barHit->getModuleID();
213 TVector3 position = barHit->getPosition();
214 TVector3 momentum = barHit->getMomentum();
215 if (geo->isModuleIDValid(moduleID)) {
216 const auto& module = geo->getModule(moduleID);
217 position = module.pointToLocal(position);
218 momentum = module.momentumToLocal(momentum);
220 m_top.barHit.moduleID = moduleID;
221 m_top.barHit.PDG = barHit->getPDG();
222 m_top.barHit.x = position.X();
223 m_top.barHit.y = position.Y();
224 m_top.barHit.z = position.Z();
225 m_top.barHit.p = momentum.Mag();
226 m_top.barHit.theta = momentum.Theta();
227 m_top.barHit.phi = momentum.Phi();
228 m_top.barHit.time = barHit->getTime() - trueEventT0;
237 void TOPNtupleModule::endRun()
241 void TOPNtupleModule::terminate()
243 TDirectory::TContext context;
Store one Ext hit as a ROOT object.
int getPdgCode() const
Get PDG code of this extrapolation's hypothesis.
TVector3 getMomentum() const
Get momentum at this extrapolation hit.
int getCopyID() const
Get detector-element ID of sensitive element within detector.
TVector3 getPosition() const
Get position of this extrapolation hit.
double getTOF() const
Get time of flight from the point of closest approach near the origin to this hit.
A Class to store the Monte Carlo particle information.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Accessor to arrays stored in the data store.
Type-safe access to single objects in the data store.
bool isValid() const
Check whether the object was created.
Class to store track parameters of incoming MC particles relation to MCParticle filled in top/simulat...
Class to store TOP log likelihoods (output of TOPReconstructor).
Module to write out a ntuple summarizing TOP reconstruction output.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.