hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TrackBiasingTool.cxx
Go to the documentation of this file.
1#include "TrackBiasingTool.h"
2#include "TFile.h"
3#include "TH1D.h"
4#include "TVector3.h"
5
6#include <stdexcept>
7
8TrackBiasingTool::TrackBiasingTool(const std::string& biasingfile,
9 const std::string& tracks) {
10
11
12
13 biasingfile_ = std::make_shared<TFile>(biasingfile.c_str());
14
15 if (!biasingfile_)
16 throw std::invalid_argument("Provided input biasing file doesn't exists");
17
18 eop_h_top_ = (TH1D*) biasingfile_->Get((tracks+"_eop_vs_charge_top").c_str());
19 eop_h_bot_ = (TH1D*) biasingfile_->Get((tracks+"_eop_vs_charge_bot").c_str());
20
21 if (!eop_h_top_ || !eop_h_bot_)
22 throw std::invalid_argument("Top and Bottom biasing histograms not found in smearing file");
23
24}
25
26
27double TrackBiasingTool::getCorrection(const double& p,
28 const double tanL,
29 const int q) {
30
31 TH1D* bias_histo_ = (tanL > 0.) ? eop_h_top_ : eop_h_bot_;
32 int binN = bias_histo_->GetXaxis()->FindBin(q);
33
34 return bias_histo_->GetBinContent(binN);
35
36}
37
38
40
41 double p = trk.getP();
42 double q = trk.getCharge();
43
44 TH1D* bias_histo_ = (trk.getTanLambda() > 0.) ? eop_h_top_ : eop_h_bot_;
45
46 int binN = bias_histo_->GetXaxis()->FindBin(q);
47 if (debug_)
48 std::cout<<"Track charge="<<q<<" bin="<<binN<<std::endl;
49
50 double eop_bias = bias_histo_->GetBinContent(binN);
51
52 double pcorr = p * eop_bias;
53
54 if (debug_)
55 std::cout<<"Original p = " << p <<" corrected p="<< pcorr <<std::endl;
56
57 return pcorr;
58}
59
61
62 double biased_p = biasTrackP(trk);
63
64 std::vector<double> momentum = trk.getMomentum();
65 double unbiasedp = trk.getP();
66
67 for (double& coordinate : momentum)
68 coordinate *= (biased_p / unbiasedp);
69
70 trk.setMomentum(momentum);
71
72}
73
74// This will recompute the track momentum from curvature and store it in the track
75void TrackBiasingTool::updateWithBiasP(Track& trk, double scaleFactor) {
76
77 std::vector<double> momentum = trk.getMomentum();
78
79 for (double& coordinate : momentum)
80 coordinate *= scaleFactor ;
81
82 trk.setMomentum(momentum);
83
84}
85
87
88 //Correct the vertex
89 double corr1 = getCorrection(vtx->getP1().Mag(), vtx->getP1Y(), -1); //ele
90 double corr2 = getCorrection(vtx->getP2().Mag(), vtx->getP2Y(), 1); //pos
91
92
93 TVector3 p1_corr, p2_corr;
94 double m_corr;
95
96 p1_corr.SetX(vtx->getP1X()*corr1);
97 p1_corr.SetY(vtx->getP1Y()*corr1);
98 p1_corr.SetZ(vtx->getP1Z()*corr1);
99
100 p2_corr.SetX(vtx->getP2X()*corr2);
101 p2_corr.SetY(vtx->getP2Y()*corr2);
102 p2_corr.SetZ(vtx->getP2Z()*corr2);
103
104 m_corr = vtx->getInvMass() * sqrt(corr1*corr2);
105
106 vtx->setVtxParameters(p1_corr, p2_corr, m_corr);
107
108}
109
110
double getCorrection(const double &p, const double tanL, const int q)
TrackBiasingTool(const std::string &biasingfile, const std::string &tracks="KalmanFullTracks")
void updateWithBiasP(Track &trk, double scaleFactor)
void updateVertexWithBiasP(Vertex *vtx)
double biasTrackP(const Track &track)
std::shared_ptr< TFile > biasingfile_
Definition Track.h:32
int getCharge() const
Definition Track.h:247
double getTanLambda() const
Definition Track.h:91
std::vector< double > getMomentum()
Definition Track.h:285
double getP() const
Definition Track.h:291
void setMomentum(double bfield=0.52)
Definition Track.cxx:63