CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CandCommonVertexFitter.cc
Go to the documentation of this file.
5 #include <sstream>
6 using namespace reco;
7 using namespace std;
8 
10  if(bField_ == 0)
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());
20  TransientVertex vertex;
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; py *= scale; pz *= scale;
42  }
43  Candidate::LorentzVector dp4(px, py, pz, energy);
44  daughter.setP4(dp4);
45  mp4 += dp4;
46  }
47  c.setP4(mp4);
48  Vertex v = vertex;
49  c.setChi2AndNdof(chi2_ = v.chi2(), ndof_ = v.ndof());
50  v.fill(cov_);
51  c.setCovariance(cov_);
52  } else {
53  c.setChi2AndNdof(chi2_ = -1, ndof_ = 0);
54  c.setCovariance(cov_ = CovarianceMatrix(ROOT::Math::SMatrixIdentity()));
55  }
56 }
57 
58 void CandCommonVertexFitterBase::fill(vector<TransientTrack> & tracks,
59  vector<Candidate *> & daughters,
60  vector<RecoCandidate::TrackType> & trackTypes,
61  Candidate & c) const {
62  size_t nDau = c.numberOfDaughters();
63  for(unsigned int j = 0; j < nDau ; ++j) {
64  Candidate * d = c.daughter(j);
65  if(d == 0) {
66  ostringstream message;
67  message << "Can't access in write mode candidate daughters. "
68  << "pdgId = " << c.pdgId() << ".\n";
69  const Candidate * d1 = c.daughter(j);
70  if(d1 == 0)
71  message << "Null daughter also found in read-only mode\n";
72  else
73  message << "Daughter found in read-only mode with id: " << d1->pdgId() << "\n";
74  throw edm::Exception(edm::errors::InvalidReference) << message.str();
75  }
76  if(d->numberOfDaughters() > 0)
77  fill(tracks, daughters, trackTypes, * d);
78  else {
79  const Track * trk = d->get<const Track *>();
81  if(trk != 0) {
82  tracks.push_back(TransientTrack(* trk, bField_));
83  daughters.push_back(d);
84  trackTypes.push_back(type);
85  } else {
86  cerr << ">>> warning: candidate of type " << d->pdgId()
87  << " has no track reference." << endl;
88  }
89  }
90  }
91 }
double p() const
momentum vector magnitude
Definition: TrackBase.h:568
type
Definition: HCALResponse.h:21
virtual double energy() const =0
energy
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
string fill
Definition: lumiContext.py:319
virtual void setP4(const LorentzVector &p4)=0
set 4-momentum
TrackType
track type
Definition: RecoCandidate.h:57
virtual double mass() const =0
mass
assert(m_qm.get())
virtual void setP4(const LorentzVector &p4)
set 4-momentum
void fill(CovarianceMatrix &v) const
fill SMatrix
Definition: Vertex.cc:27
math::Error< 5 >::type CovarianceMatrix
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:580
tuple d
Definition: ztail.py:151
virtual size_type numberOfDaughters() const =0
number of daughters
void setChi2AndNdof(double chi2, double ndof)
set chi2 and ndof
T sqrt(T t)
Definition: SSEVec.h:48
virtual void setVertex(const Point &vertex)=0
set vertex
void setCovariance(const CovarianceMatrix &m)
set covariance matrix
double chi2() const
chi-squares
Definition: Vertex.h:95
int j
Definition: DBlmapReader.cc:9
virtual void setVertex(const Point &vertex)
set vertex
void fill(std::vector< reco::TransientTrack > &, std::vector< reco::Candidate * > &, std::vector< reco::RecoCandidate::TrackType > &, reco::Candidate &) const
double ndof() const
Definition: Vertex.h:102
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:592
virtual int pdgId() const =0
PDG identifier.
void set(const MagneticField *bField)
tuple tracks
Definition: testEve_cfg.py:39
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
T get() const
get a component
Definition: Candidate.h:217
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
std::vector< reco::TransientTrack > const & refittedTracks() const
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:586