15 #include <CLHEP/Random/RandFlat.h>
16 #include <CLHEP/Random/RandGaussQ.h>
56 debug = conf_.getUntrackedParameter<
bool>(
"debug");
59 LogPrint(
"DTDigitizer") <<
"Creating a DTDigitizer" << endl;
64 produces<DTDigiCollection>();
66 produces<DTDigiSimLinkCollection>();
71 onlyMuHits = conf_.getParameter<
bool>(
"onlyMuHits");
74 interpolate = conf_.getParameter<
bool>(
"interpolate");
80 vPropWire = conf_.getParameter<
double>(
"vPropWire");
83 deadTime = conf_.getParameter<
double>(
"deadTime");
86 smearing = conf_.getParameter<
double>(
"Smearing");
90 IdealModel = conf_.getParameter<
bool>(
"IdealModel");
94 if (conf_.getParameter<
bool>(
"phase2Digis"))
101 theConstVDrift = conf_.getParameter<
double>(
"IdealModelConstantDriftVelocity");
103 theConstVDrift = 55.;
108 throw cms::Exception(
"Configuration") <<
"RandomNumberGeneratorService for DTDigitizer missing in cfg file";
118 mix_ = conf_.getParameter<
std::string>(
"mixLabel");
119 collection_for_XF = conf_.getParameter<
std::string>(
"InputCollection");
120 cf_token = consumes<CrossingFrame<PSimHit>>(
edm::InputTag(mix_, collection_for_XF));
121 muonGeom_token = esConsumes<DTGeometry, MuonGeometryRecord>(
edm::ESInputTag(
"", geometryType));
122 magnField_token = esConsumes<MagneticField, IdealMagneticFieldRecord>();
126 geometryType = conf_.getParameter<
std::string>(
"GeometryType");
135 LogPrint(
"DTDigitizer") <<
"--- Run: " <<
iEvent.id().run() <<
" Event: " <<
iEvent.id().event() << endl;
168 DTWireId wireId((*simHit).detUnitId());
170 wireMap[wireId].push_back(&(*
simHit));
173 pair<float, bool>
time(0.,
false);
179 const vector<const PSimHit *> &vhit = (*wire).second;
191 for (vector<const PSimHit *>::const_iterator
hit = vhit.begin();
hit != vhit.end();
hit++) {
201 tdCont.push_back(make_pair((*
hit),
time.first));
204 LogPrint(
"DTDigitizer") <<
"hit discarded" << endl;
229 CLHEP::HepRandomEngine *engine) {
232 int partType =
hit->particleType();
239 LogPrint(
"DTDigitizer") <<
"Hit local entry point: " << entryP << endl <<
"Hit local exit point: " << exitP << endl;
242 float xEntry = entryP.
x() - xwire;
243 float xExit = exitP.
x() - xwire;
246 LogPrint(
"DTDigitizer") <<
"wire position: " << xwire <<
" x entry in cell rf: " << xEntry
247 <<
" x exit in cell rf: " << xExit << endl;
256 pair<float, bool> driftTime(0.,
false);
264 LogPrint(
"DTDigitizer") <<
" e- hit in gas; discarding " << endl;
277 float cosAlpha = hHat.
dot(pHat);
278 float sinAlpha =
sqrt(1. - cosAlpha * cosAlpha);
279 float radius_P = (
d.mag()) / (2. * cosAlpha);
280 float sagitta_P = radius_P * (1. - sinAlpha);
284 float halfd =
d.mag() / 2.;
285 float BMag = BLoc.
mag();
287 float radius_B = (
pT.mag() / (0.3 * BMag)) * 100.;
289 if (radius_B > halfd) {
290 sagitta_B = radius_B -
sqrt(radius_B * radius_B - halfd * halfd);
292 sagitta_B = radius_B;
300 <<
" cosAlpha = " << cosAlpha << endl
301 <<
" sinAlpha = " << sinAlpha << endl
302 <<
" pMag = " <<
pT.mag() << endl
303 <<
" bMag = " << BMag << endl
304 <<
" pT = " <<
pT << endl
305 <<
" halfd = " << halfd << endl
306 <<
" radius_P (cm) = " << radius_P << endl
307 <<
" sagitta_P (um) = " << sagitta_P * 10000. << endl
308 <<
" radius_B (cm) = " << radius_B << endl
309 <<
" sagitta_B (um) = " << sagitta_B * 10000. << endl;
313 || (entrySide == exitSide)
321 && (noParametrisation ==
false)) {
323 LogPrint(
"DTDigitizer") <<
"*** WARNING: hit is not straight, type = " << partType << endl;
328 if (!noParametrisation) {
342 if (fabs(
pt.z()) < 0.002) {
346 x = xEntry - (entryP.
z() * (xExit - xEntry)) / (exitP.
z() - entryP.
z());
355 if ((driftTime.second) ==
false) {
363 if (driftTime.second) {
372 float x,
float theta,
float By,
float Bz, CLHEP::HepRandomEngine *engine)
const {
380 LogPrint(
"DTDigitizer") <<
"*** WARNING: parametrisation: x out of range = " <<
x <<
", skipping" << endl;
381 return pair<float, bool>(0.
f,
false);
389 float theta_par =
theta;
393 if (fabs(theta_par) > 45.) {
395 LogPrint(
"DTDigitizer") <<
"*** WARNING: extrapolating theta > 45: " <<
theta << endl;
398 if (fabs(By_par) > 0.75) {
400 LogPrint(
"DTDigitizer") <<
"*** WARNING: extrapolating Bnorm > 0.75: " << By_par << endl;
403 if (fabs(Bz_par) > 0.4) {
405 LogPrint(
"DTDigitizer") <<
"*** WARNING: extrapolating Bwire >0.4: " << Bz_par << endl;
414 LogPrint(
"DTDigitizer") <<
" Parametrisation: x, theta, Bnorm, Bwire = " <<
x <<
" " << theta_par <<
" "
415 << By_par <<
" " << Bz_par << endl
416 <<
" time=" <<
DT.t_drift <<
" sigma_m=" <<
DT.t_width_m <<
" sigma_p=" <<
DT.t_width_p
419 LogPrint(
"DTDigitizer") <<
"*** WARNING: call to parametrisation failed" << endl;
420 return pair<float, bool>(0.
f,
false);
434 double u = CLHEP::RandGaussQ::shoot(engine, 0.,
smearing);
438 LogPrint(
"DTDigitizer") <<
" drift time = " <<
time << endl;
440 return pair<float, bool>(
time,
true);
446 CLHEP::HepRandomEngine *engine)
const {
447 double f = sigmaLeft / (sigmaLeft + sigmaRight);
450 if (CLHEP::RandFlat::shoot(engine) <=
f) {
451 t = CLHEP::RandGaussQ::shoot(engine,
mean, sigmaLeft);
454 t = CLHEP::RandGaussQ::shoot(engine,
mean, sigmaRight);
457 return static_cast<float>(
t);
463 LogPrint(
"DTDigitizer") <<
" TimeMap " << endl;
464 return pair<float, bool>(0.,
false);
472 float wireCoord =
hit->localPosition().
y();
473 float halfL = (
layer->specificTopology().cellLenght()) / 2.;
474 float propgL = halfL - wireCoord;
479 float tof =
hit->tof();
486 LogPrint(
"DTDigitizer") <<
" propDelay =" << propDelay <<
"; TOF=" << tof <<
"; sync= " << sync << endl;
489 return propDelay + tof + sync;
505 float wakeTime = -999999.0;
506 float resolTime = -999999.0;
517 float time = (*hit).second;
518 if (
time > wakeTime) {
520 int wireN = wireId.
wire();
525 unsigned int SimTrackId = (*hit).first->trackId();
530 LogPrint(
"DTDigitizer") << endl <<
"---- DTDigitizer ----" << endl;
531 LogPrint(
"DTDigitizer") <<
"wireId: " << wireId << endl;
532 LogPrint(
"DTDigitizer") <<
"sim. time = " <<
time << endl;
533 LogPrint(
"DTDigitizer") <<
"digi number = " << digi.
number() <<
", digi time = " << digi.
time()
534 <<
", linked to SimTrack Id = " << SimTrackId << endl;
539 output.insertDigi(layerID, digi);
544 int wireN = wireId.
wire();
545 unsigned int SimTrackId = (*hit).first->trackId();
552 LogPrint(
"DTDigitizer") <<
"\nAdded multiple link: \n"
553 <<
"digi number = " << digi.
number() <<
", digi time = " << digi.
time()
554 <<
" (sim. time = " <<
time <<
")"
555 <<
", linked to SimTrack Id = " << SimTrackId << endl;
570 <<
"------- SimHit: " << endl
571 <<
" Particle type = " <<
hit->particleType() << endl
572 <<
" process type = " <<
hit->processType() << endl
573 <<
" process type = " <<
hit->processType()
576 <<
" trackId = " <<
hit->trackId()
579 <<
" |p| = " <<
hit->pabs() << endl
580 <<
" Energy loss = " <<
hit->energyLoss()
586 <<
" localDirection = " <<
hit->momentumAtEntry().unit()
588 <<
" Entry point = " << entryP <<
" cell x = " << xEntry << endl
589 <<
" Exit point = " << exitP <<
" cell x = " << xExit << endl
590 <<
" DR = = " << (exitP - entryP).
mag() << endl
591 <<
" Dx = = " << (exitP - entryP).
x() << endl
594 <<
" DY entry from edge = " << topo.
cellLenght() / 2. - fabs(entryP.
y())
595 <<
" DY exit from edge = " << topo.
cellLenght() / 2. - fabs(exitP.
y())
596 <<
" entrySide = " << (
int)entrySide <<
" ; exitSide = " << (
int)exitSide << endl;