Belle II Software development
HadronBgPrep.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 <map>
12#include <vector>
13#include <iostream>
14#include <fstream>
15
16#include <TH1D.h>
17#include <TF1.h>
18#include <TCanvas.h>
19#include <TLine.h>
20#include <TLegend.h>
21#include <TGraphErrors.h>
22#include <TTree.h>
23
24#include <calibration/CalibrationAlgorithm.h>
25#include <framework/database/DBObjPtr.h>
26#include <cdc/utilities/CDCDedxMeanPred.h>
27#include <cdc/utilities/CDCDedxSigmaPred.h>
28#include <cdc/utilities/CDCDedxHadSat.h>
29
30#include <framework/gearbox/Const.h>
31
32enum gstatus {OK, Failed};
33
34namespace Belle2 {
44
45 public:
46
51
55 virtual ~HadronBgPrep() {};
56
60 HadronBgPrep(int bgbins, double upperbg, double lowerbg, int cosbins, double uppercos, double lowercos, int injbins,
61 double lowerinj, double upperinj, int nhitbins, double lowernhit, double uppernhit, double cut);
62
66 void prepareSample(std::shared_ptr<TTree> hadron, TFile*& outfile, const std::string& suffix, const std::string& bgcurvefile,
67 const std::string& bgsigmafile, const std::string& pdg, bool ismakePlots);
68
72 void defineHisto(std::vector<TH1F*>& htemp, const std::string& svar, const std::string& stype, const std::string& pdg);
73
77 void plotDist(std::map<int, std::vector<TH1F*>>& hist, const std::string& suffix, int bins);
78
82 void plotDist(std::vector<TH1F*>& hist, const std::string& suffix, int nbins);
83
87 void setPars(TFile*& outfile, std::string pdg, std::vector<TH1F*>& hdedx_bg, std::vector<TH1F*>& hchi_bg,
88 std::vector<TH1F*>& hionzsigma_bg, std::map<int, std::vector<TH1F*>>& hchi_inj);
89
93 void fitGaussianWRange(TH1F*& temphist, gstatus& status, double sigmaR);
94
98 void fit(TH1F*& hist, const std::string& pdg);
99
103 void printCanvasCos(std::map<int, std::vector<TH1F*>>& hchicos_allbg, std::map<int, std::vector<TH1F*>>& hchicos_1by3bg,
104 std::map<int, std::vector<TH1F*>>& hchicos_2by3bg, std::map<int, std::vector<TH1F*>>& hchicos_3by3bg, const std::string& particle,
105 const std::string& suffix);
106
110 void FormatGraph(TGraphErrors& gr, int flag, const std::string& name = "")
111 {
112 if (flag == 0) {
113 gr.SetTitle(Form("%s;cos(#theta);#chi_{mean}", name.data()));
114 gr.SetMarkerStyle(24);
115 gr.SetMarkerColor(2);
116 gr.SetMarkerSize(.7);
117 gr.SetMaximum(1.0);
118 gr.SetMinimum(-1.0);
119 gr.GetXaxis()->SetRangeUser(-1, 1);
120 } else if (flag == 1) {
121 gr.SetMarkerStyle(22);
122 gr.SetMarkerColor(9);
123 gr.SetMarkerSize(.7);
124 } else if (flag == 2) {
125 gr.SetTitle(Form("%s;cos(#theta);#sigma", name.data()));
126 gr.SetMarkerStyle(24);
127 gr.SetMarkerColor(2);
128 gr.SetMarkerSize(.7);
129 gr.SetMaximum(2);
130 gr.SetMinimum(0);
131 gr.GetXaxis()->SetRangeUser(-1, 1);
132 }
133 }
134
139 {
140 m_sumcos.clear();
141 m_sumbg.clear();
142 m_sumres_square.clear();
143 m_sumsize.clear();
144 m_means.clear();
145 m_errors.clear();
146 m_suminj.clear();
147 }
148
152 void deleteHistos(std::vector<TH1F*>& htemp)
153 {
154 for (auto& hist : htemp) hist->Delete();
155 }
156
160 double getParticleMass(const std::string& particle)
161 {
162 double mass;
163 if (particle == "pion") mass = Const::pion.getMass();
164 else if (particle == "kaon") mass = Const::kaon.getMass();
165 else if (particle == "proton") mass = Const::proton.getMass();
166 else if (particle == "muon") mass = Const::muon.getMass();
167 else if (particle == "electron") mass = Const::electron.getMass();
168 else mass = 0.0;
169 return mass;
170 }
171
172 private:
173
174 std::vector<double> m_sumcos;
175 std::vector<double> m_sumbg;
176 std::vector<double> m_sumres_square;
177 std::vector<double> m_suminj;
178 std::vector<double> m_means;
179 std::vector<double> m_errors;
181 std::vector<int> m_sumsize;
182 std::vector<int> m_injsize;
185 double m_bgMin;
186 double m_bgMax;
189 double m_injMin;
190 double m_injMax;
193 double m_cosMin;
194 double m_cosMax;
197 double m_nhitMin;
198 double m_nhitMax;
200 double m_cut;
202 };
204} // namespace Belle2
double getMass() const
Particle mass.
Definition: UnitConst.cc:353
static const ChargedStable muon
muon particle
Definition: Const.h:660
static const ChargedStable pion
charged pion particle
Definition: Const.h:661
static const ChargedStable proton
proton particle
Definition: Const.h:663
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:662
static const ChargedStable electron
electron particle
Definition: Const.h:659
Class to prepare sample for fitting in beta gamma bins.
Definition: HadronBgPrep.h:43
void clearVars()
function to clear the variables
Definition: HadronBgPrep.h:138
void defineHisto(std::vector< TH1F * > &htemp, const std::string &svar, const std::string &stype, const std::string &pdg)
function to define histograms
std::vector< double > m_sumcos
variables to add cos values
Definition: HadronBgPrep.h:174
std::vector< double > m_suminj
variables to add injection time
Definition: HadronBgPrep.h:177
int m_nhitBins
bins for nhits
Definition: HadronBgPrep.h:196
int m_injBins
bins for injection time
Definition: HadronBgPrep.h:188
int m_cosBins
bins for cosine
Definition: HadronBgPrep.h:192
double getParticleMass(const std::string &particle)
function to get the particle mass
Definition: HadronBgPrep.h:160
void deleteHistos(std::vector< TH1F * > &htemp)
function to delete the histograms
Definition: HadronBgPrep.h:152
double m_cosMax
max range of cosine
Definition: HadronBgPrep.h:194
void printCanvasCos(std::map< int, std::vector< TH1F * > > &hchicos_allbg, std::map< int, std::vector< TH1F * > > &hchicos_1by3bg, std::map< int, std::vector< TH1F * > > &hchicos_2by3bg, std::map< int, std::vector< TH1F * > > &hchicos_3by3bg, const std::string &particle, const std::string &suffix)
function to draw the dedx vs costh histograms
int m_bgBins
bins for bg
Definition: HadronBgPrep.h:184
void fit(TH1F *&hist, const std::string &pdg)
function to fit the histograms
std::vector< double > m_means
mean variable
Definition: HadronBgPrep.h:178
std::vector< double > m_errors
error variable
Definition: HadronBgPrep.h:179
virtual ~HadronBgPrep()
Destructor.
Definition: HadronBgPrep.h:55
std::vector< int > m_sumsize
size of the bg bins
Definition: HadronBgPrep.h:181
void plotDist(std::map< int, std::vector< TH1F * > > &hist, const std::string &suffix, int bins)
function to plot the map of histograms
HadronBgPrep()
Constructor: Sets the description, the properties and the parameters of the algorithm.
Definition: HadronBgPrep.cc:12
void FormatGraph(TGraphErrors &gr, int flag, const std::string &name="")
function to set graph cosmetics
Definition: HadronBgPrep.h:110
double m_injMax
max range of injection time
Definition: HadronBgPrep.h:190
double m_nhitMax
max range of nhits
Definition: HadronBgPrep.h:198
std::vector< double > m_sumres_square
variables to add square of resolution
Definition: HadronBgPrep.h:176
double m_injMin
min range of injection time
Definition: HadronBgPrep.h:189
void setPars(TFile *&outfile, std::string pdg, std::vector< TH1F * > &hdedx_bg, std::vector< TH1F * > &hchi_bg, std::vector< TH1F * > &hionzsigma_bg, std::map< int, std::vector< TH1F * > > &hchi_inj)
function to fill the parameters like mean and reso in the tree
double m_bgMax
max range of bg
Definition: HadronBgPrep.h:186
std::vector< int > m_injsize
size of the injection bins
Definition: HadronBgPrep.h:182
double m_bgMin
min range of bg
Definition: HadronBgPrep.h:185
double m_cosMin
min range of cosine
Definition: HadronBgPrep.h:193
double m_cut
cut to clean protons
Definition: HadronBgPrep.h:200
std::vector< double > m_sumbg
variables to add bg values
Definition: HadronBgPrep.h:175
void fitGaussianWRange(TH1F *&temphist, gstatus &status, double sigmaR)
function to perform gauss fit for input histogram
double m_nhitMin
min range of nhits
Definition: HadronBgPrep.h:197
void prepareSample(std::shared_ptr< TTree > hadron, TFile *&outfile, const std::string &suffix, const std::string &bgcurvefile, const std::string &bgsigmafile, const std::string &pdg, bool ismakePlots)
function to prepare sample for monitoring plots, bg curve fitting and sigma vs ionz fitting
Definition: HadronBgPrep.cc:46
Abstract base class for different kinds of events.