CMS 3D CMS Logo

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