9 #include <cdc/modules/cdcCosmicSelectorAfterFullSim/CDCCosmicSelectorAfterFullSimModule.h>
10 #include <framework/logging/Logger.h>
11 #include <framework/datastore/RelationArray.h>
12 #include <framework/datastore/RelationIndex.h>
24 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.");
25 setPropertyFlags(c_ParallelProcessingCertified);
27 addParam(
"xOfRegion", m_xOfRegion,
"x of center position of region at y=0 (cm)", 0.);
28 addParam(
"zOfRegion", m_zOfRegion,
"z of center position of region at y=0 (cm)", 0.);
29 addParam(
"wOfRegion", m_wOfRegion,
"full-width (x-direction) of region at y=0 (cm)", 10.);
30 addParam(
"lOfRegion", m_lOfRegion,
"full-length (z-direction) of region at y=0 (cm)", 100.);
33 void CDCCosmicSelectorAfterFullSimModule::initialize()
35 m_mcParticles.isRequired();
36 m_simHits.isRequired();
40 void CDCCosmicSelectorAfterFullSimModule::event()
43 RelationArray mcParticlesToCDCSimHits(m_mcParticles, m_simHits);
45 bool returnVal =
false;
50 int nHits = m_simHits.getEntries();
52 B2DEBUG(250,
"No .of CDCSimHits <= 1 in the current event.");
54 setReturnValue(returnVal);
58 int nMCPs = m_mcParticles.getEntries();
60 B2ERROR(
"No. of MCParticles=0 in the current event.");
61 setReturnValue(returnVal);
66 unsigned nPrimChgds = 0;
67 for (
int iMCP = 0; iMCP < nMCPs; ++iMCP) {
73 unsigned pid = abs(m_P->
getPDG());
76 }
else if (pid == 11) {
79 }
else if (pid == 211) {
82 }
else if (pid == 321) {
85 }
else if (pid == 2212) {
93 if (nPrimChgds > 1)
continue;
123 double tof_up = -9999.;
124 double tof_dn = 9999.;
128 if (!mcp_to_hit) B2FATAL(
"No MCParticle->CDCSimHit relation found!");
135 unsigned iHitold = 0 ;
136 bool crossfind =
false;
138 for (
int iHit = 0; iHit < nHits; ++iHit) {
139 if (crossfind)
break;
142 if ((rel.from->getIndex() - 1) != iMCP)
continue;
144 if (rel.weight < 0.)
continue;
145 const double y = m_simHits[iHit]->getPosTrack().Y();
146 const double tof = m_simHits[iHit]->getFlightTime();
157 if (y * yold >= 0.) {
185 if (ihit_up < 0 || ihit_dn < 0)
continue;
186 const TVector3 pos_up = m_simHits[ihit_up]->getPosTrack();
187 const TVector3 pos_dn = m_simHits[ihit_dn]->getPosTrack();
188 const TVector3 mom_up = m_simHits[ihit_up]->getMomentum();
189 const TVector3 mom_dn = m_simHits[ihit_dn]->getMomentum();
190 if (tof_up > tof_dn) B2WARNING(
"tof_up > tof_dn " << tof_up <<
" " << tof_dn);
194 const TVector3 dpos = pos_dn - pos_up;
195 double cx = dpos.X() / dpos.Mag();
196 double cy = dpos.Y() / dpos.Mag();
197 double cz = dpos.Z() / dpos.Mag();
198 double vx = pos_up.X();
199 double vy = pos_up.Y();
200 double vz = pos_up.Z();
201 if (tof_up > tof_dn) {
210 const double yi = 0.;
214 xi = (yi - vy) * (cx / cy) + vx;
215 zi = (yi - vy) * (cz / cy) + vz;
217 zi = -vx * (cz / cx) + vz;
220 bool hitRegion = (fabs(xi - m_xOfRegion) < 0.5 * m_wOfRegion && fabs(zi - m_zOfRegion) < 0.5 * m_lOfRegion) ?
true :
false;
226 double fl = (xi - vx) * (xi - vx) + (yi - vy) * (yi - vy) + (zi - vz) * (zi - vz);
239 double dT = tof_up + (tof_dn - tof_up) * fl / dpos.Mag();
240 if (tof_up > tof_dn) dT = tof_dn + (tof_up - tof_dn) * fl / dpos.Mag();
247 for (
int iHit = 0; iHit < nHits; ++iHit) {
250 const double oldgtime = m_simHits[iHit]->getGlobalTime();
251 m_simHits[iHit]->setFlightTime(oldgtime - dT);
252 m_simHits[iHit]->setGlobalTime(oldgtime - dT);
258 setReturnValue(returnVal);
A Class to store the Monte Carlo particle information.
int getPDG() const
Return PDG code of particle.
float getProductionTime() const
Return production time in ns.
void setProductionTime(float time)
Set production time.
Low-level class to create/modify relations between StoreArrays.
Class to store a single element of a relation.
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
range_to getElementsTo(const TO *to) const
Return a range of all elements pointing to the given object.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Abstract base class for different kinds of events.
Element type for the index.