CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonBestMeasurementFinder.cc
Go to the documentation of this file.
1 
15 
18 
23 
25 
26 
27 using namespace std;
28 
30 
31  theEstimator = new Chi2MeasurementEstimator(100000.);
32 }
33 
35  delete theEstimator;
36 }
37 
39 MuonBestMeasurementFinder::findBestMeasurement(std::vector<TrajectoryMeasurement>& measC,
40  const Propagator* propagator){
41 
42  const std::string metname = "Muon|RecoMuon|MuonBestMeasurementFinder";
43 
44  TMContainer validMeasurements;
45 
46  TrajectoryMeasurement* bestMeasurement=0;
47 
48  // consider only valid TM
49  int NumValidMeas=0;
50  for ( vector<TrajectoryMeasurement>::iterator measurement = measC.begin();
51  measurement!= measC.end(); ++measurement ) {
52  if ((*measurement).recHit()->isValid()) {
53  ++NumValidMeas;
54  bestMeasurement = &(*measurement);
55  validMeasurements.push_back( &(*measurement) );
56  }
57  }
58 
59  // If we have just one (or zero) valid meas, return it at once
60  // (or return null measurement)
61  if(NumValidMeas<=1) {
62  LogTrace(metname) << "MuonBestMeasurement: just " << NumValidMeas
63  << " valid measurement ";
64  return bestMeasurement;
65  }
66 
67  TMIterator measurement;
68  double minChi2PerNDoF=1.E6;
69 
70  // if there are more than one valid measurement, then sort them.
71  for ( measurement = validMeasurements.begin(); measurement!= validMeasurements.end(); measurement++ ) {
72 
73  TransientTrackingRecHit::ConstRecHitPointer muonRecHit = (*measurement)->recHit();
74 
75  // FIXME!! FIXME !! FIXME !!
76  pair<double,int> chi2Info = lookAtSubRecHits(*measurement, propagator);
77 
78  double chi2PerNDoF = chi2Info.first/chi2Info.second;
79  LogTrace(metname) << " The measurement has a chi2/npts " << chi2PerNDoF << " with dof = " << chi2Info.second
80  << " \n Till now the best chi2 is " << minChi2PerNDoF;
81 
82  if ( chi2PerNDoF && chi2PerNDoF<minChi2PerNDoF ) {
83  minChi2PerNDoF = chi2PerNDoF;
84  bestMeasurement = *measurement;
85  }
86 
87  }
88  LogTrace(metname)<<"The final best chi2 is "<<minChi2PerNDoF<<endl;
89  return bestMeasurement;
90 }
91 
92 
94  const Propagator* propagator){
95 
96  const std::string metname = "Muon|RecoMuon|MuonBestMeasurementFinder";
97 
98  unsigned int npts=0;
99  // unused double thisChi2 = 0.;
100 
101  TransientTrackingRecHit::ConstRecHitPointer muonRecHit = measurement->recHit();
102  TrajectoryStateOnSurface predState = measurement->predictedState(); // temporarily introduced by DT
103  std::pair<bool, double> sing_chi2 = estimator()->estimate( predState, *(muonRecHit.get())); // temporarily introduced by DT
104  npts = 1; // temporarily introduced by DT
105  std::pair<double, int> result = pair<double, int>(sing_chi2.second, npts); // temporarily introduced by DT
106 
107 // // ask for the 2D-segments/2D-rechit // temporarily excluded by DT
108 // TransientTrackingRecHit::ConstRecHitContainer rhits_list = muonRecHit->transientHits();
109 
110 // LogTrace(metname)<<"Number of rechits in the measurement rechit: "<<rhits_list.size()<<endl;
111 
112 // // loop over them
113 // for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit = rhits_list.begin();
114 // rhit!= rhits_list.end(); ++rhit)
115 // if ((*rhit)->isValid() ) {
116 // LogTrace(metname)<<"Rechit dimension: "<<(*rhit)->dimension()<<endl;
117 // npts+=(*rhit)->dimension();
118 
119 // TrajectoryStateOnSurface predState;
120 
121 // if (!( (*rhit)->geographicalId() == muonRecHit->geographicalId() ) ){
122 // predState = propagator->propagate(*measurement->predictedState().freeState(),
123 // (*rhit)->det()->surface());
124 // }
125 // else predState = measurement->predictedState();
126 
127 // if ( predState.isValid() ) {
128 // std::pair<bool,double> sing_chi2 = estimator()->estimate( predState, *((*rhit).get()));
129 // thisChi2 += sing_chi2.second ;
130 // LogTrace(metname) << " single incremental chi2: " << sing_chi2.second;
131 // }
132 // }
133 
134 // pair<double,int> result = pair<double,int>(thisChi2,npts);
135  return result;
136 }
virtual ~MuonBestMeasurementFinder()
Destructor.
TrajectoryStateOnSurface const & predictedState() const
ConstRecHitPointer const & recHit() const
const std::string metname
tuple result
Definition: mps_fire.py:84
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
std::vector< TrajectoryMeasurement * > TMContainer
#define LogTrace(id)
TrajectoryMeasurement * findBestMeasurement(std::vector< TrajectoryMeasurement > &measC, const Propagator *propagator)
return the Tm with the best chi2: no cut applied.
std::pair< double, int > lookAtSubRecHits(TrajectoryMeasurement *measurement, const Propagator *propagator)