CMS 3D CMS Logo

DTTTrigSyncFromDB.cc
Go to the documentation of this file.
1 
50 
51 #include <iostream>
52 
53 namespace edm {
54  class ParameterSet;
55 }
56 
58 public:
61 
63  ~DTTTrigSyncFromDB() override;
64 
65  // Operations
66 
68  void setES(const edm::EventSetup& setup) override;
69 
74  double offset(const DTLayer* layer,
75  const DTWireId& wireId,
76  const GlobalPoint& globPos,
77  double& tTrig,
78  double& wirePropCorr,
79  double& tofCorr) const override;
80 
83  double offset(const DTWireId& wireId) const override;
84 
90  double emulatorOffset(const DTWireId& wireId, double& tTrig, double& t0cell) const override;
91 
92 private:
95  const DTT0* tZeroMap;
96  const DTTtrig* tTrigMap;
97  // Set the verbosity level
98  const bool debug;
99  // The velocity of signal propagation along the wire (cm/ns)
100  double theVPropWire;
101  // Switch on/off the T0 correction from pulses
103  // Switch on/off the TOF correction for particles from IP
106  // Switch on/off the correction for the signal propagation along the wire
109  // spacing of BX in ns
110  double theBXspace;
111 };
112 
113 using namespace std;
114 using namespace edm;
115 
117  : ttrigToken_(cc.esConsumes(edm::ESInputTag("", config.getParameter<string>("tTrigLabel")))),
118  debug(config.getUntrackedParameter<bool>("debug")),
119  // The velocity of signal propagation along the wire (cm/ns)
120  theVPropWire(config.getParameter<double>("vPropWire")),
121  // Switch on/off the T0 correction from pulses
122  doT0Correction(config.getParameter<bool>("doT0Correction")),
123  // Switch on/off the TOF correction for particles from IP
124  doTOFCorrection(config.getParameter<bool>("doTOFCorrection")),
125  theTOFCorrType(config.getParameter<int>("tofCorrType")),
126  // Switch on/off the correction for the signal propagation along the wire
127  doWirePropCorrection(config.getParameter<bool>("doWirePropCorrection")),
128  theWirePropCorrType(config.getParameter<int>("wirePropCorrType")),
129  // spacing of BX in ns
130  theBXspace(config.getUntrackedParameter<double>("bxSpace", 25.)) {
131  if (doT0Correction) {
132  t0Token_ = cc.esConsumes(edm::ESInputTag("", config.getParameter<string>("t0Label")));
133  }
134 }
135 
137 
139  if (doT0Correction) {
140  // Get the map of t0 from pulses from the Setup
141  tZeroMap = &setup.getData(t0Token_);
142  if (debug) {
143  cout << "[DTTTrigSyncFromDB] t0 version: " << tZeroMap->version() << endl;
144  }
145  }
146 
147  // Get the map of ttrig from the Setup
148  tTrigMap = &setup.getData(ttrigToken_);
149  if (debug) {
150  cout << "[DTTTrigSyncFromDB] ttrig version: " << tTrigMap->version() << endl;
151  }
152 }
153 
155  const DTWireId& wireId,
156  const GlobalPoint& globPos,
157  double& tTrig,
158  double& wirePropCorr,
159  double& tofCorr) const {
160  // Correction for the float to int conversion while writeing the ttrig in ns into an int variable
161  // (half a bin on average)
162  // FIXME: this should disappear as soon as the ttrig object will become a float
163  // static const float f2i_convCorr = (25./64.); // ns //FIXME: check how the conversion is performed
164 
165  tTrig = offset(wireId);
166 
167  // Compute the time spent in signal propagation along wire.
168  // NOTE: the FE is always at y>0
169  wirePropCorr = 0;
170  if (doWirePropCorrection) {
171  switch (theWirePropCorrType) {
172  // The ttrig computed from the timebox accounts on average for the signal propagation time
173  // from the center of the wire to the frontend. Here we just have to correct for
174  // the distance of the hit from the wire center.
175  case 0: {
176  float wireCoord = layer->toLocal(globPos).y();
177  wirePropCorr = -wireCoord / theVPropWire;
178  break;
179  // FIXME: What if hits used for the time box are not distributed uniformly along the wire?
180  }
181  //On simulated data you need to subtract the total propagation time
182  case 1: {
183  float halfL = layer->specificTopology().cellLenght() / 2;
184  float wireCoord = layer->toLocal(globPos).y();
185  float propgL = halfL - wireCoord;
186  wirePropCorr = propgL / theVPropWire;
187  break;
188  }
189  default: {
190  throw cms::Exception("[DTTTrigSyncFromDB]")
191  << " Invalid parameter: wirePropCorrType = " << theWirePropCorrType << std::endl;
192  break;
193  }
194  }
195  }
196 
197  // Compute TOF correction:
198  tofCorr = 0.;
199  // TOF Correction can be switched off with appropriate parameter
200  if (doTOFCorrection) {
201  float flightToHit = globPos.mag();
202  static const float cSpeed = 29.9792458; // cm/ns
203  switch (theTOFCorrType) {
204  case 0: {
205  // The ttrig computed from the real data accounts on average for the TOF correction
206  // Depending on the granularity used for the ttrig computation we just have to correct for the
207  // TOF from the center of the chamber, SL, layer or wire to the hit position.
208  // At the moment only SL granularity is considered
209  // Correction for TOF from the center of the SL to hit position
210  const DTSuperLayer* sl = layer->superLayer();
211  double flightToSL = sl->surface().position().mag();
212  tofCorr = (flightToSL - flightToHit) / cSpeed;
213  break;
214  }
215  case 1: {
216  // On simulated data you need to consider only the TOF from 3D center of the wire to hit position
217  // (because the TOF from the IP to the wire has been already subtracted in the digitization:
218  // SimMuon/DTDigitizer/DTDigiSyncTOFCorr.cc corrType=2)
219  float flightToWire =
220  layer->toGlobal(LocalPoint(layer->specificTopology().wirePosition(wireId.wire()), 0., 0.)).mag();
221  tofCorr = (flightToWire - flightToHit) / cSpeed;
222  break;
223  }
224  default: {
225  throw cms::Exception("[DTTTrigSyncFromDB]")
226  << " Invalid parameter: tofCorrType = " << theTOFCorrType << std::endl;
227  break;
228  }
229  }
230  }
231 
232  if (debug) {
233  cout << "[DTTTrigSyncFromDB] Channel: " << wireId << endl
234  << " Offset (ns): " << tTrig + wirePropCorr - tofCorr << endl
235  << " various contributions are: " << endl
236  << " tTrig + t0 (ns): " << tTrig
237  << endl
238  //<< " tZero (ns): " << t0 << endl
239  << " Propagation along wire delay (ns): " << wirePropCorr << endl
240  << " TOF correction (ns): " << tofCorr << endl
241  << endl;
242  }
243  //The global offset is the sum of various contributions
244  return tTrig + wirePropCorr - tofCorr;
245 }
246 
247 double DTTTrigSyncFromDB::offset(const DTWireId& wireId) const {
248  float t0 = 0;
249  float t0rms = 0;
250  if (doT0Correction) {
251  // Read the t0 from pulses for this wire (ns)
252  tZeroMap->get(wireId, t0, t0rms, DTTimeUnits::ns);
253  }
254 
255  // Read the ttrig for this wire
256  float ttrigMean = 0;
257  float ttrigSigma = 0;
258  float kFactor = 0;
259  // FIXME: should check the return value of the DTTtrigRcd::get(..) method
260  if (tTrigMap->get(wireId.superlayerId(), ttrigMean, ttrigSigma, kFactor, DTTimeUnits::ns) != 0) {
261  cout << "[DTTTrigSyncFromDB]*Error: ttrig not found for SL: " << wireId.superlayerId() << endl;
262  // FIXME: LogError.....
263  }
264 
265  return t0 + ttrigMean + kFactor * ttrigSigma;
266 }
267 
268 double DTTTrigSyncFromDB::emulatorOffset(const DTWireId& wireId, double& tTrig, double& t0cell) const {
269  float t0 = 0;
270  float t0rms = 0;
271  if (doT0Correction) {
272  // Read the t0 from pulses for this wire (ns)
273  tZeroMap->get(wireId, t0, t0rms, DTTimeUnits::ns);
274  }
275 
276  // Read the ttrig for this wire
277  float ttrigMean = 0;
278  float ttrigSigma = 0;
279  float kFactor = 0;
280  // FIXME: should check the return value of the DTTtrigRcd::get(..) method
281  if (tTrigMap->get(wireId.superlayerId(), ttrigMean, ttrigSigma, kFactor, DTTimeUnits::ns) != 0) {
282  cout << "[DTTTrigSyncFromDB]*Error: ttrig not found for SL: " << wireId.superlayerId() << endl;
283  // FIXME: LogError.....
284  }
285 
286  tTrig = ttrigMean + kFactor * ttrigSigma;
287  t0cell = t0;
288 
289  return int(tTrig / theBXspace) * theBXspace + t0cell;
290 }
291 
294 
const DTTtrig * tTrigMap
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
double offset(const DTLayer *layer, const DTWireId &wireId, const GlobalPoint &globPos, double &tTrig, double &wirePropCorr, double &tofCorr) const override
int wire() const
Return the wire number.
Definition: DTWireId.h:42
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
const std::string & version() const
access version
Definition: DTTtrig.cc:162
Definition: config.py:1
void setES(const edm::EventSetup &setup) override
Pass the Event Setup to the algo at each event.
~DTTTrigSyncFromDB() override
Destructor.
Definition: DTT0.h:48
edm::ESGetToken< DTT0, DTT0Rcd > t0Token_
T mag() const
Definition: PV3DBase.h:64
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
#define debug
Definition: HDRShower.cc:19
DTTTrigSyncFromDB(const edm::ParameterSet &config, edm::ConsumesCollector)
Constructor.
const PositionType & position() const
const std::string & version() const
access version
Definition: DTT0.cc:82
int get(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float &t0mean, float &t0rms, DTTimeUnits::type unit) const
Definition: DTT0.cc:48
int get(int wheelId, int stationId, int sectorId, int slId, float &tTrig, float &tTrms, float &kFact, DTTimeUnits::type unit) const
get content
Definition: DTTtrig.cc:59
HLT enums.
#define DEFINE_EDM_PLUGIN(factory, type, name)
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
double emulatorOffset(const DTWireId &wireId, double &tTrig, double &t0cell) const override
const edm::ESGetToken< DTTtrig, DTTtrigRcd > ttrigToken_