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 CandKinematicVertexFitter &o)
 
 CandKinematicVertexFitter (const edm::ParameterSet &cfg)
 
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>) {}

◆ 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>) {}

Member Function Documentation

◆ currentParticle()

RefCountedKinematicParticle CandKinematicVertexFitter::currentParticle ( ) const
inline

Definition at line 35 of file CandKinematicVertexFitter.h.

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

References 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.

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 }

References c, EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, hltPixelTracks_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(), ndof, reco::RecoCandidate::noTrackType, ecalTrigSettings_cff::particles, reco::LeafCandidate::pdgId(), and reco::VertexCompositeCandidate::vertexChi2().

◆ fit()

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

Definition at line 15 of file CandKinematicVertexFitter.cc.

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 }

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

Referenced by trackingPlots.Iteration::modules().

◆ 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.

32 { pdt_ = pdt; }

References pdt_.

◆ set() [3/3]

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

Definition at line 32 of file CandKinematicVertexFitter.cc.

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 }

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

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().

Vector3DBase
Definition: Vector3DBase.h:8
reco::Candidate::energy
virtual double energy() const =0
energy
CandKinematicVertexFitter::CovarianceMatrix
reco::Vertex::CovarianceMatrix CovarianceMatrix
Definition: CandKinematicVertexFitter.h:26
reco::Candidate::setP4
virtual void setP4(const LorentzVector &p4)=0
set 4-momentum
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
edm::errors::InvalidReference
Definition: EDMException.h:39
ParticleMass
double ParticleMass
Definition: ParticleMass.h:4
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CandKinematicVertexFitter::fitter_
KinematicParticleVertexFitter fitter_
fitter
Definition: CandKinematicVertexFitter.h:48
cms::cuda::assert
assert(be >=bs)
MassKinematicConstraint
Definition: MassKinematicConstraint.h:17
ReferenceCountingPointer< KinematicParticle >
CandKinematicVertexFitter::ndof_
double ndof_
number of degrees of freedom
Definition: CandKinematicVertexFitter.h:56
reco::VertexCompositeCandidate
Definition: VertexCompositeCandidate.h:16
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
CandKinematicVertexFitter::fitters_
std::shared_ptr< std::vector< CandKinematicVertexFitter > > fitters_
fitters used for recursive calls
Definition: CandKinematicVertexFitter.h:60
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
edm::Ref< TrackCollection >
reco::RecoCandidate::TrackType
TrackType
track type
Definition: RecoCandidate.h:56
ndof
Definition: HIMultiTrackSelector.h:49
BPhysicsValidation_cfi.daughters
daughters
Definition: BPhysicsValidation_cfi.py:11
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
KinematicConstraint
Definition: KinematicConstraint.h:21
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
KinematicParticleFactoryFromTransientTrack::particle
RefCountedKinematicParticle particle(const reco::TransientTrack &initialTrack, const ParticleMass &massGuess, float chiSquared, float degreesOfFr, float &m_sigma) const
Definition: KinematicParticleFactoryFromTransientTrack.cc:15
KinematicParticleVertexFitter::fit
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &particles) const
Definition: KinematicParticleVertexFitter.cc:47
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
CandKinematicVertexFitter::fit
bool fit(const std::vector< RefCountedKinematicParticle > &tracks) const
Definition: CandKinematicVertexFitter.cc:15
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
CandKinematicVertexFitter::pdt_
const ParticleDataTable * pdt_
Definition: CandKinematicVertexFitter.h:42
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
reco::LeafCandidate::pdgId
int pdgId() const final
PDG identifier.
Definition: LeafCandidate.h:176
CandKinematicVertexFitter::tree_
RefCountedKinematicTree tree_
fit tree
Definition: CandKinematicVertexFitter.h:50
reco::Candidate::setVertex
virtual void setVertex(const Point &vertex)=0
set vertex
GlobalErrorBase< double, ErrorMatrixTag >
CandKinematicVertexFitter::fill
void fill(std::vector< RefCountedKinematicParticle > &, std::vector< reco::Candidate * > &, std::vector< reco::RecoCandidate::TrackType > &, reco::Candidate &) const
Definition: CandKinematicVertexFitter.cc:103
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
reco::LeafCandidate::massConstraint
bool massConstraint() const final
do mass constraint?
Definition: LeafCandidate.h:192
reco::Candidate
Definition: Candidate.h:27
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
KinematicParticleFitter::fit
std::vector< RefCountedKinematicTree > fit(KinematicConstraint *cs, const std::vector< RefCountedKinematicTree > &trees) const
Definition: KinematicParticleFitter.cc:20
CandKinematicVertexFitter::factory_
KinematicParticleFactoryFromTransientTrack factory_
particle factor
Definition: CandKinematicVertexFitter.h:52
reco::TransientTrack
Definition: TransientTrack.h:19
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
Calorimetry_cff.bField
bField
Definition: Calorimetry_cff.py:284
reco::VertexCompositeCandidate::vertexChi2
double vertexChi2() const override
chi-squares
Definition: VertexCompositeCandidate.h:42
Exception
Definition: hltDiff.cc:245
CandKinematicVertexFitter::cov_
CovarianceMatrix cov_
covariance matrix (3x3)
Definition: CandKinematicVertexFitter.h:58
reco::Candidate::longLived
virtual bool longLived() const =0
is long lived?
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
p3
double p3[4]
Definition: TauolaWrapper.h:91
CandKinematicVertexFitter::chi2_
double chi2_
chi-sqared
Definition: CandKinematicVertexFitter.h:54
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ztail.d
d
Definition: ztail.py:151
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
reco::Candidate::Point
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
d1
static constexpr float d1
Definition: L1EGammaCrystalsEmulatorProducer.cc:85
CandKinematicVertexFitter::bField_
const MagneticField * bField_
Definition: CandKinematicVertexFitter.h:41
KinematicParticleFitter
Definition: KinematicParticleFitter.h:23