Belle II Software development
PXD2TrackBase.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/datastore/RelationsObject.h>
12#include <framework/datastore/StoreArray.h>
13#include <tracking/dataobjects/RecoTrack.h>
14
15#include <framework/database/DBObjPtr.h>
16#include <mdst/dbobjects/BeamSpot.h>
17#include <mdst/dataobjects/Track.h>
18#include <analysis/VertexFitting/RaveInterface/RaveVertexFitter.h>
19
20#include <Math/Vector3D.h>
21#include <vector>
22
23
24namespace Belle2 {
38 template <class T>
40
41 public:
42
44 typedef T baseType;
45
47 PXD2TrackBase(): m_vx(0.0), m_vy(0.0), m_vz(0.0),
48 m_track_p(),
49 m_track_m()
50 {
51 }
52
58 PXD2TrackBase(const ROOT::Math::XYZVector& vertex, const T& track_p, const T& track_m):
59 m_vx(vertex.X()), m_vy(vertex.Y()), m_vz(vertex.Z()),
60 m_track_p(track_p), m_track_m(track_m)
61 {
62 }
63
67 ROOT::Math::XYZVector getVertex() const { return ROOT::Math::XYZVector(m_vx, m_vy, m_vz); }
68
72 const T& getTrackP() const { return m_track_p; }
73
77 const T& getTrackM() const { return m_track_m; }
78
86 //bool setValues(const RelationVector<RecoTrack>& recoTracks);
87 virtual bool setValues(const StoreArray<RecoTrack>& recoTracks,
88 const std::string& recoTracksName = "",
89 const std::string& pxdInterceptsName = "",
90 const std::string& pxdTrackClustersName = "PXDClustersFromTracks"
91 );
92
93 protected:
94 float m_vx;
95 float m_vy;
96 float m_vz;
101 };
102
103 template <class T>
105 const std::string& recoTracksName,
106 const std::string& pxdInterceptsName,
107 const std::string& pxdTrackClustersName
108 )
109 {
110 // Exactly 2 tracks
111 //if(recoTracks.size() != 2) return false;
112 if (!recoTracks.isValid() or recoTracks.getEntries() != 2) return false;
113
114 // Valid Tracks
115 auto track1Ptr = recoTracks[0]->getRelated<Track>("Tracks");
116 auto track2Ptr = recoTracks[1]->getRelated<Track>("Tracks");
117 if (!track1Ptr or !track2Ptr) return false;
118
119 // Valid trackFitResults
120 auto tfr1Ptr = track1Ptr->getTrackFitResultWithClosestMass(Const::pion);
121 auto tfr2Ptr = track2Ptr->getTrackFitResultWithClosestMass(Const::pion);
122 if (!tfr1Ptr or !tfr2Ptr) return false;
123
124 // Valid P Values
125 if (tfr1Ptr->getPValue() <= 0 or tfr2Ptr->getPValue() <= 0) return false;
126
127 // Opposite charges
128 if (tfr1Ptr->getChargeSign() * tfr2Ptr->getChargeSign() >= 0) return false;
129
130 // Setup Rave vertex fitter
131 auto bField = BFieldManager::getFieldInTesla(ROOT::Math::XYZVector(0, 0, 0)).Z();
132 B2DEBUG(20, "B Field = " << bField << " T");
135 try {
136 rvf.addTrack(tfr1Ptr);
137 rvf.addTrack(tfr2Ptr);
138 } catch (...) {
139 B2DEBUG(20, "Adding tracks to RaveVertexFitter failed.");
140 return false;
141 }
142 if (rvf.fit() == 0) return false;
143 // get vertex from fitting
144 auto vertex = rvf.getPos();
145 // Reset RAVE
147
148 // Set vertex
149 m_vx = vertex.X();
150 m_vy = vertex.Y();
151 m_vz = vertex.Z();
152 B2DEBUG(20, "Vertex = (" << m_vx
153 << ", " << m_vy
154 << ", " << m_vz
155 << ")");
156
157 // Set track containers
158 DBObjPtr<BeamSpot> beamSpotDB; // beam spot is required to correct d0/z0
159 auto ip = ROOT::Math::XYZVector(beamSpotDB->getIPPosition());
160 if (tfr1Ptr->getChargeSign() > 0) {
161 m_track_p.setValues(*recoTracks[0], ip, recoTracksName, pxdInterceptsName, pxdTrackClustersName);
162 m_track_m.setValues(*recoTracks[1], ip, recoTracksName, pxdInterceptsName, pxdTrackClustersName);
163 } else {
164 m_track_p.setValues(*recoTracks[1], ip, recoTracksName, pxdInterceptsName, pxdTrackClustersName);
165 m_track_m.setValues(*recoTracks[0], ip, recoTracksName, pxdInterceptsName, pxdTrackClustersName);
166 }
167 return true;
168 }
170} // end namespace Belle2
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
Definition: BFieldManager.h:61
static const ChargedStable pion
charged pion particle
Definition: Const.h:661
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Class PXD2TrackBase: Event data container for performance and calibration studies.
Definition: PXD2TrackBase.h:39
float m_vy
Position of the vertex in y.
Definition: PXD2TrackBase.h:95
float m_vz
Position of the vertex in z.
Definition: PXD2TrackBase.h:96
ROOT::Math::XYZVector getVertex() const
Get the vertex.
Definition: PXD2TrackBase.h:67
const T & getTrackP() const
Get the track with positive charge.
Definition: PXD2TrackBase.h:72
T m_track_m
Track with the negative charge.
Definition: PXD2TrackBase.h:98
const T & getTrackM() const
Get the track with negative charge.
Definition: PXD2TrackBase.h:77
float m_vx
Position of the vertex in x.
Definition: PXD2TrackBase.h:94
PXD2TrackBase()
default constructor for ROOT
Definition: PXD2TrackBase.h:47
T baseType
The base type for a track structure.
Definition: PXD2TrackBase.h:44
PXD2TrackBase(const ROOT::Math::XYZVector &vertex, const T &track_p, const T &track_m)
Standard constructor.
Definition: PXD2TrackBase.h:58
T m_track_p
Track with the positive charge.
Definition: PXD2TrackBase.h:97
Defines interface for accessing relations of objects in StoreArray.
ClassDef(RelationsInterface, 0)
defines interface for accessing relations of objects in StoreArray.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
bool isValid() const
Check wether the array was registered.
Definition: StoreArray.h:288
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Class that bundles various TrackFitResults.
Definition: Track.h:25
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
Definition: Track.cc:104
static void initialize(int verbosity=1, double MagneticField=1.5)
Set everything up so everything needed for vertex fitting is there.
Definition: RaveSetup.cc:33
static RaveSetup * getInstance()
get the pointer to the instance to get/set any of options stored in RaveSetup
Definition: RaveSetup.h:43
void reset()
frees memory allocated by initialize().
Definition: RaveSetup.cc:58
The RaveVertexFitter class is part of the RaveInterface together with RaveSetup.
int fit(std::string options="default")
do the vertex fit with all tracks previously added with the addTrack or addMother function.
void addTrack(const Particle *const aParticlePtr)
add a track (in the format of a Belle2::Particle) to set of tracks that should be fitted to a vertex
B2Vector3D getPos(VecSize vertexId=0) const
get the position of the fitted vertex.
virtual bool setValues(const StoreArray< RecoTrack > &recoTracks, const std::string &recoTracksName="", const std::string &pxdInterceptsName="", const std::string &pxdTrackClustersName="PXDClustersFromTracks")
Set values from RecoTrack collection.
Abstract base class for different kinds of events.