CMS 3D CMS Logo

ME0SimpleModel.cc
Go to the documentation of this file.
1 #include "CLHEP/Units/defs.h"
2 #include "CLHEP/Units/SystemOfUnits.h"
3 #include "CLHEP/Units/GlobalPhysicalConstants.h"
10 #include "CLHEP/Random/RandFlat.h"
11 #include "CLHEP/Random/RandPoissonQ.h"
12 #include "CLHEP/Random/RandGaussQ.h"
13 #include <cmath>
14 #include <utility>
15 #include <map>
16 
19  averageEfficiency_(config.getParameter<double>("averageEfficiency")),
20  averageShapingTime_(config.getParameter<double>("averageShapingTime")),
21  timeResolution_(config.getParameter<double>("timeResolution")),
22  timeJitter_(config.getParameter<double>("timeJitter")),
23  averageNoiseRate_(config.getParameter<double>("averageNoiseRate")),
24  signalPropagationSpeed_(config.getParameter<double>("signalPropagationSpeed")),
25  bxwidth_(config.getParameter<int>("bxwidth")),
26  minBunch_(config.getParameter<int>("minBunch")),
27  maxBunch_(config.getParameter<int>("maxBunch")),
28  digitizeOnlyMuons_(config.getParameter<bool>("digitizeOnlyMuons")),
29  doBkgNoise_(config.getParameter<bool>("doBkgNoise")),
30  doNoiseCLS_(config.getParameter<bool>("doNoiseCLS")),
31  fixedRollRadius_(config.getParameter<bool>("fixedRollRadius")),
32  simulateElectronBkg_(config.getParameter<bool>("simulateElectronBkg")),
33  instLumi_(config.getParameter<double>("instLumi")),
34  rateFact_(config.getParameter<double>("rateFact")),
35  referenceInstLumi_(config.getParameter<double>("referenceInstLumi")),
36  ME0ElecBkgParam0_(config.getParameter<double>("ME0ElecBkgParam0")),
37  ME0ElecBkgParam1_(config.getParameter<double>("ME0ElecBkgParam1")),
38  ME0ElecBkgParam2_(config.getParameter<double>("ME0ElecBkgParam2")),
39  ME0ElecBkgParam3_(config.getParameter<double>("ME0ElecBkgParam3")),
40  ME0NeuBkgParam0_(config.getParameter<double>("ME0NeuBkgParam0")),
41  ME0NeuBkgParam1_(config.getParameter<double>("ME0NeuBkgParam1")),
42  ME0NeuBkgParam2_(config.getParameter<double>("ME0NeuBkgParam2")),
43  ME0NeuBkgParam3_(config.getParameter<double>("ME0NeuBkgParam3")) {}
44 
46 
47 void ME0SimpleModel::setup() { return; }
48 
51  CLHEP::HepRandomEngine* engine) {
53  detectorHitMap_.clear();
55 
58  bool digiMuon = false;
59  bool digiElec = false;
60  for (const auto& hit : simHits) {
61  if (std::abs(hit.particleType()) != 13 && digitizeOnlyMuons_)
62  continue;
63  double elecEff = 0.;
64  double partMom = hit.pabs();
65  double checkMuonEff = CLHEP::RandFlat::shoot(engine, 0., 1.);
66  double checkElecEff = CLHEP::RandFlat::shoot(engine, 0., 1.);
67  if (std::abs(hit.particleType()) == 13 && checkMuonEff < averageEfficiency_)
68  digiMuon = true;
69  if (std::abs(hit.particleType()) != 13) //consider all non muon particles with me0 efficiency to electrons
70  {
71  if (partMom <= 1.95e-03)
72  elecEff = 1.7e-05 * std::exp(2.1 * partMom * 1000.);
73  if (partMom > 1.95e-03 && partMom < 10.e-03)
74  elecEff =
75  1.34 * log(7.96e-01 * partMom * 1000. - 5.75e-01) / (1.34 + log(7.96e-01 * partMom * 1000. - 5.75e-01));
76  if (partMom > 10.e-03)
77  elecEff = 1.;
78  if (checkElecEff < elecEff)
79  digiElec = true;
80  }
81  if (!(digiMuon || digiElec))
82  continue;
83  const int bx(getSimHitBx(&hit, engine));
84  const std::vector<std::pair<int, int> >& cluster(simulateClustering(roll, &hit, bx, engine));
85  for (const auto& digi : cluster) {
86  detectorHitMap_.emplace(digi, &hit);
87  strips_.emplace(digi);
88  }
89  }
90 }
91 
92 int ME0SimpleModel::getSimHitBx(const PSimHit* simhit, CLHEP::HepRandomEngine* engine) {
93  int bx = -999;
94  const LocalPoint& simHitPos(simhit->localPosition());
95  const float tof(simhit->timeOfFlight());
96  // random Gaussian time correction due to electronics jitter
97  float randomJitterTime = CLHEP::RandGaussQ::shoot(engine, 0., timeJitter_);
98  const ME0DetId& id(simhit->detUnitId());
99  const ME0EtaPartition* roll(geometry_->etaPartition(id));
100  if (!roll) {
101  throw cms::Exception("Geometry") << "ME0SimpleModel::getSimHitBx() - ME0 simhit id does not match any ME0 roll id: "
102  << id << "\n";
103  return 999;
104  }
105  if (roll->id().region() == 0) {
106  throw cms::Exception("Geometry")
107  << "ME0SimpleModel::getSimHitBx() - this ME0 id is from barrel, which cannot happen: " << roll->id() << "\n";
108  }
109  const int nstrips = roll->nstrips();
110  float middleStrip = nstrips / 2.;
111  const LocalPoint& middleOfRoll = roll->centreOfStrip(middleStrip);
112  const GlobalPoint& globMiddleRol = roll->toGlobal(middleOfRoll);
113  double muRadius = sqrt(globMiddleRol.x() * globMiddleRol.x() + globMiddleRol.y() * globMiddleRol.y() +
114  globMiddleRol.z() * globMiddleRol.z());
115  double timeCalibrationOffset_ = (muRadius * CLHEP::ns * CLHEP::cm) / (CLHEP::c_light); //[cm/ns]
116  const TrapezoidalStripTopology* top(dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology())));
117  const float halfStripLength(0.5 * top->stripLength());
118  const float distanceFromEdge(halfStripLength - simHitPos.y());
119 
120  // signal propagation speed in material in [cm/ns]
121  double signalPropagationSpeedTrue = signalPropagationSpeed_ * CLHEP::c_light / (CLHEP::ns * CLHEP::cm);
122  // average time for the signal to propagate from the SimHit to the top of a strip
123  const float averagePropagationTime(distanceFromEdge / signalPropagationSpeedTrue);
124  // random Gaussian time correction due to the finite timing resolution of the detector
125  float randomResolutionTime = CLHEP::RandGaussQ::shoot(engine, 0., timeResolution_);
126  const float simhitTime(tof + averageShapingTime_ + randomResolutionTime + averagePropagationTime + randomJitterTime);
127  float referenceTime = 0.;
128  referenceTime = timeCalibrationOffset_ + halfStripLength / signalPropagationSpeedTrue + averageShapingTime_;
129  const float timeDifference(simhitTime - referenceTime);
130  // assign the bunch crossing
131  bx = static_cast<int>(std::round((timeDifference) / bxwidth_));
132 
133  // check time
134  const bool debug(false);
135  if (debug) {
136  LogDebug("ME0SimpleModel") << "checktime "
137  << "bx = " << bx << "\tdeltaT = " << timeDifference << "\tsimT = " << simhitTime
138  << "\trefT = " << referenceTime << "\ttof = " << tof
139  << "\tavePropT = " << averagePropagationTime
140  << "\taveRefPropT = " << halfStripLength / signalPropagationSpeedTrue << std::endl;
141  }
142  return bx;
143 }
144 
145 void ME0SimpleModel::simulateNoise(const ME0EtaPartition* roll, CLHEP::HepRandomEngine* engine) {
146  if (!doBkgNoise_)
147  return;
148  const ME0DetId me0Id(roll->id());
149  const int nstrips(roll->nstrips());
150  double trArea(0.0);
151  double trStripArea(0.0);
152 
153  if (me0Id.region() == 0) {
154  throw cms::Exception("Geometry")
155  << "ME0Synchronizer::simulateNoise() - this ME0 id is from barrel, which cannot happen.";
156  }
157  const TrapezoidalStripTopology* top_(dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology())));
158  const float striplength(top_->stripLength());
159  trStripArea = (roll->pitch()) * striplength;
160  trArea = trStripArea * nstrips;
161  const int nBxing(maxBunch_ - minBunch_ + 1);
162  const float rollRadius(
164  ? top_->radius()
165  : top_->radius() + CLHEP::RandFlat::shoot(engine, -1. * top_->stripLength() / 2., top_->stripLength() / 2.));
166 
167  const float rSqrtR = rollRadius * sqrt(rollRadius);
168 
169  //calculate noise from model
170  double averageNeutralNoiseRatePerRoll = 0.;
171  double averageNoiseElectronRatePerRoll = 0.;
172  double averageNoiseRatePerRoll = 0.;
173  if (me0Id.station() != 1) {
174  throw cms::Exception("Geometry")
175  << "ME0SimpleModel::simulateNoise() - this ME0 id is from station 1, which cannot happen: " << roll->id()
176  << "\n";
177  } else {
178  averageNeutralNoiseRatePerRoll = ME0NeuBkgParam0_ * rollRadius * std::exp(ME0NeuBkgParam1_ / rSqrtR) +
179  ME0NeuBkgParam2_ / rSqrtR + ME0NeuBkgParam3_ / (sqrt(rollRadius));
180  //simulate electron background for ME0
182  averageNoiseElectronRatePerRoll = ME0ElecBkgParam0_ * rSqrtR * std::exp(ME0ElecBkgParam1_ / rSqrtR) +
183  ME0ElecBkgParam2_ / rSqrtR + ME0ElecBkgParam3_ / (sqrt(rollRadius));
184  averageNoiseRatePerRoll = averageNeutralNoiseRatePerRoll + averageNoiseElectronRatePerRoll;
185  averageNoiseRatePerRoll *= instLumi_ * rateFact_ * 1.0 / referenceInstLumi_;
186  }
187 
188  //simulate intrinsic noise
190  const double aveIntrinsicNoisePerStrip(averageNoiseRate_ * nBxing * bxwidth_ * trStripArea * 1.0e-9);
191  for (int j = 0; j < nstrips; ++j) {
192  int randPoissonQ = CLHEP::RandPoissonQ::shoot(engine, aveIntrinsicNoisePerStrip);
193 
194  for (int k = 0; k < randPoissonQ; k++) {
195  const int time_hit(static_cast<int>(CLHEP::RandFlat::shoot(engine, nBxing)) + minBunch_);
196  strips_.emplace(k + 1, time_hit);
197  }
198  }
199  } //end simulate intrinsic noise
200 
201  //simulate bkg contribution
202  const double averageNoise(averageNoiseRatePerRoll * nBxing * bxwidth_ * trArea * 1.0e-9);
203  int randPoissonQ = CLHEP::RandPoissonQ::shoot(engine, averageNoise);
204 
205  for (int i = 0; i < randPoissonQ; ++i) {
206  const int centralStrip(static_cast<int>(CLHEP::RandFlat::shoot(engine, 1, nstrips)));
207  const int time_hit(static_cast<int>(CLHEP::RandFlat::shoot(engine, nBxing)) + minBunch_);
208  if (doNoiseCLS_) {
209  std::vector<std::pair<int, int> > cluster;
210  cluster.emplace_back(centralStrip, time_hit);
211  int clusterSize((CLHEP::RandFlat::shoot(engine)) <= 0.53 ? 1 : 2);
212  if (clusterSize == 2) {
213  if (CLHEP::RandFlat::shoot(engine) < 0.5) {
214  if (CLHEP::RandFlat::shoot(engine) < averageEfficiency_ && (centralStrip - 1 > 0))
215  cluster.emplace_back(centralStrip - 1, time_hit);
216  } else {
217  if (CLHEP::RandFlat::shoot(engine) < averageEfficiency_ && (centralStrip + 1 <= nstrips))
218  cluster.emplace_back(centralStrip + 1, time_hit);
219  }
220  }
221  for (const auto& digi : cluster) {
222  strips_.emplace(digi);
223  }
224  } //end doNoiseCLS_
225  else {
226  strips_.emplace(centralStrip, time_hit);
227  }
228  }
229  return;
230 }
231 
232 std::vector<std::pair<int, int> > ME0SimpleModel::simulateClustering(const ME0EtaPartition* roll,
233  const PSimHit* simHit,
234  const int bx,
235  CLHEP::HepRandomEngine* engine) {
236  const StripTopology& topology = roll->specificTopology();
237  const LocalPoint& hit_position(simHit->localPosition());
238  const int nstrips(roll->nstrips());
239  int centralStrip = 0;
240  if (!(topology.channel(hit_position) + 1 > nstrips))
241  centralStrip = topology.channel(hit_position) + 1;
242  else
243  centralStrip = topology.channel(hit_position);
244  const GlobalPoint& pointSimHit = roll->toGlobal(hit_position);
245  const GlobalPoint& pointDigiHit = roll->toGlobal(roll->centreOfStrip(centralStrip));
246  double deltaX = pointSimHit.x() - pointDigiHit.x();
247 
248  // Add central digi to cluster vector
249  std::vector<std::pair<int, int> > cluster;
250  cluster.clear();
251  cluster.emplace_back(centralStrip, bx);
252 
253  //simulate cross talk
254  int clusterSize((CLHEP::RandFlat::shoot(engine)) <= 0.53 ? 1 : 2);
255  if (clusterSize == 2) {
256  if (deltaX <= 0) {
257  if (CLHEP::RandFlat::shoot(engine) < averageEfficiency_ && (centralStrip - 1 > 0))
258  cluster.emplace_back(centralStrip - 1, bx);
259  } else {
260  if (CLHEP::RandFlat::shoot(engine) < averageEfficiency_ && (centralStrip + 1 <= nstrips))
261  cluster.emplace_back(centralStrip + 1, bx);
262  }
263  }
264  return cluster;
265 }
ME0SimpleModel::ME0NeuBkgParam0_
double ME0NeuBkgParam0_
Definition: ME0SimpleModel.h:66
ME0SimpleModel::simulateNoise
void simulateNoise(const ME0EtaPartition *, CLHEP::HepRandomEngine *) override
Definition: ME0SimpleModel.cc:145
ME0SimpleModel::ME0ElecBkgParam1_
double ME0ElecBkgParam1_
Definition: ME0SimpleModel.h:62
ME0SimpleModel::ME0NeuBkgParam3_
double ME0NeuBkgParam3_
Definition: ME0SimpleModel.h:69
PSimHit::timeOfFlight
float timeOfFlight() const
Definition: PSimHit.h:73
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
ME0DigiModel::geometry_
const ME0Geometry * geometry_
Definition: ME0DigiModel.h:62
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::DetSet::clear
void clear()
Definition: DetSet.h:71
ME0SimpleModel::doBkgNoise_
bool doBkgNoise_
Definition: ME0SimpleModel.h:52
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
ME0SimpleModel::digitizeOnlyMuons_
bool digitizeOnlyMuons_
Definition: ME0SimpleModel.h:51
ME0SimpleModel::ME0ElecBkgParam3_
double ME0ElecBkgParam3_
Definition: ME0SimpleModel.h:64
ME0EtaPartitionSpecs.h
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
ME0SimpleModel::doNoiseCLS_
bool doNoiseCLS_
Definition: ME0SimpleModel.h:53
ME0SimpleModel::simulateIntrinsicNoise_
bool simulateIntrinsicNoise_
Definition: ME0SimpleModel.h:55
ME0EtaPartition::pitch
float pitch() const
Definition: ME0EtaPartition.cc:41
ME0DigiModel::theME0DigiSimLinks_
ME0DigiSimLinks theME0DigiSimLinks_
Definition: ME0DigiModel.h:76
ME0SimpleModel::ME0ElecBkgParam2_
double ME0ElecBkgParam2_
Definition: ME0SimpleModel.h:63
ME0DigiModel::strips_
std::set< std::pair< int, int > > strips_
Definition: ME0DigiModel.h:64
PSimHit::detUnitId
unsigned int detUnitId() const
Definition: PSimHit.h:97
ME0SimpleModel::~ME0SimpleModel
~ME0SimpleModel() override
Definition: ME0SimpleModel.cc:45
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
ME0EtaPartition::specificTopology
const StripTopology & specificTopology() const
Definition: ME0EtaPartition.cc:16
config
Definition: config.py:1
debug
#define debug
Definition: HDRShower.cc:19
ME0SimpleModel::simulateElectronBkg_
bool simulateElectronBkg_
Definition: ME0SimpleModel.h:56
ME0EtaPartition::topology
const Topology & topology() const override
Definition: ME0EtaPartition.cc:14
TrapezoidalStripTopology
Definition: TrapezoidalStripTopology.h:21
rpcPointValidation_cfi.simHit
simHit
Definition: rpcPointValidation_cfi.py:24
ME0EtaPartition::centreOfStrip
LocalPoint centreOfStrip(int strip) const
Definition: ME0EtaPartition.cc:26
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Topology::channel
virtual int channel(const LocalPoint &p) const =0
PSimHit::localPosition
Local3DPoint localPosition() const
Definition: PSimHit.h:52
ME0SimpleModel::referenceInstLumi_
double referenceInstLumi_
Definition: ME0SimpleModel.h:59
ME0SimpleModel::bxwidth_
int bxwidth_
Definition: ME0SimpleModel.h:48
dqmdumpme.k
k
Definition: dqmdumpme.py:60
Point3DBase< float, LocalTag >
ME0DigiModel::detectorHitMap_
DetectorHitMap detectorHitMap_
Definition: ME0DigiModel.h:74
ME0SimpleModel::ME0NeuBkgParam2_
double ME0NeuBkgParam2_
Definition: ME0SimpleModel.h:68
ME0EtaPartition::nstrips
int nstrips() const
Return the chamber this roll belongs to.
Definition: ME0EtaPartition.cc:24
ME0DigiModel
Definition: ME0DigiModel.h:32
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
ME0SimpleModel::rateFact_
double rateFact_
Definition: ME0SimpleModel.h:58
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
createfilelist.int
int
Definition: createfilelist.py:10
ME0DigiModel::ME0DigiSimLinks
edm::DetSet< ME0DigiSimLink > ME0DigiSimLinks
Definition: ME0DigiModel.h:35
ME0DetId
Definition: ME0DetId.h:16
ME0SimpleModel::getSimHitBx
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
Definition: ME0SimpleModel.cc:92
ME0SimpleModel::ME0SimpleModel
ME0SimpleModel(const edm::ParameterSet &)
Definition: ME0SimpleModel.cc:17
ME0EtaPartition::id
ME0DetId id() const
Definition: ME0EtaPartition.h:18
ME0SimpleModel::averageShapingTime_
double averageShapingTime_
Definition: ME0SimpleModel.h:43
ME0Geometry.h
ME0SimpleModel::timeJitter_
double timeJitter_
Definition: ME0SimpleModel.h:45
ME0SimpleModel::fixedRollRadius_
bool fixedRollRadius_
Definition: ME0SimpleModel.h:54
ME0SimpleModel::simulateSignal
void simulateSignal(const ME0EtaPartition *, const edm::PSimHitContainer &, CLHEP::HepRandomEngine *) override
Definition: ME0SimpleModel.cc:49
ME0SimpleModel::timeResolution_
double timeResolution_
Definition: ME0SimpleModel.h:44
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
ME0SimpleModel::averageEfficiency_
double averageEfficiency_
Definition: ME0SimpleModel.h:42
TrapezoidalStripTopology.h
ME0SimpleModel::setup
void setup() override
Definition: ME0SimpleModel.cc:47
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
Exception
Definition: hltDiff.cc:245
ME0SimpleModel::ME0NeuBkgParam1_
double ME0NeuBkgParam1_
Definition: ME0SimpleModel.h:67
ME0SimpleModel::maxBunch_
int maxBunch_
Definition: ME0SimpleModel.h:50
Exception.h
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
ME0SimpleModel::averageNoiseRate_
double averageNoiseRate_
Definition: ME0SimpleModel.h:46
ME0DigiModel::stripDigiSimLinks_
StripDigiSimLinks stripDigiSimLinks_
Definition: ME0DigiModel.h:75
ME0SimpleModel::simulateClustering
std::vector< std::pair< int, int > > simulateClustering(const ME0EtaPartition *, const PSimHit *, const int, CLHEP::HepRandomEngine *) override
Definition: ME0SimpleModel.cc:232
ME0SimpleModel::minBunch_
int minBunch_
Definition: ME0SimpleModel.h:49
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
PSimHit
Definition: PSimHit.h:15
ME0Geometry::etaPartition
const ME0EtaPartition * etaPartition(ME0DetId id) const
Return a etaPartition given its id.
Definition: ME0Geometry.cc:35
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
ME0SimpleModel.h
StripTopology
Definition: StripTopology.h:11
ME0SimpleModel::signalPropagationSpeed_
double signalPropagationSpeed_
Definition: ME0SimpleModel.h:47
ME0DigiModel::StripDigiSimLinks
edm::DetSet< StripDigiSimLink > StripDigiSimLinks
Definition: ME0DigiModel.h:34
hit
Definition: SiStripHitEffFromCalibTree.cc:88
ME0SimpleModel::ME0ElecBkgParam0_
double ME0ElecBkgParam0_
Definition: ME0SimpleModel.h:61
ME0EtaPartition
Definition: ME0EtaPartition.h:12
ME0SimpleModel::instLumi_
double instLumi_
Definition: ME0SimpleModel.h:57
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37