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...
 
std::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 24 of file CandKinematicVertexFitter.h.

Member Typedef Documentation

◆ CovarianceMatrix

Definition at line 26 of file CandKinematicVertexFitter.h.

Constructor & Destructor Documentation

◆ CandKinematicVertexFitter() [1/2]

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

Definition at line 27 of file CandKinematicVertexFitter.h.

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

◆ CandKinematicVertexFitter() [2/2]

CandKinematicVertexFitter::CandKinematicVertexFitter ( const CandKinematicVertexFitter o)
inline

Definition at line 29 of file CandKinematicVertexFitter.h.

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

Member Function Documentation

◆ currentParticle()

RefCountedKinematicParticle CandKinematicVertexFitter::currentParticle ( ) const
inline

Definition at line 35 of file CandKinematicVertexFitter.h.

References tree_.

35  {
36  tree_->movePointerToTheTop();
37  return tree_->currentParticle();
38  }
RefCountedKinematicTree tree_
fit tree

◆ fill()

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 103 of file CandKinematicVertexFitter.cc.

References HltBtagPostValidation_cff::c, DMR_cfg::cerr, nano_mu_local_reco_cff::chi2, ztail::d, d1, data, BPhysicsValidation_cfi::daughters, Exception, ntuplemaker::fill, KinematicParticleFitter::fit(), edm::errors::InvalidReference, edm::Ref< C, T, F >::isNull(), dqmiolumiharvest::j, EgHLTOffHistBins_cfi::mass, reco::LeafCandidate::massConstraint(), PixelVertexMonitor_cff::ndof, reco::RecoCandidate::noTrackType, ecalTrigSettings_cff::particles, reco::LeafCandidate::pdgId(), and reco::VertexCompositeCandidate::vertexChi2().

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

◆ fit()

bool CandKinematicVertexFitter::fit ( const std::vector< RefCountedKinematicParticle > &  tracks) const

Definition at line 15 of file CandKinematicVertexFitter.cc.

References DMR_cfg::cerr, submitPVResolutionJobs::err, cppFunctionSkipper::exception, and ecalTrigSettings_cff::particles.

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
28  return false;
29 }
RefCountedKinematicTree tree_
fit tree
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &particles) const
KinematicParticleVertexFitter fitter_
fitter

◆ set() [1/3]

void CandKinematicVertexFitter::set ( const MagneticField bField)
inline

◆ set() [2/3]

void CandKinematicVertexFitter::set ( const ParticleDataTable pdt)
inline

Definition at line 32 of file CandKinematicVertexFitter.h.

References pdt_.

32 { pdt_ = pdt; }
const ParticleDataTable * pdt_

◆ set() [3/3]

void CandKinematicVertexFitter::set ( reco::VertexCompositeCandidate c) const

Definition at line 32 of file CandKinematicVertexFitter.cc.

References cms::cuda::assert(), HltBtagPostValidation_cff::c, BPhysicsValidation_cfi::daughters, hcalRecHitTable_cff::energy, reco::Candidate::energy(), submitPVResolutionJobs::err, Exception, ntuplemaker::fill, l1tPhase2CaloJetEmulator_cfi::fit, reco::RecoCandidate::gsfTrackType, edm::errors::InvalidReference, reco::Candidate::longLived(), EgHLTOffHistBins_cfi::mass, AlCaHLTBitMon_ParallelJobs::p, chargedHadronTrackResolutionFilter_cfi::p3, ecalTrigSettings_cff::particles, multPhiCorr_741_25nsDY_cfi::px, multPhiCorr_741_25nsDY_cfi::py, l1tEGammaCrystalsEmulatorProducer_cfi::scale, reco::Candidate::setP4(), reco::Candidate::setVertex(), mathSSE::sqrt(), bphysicsOniaDQM_cfi::vertex, and L1BJetProducer_cff::vtx.

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

Member Data Documentation

◆ bField_

const MagneticField* CandKinematicVertexFitter::bField_
private

Definition at line 41 of file CandKinematicVertexFitter.h.

Referenced by set().

◆ chi2_

double CandKinematicVertexFitter::chi2_
mutableprivate

chi-sqared

Definition at line 54 of file CandKinematicVertexFitter.h.

◆ cov_

CovarianceMatrix CandKinematicVertexFitter::cov_
mutableprivate

covariance matrix (3x3)

Definition at line 58 of file CandKinematicVertexFitter.h.

◆ factory_

KinematicParticleFactoryFromTransientTrack CandKinematicVertexFitter::factory_
private

particle factor

Definition at line 52 of file CandKinematicVertexFitter.h.

◆ fitter_

KinematicParticleVertexFitter CandKinematicVertexFitter::fitter_
private

fitter

Definition at line 48 of file CandKinematicVertexFitter.h.

◆ fitters_

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

fitters used for recursive calls

Definition at line 60 of file CandKinematicVertexFitter.h.

◆ ndof_

double CandKinematicVertexFitter::ndof_
mutableprivate

number of degrees of freedom

Definition at line 56 of file CandKinematicVertexFitter.h.

◆ pdt_

const ParticleDataTable* CandKinematicVertexFitter::pdt_
private

Definition at line 42 of file CandKinematicVertexFitter.h.

Referenced by set().

◆ tree_

RefCountedKinematicTree CandKinematicVertexFitter::tree_
mutableprivate

fit tree

Definition at line 50 of file CandKinematicVertexFitter.h.

Referenced by currentParticle().