CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
CandKinematicVertexFitter Class Reference

#include <CandKinematicVertexFitter.h>

Public Types

typedef reco::Vertex::CovarianceMatrix CovarianceMatrix
 

Public Member Functions

 CandKinematicVertexFitter (const edm::ParameterSet &cfg)
 
 CandKinematicVertexFitter (const CandKinematicVertexFitter &o)
 
RefCountedKinematicParticle currentParticle () const
 
bool fit (const std::vector< RefCountedKinematicParticle > &tracks) const
 
void set (const MagneticField *bField)
 
void set (const ParticleDataTable *pdt)
 
void set (reco::VertexCompositeCandidate &) const
 

Private Member Functions

void fill (std::vector< RefCountedKinematicParticle > &, std::vector< reco::Candidate * > &, std::vector< reco::RecoCandidate::TrackType > &, reco::Candidate &) const
 

Private Attributes

const MagneticFieldbField_
 
double chi2_
 chi-sqared More...
 
CovarianceMatrix cov_
 covariance matrix (3x3) More...
 
KinematicParticleFactoryFromTransientTrack factory_
 particle factor More...
 
KinematicParticleVertexFitter fitter_
 fitter More...
 
boost::shared_ptr< std::vector< CandKinematicVertexFitter > > fitters_
 fitters used for recursive calls More...
 
double ndof_
 number of degrees of freedom More...
 
const ParticleDataTablepdt_
 
RefCountedKinematicTree tree_
 fit tree More...
 

Detailed Description

Definition at line 23 of file CandKinematicVertexFitter.h.

Member Typedef Documentation

Definition at line 25 of file CandKinematicVertexFitter.h.

Constructor & Destructor Documentation

CandKinematicVertexFitter::CandKinematicVertexFitter ( const edm::ParameterSet cfg)
inline

Definition at line 26 of file CandKinematicVertexFitter.h.

26  :
27  bField_(nullptr), pdt_(nullptr), fitter_(), fitters_(new std::vector<CandKinematicVertexFitter>) {
28  }
KinematicParticleVertexFitter fitter_
fitter
boost::shared_ptr< std::vector< CandKinematicVertexFitter > > fitters_
fitters used for recursive calls
const ParticleDataTable * pdt_
CandKinematicVertexFitter::CandKinematicVertexFitter ( const CandKinematicVertexFitter o)
inline

Definition at line 29 of file CandKinematicVertexFitter.h.

29  :
30  bField_(o.bField_), pdt_(o.pdt_), fitter_(), fitters_(new std::vector<CandKinematicVertexFitter>) {
31  }
KinematicParticleVertexFitter fitter_
fitter
boost::shared_ptr< std::vector< CandKinematicVertexFitter > > fitters_
fitters used for recursive calls
const ParticleDataTable * pdt_

Member Function Documentation

RefCountedKinematicParticle CandKinematicVertexFitter::currentParticle ( ) const
inline

Definition at line 36 of file CandKinematicVertexFitter.h.

36  {
37  tree_->movePointerToTheTop();
38  return tree_->currentParticle();
39  }
RefCountedKinematicTree tree_
fit tree
void CandKinematicVertexFitter::fill ( std::vector< RefCountedKinematicParticle > &  particles,
std::vector< reco::Candidate * > &  daughters,
std::vector< reco::RecoCandidate::TrackType > &  trackTypes,
reco::Candidate c 
) const
private

Definition at line 98 of file CandKinematicVertexFitter.cc.

References MessageLogger_cfi::cerr, vertices_cff::chi2, edmIntegrityCheck::d, data, reco::Candidate::daughter(), Exception, lumiContext::fill, KinematicParticleFitter::fit(), reco::Candidate::get(), edm::errors::InvalidReference, edm::Ref< C, T, F >::isNull(), ResonanceBuilder::mass, reco::Candidate::mass(), reco::LeafCandidate::massConstraint(), ndof, reco::RecoCandidate::noTrackType, reco::Candidate::numberOfDaughters(), reco::Candidate::pdgId(), reco::LeafCandidate::pdgId(), and reco::VertexCompositeCandidate::vertexChi2().

