CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StandAloneMuonRefitter.cc
Go to the documentation of this file.
1 
9 
11 
13 
18 
19 using namespace edm;
20 using namespace std;
21 
22 StandAloneMuonRefitter::StandAloneMuonRefitter(const ParameterSet& par, const MuonServiceProxy* service):theService(service) {
23  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Constructor called." << endl;
24 
25  theFitterName = par.getParameter<string>("FitterName");
26  theNumberOfIterations = par.getParameter<unsigned int>("NumberOfIterations");
27  isForceAllIterations = par.getParameter<bool>("ForceAllIterations");
28  theMaxFractionOfLostHits = par.getParameter<double>("MaxFractionOfLostHits");
29  errorRescale = par.getParameter<double>("RescaleError");
30 }
31 
34  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Destructor called." << endl;
35 }
36 
37  // Operations
38 
41 
43 
44  vector<Trajectory> refitted;
45 
46  TrajectoryMeasurement lastTM = trajectory.lastMeasurement();
47 
48  TrajectoryStateOnSurface firstTsos(lastTM.updatedState());
49 
50  // Rescale errors before refit, not to bias the result
51  firstTsos.rescaleError(errorRescale);
52 
53  TransientTrackingRecHit::ConstRecHitContainer trajRH = trajectory.recHits();
54  reverse(trajRH.begin(),trajRH.end());
55  refitted = theFitter->fit(trajectory.seed(), trajRH, firstTsos);
56 
57  if(!refitted.empty()) return RefitResult(true,refitted.front());
58  else return RefitResult(false,trajectory);
59 }
60 
61 
63 
64  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "---------------------------------" << endl;
65  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Starting refitting loop:" << endl;
66 
67  unsigned int nSuccess=0;
68  unsigned int nOrigHits=trajectory.recHits().size();
69  Trajectory lastFitted=trajectory;
70  bool allIter=true;
71  bool enoughRH=true;
72 
73  for(unsigned int j=0; j<theNumberOfIterations; ++j) {
74 
75  StandAloneMuonRefitter::RefitResult singleRefitResult = singleRefit(lastFitted);
76  lastFitted = singleRefitResult.second;
77  unsigned int nLastHits=lastFitted.recHits().size();
78 
79  if(!singleRefitResult.first) {
80  allIter=false;
81  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << " refit n. " << nSuccess+1 << ": failed" << endl;
82  break;
83  }
84 
85  double lostFract= 1 - double(nLastHits)/nOrigHits;
86  if(lostFract>theMaxFractionOfLostHits) {
87  enoughRH=false;
88  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << " refit n. " << nSuccess+1 << ": too many RH lost" << endl;
89  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << " Survived RecHits: " << nLastHits << "/" << nOrigHits << endl;
90  break;
91  }
92 
93  nSuccess++;
94  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << " refit n. " << nSuccess << ": OK" << endl;
95  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << " Survived RecHits: " << nLastHits << "/" << nOrigHits << endl;
96 
97  } // end for
98 
99  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << nSuccess << " successful refits!" << endl;
100 
101  // if isForceAllIterations==true => 3 successful refits: (true, refitted trajectory)
102  // <3 successful refits: (false, original trajectory)
103  // if isForceAllIterations==false => >0 successful refits: (true, last refitted trajectory)
104  // 0 successful refits: (false, original trajectory)
105  if(!enoughRH)
106  return RefitResult(false, trajectory);
107  else if(isForceAllIterations)
108  return allIter ? RefitResult(allIter, lastFitted) : RefitResult(allIter, trajectory);
109  else
110  return nSuccess==0 ? RefitResult(false, trajectory) : RefitResult(true, lastFitted);
111 }
#define LogDebug(id)
const MuonServiceProxy * theService
T getParameter(std::string const &) const
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:275
StandAloneMuonRefitter(const edm::ParameterSet &par, const MuonServiceProxy *service)
Constructor.
edm::ESHandle< TrajectoryFitter > theFitter
std::pair< bool, Trajectory > RefitResult
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
int j
Definition: DBlmapReader.cc:9
RefitResult refit(const Trajectory &)
std::vector< ConstRecHitPointer > ConstRecHitContainer
virtual ~StandAloneMuonRefitter()
Destructor.
RefitResult singleRefit(const Trajectory &)
Refit.
TrajectoryStateOnSurface const & updatedState() const