CMS 3D CMS Logo

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