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  double func=0.0;
103  std::vector<double> sum_clsize;
104 
105  double rr_cl = flatDistribution_->fire(1);
106  if(0.0 <= posX && posX < 0.2) {
107  func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
108  sum_clsize = clsMap[1];
109  }
110  if(0.2 <= posX && posX < 0.4) {
111  func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
112  sum_clsize = clsMap[2];
113  }
114  if(0.4 <= posX && posX < 0.6) {
115  func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
116  sum_clsize = clsMap[3];
117  }
118  if(0.6 <= posX && posX < 0.8) {
119  func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
120  sum_clsize = clsMap[4];
121  }
122  if(0.8 <= posX && posX < 1.0) {
123  func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
124  sum_clsize = clsMap[5];
125  }
126 
127  for(vector<double>::iterator iter = sum_clsize.begin();
128  iter != sum_clsize.end(); ++iter){
129  cnt++;
130  if(func > (*iter)){
131  min = cnt;
132  }
133  else if(func < (*iter)){
134  break;
135  }
136  }
137  return min;
138 }
139 
140 
141 void
143  const edm::PSimHitContainer& rpcHits)
144 {
147  theDetectorHitMap.clear();
149 
150  const Topology& topology=roll->specs()->topology();
151 
152  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
153  _hit != rpcHits.end(); ++_hit){
154 
155  // Here I hould check if the RPC are up side down;
156  const LocalPoint& entr=_hit->entryPoint();
157 
158  // const LocalPoint& exit=_hit->exitPoint();
159 
160  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
161  int time_hit = _rpcSync->getSimHitBx(&(*_hit));
162 
163  // Effinciecy
164 
165  if (flatDistribution_->fire(1) < aveEff) {
166 
167  int centralStrip = topology.channel(entr)+1;
168  int fstrip=centralStrip;
169  int lstrip=centralStrip;
170  // Compute the cluster size
171  double w = flatDistribution_->fire(1);
172  if (w < 1.e-10) w=1.e-10;
173  int clsize = this->getClSize(posX);
174 
175  std::vector<int> cls;
176  cls.push_back(centralStrip);
177  if (clsize > 1){
178  for (int cl = 0; cl < (clsize-1)/2; cl++)
179  if (centralStrip - cl -1 >= 1 ){
180  fstrip = centralStrip-cl-1;
181  cls.push_back(fstrip);
182  }
183  for (int cl = 0; cl < (clsize-1)/2; cl++)
184  if (centralStrip + cl + 1 <= roll->nstrips() ){
185  lstrip = centralStrip+cl+1;
186  cls.push_back(lstrip);
187  }
188  if (clsize%2 == 0 ){
189  // insert the last strip according to the
190  // simhit position in the central strip
191  double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
192  if (deltaw<0.) {
193  if (lstrip < roll->nstrips() ){
194  lstrip++;
195  cls.push_back(lstrip);
196  }
197  }else{
198  if (fstrip > 1 ){
199  fstrip--;
200  cls.push_back(fstrip);
201  }
202  }
203  }
204  }
205 
206  for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
207  // Check the timing of the adjacent strip
208  std::pair<int, int> digi(*i,time_hit);
209  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
210  strips.insert(digi);
211  }
212  }
213  }
214 }
215 
217 {
218 
219  RPCDetId rpcId = roll->id();
220  int nstrips = roll->nstrips();
221  double area = 0.0;
222 
223  if ( rpcId.region() == 0 )
224  {
225  const RectangularStripTopology* top_ = dynamic_cast<const
226  RectangularStripTopology*>(&(roll->topology()));
227  float xmin = (top_->localPosition(0.)).x();
228  float xmax = (top_->localPosition((float)roll->nstrips())).x();
229  float striplength = (top_->stripLength());
230  area = striplength*(xmax-xmin);
231  }
232  else
233  {
234  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
235  float xmin = (top_->localPosition(0.)).x();
236  float xmax = (top_->localPosition((float)roll->nstrips())).x();
237  float striplength = (top_->stripLength());
238  area = striplength*(xmax-xmin);
239  }
240 
241  double ave = rate*nbxing*gate*area*1.0e-9;
242 
243  N_hits = poissonDistribution->fire(ave);
244 
245  for (int i = 0; i < N_hits; i++ ){
246  int strip = static_cast<int>(flatDistribution1->fire(1,nstrips));
247  int time_hit;
248  time_hit = (static_cast<int>(flatDistribution2->fire((nbxing*gate)/gate))) - nbxing/2;
249  std::pair<int, int> digi(strip,time_hit);
250  strips.insert(digi);
251  }
252 
253 }
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 std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:195
Definition: RPCSim.h:27
CLHEP::RandFlat * flatDistribution2
Definition: RPCSimAverage.h:73
Container::value_type value_type
float cl
Definition: Combine.cc:71
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:70
tuple cout
Definition: gather_cfg.py:121
std::vector< PSimHit > PSimHitContainer
virtual LocalPoint localPosition(float strip) const
x
Definition: VDTMath.h:216
T x() const
Definition: PV3DBase.h:61
virtual float stripLength() const
det heigth (strip length in the middle)
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:70
T w() const
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:67