CMS 3D CMS Logo

DTLinearDriftFromDBAlgo.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author S. Bolognesi - INFN Torino
5  */
6 
24 
25 using namespace std;
26 using namespace edm;
27 
30  mTimeMap(nullptr),
31  vDriftMap(nullptr),
32  field(nullptr),
33  fieldToken_(cc.esConsumes()),
34  nominalB(-1),
35  minTime(config.getParameter<double>("minTime")),
36  maxTime(config.getParameter<double>("maxTime")),
37  doVdriftCorr(config.getParameter<bool>("doVdriftCorr")),
38  // Option to force going back to digi time at Step 2
39  stepTwoFromDigi(config.getParameter<bool>("stepTwoFromDigi")),
40  useUncertDB(config.getParameter<bool>("useUncertDB")),
41  readLegacyTTrigDB(config.getParameter<bool>("readLegacyTTrigDB")),
42  readLegacyVDriftDB(config.getParameter<bool>("readLegacyVDriftDB")),
43  // Set verbose output
44  debug(config.getUntrackedParameter<bool>("debug")) {
45  if (readLegacyVDriftDB) {
46  mTimeMapToken_ = cc.esConsumes();
47  } else {
48  vDriftMapToken_ = cc.esConsumes();
49  }
50  if (useUncertDB) {
51  uncertMapToken_ = cc.esConsumes();
52  }
53 }
54 
56 
58  if (debug)
59  edm::LogVerbatim("DTLocalReco") << "[DTLinearDriftFromDBAlgo] setES called" << endl;
60  theSync->setES(setup);
61  // Get the map of ttrig from the Setup
62  if (readLegacyVDriftDB) {
63  mTimeMap = &setup.getData(mTimeMapToken_);
64  vDriftMap = nullptr;
65  } else {
66  vDriftMap = &setup.getData(vDriftMapToken_);
67  mTimeMap = nullptr;
68 
69  // Consistency check: no parametrization is implemented for the time being
70  int version = vDriftMap->version();
71  if (version != 1) {
72  throw cms::Exception("Configuration") << "only version 1 is presently supported for VDriftDB";
73  }
74  }
75 
76  field = &setup.getData(fieldToken_);
78 
79  if (useUncertDB) {
80  uncertMap = &setup.getData(uncertMapToken_);
81  if (uncertMap->version() > 1)
82  edm::LogError("NotImplemented") << "DT Uncertainty DB version unsupported: " << uncertMap->version();
83  }
84 
85  if (debug) {
86  if (readLegacyVDriftDB) {
87  edm::LogVerbatim("DTLocalReco") << "[DTLinearDriftFromDBAlgo] meanTimer version: " << mTimeMap->version() << endl;
88  } else {
89  edm::LogVerbatim("DTLocalReco") << "[DTLinearDriftFromDBAlgo] vDrift version: " << vDriftMap->version() << endl;
90  }
91 
92  if (useUncertDB)
93  edm::LogVerbatim("DTLocalReco") << " uncertDB version: " << uncertMap->version()
94  << endl;
95  }
96 }
97 
98 // First Step
100  const DTLayer* layer, const DTDigi& digi, LocalPoint& leftPoint, LocalPoint& rightPoint, LocalError& error) const {
101  // Get the wireId
102  DTLayerId layerId = layer->id();
103  const DTWireId wireId(layerId, digi.wire());
104 
105  // Get Wire position
106  if (!layer->specificTopology().isWireValid(digi.wire()))
107  return false;
108  LocalPoint locWirePos(layer->specificTopology().wirePosition(digi.wire()), 0, 0);
109  const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
110 
111  return compute(layer, wireId, digi.time(), globWirePos, leftPoint, rightPoint, error, 1);
112 }
113 
114 // Second step: the same as 1st step (optionally, redo 1st step starting from digi time)
116  const DTRecHit1D& recHit1D,
117  const float& angle,
118  DTRecHit1D& newHit1D) const {
119  if (!stepTwoFromDigi) {
120  newHit1D.setPositionAndError(recHit1D.localPosition(), recHit1D.localPositionError());
121  return true;
122  }
123 
124  const DTWireId wireId = recHit1D.wireId();
125 
126  // Get Wire position
127  if (!layer->specificTopology().isWireValid(wireId.wire()))
128  return false;
129  LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
130  const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
131 
132  return compute(layer, wireId, recHit1D.digiTime(), globWirePos, newHit1D, 2);
133 }
134 
135 // Third step.
137  const DTRecHit1D& recHit1D,
138  const float& angle,
139  const GlobalPoint& globPos,
140  DTRecHit1D& newHit1D) const {
141  return compute(layer, recHit1D.wireId(), recHit1D.digiTime(), globPos, newHit1D, 3);
142 }
143 
144 // Do the actual work.
146  const DTWireId& wireId,
147  const float digiTime,
148  const GlobalPoint& globPos,
149  LocalPoint& leftPoint,
150  LocalPoint& rightPoint,
151  LocalError& error,
152  int step) const {
153  // Subtract the offset to the digi time accordingly to the DTTTrigBaseSync concrete instance
154  float driftTime = digiTime - theSync->offset(layer, wireId, globPos);
155 
156  // check for out-of-time
157  if (driftTime < minTime || driftTime > maxTime) {
158  if (debug)
159  edm::LogWarning("DTLocalReco") << "[DTLinearDriftFromDBAlgo]*** Drift time out of window for in-time hits "
160  << driftTime << endl;
161 
162  if (step == 1) { //FIXME: protection against failure at 2nd and 3rd steps, must be checked!!!
163  // Hits are interpreted as coming from out-of-time pile-up and recHit
164  // is ignored.
165  return false;
166  }
167  }
168 
169  // Small negative times interpreted as hits close to the wire.
170  if (driftTime < 0.)
171  driftTime = 0;
172 
173  // Read the vDrift and reso for this wire
174  float vDrift = 0;
175  float hitResolution = 0;
176 
177  if (readLegacyVDriftDB) {
178  // vdrift is cm/ns , resolution is cm
179  mTimeMap->get(wireId.superlayerId(),
180  vDrift,
181  hitResolution, // Value from vdrift DB; replaced below if useUncertDB card is set
183  } else {
184  // For v2, we will pass also: double args[1] = {(layer->toLocal(globPos)).y()};
185  vDrift = vDriftMap->get(wireId);
186  }
187 
188  if (useUncertDB) {
189  // Read the uncertainty from the DB for the given channel and step
190  double args[1] = {double(step - 1)};
191  hitResolution = uncertMap->get(wireId, args);
192  }
193 
194  //only in step 3
195  if (doVdriftCorr && step == 3 && nominalB != 0) {
196  if (abs(wireId.wheel()) == 2 && wireId.station() == 1 && wireId.superLayer() != 2) {
197  // Variation of vdrift along Y due to B field,
199  // vdrift is lower a negative Y (lower global |Z|)
200  const float k_param = 1.2e-04;
201  LocalPoint local_pos = layer->toLocal(globPos);
202  vDrift = vDrift * (1. - k_param * local_pos.y());
203  }
204  }
205 
206  // Compute the drift distance
207  float drift = driftTime * vDrift;
208 
209  // Get Wire position
210  if (!layer->specificTopology().isWireValid(wireId.wire()))
211  return false;
212  LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
213  //Build the two possible points and the error on the position
214  leftPoint = LocalPoint(locWirePos.x() - drift, locWirePos.y(), locWirePos.z());
215  rightPoint = LocalPoint(locWirePos.x() + drift, locWirePos.y(), locWirePos.z());
217 
218  if (debug) {
219  edm::LogWarning("DTLocalReco") << "[DTLinearDriftFromDBAlgo] Compute drift distance, for digi at wire: " << wireId
220  << endl
221  << " Step: " << step << endl
222  << " Digi time: " << digiTime << endl
223  << " Drift time: " << driftTime << endl
224  << " Drift distance: " << drift << endl
225  << " Hit Resolution: " << hitResolution << endl
226  << " Left point: " << leftPoint << endl
227  << " Right point: " << rightPoint << endl
228  << " Error: " << error << endl;
229  }
230 
231  return true;
232 }
233 
234 // Interface to the method which does the actual work suited for 2nd and 3rd steps
236  const DTWireId& wireId,
237  const float digiTime,
238  const GlobalPoint& globPos,
239  DTRecHit1D& newHit1D,
240  int step) const {
241  LocalPoint leftPoint;
242  LocalPoint rightPoint;
244 
245  if (compute(layer, wireId, digiTime, globPos, leftPoint, rightPoint, error, step)) {
246  // Set the position and the error of the rechit which is being updated
247  switch (newHit1D.lrSide()) {
248  case DTEnums::Left: {
249  // Keep the original y position of newHit1D: for step==3, it's the
250  // position along the wire. Needed for rotation alignment
251  LocalPoint leftPoint3D(leftPoint.x(), newHit1D.localPosition().y(), leftPoint.z());
252  newHit1D.setPositionAndError(leftPoint3D, error);
253  break;
254  }
255 
256  case DTEnums::Right: {
257  // as above: 3d position
258  LocalPoint rightPoint3D(rightPoint.x(), newHit1D.localPosition().y(), rightPoint.z());
259  newHit1D.setPositionAndError(rightPoint3D, error);
260  break;
261  }
262 
263  default:
264  throw cms::Exception("InvalidDTCellSide") << "[DTLinearDriftFromDBAlgo] Compute at Step " << step
265  << ", Hit side " << newHit1D.lrSide() << " is invalid!" << endl;
266  return false;
267  }
268 
269  return true;
270  } else {
271  return false;
272  }
273 }
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:45
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
DTLinearDriftFromDBAlgo(const edm::ParameterSet &config, edm::ConsumesCollector cc)
Constructor.
float get(const DTWireId &wireid, double *x=nullptr) const
Get the value correspoding to the given WireId, / using x[] as parameters of the parametrization when...
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
int superLayer() const
Return the superlayer number.
edm::ESGetToken< DTRecoConditions, DTRecoConditionsUncertRcd > uncertMapToken_
int wire() const
Return the wire number.
Definition: DTWireId.h:45
T z() const
Definition: PV3DBase.h:61
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
LocalVector drift(const StripGeomDetUnit *, const MagneticField &, const SiStripLorentzAngle &)
Definition: ShallowTools.cc:36
int version() const
Version numer specifying the structure of the payload. See .cc file for details.
edm::ESGetToken< DTRecoConditions, DTRecoConditionsVdriftRcd > vDriftMapToken_
const DTRecoConditions * vDriftMap
Definition: config.py:1
int get(int wheelId, int stationId, int sectorId, int slId, float &mTime, float &mTrms, DTTimeUnits::type unit) const
Definition: DTMtime.cc:56
int wire() const
Return wire number.
Definition: DTDigi.cc:41
float digiTime() const
Return the time (ns) of the digi used to build the rechit.
Definition: DTRecHit1D.h:79
double time() const
Get time in ns.
Definition: DTDigi.cc:37
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
edm::ESGetToken< DTMtime, DTMtimeRcd > mTimeMapToken_
const std::string & version() const
access version
Definition: DTMtime.cc:158
DTEnums::DTCellSide lrSide() const
The side of the cell.
Definition: DTRecHit1D.h:61
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const DTRecoConditions * uncertMap
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > fieldToken_
const MagneticField * field
Definition: DTDigi.h:17
#define debug
Definition: HDRShower.cc:19
std::unique_ptr< DTTTrigBaseSync > theSync
~DTLinearDriftFromDBAlgo() override
Destructor.
void setES(const edm::EventSetup &setup) override
Pass the Event Setup to the algo at each event.
LocalError localPositionError() const override
Return the 3-dimensional error on the local position.
Definition: DTRecHit1D.h:50
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
HLT enums.
DTWireId wireId() const
Return the wireId.
Definition: DTRecHit1D.h:76
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:49
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:48
step
Definition: StallMonitor.cc:83
void setPositionAndError(LocalPoint pos, LocalError err)
Set the local position and its error.
Definition: DTRecHit1D.h:70
Log< level::Warning, false > LogWarning
LocalPoint localPosition() const override
Return the 3-dimensional local position.
Definition: DTRecHit1D.h:47
bool compute(const DTLayer *layer, const DTDigi &digi, LocalPoint &leftPoint, LocalPoint &rightPoint, LocalError &error) const override
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11