13 #include "CRYParticle.h" 14 #include "CRYGenerator.h" 17 #include "TDatabasePDG.h" 18 #include "TLorentzVector.h" 19 #include "TGeoManager.h" 25 #include "cetlib_except/exception.h" 42 CLHEP::HepRandomEngine& engine,
43 std::string
const& worldVol)
55 std::string config(
"date 1-1-2014 ");
59 config += pset.
get< std::string >(
"GammaSetting",
"returnGammas 1 ");
60 config += pset.
get< std::string >(
"ElectronSetting",
"returnElectrons 1 ");
61 config += pset.
get< std::string >(
"MuonSetting",
"returnMuons 1 ");
62 config += pset.
get< std::string >(
"PionSetting",
"returnPions 1 ");
63 config += pset.
get< std::string >(
"NeutronSetting",
"returnNeutrons 1 ");
64 config += pset.
get< std::string >(
"ProtonSetting",
"returnProtons 1 ");
70 std::string crydatadir;
71 const char* datapath = getenv(
"CRYDATAPATH");
72 if( datapath != 0) crydatadir = datapath;
74 mf::LogError(
"CRYHelper") <<
"no variable CRYDATAPATH set for cry data location, bail";
79 fSetup =
new CRYSetup(config, crydatadir);
98 double const& surfaceY,
99 double const& detectorLength,
104 double tstart =
fGen->timeSimulated();
106 bool particlespushed =
false;
108 std::vector<CRYParticle*> parts;
109 fGen->genEvent(&parts);
110 for (
unsigned int i=0; i<parts.size(); ++i) {
113 std::unique_ptr<CRYParticle> cryp(parts[i]);
116 int pdg = cryp->PDGid();
119 double ke = cryp->ke()*1.0E-3;
124 static TDatabasePDG* pdgt = TDatabasePDG::Instance();
125 TParticlePDG* pdgp = pdgt->GetParticle(pdg);
126 if (pdgp) m = pdgp->Mass();
128 double etot = ke + m;
129 double ptot = etot*etot-m*m;
130 if (ptot>0.0) ptot = sqrt(ptot);
135 double px = ptot * cryp->v();
136 double py = ptot * cryp->w();
137 double pz = ptot * cryp->u();
145 double vx = cryp->y()*100.0;
146 double vy = cryp->z()*100.0 + surfaceY;
147 double vz = cryp->x()*100.0 + 0.5*detectorLength;
148 double t = cryp->t()-tstart +
fToffset;
152 double xyz[3] = { vx, vy, vz};
154 double dxyz[3] = {-px, -py, -pz};
161 this->
WorldBox(&x1, &x2, &y1, &y2, &z1, &z2);
163 MF_LOG_DEBUG(
"CRYHelper") << xyz[0] <<
" " << xyz[1] <<
" " << xyz[2] <<
" " 164 << x1 <<
" " << x2 <<
" " 165 << y1 <<
" " << y2 <<
" " 179 std::string primary(
"primary");
181 particlespushed=
true;
188 TLorentzVector pos(vx,vy,vz,t*1e9);
189 TLorentzVector mom(px,py,pz,etot);
208 return fGen->timeSimulated()-tstart;
226 double* ylo,
double* yhi,
227 double* zlo,
double* zhi)
const 229 const TGeoShape* s = gGeoManager->GetVolume(
fWorldVolume.c_str())->GetShape();
231 throw cet::exception(
"CRYHelper") <<
"No TGeoShape found for world volume";
235 s->GetAxisRange(1,x1,x2);
if (xlo) *xlo =
x1;
if (xhi) *xhi =
x2;
239 s->GetAxisRange(2,y1,y2);
if (ylo) *ylo =
y1;
if (yhi) *yhi =
y2;
243 s->GetAxisRange(3,z1,z2);
if (zlo) *zlo = z1;
if (zhi) *zhi = z2;
266 double &xlo,
double &xhi,
267 double &ylo,
double &yhi,
268 double &zlo,
double &zhi,
281 if(xyz[0] < xlo || xyz[0] > xhi ||
282 xyz[1] < ylo || xyz[1] > yhi ||
283 xyz[2] < zlo || xyz[2] > zhi)
284 throw cet::exception(
"CRYHelper") <<
"Projection to edge is outside" 285 <<
" bounds of world box:\n " 286 <<
"\tx: " << xyz[0] <<
" (" 287 << xlo <<
"," << xhi <<
")\n" 288 <<
"\ty: " << xyz[1] <<
" (" 289 << ylo <<
"," << yhi <<
")\n" 290 <<
"\tz: " << xyz[2] <<
" (" 291 << zlo <<
"," << zhi <<
")";
297 if (dxyz[0] > 0.0) { dx = (xhi-xyz[0])/dxyz[0]; }
298 else if (dxyz[0] < 0.0) { dx = (xlo-xyz[0])/dxyz[0]; }
299 if (dxyz[1] > 0.0) { dy = (yhi-xyz[1])/dxyz[1]; }
300 else if (dxyz[1] < 0.0) { dy = (ylo-xyz[1])/dxyz[1]; }
301 if (dxyz[2] > 0.0) { dz = (zhi-xyz[2])/dxyz[2]; }
302 else if (dxyz[2] < 0.0) { dz = (zlo-xyz[2])/dxyz[2]; }
306 if (dx < dy && dx < dz) d = dx;
307 else if (dy < dz && dy < dx) d = dy;
308 else if (dz < dx && dz < dy) d = dz;
311 for (
int i = 0; i < 3; ++i) {
312 xyzout[i] = xyz[i] + dxyz[i]*
d;
double fSampleTime
Amount of time to sample (seconds)
void WorldBox(double *xlo_cm, double *xhi_cm, double *ylo_cm, double *yhi_cm, double *zlo_cm, double *zhi_cm) const
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
Float_t y1[n_points_granero]
void SetOrigin(simb::Origin_t origin)
Float_t x1[n_points_granero]
CRYSetup * fSetup
CRY configuration.
void ProjectToBoxEdge(const double xyz[], const double dxyz[], double &xlo, double &xhi, double &ylo, double &yhi, double &zlo, double &zhi, double xyzout[])
std::string fLatitude
Latitude of detector need space after value.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
CRYGenerator * fGen
The CRY generator.
Float_t y2[n_points_geant4]
double Sample(simb::MCTruth &mctruth, double const &surfaceY, double const &detectorLength, double *w, double rantime=0)
std::string fWorldVolume
Name of the world volume.
static void set(T *object, double(T::*func)(void))
Interface to the CRY cosmic ray generator.
T get(std::string const &key) const
std::string fAltitude
Altitude of detector need space after value.
bool fSingleEventMode
flag to turn on producing only a single cosmic ray
std::string fSubBoxL
Length of subbox (m) need space after value.
double fEthresh
Cut on kinetic energy (GeV)
void Add(simb::MCParticle const &part)
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Physics generators for neutrinos, cosmic rays, and others.
Event generator information.
Float_t x2[n_points_geant4]
double fToffset
Shift in time of particles (s)
cet::coded_exception< error, detail::translate > exception