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