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>
22 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.");
28 addParam(
"lOfRegion",
m_lOfRegion,
"full-length (z-direction) of region at y=0 (cm)", 100.);
43 bool returnVal =
false;
50 B2DEBUG(250,
"No .of CDCSimHits <= 1 in the current event.");
58 B2ERROR(
"No. of MCParticles=0 in the current event.");
64 unsigned nPrimChgds = 0;
65 for (
int iMCP = 0; iMCP < nMCPs; ++iMCP) {
71 unsigned pid = abs(m_P->
getPDG());
74 }
else if (pid == 11) {
77 }
else if (pid == 211) {
80 }
else if (pid == 321) {
83 }
else if (pid == 2212) {
91 if (nPrimChgds > 1)
continue;
121 double tof_up = -9999.;
122 double tof_dn = 9999.;
126 if (!mcp_to_hit) B2FATAL(
"No MCParticle->CDCSimHit relation found!");
133 unsigned iHitold = 0 ;
134 bool crossfind =
false;
136 for (
int iHit = 0; iHit < nHits; ++iHit) {
137 if (crossfind)
break;
140 if ((rel.from->getIndex() - 1) != iMCP)
continue;
142 if (rel.weight < 0.)
continue;
143 const double y =
m_simHits[iHit]->getPosTrack().Y();
144 const double tof =
m_simHits[iHit]->getFlightTime();
155 if (y * yold >= 0.) {
183 if (ihit_up < 0 || ihit_dn < 0)
continue;
188 if (tof_up > tof_dn) B2WARNING(
"tof_up > tof_dn " << tof_up <<
" " << tof_dn);
193 double cx = dpos.
X() / dpos.
Mag();
194 double cy = dpos.
Y() / dpos.
Mag();
195 double cz = dpos.
Z() / dpos.
Mag();
196 double vx = pos_up.
X();
197 double vy = pos_up.
Y();
198 double vz = pos_up.
Z();
199 if (tof_up > tof_dn) {
208 const double yi = 0.;
212 xi = (yi - vy) * (cx / cy) + vx;
213 zi = (yi - vy) * (cz / cy) + vz;
215 zi = -vx * (cz / cx) + vz;
224 double fl = (xi - vx) * (xi - vx) + (yi - vy) * (yi - vy) + (zi - vz) * (zi - vz);
237 double dT = tof_up + (tof_dn - tof_up) * fl / dpos.
Mag();
238 if (tof_up > tof_dn) dT = tof_dn + (tof_up - tof_dn) * fl / dpos.
Mag();
245 for (
int iHit = 0; iHit < nHits; ++iHit) {
248 const double oldgtime =
m_simHits[iHit]->getGlobalTime();
249 m_simHits[iHit]->setFlightTime(oldgtime - dT);
250 m_simHits[iHit]->setGlobalTime(oldgtime - dT);
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
DataType Mag() const
The magnitude (rho in spherical coordinate system).
void initialize() override
Initialize variables, print info, and start CPU clock.
void event() override
Actual digitization of all hits in the CDC.
double m_wOfRegion
full-width of region (cm)
StoreArray< CDCSimHit > m_simHits
array of CDCSimHit
double m_lOfRegion
full-length of region (cm)
StoreArray< MCParticle > m_mcParticles
array of MCParticle
CDCCosmicSelectorAfterFullSimModule()
Constructor.
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.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
void setReturnValue(int value)
Sets the return value for this module as integer.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
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.
RelationIndexContainer< FROM, TO >::Element Element
Struct representing a single element in the index.
range_to getElementsTo(const TO *to) const
Return a range of all elements pointing to the given object.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
B2Vector3< double > B2Vector3D
typedef for common usage with double
double sqrt(double a)
sqrt for double
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.