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<stdlib.h>
33 #include <utility>
34 #include <map>
35 
36 #include "CLHEP/Random/RandFlat.h"
37 #include "CLHEP/Random/RandPoissonQ.h"
38 
39 using namespace std;
40 
42  RPCSim(config)
43 {
44 
45  aveEff = config.getParameter<double>("averageEfficiency");
46  aveCls = config.getParameter<double>("averageClusterSize");
47  resRPC = config.getParameter<double>("timeResolution");
48  timOff = config.getParameter<double>("timingRPCOffset");
49  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
50  resEle = config.getParameter<double>("timeJitter");
51  sspeed = config.getParameter<double>("signalPropagationSpeed");
52  lbGate = config.getParameter<double>("linkGateWidth");
53  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
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  std::cout <<"Average Efficiency = "<<aveEff<<std::endl;
62  std::cout <<"Average Cluster Size = "<<aveCls<<" strips"<<std::endl;
63  std::cout <<"RPC Time Resolution = "<<resRPC<<" ns"<<std::endl;
64  std::cout <<"RPC Signal formation time = "<<timOff<<" ns"<<std::endl;
65  std::cout <<"RPC adjacent strip delay = "<<dtimCs<<" ns"<<std::endl;
66  std::cout <<"Electronic Jitter = "<<resEle<<" ns"<<std::endl;
67  std::cout <<"Signal propagation time = "<<sspeed<<" x c"<<std::endl;
68  std::cout <<"Link Board Gate Width = "<<lbGate<<" ns"<<std::endl;
69  }
70 
71  _rpcSync = new RPCSynchronizer(config);
72 
73 }
74 
76 {
77  delete _rpcSync;
78 }
79 
80 
81 int RPCSimAverageNoiseEffCls::getClSize(uint32_t id,float posX, CLHEP::HepRandomEngine* engine)
82 {
83  std::vector<double> clsForDetId = getRPCSimSetUp()->getCls(id);
84 
85  int cnt = 1;
86  int min = 1;
87  double func=0.0;
88  std::vector<double> sum_clsize;
89 
90  sum_clsize.clear();
91  sum_clsize = clsForDetId;
92  int vectOffset(0);
93 
94  double rr_cl = CLHEP::RandFlat::shoot(engine);
95 
96  if(0.0 <= posX && posX < 0.2) {
97  func = clsForDetId[19]*(rr_cl);
98  vectOffset = 0;
99  }
100  if(0.2 <= posX && posX < 0.4) {
101  func = clsForDetId[39]*(rr_cl);
102  vectOffset = 20;
103  }
104  if(0.4 <= posX && posX < 0.6) {
105  func = clsForDetId[59]*(rr_cl);
106  vectOffset = 40;
107  }
108  if(0.6 <= posX && posX < 0.8) {
109  func = clsForDetId[79]*(rr_cl);
110  vectOffset = 60;
111  }
112  if(0.8 <= posX && posX < 1.0) {
113  func = clsForDetId[89]*(rr_cl);
114  vectOffset = 80;
115  }
116 
117 
118  for(int i = vectOffset; i<(vectOffset+20); i++){
119  cnt++;
120  if(func > clsForDetId[i]){
121  min = cnt;
122  }
123  else if(func < clsForDetId[i]){
124  break;
125  }
126  }
127  return min;
128 }
129 
130 int RPCSimAverageNoiseEffCls::getClSize(float posX, CLHEP::HepRandomEngine* engine)
131 {
132 
133  std::map< int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
134 
135  int cnt = 1;
136  int min = 1;
137  double func=0.0;
138  std::vector<double> sum_clsize;
139 
140  double rr_cl = CLHEP::RandFlat::shoot(engine);
141  if(0.0 <= posX && posX < 0.2) {
142  func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
143  sum_clsize = clsMap[1];
144  }
145  if(0.2 <= posX && posX < 0.4) {
146  func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
147  sum_clsize = clsMap[2];
148  }
149  if(0.4 <= posX && posX < 0.6) {
150  func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
151  sum_clsize = clsMap[3];
152  }
153  if(0.6 <= posX && posX < 0.8) {
154  func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
155  sum_clsize = clsMap[4];
156  }
157  if(0.8 <= posX && posX < 1.0) {
158  func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
159  sum_clsize = clsMap[5];
160  }
161 
162  for(vector<double>::iterator iter = sum_clsize.begin();
163  iter != sum_clsize.end(); ++iter){
164  cnt++;
165  if(func > (*iter)){
166  min = cnt;
167  }
168  else if(func < (*iter)){
169  break;
170  }
171  }
172  return min;
173 }
174 
175 void
177  const edm::PSimHitContainer& rpcHits,
178  CLHEP::HepRandomEngine* engine)
179 {
182  theDetectorHitMap.clear();
184 
185  RPCDetId rpcId = roll->id();
186  RPCGeomServ RPCname(rpcId);
187  //std::string nameRoll = RPCname.name();
188 
189  const Topology& topology=roll->specs()->topology();
190 
191  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
192  _hit != rpcHits.end(); ++_hit){
193 
194  if(_hit-> particleType() == 11) continue;
195  // Here I hould check if the RPC are up side down;
196  const LocalPoint& entr=_hit->entryPoint();
197 
198  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
199  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
200 
201  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
202 
203  // Effinciecy
204  int centralStrip = topology.channel(entr)+1;;
205  float fire = CLHEP::RandFlat::shoot(engine);
206 
207  if (fire < veff[centralStrip-1]) {
208 
209  int fstrip=centralStrip;
210  int lstrip=centralStrip;
211 
212  // Compute the cluster size
213  // double w = CLHEP::RandFlat::shoot(engine);
214  //if (w < 1.e-10) w=1.e-10;
215 // int clsize = this->getClSize(posX, engine); // This is for one and the same cls for all the chambers
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  //std::string nameRoll = RPCname.name();
277 
278  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
279  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
280 
281  unsigned int nstrips = roll->nstrips();
282  double area = 0.0;
283 
284  if ( rpcId.region() == 0 )
285  {
286  const RectangularStripTopology* top_ = dynamic_cast<const
287  RectangularStripTopology*>(&(roll->topology()));
288  float xmin = (top_->localPosition(0.)).x();
289  float xmax = (top_->localPosition((float)roll->nstrips())).x();
290  float striplength = (top_->stripLength());
291  area = striplength*(xmax-xmin);
292  }
293  else
294  {
295  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
296  float xmin = (top_->localPosition(0.)).x();
297  float xmax = (top_->localPosition((float)roll->nstrips())).x();
298  float striplength = (top_->stripLength());
299  area = striplength*(xmax-xmin);
300  }
301 
302  for(unsigned int j = 0; j < vnoise.size(); ++j){
303 
304  if(j >= nstrips) break;
305 
306  // The efficiency of 0% does not imply on the noise rate.
307  // If the strip is masked the noise rate should be 0 Hz/cm^2
308  // if(veff[j] == 0) continue;
309 
310  // double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
311  // The vnoise is the noise rate per strip, so we shout multiply not
312  // by the chamber area,
313  // but the strip area which is area/((float)roll->nstrips()));
314  double ave =
315  vnoise[j]*nbxing*gate*area*1.0e-9*frate/((float)roll->nstrips());
316 
317  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
318  N_hits = randPoissonQ.fire();
319 
320  for (int i = 0; i < N_hits; i++ ){
321 
322  int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing*gate)/gate))) - nbxing/2;
323  std::pair<int, int> digi(j+1,time_hit);
324  strips.insert(digi);
325  }
326  }
327 }
328 
T getParameter(std::string const &) const
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:71
int getClSize(float posX, CLHEP::HepRandomEngine *)
int i
Definition: DBlmapReader.cc:9
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:52
const Topology & topology() const
Definition: RPCRoll.cc:30
virtual float stripLength() const
CaloTopology const * topology(0)
DetectorHitMap theDetectorHitMap
Definition: RPCSim.h:72
void setRPCSimSetUp(RPCSimSetUp *simsetup)
int nstrips() const
Definition: RPCRoll.cc:46
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:50
std::vector< double > clsForDetId
Definition: config.py:1
const RPCRollSpecs * specs() const
Definition: RPCRoll.cc:18
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:60
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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
int j
Definition: DBlmapReader.cc:9
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
virtual LocalPoint localPosition(float strip) const
void clear()
Definition: DetSet.h:69
RPCSimAverageNoiseEffCls(const edm::ParameterSet &config)
std::vector< PSimHit > PSimHitContainer
virtual LocalPoint localPosition(float strip) const
T x() const
Definition: PV3DBase.h:62
virtual float stripLength() const
det heigth (strip length in the middle)
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:74
const Topology & topology() const
Definition: RPCRollSpecs.cc:43
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63