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 }
Ordering along decreasing radius (for DT rechits)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T perp() const
Definition: PV3DBase.h:69
TrajectoryStateOnSurface const & predictedState() const
std::string dumpTSOS(const TrajectoryStateOnSurface &tsos) const
const std::string metname
void makeFirstTime()
reset the theFirstTSOSFlag
Ordering along increasing zed (for CSC rechits)
NavigationDirection fitDirection()
get the fit direction
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
virtual ~MuonTrajectoryUpdator()
Destructor.
Log< level::Error, false > LogError
MuonTrajectoryUpdator(const edm::ParameterSet &par, NavigationDirection fitDirection)
Constructor from Propagator and Parameter set.
#define LogTrace(id)
static TransientTrackingRecHit::ConstRecHitContainer breakInSubRecHits(TransientTrackingRecHit::ConstRecHitPointer, int granularity)
takes a muon rechit and returns its sub-rechits given a certain granularity
void sort(TransientTrackingRecHit::ConstRecHitContainer &, const DetLayer *)
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
GlobalPoint globalPosition() const
std::shared_ptr< MuonTransientTrackingRecHit > MuonRecHitPointer
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
const TrajectoryStateUpdator * measurementUpdator() const
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. ...
double theMaxChi2
the max chi2 allowed
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
std::vector< ConstRecHitPointer > ConstRecHitContainer
Ordering along increasing radius (for DT rechits)
GlobalVector globalDirection() const
static constexpr int RPC
Definition: MuonSubdetId.h:13
TrajectoryStateUpdator * theUpdator
HLT enums.
const MeasurementEstimator * estimator() const
accasso at the propagator
virtual std::pair< bool, TrajectoryStateOnSurface > update(const TrajectoryMeasurement *measurement, Trajectory &trajectory, const Propagator *propagator)
update the Trajectory with the TrajectoryMeasurement
TrajectoryStateOnSurface propagateState(const TrajectoryStateOnSurface &state, const TrajectoryMeasurement *measurement, const TransientTrackingRecHit::ConstRecHitPointer &current, const Propagator *propagator) const
static MuonRecHitPointer specificBuild(const GeomDet *geom, const TrackingRecHit *rh)
Ordering along decreasing zed (for CSC rechits)
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
const DetLayer * layer() const
def move(src, dest)
Definition: eostools.py:511
ConstRecHitPointer const & recHit() const
MeasurementEstimator * theEstimator