CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTTrigSyncFromDB.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2009/10/21 17:20:27 $
5  * $Revision: 1.9 $
6  * \author G. Cerminara - INFN Torino
7  */
8 
9 #include "DTTTrigSyncFromDB.h"
10 
11 
22 
23 #include <iostream>
24 
25 using namespace std;
26 using namespace edm;
27 
28 
30  debug = config.getUntrackedParameter<bool>("debug");
31  // The velocity of signal propagation along the wire (cm/ns)
32  theVPropWire = config.getParameter<double>("vPropWire");
33  // Switch on/off the T0 correction from pulses
34  doT0Correction = config.getParameter<bool>("doT0Correction");
35  // Switch on/off the TOF correction for particles from IP
36  doTOFCorrection = config.getParameter<bool>("doTOFCorrection");
37  theTOFCorrType = config.getParameter<int>("tofCorrType");
38  // Switch on/off the correction for the signal propagation along the wire
39  doWirePropCorrection = config.getParameter<bool>("doWirePropCorrection");
40  theWirePropCorrType = config.getParameter<int>("wirePropCorrType");
41  // spacing of BX in ns
42  theBXspace = config.getUntrackedParameter<double>("bxSpace", 25.);
43 
44  thetTrigLabel = config.getParameter<string>("tTrigLabel");
45 }
46 
47 
48 
50 
51 
52 
54  if(doT0Correction)
55  {
56  // Get the map of t0 from pulses from the Setup
57  ESHandle<DTT0> t0Handle;
58  setup.get<DTT0Rcd>().get(t0Handle);
59  tZeroMap = &*t0Handle;
60  if(debug) {
61  cout << "[DTTTrigSyncFromDB] t0 version: " << tZeroMap->version()<<endl;
62  }
63  }
64 
65  // Get the map of ttrig from the Setup
66  ESHandle<DTTtrig> ttrigHandle;
67  setup.get<DTTtrigRcd>().get(thetTrigLabel,ttrigHandle);
68  tTrigMap = &*ttrigHandle;
69  if(debug) {
70  cout << "[DTTTrigSyncFromDB] ttrig version: " << tTrigMap->version() << endl;
71  }
72 }
73 
74 
75 double DTTTrigSyncFromDB::offset(const DTLayer* layer,
76  const DTWireId& wireId,
77  const GlobalPoint& globPos,
78  double& tTrig,
79  double& wirePropCorr,
80  double& tofCorr) {
81  // Correction for the float to int conversion while writeing the ttrig in ns into an int variable
82  // (half a bin on average)
83  // FIXME: this should disappear as soon as the ttrig object will become a float
84  // static const float f2i_convCorr = (25./64.); // ns //FIXME: check how the conversion is performed
85 
86  tTrig = offset(wireId);
87 
88  // Compute the time spent in signal propagation along wire.
89  // NOTE: the FE is always at y>0
90  wirePropCorr = 0;
91  if(doWirePropCorrection) {
92  switch(theWirePropCorrType){
93  // The ttrig computed from the timebox accounts on average for the signal propagation time
94  // from the center of the wire to the frontend. Here we just have to correct for
95  // the distance of the hit from the wire center.
96  case 0: {
97  float wireCoord = layer->toLocal(globPos).y();
98  wirePropCorr = -wireCoord/theVPropWire;
99  break;
100  // FIXME: What if hits used for the time box are not distributed uniformly along the wire?
101  }
102  //On simulated data you need to subtract the total propagation time
103  case 1: {
104  float halfL = layer->specificTopology().cellLenght()/2;
105  float wireCoord = layer->toLocal(globPos).y();
106  float propgL = halfL - wireCoord;
107  wirePropCorr = propgL/theVPropWire;
108  break;
109  }
110  default: {
111  throw
112  cms::Exception("[DTTTrigSyncFromDB]") << " Invalid parameter: wirePropCorrType = "
113  << theWirePropCorrType
114  << std::endl;
115  break;
116  }
117  }
118  }
119 
120  // Compute TOF correction:
121  tofCorr = 0.;
122  // TOF Correction can be switched off with appropriate parameter
123  if(doTOFCorrection) {
124  float flightToHit = globPos.mag();
125  static const float cSpeed = 29.9792458; // cm/ns
126  switch(theTOFCorrType) {
127  case 0: {
128  // The ttrig computed from the real data accounts on average for the TOF correction
129  // Depending on the granularity used for the ttrig computation we just have to correct for the
130  // TOF from the center of the chamber, SL, layer or wire to the hit position.
131  // At the moment only SL granularity is considered
132  // Correction for TOF from the center of the SL to hit position
133  const DTSuperLayer *sl = layer->superLayer();
134  double flightToSL = sl->surface().position().mag();
135  tofCorr = (flightToSL-flightToHit)/cSpeed;
136  break;
137  }
138  case 1: {
139  // On simulated data you need to consider only the TOF from 3D center of the wire to hit position
140  // (because the TOF from the IP to the wire has been already subtracted in the digitization:
141  // SimMuon/DTDigitizer/DTDigiSyncTOFCorr.cc corrType=2)
142  float flightToWire =
143  layer->toGlobal(LocalPoint(layer->specificTopology().wirePosition(wireId.wire()), 0., 0.)).mag();
144  tofCorr = (flightToWire-flightToHit)/cSpeed;
145  break;
146  }
147  default: {
148  throw
149  cms::Exception("[DTTTrigSyncFromDB]") << " Invalid parameter: tofCorrType = "
150  << theTOFCorrType
151  << std::endl;
152  break;
153  }
154  }
155  }
156 
157 
158  if(debug) {
159  cout << "[DTTTrigSyncFromDB] Channel: " << wireId << endl
160  << " Offset (ns): " << tTrig + wirePropCorr - tofCorr << endl
161  << " various contributions are: " << endl
162  << " tTrig + t0 (ns): " << tTrig << endl
163  //<< " tZero (ns): " << t0 << endl
164  << " Propagation along wire delay (ns): " << wirePropCorr << endl
165  << " TOF correction (ns): " << tofCorr << endl
166  << endl;
167  }
168  //The global offset is the sum of various contributions
169  return tTrig + wirePropCorr - tofCorr;
170 }
171 
172 double DTTTrigSyncFromDB::offset(const DTWireId& wireId) {
173  float t0 = 0;
174  float t0rms = 0;
175  if(doT0Correction)
176  {
177  // Read the t0 from pulses for this wire (ns)
178  tZeroMap->get(wireId,
179  t0,
180  t0rms,
182 
183  }
184 
185  // Read the ttrig for this wire
186  float ttrigMean = 0;
187  float ttrigSigma = 0;
188  float kFactor = 0;
189  // FIXME: should check the return value of the DTTtrigRcd::get(..) method
190  if(tTrigMap->get(wireId.superlayerId(),
191  ttrigMean,
192  ttrigSigma,
193  kFactor,
194  DTTimeUnits::ns) != 0) {
195  cout << "[DTTTrigSyncFromDB]*Error: ttrig not found for SL: " << wireId.superlayerId() << endl;
196 // FIXME: LogError.....
197  }
198 
199  return t0 + ttrigMean + kFactor * ttrigSigma;
200 
201 }
202 
203 
204 // Set the verbosity level
205 bool DTTTrigSyncFromDB::debug = false;
206 
207 
209  double &tTrig,
210  double &t0cell) {
211  float t0 = 0;
212  float t0rms = 0;
213  if(doT0Correction)
214  {
215  // Read the t0 from pulses for this wire (ns)
216  tZeroMap->get(wireId,
217  t0,
218  t0rms,
220 
221  }
222 
223  // Read the ttrig for this wire
224  float ttrigMean = 0;
225  float ttrigSigma = 0;
226  float kFactor = 0;
227  // FIXME: should check the return value of the DTTtrigRcd::get(..) method
228  if(tTrigMap->get(wireId.superlayerId(),
229  ttrigMean,
230  ttrigSigma,
231  kFactor,
232  DTTimeUnits::ns) != 0) {
233  cout << "[DTTTrigSyncFromDB]*Error: ttrig not found for SL: " << wireId.superlayerId() << endl;
234 // FIXME: LogError.....
235  }
236 
237  tTrig = ttrigMean + kFactor * ttrigSigma;
238  t0cell = t0;
239 
240  return int(tTrig/theBXspace)*theBXspace + t0cell;
241 }
virtual ~DTTTrigSyncFromDB()
Destructor.
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
Definition: DTTopology.cc:73
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
T y() const
Definition: PV3DBase.h:57
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:64
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:61
const DTTopology & specificTopology() const
Definition: DTLayer.cc:44
T mag() const
Definition: PV3DBase.h:61
unsigned int offset(bool)
virtual double offset(const DTLayer *layer, const DTWireId &wireId, const GlobalPoint &globPos, double &tTrig, double &wirePropCorr, double &tofCorr)
virtual void setES(const edm::EventSetup &setup)
Pass the Event Setup to the algo at each event.
int wire() const
Return the wire number.
Definition: DTWireId.h:58
const T & get() const
Definition: EventSetup.h:55
const DTSuperLayer * superLayer() const
Definition: DTLayer.cc:56
Definition: DTT0Rcd.h:9
virtual double emulatorOffset(const DTWireId &wireId, double &tTrig, double &t0cell)
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
DTTTrigSyncFromDB(const edm::ParameterSet &config)
Constructor.
tuple cout
Definition: gather_cfg.py:41
#define debug
Definition: MEtoEDMFormat.h:34
const PositionType & position() const
const float cellLenght() const
Definition: DTTopology.h:75
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37