Belle II Software development
TOPEventT0OffsetAlgorithm.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 <top/calibration/TOPEventT0OffsetAlgorithm.h>
10#include <top/dbobjects/TOPCalEventT0Offset.h>
11#include <framework/gearbox/Const.h>
12#include <string>
13#include <map>
14#include <TROOT.h>
15#include <TH1F.h>
16#include <TF1.h>
17
18using namespace std;
19
20namespace Belle2 {
25 namespace TOP {
26
28 CalibrationAlgorithm("TOPOffsetCollector")
29 {
30 setDescription("Calibration algorithm for event T0 offset calibration");
31 }
32
34 {
35 gROOT->SetBatch();
36
37 // construct file name and open output root file
38
39 const auto& expRun = getRunList();
40 string expNo = to_string(expRun[0].first);
41 while (expNo.length() < 4) expNo.insert(0, "0");
42 string runNo = to_string(expRun[0].second);
43 while (runNo.length() < 5) runNo.insert(0, "0");
44 string outputFileName = "evenT0Offset-e" + expNo + "-r" + runNo + ".root";
45 auto* file = TFile::Open(outputFileName.c_str(), "recreate");
46
47 // object to store the results
48
49 auto* eventT0Offset = new TOPCalEventT0Offset();
50
51 // fit histograms and store the results
52
53 std::map<Const::EDetector, std::string> names;
54 names[Const::SVD] = "svdOffset";
55 names[Const::CDC] = "cdcOffset";
56 for (const auto& x : names) {
57 auto h = getObjectPtr<TH1F>(x.second);
58 if (not h) continue;
59 double sum = h->Integral();
60 if (sum > m_minEntries) {
61 auto* func = new TF1("func1g",
62 "[0] + [1]/sqrt(2*pi)/[3]*exp(-0.5*((x-[2])/[3])**2)",
63 h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax());
64 func->SetParameter(0, 0);
65 func->SetParameter(1, sum * h->GetBinWidth(1));
66 func->SetParameter(2, h->GetBinCenter(h->GetMaximumBin()));
67 func->SetParameter(3, m_sigma);
68 int status = h->Fit(func, "LRSQ");
69 if (status == 0) eventT0Offset->set(x.first, func->GetParameter(2), std::abs(func->GetParameter(3)));
70 }
71 h->Write();
72 }
73
74 file->Close();
75
76 if (eventT0Offset->isEmpty()) {
77 delete eventT0Offset;
78 return c_NotEnoughData;
79 }
80
81 saveCalibration(eventT0Offset);
82
83 return c_OK;
84 }
85
86 } // end namespace TOP
88} // end namespace Belle2
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)
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 successfuly =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
Class to store the calibrated EventT0 offsets of other detector components The offsets are measured r...
int m_minEntries
minimal number of entries to perform fit
virtual EResult calibrate() final
algorithm implementation
double m_sigma
initial value for Gaussian width [ns]
Abstract base class for different kinds of events.
STL namespace.