CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCSimAverageNoiseEff.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 int RPCSimAverageNoiseEff::getClSize(float posX, CLHEP::HepRandomEngine* engine)
81 {
82 
83  std::map< int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
84 
85  int cnt = 1;
86  int min = 1;
87  double func=0.0;
88  std::vector<double> sum_clsize;
89 
90  double rr_cl = CLHEP::RandFlat::shoot(engine);
91  if(0.0 <= posX && posX < 0.2) {
92  func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
93  sum_clsize = clsMap[1];
94  }
95  if(0.2 <= posX && posX < 0.4) {
96  func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
97  sum_clsize = clsMap[2];
98  }
99  if(0.4 <= posX && posX < 0.6) {
100  func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
101  sum_clsize = clsMap[3];
102  }
103  if(0.6 <= posX && posX < 0.8) {
104  func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
105  sum_clsize = clsMap[4];
106  }
107  if(0.8 <= posX && posX < 1.0) {
108  func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
109  sum_clsize = clsMap[5];
110  }
111 
112  for(vector<double>::iterator iter = sum_clsize.begin();
113  iter != sum_clsize.end(); ++iter){
114  cnt++;
115  if(func > (*iter)){
116  min = cnt;
117  }
118  else if(func < (*iter)){
119  break;
120  }
121  }
122  return min;
123 }
124 
125 void
127  const edm::PSimHitContainer& rpcHits,
128  CLHEP::HepRandomEngine* engine)
129 {
130 
133  theDetectorHitMap.clear();
135 
136  RPCDetId rpcId = roll->id();
137  RPCGeomServ RPCname(rpcId);
138  std::string nameRoll = RPCname.name();
139 
140  const Topology& topology=roll->specs()->topology();
141 
142  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
143  _hit != rpcHits.end(); ++_hit){
144 
145  if(_hit-> particleType() == 11) continue;
146 
147  // Here I hould check if the RPC are up side down;
148  const LocalPoint& entr=_hit->entryPoint();
149 
150  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
151  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
152 
153  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
154 
155  // Effinciecy
156  int centralStrip = topology.channel(entr)+1;;
157  float fire = CLHEP::RandFlat::shoot(engine);
158 
159  if (fire < veff[centralStrip-1]) {
160 
161  int fstrip=centralStrip;
162  int lstrip=centralStrip;
163 
164  // Compute the cluster size
165  //double w = CLHEP::RandFlat::shoot(engine);
166  //if (w < 1.e-10) w=1.e-10;
167  int clsize = this->getClSize(posX, engine);
168 
169  std::vector<int> cls;
170  cls.push_back(centralStrip);
171  if (clsize > 1){
172  for (int cl = 0; cl < (clsize-1)/2; cl++){
173  if (centralStrip - cl -1 >= 1 ){
174  fstrip = centralStrip-cl-1;
175  cls.push_back(fstrip);
176  }
177  if (centralStrip + cl + 1 <= roll->nstrips() ){
178  lstrip = centralStrip+cl+1;
179  cls.push_back(lstrip);
180  }
181  }
182  if (clsize%2 == 0 ){
183  // insert the last strip according to the
184  // simhit position in the central strip
185  double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
186  if (deltaw<0.) {
187  if (lstrip < roll->nstrips() ){
188  lstrip++;
189  cls.push_back(lstrip);
190  }
191  }else{
192  if (fstrip > 1 ){
193  fstrip--;
194  cls.push_back(fstrip);
195  }
196  }
197  }
198  }
199 
200  for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
201  // Check the timing of the adjacent strip
202  if(*i != centralStrip){
203  if(CLHEP::RandFlat::shoot(engine) < veff[*i-1]){
204  std::pair<int, int> digi(*i,time_hit);
205  strips.insert(digi);
206 
207  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
208  }
209  }
210  else {
211  std::pair<int, int> digi(*i,time_hit);
212  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
213 
214  strips.insert(digi);
215  }
216  }
217  }
218  }
219 }
220 
222  CLHEP::HepRandomEngine* engine)
223 {
224 
225  RPCDetId rpcId = roll->id();
226 
227  RPCGeomServ RPCname(rpcId);
228  std::string nameRoll = RPCname.name();
229 
230  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
231  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
232 
233  unsigned int nstrips = roll->nstrips();
234  double area = 0.0;
235 
236  if ( rpcId.region() == 0 )
237  {
238  const RectangularStripTopology* top_ = dynamic_cast<const
239  RectangularStripTopology*>(&(roll->topology()));
240  float xmin = (top_->localPosition(0.)).x();
241  float xmax = (top_->localPosition((float)roll->nstrips())).x();
242  float striplength = (top_->stripLength());
243  area = striplength*(xmax-xmin);
244  }
245  else
246  {
247  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
248  float xmin = (top_->localPosition(0.)).x();
249  float xmax = (top_->localPosition((float)roll->nstrips())).x();
250  float striplength = (top_->stripLength());
251  area = striplength*(xmax-xmin);
252  }
253 
254  for(unsigned int j = 0; j < vnoise.size(); ++j){
255 
256  if(j >= nstrips) break;
257 
258  // The efficiency of 0% does not imply on the noise rate.
259  // If the strip is masked the noise rate should be 0 Hz/cm^2
260  // if(veff[j] == 0) continue;
261 
262 
263  // double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
264  // The vnoise is the noise rate per strip, so we shout multiply not
265  // by the chamber area,
266  // but the strip area which is area/((float)roll->nstrips()));
267  double ave =
268  vnoise[j]*nbxing*gate*area*1.0e-9*frate/((float)roll->nstrips());
269 
270  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
271  N_hits = randPoissonQ.fire();
272 
273  for (int i = 0; i < N_hits; i++ ){
274 
275  int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing*gate)/gate))) - nbxing/2;
276  std::pair<int, int> digi(j+1,time_hit);
277  strips.insert(digi);
278  }
279  }
280 }
281 
T getParameter(std::string const &) const
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:71
std::vector< double > sum_clsize
int i
Definition: DBlmapReader.cc:9
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:52
const Topology & topology() const
Definition: RPCRoll.cc:30
int getClSize(float posX, CLHEP::HepRandomEngine *)
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
const RPCRollSpecs * specs() const
Definition: RPCRoll.cc:18
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
RPCSimAverageNoiseEff(const edm::ParameterSet &config)
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
virtual std::string name()
Definition: RPCGeomServ.cc:20
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: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
Container::value_type value_type
string const
Definition: compareJSON.py:14
virtual LocalPoint localPosition(float strip) const
RPCSynchronizer * _rpcSync
void clear()
Definition: DetSet.h:69
tuple cout
Definition: gather_cfg.py:121
std::vector< PSimHit > PSimHitContainer
std::map< int, std::vector< double > > clsMap
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