11#include <calibration/CalibrationAlgorithm.h>
18#include <TDatabasePDG.h>
105 std::unique_ptr<TList>
GenerateNewHistograms(std::shared_ptr<TTree> ttreeLambda, std::shared_ptr<TTree> ttreeDstar,
106 std::shared_ptr<TTree> ttreeGamma, std::shared_ptr<TTree>
126 const double m_MuonPDGMass = TDatabasePDG::Instance()->GetParticle(13)->Mass();
127 const double m_PionPDGMass = TDatabasePDG::Instance()->GetParticle(211)->Mass();
128 const double m_KaonPDGMass = TDatabasePDG::Instance()->GetParticle(321)->Mass();
137 std::vector<double> pbins;
139 pbins.push_back(0.0);
140 pbins.push_back(0.05);
142 for (
int iBin = 2; iBin <=
m_numPBins; iBin++) {
144 pbins.push_back(0.025 + 0.025 * iBin);
146 pbins.push_back(pbins.at(19) + 0.05 * (iBin - 19));
148 pbins.push_back(pbins.at(59) + 0.3 * (iBin - 59));
160 for (
int pbin = 0; pbin <=
m_numPBins + 1; pbin++) {
161 for (
int dedxbin = 0; dedxbin <=
m_numDEdxBins + 1; dedxbin++) {
163 if (HistoToNormalise->GetBinContent(pbin, dedxbin) <= 1) {
164 HistoToNormalise->SetBinContent(pbin, dedxbin, 0);
169 TH1D* MomentumSlice =
static_cast<TH1D*
>(HistoToNormalise->ProjectionY(
"slice_tr", pbin, pbin));
172 MomentumSlice->Scale(1. / MomentumSlice->Integral(0,
m_numDEdxBins + 1));
175 for (
int dedxbin = 0; dedxbin <=
m_numDEdxBins + 1; dedxbin++) {
176 HistoToNormalise->SetBinContent(pbin, dedxbin, MomentumSlice->GetBinContent(dedxbin));
177 HistoToNormalise->SetBinError(pbin, dedxbin, MomentumSlice->GetBinError(dedxbin));
180 return HistoToNormalise;
186 TH2F*
PrepareNewHistogram(TH2F* DataHistogram, TString NewName, TF1* betagamma_function, TF1* ResolutionFunctionOriginal,
187 double bias_correction)
189 TF1* ResolutionFunction =
static_cast<TF1*
>(ResolutionFunctionOriginal->Clone(Form(
"%sClone",
190 ResolutionFunctionOriginal->GetName())));
192 TH2F* DataHistogramNew =
static_cast<TH2F*
>(DataHistogram->Clone(NewName));
194 DataHistogramNew->Reset();
196 for (
int pbin = 1; pbin <=
m_numPBins + 1; pbin++) {
197 double mean_dEdx_value = betagamma_function->Eval(DataHistogramNew->GetXaxis()->GetBinCenter(pbin));
198 ResolutionFunction->FixParameter(1, mean_dEdx_value + bias_correction);
201 TH1D* MomentumSlice =
static_cast<TH1D*
>(DataHistogramNew->ProjectionY(
"slice", pbin, pbin));
206 MomentumSlice->Fill(ResolutionFunction->GetRandom());
211 for (
int dedxbin = 0; dedxbin <=
m_numDEdxBins + 1; dedxbin++) {
212 if (MomentumSlice->GetBinContent(dedxbin) < 1) {
213 MomentumSlice->SetBinContent(dedxbin, 0.5);
219 MomentumSlice->Scale(1. / MomentumSlice->Integral(0,
m_numDEdxBins + 1));
222 for (
int dedxbin = 0; dedxbin <=
m_numDEdxBins + 1; dedxbin++) {
223 DataHistogramNew->SetBinContent(pbin, dedxbin, MomentumSlice->GetBinContent(dedxbin));
224 DataHistogramNew->SetBinError(pbin, dedxbin, MomentumSlice->GetBinError(dedxbin));
228 return DataHistogramNew;
238 TF1* ResolutionFunction =
new TF1(
"ResolutionFunction",
"[0]*ROOT::Math::crystalball_function(x,[4],[3],[2]*[1],[1])", 100e3,
242 ResolutionFunction->SetNpx(1000);
244 ResolutionFunction->SetParameters(1000, 6.e5, 0.1, 1, 1);
245 ResolutionFunction->SetParLimits(0, 0, 1.e6);
246 ResolutionFunction->SetParLimits(1, 3.e5, 7.e6);
247 ResolutionFunction->SetParLimits(2, 0, 10);
248 ResolutionFunction->SetParLimits(3, 0.01, 100);
249 ResolutionFunction->SetParLimits(4, 0.01, 100);
253 TH1D* DataHistogramNew =
static_cast<TH1D*
>(DataHistogram->ProfileX()->ProjectionX());
254 TH1D* DataHistogramClone =
static_cast<TH1D*
>(DataHistogramNew->Clone(Form(
"%sClone",
255 DataHistogramNew->GetName())));
256 DataHistogramNew->SetName(NewName);
257 DataHistogramNew->SetTitle(NewName);
258 DataHistogramNew->Reset();
262 TH1D* MomentumSlice =
static_cast<TH1D*
>(DataHistogram->ProjectionY(
"slice", pbin, pbin));
264 if (MomentumSlice->Integral() < 1)
continue;
266 ResolutionFunction->SetParameter(1, MomentumSlice->GetMean());
267 ResolutionFunction->SetParameter(2, MomentumSlice->GetStdDev() / MomentumSlice->GetMean());
268 ResolutionFunction->SetRange(MomentumSlice->GetMean() * 0.2, MomentumSlice->GetMean() * 1.75);
270 MomentumSlice->Fit(ResolutionFunction,
"RQI");
272 double stat_error = DataHistogramClone->GetBinError(pbin);
274 double bincontent = ResolutionFunction->GetParameter(1);
275 double binerror = ResolutionFunction->GetParError(1);
277 binerror = std::max(binerror, stat_error);
279 DataHistogramNew->SetBinContent(pbin, bincontent);
280 DataHistogramNew->SetBinError(pbin, binerror);
283 return DataHistogramNew;
EResult
The result of calibration.
CalibrationAlgorithm(const std::string &collectorModuleName)
Constructor - sets the prefix for collected objects (won't be accesses until execute(....
void setMinEvtsPerTree(const double &value)
set the upper edge of the dEdx binning for the payloads
int m_numPBins
the number of momentum bins for the payloads
virtual ~SVDdEdxCalibrationAlgorithm() override
Destructor.
const double m_MuonPDGMass
PDG mass for the muon.
const double m_ElectronPDGMass
PDG mass for the electron.
void setNumDEdxBins(const int &value)
set the number of dEdx bins for the payloads
bool m_FixUnstableFitParameter
In the dEdx:betagamma fit, there is one free parameter that makes fit convergence poor.
const double m_DeuteronPDGMass
PDG mass for the deuteron.
void setFixUnstableFitParameter(bool value=true)
In the dEdx:betagamma fit, there is one free parameter that makes fit convergence poor.
std::vector< double > CreatePBinningScheme()
build the binning scheme for the momentum
SVDdEdxCalibrationAlgorithm()
Constructor.
TH2F * Normalise2DHisto(TH2F *HistoToNormalise)
Normalise a given dEdx:momentum histogram in each momentum bin, so that sum of entries in each moment...
bool m_UseProtonBGFunctionForEverything
Assume that the dEdx:betagamma trend is the same for all hadrons; use the proton trend as representat...
int m_numBGBins
the number of beta*gamma bins for the profile and fitting
void setDEdxCutoff(const double &value)
set the upper edge of the dEdx binning for the payloads
std::unique_ptr< TList > DstarHistogramming(TTree *inputTree)
produce histograms for K/pi
double m_dedxMaxPossible
the approximate max possible value of dEdx
bool m_isMakePlots
produce plots for monitoring
int m_MinEvtsPerTree
number of events in TTree below which we don't try to fit
TH1D * PrepareProfile(TH2F *DataHistogram, TString NewName)
Reimplement the Profile histogram calculation for a 2D histogram.
int m_numDEdxBins
the number of dEdx bins for the payloads
TTree * LambdaMassFit(std::shared_ptr< TTree > preselTree)
Mass fit for Lambda->ppi.
std::unique_ptr< TList > LambdaHistogramming(TTree *inputTree)
produce histograms for protons
const double m_KaonPDGMass
PDG mass for the charged kaon.
int m_NToGenerate
the number of events to be generated in each momentum bin in the new payloads.
TH2F * PrepareNewHistogram(TH2F *DataHistogram, TString NewName, TF1 *betagamma_function, TF1 *ResolutionFunctionOriginal, double bias_correction)
Generate a new dEdx:momentum histogram from a function that encodes dEdx:momentum trend and a functio...
std::unique_ptr< TList > GammaHistogramming(std::shared_ptr< TTree > preselTree)
produce histograms for e
void setNumBGBins(const int &value)
set the number of beta*gamma bins for the fits
TTree * DstarMassFit(std::shared_ptr< TTree > preselTree)
Mass fit for D*->Dpi.
void setCustomProfile(bool value=true)
reimplement the profile histogram calculation
bool m_UsePionBGFunctionForEverything
Assume that the dEdx:betagamma trend is the same for all hadrons; use the pion trend as representativ...
void setNumPBins(const int &value)
set the number of momentum bins for the payloads
std::unique_ptr< TList > GenerateNewHistograms(std::shared_ptr< TTree > ttreeLambda, std::shared_ptr< TTree > ttreeDstar, std::shared_ptr< TTree > ttreeGamma, std::shared_ptr< TTree > ttreeGeneric)
generate high-statistics histograms
virtual EResult calibrate() override
run algorithm on data
bool m_CustomProfile
reimplement profile histogram calculation instead of the ROOT implementation?
void setUsePionBGFunctionForEverything(bool value=false)
use the pion beta*gamma function for other hadrons
double m_dedxCutoff
the upper edge of the dEdx binning for the payloads
void setMonitoringPlots(bool value=false)
function to enable plotting
const double m_ProtonPDGMass
PDG mass for the proton.
void setUseProtonBGFunctionForEverything(bool value=false)
use the proton beta*gamma function for other hadrons
const double m_PionPDGMass
PDG mass for the charged pion.
Abstract base class for different kinds of events.