101  {
102  size_t nDau = c.numberOfDaughters();
103  // loop through CompositeCandidate daughters
104  for(unsigned int j = 0; j < nDau ; ++j) {
105  Candidate * d = c.daughter(j);
106  if(d == nullptr) {
107  ostringstream message;
108  message << "Can't access in write mode candidate daughters. "
109  << "pdgId = " << c.pdgId() << ".\n";
110  const Candidate * d1 = c.daughter(j);
111  if(d1 == nullptr)
112  message << "Null daughter also found in read-only mode\n";
113  else
114  message << "Daughter found in read-only mode with id: " << d1->pdgId() << "\n";
115  throw edm::Exception(edm::errors::InvalidReference) << message.str();
116  }
117  //check for a daughter which itself is a composite
118  if(d->numberOfDaughters() > 0) {
119  //try to cast to VertexCompositeCandiate
120  VertexCompositeCandidate * vtxDau = dynamic_cast<VertexCompositeCandidate*>(d);
121  if( vtxDau!=nullptr && vtxDau->vertexChi2()>0 ) {
122  // if VertexCompositeCandidate refit vtxDau via the set method
123  (*this).set(*vtxDau);
124  // if mass constraint is desired, do it here
125  if ( vtxDau->massConstraint() ) {
126  KinematicParticleFitter csFitter;
127  //get particle mass from pdg table via pdgid number
128  const ParticleData *data = pdt_->particle(vtxDau->pdgId());
129  ParticleMass mass = data->mass();
130  float mass_sigma = mass*0.000001; //needs a sigma for the fit
131  // create a KinematicConstraint and refit the tree with it
132  //KinematicConstraint * mass_c = new MassKinematicConstraint(mass,mass_sigma);
133  MassKinematicConstraint mkc(mass,mass_sigma);
134  KinematicConstraint * mass_c(&mkc);
135  tree_ = csFitter.fit(mass_c,tree_);
136  //CHECK THIS! the following works, but might not be safe
137  //tree_ = csFitter.fit(&(MassKinematicConstraint(mass,mass_sigma)),tree_);
138  }
139  // add the kinematic particle from the fit to particles
140  RefCountedKinematicParticle current = (*this).currentParticle();
141  particles.push_back(current);
142  daughters.push_back(d);
143  trackTypes.push_back(RecoCandidate::noTrackType);
144  } else {
145  fill(particles, daughters, trackTypes, *d);
146  }
147  } else {
148  //get track, make KinematicParticle and add to particles so it can be fit
149  TrackRef trk = d->get<TrackRef>();
151  if (!trk.isNull()){
152  TransientTrack trTrk(trk, bField_);
153  float chi2 = 0, ndof = 0;
154  ParticleMass mass = d->mass();
155  float sigma = mass *1.e-6;
156  particles.push_back(factory_.particle(trTrk, mass, chi2, ndof, sigma));
157  daughters.push_back(d);
158  trackTypes.push_back(type);
159  } else {
160  cerr << ">>> warning: candidate of type " << d->pdgId()
161  << " has no track reference." << endl;
162  }
163  }
164  }
165 }
type
Definition: HCALResponse.h:21
int pdgId() const final
PDG identifier.
RefCountedKinematicTree tree_
fit tree
double vertexChi2() const override
chi-squares
TrackType
track type
Definition: RecoCandidate.h:57
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
bool massConstraint() const final
do mass constraint?
double ParticleMass
Definition: ParticleMass.h:5
std::vector< RefCountedKinematicTree > fit(KinematicConstraint *cs, const std::vector< RefCountedKinematicTree > &trees) const
virtual int pdgId() const =0
PDG identifier.
HepPDT::ParticleData ParticleData
bool isNull() const
Checks for null.
Definition: Ref.h:250
virtual double mass() const =0
mass
void fill(std::vector< RefCountedKinematicParticle > &, std::vector< reco::Candidate * > &, std::vector< reco::RecoCandidate::TrackType > &, reco::Candidate &) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
KinematicParticleFactoryFromTransientTrack factory_
particle factor
T get() const
get a component
Definition: Candidate.h:217
RefCountedKinematicParticle particle(const reco::TransientTrack &initialTrack, const ParticleMass &massGuess, float chiSquared, float degreesOfFr, float &m_sigma) const
const ParticleDataTable * pdt_
virtual size_type numberOfDaughters() const =0
number of daughters
bool CandKinematicVertexFitter::fit ( const std::vector< RefCountedKinematicParticle > &  tracks) const

