CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GEMSimAverage.cc
Go to the documentation of this file.
4 
8 
12 
13 #include "CLHEP/Random/RandomEngine.h"
14 #include "CLHEP/Random/RandFlat.h"
15 #include "CLHEP/Random/RandPoissonQ.h"
16 
17 #include <cmath>
18 #include <utility>
19 #include <map>
20 
21 
23  GEMSim(config)
24 {
25  averageEfficiency_ = config.getParameter<double>("averageEfficiency");
26  averageShapingTime_ = config.getParameter<double>("averageShapingTime");
27  averageNoiseRate_ = config.getParameter<double>("averageNoiseRate");
28  bxwidth_ = config.getParameter<double>("bxwidth");
29  minBunch_ = config.getParameter<int>("minBunch");
30  maxBunch_ = config.getParameter<int>("maxBunch");
31 
32  sync_ = new GEMSynchronizer(config);
33 }
34 
35 void GEMSimAverage::setRandomEngine(CLHEP::HepRandomEngine& eng)
36 {
37  flatDistr1_ = new CLHEP::RandFlat(eng);
38  flatDistr2_ = new CLHEP::RandFlat(eng);
39  poissonDistr_ = new CLHEP::RandPoissonQ(eng);
40  sync_->setRandomEngine(eng);
41 }
42 
43 
45 {
46  if (flatDistr1_) delete flatDistr1_;
47  if (flatDistr2_) delete flatDistr2_;
48  if (poissonDistr_) delete poissonDistr_;
49  delete sync_;
50 }
51 
54 {
57  detectorHitMap_.clear();
59 
60  const Topology& topology = roll->specs()->topology();
61 
62  for (const auto & hit: simHits)
63  {
64  if (std::abs(hit.particleType()) != 13) continue;
65  // Check GEM efficiency
66  if (flatDistr1_->fire(1) > averageEfficiency_) continue;
67  auto entry = hit.entryPoint();
68 
69  int time_hit = sync_->getSimHitBx(&hit);
70  std::pair<int, int> digi(topology.channel(entry) + 1, time_hit);
71 
73  strips_.insert(digi);
74  }
75 }
76 
77 
79 {
80  GEMDetId gemId = roll->id();
81  int nstrips = roll->nstrips();
82  double area = 0.0;
83 
84  if ( gemId.region() == 0 )
85  {
86  throw cms::Exception("Geometry")
87  << "GEMSynchronizer::simulateNoise() - this GEM id is from barrel, which cannot happen.";
88  }
89  else
90  {
91  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
92  float xmin = (top_->localPosition(0.)).x();
93  float xmax = (top_->localPosition((float)roll->nstrips())).x();
94  float striplength = (top_->stripLength());
95  area = striplength*(xmax-xmin);
96  }
97 
98  const int nBxing = maxBunch_ - minBunch_ + 1;
99  double averageNoise = averageNoiseRate_ * nBxing * bxwidth_ * area * 1.0e-9;
100 
101  int n_hits = poissonDistr_->fire(averageNoise);
102 
103  for (int i = 0; i < n_hits; i++ ){
104  int strip = static_cast<int>(flatDistr1_->fire(1,nstrips));
105  int time_hit = static_cast<int>(flatDistr2_->fire(nBxing)) + minBunch_;
106  std::pair<int, int> digi(strip,time_hit);
107  strips_.insert(digi);
108  }
109 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
DetectorHitMap detectorHitMap_
Definition: GEMSim.h:67
CLHEP::RandFlat * flatDistr2_
Definition: GEMSimAverage.h:52
void setRandomEngine(CLHEP::HepRandomEngine &eng)
Definition: GEMSim.h:26
edm::DetSet< StripDigiSimLink > StripDigiSimLinks
Definition: GEMSim.h:30
std::set< std::pair< int, int > > strips_
Definition: GEMSim.h:54
double averageNoiseRate_
Definition: GEMSimAverage.h:45
const Topology & topology() const
GEMDetId id() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
const Topology & topology() const
void setRandomEngine(CLHEP::HepRandomEngine &eng)
int nstrips() const
Return the chamber this roll belongs to.
double averageEfficiency_
Definition: GEMSimAverage.h:43
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CLHEP::RandFlat * flatDistr1_
Definition: GEMSimAverage.h:51
void simulateNoise(const GEMEtaPartition *roll)
Container::value_type value_type
int region() const
Region id: 0 for Barrel Not in use, +/-1 For +/- Endcap.
Definition: GEMDetId.h:53
double averageShapingTime_
Definition: GEMSimAverage.h:44
void setGEMSimSetUp(GEMSimSetUp *simsetup)
const GEMEtaPartitionSpecs * specs() const
CLHEP::RandPoissonQ * poissonDistr_
Definition: GEMSimAverage.h:53
tuple simHits
Definition: trackerHits.py:16
GEMSimSetUp * getGEMSimSetUp()
Definition: GEMSim.h:44
void clear()
Definition: DetSet.h:69
int getSimHitBx(const PSimHit *)
std::vector< PSimHit > PSimHitContainer
Definition: DDAxes.h:10
GEMSynchronizer * sync_
Definition: GEMSimAverage.h:42
StripDigiSimLinks stripDigiSimLinks_
Definition: GEMSim.h:68
void simulate(const GEMEtaPartition *roll, const edm::PSimHitContainer &rpcHits)
GEMSimAverage(const edm::ParameterSet &config)