CMS 3D CMS Logo

PFDisplacedVertex.cc
Go to the documentation of this file.
2 
3 #include "TMath.h"
4 
5 using namespace std;
6 using namespace reco;
7 
8 PFDisplacedVertex::PFDisplacedVertex() : Vertex(), vertexType_(ANY), primaryDirection_(0, 0, 0) {}
9 
10 PFDisplacedVertex::PFDisplacedVertex(Vertex& v) : Vertex(v), vertexType_(ANY), primaryDirection_(0, 0, 0) {}
11 
13  const Track& refTrack,
14  const PFTrackHitFullInfo& hitInfo,
16  float w) {
17  add(r, refTrack, w);
18  trackTypes_.push_back(trackType);
19  trackHitFullInfos_.push_back(hitInfo);
20 }
21 
23  removeTracks();
24  trackTypes_.clear();
25  trackHitFullInfos_.clear();
26 }
27 
29  vector<VertexTrackType>::const_iterator iter = find(trackTypes_.begin(), trackTypes_.end(), T);
30  return (iter != trackTypes_.end());
31 }
32 
34  return count(trackTypes_.begin(), trackTypes_.end(), T);
35 }
36 
37 const size_t PFDisplacedVertex::trackPosition(const reco::TrackBaseRef& originalTrack) const {
38  size_t pos = -1;
39 
41 
42  std::vector<Track> refitTrks = refittedTracks();
43  for (size_t i = 0; i < refitTrks.size(); i++) {
44  if (fabs(refitTrks[i].pt() - refittedTrack.pt()) < 1.e-5) {
45  pos = i;
46  continue;
47  }
48  }
49  // cout << "pos = " << pos << endl;
50 
51  return pos;
52 }
53 
56  math::XYZVector vtx(pvtx.x(), pvtx.y(), pvtx.z());
57 
59  primaryDirection_ /= (sqrt(primaryDirection_.Mag2()) + 1e-10);
60 }
61 
63  switch (vertexType_) {
64  case ANY:
65  return "ANY";
66  case FAKE:
67  return "FAKE";
68  case LOOPER:
69  return "LOOPER";
70  case NUCL:
71  return "NUCL";
72  case NUCL_LOOSE:
73  return "NUCL_LOOSE";
74  case NUCL_KINK:
75  return "NUCL_KINK";
76  case CONVERSION:
77  return "CONVERSION";
78  case CONVERSION_LOOSE:
79  return "CONVERSION_LOOSE";
80  case CONVERTED_BREMM:
81  return "CONVERTED_BREMM";
82  case K0_DECAY:
83  return "K0_DECAY";
84  case LAMBDA_DECAY:
85  return "LAMBDA_DECAY";
86  case LAMBDABAR_DECAY:
87  return "LAMBDABAR_DECAY";
88  case KPLUS_DECAY:
89  return "KPLUS_DECAY";
90  case KMINUS_DECAY:
91  return "KMINUS_DECAY";
92  case KPLUS_DECAY_LOOSE:
93  return "KPLUS_DECAY_LOOSE";
94  case KMINUS_DECAY_LOOSE:
95  return "KMINUS_DECAY_LOOSE";
96  case BSM_VERTEX:
97  return "BSM_VERTEX";
98  default:
99  return "?";
100  }
101  return "?";
102 }
103 
105  VertexTrackType T,
106  bool useRefitted,
107  double mass) const {
108  M_Hypo mHypo = M_CUSTOM;
109 
110  if (massHypo.find("PI") != string::npos)
111  mHypo = M_PION;
112  else if (massHypo.find("KAON") != string::npos)
113  mHypo = M_KAON;
114  else if (massHypo.find("LAMBDA") != string::npos)
115  mHypo = M_LAMBDA;
116  else if (massHypo.find("MASSLESS") != string::npos)
117  mHypo = M_MASSLESS;
118  else if (massHypo.find("CUSTOM") != string::npos)
119  mHypo = M_CUSTOM;
120 
121  return momentum(mHypo, T, useRefitted, mass);
122 }
123 
126  bool useRefitted,
127  double mass) const {
128  const double m2 = getMass2(massHypo, mass);
129 
131 
132  for (size_t i = 0; i < tracksSize(); i++) {
133  bool bType = (trackTypes_[i] == T);
134  if (T == T_TO_VERTEX || T == T_MERGED)
135  bType = (trackTypes_[i] == T_TO_VERTEX || trackTypes_[i] == T_MERGED);
136 
137  if (bType) {
138  if (!useRefitted) {
140 
141  double p2 = trackRef->momentum().Mag2();
143  trackRef->momentum().x(), trackRef->momentum().y(), trackRef->momentum().z(), sqrt(m2 + p2));
144  } else {
145  // cout << "m2 " << m2 << endl;
146 
147  double p2 = refittedTracks()[i].momentum().Mag2();
149  refittedTracks()[i].momentum().y(),
150  refittedTracks()[i].momentum().z(),
151  sqrt(m2 + p2));
152  }
153  }
154  }
155 
156  return P;
157 }
158 
160  int charge = 0;
161 
162  for (size_t i = 0; i < tracksSize(); i++) {
163  if (trackTypes_[i] == T_TO_VERTEX)
164  charge += refittedTracks()[i].charge();
165  else if (trackTypes_[i] == T_FROM_VERTEX)
166  charge -= refittedTracks()[i].charge();
167  }
168 
169  return charge;
170 }
171 
172 const double PFDisplacedVertex::angle_io() const {
173  math::XYZTLorentzVector momentumSec = secondaryMomentum((string) "PI", true);
174 
175  math::XYZVector p_out = momentumSec.Vect();
176 
178 
179  if (p_in.Mag2() < 1e-10)
180  return -1;
181  return acos(p_in.Dot(p_out) / sqrt(p_in.Mag2() * p_out.Mag2())) / TMath::Pi() * 180.0;
182 }
183 
185  math::XYZTLorentzVector momentumPrim = primaryMomentum((string) "PI", true);
186  math::XYZTLorentzVector momentumSec = secondaryMomentum((string) "PI", true);
187 
188  math::XYZVector p_in;
189 
190  if ((isThereKindTracks(T_TO_VERTEX) || isThereKindTracks(T_MERGED)) && momentumPrim.E() > momentumSec.E()) {
191  p_in = momentumPrim.Vect() / sqrt(momentumPrim.Vect().Mag2() + 1e-10);
192  } else {
193  p_in = primaryDirection_;
194  }
195 
196  return p_in;
197 }
198 
199 const double PFDisplacedVertex::getMass2(M_Hypo massHypo, double mass) const {
200  // pion_mass = 0.1396 GeV
201  double pion_mass2 = 0.0194;
202  // k0_mass = 0.4976 GeV
203  double kaon_mass2 = 0.2476;
204  // lambda0_mass = 1.116 GeV
205  double lambda_mass2 = 1.267;
206 
207  if (massHypo == M_PION)
208  return pion_mass2;
209  else if (massHypo == M_KAON)
210  return kaon_mass2;
211  else if (massHypo == M_LAMBDA)
212  return lambda_mass2;
213  else if (massHypo == M_MASSLESS)
214  return 0;
215  else if (massHypo == M_CUSTOM)
216  return mass * mass;
217 
218  cout << "Warning: undefined mass hypothesis" << endl;
219  return 0;
220 }
221 
222 void PFDisplacedVertex::Dump(ostream& out) const {
223  if (!out)
224  return;
225 
226  out << "" << endl;
227  out << "==================== This is a Displaced Vertex type " << nameVertexType() << " ===============" << endl;
228 
229  out << " Vertex chi2 = " << chi2() << " ndf = " << ndof() << " normalised chi2 = " << normalizedChi2() << endl;
230 
231  out << " The vertex Fitted Position is: x = " << position().x() << " y = " << position().y()
232  << " rho = " << position().rho() << " z = " << position().z() << endl;
233 
234  out << "\t--- Structure --- " << endl;
235  out << "Number of tracks: " << nTracks() << " nPrimary " << nPrimaryTracks() << " nMerged " << nMergedTracks()
236  << " nSecondary " << nSecondaryTracks() << endl;
237 
238  vector<PFDisplacedVertex::PFTrackHitFullInfo> pattern = trackHitFullInfos();
239  vector<PFDisplacedVertex::VertexTrackType> trackType = trackTypes();
240  for (unsigned i = 0; i < pattern.size(); i++) {
241  out << "track " << i << " type = " << trackType[i] << " nHit BeforeVtx = " << pattern[i].first.first
242  << " AfterVtx = " << pattern[i].second.first << " MissHit BeforeVtx = " << pattern[i].first.second
243  << " AfterVtx = " << pattern[i].second.second << endl;
244  }
245 
246  math::XYZTLorentzVector mom_prim = primaryMomentum((string) "PI", true);
247  math::XYZTLorentzVector mom_sec = secondaryMomentum((string) "PI", true);
248 
249  // out << "Primary P:\t E " << setprecision(3) << setw(5) << mom_prim.E()
250  out << "Primary P:\t E " << mom_prim.E() << "\tPt = " << mom_prim.Pt() << "\tPz = " << mom_prim.Pz()
251  << "\tM = " << mom_prim.M() << "\tEta = " << mom_prim.Eta() << "\tPhi = " << mom_prim.Phi() << endl;
252 
253  out << "Secondary P:\t E " << mom_sec.E() << "\tPt = " << mom_sec.Pt() << "\tPz = " << mom_sec.Pz()
254  << "\tM = " << mom_sec.M() << "\tEta = " << mom_sec.Eta() << "\tPhi = " << mom_sec.Phi() << endl;
255 
256  out << " The vertex Direction is x = " << primaryDirection().x() << " y = " << primaryDirection().y()
257  << " z = " << primaryDirection().z() << " eta = " << primaryDirection().eta()
258  << " phi = " << primaryDirection().phi() << endl;
259 
260  out << " Angle_io = " << angle_io() << " deg" << endl << endl;
261 }
const double Pi
const math::XYZTLorentzVector primaryMomentum(std::string massHypo="PI", bool useRefitted=true, double mass=0.0) const
Momentum of primary or merged track calculated with a mass hypothesis.
double z() const
z coordinate
Definition: Vertex.h:133
std::string nameVertexType() const
void setPrimaryDirection(const math::XYZPoint &pvtx)
T w() const
const int nMergedTracks() const
Number of merged tracks was identified.
void Dump(std::ostream &out=std::cout) const
cout function
const Point & position() const
position
Definition: Vertex.h:127
const int nPrimaryTracks() const
Number of primary tracks was identified.
void add(Ref const &r, float w=1.0)
add a reference to a Track
Definition: Vertex.h:86
const int nSecondaryTracks() const
Number of secondary tracks was identified.
Track refittedTrack(const TrackBaseRef &track) const
Definition: Vertex.cc:91
const std::vector< VertexTrackType > trackTypes() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
double ndof() const
Definition: Vertex.h:123
const math::XYZVector primaryDirection() const
Primary Direction.
const int nTracks() const
Number of tracks.
const math::XYZTLorentzVector secondaryMomentum(std::string massHypo="PI", bool useRefitted=true, double mass=0.0) const
size_t tracksSize() const
number of tracks
Definition: Vertex.h:112
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
double pt() const
track transverse momentum
Definition: TrackBase.h:637
void addElement(const TrackBaseRef &r, const Track &refTrack, const PFTrackHitFullInfo &hitInfo, VertexTrackType trackType=T_NOT_FROM_VERTEX, float w=1.0)
Add a new track to the vertex.
std::vector< PFTrackHitFullInfo > trackHitFullInfos_
Information on the distance between track&#39;s hits and the Vertex.
T sqrt(T t)
Definition: SSEVec.h:19
double x() const
x coordinate
Definition: Vertex.h:129
const int totalCharge() const
Total Charge.
const std::vector< PFTrackHitFullInfo > trackHitFullInfos() const
const size_t trackPosition(const reco::TrackBaseRef &originalTrack) const
double y() const
y coordinate
Definition: Vertex.h:131
VertexType vertexType_
--—— MEMBERS --—— ///
double normalizedChi2() const
chi-squared divided by n.d.o.f.
Definition: Vertex.h:125
PFDisplacedVertex()
Default constructor.
std::pair< PFTrackHitInfo, PFTrackHitInfo > PFTrackHitFullInfo
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
const std::vector< Track > & refittedTracks() const
Returns the container of refitted tracks.
Definition: Vertex.h:196
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< VertexTrackType > trackTypes_
Types of the tracks associated to the vertex.
const int nKindTracks(VertexTrackType) const
Common tool used to get the number of tracks of a given Kind.
const double getMass2(M_Hypo, double) const
Get the mass with a given hypothesis.
std::pair< OmniClusterRef, TrackingParticleRef > P
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:664
math::XYZVector primaryDirection_
const math::XYZTLorentzVector momentum(std::string, VertexTrackType, bool, double mass) const
Common tool to calculate the momentum vector of tracks with a given Kind.
double chi2() const
chi-squares
Definition: Vertex.h:116
const bool isThereKindTracks(VertexTrackType) const
---—— TOOLS --------—— ///
fixed size matrix
void cleanTracks()
Clean the tracks collection and all the associated collections.
const double angle_io() const
void removeTracks()
Definition: Vertex.cc:75
long double T
M_Hypo
Mass hypothesis enum.
TrackBaseRef originalTrack(const Track &refTrack) const
Definition: Vertex.cc:81