CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLocalMuon/DTRecHit/plugins/DTNoDriftAlgo.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.2 $
00006  *  \author Martijn Mulders - CERN (martijn.mulders@cern.ch)
00007  *  based on DTLinearDriftAlgo
00008  */
00009 
00010 #include "RecoLocalMuon/DTRecHit/plugins/DTNoDriftAlgo.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/Utilities/interface/Exception.h"
00016 
00017 using namespace std;
00018 using namespace edm;
00019 
00020 DTNoDriftAlgo::DTNoDriftAlgo(const ParameterSet& config) :
00021   DTRecHitBaseAlgo(config) {
00022 
00023     minTime = config.getParameter<double>("minTime");
00024 
00025     maxTime = config.getParameter<double>("maxTime"); 
00026 
00027     fixedDrift = config.getParameter<double>("fixedDrift");
00028 
00029     hitResolution = config.getParameter<double>("hitResolution"); // Set to size of (half)cell 
00030     // Set verbose output
00031     debug = config.getUntrackedParameter<bool>("debug");
00032     
00033   }
00034 
00035 
00036 
00037 DTNoDriftAlgo::~DTNoDriftAlgo(){}
00038 
00039 
00040 
00041 void DTNoDriftAlgo::setES(const EventSetup& setup) {
00042   //  theSync->setES(setup);
00043 }
00044 
00045 
00046 
00047 
00048 // Build all hits in the range associated to the layerId, at the 1st step.
00049 OwnVector<DTRecHit1DPair> DTNoDriftAlgo::reconstruct(const DTLayer* layer,
00050                                                         const DTLayerId& layerId,
00051                                                         const DTDigiCollection::Range& digiRange) {
00052   OwnVector<DTRecHit1DPair> result; 
00053 
00054   // Loop over all digis in the given range
00055   for (DTDigiCollection::const_iterator digi = digiRange.first;
00056        digi != digiRange.second;
00057        digi++) {
00058     // Get the wireId
00059     DTWireId wireId(layerId, (*digi).wire());
00060 
00061     bool isDouble = false;
00062     for (OwnVector<DTRecHit1DPair>::const_iterator doubleWireCheck =  result.begin();
00063          doubleWireCheck != result.end();
00064          doubleWireCheck++) {
00065       if( wireId == (*doubleWireCheck).wireId()) {
00066         isDouble = true;
00067         //      std::cout << " Reject this hit with time " << (*digi).time() << std::endl; 
00068         break;
00069       }
00070     }
00071     
00072     if (isDouble) continue;
00073 
00074     LocalError tmpErr;
00075     LocalPoint lpoint, rpoint;
00076     // Call the compute method
00077     bool OK = compute(layer, *digi, lpoint, rpoint, tmpErr);
00078 
00079     if (!OK) continue;
00080 
00081     // Build a new pair of 1D rechit    
00082     DTRecHit1DPair*  recHitPair = new DTRecHit1DPair(wireId, *digi);
00083 
00084     // Set the position and the error of the 1D rechits
00085     recHitPair->setPositionAndError(DTEnums::Left, lpoint, tmpErr);
00086     recHitPair->setPositionAndError(DTEnums::Right, rpoint, tmpErr);        
00087 
00088     result.push_back(recHitPair);
00089   }
00090   return result;
00091 }
00092 
00093 
00094 
00095 
00096 
00097 // First Step
00098 bool DTNoDriftAlgo::compute(const DTLayer* layer,
00099                                 const DTDigi& digi,
00100                                 LocalPoint& leftPoint,
00101                                 LocalPoint& rightPoint,
00102                                 LocalError& error) const {
00103   // Get the wireId
00104   DTLayerId layerId = layer->id();
00105   const DTWireId wireId(layerId, digi.wire());
00106 
00107   // Get Wire position
00108   if(!layer->specificTopology().isWireValid(digi.wire())) return false;
00109   LocalPoint locWirePos(layer->specificTopology().wirePosition(digi.wire()), 0, 0);
00110   const GlobalPoint globWirePos = layer->toGlobal(locWirePos);
00111   
00112   return compute(layer, wireId, digi.time(), globWirePos, leftPoint, rightPoint, error, 1); 
00113 }
00114 
00115 
00116 
00117 // Second step: the same as 1st step
00118 bool DTNoDriftAlgo::compute(const DTLayer* layer,
00119                                 const DTRecHit1D& recHit1D,
00120                                 const float& angle,
00121                                 DTRecHit1D& newHit1D) const {
00122   newHit1D.setPositionAndError(recHit1D.localPosition(), recHit1D.localPositionError());
00123   return true;
00124 }
00125 
00126 
00127 
00128 // Third step.
00129 bool DTNoDriftAlgo::compute(const DTLayer* layer,
00130                                 const DTRecHit1D& recHit1D,
00131                                 const float& angle,
00132                                 const GlobalPoint& globPos, 
00133                                 DTRecHit1D& newHit1D) const {
00134   return compute(layer, recHit1D.wireId(), recHit1D.digiTime(), globPos, newHit1D, 3);
00135 }
00136 
00137 
00138 
00139 // Do the actual work.
00140 bool DTNoDriftAlgo::compute(const DTLayer* layer,
00141                                 const DTWireId& wireId,
00142                                 const float digiTime,
00143                                 const GlobalPoint& globPos, 
00144                                 LocalPoint& leftPoint,
00145                                 LocalPoint& rightPoint,
00146                                 LocalError& error,
00147                                 int step) const {
00148   //}
00149 
00150   // Small negative times interpreted as hits close to the wire.
00151   //if (driftTime<0.) driftTime=0;
00152 
00153 
00154   // check for out-of-time
00155   if (digiTime < minTime || digiTime > maxTime) {
00156     if (debug) cout << "[DTNoDriftAlgo]*** Drift time out of window for in-time hits "
00157                               << digiTime << endl;
00158 
00159     if(step == 1) { //FIXME: protection against failure at 2nd and 3rd steps, must be checked!!!
00160       // Hits are interpreted as coming from out-of-time pile-up and recHit
00161       // is ignored.
00162       return false;
00163     }
00164   }
00165 
00166 
00167   // Compute the drift distance
00168   float drift = fixedDrift;
00169 
00170   // Get Wire position
00171   if(!layer->specificTopology().isWireValid(wireId.wire())) return false;
00172   LocalPoint locWirePos(layer->specificTopology().wirePosition(wireId.wire()), 0, 0);
00173   //Build the two possible points and the error on the position
00174   leftPoint  = LocalPoint(locWirePos.x()-drift,
00175                             locWirePos.y(),
00176                             locWirePos.z());
00177   rightPoint = LocalPoint(locWirePos.x()+drift,
00178                             locWirePos.y(),
00179                             locWirePos.z());
00180   error = LocalError(hitResolution*hitResolution,0.,0.);
00181 
00182   
00183   if(debug) {
00184     cout << "[DTNoDriftAlgo] Compute drift distance, for digi at wire: " << wireId << endl
00185          << "       Step:           " << step << endl
00186          << "       Digi time:      " << digiTime << endl
00187       //         << "       Drift time:     " << driftTime << endl
00188          << "       Fixed Drift distance: " << drift << endl
00189          << "       Hit Resolution: " << hitResolution << endl
00190          << "       Left point:     " << leftPoint << endl
00191          << "       Right point:    " << rightPoint << endl
00192          << "       Error:          " << error << endl;
00193   }
00194 
00195 
00196 
00197   return true;
00198   
00199 }
00200 
00201 
00202 // Interface to the method which does the actual work suited for 2nd and 3rd steps 
00203 bool DTNoDriftAlgo::compute(const DTLayer* layer,
00204                                 const DTWireId& wireId,
00205                                 const float digiTime,
00206                                 const GlobalPoint& globPos, 
00207                                 DTRecHit1D& newHit1D,
00208                                 int step) const {
00209   LocalPoint leftPoint;
00210   LocalPoint rightPoint;
00211   LocalError error;
00212 
00213   if(compute(layer, wireId, digiTime, globPos, leftPoint, rightPoint, error, step)) {
00214     // Set the position and the error of the rechit which is being updated
00215     switch(newHit1D.lrSide()) {
00216         
00217     case DTEnums::Left:
00218       newHit1D.setPositionAndError(leftPoint, error);
00219       break;
00220         
00221     case DTEnums::Right:
00222       newHit1D.setPositionAndError(rightPoint, error);
00223       break;
00224         
00225     default:
00226       throw cms::Exception("InvalidDTCellSide") << "[DTNoDriftAlgo] Compute at Step "
00227                                                 << step << ", Hit side "
00228                                                 << newHit1D.lrSide()
00229                                                 << " is invalid!" << endl;
00230       return false;
00231     }
00232       
00233     return true;
00234   }else {
00235     return false;
00236   }
00237 }
00238 
00239 
00240 float DTNoDriftAlgo::fixedDrift;
00241 
00242   
00243 float DTNoDriftAlgo::hitResolution;
00244 
00245   
00246 float DTNoDriftAlgo::minTime;
00247 
00248   
00249 float DTNoDriftAlgo::maxTime;
00250 
00251   
00252 bool DTNoDriftAlgo::debug;