CMS 3D CMS Logo

GEMSimpleModel.cc
Go to the documentation of this file.
6 #include "CLHEP/Random/RandFlat.h"
7 #include "CLHEP/Random/RandPoissonQ.h"
8 #include "CLHEP/Random/RandGaussQ.h"
9 #include <cmath>
10 #include <utility>
11 #include <map>
12 
14 GEMDigiModel(config)
15 , averageEfficiency_(config.getParameter<double> ("averageEfficiency"))
16 , averageShapingTime_(config.getParameter<double> ("averageShapingTime"))
17 , timeResolution_(config.getParameter<double> ("timeResolution"))
18 , timeJitter_(config.getParameter<double> ("timeJitter"))
19 , averageNoiseRate_(config.getParameter<double> ("averageNoiseRate"))
20 , signalPropagationSpeed_(config.getParameter<double> ("signalPropagationSpeed"))
21 , bxwidth_(config.getParameter<int> ("bxwidth"))
22 , minBunch_(config.getParameter<int> ("minBunch"))
23 , maxBunch_(config.getParameter<int> ("maxBunch"))
24 , digitizeOnlyMuons_(config.getParameter<bool> ("digitizeOnlyMuons"))
25 , doBkgNoise_(config.getParameter<bool> ("doBkgNoise"))
26 , doNoiseCLS_(config.getParameter<bool> ("doNoiseCLS"))
27 , fixedRollRadius_(config.getParameter<bool> ("fixedRollRadius"))
28 , simulateElectronBkg_(config.getParameter<bool> ("simulateElectronBkg"))
29 , instLumi_(config.getParameter<double>("instLumi"))
30 , rateFact_(config.getParameter<double>("rateFact"))
31 , referenceInstLumi_(config.getParameter<double>("referenceInstLumi"))
32 , GE11ElecBkgParam0_(config.getParameter<double>("GE11ElecBkgParam0"))
33 , GE11ElecBkgParam1_(config.getParameter<double>("GE11ElecBkgParam1"))
34 , GE11ElecBkgParam2_(config.getParameter<double>("GE11ElecBkgParam2"))
35 , GE21ElecBkgParam0_(config.getParameter<double>("GE21ElecBkgParam0"))
36 , GE21ElecBkgParam1_(config.getParameter<double>("GE21ElecBkgParam1"))
37 , GE21ElecBkgParam2_(config.getParameter<double>("GE21ElecBkgParam2"))
38 , GE11ModNeuBkgParam0_(config.getParameter<double>("GE11ModNeuBkgParam0"))
39 , GE11ModNeuBkgParam1_(config.getParameter<double>("GE11ModNeuBkgParam1"))
40 , GE11ModNeuBkgParam2_(config.getParameter<double>("GE11ModNeuBkgParam2"))
41 , GE21ModNeuBkgParam0_(config.getParameter<double>("GE11ModNeuBkgParam0"))
42 , GE21ModNeuBkgParam1_(config.getParameter<double>("GE11ModNeuBkgParam1"))
43 , GE21ModNeuBkgParam2_(config.getParameter<double>("GE11ModNeuBkgParam2"))
44 {
45 }
46 
48 {
49 }
50 
52 {
53  return;
54 }
55 
56 void GEMSimpleModel::simulateSignal(const GEMEtaPartition* roll, const edm::PSimHitContainer& simHits, CLHEP::HepRandomEngine* engine)
57 {
59  detectorHitMap_.clear();
63  bool digiMuon = false;
64  bool digiElec = false;
65  for (const auto& hit : simHits)
66  {
67  if (std::abs(hit.particleType()) != 13 && digitizeOnlyMuons_)
68  continue;
69  double elecEff = 0.;
70  double partMom = hit.pabs();
71  double checkMuonEff = CLHEP::RandFlat::shoot(engine, 0., 1.);
72  double checkElecEff = CLHEP::RandFlat::shoot(engine, 0., 1.);
73  if (std::abs(hit.particleType()) == 13 && checkMuonEff < averageEfficiency_)
74  digiMuon = true;
75  if (std::abs(hit.particleType()) != 13) //consider all non muon particles with gem efficiency to electrons
76  {
77  if (partMom <= 1.95e-03)
78  elecEff = 1.7e-05 * std::exp(2.1 * partMom * 1000.);
79  if (partMom > 1.95e-03 && partMom < 10.e-03)
80  elecEff = 1.34 * log(7.96e-01 * partMom * 1000. - 5.75e-01)
81  / (1.34 + log(7.96e-01 * partMom * 1000. - 5.75e-01));
82  if (partMom > 10.e-03)
83  elecEff = 1.;
84  if (checkElecEff < elecEff)
85  digiElec = true;
86  }
87  if (!(digiMuon || digiElec))
88  continue;
89  const int bx(getSimHitBx(&hit, engine));
90  const std::vector<std::pair<int, int> >& cluster(simulateClustering(roll, &hit, bx, engine));
91  for (const auto & digi : cluster)
92  {
93  detectorHitMap_.emplace(digi,&hit);
94  strips_.emplace(digi);
95  }
96  }
97 }
98 
99 int GEMSimpleModel::getSimHitBx(const PSimHit* simhit, CLHEP::HepRandomEngine* engine)
100 {
101  int bx = -999;
102  const LocalPoint simHitPos(simhit->localPosition());
103  const float tof(simhit->timeOfFlight());
104  // random Gaussian time correction due to electronics jitter
105  float randomJitterTime = CLHEP::RandGaussQ::shoot(engine, 0., timeJitter_);
106  const GEMDetId id(simhit->detUnitId());
107  const GEMEtaPartition* roll(geometry_->etaPartition(id));
108  if (!roll)
109  {
110  throw cms::Exception("Geometry")<< "GEMSimpleModel::getSimHitBx() - GEM simhit id does not match any GEM roll id: " << id << "\n";
111  return 999;
112  }
113  if (roll->id().region() == 0)
114  {
115  throw cms::Exception("Geometry") << "GEMSimpleModel::getSimHitBx() - this GEM id is from barrel, which cannot happen: " << roll->id() << "\n";
116  }
117  const double cspeed = 299792458; // signal propagation speed in vacuum in [m/s]
118  const int nstrips = roll->nstrips();
119  float middleStrip = nstrips/2.;
120  const LocalPoint& middleOfRoll = roll->centreOfStrip(middleStrip);
121  const GlobalPoint& globMiddleRol = roll->toGlobal(middleOfRoll);
122  double muRadius = sqrt(globMiddleRol.x()*globMiddleRol.x() + globMiddleRol.y()*globMiddleRol.y() +globMiddleRol.z()*globMiddleRol.z());
123  double timeCalibrationOffset_ = (muRadius *1e+9)/(cspeed*1e+2); //[ns]
124 
125  const TrapezoidalStripTopology* top(dynamic_cast<const TrapezoidalStripTopology*> (&(roll->topology())));
126  const float halfStripLength(0.5 * top->stripLength());
127  const float distanceFromEdge(halfStripLength - simHitPos.y());
128 
129  // signal propagation speed in material in [cm/ns]
130  double signalPropagationSpeedTrue = signalPropagationSpeed_ * cspeed * 1e-7; // 1e+2 * 1e-9;
131 
132  // average time for the signal to propagate from the SimHit to the top of a strip
133  const float averagePropagationTime(distanceFromEdge / signalPropagationSpeedTrue);
134  // random Gaussian time correction due to the finite timing resolution of the detector
135  float randomResolutionTime = CLHEP::RandGaussQ::shoot(engine, 0., timeResolution_);
136  const float simhitTime(tof + averageShapingTime_ + randomResolutionTime + averagePropagationTime + randomJitterTime);
137  float referenceTime = 0.;
138  referenceTime = timeCalibrationOffset_ + halfStripLength / signalPropagationSpeedTrue + averageShapingTime_;
139  const float timeDifference(simhitTime - referenceTime);
140  // assign the bunch crossing
141  bx = static_cast<int> (std::round((timeDifference) / bxwidth_));
142 
143  // check time
144  const bool debug(false);
145  if (debug)
146  {
147  std::cout << "checktime " << "bx = " << bx << "\tdeltaT = " << timeDifference << "\tsimT = " << simhitTime
148  << "\trefT = " << referenceTime << "\ttof = " << tof << "\tavePropT = " << averagePropagationTime
149  << "\taveRefPropT = " << halfStripLength / signalPropagationSpeedTrue << std::endl;
150  }
151  return bx;
152 }
153 
154 void GEMSimpleModel::simulateNoise(const GEMEtaPartition* roll, CLHEP::HepRandomEngine* engine)
155 {
156  if (!doBkgNoise_)
157  return;
158  const GEMDetId& gemId(roll->id());
159  const int nstrips(roll->nstrips());
160  double trArea(0.0);
161  double trStripArea(0.0);
162  if (gemId.region() == 0)
163  {
164  throw cms::Exception("Geometry")
165  << "GEMSynchronizer::simulateNoise() - this GEM id is from barrel, which cannot happen.";
166  }
167  const TrapezoidalStripTopology* top_(dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology())));
168  const float striplength(top_->stripLength());
169  trStripArea = (roll->pitch()) * striplength;
170  trArea = trStripArea * nstrips;
171  const int nBxing(maxBunch_ - minBunch_ + 1);
172  const float rollRadius(fixedRollRadius_ ? top_->radius() :
173  top_->radius() + CLHEP::RandFlat::shoot(engine, -1.*top_->stripLength()/2., top_->stripLength()/2.));
174 
175  //calculate noise from model
176  double averageNeutralNoiseRatePerRoll = 0.;
177  double averageNoiseElectronRatePerRoll = 0.;
178  double averageNoiseRatePerRoll = 0.;
179  if (gemId.station() == 1)
180  {
181  //simulate neutral background for GE1/1
182  averageNeutralNoiseRatePerRoll = (GE11ModNeuBkgParam0_
183  + GE11ModNeuBkgParam1_ * rollRadius
184  + GE11ModNeuBkgParam2_ * rollRadius * rollRadius); //simulate electron background for GE1/1
186  averageNoiseElectronRatePerRoll = (GE11ElecBkgParam0_
187  + GE11ElecBkgParam1_ * rollRadius
188  + GE11ElecBkgParam2_ * rollRadius * rollRadius);
189 
190  // Scale up/down for desired instantaneous lumi (reference is 5E34, double from config is in units of 1E34)
191  averageNoiseRatePerRoll = averageNeutralNoiseRatePerRoll + averageNoiseElectronRatePerRoll;
192  averageNoiseRatePerRoll *= instLumi_*rateFact_*1.0/referenceInstLumi_;
193  }
194  if (gemId.station() == 2)
195  {
196  //simulate neutral background for GE2/1
197  averageNeutralNoiseRatePerRoll = (GE21ModNeuBkgParam0_
198  + GE21ModNeuBkgParam1_ * rollRadius
199  + GE21ModNeuBkgParam2_ * rollRadius * rollRadius);
200  //simulate electron background for GE2/1
202  averageNoiseElectronRatePerRoll = (GE21ElecBkgParam0_
203  + GE21ElecBkgParam1_ * rollRadius
204  + GE21ElecBkgParam2_ * rollRadius * rollRadius);
205 
206  // Scale up/down for desired instantaneous lumi (reference is 5E34, double from config is in units of 1E34)
207  averageNoiseRatePerRoll = averageNeutralNoiseRatePerRoll + averageNoiseElectronRatePerRoll;
208  averageNoiseRatePerRoll *= instLumi_*rateFact_*1.0/referenceInstLumi_;
209  }
210 
211  //simulate intrinsic noise
213  {
214  const double aveIntrinsicNoisePerStrip(averageNoiseRate_ * nBxing * bxwidth_ * trStripArea * 1.0e-9);
215  for(int j = 0; j < nstrips; ++j)
216  {
217  CLHEP::RandPoissonQ randPoissonQ(*engine, aveIntrinsicNoisePerStrip);
218  const int n_intrHits(randPoissonQ.fire());
219 
220  for (int k = 0; k < n_intrHits; k++ )
221  {
222  const int time_hit(static_cast<int>(CLHEP::RandFlat::shoot(engine, nBxing)) + minBunch_);
223  std::pair<int, int> digi(k+1,time_hit);
224  strips_.emplace(digi);
225  }
226  }
227  }//end simulate intrinsic noise
228 
229  //simulate bkg contribution
230  const double averageNoise(averageNoiseRatePerRoll * nBxing * bxwidth_ * trArea * 1.0e-9);
231  CLHEP::RandPoissonQ randPoissonQ(*engine, averageNoise);
232  const int n_hits(randPoissonQ.fire());
233  for (int i = 0; i < n_hits; ++i)
234  {
235  const int centralStrip(static_cast<int> (CLHEP::RandFlat::shoot(engine, 1, nstrips)));
236  const int time_hit(static_cast<int>(CLHEP::RandFlat::shoot(engine, nBxing)) + minBunch_);
237  if (doNoiseCLS_)
238  {
239  std::vector < std::pair<int, int> > cluster_;
240  cluster_.clear();
241  cluster_.emplace_back(centralStrip, time_hit);
242  int clusterSize((CLHEP::RandFlat::shoot(engine)) <= 0.53 ? 1 : 2);
243  if (clusterSize == 2)
244  {
245  if(CLHEP::RandFlat::shoot(engine) < 0.5)
246  {
247  if (CLHEP::RandFlat::shoot(engine) < averageEfficiency_ && (centralStrip - 1 > 0))
248  cluster_.emplace_back(centralStrip - 1, time_hit);
249  }
250  else
251  {
252  if (CLHEP::RandFlat::shoot(engine) < averageEfficiency_ && (centralStrip + 1 <= nstrips))
253  cluster_.emplace_back(centralStrip + 1, time_hit);
254  }
255  }
256  for (const auto& digi : cluster_)
257  {
258  strips_.emplace(digi);
259  }
260  } //end doNoiseCLS_
261  else
262  {
263  strips_.emplace(centralStrip, time_hit);
264  }
265  }
266  return;
267 }
268 
269 std::vector<std::pair<int, int> > GEMSimpleModel::simulateClustering(const GEMEtaPartition* roll,
270  const PSimHit* simHit, const int bx,
271  CLHEP::HepRandomEngine* engine)
272 {
273  const StripTopology& topology = roll->specificTopology(); // const LocalPoint& entry(simHit->entryPoint());
274  const LocalPoint& hit_position(simHit->localPosition());
275  const int nstrips(roll->nstrips());
276  int centralStrip = 0;
277  if (!(topology.channel(hit_position) + 1 > nstrips))
278  centralStrip = topology.channel(hit_position) + 1;
279  else
280  centralStrip = topology.channel(hit_position);
281  const GlobalPoint& pointSimHit = roll->toGlobal(hit_position);
282  const GlobalPoint& pointDigiHit = roll->toGlobal(roll->centreOfStrip(centralStrip));
283  double deltaX = pointSimHit.x() - pointDigiHit.x();
284 
285  // Add central digi to cluster vector
286  std::vector < std::pair<int, int> > cluster_;
287  cluster_.clear();
288  cluster_.emplace_back(centralStrip, bx);
289 
290  //simulate cross talk
291  int clusterSize((CLHEP::RandFlat::shoot(engine)) <= 0.53 ? 1 : 2);
292  if (clusterSize == 2)
293  {
294  if (deltaX <= 0)
295  {
296  if (CLHEP::RandFlat::shoot(engine) < averageEfficiency_ && (centralStrip - 1 > 0))
297  cluster_.emplace_back(centralStrip - 1, bx);
298  }
299  else
300  {
301  if (CLHEP::RandFlat::shoot(engine) < averageEfficiency_ && (centralStrip + 1 <= nstrips))
302  cluster_.emplace_back(centralStrip + 1, bx);
303  }
304  }
305  return cluster_;
306 }
double signalPropagationSpeed_
double GE21ElecBkgParam1_
double GE11ModNeuBkgParam2_
edm::DetSet< GEMDigiSimLink > GEMDigiSimLinks
Definition: GEMDigiModel.h:37
double GE11ElecBkgParam2_
CaloTopology const * topology(0)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
double averageNoiseRate_
T y() const
Definition: PV3DBase.h:63
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
double GE11ElecBkgParam0_
void setup() override
Definition: config.py:1
GEMDigiSimLinks theGemDigiSimLinks_
Definition: GEMDigiModel.h:80
const Topology & topology() const
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:99
GEMDetId id() const
LocalPoint centreOfStrip(int strip) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
double GE21ElecBkgParam2_
int nstrips() const
number of readout strips in partition
float timeOfFlight() const
Definition: PSimHit.h:69
bool simulateIntrinsicNoise_
Local3DPoint localPosition() const
Definition: PSimHit.h:44
T sqrt(T t)
Definition: SSEVec.h:18
double GE21ModNeuBkgParam1_
double averageEfficiency_
double GE21ModNeuBkgParam2_
double GE11ModNeuBkgParam1_
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< std::pair< int, int > > simulateClustering(const GEMEtaPartition *, const PSimHit *, const int, CLHEP::HepRandomEngine *) override
double GE21ModNeuBkgParam0_
const StripTopology & specificTopology() const
double GE11ModNeuBkgParam0_
GEMSimpleModel(const edm::ParameterSet &)
virtual int channel(const LocalPoint &p) const =0
float pitch() const
double GE21ElecBkgParam0_
int k[5][pyjets_maxn]
const double referenceInstLumi_
bool simulateElectronBkg_
#define debug
Definition: HDRShower.cc:19
double GE11ElecBkgParam1_
void simulateNoise(const GEMEtaPartition *, CLHEP::HepRandomEngine *) override
const GEMGeometry * geometry_
Definition: GEMDigiModel.h:63
double averageShapingTime_
std::set< std::pair< int, int > > strips_
Definition: GEMDigiModel.h:65
void clear()
Definition: DetSet.h:69
DetectorHitMap detectorHitMap_
Definition: GEMDigiModel.h:78
double timeResolution_
std::vector< PSimHit > PSimHitContainer
StripDigiSimLinks stripDigiSimLinks_
Definition: GEMDigiModel.h:79
edm::DetSet< StripDigiSimLink > StripDigiSimLinks
Definition: GEMDigiModel.h:36
T x() const
Definition: PV3DBase.h:62
void simulateSignal(const GEMEtaPartition *, const edm::PSimHitContainer &, CLHEP::HepRandomEngine *) override
unsigned int detUnitId() const
Definition: PSimHit.h:93