CMS 3D CMS Logo

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