CMS 3D CMS Logo

RPCSimAverageNoiseEff.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 
37 using namespace std;
38 
40  aveEff = config.getParameter<double>("averageEfficiency");
41  aveCls = config.getParameter<double>("averageClusterSize");
42  resRPC = config.getParameter<double>("timeResolution");
43  timOff = config.getParameter<double>("timingRPCOffset");
44  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
45  resEle = config.getParameter<double>("timeJitter");
46  sspeed = config.getParameter<double>("signalPropagationSpeed");
47  lbGate = config.getParameter<double>("linkGateWidth");
48  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
49 
50  rate = config.getParameter<double>("Rate");
51  nbxing = config.getParameter<int>("Nbxing");
52  gate = config.getParameter<double>("Gate");
53  frate = config.getParameter<double>("Frate");
54 
55  if (rpcdigiprint) {
56  std::cout << "Average Efficiency = " << aveEff << std::endl;
57  std::cout << "Average Cluster Size = " << aveCls << " strips" << std::endl;
58  std::cout << "RPC Time Resolution = " << resRPC << " ns" << std::endl;
59  std::cout << "RPC Signal formation time = " << timOff << " ns" << std::endl;
60  std::cout << "RPC adjacent strip delay = " << dtimCs << " ns" << std::endl;
61  std::cout << "Electronic Jitter = " << resEle << " ns" << std::endl;
62  std::cout << "Signal propagation time = " << sspeed << " x c" << std::endl;
63  std::cout << "Link Board Gate Width = " << lbGate << " ns" << std::endl;
64  }
65 
67 }
68 
70 
71 int RPCSimAverageNoiseEff::getClSize(float posX, CLHEP::HepRandomEngine* engine) {
72  std::map<int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
73 
74  int cnt = 1;
75  int min = 1;
76  double func = 0.0;
77  std::vector<double> sum_clsize;
78 
79  double rr_cl = CLHEP::RandFlat::shoot(engine);
80  if (0.0 <= posX && posX < 0.2) {
81  func = (clsMap[1])[(clsMap[1]).size() - 1] * (rr_cl);
82  sum_clsize = clsMap[1];
83  }
84  if (0.2 <= posX && posX < 0.4) {
85  func = (clsMap[2])[(clsMap[2]).size() - 1] * (rr_cl);
86  sum_clsize = clsMap[2];
87  }
88  if (0.4 <= posX && posX < 0.6) {
89  func = (clsMap[3])[(clsMap[3]).size() - 1] * (rr_cl);
90  sum_clsize = clsMap[3];
91  }
92  if (0.6 <= posX && posX < 0.8) {
93  func = (clsMap[4])[(clsMap[4]).size() - 1] * (rr_cl);
94  sum_clsize = clsMap[4];
95  }
96  if (0.8 <= posX && posX < 1.0) {
97  func = (clsMap[5])[(clsMap[5]).size() - 1] * (rr_cl);
98  sum_clsize = clsMap[5];
99  }
100 
101  for (vector<double>::iterator iter = sum_clsize.begin(); iter != sum_clsize.end(); ++iter) {
102  cnt++;
103  if (func > (*iter)) {
104  min = cnt;
105  } else if (func < (*iter)) {
106  break;
107  }
108  }
109  return min;
110 }
111 
113  const edm::PSimHitContainer& rpcHits,
114  CLHEP::HepRandomEngine* engine) {
117  theDetectorHitMap.clear();
118  theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
119 
120  RPCDetId rpcId = roll->id();
121  RPCGeomServ RPCname(rpcId);
122  std::string nameRoll = RPCname.name();
123 
124  const Topology& topology = roll->specs()->topology();
125 
126  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin(); _hit != rpcHits.end(); ++_hit) {
127  if (_hit->particleType() == 11)
128  continue;
129 
130  // Here I hould check if the RPC are up side down;
131  const LocalPoint& entr = _hit->entryPoint();
132 
133  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
134  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
135 
136  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
137 
138  // Effinciecy
139  int centralStrip = topology.channel(entr) + 1;
140  ;
141  float fire = CLHEP::RandFlat::shoot(engine);
142 
143  if (fire < veff[centralStrip - 1]) {
144  int fstrip = centralStrip;
145  int lstrip = centralStrip;
146 
147  // Compute the cluster size
148  //double w = CLHEP::RandFlat::shoot(engine);
149  //if (w < 1.e-10) w=1.e-10;
150  int clsize = this->getClSize(posX, engine);
151 
152  std::vector<int> cls;
153  cls.push_back(centralStrip);
154  if (clsize > 1) {
155  for (int cl = 0; cl < (clsize - 1) / 2; cl++) {
156  if (centralStrip - cl - 1 >= 1) {
157  fstrip = centralStrip - cl - 1;
158  cls.push_back(fstrip);
159  }
160  if (centralStrip + cl + 1 <= roll->nstrips()) {
161  lstrip = centralStrip + cl + 1;
162  cls.push_back(lstrip);
163  }
164  }
165  if (clsize % 2 == 0) {
166  // insert the last strip according to the
167  // simhit position in the central strip
168  double deltaw = roll->centreOfStrip(centralStrip).x() - entr.x();
169  if (deltaw < 0.) {
170  if (lstrip < roll->nstrips()) {
171  lstrip++;
172  cls.push_back(lstrip);
173  }
174  } else {
175  if (fstrip > 1) {
176  fstrip--;
177  cls.push_back(fstrip);
178  }
179  }
180  }
181  }
182 
183  for (std::vector<int>::iterator i = cls.begin(); i != cls.end(); i++) {
184  // Check the timing of the adjacent strip
185  if (*i != centralStrip) {
186  if (CLHEP::RandFlat::shoot(engine) < veff[*i - 1]) {
187  std::pair<int, int> digi(*i, time_hit);
188  strips.insert(digi);
189 
190  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
191  }
192  } else {
193  std::pair<int, int> digi(*i, time_hit);
194  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
195 
196  strips.insert(digi);
197  }
198  }
199  }
200  }
201 }
202 
203 void RPCSimAverageNoiseEff::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine) {
204  RPCDetId rpcId = roll->id();
205 
206  RPCGeomServ RPCname(rpcId);
207  std::string nameRoll = RPCname.name();
208 
209  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
210  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
211 
212  unsigned int nstrips = roll->nstrips();
213  double area = 0.0;
214 
215  if (rpcId.region() == 0) {
216  const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(roll->topology()));
217  float xmin = (top_->localPosition(0.)).x();
218  float xmax = (top_->localPosition((float)roll->nstrips())).x();
219  float striplength = (top_->stripLength());
220  area = striplength * (xmax - xmin);
221  } else {
222  const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
223  float xmin = (top_->localPosition(0.)).x();
224  float xmax = (top_->localPosition((float)roll->nstrips())).x();
225  float striplength = (top_->stripLength());
226  area = striplength * (xmax - xmin);
227  }
228 
229  for (unsigned int j = 0; j < vnoise.size(); ++j) {
230  if (j >= nstrips)
231  break;
232 
233  // The efficiency of 0% does not imply on the noise rate.
234  // If the strip is masked the noise rate should be 0 Hz/cm^2
235  // if(veff[j] == 0) continue;
236 
237  // double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
238  // The vnoise is the noise rate per strip, so we shout multiply not
239  // by the chamber area,
240  // but the strip area which is area/((float)roll->nstrips()));
241  double ave = vnoise[j] * nbxing * gate * area * 1.0e-9 * frate / ((float)roll->nstrips());
242 
243  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
244  N_hits = randPoissonQ.fire();
245 
246  for (int i = 0; i < N_hits; i++) {
247  int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing * gate) / gate))) - nbxing / 2;
248  std::pair<int, int> digi(j + 1, time_hit);
249  strips.insert(digi);
250  }
251  }
252 }
std::vector< double > sum_clsize
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
Definition: config.py:1
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
RPCSimAverageNoiseEff(const edm::ParameterSet &config)
float stripLength() const override
T x() const
Definition: PV3DBase.h:59
edm::DetSet< RPCDigiSimLink > RPCDigiSimLinks
Definition: RPCSim.h:33
virtual std::string name()
Definition: RPCGeomServ.cc:11
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:55
void simulateNoise(const RPCRoll *, CLHEP::HepRandomEngine *) override
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits, CLHEP::HepRandomEngine *) override
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:454
virtual int channel(const LocalPoint &p) const =0
Definition: RPCSim.h:30
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
RPCSynchronizer * _rpcSync
void clear()
Definition: DetSet.h:71
std::vector< PSimHit > PSimHitContainer
std::map< int, std::vector< double > > clsMap
float stripLength() const override
det heigth (strip length in the middle)
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:70
LocalPoint localPosition(float strip) const override