CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCSimAverageNoise.cc
Go to the documentation of this file.
4 
8 
9 #include <cmath>
10 
17 
24 
25 #include<cstring>
26 #include<iostream>
27 #include<fstream>
28 #include<string>
29 #include<vector>
30 #include<stdlib.h>
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  RPCSim(config)
41 {
42  aveEff = config.getParameter<double>("averageEfficiency");
43  aveCls = config.getParameter<double>("averageClusterSize");
44  resRPC = config.getParameter<double>("timeResolution");
45  timOff = config.getParameter<double>("timingRPCOffset");
46  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
47  resEle = config.getParameter<double>("timeJitter");
48  sspeed = config.getParameter<double>("signalPropagationSpeed");
49  lbGate = config.getParameter<double>("linkGateWidth");
50  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
51  rate=config.getParameter<double>("Rate");
52  nbxing=config.getParameter<int>("Nbxing");
53  gate=config.getParameter<double>("Gate");
54  frate=config.getParameter<double>("Frate");
55 
56  if (rpcdigiprint) {
57  std::cout <<"Average Efficiency = "<<aveEff<<std::endl;
58  std::cout <<"Average Cluster Size = "<<aveCls<<" strips"<<std::endl;
59  std::cout <<"RPC Time Resolution = "<<resRPC<<" ns"<<std::endl;
60  std::cout <<"RPC Signal formation time = "<<timOff<<" ns"<<std::endl;
61  std::cout <<"RPC adjacent strip delay = "<<dtimCs<<" ns"<<std::endl;
62  std::cout <<"Electronic Jitter = "<<resEle<<" ns"<<std::endl;
63  std::cout <<"Signal propagation time = "<<sspeed<<" x c"<<std::endl;
64  std::cout <<"Link Board Gate Width = "<<lbGate<<" ns"<<std::endl;
65  }
66 
67  _rpcSync = new RPCSynchronizer(config);
68 
69 }
70 
72 {
73  delete _rpcSync;
74 }
75 
76 int RPCSimAverageNoise::getClSize(float posX, CLHEP::HepRandomEngine* engine)
77 {
78 
79  std::map< int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
80 
81  int cnt = 1;
82  int min = 1;
83  double func=0.0;
84  std::vector<double> sum_clsize;
85 
86  double rr_cl = CLHEP::RandFlat::shoot(engine);
87  if(0.0 <= posX && posX < 0.2) {
88  func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
89  sum_clsize = clsMap[1];
90  }
91  if(0.2 <= posX && posX < 0.4) {
92  func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
93  sum_clsize = clsMap[2];
94  }
95  if(0.4 <= posX && posX < 0.6) {
96  func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
97  sum_clsize = clsMap[3];
98  }
99  if(0.6 <= posX && posX < 0.8) {
100  func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
101  sum_clsize = clsMap[4];
102  }
103  if(0.8 <= posX && posX < 1.0) {
104  func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
105  sum_clsize = clsMap[5];
106  }
107 
108  for(vector<double>::iterator iter = sum_clsize.begin();
109  iter != sum_clsize.end(); ++iter){
110  cnt++;
111  if(func > (*iter)){
112  min = cnt;
113  }
114  else if(func < (*iter)){
115  break;
116  }
117  }
118  return min;
119 }
120 
121 
122 void
124  const edm::PSimHitContainer& rpcHits,
125  CLHEP::HepRandomEngine* engine)
126 {
129  theDetectorHitMap.clear();
131 
132  const Topology& topology=roll->specs()->topology();
133 
134  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
135  _hit != rpcHits.end(); ++_hit){
136 
137  // Here I hould check if the RPC are up side down;
138  const LocalPoint& entr=_hit->entryPoint();
139  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
140  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
141 
142  // Effinciecy
143 
144  if (CLHEP::RandFlat::shoot(engine) < aveEff) {
145 
146  int centralStrip = topology.channel(entr)+1;
147  int fstrip=centralStrip;
148  int lstrip=centralStrip;
149  // Compute the cluster size
150  double w = CLHEP::RandFlat::shoot(engine);
151  if (w < 1.e-10) w=1.e-10;
152  int clsize = this->getClSize(posX, engine);
153 
154  std::vector<int> cls;
155  cls.push_back(centralStrip);
156  if (clsize > 1){
157  for (int cl = 0; cl < (clsize-1)/2; cl++)
158  {
159  if (centralStrip - cl -1 >= 1 ){
160  fstrip = centralStrip-cl-1;
161  cls.push_back(fstrip);
162  }
163  if (centralStrip + cl + 1 <= roll->nstrips() ){
164  lstrip = centralStrip+cl+1;
165  cls.push_back(lstrip);
166  }
167  }
168  if (clsize%2 == 0 ){
169  // insert the last strip according to the
170  // simhit position in the central strip
171  double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
172  if (deltaw<0.) {
173  if (lstrip < roll->nstrips() ){
174  lstrip++;
175  cls.push_back(lstrip);
176  }
177  }else{
178  if (fstrip > 1 ){
179  fstrip--;
180  cls.push_back(fstrip);
181  }
182  }
183  }
184  }
185 
186  for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
187  // Check the timing of the adjacent strip
188  std::pair<int, int> digi(*i,time_hit );
189 
190  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
191  strips.insert(digi);
192  }
193  }
194  }
195 }
196 
197 void RPCSimAverageNoise::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine)
198 {
199  RPCDetId rpcId = roll->id();
200  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
201  unsigned int nstrips = roll->nstrips();
202 
203  double area = 0.0;
204 
205  if ( rpcId.region() == 0 )
206  {
207  const RectangularStripTopology* top_ = dynamic_cast<const
208  RectangularStripTopology*>(&(roll->topology()));
209  float xmin = (top_->localPosition(0.)).x();
210  float xmax = (top_->localPosition((float)roll->nstrips())).x();
211  float striplength = (top_->stripLength());
212  area = striplength*(xmax-xmin);
213  }
214  else
215  {
216  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(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  }
222  for(unsigned int j = 0; j < vnoise.size(); ++j){
223 
224  if(j >= nstrips) break;
225 
226  double ave = frate*vnoise[j]*nbxing*gate*area*1.0e-9;
227  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
228  N_hits = randPoissonQ.fire();
229 
230  for (int i = 0; i < N_hits; i++ ){
231  int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing*gate)/gate))) - nbxing/2;
232  std::pair<int, int> digi(j+1,time_hit);
233  strips.insert(digi);
234  }
235  }
236 }
T getParameter(std::string const &) const
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:71
int i
Definition: DBlmapReader.cc:9
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:52
const Topology & topology() const
Definition: RPCRoll.cc:30
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 *)
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:60
int getClSize(float posX, CLHEP::HepRandomEngine *)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
std::map< int, std::vector< double > > clsMap
edm::DetSet< RPCDigiSimLink > RPCDigiSimLinks
Definition: RPCSim.h:35
RPCDetId id() const
Definition: RPCRoll.cc:24
void simulateNoise(const RPCRoll *, CLHEP::HepRandomEngine *) override
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:205
int j
Definition: DBlmapReader.cc:9
Definition: RPCSim.h:30
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits, CLHEP::HepRandomEngine *) override
Container::value_type value_type
RPCSimAverageNoise(const edm::ParameterSet &config)
RPCSynchronizer * _rpcSync
string const
Definition: compareJSON.py:14
void clear()
Definition: DetSet.h:69
tuple cout
Definition: gather_cfg.py:121
std::vector< PSimHit > PSimHitContainer
T w() const
Definition: DDAxes.h:10
T x() const
Definition: PV3DBase.h:62
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:73
std::vector< double > sum_clsize
const Topology & topology() const
Definition: RPCRollSpecs.cc:43
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63