CMS 3D CMS Logo

RPCSimAverage.cc
Go to the documentation of this file.
4 
8 
9 #include <cmath>
10 
15 
22 
23 #include <cstring>
24 #include <iostream>
25 #include <fstream>
26 #include <string>
27 #include <vector>
28 #include <cstdlib>
29 #include <utility>
30 #include <map>
31 
32 #include "CLHEP/Random/RandFlat.h"
33 #include "CLHEP/Random/RandPoissonQ.h"
34 
35 using namespace std;
36 
38  aveEff = config.getParameter<double>("averageEfficiency");
39  aveCls = config.getParameter<double>("averageClusterSize");
40  resRPC = config.getParameter<double>("timeResolution");
41  timOff = config.getParameter<double>("timingRPCOffset");
42  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
43  resEle = config.getParameter<double>("timeJitter");
44  sspeed = config.getParameter<double>("signalPropagationSpeed");
45  lbGate = config.getParameter<double>("linkGateWidth");
46  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
47  rate = config.getParameter<double>("Rate");
48  nbxing = config.getParameter<int>("Nbxing");
49  gate = config.getParameter<double>("Gate");
50 
51  if (rpcdigiprint) {
52  std::cout << "Average Efficiency = " << aveEff << std::endl;
53  std::cout << "Average Cluster Size = " << aveCls << " strips" << std::endl;
54  std::cout << "RPC Time Resolution = " << resRPC << " ns" << std::endl;
55  std::cout << "RPC Signal formation time = " << timOff << " ns" << std::endl;
56  std::cout << "RPC adjacent strip delay = " << dtimCs << " ns" << std::endl;
57  std::cout << "Electronic Jitter = " << resEle << " ns" << std::endl;
58  std::cout << "Signal propagation time = " << sspeed << " x c" << std::endl;
59  std::cout << "Link Board Gate Width = " << lbGate << " ns" << std::endl;
60  }
61 
63 }
64 
66 
67 int RPCSimAverage::getClSize(float posX, CLHEP::HepRandomEngine* engine) {
68  std::map<int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
69 
70  int cnt = 1;
71  int min = 1;
72  double func = 0.0;
73  std::vector<double> sum_clsize;
74 
75  double rr_cl = CLHEP::RandFlat::shoot(engine);
76  if (0.0 <= posX && posX < 0.2) {
77  func = (clsMap[1])[(clsMap[1]).size() - 1] * (rr_cl);
78  sum_clsize = clsMap[1];
79  }
80  if (0.2 <= posX && posX < 0.4) {
81  func = (clsMap[2])[(clsMap[2]).size() - 1] * (rr_cl);
82  sum_clsize = clsMap[2];
83  }
84  if (0.4 <= posX && posX < 0.6) {
85  func = (clsMap[3])[(clsMap[3]).size() - 1] * (rr_cl);
86  sum_clsize = clsMap[3];
87  }
88  if (0.6 <= posX && posX < 0.8) {
89  func = (clsMap[4])[(clsMap[4]).size() - 1] * (rr_cl);
90  sum_clsize = clsMap[4];
91  }
92  if (0.8 <= posX && posX < 1.0) {
93  func = (clsMap[5])[(clsMap[5]).size() - 1] * (rr_cl);
94  sum_clsize = clsMap[5];
95  }
96 
97  for (vector<double>::iterator iter = sum_clsize.begin(); iter != sum_clsize.end(); ++iter) {
98  cnt++;
99  if (func > (*iter)) {
100  min = cnt;
101  } else if (func < (*iter)) {
102  break;
103  }
104  }
105  return min;
106 }
107 
109  const edm::PSimHitContainer& rpcHits,
110  CLHEP::HepRandomEngine* engine) {
113  theDetectorHitMap.clear();
114  theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
115 
116  const Topology& topology = roll->specs()->topology();
117 
118  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin(); _hit != rpcHits.end(); ++_hit) {
119  // Here I hould check if the RPC are up side down;
120  const LocalPoint& entr = _hit->entryPoint();
121 
122  // const LocalPoint& exit=_hit->exitPoint();
123 
124  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
125  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
126 
127  // Effinciecy
128 
129  if (CLHEP::RandFlat::shoot(engine) < aveEff) {
130  int centralStrip = topology.channel(entr) + 1;
131  int fstrip = centralStrip;
132  int lstrip = centralStrip;
133  // Compute the cluster size
134  //double w = CLHEP::RandFlat::shoot(engine);
135  //if (w < 1.e-10) w=1.e-10;
136  int clsize = this->getClSize(posX, engine);
137 
138  std::vector<int> cls;
139  cls.push_back(centralStrip);
140  if (clsize > 1) {
141  for (int cl = 0; cl < (clsize - 1) / 2; cl++)
142  if (centralStrip - cl - 1 >= 1) {
143  fstrip = centralStrip - cl - 1;
144  cls.push_back(fstrip);
145  }
146  for (int cl = 0; cl < (clsize - 1) / 2; cl++)
147  if (centralStrip + cl + 1 <= roll->nstrips()) {
148  lstrip = centralStrip + cl + 1;
149  cls.push_back(lstrip);
150  }
151  if (clsize % 2 == 0) {
152  // insert the last strip according to the
153  // simhit position in the central strip
154  double deltaw = roll->centreOfStrip(centralStrip).x() - entr.x();
155  if (deltaw < 0.) {
156  if (lstrip < roll->nstrips()) {
157  lstrip++;
158  cls.push_back(lstrip);
159  }
160  } else {
161  if (fstrip > 1) {
162  fstrip--;
163  cls.push_back(fstrip);
164  }
165  }
166  }
167  }
168 
169  for (std::vector<int>::iterator i = cls.begin(); i != cls.end(); i++) {
170  // Check the timing of the adjacent strip
171  std::pair<int, int> digi(*i, time_hit);
172  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
173  strips.insert(digi);
174  }
175  }
176  }
177 }
178 
179 void RPCSimAverage::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine) {
180  RPCDetId rpcId = roll->id();
181  int nstrips = roll->nstrips();
182  double area = 0.0;
183 
184  if (rpcId.region() == 0) {
185  const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(roll->topology()));
186  float xmin = (top_->localPosition(0.)).x();
187  float xmax = (top_->localPosition((float)roll->nstrips())).x();
188  float striplength = (top_->stripLength());
189  area = striplength * (xmax - xmin);
190  } else {
191  const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
192  float xmin = (top_->localPosition(0.)).x();
193  float xmax = (top_->localPosition((float)roll->nstrips())).x();
194  float striplength = (top_->stripLength());
195  area = striplength * (xmax - xmin);
196  }
197 
198  double ave = rate * nbxing * gate * area * 1.0e-9;
199 
200  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
201  N_hits = randPoissonQ.fire();
202 
203  for (int i = 0; i < N_hits; i++) {
204  int strip = static_cast<int>(CLHEP::RandFlat::shoot(engine, 1, nstrips));
205  int time_hit;
206  time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing * gate) / gate))) - nbxing / 2;
207  std::pair<int, int> digi(strip, time_hit);
208  strips.insert(digi);
209  }
210 }
std::vector< double > sum_clsize
Definition: RPCSimAverage.h:58
void simulateNoise(const RPCRoll *, CLHEP::HepRandomEngine *) override
LocalPoint localPosition(float strip) const override
int getClSize(float posX, CLHEP::HepRandomEngine *)
DetectorHitMap theDetectorHitMap
Definition: RPCSim.h:68
void setRPCSimSetUp(RPCSimSetUp *simsetup)
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:45
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits, CLHEP::HepRandomEngine *) override
Definition: config.py:1
~RPCSimAverage() override
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
float stripLength() const override
T x() const
Definition: PV3DBase.h:59
edm::DetSet< RPCDigiSimLink > RPCDigiSimLinks
Definition: RPCSim.h:33
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:55
std::map< int, std::vector< double > > clsMap
Definition: RPCSimAverage.h:57
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:454
Definition: RPCSim.h:30
RPCSynchronizer * _rpcSync
Definition: RPCSimAverage.h:61
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
RPCSimAverage(const edm::ParameterSet &config)
void clear()
Definition: DetSet.h:71
std::vector< PSimHit > PSimHitContainer
float stripLength() const override
det heigth (strip length in the middle)
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:70
LocalPoint localPosition(float strip) const override