Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:00:22

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author G. Cerminara - INFN Torino
0005  */
0006 
0007 #include "RecoLocalMuon/DTRecHit/plugins/DTLinearDriftAlgo.h"
0008 #include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h"
0009 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0010 #include "Geometry/DTGeometry/interface/DTLayer.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/Framework/interface/ConsumesCollector.h"
0014 #include "FWCore/Utilities/interface/Exception.h"
0015 
0016 using namespace std;
0017 using namespace edm;
0018 
0019 DTLinearDriftAlgo::DTLinearDriftAlgo(const ParameterSet& config, edm::ConsumesCollector cc)
0020     : DTRecHitBaseAlgo(config, cc),
0021       // Get the Drift Velocity from parameter set.
0022       vDrift(config.getParameter<double>("driftVelocity")),         // FIXME: Default was 0.00543 cm/ns
0023       hitResolution(config.getParameter<double>("hitResolution")),  // FIXME: Default is
0024       // vDriftMB1W1(config.getParameter<double>("driftVelocityMB1W1")), // FIXME: Default was 0.00543 cm/ns
0025       minTime(config.getParameter<double>("minTime")),  // FIXME: Default was -3 ns
0026       maxTime(config.getParameter<double>("maxTime")),  // FIXME: Default was 415 ns
0027       // Set verbose output
0028       debug(config.getUntrackedParameter<bool>("debug")) {}
0029 
0030 DTLinearDriftAlgo::~DTLinearDriftAlgo() {}
0031 
0032 void DTLinearDriftAlgo::setES(const EventSetup& setup) { theSync->setES(setup); }
0033 
0034 // First Step
0035 bool DTLinearDriftAlgo::compute(
0036     const DTLayer* layer, const DTDigi& digi, LocalPoint& leftPoint, LocalPoint& rightPoint, LocalError& error) const {
0037   // Get the wireId
0038   DTLayerId layerId = layer->id();
0039   const DTWireId wireId(layerId, digi.wire());
0040 
0041   // Get Wire position
0042   if (!layer->specificTopology().isWireValid(digi.wire()))
0043     return false;
0044   LocalPoint locWirePos(layer->specificTopology().wirePosition(digi.wire()), 0, 0);
0045   const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
0046 
0047   return compute(layer, wireId, digi.time(), globWirePos, leftPoint, rightPoint, error, 1);
0048 }
0049 
0050 // Second step: the same as 1st step
0051 bool DTLinearDriftAlgo::compute(const DTLayer* layer,
0052                                 const DTRecHit1D& recHit1D,
0053                                 const float& angle,
0054                                 DTRecHit1D& newHit1D) const {
0055   newHit1D.setPositionAndError(recHit1D.localPosition(), recHit1D.localPositionError());
0056   return true;
0057 }
0058 
0059 // Third step.
0060 bool DTLinearDriftAlgo::compute(const DTLayer* layer,
0061                                 const DTRecHit1D& recHit1D,
0062                                 const float& angle,
0063                                 const GlobalPoint& globPos,
0064                                 DTRecHit1D& newHit1D) const {
0065   return compute(layer, recHit1D.wireId(), recHit1D.digiTime(), globPos, newHit1D, 3);
0066 }
0067 
0068 // Do the actual work.
0069 bool DTLinearDriftAlgo::compute(const DTLayer* layer,
0070                                 const DTWireId& wireId,
0071                                 const float digiTime,
0072                                 const GlobalPoint& globPos,
0073                                 LocalPoint& leftPoint,
0074                                 LocalPoint& rightPoint,
0075                                 LocalError& error,
0076                                 int step) const {
0077   // Subtract the offset to the digi time accordingly to the DTTTrigBaseSync concrete instance
0078   float driftTime = digiTime - theSync->offset(layer, wireId, globPos);
0079 
0080   // check for out-of-time
0081   if (driftTime < minTime || driftTime > maxTime) {
0082     if (debug)
0083       cout << "[DTLinearDriftAlgo]*** Drift time out of window for in-time hits " << driftTime << endl;
0084 
0085     if (step == 1) {  //FIXME: protection against failure at 2nd and 3rd steps, must be checked!!!
0086       // Hits are interpreted as coming from out-of-time pile-up and recHit
0087       // is ignored.
0088       return false;
0089     }
0090   }
0091 
0092   // Small negative times interpreted as hits close to the wire.
0093   if (driftTime < 0.)
0094     driftTime = 0;
0095 
0096   // Compute the drift distance
0097   // SL 21-Dec-2006: Use specific Drift for MB1W1 (non fluxed chamber)
0098   float vd = vDrift;
0099   // if (wireId.wheel()==1 && wireId.station()==1) {
0100   //   vd=vDriftMB1W1;
0101   //   //cout << "Using Vd " << vd<< endl;
0102   // }
0103 
0104   float drift = driftTime * vd;
0105 
0106   // Get Wire position
0107   if (!layer->specificTopology().isWireValid(wireId.wire()))
0108     return false;
0109   LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
0110   //Build the two possible points and the error on the position
0111   leftPoint = LocalPoint(locWirePos.x() - drift, locWirePos.y(), locWirePos.z());
0112   rightPoint = LocalPoint(locWirePos.x() + drift, locWirePos.y(), locWirePos.z());
0113   error = LocalError(hitResolution * hitResolution, 0., 0.);
0114 
0115   if (debug) {
0116     cout << "[DTLinearDriftAlgo] Compute drift distance, for digi at wire: " << wireId << endl
0117          << "       Step:           " << step << endl
0118          << "       Digi time:      " << digiTime << endl
0119          << "       Drift time:     " << driftTime << endl
0120          << "       Drift distance: " << drift << endl
0121          << "       Hit Resolution: " << hitResolution << endl
0122          << "       Left point:     " << leftPoint << endl
0123          << "       Right point:    " << rightPoint << endl
0124          << "       Error:          " << error << endl;
0125   }
0126 
0127   return true;
0128 }
0129 
0130 // Interface to the method which does the actual work suited for 2nd and 3rd steps
0131 bool DTLinearDriftAlgo::compute(const DTLayer* layer,
0132                                 const DTWireId& wireId,
0133                                 const float digiTime,
0134                                 const GlobalPoint& globPos,
0135                                 DTRecHit1D& newHit1D,
0136                                 int step) const {
0137   LocalPoint leftPoint;
0138   LocalPoint rightPoint;
0139   LocalError error;
0140 
0141   if (compute(layer, wireId, digiTime, globPos, leftPoint, rightPoint, error, step)) {
0142     // Set the position and the error of the rechit which is being updated
0143     switch (newHit1D.lrSide()) {
0144       case DTEnums::Left: {
0145         // Keep the original y position of newHit1D: for step==3, it's the
0146         // position along the wire. Needed for rotation alignment
0147         LocalPoint leftPoint3D(leftPoint.x(), newHit1D.localPosition().y(), leftPoint.z());
0148         newHit1D.setPositionAndError(leftPoint3D, error);
0149         break;
0150       }
0151 
0152       case DTEnums::Right: {
0153         // as above: 3d position
0154         LocalPoint rightPoint3D(rightPoint.x(), newHit1D.localPosition().y(), rightPoint.z());
0155         newHit1D.setPositionAndError(rightPoint3D, error);
0156         break;
0157       }
0158 
0159       default:
0160         throw cms::Exception("InvalidDTCellSide") << "[DTLinearDriftAlgo] Compute at Step " << step << ", Hit side "
0161                                                   << newHit1D.lrSide() << " is invalid!" << endl;
0162         return false;
0163     }
0164 
0165     return true;
0166   } else {
0167     return false;
0168   }
0169 }