Belle II Software development
CDCDedxHadSatAlgorithm.cc
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#include <cdc/calibration/CDCdEdx/CDCDedxHadSatAlgorithm.h>
10
11using namespace Belle2;
12
13//-----------------------------------------------------------------
14// Implementation
15//-----------------------------------------------------------------
17 CalibrationAlgorithm("CDCDedxHadronCollector"),
18 m_ismakePlots(true),
19 m_suffix("")
20{
21 // Set module properties
22 setDescription("A calibration algorithm for CDC dE/dx hadron saturation");
23}
24
25//-----------------------------------------------------------------
26// Run the calibration
27//-----------------------------------------------------------------
29{
30
31 gROOT->SetBatch();
33
34 //existing hadron saturation payload for merging
35 if (!m_DBHadronCor.isValid())
36 B2FATAL("There is no valid payload for Hadron saturation");
37
38 // particle list
39 std::vector<std::string> particles = {"pion", "kaon", "muon", "proton"};
40
41 // check we have enough data
42 for (int i = 0; i < int(particles.size()); i++) {
43 std::string p = particles[i];
44 auto tree = getObjectPtr<TTree>(Form("%s", p.data()));
45 if (!tree) return c_NotEnoughData;
46 }
47
48 gSystem->Exec("mkdir -p plots/HadronSat");
49
50 // save plots with no had saturation correction
51 std::string filename = "widget_uncorrected_NoHSpar_2D.root";
52 prepareSample(particles, filename, "noSat", false);
53
54 // save plots with default had saturation correction
55 filename = "widget_corrected_defHSpar_2D.root";
56 prepareSample(particles, filename, "defSat", true);
57
58 double par[5];
59 for (int i = 0; i < 5; ++i) par[i] = m_DBHadronCor->getHadronPar(i);
60
61 HadronSaturation hadsat(par[0], par[1], par[2], par[3], par[4], m_cosBins);
62
63 hadsat.fillSample("widget_uncorrected_NoHSpar_2D.root");
64
65 // perform the hadron saturation correction
66 hadsat.fitSaturation();
67
68 // save plots with new had saturation correction
69 filename = "widget_corrected_newHSpar_2D.root";
70 prepareSample(particles, filename, "newSat", true);
71
72 B2INFO("Saving calibration for: " << m_suffix << "");
74
75 return c_OK;
76}
77
78
79//------------------------------------
81{
82 int cruns = 0;
83 for (auto expRun : getRunList()) {
84 if (cruns == 0)B2INFO("CDCDedxInjectTimeAlgorithm: start exp " << expRun.first << " and run " << expRun.second << "");
85 cruns++;
86 }
87
88 const auto erStart = getRunList()[0];
89 int estart = erStart.first;
90 int rstart = erStart.second;
91
92 updateDBObjPtrs(1, erStart.second, erStart.first);
93
94 m_suffix = Form("e%dr%d", estart, rstart);
95 B2INFO("tool exp = " << estart << ", run = " << rstart << ", m_suffix = " << m_suffix << "");
96}
97
98//--------------------------
100{
101
102 std::ifstream fin("sat-pars.fit.txt");
103 if (!fin.good()) B2FATAL("\tWARNING: CANNOT FIND sat-pars.fit.txt!");
104
105 double hadsatpars;
106 std::vector<double> v_hadsatpars;
107
108 B2INFO("\t --> Hadron saturation parameters");
109 for (int i = 0; i < 5; ++i) {
110 fin >> hadsatpars;
111 v_hadsatpars.push_back(hadsatpars);
112 B2INFO("\t\t (" << i << ")" << v_hadsatpars[i]);
113 }
114 fin.close();
115
116 B2INFO("dE/dx Calibration done for " << v_hadsatpars.size() << " CDC Hadron saturation");
117 CDCDedxHadronCor* gains = new CDCDedxHadronCor(0, v_hadsatpars);
118 saveCalibration(gains, "CDCDedxHadronCor");
119
120}
121
122void CDCDedxHadSatAlgorithm::prepareSample(std::vector< std::string >& particles, const std::string& filename,
123 const std::string& sfx,
124 bool correct)
125{
126 TFile* outfile = new TFile(Form("%s", filename.data()), "RECREATE");
127
128 for (int i = 0; i < int(particles.size()); i++) {
129
130 // strip the name of the particle lists to make this work
131 std::string p = particles[i];
132 auto tree = getObjectPtr<TTree>(Form("%s", p.data()));
133
134 HadronPrep prep(m_bgpar[p][0], m_bgpar[p][1], m_bgpar[p][2], m_cosBins, m_cosMin, m_cosMax, m_cut);
135 prep.prepareSample(tree, outfile, Form("%s_%s", m_suffix.data(), sfx.data()), p.data(), m_ismakePlots, correct);
136
137 }
138 outfile->Close();
139}
std::map< std::string, std::array< double, 3 > > m_bgpar
bg bins, min, max for different particles
DBObjPtr< CDCDedxHadronCor > m_DBHadronCor
db object for dE/dx hadron saturation parameters
void getExpRunInfo()
function to get exp/run information (payload object, plotting)
CDCDedxHadSatAlgorithm()
Constructor: Sets the description, the properties and the parameters of the algorithm.
void prepareSample(std::vector< std::string > &particles, const std::string &filename, const std::string &sfx, bool correct)
function to prepare sample for bgcurve hadron saturation and monitoring plots
bool m_ismakePlots
produce plots for monitoring
std::string m_suffix
string suffix for object names
virtual EResult calibrate() override
CDC dE/dx Hadron saturation algorithm.
void createPayload()
function to store payloads after full calibration
dE/dx hadron saturation parameterization constants
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
void updateDBObjPtrs(const unsigned int event, const int run, const int experiment)
Updates any DBObjPtrs by calling update(event) for DBStore.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
CalibrationAlgorithm(const std::string &collectorModuleName)
Constructor - sets the prefix for collected objects (won't be accesses until execute(....
Class to prepare sample for hadron saturation calibration.
Definition HadronPrep.h:40
void prepareSample(std::shared_ptr< TTree > hadron, TFile *&outfile, const std::string &suffix, const std::string &pdg, bool ismakePlots, bool correct)
function to prepare sample for monitoring plots, bg curve fitting and sigma vs ionz fitting
Definition HadronPrep.cc:34
Class to perform the hadron saturation calibration.
void fillSample(TString infilename)
fill the vectors below
void fitSaturation()
perform the hadron saturation fit
std::shared_ptr< T > getObjectPtr(const std::string &name, const std::vector< Calibration::ExpRun > &requestedRuns)
Get calibration data object by name and list of runs, the Merge function will be called to generate t...
Abstract base class for different kinds of events.