CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GEMSynchronizer.cc
Go to the documentation of this file.
3 
8 
9 #include "CLHEP/Random/RandGaussQ.h"
10 
11 
12 namespace
13 {
14  // "magic" parameter for cosmics
15  const double COSMIC_PAR = 37.62;
16 }
17 
18 
20  gauss1_(0), gauss2_(0)
21 {
22  timeResolution_ = config.getParameter<double>("timeResolution");
23  averageShapingTime_ = config.getParameter<double>("averageShapingTime");
24  timeJitter_ = config.getParameter<double>("timeJitter");
25  signalPropagationSpeed_ = config.getParameter<double>("signalPropagationSpeed");
26  cosmics_ = config.getParameter<bool>("cosmics");
27  bxwidth_ = config.getParameter<double>("bxwidth");
28 
29  // signal propagation speed in vacuum in [m/s]
30  const double cspeed = 299792458;
31  // signal propagation speed in material in [cm/ns]
32  signalPropagationSpeed_ = signalPropagationSpeed_ * cspeed * 1e+2 * 1e-9;
33 }
34 
35 
36 void GEMSynchronizer::setRandomEngine(CLHEP::HepRandomEngine& eng)
37 {
38  gauss1_ = new CLHEP::RandGaussQ(eng);
39  gauss2_ = new CLHEP::RandGaussQ(eng);
40 }
41 
42 
44 {
45  if (gauss1_) delete gauss1_;
46  if (gauss2_) delete gauss2_;
47 }
48 
49 
51 {
52  GEMSimSetUp* simsetup = getGEMSimSetUp();
53  const GEMGeometry * geometry = simsetup->getGeometry();
54  // calibration offset for a particular detector part
55  float calibrationTime = simsetup->getTime(simhit->detUnitId());
56 
57  int bx = -999;
58  LocalPoint simHitPos = simhit->localPosition();
59  float tof = simhit->timeOfFlight();
60  // random Gaussian time correction due to electronics jitter
61  float randomJitterTime = gauss1_->fire(0., timeJitter_);
62 
63  GEMDetId shdetid(simhit->detUnitId());
64 
65  const GEMEtaPartition* shRoll = 0;
66 
67  for(const auto &det: geometry->dets())
68  {
69  if( dynamic_cast< GEMEtaPartition* >( det ) != 0 )
70  {
71  GEMEtaPartition* roll = dynamic_cast< GEMEtaPartition* >( det );
72 
73  if(roll->id() == shdetid)
74  {
75  shRoll = roll;
76  break;
77  }
78  }
79  }
80 
81  if(shRoll != 0)
82  {
83  float distanceFromEdge = 0;
84  float halfStripLength = 0.;
85 
86  if(shRoll->id().region() == 0)
87  {
88  throw cms::Exception("Geometry")
89  << "GEMSynchronizer::getSimHitBx() - this GEM id is from barrel, which cannot happen: "<<shRoll->id()<< "\n";
90  }
91  else
92  {
93  const TrapezoidalStripTopology* top = dynamic_cast<const TrapezoidalStripTopology*> (&(shRoll->topology()));
94  halfStripLength = 0.5 * top->stripLength();
95  distanceFromEdge = halfStripLength - simHitPos.y();
96  }
97 
98  // average time for the signal to propagate from the SimHit to the top of a strip
99  float averagePropagationTime = distanceFromEdge/signalPropagationSpeed_;
100  // random Gaussian time correction due to the finite timing resolution of the detector
101  float randomResolutionTime = gauss2_->fire(0., timeResolution_);
102 
103  float simhitTime = tof + (averageShapingTime_ + randomResolutionTime) + (averagePropagationTime + randomJitterTime);
104  float referenceTime = calibrationTime + halfStripLength/signalPropagationSpeed_ + averageShapingTime_;
105  float timeDifference = cosmics_ ? (simhitTime - referenceTime)/COSMIC_PAR : simhitTime - referenceTime;
106 
107  // assign the bunch crossing
108  bx = static_cast<int>( std::round((timeDifference)/bxwidth_) );
109 
110  // check time
111  const bool debug( false );
112  if (debug)
113  {
114  std::cout<<"checktime "<<bx<<" "<<timeDifference<<" "<<simhitTime<<" "<<referenceTime<<" "<<tof<<" "<<averagePropagationTime<<std::endl;
115  }
116  }
117  return bx;
118 }
119 
T getParameter(std::string const &) const
void setRandomEngine(CLHEP::HepRandomEngine &eng)
CLHEP::RandGaussQ * gauss1_
T y() const
Definition: PV3DBase.h:63
GEMDetId id() const
GEMSimSetUp * getGEMSimSetUp()
double signalPropagationSpeed_
float timeOfFlight() const
Definition: PSimHit.h:69
virtual const DetContainer & dets() const
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: GEMGeometry.cc:25
Local3DPoint localPosition() const
Definition: PSimHit.h:44
double averageShapingTime_
GEMSynchronizer(const edm::ParameterSet &config)
#define debug
Definition: HDRShower.cc:19
const GEMGeometry * getGeometry()
Definition: GEMSimSetUp.h:43
ESHandle< TrackerGeometry > geometry
CLHEP::RandGaussQ * gauss2_
int getSimHitBx(const PSimHit *)
tuple cout
Definition: gather_cfg.py:121
float getTime(uint32_t id)
Definition: GEMSimSetUp.cc:140
unsigned int detUnitId() const
Definition: PSimHit.h:93