10 #include <top/modules/TOPLaserCalibrator/TOPLaserCalibratorModule.h>
11 #include <top/modules/TOPLaserCalibrator/LaserCalibratorFit.h>
14 #include <framework/datastore/StoreArray.h>
17 #include <framework/logging/Logger.h>
21 #include <top/dataobjects/TOPDigit.h>
49 setDescription(
"T0 Calibration using the laser calibration system");
51 std::vector<double> frange = {100, 0., 1.};
53 addParam(
"dataFitOutput", m_dataFitOutput,
"Output root file for data",
55 addParam(
"mcInput", m_mcInput,
"Input root file from MC",
string(
""));
56 addParam(
"channelT0constant", m_chT0C,
"Output of channel T0 constant",
string(
""));
57 addParam(
"fitChannel", m_fitChannel,
"set 0 - 511 to a specific channel; set 0 to all channels in the fit",
59 addParam(
"barID", m_barID,
"ID of TOP module to calibrate");
60 addParam(
"refCh", m_refCh,
"reference channel of T0 constant");
61 addParam(
"fitMethod", m_fitMethod,
"gauss: single gaussian; cb: single Crystal Ball; cb2: double Crystal Ball",
string(
"gauss"));
62 addParam(
"fitRange", m_fitRange,
"fit range[nbins, xmin, xmax]", frange);
64 for (
int i = 0; i < c_NumChannels; ++i) {
69 TOPLaserCalibratorModule::~TOPLaserCalibratorModule()
73 void TOPLaserCalibratorModule::initialize()
75 B2WARNING(
"You are using an old version of the laser fitter, now deprecated. This module has been superseded by the CAF collector TOPLaserCalibratorCollector and the CAF fitter TOPLocalCalFitter.");
76 m_digits.isRequired();
79 void TOPLaserCalibratorModule::beginRun()
83 void TOPLaserCalibratorModule::event()
85 for (
auto& digit : m_digits) {
86 if (m_barID != 0 && digit.getModuleID() != m_barID)
continue;
87 unsigned channel = digit.getChannel();
88 if (channel < c_NumChannels) {
89 auto histo = m_histo[channel];
92 ss <<
"chan" << channel ;
95 string title =
"Times " + name;
96 histo =
new TH1F(name.c_str(), title.c_str(), (
int)m_fitRange[0], m_fitRange[1], m_fitRange[2]);
97 m_histo[channel] = histo;
99 if (digit.getHitQuality() != TOPDigit::EHitQuality::c_Good)
continue;
100 if (digit.getTime() < m_fitRange[1] || digit.getTime() > m_fitRange[2])
continue;
101 if (!digit.isTimeBaseCalibrated())
continue;
102 histo->Fill(digit.getTime());
107 void TOPLaserCalibratorModule::endRun()
111 void TOPLaserCalibratorModule::terminate()
113 std::vector<TH1F*> v_histo;
114 for (
int i = 0; i < c_NumChannels; ++i) {
115 v_histo.push_back(m_histo[i]);
118 double dataT[c_NumChannels] = {0};
119 double dataTErr[c_NumChannels] = {0};
120 double mcT[c_NumChannels] = {0};
126 if (m_fitChannel == c_NumChannels) {
127 for (
int i = 0; i < c_NumChannels; ++i) {
134 dataT[m_fitChannel] = t0fit.
getFitT();
140 auto mcFile =
new TFile(m_mcInput.c_str());
141 auto tree =
static_cast<TTree*
>(mcFile->Get(
"t0MC"));
145 tree->SetBranchAddress(
"channel", &channel_mc);
146 tree->SetBranchAddress(
"maxpos", &maxpos);
147 for (
int i = 0; i < tree->GetEntries(); i++) {
149 mcT[channel_mc] = maxpos;
153 for (
int i = 0; i < c_NumChannels; i++) {
154 if (i == m_refCh)
continue;
155 dataT[i] = dataT[i] - dataT[m_refCh];
156 mcT[i] = mcT[i] - mcT[m_refCh];
164 auto file =
new TFile(m_chT0C.c_str(),
"RECREATE");
165 auto otree =
new TTree(
"chT0",
"Channel T0 Const");
167 unsigned channel = 0;
169 double t0ConstRaw = 0;
170 double fittedTime = 0;
171 double fittedTimeError = 0;
173 double mcCorrection = 0;
174 double t0ConstError = 0;
176 otree->Branch(
"fittedTime", &fittedTime,
"fittedTime/D");
177 otree->Branch(
"fittedTimeError", &fittedTimeError,
"fittedTimeError/D");
178 otree->Branch(
"mcTime", &mcTime,
"mcTime/D");
179 otree->Branch(
"t0ConstRaw", &t0ConstRaw,
"t0ConstRaw/D");
180 otree->Branch(
"mcCorrection", &mcCorrection,
"mcCorrection/D");
181 otree->Branch(
"t0Const", &t0_const,
"t0_const/D");
182 otree->Branch(
"t0ConstError", &t0ConstError,
"t0ConstError/D");
183 otree->Branch(
"channel", &channel,
"channel/I");
184 otree->Branch(
"slot", &m_barID,
"slot/I");
186 for (
int i = 0; i < c_NumChannels; i++) {
188 fittedTime = dataT[i];
191 fittedTime = dataT[i] + dataT[m_refCh];
192 mcTime = mcT[i] + mcT[m_refCh];
194 fittedTimeError = dataTErr[i];
195 t0ConstRaw = dataT[i];
196 mcCorrection = mcT[i];
198 t0_const = dataT[i] - mcT[i];
200 t0ConstError = TMath::Sqrt(dataTErr[i] * dataTErr[i] + dataTErr[m_refCh] * dataTErr[m_refCh]);
203 t0ConstError = dataTErr[m_refCh];
T0 Laser calibration module (under development)
A class do laser calibration fit provide different fitting method (under development)
void setHist(const std::vector< TH1F * > &hist)
set time hist of all channels in one moduleID
double getFitT()
get mean positon after fit
void setFitMethod(const std::string &method)
set time fit function
void setFitRange(double xmin=-200, double xmax=200)
set x range in the fit
int fitChannel(unsigned channel)
fit for a specific channel
double getFitTErr()
returns the error mean positon after fit
void writeFile(const std::string &outfile)
write fit result to a root file
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.