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  irpc_timing_res = config.getParameter<double>("IRPC_time_resolution");
45  irpc_electronics_jitter = config.getParameter<double>("IRPC_electronics_jitter");
46 
47  //"magic" parameter for cosmics
48  cosmicPar=37.62;
49 
50  double c=299792458;// [m/s]
51  //light speed in [cm/ns]
52  cspeed=c*1e+2*1e-9;
53  //signal propagation speed [cm/ns]
54  sspeed=sspeed*cspeed;
55 }
56 
58 
59 int RPCSynchronizer::getSimHitBx(const PSimHit* simhit, CLHEP::HepRandomEngine* engine)
60 {
61  RPCSimSetUp* simsetup = this->getRPCSimSetUp();
62  const RPCGeometry * geometry = simsetup->getGeometry();
63  float timeref = simsetup->getTime(simhit->detUnitId());
64 
65  int bx = -999;
66  LocalPoint simHitPos = simhit->localPosition();
67  float tof = simhit->timeOfFlight();
68 
69  //automatic variable to prevent memory leak
70 
71  float rr_el = CLHEP::RandGaussQ::shoot(engine, 0.,resEle);
72 
73  RPCDetId SimDetId(simhit->detUnitId());
74 
75  const RPCRoll* SimRoll = 0;
76 
77  for(TrackingGeometry::DetContainer::const_iterator it = geometry->dets().begin(); it != geometry->dets().end(); it++){
78 
79  if( dynamic_cast< const RPCChamber* >( *it ) != 0 ){
80 
81  auto ch = dynamic_cast<const RPCChamber* >( *it );
82 
83  std::vector< const RPCRoll*> rollsRaf = (ch->rolls());
84  for(std::vector<const RPCRoll*>::iterator r = rollsRaf.begin();
85  r != rollsRaf.end(); ++r){
86 
87  if((*r)->id() == SimDetId) {
88  SimRoll = &(*(*r));
89  break;
90  }
91  }
92  }
93  }
94 
95  if(SimRoll != 0){
96 
97  float distanceFromEdge = 0;
98  float half_stripL = 0.;
99 
100  if(SimRoll->id().region() == 0){
101  const RectangularStripTopology* top_= dynamic_cast<const RectangularStripTopology*> (&(SimRoll->topology()));
102  half_stripL = top_->stripLength()/2;
103  distanceFromEdge = half_stripL + simHitPos.y();
104  }else{
105  const TrapezoidalStripTopology* top_= dynamic_cast<const TrapezoidalStripTopology*> (&(SimRoll->topology()));
106  half_stripL = top_->stripLength()/2;
107  distanceFromEdge = half_stripL - simHitPos.y();
108  }
109 
110 
111  float prop_time = distanceFromEdge/sspeed;
112 
113  double rr_tim1 = CLHEP::RandGaussQ::shoot(engine, 0.,resRPC);
114  double total_time = tof + prop_time + timOff + rr_tim1 + rr_el;
115 
116  // Bunch crossing assignment
117  double time_differ = 0.;
118 
119  if(cosmics){
120  time_differ = (total_time - (timeref + ((half_stripL/sspeed ) + timOff)))/cosmicPar;
121  }
122  else if(!cosmics){
123  time_differ = total_time - (timeref + ( half_stripL/sspeed ) + timOff);
124  }
125 
126  double inf_time = 0;
127  double sup_time = 0;
128 
129 
130  for(int n = -5; n <= 5; ++n){
131 
132  if(cosmics){
133  inf_time = (-lbGate/2 + n*LHCGate )/cosmicPar;
134  sup_time = ( lbGate/2 + n*LHCGate )/cosmicPar;
135  }
136  else if(!cosmics){
137  inf_time = -lbGate/2 + n*LHCGate;
138  sup_time = lbGate/2 + n*LHCGate;
139  }
140 
141  if(inf_time < time_differ && time_differ < sup_time) {
142  bx = n;
143  break;
144  }
145  }
146  }
147 
148 
149  return bx;
150 }
151 
152 int RPCSynchronizer::getSimHitBxAndTimingForIRPC(const PSimHit* simhit, CLHEP::HepRandomEngine* engine)
153 {
154 
155  RPCSimSetUp* simsetup = this->getRPCSimSetUp();
156  const RPCGeometry * geometry = simsetup->getGeometry();
157  float timeref = simsetup->getTime(simhit->detUnitId());
158 
159  int bx = -999;
160  LocalPoint simHitPos = simhit->localPosition();
161  float tof = simhit->timeOfFlight();
162 
163  //automatic variable to prevent memory leak
164 
165  // float rr_el = CLHEP::RandGaussQ::shoot(engine, 0.,resEle);
166  float rr_el = CLHEP::RandGaussQ::shoot(engine, 0., irpc_electronics_jitter);
167 
168  RPCDetId SimDetId(simhit->detUnitId());
169 
170  const RPCRoll* SimRoll = 0;
171 
172  for(TrackingGeometry::DetContainer::const_iterator it = geometry->dets().begin(); it != geometry->dets().end(); it++){
173 
174  if( dynamic_cast< const RPCChamber* >( *it ) != 0 ){
175 
176  auto ch = dynamic_cast<const RPCChamber* >( *it );
177 
178  std::vector< const RPCRoll*> rollsRaf = (ch->rolls());
179  for(std::vector<const RPCRoll*>::iterator r = rollsRaf.begin();
180  r != rollsRaf.end(); ++r){
181 
182  if((*r)->id() == SimDetId) {
183  SimRoll = &(*(*r));
184  break;
185  }
186  }
187  }
188  }
189 
190  if(SimRoll != 0){
191 
192  float distanceFromEdge = 0;
193  float half_stripL = 0.;
194 
195  if(SimRoll->id().region() == 0){
196  const RectangularStripTopology* top_= dynamic_cast<const RectangularStripTopology*> (&(SimRoll->topology()));
197  half_stripL = top_->stripLength()/2;
198  distanceFromEdge = half_stripL + simHitPos.y();
199  }
200  else{
201  const TrapezoidalStripTopology* top_= dynamic_cast<const TrapezoidalStripTopology*> (&(SimRoll->topology()));
202  half_stripL = top_->stripLength()/2;
203  distanceFromEdge = half_stripL - simHitPos.y();
204  }
205 
206 
207  float prop_time = distanceFromEdge/sspeed;
208 
209  // double rr_tim1 = CLHEP::RandGaussQ::shoot(engine, 0.,resRPC);
210  double rr_tim1 = CLHEP::RandGaussQ::shoot(engine, 0., irpc_timing_res);
211 
212  double total_time = tof + prop_time + timOff + rr_tim1 + rr_el;
213 
214 
215  // Bunch crossing assignment
216  double time_differ = 0.;
217 
218  if(cosmics){
219  time_differ = (total_time - (timeref + ((half_stripL/sspeed ) + timOff)))/cosmicPar;
220  }
221  else if(!cosmics){
222  time_differ = total_time - (timeref + ( half_stripL/sspeed ) + timOff);
223  }
224 
225  double exact_total_time = tof + prop_time + timOff;
226  double exact_time_differ = 0.;
227 
228  if(cosmics){
229  exact_time_differ = (exact_total_time - (timeref + ((half_stripL/sspeed ) + timOff)))/cosmicPar;
230  }
231  else if(!cosmics){
232  exact_time_differ = exact_total_time - (timeref + ( half_stripL/sspeed ) + timOff);
233  }
234 
235 
236  double inf_time = 0;
237  double sup_time = 0;
238 
239 
240  for(int n = -5; n <= 5; ++n){
241 
242  if(cosmics){
243  inf_time = (-lbGate/2 + n*LHCGate )/cosmicPar;
244  sup_time = ( lbGate/2 + n*LHCGate )/cosmicPar;
245  }
246  else if(!cosmics){
247  inf_time = -lbGate/2 + n*LHCGate;
248  sup_time = lbGate/2 + n*LHCGate;
249  }
250 
251  if(inf_time < time_differ && time_differ < sup_time) {
252  bx = n;
253  the_exact_time=exact_time_differ;
254  the_smeared_time=time_differ;
255 
256  //cout<<"Debug\t"<<inf_time<<'\t'<<sup_time<<endl;
258  // cout<<"Bingo\t"<<time_differ<<'\t'<<bx<<'\t'<<exact_time_differ<<'\t'<<exact_time_differ-time_differ<<'\t'<<exact_time_differ-bx*25.<<endl;
259  break;
260  }
261  }
262  }
263  return bx;
264 }
265 
T getParameter(std::string const &) const
virtual float stripLength() const
float getTime(uint32_t id)
Definition: RPCSimSetUp.cc:386
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
ESHandle< TrackerGeometry > geometry
virtual float stripLength() const
det heigth (strip length in the middle)
int getSimHitBxAndTimingForIRPC(const PSimHit *, CLHEP::HepRandomEngine *)
unsigned int detUnitId() const
Definition: PSimHit.h:93