15 #include <arich/modules/arichNtuple/ARICHNtupleModule.h>
18 #include <framework/dataobjects/EventMetaData.h>
19 #include <arich/dataobjects/ARICHLikelihood.h>
20 #include <arich/dataobjects/ARICHAeroHit.h>
21 #include <arich/dataobjects/ARICHTrack.h>
22 #include <arich/dataobjects/ARICHPhoton.h>
23 #include <arich/dataobjects/ARICHHit.h>
24 #include <arich/dataobjects/ARICHInfo.h>
27 #include <framework/datastore/StoreObjPtr.h>
29 #include <mdst/dataobjects/HitPatternCDC.h>
31 #ifdef ALIGNMENT_USING_BHABHA
32 #include <mdst/dataobjects/ECLCluster.h>
36 #include <framework/gearbox/Const.h>
37 #include <framework/logging/Logger.h>
66 setDescription(
"The module saves variables needed for performance analysis, such as postion and momentum of the hit, likelihoods for hypotheses and number of photons.");
69 addParam(
"outputFile", m_outputFile,
"ROOT output file name",
string(
"ARICHNtuple.root"));
72 ARICHNtupleModule::~ARICHNtupleModule()
76 void ARICHNtupleModule::initialize()
79 if (m_file)
delete m_file;
80 m_file =
new TFile(m_outputFile.c_str(),
"RECREATE");
81 if (m_file->IsZombie()) {
82 B2FATAL(
"Couldn't open file '" << m_outputFile <<
"' for writing!");
86 m_tree =
new TTree(
"arich",
"ARICH validation ntuple");
88 m_tree->Branch(
"evt", &m_arich.evt,
"evt/I");
89 m_tree->Branch(
"run", &m_arich.run,
"run/I");
90 m_tree->Branch(
"exp", &m_arich.exp,
"exp/I");
92 m_tree->Branch(
"charge", &m_arich.charge,
"charge/S");
93 m_tree->Branch(
"pValue", &m_arich.pValue,
"pValue/F");
94 m_tree->Branch(
"d0", &m_arich.z0,
"pValue/F");
95 m_tree->Branch(
"z0", &m_arich.d0,
"pValue/F");
97 #ifdef ALIGNMENT_USING_BHABHA
98 m_tree->Branch(
"eop", &m_arich.eop,
"eop/F");
99 m_tree->Branch(
"e9e21", &m_arich.e9e21,
"e9e21/F");
100 m_tree->Branch(
"etot", &m_arich.etot,
"etot/F");
103 m_tree->Branch(
"PDG", &m_arich.PDG,
"PDG/I");
104 m_tree->Branch(
"motherPDG", &m_arich.motherPDG,
"motherPDG/I");
105 m_tree->Branch(
"primary", &m_arich.primary,
"primary/S");
106 m_tree->Branch(
"seen", &m_arich.seen,
"seen/S");
107 m_tree->Branch(
"scatter", &m_arich.scatter,
"scatter/I");
109 m_tree->Branch(
"rhoProd", &m_arich.rhoProd,
"rhoProd/F");
110 m_tree->Branch(
"zProd", &m_arich.zProd,
"zProd/F");
111 m_tree->Branch(
"phiProd", &m_arich.phiProd,
"phiProd/F");
112 m_tree->Branch(
"rhoDec", &m_arich.rhoDec,
"rhoDec/F");
113 m_tree->Branch(
"zDec", &m_arich.zDec,
"zDec/F");
114 m_tree->Branch(
"phiDec", &m_arich.phiDec,
"phiDec/F");
115 m_tree->Branch(
"status", &m_arich.status,
"status/I");
117 m_tree->Branch(
"detPhot", &m_arich.detPhot,
"detPhot/I");
118 m_tree->Branch(
"numBkg", &m_arich.numBkg,
"e/F:mu:pi:K:p:d");
119 m_tree->Branch(
"expPhot", &m_arich.expPhot,
"e/F:mu:pi:K:p:d");
120 m_tree->Branch(
"logL", &m_arich.logL,
"e/F:mu:pi:K:p:d");
122 m_tree->Branch(
"recHit", &m_arich.recHit,
"PDG/I:x/F:y:z:p:theta:phi");
123 m_tree->Branch(
"mcHit", &m_arich.mcHit,
"PDG/I:x/F:y:z:p:theta:phi");
124 m_tree->Branch(
"winHit", &m_arich.winHit,
"x/F:y");
125 m_tree->Branch(
"nrec", &m_arich.nRec,
"nRec/I");
126 m_tree->Branch(
"nCDC", &m_arich.nCDC,
"nCDC/I");
127 m_tree->Branch(
"inAcceptance", &m_arich.inAcc,
"inAcc/O");
128 m_tree->Branch(
"photons",
"std::vector<Belle2::ARICHPhoton>", &m_arich.photons);
131 m_arichTracks.isRequired();
132 m_arichLikelihoods.isRequired();
135 m_tracks.isOptional();
136 m_arichMCPs.isOptional();
137 m_arichAeroHits.isOptional();
138 m_arichInfo.isOptional();
141 arichHits.isRequired();
145 void ARICHNtupleModule::beginRun()
149 void ARICHNtupleModule::event()
155 if (!m_arichTracks.isValid())
return;
157 #ifdef ALIGNMENT_USING_BHABHA
160 for (
const auto& trk : m_tracks) {
166 for (
const auto& cluster : eclClusters) {
167 if (!cluster.isNeutral())
continue;
168 if (cluster.getHypothesisId() != 5 && cluster.getHypothesisId() != 1)
170 if (cluster.getEnergy() > 0.1) E_tot += cluster.getEnergy();
174 for (
const auto& arichTrack : m_arichTracks) {
178 const Track* mdstTrack = NULL;
191 m_arich.evt = evtMetaData->getEvent();
192 m_arich.run = evtMetaData->getRun();
193 m_arich.exp = evtMetaData->getExperiment();
196 if (arichTrack.hitsWindow()) {
197 TVector2 winHit = arichTrack.windowHitPosition();
198 m_arich.winHit[0] = winHit.X();
199 m_arich.winHit[1] = winHit.Y();
202 if (lkh->
getFlag() == 1) m_arich.inAcc = 1;
203 m_arich.logL.e = lkh->
getLogL(Const::electron);
204 m_arich.logL.mu = lkh->
getLogL(Const::muon);
205 m_arich.logL.pi = lkh->
getLogL(Const::pion);
206 m_arich.logL.K = lkh->
getLogL(Const::kaon);
207 m_arich.logL.p = lkh->
getLogL(Const::proton);
208 m_arich.logL.d = lkh->
getLogL(Const::deuteron);
210 m_arich.expPhot.e = lkh->
getExpPhot(Const::electron);
211 m_arich.expPhot.mu = lkh->
getExpPhot(Const::muon);
212 m_arich.expPhot.pi = lkh->
getExpPhot(Const::pion);
213 m_arich.expPhot.K = lkh->
getExpPhot(Const::kaon);
214 m_arich.expPhot.p = lkh->
getExpPhot(Const::proton);
215 m_arich.expPhot.d = lkh->
getExpPhot(Const::deuteron);
219 #ifdef ALIGNMENT_USING_BHABHA
220 m_arich.etot = E_tot;
225 if (m_arichInfo.getEntries() > 0) {
226 auto arichInfo = *m_arichInfo[0];
227 m_arich.trgtype = arichInfo.gettrgtype();
233 const TrackFitResult* fitResult = mdstTrack->getTrackFitResultWithClosestMass(Const::pion);
238 m_arich.z0 = trkPos.Z();
239 m_arich.d0 = (trkPos.XYvector()).Mod();
241 #ifdef ALIGNMENT_USING_BHABHA
245 m_arich.eop = eclTrack->
getEnergy() / trkMom.Mag();
250 m_arich.status += 10;
251 int fromARICHMCP = 0;
252 particle = mdstTrack->getRelated<
MCParticle>();
253 if (!particle) { particle = mdstTrack->getRelated<
MCParticle>(
"arichMCParticles"); fromARICHMCP = 1;}
255 m_arich.PDG = particle->getPDG();
256 m_arich.primary = particle->getStatus(MCParticle::c_PrimaryParticle);
257 m_arich.seen = particle->hasSeenInDetector(Const::ARICH);
258 TVector3 prodVertex = particle->getProductionVertex();
259 m_arich.rhoProd = prodVertex.Perp();
260 m_arich.zProd = prodVertex.Z();
261 m_arich.phiProd = prodVertex.Phi();
262 TVector3 decVertex = particle->getDecayVertex();
263 m_arich.rhoDec = decVertex.Perp();
264 m_arich.zDec = decVertex.Z();
265 m_arich.phiDec = decVertex.Phi();
269 if (mother) m_arich.motherPDG = mother->getPDG();
270 std::vector<Belle2::MCParticle*> daughs = particle->getDaughters();
271 for (
const auto daugh : daughs) {
272 if (daugh == NULL)
continue;
273 if (daugh->getPDG() == particle->getPDG()) m_arich.scatter = 1;
281 const std::vector<ARICHPhoton>& photons = arichTrack.getPhotons();
282 m_arich.nRec = photons.size();
284 for (
auto it = photons.begin(); it != photons.end(); ++it) {
286 if (iph.
getHitID() < arichHits.getEntries()) {
287 auto ihit = *arichHits[iph.
getHitID()];
288 int module = ihit.getModule();
289 int channel = ihit.getChannel();
290 int chid = 1 << 16 | module << 8 | channel;
293 m_arich.photons.push_back(iph);
297 TVector3 recPos = arichTrack.getPosition();
298 m_arich.recHit.x = recPos.X();
299 m_arich.recHit.y = recPos.Y();
300 m_arich.recHit.z = recPos.Z();
302 TVector3 recMom = arichTrack.getDirection() * arichTrack.getMomentum();
303 m_arich.recHit.p = recMom.Mag();
304 m_arich.recHit.theta = recMom.Theta();
305 m_arich.recHit.phi = recMom.Phi();
308 TVector3 truePos = aeroHit->getPosition();
309 m_arich.mcHit.x = truePos.X();
310 m_arich.mcHit.y = truePos.Y();
311 m_arich.mcHit.z = truePos.Z();
313 TVector3 trueMom = aeroHit->getMomentum();
314 m_arich.mcHit.p = trueMom.Mag();
315 m_arich.mcHit.theta = trueMom.Theta();
316 m_arich.mcHit.phi = trueMom.Phi();
318 m_arich.mcHit.PDG = aeroHit->getPDG();
319 m_arich.status += 1000;
324 m_arich.PDG = particle->getPDG();
326 if (mother) m_arich.motherPDG = mother->getPDG();
327 m_arich.primary = particle->getStatus(MCParticle::c_PrimaryParticle);
328 m_arich.seen = particle->hasSeenInDetector(Const::ARICH);
329 TVector3 prodVertex = particle->getProductionVertex();
330 m_arich.rhoProd = prodVertex.Perp();
331 m_arich.zProd = prodVertex.Z();
332 m_arich.phiProd = prodVertex.Phi();
333 TVector3 decVertex = particle->getDecayVertex();
334 m_arich.rhoDec = decVertex.Perp();
335 m_arich.zDec = decVertex.Z();
336 m_arich.phiDec = decVertex.Phi();
338 std::vector<Belle2::MCParticle*> daughs = particle->getDaughters();
339 for (
const auto daugh : daughs) {
340 if (daugh->getPDG() == particle->getPDG()) m_arich.scatter = 1;
351 void ARICHNtupleModule::endRun()
355 void ARICHNtupleModule::terminate()