CMS 3D CMS Logo

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