Definition at line 15 of file CandKinematicVertexFitter.cc.

References MessageLogger_cfi::cerr, and cppFunctionSkipper::exception.

Referenced by trackingPlots.Iteration::modules().

15  {
16  try {
18  } catch (std::exception & err) {
19  std::cerr << ">>> exception thrown by KinematicParticleVertexFitter:\n"
20  << err.what() << "\n"
21  << ">>> candidate not fitted to common vertex" << std::endl;
22  return false;
23  }
24  //check tree_ is valid here!
25  if (tree_->isValid())
26  return true;
27  else return false;
28 }
RefCountedKinematicTree tree_
fit tree
KinematicParticleVertexFitter fitter_
fitter
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &particles) const
void CandKinematicVertexFitter::set ( const MagneticField bField)
inline
void CandKinematicVertexFitter::set ( const ParticleDataTable pdt)
inline

Definition at line 33 of file CandKinematicVertexFitter.h.

References trackingPlots::fit, and l1t::tracks.

33 { pdt_ = pdt; }
const ParticleDataTable * pdt_
void CandKinematicVertexFitter::set ( reco::VertexCompositeCandidate c) const

Definition at line 31 of file CandKinematicVertexFitter.cc.

References GlobalErrorBase< T, ErrorWeightType >::cxx(), GlobalErrorBase< T, ErrorWeightType >::cyx(), GlobalErrorBase< T, ErrorWeightType >::cyy(), GlobalErrorBase< T, ErrorWeightType >::czx(), GlobalErrorBase< T, ErrorWeightType >::czy(), GlobalErrorBase< T, ErrorWeightType >::czz(), BPhysicsValidation_cfi::daughters, reco::Candidate::energy(), Exception, lumiContext::fill, trackingPlots::fit, reco::RecoCandidate::gsfTrackType, edm::errors::InvalidReference, reco::Candidate::longLived(), PV3DBase< T, PVType, FrameType >::mag(), ResonanceBuilder::mass, AlCaHLTBitMon_ParallelJobs::p, p3, HadronAndPartonSelector_cfi::particles, Scenarios_cff::scale, reco::VertexCompositeCandidate::setChi2AndNdof(), reco::VertexCompositeCandidate::setCovariance(), reco::Candidate::setP4(), reco::LeafCandidate::setP4(), reco::Candidate::setVertex(), reco::LeafCandidate::setVertex(), mathSSE::sqrt(), badGlobalMuonTaggersAOD_cff::vtx, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

