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