Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:01:31

0001 /** \class StandAloneMuonRefitter
0002  *  Class ti interface the muon system rechits with the standard KF tools.
0003  *
0004  *  \authors R. Bellan - INFN Torino <riccardo.bellan@cern.ch>,
0005  *           D. Trocino - INFN Torino <daniele.trocino@to.infn.it>
0006  */
0007 
0008 #include "RecoMuon/StandAloneTrackFinder/interface/StandAloneMuonRefitter.h"
0009 
0010 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/ConsumesCollector.h"
0016 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0017 
0018 using namespace edm;
0019 using namespace std;
0020 
0021 StandAloneMuonRefitter::StandAloneMuonRefitter(const ParameterSet& par,
0022                                                edm::ConsumesCollector col,
0023                                                const MuonServiceProxy* service)
0024     : theService(service), theFitterToken(col.esConsumes(edm::ESInputTag("", par.getParameter<string>("FitterName")))) {
0025   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Constructor called." << endl;
0026 
0027   theNumberOfIterations = par.getParameter<unsigned int>("NumberOfIterations");
0028   isForceAllIterations = par.getParameter<bool>("ForceAllIterations");
0029   theMaxFractionOfLostHits = par.getParameter<double>("MaxFractionOfLostHits");
0030   errorRescale = par.getParameter<double>("RescaleError");
0031 }
0032 
0033 /// Destructor
0034 StandAloneMuonRefitter::~StandAloneMuonRefitter() {
0035   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Destructor called." << endl;
0036 }
0037 
0038 // Operations
0039 
0040 /// Refit
0041 StandAloneMuonRefitter::RefitResult StandAloneMuonRefitter::singleRefit(const Trajectory& trajectory) {
0042   theFitter = theService->eventSetup().getHandle(theFitterToken);
0043 
0044   vector<Trajectory> refitted;
0045 
0046   const TrajectoryMeasurement& lastTM = trajectory.lastMeasurement();
0047 
0048   TrajectoryStateOnSurface firstTsos(lastTM.updatedState());
0049 
0050   // Rescale errors before refit, not to bias the result
0051   firstTsos.rescaleError(errorRescale);
0052 
0053   TransientTrackingRecHit::ConstRecHitContainer trajRH = trajectory.recHits();
0054   reverse(trajRH.begin(), trajRH.end());
0055   refitted = theFitter->fit(trajectory.seed(), trajRH, firstTsos);
0056 
0057   if (!refitted.empty())
0058     return RefitResult(true, refitted.front());
0059   else
0060     return RefitResult(false, trajectory);
0061 }
0062 
0063 StandAloneMuonRefitter::RefitResult StandAloneMuonRefitter::refit(const Trajectory& trajectory) {
0064   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "---------------------------------" << endl;
0065   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Starting refitting loop:" << endl;
0066 
0067   unsigned int nSuccess = 0;
0068   unsigned int nOrigHits = trajectory.recHits().size();
0069   Trajectory lastFitted = trajectory;
0070   bool allIter = true;
0071   bool enoughRH = true;
0072 
0073   for (unsigned int j = 0; j < theNumberOfIterations; ++j) {
0074     StandAloneMuonRefitter::RefitResult singleRefitResult = singleRefit(lastFitted);
0075     lastFitted = singleRefitResult.second;
0076     unsigned int nLastHits = lastFitted.recHits().size();
0077 
0078     if (!singleRefitResult.first) {
0079       allIter = false;
0080       LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "  refit n. " << nSuccess + 1 << ": failed" << endl;
0081       break;
0082     }
0083 
0084     double lostFract = 1 - double(nLastHits) / nOrigHits;
0085     if (lostFract > theMaxFractionOfLostHits) {
0086       enoughRH = false;
0087       LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "  refit n. " << nSuccess + 1 << ": too many RH lost" << endl;
0088       LogDebug("Muon|RecoMuon|StandAloneMuonRefitter")
0089           << "     Survived RecHits: " << nLastHits << "/" << nOrigHits << endl;
0090       break;
0091     }
0092 
0093     nSuccess++;
0094     LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "  refit n. " << nSuccess << ": OK" << endl;
0095     LogDebug("Muon|RecoMuon|StandAloneMuonRefitter")
0096         << "     Survived RecHits: " << nLastHits << "/" << nOrigHits << endl;
0097 
0098   }  // end for
0099 
0100   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << nSuccess << " successful refits!" << endl;
0101 
0102   // if isForceAllIterations==true  =>   3 successful refits: (true, refitted trajectory)
0103   //                                    <3 successful refits: (false, original trajectory)
0104   // if isForceAllIterations==false =>  >0 successful refits: (true, last refitted trajectory)
0105   //                                     0 successful refits: (false, original trajectory)
0106   if (!enoughRH)
0107     return RefitResult(false, trajectory);
0108   else if (isForceAllIterations)
0109     return allIter ? RefitResult(allIter, lastFitted) : RefitResult(allIter, trajectory);
0110   else
0111     return nSuccess == 0 ? RefitResult(false, trajectory) : RefitResult(true, lastFitted);
0112 }