CMS 3D CMS Logo

GEMSignalModel.cc
Go to the documentation of this file.
7 #include "CLHEP/Random/RandFlat.h"
8 #include "CLHEP/Random/RandPoissonQ.h"
9 #include "CLHEP/Random/RandGaussQ.h"
10 #include "CLHEP/Units/GlobalPhysicalConstants.h"
12 #include <cmath>
13 #include <utility>
14 #include <map>
15 
17  : GEMDigiModel(config),
18  averageEfficiency_(config.getParameter<double>("averageEfficiency")),
19  averageShapingTime_(config.getParameter<double>("averageShapingTime")),
20  timeResolution_(config.getParameter<double>("timeResolution")),
21  timeJitter_(config.getParameter<double>("timeJitter")),
22  signalPropagationSpeed_(config.getParameter<double>("signalPropagationSpeed")),
23  digitizeOnlyMuons_(config.getParameter<bool>("digitizeOnlyMuons")),
24  resolutionX_(config.getParameter<double>("resolutionX")),
25  muonPdgId(13),
26  cspeed(geant_units::operators::convertMmToCm(CLHEP::c_light)),
27  momConvFact(1000.),
28  elecMomCut1(1.96e-03),
29  elecMomCut2(10.e-03),
30  elecEffLowCoeff(1.7e-05),
31  elecEffLowParam0(2.1),
32  elecEffMidCoeff(1.34),
33  elecEffMidParam0(-5.75e-01),
34  elecEffMidParam1(7.96e-01) {}
35 
37 
40  CLHEP::HepRandomEngine* engine,
41  Strips& strips_,
42  DetectorHitMap& detectorHitMap_) {
43  bool digiMuon = false;
44  bool digiElec = false;
45  const TrapezoidalStripTopology* top(dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology())));
46  for (const auto& hit : simHits) {
47  if (std::abs(hit.particleType()) != muonPdgId && digitizeOnlyMuons_)
48  continue;
49  double elecEff = 0.;
50  double partMom = hit.pabs();
51  double checkMuonEff = CLHEP::RandFlat::shoot(engine, 0., 1.);
52  double checkElecEff = CLHEP::RandFlat::shoot(engine, 0., 1.);
53  if (std::abs(hit.particleType()) == muonPdgId && checkMuonEff < averageEfficiency_)
54  digiMuon = true;
55  if (std::abs(hit.particleType()) != muonPdgId) //consider all non muon particles with gem efficiency to electrons
56  {
57  if (partMom <= elecMomCut1)
58  elecEff = elecEffLowCoeff * std::exp(elecEffLowParam0 * partMom * momConvFact);
59  if (partMom > elecMomCut1 && partMom < elecMomCut2)
60  elecEff = elecEffMidCoeff * log(elecEffMidParam1 * partMom * momConvFact - elecEffMidParam0) /
61  (elecEffMidCoeff + log(elecEffMidParam1 * partMom * momConvFact - elecEffMidParam0));
62  if (partMom > elecMomCut2)
63  elecEff = 1.;
64  if (checkElecEff < elecEff)
65  digiElec = true;
66  }
67  if (!(digiMuon || digiElec))
68  continue;
69  const int bx(getSimHitBx(&hit, engine));
70  const std::vector<std::pair<int, int> >& cluster(simulateClustering(top, &hit, bx, engine));
71  for (const auto& digi : cluster) {
72  detectorHitMap_.emplace(digi, &hit);
73  strips_.emplace(digi);
74  }
75  }
76 }
77 
78 int GEMSignalModel::getSimHitBx(const PSimHit* simhit, CLHEP::HepRandomEngine* engine) {
79  int bx = -999;
80  const LocalPoint simHitPos(simhit->localPosition());
81  const float tof(simhit->timeOfFlight());
82  // random Gaussian time correction due to electronics jitter
83  float randomJitterTime = CLHEP::RandGaussQ::shoot(engine, 0., timeJitter_);
84  const GEMDetId id(simhit->detUnitId());
85  const GEMEtaPartition* roll(geometry_->etaPartition(id));
86  if (!roll) {
87  throw cms::Exception("Geometry") << "GEMSignalModel::getSimHitBx() - GEM simhit id does not match any GEM roll id: "
88  << id << "\n";
89  return 999;
90  }
91  if (roll->id().region() == 0) {
92  throw cms::Exception("Geometry")
93  << "GEMSignalModel::getSimHitBx() - this GEM id is from barrel, which cannot happen: " << roll->id() << "\n";
94  }
95  const int nstrips = roll->nstrips();
96  float middleStrip = nstrips / 2.;
97  const LocalPoint& middleOfRoll = roll->centreOfStrip(middleStrip);
98  const GlobalPoint& globMiddleRol = roll->toGlobal(middleOfRoll);
99  double muRadius = sqrt(globMiddleRol.x() * globMiddleRol.x() + globMiddleRol.y() * globMiddleRol.y() +
100  globMiddleRol.z() * globMiddleRol.z());
101  double timeCalibrationOffset_ = muRadius / cspeed; //[ns]
102 
103  const TrapezoidalStripTopology* top(dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology())));
104  const float halfStripLength(0.5 * top->stripLength());
105  const float distanceFromEdge(halfStripLength - simHitPos.y());
106 
107  // signal propagation speed in material in [cm/ns]
108  double signalPropagationSpeedTrue = signalPropagationSpeed_ * cspeed;
109 
110  // average time for the signal to propagate from the SimHit to the top of a strip
111  const float averagePropagationTime(distanceFromEdge / signalPropagationSpeedTrue);
112  // random Gaussian time correction due to the finite timing resolution of the detector
113  float randomResolutionTime = CLHEP::RandGaussQ::shoot(engine, 0., timeResolution_);
114  const float simhitTime(tof + averageShapingTime_ + randomResolutionTime + averagePropagationTime + randomJitterTime);
115  float referenceTime = 0.;
116  referenceTime = timeCalibrationOffset_ + halfStripLength / signalPropagationSpeedTrue + averageShapingTime_;
117  const float timeDifference(simhitTime - referenceTime);
118  // assign the bunch crossing
119  bx = static_cast<int>(std::round((timeDifference) / 25.));
120 
121  // check time
122  LogDebug("GEMDigiProducer") << "checktime "
123  << "bx = " << bx << "\tdeltaT = " << timeDifference << "\tsimT = " << simhitTime
124  << "\trefT = " << referenceTime << "\ttof = " << tof
125  << "\tavePropT = " << averagePropagationTime
126  << "\taveRefPropT = " << halfStripLength / signalPropagationSpeedTrue << "\n";
127  return bx;
128 }
129 
130 std::vector<std::pair<int, int> > GEMSignalModel::simulateClustering(const TrapezoidalStripTopology* top,
131  const PSimHit* simHit,
132  const int bx,
133  CLHEP::HepRandomEngine* engine) {
134  const LocalPoint& hit_entry(simHit->entryPoint());
135  const LocalPoint& hit_exit(simHit->exitPoint());
136 
137  LocalPoint start_point, end_point;
138  if (hit_entry.x() < hit_exit.x()) {
139  start_point = hit_entry;
140  end_point = hit_exit;
141  } else {
142  start_point = hit_exit;
143  end_point = hit_entry;
144  }
145 
146  // Add Gaussian noise to the points towards outside.
147  float smeared_start_x = start_point.x() - std::abs(CLHEP::RandGaussQ::shoot(engine, 0, resolutionX_));
148  float smeared_end_x = end_point.x() + std::abs(CLHEP::RandGaussQ::shoot(engine, 0, resolutionX_));
149 
150  LocalPoint smeared_start_point(smeared_start_x, start_point.y(), start_point.z());
151  LocalPoint smeared_end_point(smeared_end_x, end_point.y(), end_point.z());
152 
153  int cluster_start = top->channel(smeared_start_point);
154  int cluster_end = top->channel(smeared_end_point);
155 
156  std::vector<std::pair<int, int> > cluster;
157  for (int strip = cluster_start; strip <= cluster_end; strip++) {
158  cluster.emplace_back(strip, bx);
159  }
160 
161  return cluster;
162 }
#define LogDebug(id)
const double elecMomCut1
double averageEfficiency_
const double elecEffMidParam1
const double elecEffMidCoeff
T y() const
Definition: PV3DBase.h:60
const double cspeed
Definition: config.py:1
const Topology & topology() const override
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:77
double signalPropagationSpeed_
const double elecEffLowCoeff
Local3DPoint exitPoint() const
Exit point in the local Det frame.
Definition: PSimHit.h:46
float timeOfFlight() const
Definition: PSimHit.h:73
Local3DPoint localPosition() const
Definition: PSimHit.h:52
const double elecEffLowParam0
const double elecMomCut2
T sqrt(T t)
Definition: SSEVec.h:19
T z() const
Definition: PV3DBase.h:61
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void simulate(const GEMEtaPartition *, const edm::PSimHitContainer &, CLHEP::HepRandomEngine *, Strips &, DetectorHitMap &) override
const double elecEffMidParam0
double timeResolution_
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
std::vector< std::pair< int, int > > simulateClustering(const TrapezoidalStripTopology *, const PSimHit *, const int, CLHEP::HepRandomEngine *)
int channel(const LocalPoint &) const override
std::multimap< std::pair< unsigned int, int >, const PSimHit *, std::less< std::pair< unsigned int, int > > > DetectorHitMap
Definition: GEMDigiModel.h:35
std::set< std::pair< int, int > > Strips
Definition: GEMDigiModel.h:31
const GEMGeometry * geometry_
Definition: GEMDigiModel.h:47
constexpr NumType convertMmToCm(NumType millimeters)
Definition: GeantUnits.h:62
std::vector< PSimHit > PSimHitContainer
~GEMSignalModel() override
double averageShapingTime_
T x() const
Definition: PV3DBase.h:59
const int muonPdgId
GEMSignalModel(const edm::ParameterSet &)
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Definition: PSimHit.h:43
const double momConvFact
unsigned int detUnitId() const
Definition: PSimHit.h:97