Belle II Software development
CDCDedxMomentumAlgorithm.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 <reconstruction/calibration/CDCDedxMomentumAlgorithm.h>
10
11#include <reconstruction/dbobjects/CDCDedxMomentumCor.h>
12
13#include <TF1.h>
14#include <TH1F.h>
15#include <TCanvas.h>
16
17using namespace Belle2;
18
19
20//-----------------------------------------------------------------
21// Implementation
22//-----------------------------------------------------------------
23
25{
26 // Set module properties
27 setDescription("A calibration algorithm for CDC dE/dx electron cos(theta) dependence");
28}
29
30//-----------------------------------------------------------------
31// Run the calibration
32//-----------------------------------------------------------------
33
35{
36 // Get data objects
37 auto ttree = getObjectPtr<TTree>("tree");
38
39 // require at least 100 tracks (arbitrary for now)
40 if (ttree->GetEntries() < 100)
41 return c_NotEnoughData;
42
43 double dedx, p;
44 ttree->SetBranchAddress("dedx", &dedx);
45 ttree->SetBranchAddress("p", &p);
46
47 // make histograms to store dE/dx values in bins of cos(theta)
48 // bin size can be arbitrary, for now just make uniform bins
49 const int nbins = 100;
50 TH1F dedxp[nbins];
51 for (unsigned int i = 0; i < nbins; ++i) {
52 dedxp[i] = TH1F(TString::Format("dedxp%d", i), "dE/dx in bins of momentum", 200, 0, 4);
53 }
54
55 // fill histograms, bin size may be arbitrary
56 for (int i = 0; i < ttree->GetEntries(); ++i) {
57 ttree->GetEvent(i);
58 if (dedx == 0) continue;
59 if (p <= 0.0 || p > 10.0) continue;
60 int bin = std::floor(p / (10.0 / nbins));
61 if (bin < 0 || bin >= nbins) continue;
62 dedxp[bin].Fill(dedx);
63 }
64
65 // Print the histograms for quality control
66 TCanvas* ctmp = new TCanvas("tmp", "tmp", 900, 900);
67 ctmp->Divide(3, 3);
68 std::stringstream psname; psname << "dedx_momentum.ps[";
69 ctmp->Print(psname.str().c_str());
70 psname.str(""); psname << "dedx_momentum.ps";
71
72 // fit histograms to get gains in bins of cos(theta)
73 std::vector<double> momentum;
74 for (unsigned int i = 0; i < nbins; ++i) {
75 ctmp->cd(i % 9 + 1); // each canvas is 9x9
76 dedxp[i].DrawCopy("hist");
77
78 double mean = 1.0;
79 if (dedxp[i].Integral() < 10)
80 momentum.push_back(mean); // FIXME! --> should return not enough data
81 else {
82 if (dedxp[i].Fit("gaus")) {
83 B2WARNING("Fit failed...");
84 momentum.push_back(mean); // FIXME! --> should return not enough data
85 } else {
86 B2WARNING("Fit succeeded: " << mean << "\t" << dedxp[i].GetFunction("gaus")->GetParameter(1));
87 mean *= dedxp[i].GetFunction("gaus")->GetParameter(1);
88 momentum.push_back(mean);
89 }
90 }
91 if ((i + 1) % 9 == 0)
92 ctmp->Print(psname.str().c_str());
93 }
94
95 psname.str(""); psname << "dedx_momentum.ps]";
96 ctmp->Print(psname.str().c_str());
97
98 B2INFO("dE/dx Calibration done for CDC dE/dx momentum correction");
99 std::cout << "dE/dx Calibration done for CDC dE/dx momentum correction" << std::endl;
100
101 CDCDedxMomentumCor* gain = new CDCDedxMomentumCor(momentum);
102 saveCalibration(gain, "CDCDedxMomentumCor");
103
104 delete ctmp;
105
106 return c_OK;
107}
CDCDedxMomentumAlgorithm()
Constructor: Sets the description, the properties and the parameters of the algorithm.
virtual EResult calibrate() override
Scale Momentum algorithm.
dE/dx wire gain calibration constants
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
EResult
The result of calibration.
@ c_OK
Finished successfuly =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
Abstract base class for different kinds of events.