CMS 3D CMS Logo

RPCSimAverageNoiseEffCls.cc
Go to the documentation of this file.
5 
10 
11 #include <cmath>
12 
19 
26 
27 #include <cstring>
28 #include <iostream>
29 #include <fstream>
30 #include <string>
31 #include <vector>
32 #include <cstdlib>
33 #include <utility>
34 #include <map>
35 
36 #include "CLHEP/Random/RandFlat.h"
37 #include "CLHEP/Random/RandPoissonQ.h"
38 
40 
41 using namespace std;
42 
44  aveEff = config.getParameter<double>("averageEfficiency");
45  aveCls = config.getParameter<double>("averageClusterSize");
46  resRPC = config.getParameter<double>("timeResolution");
47  timOff = config.getParameter<double>("timingRPCOffset");
48  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
49  resEle = config.getParameter<double>("timeJitter");
50  sspeed = config.getParameter<double>("signalPropagationSpeed");
51  lbGate = config.getParameter<double>("linkGateWidth");
52  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
53  eledig = config.getParameter<bool>("digitizeElectrons"); //flag to turn on/off electron digitization
54 
55  rate = config.getParameter<double>("Rate");
56  nbxing = config.getParameter<int>("Nbxing");
57  gate = config.getParameter<double>("Gate");
58  frate = config.getParameter<double>("Frate");
59 
60  if (rpcdigiprint) {
61  edm::LogInfo("RPC digitizer parameters") << "Average Efficiency = " << aveEff << '\n'
62  << "Average Cluster Size = " << aveCls << " strips" << '\n'
63  << "RPC Time Resolution = " << resRPC << " ns" << '\n'
64  << "RPC Signal formation time = " << timOff << " ns" << '\n'
65  << "RPC adjacent strip delay = " << dtimCs << " ns" << '\n'
66  << "Electronic Jitter = " << resEle << " ns" << '\n'
67  << "Signal propagation time = " << sspeed << " x c" << '\n'
68  << "Link Board Gate Width = " << lbGate << " ns" << '\n';
69  }
70 
71  _rpcSync = new RPCSynchronizer(config);
72 }
73 
75 
76 int RPCSimAverageNoiseEffCls::getClSize(uint32_t id, float posX, CLHEP::HepRandomEngine* engine) {
77  std::vector<double> clsForDetId = getRPCSimSetUp()->getCls(id);
78 
79  int cnt = 1;
80  int min = 1;
81  double func = 0.0;
82  std::vector<double> sum_clsize;
83 
84  sum_clsize.clear();
85  sum_clsize = clsForDetId;
86  int vectOffset(0);
87 
88  double rr_cl = CLHEP::RandFlat::shoot(engine);
89 
90  if (0.0 <= posX && posX < 0.2) {
91  func = clsForDetId[19] * (rr_cl);
92  vectOffset = 0;
93  }
94  if (0.2 <= posX && posX < 0.4) {
95  func = clsForDetId[39] * (rr_cl);
96  vectOffset = 20;
97  }
98  if (0.4 <= posX && posX < 0.6) {
99  func = clsForDetId[59] * (rr_cl);
100  vectOffset = 40;
101  }
102  if (0.6 <= posX && posX < 0.8) {
103  func = clsForDetId[79] * (rr_cl);
104  vectOffset = 60;
105  }
106  if (0.8 <= posX && posX < 1.0) {
107  func = clsForDetId[89] * (rr_cl);
108  vectOffset = 80;
109  }
110 
111  for (int i = vectOffset; i < (vectOffset + 20); i++) {
112  cnt++;
113  if (func > clsForDetId[i]) {
114  min = cnt;
115  } else if (func < clsForDetId[i]) {
116  break;
117  }
118  }
119  return min;
120 }
121 
122 int RPCSimAverageNoiseEffCls::getClSize(float posX, CLHEP::HepRandomEngine* engine) {
123  std::map<int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
124 
125  int cnt = 1;
126  int min = 1;
127  double func = 0.0;
128  std::vector<double> sum_clsize;
129 
130  double rr_cl = CLHEP::RandFlat::shoot(engine);
131  if (0.0 <= posX && posX < 0.2) {
132  func = (clsMap[1])[(clsMap[1]).size() - 1] * (rr_cl);
133  sum_clsize = clsMap[1];
134  }
135  if (0.2 <= posX && posX < 0.4) {
136  func = (clsMap[2])[(clsMap[2]).size() - 1] * (rr_cl);
137  sum_clsize = clsMap[2];
138  }
139  if (0.4 <= posX && posX < 0.6) {
140  func = (clsMap[3])[(clsMap[3]).size() - 1] * (rr_cl);
141  sum_clsize = clsMap[3];
142  }
143  if (0.6 <= posX && posX < 0.8) {
144  func = (clsMap[4])[(clsMap[4]).size() - 1] * (rr_cl);
145  sum_clsize = clsMap[4];
146  }
147  if (0.8 <= posX && posX < 1.0) {
148  func = (clsMap[5])[(clsMap[5]).size() - 1] * (rr_cl);
149  sum_clsize = clsMap[5];
150  }
151 
152  for (vector<double>::iterator iter = sum_clsize.begin(); iter != sum_clsize.end(); ++iter) {
153  cnt++;
154  if (func > (*iter)) {
155  min = cnt;
156  } else if (func < (*iter)) {
157  break;
158  }
159  }
160  return min;
161 }
162 
164  const edm::PSimHitContainer& rpcHits,
165  CLHEP::HepRandomEngine* engine) {
168  theDetectorHitMap.clear();
170 
171  RPCDetId rpcId = roll->id();
172  RPCGeomServ RPCname(rpcId);
173  //std::string nameRoll = RPCname.name();
174 
175  const Topology& topology = roll->specs()->topology();
176 
177  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin(); _hit != rpcHits.end(); ++_hit) {
178  if (!eledig && _hit->particleType() == 11)
179  continue;
180  // Here I hould check if the RPC are up side down;
181  const LocalPoint& entr = _hit->entryPoint();
182 
183  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
184  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
185 
186  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
187 
188  // Effinciecy
189  int centralStrip = topology.channel(entr) + 1;
190  ;
191  float fire = CLHEP::RandFlat::shoot(engine);
192 
193  if (fire < veff[centralStrip - 1]) {
194  int fstrip = centralStrip;
195  int lstrip = centralStrip;
196 
197  // Compute the cluster size
198  int clsize = this->getClSize(rpcId.rawId(), posX, engine); // This is for cluster size chamber by chamber
199  std::vector<int> cls;
200  cls.push_back(centralStrip);
201  if (clsize > 1) {
202  for (int cl = 0; cl < (clsize - 1) / 2; cl++) {
203  if (centralStrip - cl - 1 >= 1) {
204  fstrip = centralStrip - cl - 1;
205  cls.push_back(fstrip);
206  }
207  if (centralStrip + cl + 1 <= roll->nstrips()) {
208  lstrip = centralStrip + cl + 1;
209  cls.push_back(lstrip);
210  }
211  }
212  if (clsize % 2 == 0) {
213  // insert the last strip according to the
214  // simhit position in the central strip
215  double deltaw = roll->centreOfStrip(centralStrip).x() - entr.x();
216  if (deltaw < 0.) {
217  if (lstrip < roll->nstrips()) {
218  lstrip++;
219  cls.push_back(lstrip);
220  }
221  } else {
222  if (fstrip > 1) {
223  fstrip--;
224  cls.push_back(fstrip);
225  }
226  }
227  }
228  }
229 
230  for (std::vector<int>::iterator i = cls.begin(); i != cls.end(); i++) {
231  // Check the timing of the adjacent strip
232  if (*i != centralStrip) {
233  if (CLHEP::RandFlat::shoot(engine) < veff[*i - 1]) {
234  std::pair<int, int> digi(*i, time_hit);
235  strips.insert(digi);
236 
237  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
238  }
239  } else {
240  std::pair<int, int> digi(*i, time_hit);
241  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
242 
243  strips.insert(digi);
244  }
245  }
246  }
247  }
248 }
249 
250 void RPCSimAverageNoiseEffCls::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine) {
251  RPCDetId rpcId = roll->id();
252 
253  RPCGeomServ RPCname(rpcId);
254 
255  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
256  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
257 
258  unsigned int nstrips = roll->nstrips();
259  double area = 0.0;
260 
261  if (rpcId.region() == 0) {
262  const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(roll->topology()));
263  float xmin = (top_->localPosition(0.)).x();
264  float xmax = (top_->localPosition((float)roll->nstrips())).x();
265  float striplength = (top_->stripLength());
266  area = striplength * (xmax - xmin);
267  } else {
268  const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
269  float xmin = (top_->localPosition(0.)).x();
270  float xmax = (top_->localPosition((float)roll->nstrips())).x();
271  float striplength = (top_->stripLength());
272  area = striplength * (xmax - xmin);
273  }
274 
275  for (unsigned int j = 0; j < vnoise.size(); ++j) {
276  if (j >= nstrips)
277  break;
278 
279  // The efficiency of 0% does not imply on the noise rate.
280  // If the strip is masked the noise rate should be 0 Hz/cm^2
281  // if(veff[j] == 0) continue;
282 
283  // double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
284  // The vnoise is the noise rate per strip, so we shout multiply not
285  // by the chamber area,
286  // but the strip area which is area/((float)roll->nstrips()));
287  double ave = vnoise[j] * nbxing * gate * area * 1.0e-9 * frate / ((float)roll->nstrips());
288 
289  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
290  N_hits = randPoissonQ.fire();
291 
292  for (int i = 0; i < N_hits; i++) {
293  int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing * gate) / gate))) - nbxing / 2;
294  std::pair<int, int> digi(j + 1, time_hit);
295  strips.insert(digi);
296  }
297  }
298 }
T getParameter(std::string const &) const
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:35
int getClSize(float posX, CLHEP::HepRandomEngine *)
const Topology & topology() const override
Definition: RPCRollSpecs.cc:36
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:26
LocalPoint localPosition(float strip) const override
CaloTopology const * topology(0)
DetectorHitMap theDetectorHitMap
Definition: RPCSim.h:68
void setRPCSimSetUp(RPCSimSetUp *simsetup)
int nstrips() const
Definition: RPCRoll.cc:24
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
LocalPoint localPosition(float strip) const override
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:45
std::vector< double > clsForDetId
Definition: config.py:1
const RPCRollSpecs * specs() const
Definition: RPCRoll.cc:14
const Topology & topology() const override
Definition: RPCRoll.cc:18
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
std::map< int, std::vector< double > > clsMap
edm::DetSet< RPCDigiSimLink > RPCDigiSimLinks
Definition: RPCSim.h:33
RPCDetId id() const
Definition: RPCRoll.cc:16
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:55
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits, CLHEP::HepRandomEngine *) override
std::vector< double > sum_clsize
void simulateNoise(const RPCRoll *, CLHEP::HepRandomEngine *) override
const std::vector< double > & getCls(uint32_t id)
Definition: RPCSimSetUp.cc:421
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:413
float stripLength() const override
det heigth (strip length in the middle)
virtual int channel(const LocalPoint &p) const =0
Definition: RPCSim.h:30
T min(T a, T b)
Definition: MathUtil.h:58
void clear()
Definition: DetSet.h:72
RPCSimAverageNoiseEffCls(const edm::ParameterSet &config)
std::vector< PSimHit > PSimHitContainer
T x() const
Definition: PV3DBase.h:59
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:70
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
float stripLength() const override