CMS 3D CMS Logo

CandCommonVertexFitter.cc
Go to the documentation of this file.
5 #include <sstream>
6 using namespace reco;
7 using namespace std;
8 
10  if (bField_ == nullptr)
12  << "B-Field was not set up CandCommonVertexFitter.\n"
13  << "the following method must be called before fitting a candidate:\n"
14  << " CandCommonVertexFitter:.set( const MagneticField * )" << endl;
15  vector<TransientTrack> tracks;
16  vector<Candidate *> daughters;
17  vector<RecoCandidate::TrackType> trackTypes;
18  fill(tracks, daughters, trackTypes, c);
19  assert(tracks.size() == daughters.size());
21  if (fit(vertex, tracks)) {
22  tracks = vertex.refittedTracks();
23  Candidate::Point vtx(vertex.position());
24  c.setVertex(vtx);
25  vector<TransientTrack>::const_iterator trackIt = tracks.begin(), tracksEnd = tracks.end();
26  vector<Candidate *>::const_iterator daughterIt = daughters.begin();
27  vector<RecoCandidate::TrackType>::const_iterator trackTypeIt = trackTypes.begin();
28  Candidate::LorentzVector mp4(0, 0, 0, 0);
29  for (; trackIt != tracksEnd; ++trackIt, ++daughterIt, ++trackTypeIt) {
30  const Track &track = trackIt->track();
31  Candidate &daughter = **daughterIt;
32  double px = track.px(), py = track.py(), pz = track.pz(), p = track.p();
33  double energy;
34  daughter.setVertex(vtx);
35  if (*trackTypeIt == RecoCandidate::recoTrackType) {
36  double mass = daughter.mass();
37  energy = sqrt(p * p + mass * mass);
38  } else {
39  energy = daughter.energy();
40  double scale = energy / p;
41  px *= scale;
42  py *= scale;
43  pz *= scale;
44  }
46  daughter.setP4(dp4);
47  mp4 += dp4;
48  }
49  c.setP4(mp4);
50  Vertex v = vertex;
51  c.setChi2AndNdof(chi2_ = v.chi2(), ndof_ = v.ndof());
52  v.fill(cov_);
53  c.setCovariance(cov_);
54  } else {
55  c.setChi2AndNdof(chi2_ = -1, ndof_ = 0);
56  c.setCovariance(cov_ = CovarianceMatrix(ROOT::Math::SMatrixIdentity()));
57  }
58 }
59 
60 void CandCommonVertexFitterBase::fill(vector<TransientTrack> &tracks,
61  vector<Candidate *> &daughters,
62  vector<RecoCandidate::TrackType> &trackTypes,
63  Candidate &c) const {
64  size_t nDau = c.numberOfDaughters();
65  for (unsigned int j = 0; j < nDau; ++j) {
66  Candidate *d = c.daughter(j);
67  if (d == nullptr) {
68  ostringstream message;
69  message << "Can't access in write mode candidate daughters. "
70  << "pdgId = " << c.pdgId() << ".\n";
71  const Candidate *d1 = c.daughter(j);
72  if (d1 == nullptr)
73  message << "Null daughter also found in read-only mode\n";
74  else
75  message << "Daughter found in read-only mode with id: " << d1->pdgId() << "\n";
76  throw edm::Exception(edm::errors::InvalidReference) << message.str();
77  }
78  if (d->numberOfDaughters() > 0)
79  fill(tracks, daughters, trackTypes, *d);
80  else {
81  const Track *trk = d->get<const Track *>();
83  if (trk != nullptr) {
84  tracks.push_back(TransientTrack(*trk, bField_));
85  daughters.push_back(d);
86  trackTypes.push_back(type);
87  } else {
88  cerr << ">>> warning: candidate of type " << d->pdgId() << " has no track reference." << endl;
89  }
90  }
91  }
92 }
reco::Candidate::energy
virtual double energy() const =0
energy
CandCommonVertexFitter.h
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
reco::Candidate::setP4
virtual void setP4(const LorentzVector &p4)=0
set 4-momentum
edm::errors::InvalidReference
Definition: EDMException.h:39
reco::Candidate::mass
virtual double mass() const =0
mass
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cms::cuda::assert
assert(be >=bs)
L1TowerCalibrationProducer_cfi.fit
fit
Definition: L1TowerCalibrationProducer_cfi.py:36
reco::VertexCompositeCandidate
Definition: VertexCompositeCandidate.h:16
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
findQualityFiles.v
v
Definition: findQualityFiles.py:179
reco::RecoCandidate::TrackType
TrackType
track type
Definition: RecoCandidate.h:56
CandCommonVertexFitterBase::fill
void fill(std::vector< reco::TransientTrack > &, std::vector< reco::Candidate * > &, std::vector< reco::RecoCandidate::TrackType > &, reco::Candidate &) const
Definition: CandCommonVertexFitter.cc:60
CovarianceMatrix
math::Error< 5 >::type CovarianceMatrix
Definition: SeedToTrackProducer.h:48
EDMException.h
BPhysicsValidation_cfi.daughters
daughters
Definition: BPhysicsValidation_cfi.py:11
VertexCompositeCandidate.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::Track
Definition: Track.h:27
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
badGlobalMuonTaggersAOD_cff.vtx
vtx
Definition: badGlobalMuonTaggersAOD_cff.py:5
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
Scenarios_cff.scale
scale
Definition: Scenarios_cff.py:2186
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
GsfTrack.h
reco::Candidate::setVertex
virtual void setVertex(const Point &vertex)=0
set vertex
TransientVertex
Definition: TransientVertex.h:18
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
reco::RecoCandidate::recoTrackType
Definition: RecoCandidate.h:56
reco::Candidate
Definition: Candidate.h:27
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
type
type
Definition: HCALResponse.h:21
std
Definition: JetResolutionObject.h:76
reco::TransientTrack
Definition: TransientTrack.h:19
Exception
Definition: hltDiff.cc:246
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
CandCommonVertexFitterBase::set
void set(const MagneticField *bField)
Definition: CandCommonVertexFitter.h:24
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
ztail.d
d
Definition: ztail.py:151
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
reco::Candidate::Point
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
d1
static constexpr float d1
Definition: L1EGammaCrystalsEmulatorProducer.cc:85
reco::Vertex
Definition: Vertex.h:35