CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
180 
183  theDetectorHitMap.clear();
185 
186  RPCDetId rpcId = roll->id();
187  RPCGeomServ RPCname(rpcId);
188  //std::string nameRoll = RPCname.name();
189 
190  const Topology& topology=roll->specs()->topology();
191 
192  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
193  _hit != rpcHits.end(); ++_hit){
194 
195  if(_hit-> particleType() == 11) continue;
196 
197  // Here I hould check if the RPC are up side down;
198  const LocalPoint& entr=_hit->entryPoint();
199 
200  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
201  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
202 
203  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
204 
205  // Effinciecy
206  int centralStrip = topology.channel(entr)+1;;
207  float fire = CLHEP::RandFlat::shoot(engine);
208 
209  if (fire < veff[centralStrip-1]) {
210 
211  int fstrip=centralStrip;
212  int lstrip=centralStrip;
213 
214  // Compute the cluster size
215  // double w = CLHEP::RandFlat::shoot(engine);
216  //if (w < 1.e-10) w=1.e-10;
217 // int clsize = this->getClSize(posX, engine); // This is for one and the same cls for all the chambers
218  int clsize = this->getClSize(rpcId.rawId(),posX, engine); // This is for cluster size chamber by chamber
219  std::vector<int> cls;
220  cls.push_back(centralStrip);
221  if (clsize > 1){
222  for (int cl = 0; cl < (clsize-1)/2; cl++){
223  if (centralStrip - cl -1 >= 1 ){
224  fstrip = centralStrip-cl-1;
225  cls.push_back(fstrip);
226  }
227  if (centralStrip + cl + 1 <= roll->nstrips() ){
228  lstrip = centralStrip+cl+1;
229  cls.push_back(lstrip);
230  }
231  }
232  if (clsize%2 == 0 ){
233  // insert the last strip according to the
234  // simhit position in the central strip
235  double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
236  if (deltaw<0.) {
237  if (lstrip < roll->nstrips() ){
238  lstrip++;
239  cls.push_back(lstrip);
240  }
241  }else{
242  if (fstrip > 1 ){
243  fstrip--;
244  cls.push_back(fstrip);
245  }
246  }
247  }
248  }
249 
250  for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
251  // Check the timing of the adjacent strip
252  if(*i != centralStrip){
253  if(CLHEP::RandFlat::shoot(engine) < veff[*i-1]){
254  std::pair<int, int> digi(*i,time_hit);
255  strips.insert(digi);
256 
257  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
258  }
259  }
260  else {
261  std::pair<int, int> digi(*i,time_hit);
262  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
263 
264  strips.insert(digi);
265  }
266  }
267  }
268  }
269 }
270 
272  CLHEP::HepRandomEngine* engine)
273 {
274 
275  RPCDetId rpcId = roll->id();
276 
277  RPCGeomServ RPCname(rpcId);
278  //std::string nameRoll = RPCname.name();
279 
280  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
281  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
282 
283  unsigned int nstrips = roll->nstrips();
284  double area = 0.0;
285 
286  if ( rpcId.region() == 0 )
287  {
288  const RectangularStripTopology* top_ = dynamic_cast<const
289  RectangularStripTopology*>(&(roll->topology()));
290  float xmin = (top_->localPosition(0.)).x();
291  float xmax = (top_->localPosition((float)roll->nstrips())).x();
292  float striplength = (top_->stripLength());
293  area = striplength*(xmax-xmin);
294  }
295  else
296  {
297  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
298  float xmin = (top_->localPosition(0.)).x();
299  float xmax = (top_->localPosition((float)roll->nstrips())).x();
300  float striplength = (top_->stripLength());
301  area = striplength*(xmax-xmin);
302  }
303 
304  for(unsigned int j = 0; j < vnoise.size(); ++j){
305 
306  if(j >= nstrips) break;
307 
308  // The efficiency of 0% does not imply on the noise rate.
309  // If the strip is masked the noise rate should be 0 Hz/cm^2
310  // if(veff[j] == 0) continue;
311 
312  // double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
313  // The vnoise is the noise rate per strip, so we shout multiply not
314  // by the chamber area,
315  // but the strip area which is area/((float)roll->nstrips()));
316  double ave =
317  vnoise[j]*nbxing*gate*area*1.0e-9*frate/((float)roll->nstrips());
318 
319  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
320  N_hits = randPoissonQ.fire();
321 
322  for (int i = 0; i < N_hits; i++ ){
323 
324  int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing*gate)/gate))) - nbxing/2;
325  std::pair<int, int> digi(j+1,time_hit);
326  strips.insert(digi);
327  }
328  }
329 }
330 
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:71
void setRPCSimSetUp(RPCSimSetUp *simsetup)
int nstrips() const
Definition: RPCRoll.cc:46
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:50
std::vector< double > clsForDetId
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
string const
Definition: compareJSON.py:14
virtual LocalPoint localPosition(float strip) const
void clear()
Definition: DetSet.h:69
tuple cout
Definition: gather_cfg.py:145
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:73
const Topology & topology() const
Definition: RPCRollSpecs.cc:43
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63