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