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>
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 
43  aveEff = config.getParameter<double>("averageEfficiency");
44  aveCls = config.getParameter<double>("averageClusterSize");
45  resRPC = config.getParameter<double>("timeResolution");
46  timOff = config.getParameter<double>("timingRPCOffset");
47  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
48  resEle = config.getParameter<double>("timeJitter");
49  sspeed = config.getParameter<double>("signalPropagationSpeed");
50  lbGate = config.getParameter<double>("linkGateWidth");
51  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
52  rate=config.getParameter<double>("Rate");
53  nbxing=config.getParameter<int>("Nbxing");
54  gate=config.getParameter<double>("Gate");
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 
71  delete _rpcSync;
72 }
73 
74 int RPCSimAverage::getClSize(float posX, CLHEP::HepRandomEngine* engine)
75 {
76 
77  std::map< int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
78 
79  int cnt = 1;
80  int min = 1;
81  double func=0.0;
82  std::vector<double> sum_clsize;
83 
84  double rr_cl = CLHEP::RandFlat::shoot(engine);
85  if(0.0 <= posX && posX < 0.2) {
86  func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
87  sum_clsize = clsMap[1];
88  }
89  if(0.2 <= posX && posX < 0.4) {
90  func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
91  sum_clsize = clsMap[2];
92  }
93  if(0.4 <= posX && posX < 0.6) {
94  func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
95  sum_clsize = clsMap[3];
96  }
97  if(0.6 <= posX && posX < 0.8) {
98  func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
99  sum_clsize = clsMap[4];
100  }
101  if(0.8 <= posX && posX < 1.0) {
102  func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
103  sum_clsize = clsMap[5];
104  }
105 
106  for(vector<double>::iterator iter = sum_clsize.begin();
107  iter != sum_clsize.end(); ++iter){
108  cnt++;
109  if(func > (*iter)){
110  min = cnt;
111  }
112  else if(func < (*iter)){
113  break;
114  }
115  }
116  return min;
117 }
118 
119 
120 void
122  const edm::PSimHitContainer& rpcHits,
123  CLHEP::HepRandomEngine* engine)
124 {
127  theDetectorHitMap.clear();
129 
130  const Topology& topology=roll->specs()->topology();
131 
132  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
133  _hit != rpcHits.end(); ++_hit){
134 
135  // Here I hould check if the RPC are up side down;
136  const LocalPoint& entr=_hit->entryPoint();
137 
138  // const LocalPoint& exit=_hit->exitPoint();
139 
140  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
141  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
142 
143  // Effinciecy
144 
145  if (CLHEP::RandFlat::shoot(engine) < aveEff) {
146 
147  int centralStrip = topology.channel(entr)+1;
148  int fstrip=centralStrip;
149  int lstrip=centralStrip;
150  // Compute the cluster size
151  //double w = CLHEP::RandFlat::shoot(engine);
152  //if (w < 1.e-10) w=1.e-10;
153  int clsize = this->getClSize(posX, engine);
154 
155  std::vector<int> cls;
156  cls.push_back(centralStrip);
157  if (clsize > 1){
158  for (int cl = 0; cl < (clsize-1)/2; cl++)
159  if (centralStrip - cl -1 >= 1 ){
160  fstrip = centralStrip-cl-1;
161  cls.push_back(fstrip);
162  }
163  for (int cl = 0; cl < (clsize-1)/2; cl++)
164  if (centralStrip + cl + 1 <= roll->nstrips() ){
165  lstrip = centralStrip+cl+1;
166  cls.push_back(lstrip);
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  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
190  strips.insert(digi);
191  }
192  }
193  }
194 }
195 
197  CLHEP::HepRandomEngine* engine)
198 {
199 
200  RPCDetId rpcId = roll->id();
201  int nstrips = roll->nstrips();
202  double area = 0.0;
203 
204  if ( rpcId.region() == 0 )
205  {
206  const RectangularStripTopology* top_ = dynamic_cast<const
207  RectangularStripTopology*>(&(roll->topology()));
208  float xmin = (top_->localPosition(0.)).x();
209  float xmax = (top_->localPosition((float)roll->nstrips())).x();
210  float striplength = (top_->stripLength());
211  area = striplength*(xmax-xmin);
212  }
213  else
214  {
215  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
216  float xmin = (top_->localPosition(0.)).x();
217  float xmax = (top_->localPosition((float)roll->nstrips())).x();
218  float striplength = (top_->stripLength());
219  area = striplength*(xmax-xmin);
220  }
221 
222  double ave = rate*nbxing*gate*area*1.0e-9;
223 
224  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
225  N_hits = randPoissonQ.fire();
226 
227  for (int i = 0; i < N_hits; i++ ){
228  int strip = static_cast<int>(CLHEP::RandFlat::shoot(engine, 1, nstrips));
229  int time_hit;
230  time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing*gate)/gate))) - nbxing/2;
231  std::pair<int, int> digi(strip,time_hit);
232  strips.insert(digi);
233  }
234 
235 }
T getParameter(std::string const &) const
std::vector< double > sum_clsize
Definition: RPCSimAverage.h:62
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:71
int i
Definition: DBlmapReader.cc:9
void simulateNoise(const RPCRoll *, CLHEP::HepRandomEngine *) override
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:52
const Topology & topology() const
Definition: RPCRoll.cc:30
virtual float stripLength() const
int getClSize(float posX, CLHEP::HepRandomEngine *)
CaloTopology const * topology(0)
DetectorHitMap theDetectorHitMap
Definition: RPCSim.h:72
void setRPCSimSetUp(RPCSimSetUp *simsetup)
int nstrips() const
Definition: RPCRoll.cc:46
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:50
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits, CLHEP::HepRandomEngine *) override
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
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
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:397
Definition: RPCSim.h:30
T min(T a, T b)
Definition: MathUtil.h:58
RPCSynchronizer * _rpcSync
Definition: RPCSimAverage.h:65
virtual LocalPoint localPosition(float strip) const
RPCSimAverage(const edm::ParameterSet &config)
void clear()
Definition: DetSet.h:69
tuple cout
Definition: gather_cfg.py:145
std::vector< PSimHit > PSimHitContainer
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:74
std::map< int, std::vector< double > > clsMap
Definition: RPCSimAverage.h:61
const Topology & topology() const
Definition: RPCRollSpecs.cc:43
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63