00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "RecoLocalMuon/DTRecHit/plugins/DTLinearDriftFromDBAlgo.h"
00010 #include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h"
00011 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00012 #include "Geometry/DTGeometry/interface/DTLayer.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/Utilities/interface/Exception.h"
00017 #include "CondFormats/DTObjects/interface/DTMtime.h"
00018 #include "CondFormats/DataRecord/interface/DTMtimeRcd.h"
00019
00020 using namespace std;
00021 using namespace edm;
00022
00023 DTLinearDriftFromDBAlgo::DTLinearDriftFromDBAlgo(const ParameterSet& config) :
00024 DTRecHitBaseAlgo(config) {
00025
00026 minTime = config.getParameter<double>("minTime");
00027
00028 maxTime = config.getParameter<double>("maxTime");
00029
00030
00031 debug = config.getUntrackedParameter<bool>("debug");
00032 if(debug)
00033 cout<<"[DTLinearDriftFromDBAlgo] Constructor called"<<endl;
00034 }
00035
00036
00037
00038 DTLinearDriftFromDBAlgo::~DTLinearDriftFromDBAlgo(){}
00039
00040
00041
00042 void DTLinearDriftFromDBAlgo::setES(const EventSetup& setup) {
00043 if(debug)
00044 cout<<"[DTLinearDriftFromDBAlgo] setES called"<<endl;
00045 theSync->setES(setup);
00046
00047 ESHandle<DTMtime> mTimeHandle;
00048 setup.get<DTMtimeRcd>().get(mTimeHandle);
00049 mTimeMap = &*mTimeHandle;
00050
00051 if(debug)
00052 cout << "[DTLinearDriftFromDBAlgo] meanTimer version: " << mTimeMap->version()<<endl;
00053 }
00054
00055
00056
00057
00058 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00059 const DTDigi& digi,
00060 LocalPoint& leftPoint,
00061 LocalPoint& rightPoint,
00062 LocalError& error) const {
00063
00064 DTLayerId layerId = layer->id();
00065 const DTWireId wireId(layerId, digi.wire());
00066
00067
00068 if(!layer->specificTopology().isWireValid(digi.wire())) return false;
00069 LocalPoint locWirePos(layer->specificTopology().wirePosition(digi.wire()), 0, 0);
00070 const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
00071
00072 return compute(layer, wireId, digi.time(), globWirePos, leftPoint, rightPoint, error, 1);
00073 }
00074
00075
00076
00077
00078 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00079 const DTRecHit1D& recHit1D,
00080 const float& angle,
00081 DTRecHit1D& newHit1D) const {
00082 newHit1D.setPositionAndError(recHit1D.localPosition(), recHit1D.localPositionError());
00083 return true;
00084 }
00085
00086
00087
00088
00089 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00090 const DTRecHit1D& recHit1D,
00091 const float& angle,
00092 const GlobalPoint& globPos,
00093 DTRecHit1D& newHit1D) const {
00094 return compute(layer, recHit1D.wireId(), recHit1D.digiTime(), globPos, newHit1D, 3);
00095 }
00096
00097
00098
00099
00100 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00101 const DTWireId& wireId,
00102 const float digiTime,
00103 const GlobalPoint& globPos,
00104 LocalPoint& leftPoint,
00105 LocalPoint& rightPoint,
00106 LocalError& error,
00107 int step) const {
00108
00109 float driftTime = digiTime - theSync->offset(layer, wireId, globPos);
00110
00111
00112 if (driftTime < minTime || driftTime > maxTime) {
00113 if (debug) cout << "[DTLinearDriftFromDBAlgo]*** Drift time out of window for in-time hits "
00114 << driftTime << endl;
00115
00116 if(step == 1) {
00117
00118
00119 return false;
00120 }
00121 }
00122
00123
00124 if (driftTime<0.) driftTime=0;
00125
00126
00127 float vDrift = 0;
00128 float hitResolution = 0;
00129
00130 mTimeMap->get(wireId.superlayerId(),
00131 vDrift,
00132 hitResolution,
00133 DTVelocityUnits::cm_per_ns);
00134
00135
00136
00137 float drift = driftTime * vDrift;
00138
00139
00140 if(!layer->specificTopology().isWireValid(wireId.wire())) return false;
00141 LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
00142
00143 leftPoint = LocalPoint(locWirePos.x()-drift,
00144 locWirePos.y(),
00145 locWirePos.z());
00146 rightPoint = LocalPoint(locWirePos.x()+drift,
00147 locWirePos.y(),
00148 locWirePos.z());
00149 error = LocalError(hitResolution*hitResolution,0.,0.);
00150
00151
00152 if(debug) {
00153 cout << "[DTLinearDriftFromDBAlgo] Compute drift distance, for digi at wire: " << wireId << endl
00154 << " Step: " << step << endl
00155 << " Digi time: " << digiTime << endl
00156 << " Drift time: " << driftTime << endl
00157 << " Drift distance: " << drift << endl
00158 << " Hit Resolution: " << hitResolution << endl
00159 << " Left point: " << leftPoint << endl
00160 << " Right point: " << rightPoint << endl
00161 << " Error: " << error << endl;
00162 }
00163
00164 return true;
00165
00166 }
00167
00168
00169
00170 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00171 const DTWireId& wireId,
00172 const float digiTime,
00173 const GlobalPoint& globPos,
00174 DTRecHit1D& newHit1D,
00175 int step) const {
00176 LocalPoint leftPoint;
00177 LocalPoint rightPoint;
00178 LocalError error;
00179
00180 if(compute(layer, wireId, digiTime, globPos, leftPoint, rightPoint, error, step)) {
00181
00182 switch(newHit1D.lrSide()) {
00183
00184 case DTEnums::Left:
00185 {
00186
00187
00188 LocalPoint leftPoint3D(leftPoint.x(), newHit1D.localPosition().y(), leftPoint.z());
00189 newHit1D.setPositionAndError(leftPoint3D, error);
00190 break;
00191 }
00192
00193 case DTEnums::Right:
00194 {
00195
00196 LocalPoint rightPoint3D(rightPoint.x(), newHit1D.localPosition().y(), rightPoint.z());
00197 newHit1D.setPositionAndError(rightPoint3D, error);
00198 break;
00199 }
00200
00201 default:
00202 throw cms::Exception("InvalidDTCellSide") << "[DTLinearDriftFromDBAlgo] Compute at Step "
00203 << step << ", Hit side "
00204 << newHit1D.lrSide()
00205 << " is invalid!" << endl;
00206 return false;
00207 }
00208
00209 return true;
00210 }else {
00211 return false;
00212 }
00213 }
00214
00215 float DTLinearDriftFromDBAlgo::minTime;
00216
00217
00218 float DTLinearDriftFromDBAlgo::maxTime;
00219
00220
00221 bool DTLinearDriftFromDBAlgo::debug;