CMS 3D CMS Logo

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