CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCSynchronizer.cc
Go to the documentation of this file.
6 
13 
21 
22 #include "CLHEP/Random/RandGaussQ.h"
23 
24 #include<cstring>
25 #include<iostream>
26 #include<fstream>
27 #include<string>
28 #include<vector>
29 #include<stdlib.h>
30 #include <cmath>
31 
32 using namespace std;
33 
35 
36  resRPC = config.getParameter<double>("timeResolution");
37  timOff = config.getParameter<double>("timingRPCOffset");
38  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
39  resEle = config.getParameter<double>("timeJitter");
40  sspeed = config.getParameter<double>("signalPropagationSpeed");
41  lbGate = config.getParameter<double>("linkGateWidth");
42  LHCGate = config.getParameter<double>("Gate");
43  cosmics = config.getParameter<bool>("cosmics");
44 
45  //"magic" parameter for cosmics
46  cosmicPar=37.62;
47 
48  double c=299792458;// [m/s]
49  //light speed in [cm/ns]
50  cspeed=c*1e+2*1e-9;
51  //signal propagation speed [cm/ns]
52  sspeed=sspeed*cspeed;
53 
54 }
55 
57 }
58 
59 
60 int RPCSynchronizer::getSimHitBx(const PSimHit* simhit, CLHEP::HepRandomEngine* engine)
61 {
62 
63  RPCSimSetUp* simsetup = this->getRPCSimSetUp();
64  const RPCGeometry * geometry = simsetup->getGeometry();
65  float timeref = simsetup->getTime(simhit->detUnitId());
66 
67  int bx = -999;
68  LocalPoint simHitPos = simhit->localPosition();
69  float tof = simhit->timeOfFlight();
70 
71  //automatic variable to prevent memory leak
72 
73  float rr_el = CLHEP::RandGaussQ::shoot(engine, 0.,resEle);
74 
75  RPCDetId SimDetId(simhit->detUnitId());
76 
77  const RPCRoll* SimRoll = 0;
78 
79  for(TrackingGeometry::DetContainer::const_iterator it = geometry->dets().begin(); it != geometry->dets().end(); it++){
80 
81  if( dynamic_cast< const RPCChamber* >( *it ) != 0 ){
82 
83  auto ch = dynamic_cast<const RPCChamber* >( *it );
84 
85  std::vector< const RPCRoll*> rollsRaf = (ch->rolls());
86  for(std::vector<const RPCRoll*>::iterator r = rollsRaf.begin();
87  r != rollsRaf.end(); ++r){
88 
89  if((*r)->id() == SimDetId) {
90  SimRoll = &(*(*r));
91  break;
92  }
93  }
94  }
95  }
96 
97  if(SimRoll != 0){
98 
99  float distanceFromEdge = 0;
100  float half_stripL = 0.;
101 
102  if(SimRoll->id().region() == 0){
103  const RectangularStripTopology* top_= dynamic_cast<const RectangularStripTopology*> (&(SimRoll->topology()));
104  half_stripL = top_->stripLength()/2;
105  distanceFromEdge = half_stripL + simHitPos.y();
106  }else{
107  const TrapezoidalStripTopology* top_= dynamic_cast<const TrapezoidalStripTopology*> (&(SimRoll->topology()));
108  half_stripL = top_->stripLength()/2;
109  distanceFromEdge = half_stripL - simHitPos.y();
110  }
111 
112 
113  float prop_time = distanceFromEdge/sspeed;
114 
115  double rr_tim1 = CLHEP::RandGaussQ::shoot(engine, 0.,resRPC);
116  double total_time = tof + prop_time + timOff + rr_tim1 + rr_el;
117 
118  // Bunch crossing assignment
119  double time_differ = 0.;
120 
121  if(cosmics){
122  time_differ = (total_time - (timeref + ((half_stripL/sspeed ) + timOff)))/cosmicPar;
123  }
124  else if(!cosmics){
125  time_differ = total_time - (timeref + ( half_stripL/sspeed ) + timOff);
126  }
127 
128  double inf_time = 0;
129  double sup_time = 0;
130 
131 
132  for(int n = -5; n <= 5; ++n){
133 
134  if(cosmics){
135  inf_time = (-lbGate/2 + n*LHCGate )/cosmicPar;
136  sup_time = ( lbGate/2 + n*LHCGate )/cosmicPar;
137  }
138  else if(!cosmics){
139  inf_time = -lbGate/2 + n*LHCGate;
140  sup_time = lbGate/2 + n*LHCGate;
141  }
142 
143  if(inf_time < time_differ && time_differ < sup_time) {
144  bx = n;
145  break;
146  }
147  }
148  }
149 
150 
151  return bx;
152 }
153 
T getParameter(std::string const &) const
float getTime(uint32_t id)
Definition: RPCSimSetUp.cc:194
T y() const
Definition: PV3DBase.h:63
RPCSynchronizer(const edm::ParameterSet &config)
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
const RPCGeometry * getGeometry()
Definition: RPCSimSetUp.h:50
float timeOfFlight() const
Definition: PSimHit.h:69
Local3DPoint localPosition() const
Definition: PSimHit.h:44
virtual const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: RPCGeometry.cc:33
string bx
Definition: rpc-layouts.py:13
ESHandle< TrackerGeometry > geometry
unsigned int detUnitId() const
Definition: PSimHit.h:93