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.");
30 addParam(
"lOfRegion",
m_lOfRegion,
"full-length (z-direction) of region at y=0 (cm)", 100.);
45 bool returnVal =
false;
52 B2DEBUG(250,
"No .of CDCSimHits <= 1 in the current event.");
60 B2ERROR(
"No. of MCParticles=0 in the current event.");
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;
190 if (tof_up > tof_dn) B2WARNING(
"tof_up > tof_dn " << tof_up <<
" " << tof_dn);
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;
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);
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.
range_to getElementsTo(const TO *to) const
Return a range of all elements pointing to the given object.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
int getEntries() const
Get the number of objects in the array.
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.
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.
Element type for the index.