-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from JeffersonLab/biasingTool
Biasing tool
- Loading branch information
Showing
6 changed files
with
224 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
//------------------// | ||
// C++ // | ||
//------------------// | ||
#include <iostream> | ||
#include <random> | ||
#include <memory> | ||
|
||
//------------------// | ||
// hpstr // | ||
//------------------// | ||
|
||
#include "Track.h" | ||
|
||
class TFile; | ||
class TH1D; | ||
|
||
class TrackBiasingTool { | ||
|
||
public : | ||
|
||
TrackBiasingTool(const std::string& biasingfile, | ||
const std::string& tracks = "KalmanFullTracks"); | ||
|
||
double biasTrackP(const Track& track); | ||
|
||
//Update the track P with a specific scale Factor | ||
void updateWithBiasP(Track& trk, double scaleFactor); | ||
|
||
//Update the track P with scale Factors according to the internal calibration plots | ||
void updateWithBiasP(Track& trk); | ||
|
||
private: | ||
|
||
std::shared_ptr<TFile> biasingfile_; | ||
|
||
//Biasing terms | ||
|
||
//This is per charge -1: electron +1: positron | ||
TH1D* eop_h_top_; | ||
TH1D* eop_h_bot_; | ||
|
||
// debug | ||
bool debug_{false}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "TrackBiasingTool.h" | ||
#include "TFile.h" | ||
#include "TH1D.h" | ||
|
||
#include <stdexcept> | ||
|
||
TrackBiasingTool::TrackBiasingTool(const std::string& biasingfile, | ||
const std::string& tracks) { | ||
|
||
|
||
|
||
biasingfile_ = std::make_shared<TFile>(biasingfile.c_str()); | ||
|
||
if (!biasingfile_) | ||
throw std::invalid_argument("Provided input biasing file doesn't exists"); | ||
|
||
eop_h_top_ = (TH1D*) biasingfile_->Get((tracks+"_eop_vs_charge_top").c_str()); | ||
eop_h_bot_ = (TH1D*) biasingfile_->Get((tracks+"_eop_vs_charge_bot").c_str()); | ||
|
||
if (!eop_h_top_ || !eop_h_bot_) | ||
throw std::invalid_argument("Top and Bottom biasing histograms not found in smearing file"); | ||
|
||
} | ||
|
||
double TrackBiasingTool::biasTrackP(const Track& trk) { | ||
|
||
double p = trk.getP(); | ||
double isTop = trk.getTanLambda() > 0. ? true : false; | ||
double q = trk.getCharge(); | ||
|
||
TH1D* bias_histo_ = isTop ? eop_h_top_ : eop_h_bot_; | ||
|
||
int binN = bias_histo_->GetXaxis()->FindBin(q); | ||
if (debug_) | ||
std::cout<<"Track charge="<<q<<" bin="<<binN<<std::endl; | ||
|
||
double eop_bias = bias_histo_->GetBinContent(binN); | ||
|
||
double pcorr = p * eop_bias; | ||
|
||
if (debug_) | ||
std::cout<<"Original p = " << p <<" corrected p="<< pcorr <<std::endl; | ||
|
||
return pcorr; | ||
} | ||
|
||
void TrackBiasingTool::updateWithBiasP(Track& trk) { | ||
|
||
double biased_p = biasTrackP(trk); | ||
|
||
std::vector<double> momentum = trk.getMomentum(); | ||
double unbiasedp = trk.getP(); | ||
|
||
for (double& coordinate : momentum) | ||
coordinate *= (biased_p / unbiasedp); | ||
|
||
trk.setMomentum(momentum); | ||
|
||
} | ||
|
||
// This will recompute the track momentum from curvature and store it in the track | ||
void TrackBiasingTool::updateWithBiasP(Track& trk, double scaleFactor) { | ||
|
||
std::vector<double> momentum = trk.getMomentum(); | ||
|
||
for (double& coordinate : momentum) | ||
coordinate *= scaleFactor ; | ||
|
||
trk.setMomentum(momentum); | ||
|
||
} |