CMS 3D CMS Logo

ConversionVertexFinder.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
4 // Framework
7 //
8 //Kinematic constraint vertex fitter
10 
12 
13 // new templated one
16 
17 
18 
19 //
20 
21 
22 
23 
24 
26  conf_(config)
27 {
28  LogDebug("ConversionVertexFinder") << "ConversionVertexFinder CTOR " << "\n";
29  maxDelta_ = conf_.getParameter<double>("maxDelta");
30  maxReducedChiSq_ = conf_.getParameter<double>("maxReducedChiSq");
31  minChiSqImprovement_ = conf_.getParameter<double>("minChiSqImprovement");
32  maxNbrOfIterations_ = conf_.getParameter<int>("maxNbrOfIterations");
34  kcvFitter_->setParameters(conf_);
35 
36 }
37 
39 
40  LogDebug("ConversionVertexFinder") << "ConversionVertexFinder DTOR " << "\n";
41  delete kcvFitter_;
42 
43 }
44 
45 bool ConversionVertexFinder::run( const std::vector<reco::TransientTrack>& _pair, reco::Vertex& the_vertex) {
46  std::vector<reco::TransientTrack> pair = _pair;
47  bool found= false;
48 
49  if ( pair.size() < 2) return found;
50 
51  float sigma = 0.00000001;
52  float chi = 0.;
53  float ndf = 0.;
54  float mass = 0.000511;
55 
56 
58 
59  std::vector<RefCountedKinematicParticle> particles;
60 
61  particles.push_back(pFactory.particle (pair[0],mass,chi,ndf,sigma,*pair[0].innermostMeasurementState().freeState()));
62  particles.push_back(pFactory.particle (pair[1],mass,chi,ndf,sigma,*pair[1].innermostMeasurementState().freeState()));
63 
64 
65 #ifdef OldKineFit
67 
68  RefCountedKinematicTree myTree = kcvFitter_->fit(particles, &constr);
69 #else
70 
71  // bizzare way to the get the field...
72  const MagneticField* mf = pair[0].field();
73 
76  kcvFitter.setParameters(conf_);
77  RefCountedKinematicTree myTree = kcvFitter.fit(particles, &constr);
78 
79 #ifdef KineFitDebug
80 
82 
83  RefCountedKinematicTree oldTree = kcvFitter_->fit(particles, &oldconstr);
84 
85 
86  if( oldTree->isValid() ) {
87  std::cout << "old " << kcvFitter_->getNit() << std::endl;
88  RefCountedKinematicVertex gamma_dec_vertex = oldTree->currentDecayVertex();
89  if( gamma_dec_vertex->vertexIsValid())
90  std::cout << gamma_dec_vertex->chiSquared() << " " << gamma_dec_vertex->degreesOfFreedom() << std::endl;
91  std::cout << oldTree->currentParticle()->currentState().globalMomentum() <<
92  oldTree->currentParticle()->currentState().globalPosition()<< std::endl;
93  std::vector<RefCountedKinematicParticle> fStates=oldTree->finalStateParticles();
94  for (unsigned int kk=0; kk<fStates.size(); kk++) {
95  std::cout << fStates[kk]->currentState().globalMomentum() <<
96  fStates[kk]->currentState().globalPosition() << std::endl;
97  std::cout << fStates[kk]->currentState().kinematicParametersError().matrix()<<std::endl;
98  }
99  } else std::cout << "old invalid " << kcvFitter_->getNit() << std::endl;
100 
101  if( myTree->isValid() ) {
102  std::cout << "new " << kcvFitter.getNit() << std::endl;
103  RefCountedKinematicVertex gamma_dec_vertex = myTree->currentDecayVertex();
104  if( gamma_dec_vertex->vertexIsValid())
105  std::cout << gamma_dec_vertex->chiSquared() << " " << gamma_dec_vertex->degreesOfFreedom() << std::endl;
106  std::cout << myTree->currentParticle()->currentState().globalMomentum() <<
107  myTree->currentParticle()->currentState().globalPosition()<< std::endl;
108  std::vector<RefCountedKinematicParticle> fStates=myTree->finalStateParticles();
109  for (unsigned int kk=0; kk<fStates.size(); kk++) {
110  std::cout << fStates[kk]->currentState().globalMomentum() <<
111  fStates[kk]->currentState().globalPosition() << std::endl;
112  std::cout << fStates[kk]->currentState().kinematicParametersError().matrix()<<std::endl;
113  }
114  } else std::cout << "new invalid " << kcvFitter.getNit() << std::endl;
115 
116 #endif // TemplateKineFitDebug
117 
118 #endif
119 
120  if( myTree->isValid() ) {
121  myTree->movePointerToTheTop();
122  RefCountedKinematicParticle the_photon = myTree->currentParticle();
123  if (the_photon->currentState().isValid()){
124  //const ParticleMass photon_mass = the_photon->currentState().mass();
125  RefCountedKinematicVertex gamma_dec_vertex;
126  gamma_dec_vertex = myTree->currentDecayVertex();
127  if( gamma_dec_vertex->vertexIsValid() ){
128  const float chi2Prob = ChiSquaredProbability(gamma_dec_vertex->chiSquared(), gamma_dec_vertex->degreesOfFreedom());
129  if (chi2Prob>0.){// no longer cut here, only ask positive probability here
130  //const math::XYZPoint vtxPos(gamma_dec_vertex->position());
131  the_vertex = *gamma_dec_vertex;
132  found = true;
133  }
134  }
135  }
136  }
137 
138  return found;
139 }
140 
141 
142 TransientVertex ConversionVertexFinder::run(const std::vector<reco::TransientTrack>& pair) {
143  LogDebug("ConversionVertexFinder") << "ConversionVertexFinder run pair size " << pair.size() << "\n";
144 
145  //for ( std::vector<reco::TransientTrack>::const_iterator iTk=pair.begin(); iTk!=pair.end(); ++iTk) {
146  // LogDebug("ConversionVertexFinder") << " ConversionVertexFinder Tracks in the pair charge " << iTk->charge() << " Num of RecHits " << iTk->recHitsSize() << " inner momentum " << iTk->track().innerMomentum() << "\n";
147  //}
148 
149 
150  reco::Vertex theVertex;
151  KalmanVertexFitter fitter(true);
152  TransientVertex transientVtx;
153 
154  const std::string metname = "ConversionVertexFinder| ConversionVertexFinder";
155  try{
156 
157  transientVtx = fitter.vertex(pair);
158 
159  } catch ( cms::Exception& e ) {
160 
161 
162  edm::LogWarning(metname) << "cms::Exception caught in ConversionVertexFinder::run\n"
163  << e.explainSelf();
164 
165  }
166 
167 
168  return transientVtx;
169 
170 
171 
172 }
173 
#define LogDebug(id)
ConversionVertexFinder(const edm::ParameterSet &config)
T getParameter(std::string const &) const
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)
TransientVertex run(const std::vector< reco::TransientTrack > &pair)
const std::string metname
virtual std::string explainSelf() const
Definition: Exception.cc:108
Definition: config.py:1
void setParameters(const edm::ParameterSet &pSet)
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
float ChiSquaredProbability(double chiSquared, double nrDOF)
KinematicConstrainedVertexFitter * kcvFitter_
RefCountedKinematicParticle particle(const reco::TransientTrack &initialTrack, const ParticleMass &massGuess, float chiSquared, float degreesOfFr, float &m_sigma) const
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)