Belle II Software  release-08-01-10
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 <TVector3.h>
22 #include <vector>
23 
24 
25 namespace Belle2 {
39  template <class T>
40  class PXD2TrackBase : public RelationsObject {
41 
42  public:
43 
45  typedef T baseType;
46 
48  PXD2TrackBase(): m_vx(0.0), m_vy(0.0), m_vz(0.0),
49  m_track_p(),
50  m_track_m()
51  {
52  }
53 
59  PXD2TrackBase(const TVector3& vertex, const T& track_p, const T& track_m):
60  m_vx(vertex.X()), m_vy(vertex.Y()), m_vz(vertex.Z()),
61  m_track_p(track_p), m_track_m(track_m)
62  {
63  }
64 
68  TVector3 getVertex() const { return TVector3(m_vx, m_vy, m_vz); }
69 
73  const T& getTrackP() const { return m_track_p; }
74 
78  const T& getTrackM() const { return m_track_m; }
79 
87  //bool setValues(const RelationVector<RecoTrack>& recoTracks);
88  virtual bool setValues(const StoreArray<RecoTrack>& recoTracks,
89  const std::string& recoTracksName = "",
90  const std::string& pxdInterceptsName = "",
91  const std::string& pxdTrackClustersName = "PXDClustersFromTracks"
92  );
93 
94  protected:
95  float m_vx;
96  float m_vy;
97  float m_vz;
102  };
103 
104  template <class T>
106  const std::string& recoTracksName,
107  const std::string& pxdInterceptsName,
108  const std::string& pxdTrackClustersName
109  )
110  {
111  // Exactly 2 tracks
112  //if(recoTracks.size() != 2) return false;
113  if (!recoTracks.isValid() or recoTracks.getEntries() != 2) return false;
114 
115  // Valid Tracks
116  auto track1Ptr = recoTracks[0]->getRelated<Track>("Tracks");
117  auto track2Ptr = recoTracks[1]->getRelated<Track>("Tracks");
118  if (!track1Ptr or !track2Ptr) return false;
119 
120  // Valid trackFitResults
121  auto tfr1Ptr = track1Ptr->getTrackFitResultWithClosestMass(Const::pion);
122  auto tfr2Ptr = track2Ptr->getTrackFitResultWithClosestMass(Const::pion);
123  if (!tfr1Ptr or !tfr2Ptr) return false;
124 
125  // Valid P Values
126  if (tfr1Ptr->getPValue() <= 0 or tfr2Ptr->getPValue() <= 0) return false;
127 
128  // Opposite charges
129  if (tfr1Ptr->getChargeSign() * tfr2Ptr->getChargeSign() >= 0) return false;
130 
131  // Setup Rave vertex fitter
132  auto bField = BFieldManager::getFieldInTesla(ROOT::Math::XYZVector(0, 0, 0)).Z();
133  B2DEBUG(20, "B Field = " << bField << " T");
136  try {
137  rvf.addTrack(tfr1Ptr);
138  rvf.addTrack(tfr2Ptr);
139  } catch (...) {
140  B2DEBUG(20, "Adding tracks to RaveVertexFitter failed.");
141  return false;
142  }
143  if (rvf.fit() == 0) return false;
144  // get vertex from fitting
145  auto vertex = rvf.getPos();
146  // Reset RAVE
148 
149  // Set vertex
150  m_vx = vertex.X();
151  m_vy = vertex.Y();
152  m_vz = vertex.Z();
153  B2DEBUG(20, "Vertex = (" << m_vx
154  << ", " << m_vy
155  << ", " << m_vz
156  << ")");
157 
158  // Set track containers
159  DBObjPtr<BeamSpot> beamSpotDB; // beam spot is required to correct d0/z0
160  auto ip = ROOT::Math::XYZVector(beamSpotDB->getIPPosition());
161  if (tfr1Ptr->getChargeSign() > 0) {
162  m_track_p.setValues(*recoTracks[0], ip, recoTracksName, pxdInterceptsName, pxdTrackClustersName);
163  m_track_m.setValues(*recoTracks[1], ip, recoTracksName, pxdInterceptsName, pxdTrackClustersName);
164  } else {
165  m_track_p.setValues(*recoTracks[1], ip, recoTracksName, pxdInterceptsName, pxdTrackClustersName);
166  m_track_m.setValues(*recoTracks[0], ip, recoTracksName, pxdInterceptsName, pxdTrackClustersName);
167  }
168  return true;
169  }
171 } // 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:652
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Class PXD2TrackBase: Event data container for performance and calibration studies.
Definition: PXD2TrackBase.h:40
const T & getTrackM() const
Get the track with negative charge.
Definition: PXD2TrackBase.h:78
const T & getTrackP() const
Get the track with positive charge.
Definition: PXD2TrackBase.h:73
PXD2TrackBase(const TVector3 &vertex, const T &track_p, const T &track_m)
Standard constructor.
Definition: PXD2TrackBase.h:59
float m_vy
Position of the vertex in y.
Definition: PXD2TrackBase.h:96
float m_vz
Position of the vertex in z.
Definition: PXD2TrackBase.h:97
TVector3 getVertex() const
Get the vertex.
Definition: PXD2TrackBase.h:68
T m_track_m
Track with the negative charge.
Definition: PXD2TrackBase.h:99
float m_vx
Position of the vertex in x.
Definition: PXD2TrackBase.h:95
PXD2TrackBase()
default constructor for ROOT
Definition: PXD2TrackBase.h:48
T baseType
The base type for a track structure.
Definition: PXD2TrackBase.h:45
T m_track_p
Track with the positive charge.
Definition: PXD2TrackBase.h:98
Defines interface for accessing relations of objects in StoreArray.
ClassDef(RelationsInterface, 0)
defines interface for accessing relations of objects in StoreArray.
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.