31  {
32  if(bField_ == nullptr)
34  << "B-Field was not set up CandKinematicVertexFitter.\n"
35  << "the following method must be called before fitting a candidate:\n"
36  << " CandKinematicVertexFitter:.set( const MagneticField * )" << endl;
37  vector<RefCountedKinematicParticle> particles;
38  vector<Candidate *> daughters;
39  vector<RecoCandidate::TrackType> trackTypes;
40  // fill particles with KinematicParticles and daughters with Candidates of the daughters of c
41  fill(particles, daughters, trackTypes, c);
42  assert(particles.size() == daughters.size());
43 
44  // attempt to fit the KinematicParticles, particles
45  if(fit(particles)) {
46  // after the fit, tree_ contains the KinematicTree from the fit
47  tree_->movePointerToTheTop();
48  // set the kinematic properties of the daughters from the fit
49  RefCountedKinematicVertex vertex = tree_->currentDecayVertex();
50  if(vertex->vertexIsValid()) {
51  Candidate::Point vtx(vertex->position());
52  c.setVertex(vtx);
53  vector<RefCountedKinematicParticle> treeParticles = tree_->daughterParticles();
54  vector<RefCountedKinematicParticle>::const_iterator particleIt = treeParticles.begin();
55  vector<Candidate *>::const_iterator daughterIt = daughters.begin(), daughtersEnd = daughters.end();
56  vector<RecoCandidate::TrackType>::const_iterator trackTypeIt = trackTypes.begin();
57  Candidate::LorentzVector mp4(0, 0, 0, 0);
58  for(; daughterIt != daughtersEnd; ++ particleIt, ++ daughterIt, ++trackTypeIt) {
59  Candidate & daughter = * * daughterIt;
60  GlobalVector p3 = (*particleIt)->currentState().globalMomentum();
61  double px = p3.x(), py = p3.y(), pz = p3.z(), p = p3.mag();
62  double energy;
63 
64  if(!daughter.longLived()) daughter.setVertex(vtx);
65  double scale;
66  switch(*trackTypeIt) {
67  case RecoCandidate::gsfTrackType :
68  //gsf used for electron tracks
69  energy = daughter.energy();
70  scale = energy / p;
71  px *= scale; py *= scale; pz *= scale;
72  default:
73  double mass = (*particleIt)->currentState().mass();
74  energy = sqrt(p*p + mass*mass);
75  };
76  Candidate::LorentzVector dp4(px, py, pz, energy);
77  daughter.setP4(dp4);
78  mp4 += dp4;
79  }
80  c.setP4(mp4);
81  c.setChi2AndNdof(chi2_ = vertex->chiSquared(), ndof_ = vertex->degreesOfFreedom());
82  GlobalError err = vertex->error();
83  cov_(0,0) = err.cxx();
84  cov_(0,1) = err.cyx();
85  cov_(0,2) = err.czx();
86  cov_(1,2) = err.czy();
87  cov_(1,1) = err.cyy();
88  cov_(2,2) = err.czz();
90  }
91  } else {
92  c.setChi2AndNdof(chi2_ = -1, ndof_ = 0);
93  c.setCovariance(cov_ = CovarianceMatrix(ROOT::Math::SMatrixIdentity()));
94  }
95 }
RefCountedKinematicTree tree_
fit tree
virtual void setP4(const LorentzVector &p4)=0
set 4-momentum
double ndof_
number of degrees of freedom
T y() const
Definition: PV3DBase.h:63
virtual bool longLived() const =0
is long lived?
void setVertex(const Point &vertex) override
set vertex
bool fit(const std::vector< RefCountedKinematicParticle > &tracks) const
void setChi2AndNdof(double chi2, double ndof)
set chi2 and ndof
virtual double energy() const =0
energy
T mag() const
Definition: PV3DBase.h:67
T sqrt(T t)
Definition: SSEVec.h:18
virtual void setVertex(const Point &vertex)=0
set vertex
T z() const
Definition: PV3DBase.h:64
void setCovariance(const CovarianceMatrix &m)
set covariance matrix
reco::Vertex::CovarianceMatrix CovarianceMatrix
CovarianceMatrix cov_
covariance matrix (3x3)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
void fill(std::vector< RefCountedKinematicParticle > &, std::vector< reco::Candidate * > &, std::vector< reco::RecoCandidate::TrackType > &, reco::Candidate &) const
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
T x() const
Definition: PV3DBase.h:62
void setP4(const LorentzVector &p4) final
set 4-momentum
double p3[4]
Definition: TauolaWrapper.h:91

Member Data Documentation

const MagneticField* CandKinematicVertexFitter::bField_
private

Definition at line 41 of file CandKinematicVertexFitter.h.

double CandKinematicVertexFitter::chi2_
mutableprivate

chi-sqared

Definition at line 54 of file CandKinematicVertexFitter.h.

CovarianceMatrix CandKinematicVertexFitter::cov_
mutableprivate

covariance matrix (3x3)

Definition at line 58 of file CandKinematicVertexFitter.h.

KinematicParticleFactoryFromTransientTrack CandKinematicVertexFitter::factory_
private

particle factor

Definition at line 52 of file CandKinematicVertexFitter.h.

KinematicParticleVertexFitter CandKinematicVertexFitter::fitter_
private

fitter

Definition at line 48 of file CandKinematicVertexFitter.h.

boost::shared_ptr<std::vector<CandKinematicVertexFitter> > CandKinematicVertexFitter::fitters_
private

fitters used for recursive calls

Definition at line 60 of file CandKinematicVertexFitter.h.

double CandKinematicVertexFitter::ndof_
mutableprivate

number of degrees of freedom

Definition at line 56 of file CandKinematicVertexFitter.h.

const ParticleDataTable* CandKinematicVertexFitter::pdt_
private

Definition at line 42 of file CandKinematicVertexFitter.h.

RefCountedKinematicTree CandKinematicVertexFitter::tree_
mutableprivate

fit tree

Definition at line 50 of file CandKinematicVertexFitter.h.