CMS 3D CMS Logo

DTLinearDriftFromDBAlgo.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2007/06/20 14:23:41 $
00005  *  $Revision: 1.2 $
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   LocalPoint locWirePos(layer->specificTopology().wirePosition(digi.wire()), 0, 0);
00069   const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
00070   
00071   return compute(layer, wireId, digi.time(), globWirePos, leftPoint, rightPoint, error, 1); 
00072 }
00073 
00074 
00075 
00076 // Second step: the same as 1st step
00077 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00078                                 const DTRecHit1D& recHit1D,
00079                                 const float& angle,
00080                                 DTRecHit1D& newHit1D) const {
00081   newHit1D.setPositionAndError(recHit1D.localPosition(), recHit1D.localPositionError());
00082   return true;
00083 }
00084 
00085 
00086 
00087 // Third step.
00088 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00089                                 const DTRecHit1D& recHit1D,
00090                                 const float& angle,
00091                                 const GlobalPoint& globPos, 
00092                                 DTRecHit1D& newHit1D) const {
00093   return compute(layer, recHit1D.wireId(), recHit1D.digiTime(), globPos, newHit1D, 3);
00094 }
00095 
00096 
00097 
00098 // Do the actual work.
00099 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00100                                 const DTWireId& wireId,
00101                                 const float digiTime,
00102                                 const GlobalPoint& globPos, 
00103                                 LocalPoint& leftPoint,
00104                                 LocalPoint& rightPoint,
00105                                 LocalError& error,
00106                                 int step) const {
00107   // Subtract the offset to the digi time accordingly to the DTTTrigBaseSync concrete instance
00108   float driftTime = digiTime - theSync->offset(layer, wireId, globPos); 
00109   
00110   // check for out-of-time
00111   if (driftTime < minTime || driftTime > maxTime) {
00112     if (debug) cout << "[DTLinearDriftFromDBAlgo]*** Drift time out of window for in-time hits "
00113                               << driftTime << endl;
00114 
00115     if(step == 1) { //FIXME: protection against failure at 2nd and 3rd steps, must be checked!!!
00116       // Hits are interpreted as coming from out-of-time pile-up and recHit
00117       // is ignored.
00118       return false;
00119     }
00120   }
00121 
00122   // Small negative times interpreted as hits close to the wire.
00123   if (driftTime<0.) driftTime=0;
00124 
00125   // Read the vDrift and reso for this wire
00126   float vDrift = 0;
00127   float hitResolution = 0;//FIXME: should use this!
00128   mTimeMap->slMtime(wireId.superlayerId(),
00129                     vDrift,
00130                     hitResolution,
00131                     DTTimeUnits::ns);
00132 
00133 
00134   // Compute the drift distance
00135   float drift = driftTime * vDrift;
00136 
00137   // Get Wire position
00138   LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
00139   //Build the two possible points and the error on the position
00140   leftPoint  = LocalPoint(locWirePos.x()-drift,
00141                             locWirePos.y(),
00142                             locWirePos.z());
00143   rightPoint = LocalPoint(locWirePos.x()+drift,
00144                             locWirePos.y(),
00145                             locWirePos.z());
00146   error = LocalError(hitResolution*hitResolution,0.,0.);
00147 
00148 
00149   if(debug) {
00150     cout << "[DTLinearDriftFromDBAlgo] Compute drift distance, for digi at wire: " << wireId << endl
00151          << "       Step:           " << step << endl
00152          << "       Digi time:      " << digiTime << endl
00153          << "       Drift time:     " << driftTime << endl
00154          << "       Drift distance: " << drift << endl
00155          << "       Hit Resolution: " << hitResolution << endl
00156          << "       Left point:     " << leftPoint << endl
00157          << "       Right point:    " << rightPoint << endl
00158          << "       Error:          " << error << endl;
00159    }
00160   
00161   return true;
00162   
00163 }
00164 
00165 
00166 // Interface to the method which does the actual work suited for 2nd and 3rd steps 
00167 bool DTLinearDriftFromDBAlgo::compute(const DTLayer* layer,
00168                                 const DTWireId& wireId,
00169                                 const float digiTime,
00170                                 const GlobalPoint& globPos, 
00171                                 DTRecHit1D& newHit1D,
00172                                 int step) const {
00173   LocalPoint leftPoint;
00174   LocalPoint rightPoint;
00175   LocalError error;
00176 
00177   if(compute(layer, wireId, digiTime, globPos, leftPoint, rightPoint, error, step)) {
00178     // Set the position and the error of the rechit which is being updated
00179     switch(newHit1D.lrSide()) {
00180         
00181     case DTEnums::Left:
00182         {
00183           // Keep the original y position of newHit1D: for step==3, it's the
00184           // position along the wire. Needed for rotation alignment
00185           LocalPoint leftPoint3D(leftPoint.x(), newHit1D.localPosition().y(), leftPoint.z());
00186           newHit1D.setPositionAndError(leftPoint3D, error);
00187           break;
00188         }
00189         
00190     case DTEnums::Right:
00191         {
00192           // as above: 3d position
00193           LocalPoint rightPoint3D(rightPoint.x(), newHit1D.localPosition().y(), rightPoint.z());
00194           newHit1D.setPositionAndError(rightPoint3D, error);
00195           break;
00196         }
00197         
00198     default:
00199       throw cms::Exception("InvalidDTCellSide") << "[DTLinearDriftFromDBAlgo] Compute at Step "
00200                                                 << step << ", Hit side "
00201                                                 << newHit1D.lrSide()
00202                                                 << " is invalid!" << endl;
00203       return false;
00204     }
00205       
00206     return true;
00207   }else {
00208     return false;
00209   }
00210 }
00211 
00212 float DTLinearDriftFromDBAlgo::minTime;
00213 
00214   
00215 float DTLinearDriftFromDBAlgo::maxTime;
00216 
00217   
00218 bool DTLinearDriftFromDBAlgo::debug;

Generated on Tue Jun 9 17:43:53 2009 for CMSSW by  doxygen 1.5.4