CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoLocalMuon/DTRecHit/plugins/DTLinearDriftFromDBAlgo.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2009/04/30 09:30:06 $
00005  *  $Revision: 1.4 $
00006  *  \author S. Bolognesi - INFN Torino
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     // Set verbose output
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   // Get the map of ttrig from the Setup
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 // First Step
00058 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00059                                 const DTDigi& digi,
00060                                 LocalPoint& leftPoint,
00061                                 LocalPoint& rightPoint,
00062                                 LocalError& error) const {
00063   // Get the wireId
00064   DTLayerId layerId = layer->id();
00065   const DTWireId wireId(layerId, digi.wire());
00066 
00067   // Get Wire position
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 // Second step: the same as 1st step
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 // Third step.
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 // Do the actual work.
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   // Subtract the offset to the digi time accordingly to the DTTTrigBaseSync concrete instance
00109   float driftTime = digiTime - theSync->offset(layer, wireId, globPos); 
00110   
00111   // check for out-of-time
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) { //FIXME: protection against failure at 2nd and 3rd steps, must be checked!!!
00117       // Hits are interpreted as coming from out-of-time pile-up and recHit
00118       // is ignored.
00119       return false;
00120     }
00121   }
00122 
00123   // Small negative times interpreted as hits close to the wire.
00124   if (driftTime<0.) driftTime=0;
00125 
00126   // Read the vDrift and reso for this wire
00127   float vDrift = 0;
00128   float hitResolution = 0;//FIXME: should use this!
00129   // vdrift is cm/ns , resolution is cm
00130   mTimeMap->get(wireId.superlayerId(),
00131                 vDrift,
00132                 hitResolution,
00133                 DTVelocityUnits::cm_per_ns);
00134 
00135 
00136   // Compute the drift distance
00137   float drift = driftTime * vDrift;
00138 
00139   // Get Wire position
00140   if(!layer->specificTopology().isWireValid(wireId.wire())) return false;
00141   LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
00142   //Build the two possible points and the error on the position
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 // Interface to the method which does the actual work suited for 2nd and 3rd steps 
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     // Set the position and the error of the rechit which is being updated
00182     switch(newHit1D.lrSide()) {
00183         
00184     case DTEnums::Left:
00185         {
00186           // Keep the original y position of newHit1D: for step==3, it's the
00187           // position along the wire. Needed for rotation alignment
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           // as above: 3d position
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;