CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(0),
29  field(0),
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(false),
37  // Set verbose output
38  debug(config.getUntrackedParameter<bool>("debug"))
39 {
40  if(debug)
41  cout<<"[DTLinearDriftFromDBAlgo] Constructor called"<<endl;
42 
43  // Check for compatibility with older configurations
44  if (config.existsAs<bool>("useUncertDB")) {
45  // Assign hit uncertainties based on new uncertainties DB
46  useUncertDB= config.getParameter<bool>("useUncertDB");
47  }
48 }
49 
50 
51 
53 
54 
55 
57  if(debug)
58  cout<<"[DTLinearDriftFromDBAlgo] setES called"<<endl;
59  theSync->setES(setup);
60  // Get the map of ttrig from the Setup
61  ESHandle<DTMtime> mTimeHandle;
62  setup.get<DTMtimeRcd>().get(mTimeHandle);
63  mTimeMap = &*mTimeHandle;
64 
66  setup.get<IdealMagneticFieldRecord>().get(magfield);
67  field = &*magfield;
69 
70  if (useUncertDB) {
72  setup.get<DTRecoUncertaintiesRcd>().get(uncerts);
73  uncertMap = &*uncerts;
74 
75  // check uncertainty map type
76  if (uncertMap->version()>1) edm::LogError("NotImplemented") << "DT Uncertainty DB version unknown: " << uncertMap->version();
77  }
78 
79  if(debug) {
80  cout << "[DTLinearDriftFromDBAlgo] meanTimer version: " << mTimeMap->version()<<endl;
81  if (useUncertDB) cout << " uncertDB version: " << uncertMap->version()<<endl;
82  }
83 
84 }
85 
86 
87 
88 // First Step
90  const DTDigi& digi,
91  LocalPoint& leftPoint,
92  LocalPoint& rightPoint,
93  LocalError& error) const {
94  // Get the wireId
95  DTLayerId layerId = layer->id();
96  const DTWireId wireId(layerId, digi.wire());
97 
98  // Get Wire position
99  if(!layer->specificTopology().isWireValid(digi.wire())) return false;
100  LocalPoint locWirePos(layer->specificTopology().wirePosition(digi.wire()), 0, 0);
101  const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
102 
103  return compute(layer, wireId, digi.time(), globWirePos, leftPoint, rightPoint, error, 1);
104 }
105 
106 
107 
108 // Second step: the same as 1st step (optionally, redo 1st step starting from digi time)
110  const DTRecHit1D& recHit1D,
111  const float& angle,
112  DTRecHit1D& newHit1D) const {
113 
114  if (!stepTwoFromDigi) {
115  newHit1D.setPositionAndError(recHit1D.localPosition(), recHit1D.localPositionError());
116  return true;
117  }
118 
119  const DTWireId wireId = recHit1D.wireId();
120 
121  // Get Wire position
122  if(!layer->specificTopology().isWireValid(wireId.wire())) return false;
123  LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
124  const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
125 
126  return compute(layer, wireId, recHit1D.digiTime(), globWirePos, newHit1D, 2);
127 
128 }
129 
130 
131 
132 // Third step.
134  const DTRecHit1D& recHit1D,
135  const float& angle,
136  const GlobalPoint& globPos,
137  DTRecHit1D& newHit1D) const {
138  return compute(layer, recHit1D.wireId(), recHit1D.digiTime(), globPos, newHit1D, 3);
139 }
140 
141 
142 
143 // Do the actual work.
145  const DTWireId& wireId,
146  const float digiTime,
147  const GlobalPoint& globPos,
148  LocalPoint& leftPoint,
149  LocalPoint& rightPoint,
150  LocalError& error,
151  int step) const {
152  // Subtract the offset to the digi time accordingly to the DTTTrigBaseSync concrete instance
153  float driftTime = digiTime - theSync->offset(layer, wireId, globPos);
154 
155  // check for out-of-time
156  if (driftTime < minTime || driftTime > maxTime) {
157  if (debug) cout << "[DTLinearDriftFromDBAlgo]*** Drift time out of window for in-time hits "
158  << driftTime << endl;
159 
160  if(step == 1) { //FIXME: protection against failure at 2nd and 3rd steps, must be checked!!!
161  // Hits are interpreted as coming from out-of-time pile-up and recHit
162  // is ignored.
163  return false;
164  }
165  }
166 
167  // Small negative times interpreted as hits close to the wire.
168  if (driftTime<0.) driftTime=0;
169 
170  // Read the vDrift and reso for this wire
171  float vDrift = 0;
172  float hitResolution = 0;
173  // vdrift is cm/ns , resolution is cm
174  mTimeMap->get(wireId.superlayerId(),
175  vDrift,
176  hitResolution, // Value from vdrift DB; replaced below if useUncertDB card is set
178 
179  if (useUncertDB) {
180  // Read the uncertainty from the DB for the given channel and step
181  hitResolution = uncertMap->get(wireId, step-1);
182  }
183 
184  //only in step 3
185  if(doVdriftCorr && step == 3 && nominalB !=0){
186  if (abs(wireId.wheel()) == 2 &&
187  wireId.station() == 1 &&
188  wireId.superLayer() != 2) {
189  // Variation of vdrift along Y due to B field,
191  // vdrift is lower a negative Y (lower global |Z|)
192  const float k_param = 1.2e-04;
193  LocalPoint local_pos = layer->toLocal(globPos);
194  vDrift = vDrift*(1. - k_param*local_pos.y());
195  }
196  }
197 
198  // Compute the drift distance
199  float drift = driftTime * vDrift;
200 
201  // Get Wire position
202  if(!layer->specificTopology().isWireValid(wireId.wire())) return false;
203  LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
204  //Build the two possible points and the error on the position
205  leftPoint = LocalPoint(locWirePos.x()-drift,
206  locWirePos.y(),
207  locWirePos.z());
208  rightPoint = LocalPoint(locWirePos.x()+drift,
209  locWirePos.y(),
210  locWirePos.z());
211  error = LocalError(hitResolution*hitResolution,0.,0.);
212 
213 
214  if(debug) {
215  cout << "[DTLinearDriftFromDBAlgo] Compute drift distance, for digi at wire: " << wireId << endl
216  << " Step: " << step << endl
217  << " Digi time: " << digiTime << endl
218  << " Drift time: " << driftTime << endl
219  << " Drift distance: " << drift << endl
220  << " Hit Resolution: " << hitResolution << endl
221  << " Left point: " << leftPoint << endl
222  << " Right point: " << rightPoint << endl
223  << " Error: " << error << endl;
224  }
225 
226  return true;
227 
228 }
229 
230 
231 // Interface to the method which does the actual work suited for 2nd and 3rd steps
233  const DTWireId& wireId,
234  const float digiTime,
235  const GlobalPoint& globPos,
236  DTRecHit1D& newHit1D,
237  int step) const {
238  LocalPoint leftPoint;
239  LocalPoint rightPoint;
241 
242  if(compute(layer, wireId, digiTime, globPos, leftPoint, rightPoint, error, step)) {
243  // Set the position and the error of the rechit which is being updated
244  switch(newHit1D.lrSide()) {
245 
246  case DTEnums::Left:
247  {
248  // Keep the original y position of newHit1D: for step==3, it's the
249  // position along the wire. Needed for rotation alignment
250  LocalPoint leftPoint3D(leftPoint.x(), newHit1D.localPosition().y(), leftPoint.z());
251  newHit1D.setPositionAndError(leftPoint3D, error);
252  break;
253  }
254 
255  case DTEnums::Right:
256  {
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 "
265  << step << ", Hit side "
266  << newHit1D.lrSide()
267  << " is invalid!" << endl;
268  return false;
269  }
270 
271  return true;
272  }else {
273  return false;
274  }
275 }
T getParameter(std::string const &) const
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
Definition: DTTopology.cc:86
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
float get(const DTWireId &wireid, unsigned int index) const
get the uncertainties for the SL correspoding to the given WireId and for the correct step as defined...
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:56
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:52
double offset(const DTLayer *layer, const DTWireId &wireId, const GlobalPoint &globalPos)
virtual bool compute(const DTLayer *layer, const DTDigi &digi, LocalPoint &leftPoint, LocalPoint &rightPoint, LocalError &error) const
LocalVector drift(const StripGeomDetUnit *, const MagneticField &, const SiStripLorentzAngle &)
Definition: ShallowTools.cc:39
tuple magfield
Definition: HLT_ES_cff.py:2311
T y() const
Definition: PV3DBase.h:63
const DTRecoUncertainties * uncertMap
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
int wire() const
Return wire number.
Definition: DTDigi.cc:67
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:59
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
virtual ~DTLinearDriftFromDBAlgo()
Destructor.
float digiTime() const
Return the time (ns) of the digi used to build the rechit.
Definition: DTRecHit1D.h:113
virtual void setES(const edm::EventSetup &setup)
Pass the Event Setup to the algo at each event.
const MagneticField * field
Definition: DTDigi.h:17
virtual LocalError localPositionError() const
Return the 3-dimensional error on the local position.
Definition: DTRecHit1D.h:66
DTTTrigBaseSync * theSync
virtual LocalPoint localPosition() const
Return the 3-dimensional local position.
Definition: DTRecHit1D.h:60
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
const std::string & version() const
access version
Definition: DTMtime.cc:233
int get(int wheelId, int stationId, int sectorId, int slId, float &mTime, float &mTrms, DTTimeUnits::type unit) const
Definition: DTMtime.cc:82
bool isWireValid(const int wireNumber) const
Definition: DTTopology.h:65
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false
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
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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