11 #include <cdc/modules/cdcCosmicSelectorAfterFullSim/CDCCosmicSelectorAfterFullSimModule.h>
12 #include <framework/logging/Logger.h>
13 #include <framework/datastore/RelationArray.h>
14 #include <framework/datastore/RelationIndex.h>
26 setDescription(
"Modify CDCSimHits and MCParticles for cosmics so that the global time is (approximately) zero at y=0 using FullSim output (=CDCSimHits). And select cosmics passing through a user-specified region at y=0. This module works only for the event with the no. of primary charged MC particles=1. Please place this module after FullSim and before CDCDigitizer. This module is not needed for normal MC; only needed when you want to evaluate performance of T0 extraction module.");
27 setPropertyFlags(c_ParallelProcessingCertified);
29 addParam(
"xOfRegion", m_xOfRegion,
"x of center position of region at y=0 (cm)", 0.);
30 addParam(
"zOfRegion", m_zOfRegion,
"z of center position of region at y=0 (cm)", 0.);
31 addParam(
"wOfRegion", m_wOfRegion,
"full-width (x-direction) of region at y=0 (cm)", 10.);
32 addParam(
"lOfRegion", m_lOfRegion,
"full-length (z-direction) of region at y=0 (cm)", 100.);
35 void CDCCosmicSelectorAfterFullSimModule::initialize()
37 m_mcParticles.isRequired();
38 m_simHits.isRequired();
42 void CDCCosmicSelectorAfterFullSimModule::event()
45 RelationArray mcParticlesToCDCSimHits(m_mcParticles, m_simHits);
47 bool returnVal =
false;
52 int nHits = m_simHits.getEntries();
54 B2DEBUG(250,
"No .of CDCSimHits <= 1 in the current event.");
56 setReturnValue(returnVal);
60 int nMCPs = m_mcParticles.getEntries();
62 B2ERROR(
"No. of MCParticles=0 in the current event.");
63 setReturnValue(returnVal);
68 unsigned nPrimChgds = 0;
69 for (
int iMCP = 0; iMCP < nMCPs; ++iMCP) {
75 unsigned pid = abs(m_P->
getPDG());
78 }
else if (pid == 11) {
81 }
else if (pid == 211) {
84 }
else if (pid == 321) {
87 }
else if (pid == 2212) {
95 if (nPrimChgds > 1)
continue;
125 double tof_up = -9999.;
126 double tof_dn = 9999.;
130 if (!mcp_to_hit) B2FATAL(
"No MCParticle->CDCSimHit relation found!");
137 unsigned iHitold = 0 ;
138 bool crossfind =
false;
140 for (
int iHit = 0; iHit < nHits; ++iHit) {
141 if (crossfind)
break;
144 if ((rel.from->getIndex() - 1) != iMCP)
continue;
146 if (rel.weight < 0.)
continue;
147 const double y = m_simHits[iHit]->getPosTrack().Y();
148 const double tof = m_simHits[iHit]->getFlightTime();
159 if (y * yold >= 0.) {
187 if (ihit_up < 0 || ihit_dn < 0)
continue;
188 const TVector3 pos_up = m_simHits[ihit_up]->getPosTrack();
189 const TVector3 pos_dn = m_simHits[ihit_dn]->getPosTrack();
190 const TVector3 mom_up = m_simHits[ihit_up]->getMomentum();
191 const TVector3 mom_dn = m_simHits[ihit_dn]->getMomentum();
192 if (tof_up > tof_dn) B2WARNING(
"tof_up > tof_dn " << tof_up <<
" " << tof_dn);
196 const TVector3 dpos = pos_dn - pos_up;
197 double cx = dpos.X() / dpos.Mag();
198 double cy = dpos.Y() / dpos.Mag();
199 double cz = dpos.Z() / dpos.Mag();
200 double vx = pos_up.X();
201 double vy = pos_up.Y();
202 double vz = pos_up.Z();
203 if (tof_up > tof_dn) {
212 const double yi = 0.;
216 xi = (yi - vy) * (cx / cy) + vx;
217 zi = (yi - vy) * (cz / cy) + vz;
219 zi = -vx * (cz / cx) + vz;
222 bool hitRegion = (fabs(xi - m_xOfRegion) < 0.5 * m_wOfRegion && fabs(zi - m_zOfRegion) < 0.5 * m_lOfRegion) ?
true :
false;
228 double fl = (xi - vx) * (xi - vx) + (yi - vy) * (yi - vy) + (zi - vz) * (zi - vz);
241 double dT = tof_up + (tof_dn - tof_up) * fl / dpos.Mag();
242 if (tof_up > tof_dn) dT = tof_dn + (tof_up - tof_dn) * fl / dpos.Mag();
249 for (
int iHit = 0; iHit < nHits; ++iHit) {
252 const double oldgtime = m_simHits[iHit]->getGlobalTime();
253 m_simHits[iHit]->setFlightTime(oldgtime - dT);
254 m_simHits[iHit]->setGlobalTime(oldgtime - dT);
260 setReturnValue(returnVal);