test
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 
20 
21 using namespace std;
22 using namespace edm;
23 
25  DTRecHitBaseAlgo(config),
26  minTime(config.getParameter<double>("minTime")),
27  maxTime(config.getParameter<double>("maxTime")),
28  doVdriftCorr(config.getParameter<bool>("doVdriftCorr")),
29  // Option to force going back to digi time at Step 2
30  stepTwoFromDigi(config.getParameter<bool>("stepTwoFromDigi")),
31  useUncertDB(false),
32  // Set verbose output
33  debug(config.getUntrackedParameter<bool>("debug"))
34 {
35  if(debug)
36  cout<<"[DTLinearDriftFromDBAlgo] Constructor called"<<endl;
37 
38  // Check for compatibility with older configurations
39  if (config.existsAs<bool>("useUncertDB")) {
40  // Assign hit uncertainties based on new uncertainties DB
41  useUncertDB= config.getParameter<bool>("useUncertDB");
42  }
43 }
44 
45 
46 
48 
49 
50 
52  if(debug)
53  cout<<"[DTLinearDriftFromDBAlgo] setES called"<<endl;
54  theSync->setES(setup);
55  // Get the map of ttrig from the Setup
56  ESHandle<DTMtime> mTimeHandle;
57  setup.get<DTMtimeRcd>().get(mTimeHandle);
58  mTimeMap = &*mTimeHandle;
59 
60  if (useUncertDB) {
62  setup.get<DTRecoUncertaintiesRcd>().get(uncerts);
63  uncertMap = &*uncerts;
64 
65  // check uncertainty map type
66  if (uncertMap->version()>1) edm::LogError("NotImplemented") << "DT Uncertainty DB version unknown: " << uncertMap->version();
67  }
68 
69  if(debug) {
70  cout << "[DTLinearDriftFromDBAlgo] meanTimer version: " << mTimeMap->version()<<endl;
71  if (useUncertDB) cout << " uncertDB version: " << uncertMap->version()<<endl;
72  }
73 
74 }
75 
76 
77 
78 // First Step
80  const DTDigi& digi,
81  LocalPoint& leftPoint,
82  LocalPoint& rightPoint,
83  LocalError& error) const {
84  // Get the wireId
85  DTLayerId layerId = layer->id();
86  const DTWireId wireId(layerId, digi.wire());
87 
88  // Get Wire position
89  if(!layer->specificTopology().isWireValid(digi.wire())) return false;
90  LocalPoint locWirePos(layer->specificTopology().wirePosition(digi.wire()), 0, 0);
91  const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
92 
93  return compute(layer, wireId, digi.time(), globWirePos, leftPoint, rightPoint, error, 1);
94 }
95 
96 
97 
98 // Second step: the same as 1st step (optionally, redo 1st step starting from digi time)
100  const DTRecHit1D& recHit1D,
101  const float& angle,
102  DTRecHit1D& newHit1D) const {
103 
104  if (!stepTwoFromDigi) {
105  newHit1D.setPositionAndError(recHit1D.localPosition(), recHit1D.localPositionError());
106  return true;
107  }
108 
109  const DTWireId wireId = recHit1D.wireId();
110 
111  // Get Wire position
112  if(!layer->specificTopology().isWireValid(wireId.wire())) return false;
113  LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
114  const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
115 
116  return compute(layer, wireId, recHit1D.digiTime(), globWirePos, newHit1D, 2);
117 
118 }
119 
120 
121 
122 // Third step.
124  const DTRecHit1D& recHit1D,
125  const float& angle,
126  const GlobalPoint& globPos,
127  DTRecHit1D& newHit1D) const {
128  return compute(layer, recHit1D.wireId(), recHit1D.digiTime(), globPos, newHit1D, 3);
129 }
130 
131 
132 
133 // Do the actual work.
135  const DTWireId& wireId,
136  const float digiTime,
137  const GlobalPoint& globPos,
138  LocalPoint& leftPoint,
139  LocalPoint& rightPoint,
140  LocalError& error,
141  int step) const {
142  // Subtract the offset to the digi time accordingly to the DTTTrigBaseSync concrete instance
143  float driftTime = digiTime - theSync->offset(layer, wireId, globPos);
144 
145  // check for out-of-time
146  if (driftTime < minTime || driftTime > maxTime) {
147  if (debug) cout << "[DTLinearDriftFromDBAlgo]*** Drift time out of window for in-time hits "
148  << driftTime << endl;
149 
150  if(step == 1) { //FIXME: protection against failure at 2nd and 3rd steps, must be checked!!!
151  // Hits are interpreted as coming from out-of-time pile-up and recHit
152  // is ignored.
153  return false;
154  }
155  }
156 
157  // Small negative times interpreted as hits close to the wire.
158  if (driftTime<0.) driftTime=0;
159 
160  // Read the vDrift and reso for this wire
161  float vDrift = 0;
162  float hitResolution = 0;
163  // vdrift is cm/ns , resolution is cm
164  mTimeMap->get(wireId.superlayerId(),
165  vDrift,
166  hitResolution, // Value from vdrift DB; replaced below if useUncertDB card is set
168 
169  if (useUncertDB) {
170  // Read the uncertainty from the DB for the given channel and step
171  hitResolution = uncertMap->get(wireId, step-1);
172  }
173 
174  //only in step 3
175  if(doVdriftCorr && step == 3){
176  if (abs(wireId.wheel()) == 2 &&
177  wireId.station() == 1 &&
178  wireId.superLayer() != 2) {
179  // Variation of vdrift along Y due to B field,
181  // vdrift is lower a negative Y (lower global |Z|)
182  const float k_param = 1.2e-04;
183  LocalPoint local_pos = layer->toLocal(globPos);
184  vDrift = vDrift*(1. - k_param*local_pos.y());
185  }
186  }
187 
188  // Compute the drift distance
189  float drift = driftTime * vDrift;
190 
191  // Get Wire position
192  if(!layer->specificTopology().isWireValid(wireId.wire())) return false;
193  LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
194  //Build the two possible points and the error on the position
195  leftPoint = LocalPoint(locWirePos.x()-drift,
196  locWirePos.y(),
197  locWirePos.z());
198  rightPoint = LocalPoint(locWirePos.x()+drift,
199  locWirePos.y(),
200  locWirePos.z());
201  error = LocalError(hitResolution*hitResolution,0.,0.);
202 
203 
204  if(debug) {
205  cout << "[DTLinearDriftFromDBAlgo] Compute drift distance, for digi at wire: " << wireId << endl
206  << " Step: " << step << endl
207  << " Digi time: " << digiTime << endl
208  << " Drift time: " << driftTime << endl
209  << " Drift distance: " << drift << endl
210  << " Hit Resolution: " << hitResolution << endl
211  << " Left point: " << leftPoint << endl
212  << " Right point: " << rightPoint << endl
213  << " Error: " << error << endl;
214  }
215 
216  return true;
217 
218 }
219 
220 
221 // Interface to the method which does the actual work suited for 2nd and 3rd steps
223  const DTWireId& wireId,
224  const float digiTime,
225  const GlobalPoint& globPos,
226  DTRecHit1D& newHit1D,
227  int step) const {
228  LocalPoint leftPoint;
229  LocalPoint rightPoint;
231 
232  if(compute(layer, wireId, digiTime, globPos, leftPoint, rightPoint, error, step)) {
233  // Set the position and the error of the rechit which is being updated
234  switch(newHit1D.lrSide()) {
235 
236  case DTEnums::Left:
237  {
238  // Keep the original y position of newHit1D: for step==3, it's the
239  // position along the wire. Needed for rotation alignment
240  LocalPoint leftPoint3D(leftPoint.x(), newHit1D.localPosition().y(), leftPoint.z());
241  newHit1D.setPositionAndError(leftPoint3D, error);
242  break;
243  }
244 
245  case DTEnums::Right:
246  {
247  // as above: 3d position
248  LocalPoint rightPoint3D(rightPoint.x(), newHit1D.localPosition().y(), rightPoint.z());
249  newHit1D.setPositionAndError(rightPoint3D, error);
250  break;
251  }
252 
253  default:
254  throw cms::Exception("InvalidDTCellSide") << "[DTLinearDriftFromDBAlgo] Compute at Step "
255  << step << ", Hit side "
256  << newHit1D.lrSide()
257  << " is invalid!" << endl;
258  return false;
259  }
260 
261  return true;
262  }else {
263  return false;
264  }
265 }
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:184
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...
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:47
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
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:62
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.
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