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 
87 std::string
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_out = momentumSec.Vect();
208 
209  math::XYZVector p_in;
210 
212  momentumPrim.E() > momentumSec.E()){
213  p_in = momentumPrim.Vect()/sqrt(momentumPrim.Vect().Mag2()+1e-10);
214  } else {
215  p_in = primaryDirection_;
216  }
217 
218  return p_in;
219 }
220 
221 
222 const double
223 PFDisplacedVertex::getMass2(M_Hypo massHypo, double mass) const {
224 
225  // pion_mass = 0.1396 GeV
226  double pion_mass2 = 0.0194;
227  // k0_mass = 0.4976 GeV
228  double kaon_mass2 = 0.2476;
229  // lambda0_mass = 1.116 GeV
230  double lambda_mass2 = 1.267;
231 
232  if (massHypo == M_PION) return pion_mass2;
233  else if (massHypo == M_KAON) return kaon_mass2;
234  else if (massHypo == M_LAMBDA) return lambda_mass2;
235  else if (massHypo == M_MASSLESS) return 0;
236  else if (massHypo == M_CUSTOM) return mass*mass;
237 
238  cout << "Warning: undefined mass hypothesis" << endl;
239  return 0;
240 
241 }
242 
243 void PFDisplacedVertex::Dump( ostream& out ) const {
244  if(! out ) return;
245 
246  out << "" << endl;
247  out << "==================== This is a Displaced Vertex type " <<
248  nameVertexType() << " ===============" << endl;
249 
250  out << " Vertex chi2 = " << chi2() << " ndf = " << ndof()<< " normalised chi2 = " << normalizedChi2()<< endl;
251 
252  out << " The vertex Fitted Position is: x = " << position().x()
253  << " y = " << position().y()
254  << " rho = " << position().rho()
255  << " z = " << position().z()
256  << endl;
257 
258  out<< "\t--- Structure --- " << endl;
259  out<< "Number of tracks: " << nTracks()
260  << " nPrimary " << nPrimaryTracks()
261  << " nMerged " << nMergedTracks()
262  << " nSecondary " << nSecondaryTracks() << endl;
263 
264  vector <PFDisplacedVertex::PFTrackHitFullInfo> pattern = trackHitFullInfos();
265  vector <PFDisplacedVertex::VertexTrackType> trackType = trackTypes();
266  for (unsigned i = 0; i < pattern.size(); i++){
267  out << "track " << i
268  << " type = " << trackType[i]
269  << " nHit BeforeVtx = " << pattern[i].first.first
270  << " AfterVtx = " << pattern[i].second.first
271  << " MissHit BeforeVtx = " << pattern[i].first.second
272  << " AfterVtx = " << pattern[i].second.second
273  << endl;
274  }
275 
276  math::XYZTLorentzVector mom_prim = primaryMomentum((string) "PI", true);
277  math::XYZTLorentzVector mom_sec = secondaryMomentum((string) "PI", true);
278 
279  // out << "Primary P:\t E " << setprecision(3) << setw(5) << mom_prim.E()
280  out << "Primary P:\t E " << mom_prim.E()
281  << "\tPt = " << mom_prim.Pt()
282  << "\tPz = " << mom_prim.Pz()
283  << "\tM = " << mom_prim.M()
284  << "\tEta = " << mom_prim.Eta()
285  << "\tPhi = " << mom_prim.Phi() << endl;
286 
287  out << "Secondary P:\t E " << mom_sec.E()
288  << "\tPt = " << mom_sec.Pt()
289  << "\tPz = " << mom_sec.Pz()
290  << "\tM = " << mom_sec.M()
291  << "\tEta = " << mom_sec.Eta()
292  << "\tPhi = " << mom_sec.Phi() << endl;
293 
294  out << " The vertex Direction is x = " << primaryDirection().x()
295  << " y = " << primaryDirection().y()
296  << " z = " << primaryDirection().z()
297  << " eta = " << primaryDirection().eta()
298  << " phi = " << primaryDirection().phi() << endl;
299 
300  out << " Angle_io = " << angle_io() << " deg" << endl << endl;
301 
302 }
303 
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 Vector & momentum() const
track momentum vector
Definition: TrackBase.h:150
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:97
const math::XYZTLorentzVector secondaryMomentum(std::string massHypo="PI", bool useRefitted=true, double mass=0.0) const
const int totalCharge() const
Total Charge.
#define P
void Dump(std::ostream &out=std::cout) const
cout function
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:136
const Point & position() const
position
Definition: Vertex.h:93
double charge(const std::vector< uint8_t > &Ampls)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
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:28
double pt() const
track transverse momentum
Definition: TrackBase.h:131
const int nPrimaryTracks() const
Number of primary tracks was identified.
double chi2() const
chi-squares
Definition: Vertex.h:82
double z() const
y coordinate
Definition: Vertex.h:99
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:89
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:95
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:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
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:45
std::string nameVertexType() const
const int nMergedTracks() const
Number of merged tracks was identified.
tuple cout
Definition: gather_cfg.py:41
double normalizedChi2() const
chi-squared divided by n.d.o.f.
Definition: Vertex.h:91
void removeTracks()
Definition: Vertex.cc:65
long double T
const int nSecondaryTracks() const
Number of secondary tracks was identified.
mathSSE::Vec4< T > v
M_Hypo
Mass hypothesis enum.
size_t tracksSize() const
number of tracks
Definition: Vertex.cc:35
std::vector< VertexTrackType > trackTypes_
Types of the tracks associated to the vertex.
const int nTracks() const
Number of tracks.