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 
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  bx0filter_(config.getParameter<bool>("bx0filter")),
24  resolutionX_(config.getParameter<double>("resolutionX")),
25  cspeed(geant_units::operators::convertMmToCm(CLHEP::c_light)),
26  // average energy required to remove an electron due to ionization for an Ar/CO2 gas mixture (in the ratio of 70/30) is 28.1 eV
27  energyMinCut(28.1e-09) {}
28 
30 
33  CLHEP::HepRandomEngine* engine,
34  Strips& strips_,
35  DetectorHitMap& detectorHitMap_) {
36  const GEMStripTopology* top(dynamic_cast<const GEMStripTopology*>(&(roll->topology())));
37  for (const auto& hit : simHits) {
38  if (hit.energyLoss() < energyMinCut)
39  continue;
40  const int bx(getSimHitBx(&hit, engine));
41  if (bx != 0 and bx0filter_)
42  continue;
43  const std::vector<std::pair<int, int> >& cluster(simulateClustering(top, &hit, bx, engine));
44  for (const auto& digi : cluster) {
45  detectorHitMap_.emplace(digi, &hit);
46  strips_.emplace(digi);
47  }
48  }
49 }
50 
51 int GEMSignalModel::getSimHitBx(const PSimHit* simhit, CLHEP::HepRandomEngine* engine) {
52  int bx = -999;
53  const LocalPoint simHitPos(simhit->localPosition());
54  const float tof(simhit->timeOfFlight());
55  // random Gaussian time correction due to electronics jitter
56  float randomJitterTime = CLHEP::RandGaussQ::shoot(engine, 0., timeJitter_);
57  const GEMDetId id(simhit->detUnitId());
58  const GEMEtaPartition* roll(geometry_->etaPartition(id));
59  if (!roll) {
60  throw cms::Exception("Geometry") << "GEMSignalModel::getSimHitBx() - GEM simhit id does not match any GEM roll id: "
61  << id << "\n";
62  return 999;
63  }
64  if (roll->id().region() == 0) {
65  throw cms::Exception("Geometry")
66  << "GEMSignalModel::getSimHitBx() - this GEM id is from barrel, which cannot happen: " << roll->id() << "\n";
67  }
68  const int nstrips = roll->nstrips();
69  float middleStrip = nstrips / 2.;
70  const LocalPoint& middleOfRoll = roll->centreOfStrip(middleStrip);
71  const GlobalPoint& globMiddleRol = roll->toGlobal(middleOfRoll);
72  double muRadius = sqrt(globMiddleRol.x() * globMiddleRol.x() + globMiddleRol.y() * globMiddleRol.y() +
73  globMiddleRol.z() * globMiddleRol.z());
74  double timeCalibrationOffset_ = muRadius / cspeed; //[ns]
75 
76  const GEMStripTopology* top(dynamic_cast<const GEMStripTopology*>(&(roll->topology())));
77  const float halfStripLength(0.5 * top->stripLength());
78  const float distanceFromEdge(halfStripLength - simHitPos.y());
79 
80  // signal propagation speed in material in [cm/ns]
81  double signalPropagationSpeedTrue = signalPropagationSpeed_ * cspeed;
82 
83  // average time for the signal to propagate from the SimHit to the top of a strip
84  const float averagePropagationTime(distanceFromEdge / signalPropagationSpeedTrue);
85  // random Gaussian time correction due to the finite timing resolution of the detector
86  float randomResolutionTime = CLHEP::RandGaussQ::shoot(engine, 0., timeResolution_);
87  const float simhitTime(tof + averageShapingTime_ + randomResolutionTime + averagePropagationTime + randomJitterTime);
88  float referenceTime = 0.;
89  referenceTime = timeCalibrationOffset_ + halfStripLength / signalPropagationSpeedTrue + averageShapingTime_;
90  const float timeDifference(simhitTime - referenceTime);
91  // assign the bunch crossing
92  bx = static_cast<int>(std::round((timeDifference) / 25.));
93 
94  // check time
95  LogDebug("GEMDigiProducer") << "checktime "
96  << "bx = " << bx << "\tdeltaT = " << timeDifference << "\tsimT = " << simhitTime
97  << "\trefT = " << referenceTime << "\ttof = " << tof
98  << "\tavePropT = " << averagePropagationTime
99  << "\taveRefPropT = " << halfStripLength / signalPropagationSpeedTrue << "\n";
100  return bx;
101 }
102 
103 std::vector<std::pair<int, int> > GEMSignalModel::simulateClustering(const GEMStripTopology* top,
104  const PSimHit* simHit,
105  const int bx,
106  CLHEP::HepRandomEngine* engine) {
107  const LocalPoint& hit_entry(simHit->entryPoint());
108  const LocalPoint& hit_exit(simHit->exitPoint());
109 
110  LocalPoint start_point, end_point;
111  if (hit_entry.x() < hit_exit.x()) {
112  start_point = hit_entry;
113  end_point = hit_exit;
114  } else {
115  start_point = hit_exit;
116  end_point = hit_entry;
117  }
118 
119  // Add Gaussian noise to the points towards outside.
120  float smeared_start_x = start_point.x() - std::abs(CLHEP::RandGaussQ::shoot(engine, 0, resolutionX_));
121  float smeared_end_x = end_point.x() + std::abs(CLHEP::RandGaussQ::shoot(engine, 0, resolutionX_));
122 
123  LocalPoint smeared_start_point(smeared_start_x, start_point.y(), start_point.z());
124  LocalPoint smeared_end_point(smeared_end_x, end_point.y(), end_point.z());
125 
126  int cluster_start = top->channel(smeared_start_point);
127  int cluster_end = top->channel(smeared_end_point);
128 
129  std::vector<std::pair<int, int> > cluster;
130  for (int strip = cluster_start; strip <= cluster_end; strip++) {
131  cluster.emplace_back(strip, bx);
132  }
133 
134  return cluster;
135 }
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:77
unsigned int detUnitId() const
Definition: PSimHit.h:97
T z() const
Definition: PV3DBase.h:61
std::vector< std::pair< int, int > > simulateClustering(const GEMStripTopology *, const PSimHit *, const int, CLHEP::HepRandomEngine *)
int channel(const LocalPoint &) const override
const double cspeed
Definition: config.py:1
double signalPropagationSpeed_
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
const double energyMinCut
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void simulate(const GEMEtaPartition *, const edm::PSimHitContainer &, CLHEP::HepRandomEngine *, Strips &, DetectorHitMap &) override
double timeResolution_
constexpr NumType convertMmToCm(NumType millimeters)
Definition: angle_units.h:44
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
const Topology & topology() const override
Local3DPoint localPosition() const
Definition: PSimHit.h:52
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
float timeOfFlight() const
Definition: PSimHit.h:73
std::vector< PSimHit > PSimHitContainer
~GEMSignalModel() override
double averageShapingTime_
GEMSignalModel(const edm::ParameterSet &)
#define LogDebug(id)