CMS 3D CMS Logo

MuonTrajectoryUpdator.cc
Go to the documentation of this file.
1 
20 
28 
31 
35 
36 #include <algorithm>
37 
38 using namespace edm;
39 using namespace std;
40 
43  : theFitDirection(fitDirection) {
44  // The max allowed chi2 to accept a rechit in the fit
45  theMaxChi2 = par.getParameter<double>("MaxChi2");
47 
48  // The KF updator
49  theUpdator = new KFUpdator();
50 
51  // The granularity
52  theGranularity = par.getParameter<int>("Granularity");
53 
54  // Rescale the error of the first state?
55  theRescaleErrorFlag = par.getParameter<bool>("RescaleError");
56 
58  // The rescale factor
59  theRescaleFactor = par.getParameter<double>("RescaleErrorFactor");
60 
61  // Use the invalid hits?
62  useInvalidHits = par.getParameter<bool>("UseInvalidHits");
63 
64  // Flag needed for the rescaling
65  theFirstTSOSFlag = true;
66 
67  // Exlude RPC from the fit?
68  theRPCExFlag = par.getParameter<bool>("ExcludeRPCFromFit");
69 }
70 
72  : theMaxChi2(chi2), theGranularity(granularity), theFitDirection(fitDirection) {
74 
75  // The KF updator
76  theUpdator = new KFUpdator();
77 }
78 
81  delete theEstimator;
82  delete theUpdator;
83 }
84 
86 
87 pair<bool, TrajectoryStateOnSurface> MuonTrajectoryUpdator::update(const TrajectoryMeasurement* measurement,
88  Trajectory& trajectory,
89  const Propagator* propagator) {
90  const std::string metname = "Muon|RecoMuon|MuonTrajectoryUpdator";
91 
92  MuonPatternRecoDumper muonDumper;
93 
94  // Status of the updating
95  bool updated = false;
96 
97  if (!measurement)
98  return pair<bool, TrajectoryStateOnSurface>(updated, TrajectoryStateOnSurface());
99 
100  // measurement layer
101  const DetLayer* detLayer = measurement->layer();
102 
103  // these are the 4D segment for the CSC/DT and a point for the RPC
104  TransientTrackingRecHit::ConstRecHitPointer muonRecHit = measurement->recHit();
105 
106  // The KFUpdator takes TransientTrackingRecHits as arg.
109 
110  // sort the container in agreement with the porpagation direction
111  sort(recHitsForFit, detLayer);
112 
113  TrajectoryStateOnSurface lastUpdatedTSOS = measurement->predictedState();
114 
115  LogTrace(metname) << "Number of rechits for the fit: " << recHitsForFit.size() << endl;
116 
117  TransientTrackingRecHit::ConstRecHitContainer::iterator recHit;
118  for (recHit = recHitsForFit.begin(); recHit != recHitsForFit.end(); ++recHit) {
119  if ((*recHit)->isValid()) {
120  // propagate the TSOS onto the rechit plane
121  TrajectoryStateOnSurface propagatedTSOS = propagateState(lastUpdatedTSOS, measurement, *recHit, propagator);
122 
123  if (propagatedTSOS.isValid()) {
124  pair<bool, double> thisChi2 = estimator()->estimate(propagatedTSOS, *((*recHit).get()));
125 
126  LogTrace(metname) << "Estimation for Kalman Fit. Chi2: " << thisChi2.second;
127 
128  // Is an RPC hit? Prepare the variable to possibly exluding it from the fit
129  bool wantIncludeThisHit = true;
130  if (theRPCExFlag && (*recHit)->geographicalId().det() == DetId::Muon &&
131  (*recHit)->geographicalId().subdetId() == MuonSubdetId::RPC) {
132  wantIncludeThisHit = false;
134  << "This is an RPC hit and the present configuration is such that it will be excluded from the fit";
135  }
136 
137  // The Chi2 cut was already applied in the estimator, which
138  // returns 0 if the chi2 is bigger than the cut defined in its
139  // constructor
140  if (thisChi2.first) {
141  updated = true;
142  if (wantIncludeThisHit) { // This split is a trick to have the RPC hits counted as updatable (in used chamber counting), while are not actually included in the fit when the proper obtion is activated.
143 
144  LogTrace(metname) << endl
145  << " Kalman Start"
146  << "\n"
147  << "\n";
148  LogTrace(metname) << " Meas. Position : " << (**recHit).globalPosition() << "\n"
149  << " Pred. Position : " << propagatedTSOS.globalPosition()
150  << " Pred Direction : " << propagatedTSOS.globalDirection() << endl;
151 
153  propagatedTSOS.rescaleError(theRescaleFactor);
154  theFirstTSOSFlag = false;
155  }
156 
157  lastUpdatedTSOS = measurementUpdator()->update(propagatedTSOS, *((*recHit).get()));
158 
159  LogTrace(metname) << " Fit Position : " << lastUpdatedTSOS.globalPosition()
160  << " Fit Direction : " << lastUpdatedTSOS.globalDirection() << "\n"
161  << " Fit position radius : " << lastUpdatedTSOS.globalPosition().perp()
162  << "filter updated" << endl;
163 
164  LogTrace(metname) << muonDumper.dumpTSOS(lastUpdatedTSOS);
165 
166  LogTrace(metname) << "\n\n Kalman End"
167  << "\n"
168  << "\n";
169 
170  TrajectoryMeasurement&& updatedMeasurement =
171  updateMeasurement(propagatedTSOS, lastUpdatedTSOS, *recHit, thisChi2.second, detLayer, measurement);
172  // FIXME: check!
173  trajectory.push(std::move(updatedMeasurement), thisChi2.second);
174  } else {
175  LogTrace(metname) << " Compatible RecHit with good chi2 but made with RPC when it was decided to not "
176  "include it in the fit"
177  << " --> trajectory NOT updated, invalid RecHit added." << endl;
178 
180  MuonTransientTrackingRecHit::specificBuild((*recHit)->det(), (*recHit)->hit());
181  invalidRhPtr->invalidateHit();
182  TrajectoryMeasurement invalidRhMeasurement(
183  propagatedTSOS, propagatedTSOS, invalidRhPtr, thisChi2.second, detLayer);
184  trajectory.push(std::move(invalidRhMeasurement), thisChi2.second);
185  }
186  } else {
187  if (useInvalidHits) {
188  LogTrace(metname) << " Compatible RecHit with too large chi2"
189  << " --> trajectory NOT updated, invalid RecHit added." << endl;
190 
192  MuonTransientTrackingRecHit::specificBuild((*recHit)->det(), (*recHit)->hit());
193  invalidRhPtr->invalidateHit();
194  TrajectoryMeasurement invalidRhMeasurement(
195  propagatedTSOS, propagatedTSOS, invalidRhPtr, thisChi2.second, detLayer);
196  trajectory.push(std::move(invalidRhMeasurement), thisChi2.second);
197  }
198  }
199  }
200  }
201  }
202  recHitsForFit.clear();
203  return pair<bool, TrajectoryStateOnSurface>(updated, lastUpdatedTSOS);
204 }
205 
208  const TrajectoryMeasurement* measurement,
210  const Propagator* propagator) const {
211  const TransientTrackingRecHit::ConstRecHitPointer& mother = measurement->recHit();
212 
213  if (current->geographicalId() == mother->geographicalId())
214  return measurement->predictedState();
215 
216  const TrajectoryStateOnSurface tsos = propagator->propagate(state, current->det()->surface());
217  return tsos;
218 }
219 
220 // FIXME: would I a different threatment for the two prop dirrections??
222  const TrajectoryStateOnSurface& lastUpdatedTSOS,
224  const double& chi2,
225  const DetLayer* detLayer,
226  const TrajectoryMeasurement* initialMeasurement) {
227  return TrajectoryMeasurement(propagatedTSOS, lastUpdatedTSOS, recHit, chi2, detLayer);
228 
229  // // FIXME: put a better check! One could fit in first out-in and then in - out
230  // if(propagator()->propagationDirection() == alongMomentum)
231  // return TrajectoryMeasurement(propagatedTSOS, lastUpdatedTSOS,
232  // recHit,thisChi2.second,detLayer);
233 
234  // // FIXME: Check this carefully!!
235  // else if(propagator()->propagationDirection() == oppositeToMomentum)
236  // return TrajectoryMeasurement(initialMeasurement->forwardPredictedState(),
237  // propagatedTSOS, lastUpdatedTSOS,
238  // recHit,thisChi2.second,detLayer);
239  // else{
240  // LogError("MuonTrajectoryUpdator::updateMeasurement") <<"Wrong propagation direction!!";
241  // }
242 }
243 
245  const DetLayer* detLayer) {
246  if (detLayer->subDetector() == GeomDetEnumerators::DT) {
247  if (fitDirection() == insideOut)
248  stable_sort(recHitsForFit.begin(), recHitsForFit.end(), RadiusComparatorInOut());
249  else if (fitDirection() == outsideIn)
250  stable_sort(recHitsForFit.begin(), recHitsForFit.end(), RadiusComparatorOutIn());
251  else
252  LogError("Muon|RecoMuon|MuonTrajectoryUpdator") << "MuonTrajectoryUpdator::sort: Wrong propagation direction!!";
253  }
254 
255  else if (detLayer->subDetector() == GeomDetEnumerators::CSC) {
256  if (fitDirection() == insideOut)
257  stable_sort(recHitsForFit.begin(), recHitsForFit.end(), ZedComparatorInOut());
258  else if (fitDirection() == outsideIn)
259  stable_sort(recHitsForFit.begin(), recHitsForFit.end(), ZedComparatorOutIn());
260  else
261  LogError("Muon|RecoMuon|MuonTrajectoryUpdator") << "MuonTrajectoryUpdator::sort: Wrong propagation direction!!";
262  }
263 
264  else if (detLayer->subDetector() == GeomDetEnumerators::GEM) {
265  if (fitDirection() == insideOut)
266  stable_sort(recHitsForFit.begin(), recHitsForFit.end(), ZedComparatorInOut());
267  else if (fitDirection() == outsideIn)
268  stable_sort(recHitsForFit.begin(), recHitsForFit.end(), ZedComparatorOutIn());
269  else
270  LogError("Muon|RecoMuon|MuonTrajectoryUpdator") << "MuonTrajectoryUpdator::sort: Wrong propagation direction!!";
271  } else if (detLayer->subDetector() == GeomDetEnumerators::ME0) {
272  if (fitDirection() == insideOut)
273  stable_sort(recHitsForFit.begin(), recHitsForFit.end(), ZedComparatorInOut());
274  else if (fitDirection() == outsideIn)
275  stable_sort(recHitsForFit.begin(), recHitsForFit.end(), ZedComparatorOutIn());
276  else
277  LogError("Muon|RecoMuon|MuonTrajectoryUpdator") << "MuonTrajectoryUpdator::sort: Wrong propagation direction!!";
278  }
279 }
TrajectoryStateOnSurface::globalDirection
GlobalVector globalDirection() const
Definition: TrajectoryStateOnSurface.h:67
Propagator.h
Chi2MeasurementEstimator.h
dtChamberEfficiency_cfi.theMaxChi2
theMaxChi2
Definition: dtChamberEfficiency_cfi.py:10
TrajectoryStateOnSurface.h
MuonTransientTrackingRecHit::specificBuild
static MuonRecHitPointer specificBuild(const GeomDet *geom, const TrackingRecHit *rh)
Definition: MuonTransientTrackingRecHit.h:75
MessageLogger.h
MuonPatternRecoDumper.h
DetLayer::subDetector
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel,...
DetLayer
Definition: DetLayer.h:21
MuonTrajectoryUpdator::theRescaleErrorFlag
bool theRescaleErrorFlag
Definition: MuonTrajectoryUpdator.h:146
edm
HLT enums.
Definition: AlignableModifier.h:19
MuonTrajectoryUpdator::update
virtual std::pair< bool, TrajectoryStateOnSurface > update(const TrajectoryMeasurement *measurement, Trajectory &trajectory, const Propagator *propagator)
update the Trajectory with the TrajectoryMeasurement
Definition: MuonTrajectoryUpdator.cc:87
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
MuonTrajectoryUpdator::RadiusComparatorInOut
Ordering along increasing radius (for DT rechits)
Definition: MuonTrajectoryUpdator.h:94
TrajectoryMeasurement.h
MuonTrajectoryUpdator::makeFirstTime
void makeFirstTime()
reset the theFirstTSOSFlag
Definition: MuonTrajectoryUpdator.cc:85
MuonTransientTrackingRecHit.h
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
MuonTrajectoryUpdator::ZedComparatorOutIn
Ordering along decreasing zed (for CSC rechits)
Definition: MuonTrajectoryUpdator.h:118
MuonTrajectoryUpdator::theRPCExFlag
bool theRPCExFlag
Definition: MuonTrajectoryUpdator.h:152
MeasurementEstimator::estimate
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
Propagator
Definition: Propagator.h:44
MuonTrajectoryUpdator::theRescaleFactor
double theRescaleFactor
Definition: MuonTrajectoryUpdator.h:147
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MuonTransientTrackingRecHit::MuonRecHitPointer
std::shared_ptr< MuonTransientTrackingRecHit > MuonRecHitPointer
Definition: MuonTransientTrackingRecHit.h:21
MuonTrajectoryUpdator::propagateState
TrajectoryStateOnSurface propagateState(const TrajectoryStateOnSurface &state, const TrajectoryMeasurement *measurement, const TransientTrackingRecHit::ConstRecHitPointer &current, const Propagator *propagator) const
Definition: MuonTrajectoryUpdator.cc:206
TrajectoryMeasurement::predictedState
TrajectoryStateOnSurface const & predictedState() const
Definition: TrajectoryMeasurement.h:174
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
MuonTrajectoryUpdator::useInvalidHits
bool useInvalidHits
Definition: MuonTrajectoryUpdator.h:150
MuonPatternRecoDumper
Definition: MuonPatternRecoDumper.h:18
MuonTrajectoryUpdator::theMaxChi2
double theMaxChi2
the max chi2 allowed
Definition: MuonTrajectoryUpdator.h:82
MuonTrajectoryUpdator::ZedComparatorInOut
Ordering along increasing zed (for CSC rechits)
Definition: MuonTrajectoryUpdator.h:110
MuonTransientTrackingRecHitBreaker::breakInSubRecHits
static TransientTrackingRecHit::ConstRecHitContainer breakInSubRecHits(TransientTrackingRecHit::ConstRecHitPointer, int granularity)
takes a muon rechit and returns its sub-rechits given a certain granularity
Definition: MuonTransientTrackingRecHitBreaker.cc:5
Chi2MeasurementEstimator_cfi.Chi2MeasurementEstimator
Chi2MeasurementEstimator
Definition: Chi2MeasurementEstimator_cfi.py:5
GeomDetEnumerators::CSC
Definition: GeomDetEnumerators.h:17
MuonTrajectoryUpdator::theEstimator
MeasurementEstimator * theEstimator
Definition: MuonTrajectoryUpdator.h:136
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MuonTrajectoryUpdator::theFirstTSOSFlag
bool theFirstTSOSFlag
Definition: MuonTrajectoryUpdator.h:145
TrajectoryStateUpdator::update
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
GeomDetEnumerators::DT
Definition: GeomDetEnumerators.h:18
KFUpdator.h
edm::ParameterSet
Definition: ParameterSet.h:47
MuonTrajectoryUpdator::sort
void sort(TransientTrackingRecHit::ConstRecHitContainer &, const DetLayer *)
Definition: MuonTrajectoryUpdator.cc:244
MuonTrajectoryUpdator::fitDirection
NavigationDirection fitDirection()
get the fit direction
Definition: MuonTrajectoryUpdator.h:60
TrackingRecHit::ConstRecHitContainer
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: TrackingRecHit.h:32
MuonTrajectoryUpdator::RadiusComparatorOutIn
Ordering along decreasing radius (for DT rechits)
Definition: MuonTrajectoryUpdator.h:102
MuonTrajectoryUpdator.h
TrackingRecHit::ConstRecHitPointer
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
Definition: TrackingRecHit.h:25
MuonPatternRecoDumper::dumpTSOS
std::string dumpTSOS(const TrajectoryStateOnSurface &tsos) const
Definition: MuonPatternRecoDumper.cc:56
MuonTrajectoryUpdator::theUpdator
TrajectoryStateUpdator * theUpdator
Definition: MuonTrajectoryUpdator.h:137
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
Trajectory::push
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
MuonSubdetId.h
TrajectoryStateOnSurface::rescaleError
void rescaleError(double factor)
Definition: TrajectoryStateOnSurface.h:82
TrajectoryMeasurement::recHit
ConstRecHitPointer const & recHit() const
Definition: TrajectoryMeasurement.h:190
Trajectory.h
MuonTrajectoryUpdator::estimator
const MeasurementEstimator * estimator() const
accasso at the propagator
Definition: MuonTrajectoryUpdator.h:53
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
NavigationDirection
NavigationDirection
Definition: NavigationDirection.h:4
outsideIn
Definition: NavigationDirection.h:4
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
MuonTrajectoryUpdator::theGranularity
int theGranularity
Definition: MuonTrajectoryUpdator.h:90
MuonTrajectoryUpdator::~MuonTrajectoryUpdator
virtual ~MuonTrajectoryUpdator()
Destructor.
Definition: MuonTrajectoryUpdator.cc:80
MuonTrajectoryUpdator::measurementUpdator
const TrajectoryStateUpdator * measurementUpdator() const
Definition: MuonTrajectoryUpdator.h:54
Trajectory
Definition: Trajectory.h:38
MuonSubdetId::RPC
static constexpr int RPC
Definition: MuonSubdetId.h:13
MuonTrajectoryUpdator::MuonTrajectoryUpdator
MuonTrajectoryUpdator(const edm::ParameterSet &par, NavigationDirection fitDirection)
Constructor from Propagator and Parameter set.
Definition: MuonTrajectoryUpdator.cc:42
DetLayer.h
GeomDetEnumerators::GEM
Definition: GeomDetEnumerators.h:21
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
insideOut
Definition: NavigationDirection.h:4
MuonTrajectoryUpdator::updateMeasurement
TrajectoryMeasurement updateMeasurement(const TrajectoryStateOnSurface &propagatedTSOS, const TrajectoryStateOnSurface &lastUpdatedTSOS, const TransientTrackingRecHit::ConstRecHitPointer &recHit, const double &chi2, const DetLayer *detLayer, const TrajectoryMeasurement *initialMeasurement)
Return the trajectory measurement. It handles both the fw and the bw propagation.
Definition: MuonTrajectoryUpdator.cc:221
DetId::Muon
Definition: DetId.h:26
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
ParameterSet.h
TrajectoryMeasurement::layer
const DetLayer * layer() const
Definition: TrajectoryMeasurement.h:194
GeomDetEnumerators::ME0
Definition: GeomDetEnumerators.h:22
MuonTransientTrackingRecHitBreaker.h
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
KFUpdator
Definition: KFUpdator.h:32
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:40