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