CMS 3D CMS Logo

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 <cstdlib>
30 #include <cmath>
31 
32 using namespace std;
33 
35  resRPC = config.getParameter<double>("timeResolution");
36  timOff = config.getParameter<double>("timingRPCOffset");
37  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
38  resEle = config.getParameter<double>("timeJitter");
39  sspeed = config.getParameter<double>("signalPropagationSpeed");
40  lbGate = config.getParameter<double>("linkGateWidth");
41  LHCGate = config.getParameter<double>("Gate");
42  cosmics = config.getParameter<bool>("cosmics");
43  irpc_timing_res = config.getParameter<double>("IRPC_time_resolution");
44  irpc_electronics_jitter = config.getParameter<double>("IRPC_electronics_jitter");
45  N_BX = config.getParameter<int>("BX_range");
46  //"magic" parameter for cosmics
47  cosmicPar = 37.62;
48 
49  double c = 299792458; // [m/s]
50  //light speed in [cm/ns]
51  cspeed = c * 1e+2 * 1e-9;
52  //signal propagation speed [cm/ns]
53  sspeed = sspeed * cspeed;
54 }
55 
57 
58 int RPCSynchronizer::getSimHitBx(const PSimHit* simhit, CLHEP::HepRandomEngine* engine) {
59  RPCSimSetUp* simsetup = this->getRPCSimSetUp();
60  const RPCGeometry* geometry = simsetup->getGeometry();
61  float timeref = simsetup->getTime(simhit->detUnitId());
62 
63  int bx = -999;
64  LocalPoint simHitPos = simhit->localPosition();
65  float tof = simhit->timeOfFlight();
66 
67  //automatic variable to prevent memory leak
68 
69  float rr_el = CLHEP::RandGaussQ::shoot(engine, 0., resEle);
70 
71  RPCDetId SimDetId(simhit->detUnitId());
72 
73  const RPCRoll* SimRoll = nullptr;
74 
75  for (TrackingGeometry::DetContainer::const_iterator it = geometry->dets().begin(); it != geometry->dets().end();
76  it++) {
77  if (dynamic_cast<const RPCChamber*>(*it) != nullptr) {
78  auto ch = dynamic_cast<const RPCChamber*>(*it);
79 
80  std::vector<const RPCRoll*> rollsRaf = (ch->rolls());
81  for (std::vector<const RPCRoll*>::iterator r = rollsRaf.begin(); r != rollsRaf.end(); ++r) {
82  if ((*r)->id() == SimDetId) {
83  SimRoll = &(*(*r));
84  break;
85  }
86  }
87  }
88  }
89 
90  if (SimRoll != nullptr) {
91  float distanceFromEdge = 0;
92  float half_stripL = 0.;
93 
94  if (SimRoll->id().region() == 0) {
95  const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(SimRoll->topology()));
96  half_stripL = top_->stripLength() / 2;
97  distanceFromEdge = half_stripL + simHitPos.y();
98  } else {
99  const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(SimRoll->topology()));
100  half_stripL = top_->stripLength() / 2;
101  distanceFromEdge = half_stripL - simHitPos.y();
102  }
103 
104  float prop_time = distanceFromEdge / sspeed;
105 
106  double rr_tim1 = CLHEP::RandGaussQ::shoot(engine, 0., resRPC);
107  double total_time = tof + prop_time + timOff + rr_tim1 + rr_el;
108 
109  // Bunch crossing assignment
110  double time_differ = 0.;
111 
112  if (cosmics) {
113  time_differ = (total_time - (timeref + ((half_stripL / sspeed) + timOff))) / cosmicPar;
114  } else if (!cosmics) {
115  time_differ = total_time - (timeref + (half_stripL / sspeed) + timOff);
116  }
117 
118  double inf_time = 0;
119  double sup_time = 0;
120 
121  for (int n = -N_BX; n <= N_BX; ++n) {
122  if (cosmics) {
123  inf_time = (-lbGate / 2 + n * LHCGate) / cosmicPar;
124  sup_time = (lbGate / 2 + n * LHCGate) / cosmicPar;
125  } else if (!cosmics) {
126  inf_time = -lbGate / 2 + n * LHCGate;
127  sup_time = lbGate / 2 + n * LHCGate;
128  }
129 
130  if (inf_time < time_differ && time_differ < sup_time) {
131  bx = n;
132  break;
133  }
134  }
135  }
136 
137  return bx;
138 }
139 
140 int RPCSynchronizer::getSimHitBxAndTimingForIRPC(const PSimHit* simhit, CLHEP::HepRandomEngine* engine) {
141  RPCSimSetUp* simsetup = this->getRPCSimSetUp();
142  const RPCGeometry* geometry = simsetup->getGeometry();
143  float timeref = simsetup->getTime(simhit->detUnitId());
144 
145  int bx = -999;
146  LocalPoint simHitPos = simhit->localPosition();
147  float tof = simhit->timeOfFlight();
148 
149  //automatic variable to prevent memory leak
150 
151  // float rr_el = CLHEP::RandGaussQ::shoot(engine, 0.,resEle);
152  float rr_el = CLHEP::RandGaussQ::shoot(engine, 0., irpc_electronics_jitter);
153 
154  RPCDetId SimDetId(simhit->detUnitId());
155 
156  const RPCRoll* SimRoll = nullptr;
157 
158  for (TrackingGeometry::DetContainer::const_iterator it = geometry->dets().begin(); it != geometry->dets().end();
159  it++) {
160  if (dynamic_cast<const RPCChamber*>(*it) != nullptr) {
161  auto ch = dynamic_cast<const RPCChamber*>(*it);
162 
163  std::vector<const RPCRoll*> rollsRaf = (ch->rolls());
164  for (std::vector<const RPCRoll*>::iterator r = rollsRaf.begin(); r != rollsRaf.end(); ++r) {
165  if ((*r)->id() == SimDetId) {
166  SimRoll = &(*(*r));
167  break;
168  }
169  }
170  }
171  }
172 
173  if (SimRoll != nullptr) {
174  float distanceFromEdge = 0;
175  float half_stripL = 0.;
176 
177  if (SimRoll->id().region() == 0) {
178  const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(SimRoll->topology()));
179  half_stripL = top_->stripLength() / 2;
180  distanceFromEdge = half_stripL + simHitPos.y();
181  } else {
182  const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(SimRoll->topology()));
183  half_stripL = top_->stripLength() / 2;
184  distanceFromEdge = half_stripL - simHitPos.y();
185  }
186 
187  float prop_time = distanceFromEdge / sspeed;
188 
189  // double rr_tim1 = CLHEP::RandGaussQ::shoot(engine, 0.,resRPC);
190  double rr_tim1 = CLHEP::RandGaussQ::shoot(engine, 0., irpc_timing_res);
191 
192  double total_time = tof + prop_time + timOff + rr_tim1 + rr_el;
193 
194  // Bunch crossing assignment
195  double time_differ = 0.;
196 
197  if (cosmics) {
198  time_differ = (total_time - (timeref + ((half_stripL / sspeed) + timOff))) / cosmicPar;
199  } else if (!cosmics) {
200  time_differ = total_time - (timeref + (half_stripL / sspeed) + timOff);
201  }
202 
203  double exact_total_time = tof + prop_time + timOff;
204  double exact_time_differ = 0.;
205 
206  if (cosmics) {
207  exact_time_differ = (exact_total_time - (timeref + ((half_stripL / sspeed) + timOff))) / cosmicPar;
208  } else if (!cosmics) {
209  exact_time_differ = exact_total_time - (timeref + (half_stripL / sspeed) + timOff);
210  }
211 
212  double inf_time = 0;
213  double sup_time = 0;
214 
215  for (int n = -N_BX; n <= N_BX; ++n) {
216  if (cosmics) {
217  inf_time = (-lbGate / 2 + n * LHCGate) / cosmicPar;
218  sup_time = (lbGate / 2 + n * LHCGate) / cosmicPar;
219  } else if (!cosmics) {
220  inf_time = -lbGate / 2 + n * LHCGate;
221  sup_time = lbGate / 2 + n * LHCGate;
222  }
223 
224  if (inf_time < time_differ && time_differ < sup_time) {
225  bx = n;
226  the_exact_time = exact_time_differ;
227  the_smeared_time = time_differ;
228 
229  //cout<<"Debug\t"<<inf_time<<'\t'<<sup_time<<endl;
231  // cout<<"Bingo\t"<<time_differ<<'\t'<<bx<<'\t'<<exact_time_differ<<'\t'<<exact_time_differ-time_differ<<'\t'<<exact_time_differ-bx*25.<<endl;
232  break;
233  }
234  }
235  }
236  return bx;
237 }
RPCSimSetUp::getTime
float getTime(uint32_t id)
Definition: RPCSimSetUp.cc:403
RPCRoll
Definition: RPCRoll.h:12
PSimHit::timeOfFlight
float timeOfFlight() const
Definition: PSimHit.h:73
TrapezoidalStripTopology::stripLength
float stripLength() const override
det heigth (strip length in the middle)
Definition: TrapezoidalStripTopology.h:63
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
ESHandle.h
RPCDetId
Definition: RPCDetId.h:16
geometry
Definition: geometry.py:1
PSimHitContainer.h
RPCSynchronizer::getSimHitBx
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
Definition: RPCSynchronizer.cc:58
RPCRoll.h
EDAnalyzer.h
RPCSynchronizer::~RPCSynchronizer
~RPCSynchronizer()
Definition: RPCSynchronizer.cc:56
RPCSimSetUp::getGeometry
const RPCGeometry * getGeometry()
Definition: RPCSimSetUp.h:49
RPCSynchronizer::RPCSynchronizer
RPCSynchronizer(const edm::ParameterSet &config)
Definition: RPCSynchronizer.cc:34
RectangularStripTopology.h
PSimHit::detUnitId
unsigned int detUnitId() const
Definition: PSimHit.h:97
simKBmtfDigis_cfi.bx
bx
Definition: simKBmtfDigis_cfi.py:55
config
Definition: config.py:1
PSimHit.h
RectangularStripTopology
Definition: RectangularStripTopology.h:11
TrapezoidalStripTopology
Definition: TrapezoidalStripTopology.h:21
PSimHit::localPosition
Local3DPoint localPosition() const
Definition: PSimHit.h:52
Point3DBase< float, LocalTag >
RPCDetId.h
RectangularStripTopology::stripLength
float stripLength() const override
Definition: RectangularStripTopology.h:44
RPCRollSpecs.h
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
alignCSCRings.r
r
Definition: alignCSCRings.py:93
std
Definition: JetResolutionObject.h:76
TrapezoidalStripTopology.h
Frameworkfwd.h
EventSetup.h
RPCSimSetUp.h
RPCGeometry
Definition: RPCGeometry.h:20
RPCSynchronizer::getSimHitBxAndTimingForIRPC
int getSimHitBxAndTimingForIRPC(const PSimHit *, CLHEP::HepRandomEngine *)
Definition: RPCSynchronizer.cc:140
RPCSimSetUp
Definition: RPCSimSetUp.h:28
ParameterSet.h
PSimHit
Definition: PSimHit.h:15
MuonGeometryRecord.h
GlobalTrackerMuonAlignment_cfi.cosmics
cosmics
Definition: GlobalTrackerMuonAlignment_cfi.py:5
RPCGeometry.h
RPCSynchronizer.h
lumi::N_BX
const unsigned int N_BX
Definition: ConstantDef.h:5
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37