10 #include <ecl/modules/eclChargedPIDDataAnalysisExpert/ECLChargedPIDDataAnalysisModule.h>
11 #include <framework/datastore/RelationVector.h>
12 #include <framework/logging/Logger.h>
13 #include <framework/gearbox/Const.h>
15 #include <mdst/dataobjects/MCParticle.h>
16 #include <mdst/dataobjects/Track.h>
17 #include <ecl/dataobjects/ECLShower.h>
36 m_eclShowers(eclShowerArrayName()),
45 n1_eclShowerMultip(0),
46 n1_eclShowerEnergy(0),
50 n1_eclShowerHypothesisId(0),
51 n1_eclShowerAbsZernike40(0),
52 n1_eclShowerAbsZernike51(0),
80 n2_eclShowerMultip(0),
81 n2_eclShowerEnergy(0),
85 n2_eclShowerHypothesisId(0),
86 n2_eclShowerAbsZernike40(0),
87 n2_eclShowerAbsZernike51(0),
109 setDescription(
"This module produces an ntuple with ECL-related quantities starting from mdst");
110 addParam(
"writeToRoot", m_writeToRoot,
111 "set true if you want to save the informations in a root file named by parameter 'rootFileName'",
113 addParam(
"rootFileName", m_rootFileName,
114 "fileName used for root file where info are saved. Will be ignored if parameter 'writeToRoot' is false (standard)",
115 string(
"eclChargedPID"));
118 ECLChargedPIDDataAnalysisModule::~ECLChargedPIDDataAnalysisModule()
122 void ECLChargedPIDDataAnalysisModule::initialize()
124 B2INFO(
"[ECLChargedPIDDataAnalysis Module]: Starting initialization of ECLChargedPIDDataAnalysis Module.");
127 m_rootFilePtr =
new TFile(m_rootFileName.c_str(),
"RECREATE");
129 m_rootFilePtr =
nullptr;
132 n1_tree =
new TTree(
"n1_tree",
"ECL Charged PID tree: N1 Hypothesis");
134 n1_tree->Branch(
"expNo", &n1_iExperiment,
"expNo/I");
135 n1_tree->Branch(
"runNo", &n1_iRun,
"runNo/I");
136 n1_tree->Branch(
"evtNo", &n1_iEvent,
"evtNo/I");
139 n1_tree->Branch(
"eclShowerMultip", &n1_eclShowerMultip,
"eclShowerMultip/I");
140 n1_tree->Branch(
"eclShowerEnergy",
"std::vector<double>", &n1_eclShowerEnergy);
141 n1_tree->Branch(
"eclShowerTheta",
"std::vector<double>", &n1_eclShowerTheta);
142 n1_tree->Branch(
"eclShowerPhi",
"std::vector<double>", &n1_eclShowerPhi);
143 n1_tree->Branch(
"eclShowerR",
"std::vector<double>", &n1_eclShowerR);
144 n1_tree->Branch(
"eclShowerHypothesisId",
"std::vector<int>", &n1_eclShowerHypothesisId);
145 n1_tree->Branch(
"eclShowerAbsZernike40",
"std::vector<double>", &n1_eclShowerAbsZernike40);
146 n1_tree->Branch(
"eclShowerAbsZernike51",
"std::vector<double>", &n1_eclShowerAbsZernike51);
149 n1_tree->Branch(
"mcMultip", &n1_mcMultip,
"mcMultip/I");
150 n1_tree->Branch(
"mcPdg",
"std::vector<int>", &n1_mcPdg);
151 n1_tree->Branch(
"mcMothPdg",
"std::vector<int>", &n1_mcMothPdg);
152 n1_tree->Branch(
"mcEnergy",
"std::vector<double>", &n1_mcEnergy);
153 n1_tree->Branch(
"mcP",
"std::vector<double>", &n1_mcP);
154 n1_tree->Branch(
"mcTheta",
"std::vector<double>", &n1_mcTheta);
155 n1_tree->Branch(
"mcPhi",
"std::vector<double>", &n1_mcPhi);
158 n1_tree->Branch(
"trkMultip", &n1_trkMultip,
"trkMulti/I");
159 n1_tree->Branch(
"trkPdg",
"std::vector<int>", &n1_trkPdg);
160 n1_tree->Branch(
"trkCharge",
"std::vector<int>", &n1_trkCharge);
161 n1_tree->Branch(
"trkP",
"std::vector<double>", &n1_trkP);
162 n1_tree->Branch(
"trkTheta",
"std::vector<double>", &n1_trkTheta);
163 n1_tree->Branch(
"trkPhi",
"std::vector<double>", &n1_trkPhi);
165 n1_tree->Branch(
"eclEoP",
"std::vector<double>", &n1_eclEoP);
168 n2_tree =
new TTree(
"n2_tree",
"ECL Charged PID tree: N2 Hypothesis");
170 n2_tree->Branch(
"expNo", &n2_iExperiment,
"expNo/I");
171 n2_tree->Branch(
"runNo", &n2_iRun,
"runNo/I");
172 n2_tree->Branch(
"evtNo", &n2_iEvent,
"evtNo/I");
175 n2_tree->Branch(
"eclShowerMultip", &n2_eclShowerMultip,
"eclShowerMultip/I");
176 n2_tree->Branch(
"eclShowerEnergy",
"std::vector<double>", &n2_eclShowerEnergy);
177 n2_tree->Branch(
"eclShowerTheta",
"std::vector<double>", &n2_eclShowerTheta);
178 n2_tree->Branch(
"eclShowerPhi",
"std::vector<double>", &n2_eclShowerPhi);
179 n2_tree->Branch(
"eclShowerR",
"std::vector<double>", &n2_eclShowerR);
180 n2_tree->Branch(
"eclShowerHypothesisId",
"std::vector<int>", &n2_eclShowerHypothesisId);
181 n2_tree->Branch(
"eclShowerAbsZernike40",
"std::vector<double>", &n2_eclShowerAbsZernike40);
182 n2_tree->Branch(
"eclShowerAbsZernike51",
"std::vector<double>", &n2_eclShowerAbsZernike51);
185 n2_tree->Branch(
"mcMultip", &n2_mcMultip,
"mcMultip/I");
186 n2_tree->Branch(
"mcPdg",
"std::vector<int>", &n2_mcPdg);
187 n2_tree->Branch(
"mcMothPdg",
"std::vector<int>", &n2_mcMothPdg);
188 n2_tree->Branch(
"mcEnergy",
"std::vector<double>", &n2_mcEnergy);
189 n2_tree->Branch(
"mcP",
"std::vector<double>", &n2_mcP);
190 n2_tree->Branch(
"mcTheta",
"std::vector<double>", &n2_mcTheta);
191 n2_tree->Branch(
"mcPhi",
"std::vector<double>", &n2_mcPhi);
194 n2_tree->Branch(
"trkMultip", &n2_trkMultip,
"trkMulti/I");
195 n2_tree->Branch(
"trkPdg",
"std::vector<int>", &n2_trkPdg);
196 n2_tree->Branch(
"trkCharge",
"std::vector<int>", &n2_trkCharge);
197 n2_tree->Branch(
"trkP",
"std::vector<double>", &n2_trkP);
198 n2_tree->Branch(
"trkTheta",
"std::vector<double>", &n2_trkTheta);
199 n2_tree->Branch(
"trkPhi",
"std::vector<double>", &n2_trkPhi);
201 n2_tree->Branch(
"eclEoP",
"std::vector<double>", &n2_eclEoP);
203 B2INFO(
"[ECLChargedPIDDataAnalysis Module]: Initialization of ECLChargedPIDDataAnalysis Module completed.");
206 void ECLChargedPIDDataAnalysisModule::beginRun()
210 void ECLChargedPIDDataAnalysisModule::event()
213 B2DEBUG(1,
" ++++++++++++++ ECLChargedPIDDataAnalysisModule");
216 n1_eclShowerMultip = 0;
217 n1_eclShowerEnergy->clear();
218 n1_eclShowerTheta->clear();
219 n1_eclShowerPhi->clear();
220 n1_eclShowerR->clear();
221 n1_eclShowerHypothesisId->clear();
222 n1_eclShowerAbsZernike40->clear();
223 n1_eclShowerAbsZernike51->clear();
228 n1_mcMothPdg->clear();
229 n1_mcEnergy->clear();
237 n1_trkCharge->clear();
239 n1_trkTheta->clear();
245 n2_eclShowerMultip = 0;
246 n2_eclShowerEnergy->clear();
247 n2_eclShowerTheta->clear();
248 n2_eclShowerPhi->clear();
249 n2_eclShowerR->clear();
250 n2_eclShowerHypothesisId->clear();
251 n2_eclShowerAbsZernike40->clear();
252 n2_eclShowerAbsZernike51->clear();
257 n2_mcMothPdg->clear();
258 n2_mcEnergy->clear();
266 n2_trkCharge->clear();
268 n2_trkTheta->clear();
273 if (m_EventMetaData) {
274 n1_iExperiment = m_EventMetaData->getExperiment();
275 n1_iRun = m_EventMetaData->getRun();
276 n1_iEvent = m_EventMetaData->getEvent();
277 n2_iExperiment = m_EventMetaData->getExperiment();
278 n2_iRun = m_EventMetaData->getRun();
279 n2_iEvent = m_EventMetaData->getEvent();
290 for (
const MCParticle& imcpart : m_mcParticles) {
291 if (!imcpart.hasStatus(MCParticle::c_PrimaryParticle))
continue;
292 if (imcpart.hasStatus(MCParticle::c_Initial))
continue;
293 if (imcpart.hasStatus(MCParticle::c_IsVirtual))
continue;
299 n1_mcPdg->push_back(imcpart.getPDG());
300 if (imcpart.getMother() !=
nullptr) n1_mcMothPdg->push_back(imcpart.getMother()->getPDG());
301 else n1_mcMothPdg->push_back(-999);
302 n1_mcEnergy->push_back(imcpart.getEnergy());
303 n1_mcP->push_back(imcpart.getMomentum().Mag());
304 n1_mcTheta->push_back(imcpart.getMomentum().Theta());
305 n1_mcPhi->push_back(imcpart.getMomentum().Phi());
307 n2_mcPdg->push_back(imcpart.getPDG());
308 if (imcpart.getMother() !=
nullptr) n2_mcMothPdg->push_back(imcpart.getMother()->getPDG());
309 else n2_mcMothPdg->push_back(-999);
310 n2_mcEnergy->push_back(imcpart.getEnergy());
311 n2_mcP->push_back(imcpart.getMomentum().Mag());
312 n2_mcTheta->push_back(imcpart.getMomentum().Theta());
313 n2_mcPhi->push_back(imcpart.getMomentum().Phi());
317 int index_max_mom = -1;
319 for (
const auto& itrk : imcpart.getRelationsFrom<
Track>()) {
321 const TrackFitResult* atrkF = itrk.getTrackFitResult(Const::pion);
322 if (atrkF ==
nullptr)
continue;
325 index_max_mom = index;
329 if (index_max_mom == -1)
continue;
332 const auto itrack = imcpart.getRelationsFrom<
Track>()[index_max_mom];
334 const TrackFitResult* atrkF = itrack->getTrackFitResult(Const::pion);
340 n1_trkPdg->push_back(atrkF->getParticleType().getPDGCode());
341 n1_trkCharge->push_back(atrkF->getChargeSign());
342 n1_trkP->push_back(atrkF->getMomentum().Mag());
343 n1_trkTheta->push_back(atrkF->getMomentum().Theta());
344 n1_trkPhi->push_back(atrkF->getMomentum().Phi());
346 n2_trkPdg->push_back(atrkF->getParticleType().getPDGCode());
347 n2_trkCharge->push_back(atrkF->getChargeSign());
348 n2_trkP->push_back(atrkF->getMomentum().Mag());
349 n2_trkTheta->push_back(atrkF->getMomentum().Theta());
350 n2_trkPhi->push_back(atrkF->getMomentum().Phi());
354 int jndex1_max_e = -1;
356 for (
const auto& i1sh : itrack->getRelationsTo<
ECLShower>()) {
359 if (i1sh.getHypothesisId() != 5)
continue;
361 if (abs(i1sh.getTime()) > i1sh.getDeltaTime99())
continue;
362 if (i1sh.getEnergy() > max_e1) {
364 jndex1_max_e = jndex1;
368 int jndex2_max_e = -1;
370 for (
const auto& i2sh : itrack->getRelationsTo<
ECLShower>()) {
373 if (i2sh.getHypothesisId() != 6)
continue;
375 if (abs(i2sh.getTime()) > i2sh.getDeltaTime99())
continue;
376 if (i2sh.getEnergy() > max_e2) {
377 max_e2 = i2sh.getEnergy();
378 jndex2_max_e = jndex2;
383 if (jndex1_max_e != -1) {
384 const auto i1shower = itrack->getRelationsTo<
ECLShower>()[jndex1_max_e];
386 n1_eclShowerEnergy->push_back(i1shower->getEnergy());
387 n1_eclShowerTheta->push_back(i1shower->getTheta());
388 n1_eclShowerPhi->push_back(i1shower->getPhi());
389 n1_eclShowerR->push_back(i1shower->getR());
390 n1_eclShowerHypothesisId->push_back(i1shower->getHypothesisId());
392 n1_eclShowerAbsZernike40->push_back(i1shower->getAbsZernike40());
393 n1_eclShowerAbsZernike51->push_back(i1shower->getAbsZernike51());
395 n1_eclEoP->push_back((i1shower->getEnergy()) / (atrkF->getMomentum().Mag()));
396 n1_eclShowerMultip++;
398 if (jndex2_max_e != -1) {
401 n2_eclShowerEnergy->push_back(i2shower->getEnergy());
402 n2_eclShowerTheta->push_back(i2shower->getTheta());
403 n2_eclShowerPhi->push_back(i2shower->getPhi());
404 n2_eclShowerR->push_back(i2shower->getR());
405 n2_eclShowerHypothesisId->push_back(i2shower->getHypothesisId());
407 n2_eclShowerAbsZernike40->push_back(i2shower->getAbsZernike40());
408 n2_eclShowerAbsZernike51->push_back(i2shower->getAbsZernike51());
410 n2_eclEoP->push_back((i2shower->getEnergy()) / (atrkF->getMomentum().Mag()));
411 n2_eclShowerMultip++;
420 void ECLChargedPIDDataAnalysisModule::endRun()
424 void ECLChargedPIDDataAnalysisModule::terminate()
426 if (m_rootFilePtr !=
nullptr) {
The ECL Charged PID Data Analysis Module.
Class to store ECL Showers.
A Class to store the Monte Carlo particle information.
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Values of the result of a track fit with a given particle hypothesis.
double getEnergy() const
Getter for the Energy at the closest approach of the track in the r/phi projection.
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
Class that bundles various TrackFitResults.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.