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