CMS 3D CMS Logo

StandAloneMuonRefitter.cc
Go to the documentation of this file.
1 
9 
11 
17 
18 using namespace edm;
19 using namespace std;
20 
24  : theService(service), theFitterToken(col.esConsumes(edm::ESInputTag("", par.getParameter<string>("FitterName")))) {
25  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Constructor called." << endl;
26 
27  theNumberOfIterations = par.getParameter<unsigned int>("NumberOfIterations");
28  isForceAllIterations = par.getParameter<bool>("ForceAllIterations");
29  theMaxFractionOfLostHits = par.getParameter<double>("MaxFractionOfLostHits");
30  errorRescale = par.getParameter<double>("RescaleError");
31 }
32 
35  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Destructor called." << endl;
36 }
37 
38 // Operations
39 
42  theFitter = theService->eventSetup().getHandle(theFitterToken);
43 
44  vector<Trajectory> refitted;
45 
46  const 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 
54  reverse(trajRH.begin(), trajRH.end());
55  refitted = theFitter->fit(trajectory.seed(), trajRH, firstTsos);
56 
57  if (!refitted.empty())
58  return RefitResult(true, refitted.front());
59  else
60  return RefitResult(false, trajectory);
61 }
62 
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  StandAloneMuonRefitter::RefitResult singleRefitResult = singleRefit(lastFitted);
75  lastFitted = singleRefitResult.second;
76  unsigned int nLastHits = lastFitted.recHits().size();
77 
78  if (!singleRefitResult.first) {
79  allIter = false;
80  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << " refit n. " << nSuccess + 1 << ": failed" << endl;
81  break;
82  }
83 
84  double lostFract = 1 - double(nLastHits) / nOrigHits;
85  if (lostFract > theMaxFractionOfLostHits) {
86  enoughRH = false;
87  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << " refit n. " << nSuccess + 1 << ": too many RH lost" << endl;
88  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter")
89  << " 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")
96  << " Survived RecHits: " << nLastHits << "/" << nOrigHits << endl;
97 
98  } // end for
99 
100  LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << nSuccess << " successful refits!" << endl;
101 
102  // if isForceAllIterations==true => 3 successful refits: (true, refitted trajectory)
103  // <3 successful refits: (false, original trajectory)
104  // if isForceAllIterations==false => >0 successful refits: (true, last refitted trajectory)
105  // 0 successful refits: (false, original trajectory)
106  if (!enoughRH)
107  return RefitResult(false, trajectory);
108  else if (isForceAllIterations)
109  return allIter ? RefitResult(allIter, lastFitted) : RefitResult(allIter, trajectory);
110  else
111  return nSuccess == 0 ? RefitResult(false, trajectory) : RefitResult(true, lastFitted);
112 }
StandAloneMuonRefitter::theFitterToken
const edm::ESGetToken< TrajectoryFitter, TrajectoryFitter::Record > theFitterToken
Definition: StandAloneMuonRefitter.h:44
service
Definition: service.py:1
StandAloneMuonRefitter::RefitResult
std::pair< bool, Trajectory > RefitResult
Definition: StandAloneMuonRefitter.h:26
StandAloneMuonRefitter::theFitter
edm::ESHandle< TrajectoryFitter > theFitter
Definition: StandAloneMuonRefitter.h:45
edm::ESInputTag
Definition: ESInputTag.h:87
MessageLogger.h
StandAloneMuonRefitter::singleRefit
RefitResult singleRefit(const Trajectory &)
Refit.
Definition: StandAloneMuonRefitter.cc:41
StandAloneMuonRefitter::~StandAloneMuonRefitter
virtual ~StandAloneMuonRefitter()
Destructor.
Definition: StandAloneMuonRefitter.cc:34
edm
HLT enums.
Definition: AlignableModifier.h:19
cuy.col
col
Definition: cuy.py:1009
TrajectoryMeasurement::updatedState
TrajectoryStateOnSurface const & updatedState() const
Definition: TrajectoryMeasurement.h:184
MuonServiceProxy_cff.MuonServiceProxy
MuonServiceProxy
Definition: MuonServiceProxy_cff.py:14
groupFilesInBlocks.reverse
reverse
Definition: groupFilesInBlocks.py:131
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
StandAloneMuonRefitter::theMaxFractionOfLostHits
double theMaxFractionOfLostHits
Definition: StandAloneMuonRefitter.h:48
StandAloneMuonRefitter::StandAloneMuonRefitter
StandAloneMuonRefitter(const edm::ParameterSet &par, edm::ConsumesCollector col, const MuonServiceProxy *service)
Constructor.
Definition: StandAloneMuonRefitter.cc:21
StandAloneMuonRefitter::errorRescale
double errorRescale
Definition: StandAloneMuonRefitter.h:49
StandAloneMuonRefitter::isForceAllIterations
bool isForceAllIterations
Definition: StandAloneMuonRefitter.h:47
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
TrackingRecHit::ConstRecHitContainer
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: TrackingRecHit.h:32
StandAloneMuonRefitter::theService
const MuonServiceProxy * theService
Definition: StandAloneMuonRefitter.h:43
Trajectory::lastMeasurement
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TrajectoryFitter::fit
std::vector< Trajectory > fit(const Trajectory &traj, fitType type=standard) const
Definition: TrajectoryFitter.h:43
TrajectoryStateOnSurface::rescaleError
void rescaleError(double factor)
Definition: TrajectoryStateOnSurface.h:82
Trajectory::recHits
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
std
Definition: JetResolutionObject.h:76
Trajectory
Definition: Trajectory.h:38
TrackingComponentsRecord.h
MuonServiceProxy.h
Trajectory::seed
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ConsumesCollector.h
StandAloneMuonRefitter::theNumberOfIterations
unsigned int theNumberOfIterations
Definition: StandAloneMuonRefitter.h:46
StandAloneMuonRefitter::refit
RefitResult refit(const Trajectory &)
Definition: StandAloneMuonRefitter.cc:63
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
StandAloneMuonRefitter.h
edm::ConsumesCollector
Definition: ConsumesCollector.h:45