10#include <top/modules/TOPLaserCalibrator/TOPLaserCalibratorModule.h>
13#include <top/modules/TOPLaserCalibrator/LaserCalibratorFit.h>
16#include <framework/datastore/StoreArray.h>
19#include <framework/logging/Logger.h>
23#include <top/dataobjects/TOPDigit.h>
51 setDescription(
"T0 Calibration using the laser calibration system");
53 std::vector<double> frange = {100, 0., 1.};
58 addParam(
"channelT0constant",
m_chT0C,
"Output of channel T0 constant",
string(
""));
59 addParam(
"fitChannel",
m_fitChannel,
"set 0 - 511 to a specific channel; set 0 to all channels in the fit",
63 addParam(
"fitMethod",
m_fitMethod,
"gauss: single gaussian; cb: single Crystal Ball; cb2: double Crystal Ball",
string(
"gauss"));
66 for (
int i = 0; i < c_NumChannels; ++i) {
73 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.");
81 unsigned channel = digit.getChannel();
82 if (channel < c_NumChannels) {
86 ss <<
"chan" << channel ;
89 string title =
"Times " + name;
93 if (digit.getHitQuality() != TOPDigit::EHitQuality::c_Good)
continue;
95 if (!digit.isTimeBaseCalibrated())
continue;
96 histo->Fill(digit.getTime());
103 std::vector<TH1F*> v_histo;
104 for (
int i = 0; i < c_NumChannels; ++i) {
108 double dataT[c_NumChannels] = {0};
109 double dataTErr[c_NumChannels] = {0};
110 double mcT[c_NumChannels] = {0};
117 for (
int i = 0; i < c_NumChannels; ++i) {
130 auto mcFile =
new TFile(
m_mcInput.c_str());
131 auto tree =
static_cast<TTree*
>(mcFile->Get(
"t0MC"));
135 tree->SetBranchAddress(
"channel", &channel_mc);
136 tree->SetBranchAddress(
"maxpos", &maxpos);
137 for (
int i = 0; i < tree->GetEntries(); i++) {
139 mcT[channel_mc] = maxpos;
143 for (
int i = 0; i < c_NumChannels; i++) {
145 dataT[i] = dataT[i] - dataT[
m_refCh];
146 mcT[i] = mcT[i] - mcT[
m_refCh];
154 auto file =
new TFile(
m_chT0C.c_str(),
"RECREATE");
155 auto otree =
new TTree(
"chT0",
"Channel T0 Const");
157 unsigned channel = 0;
159 double t0ConstRaw = 0;
160 double fittedTime = 0;
161 double fittedTimeError = 0;
163 double mcCorrection = 0;
164 double t0ConstError = 0;
166 otree->Branch(
"fittedTime", &fittedTime,
"fittedTime/D");
167 otree->Branch(
"fittedTimeError", &fittedTimeError,
"fittedTimeError/D");
168 otree->Branch(
"mcTime", &mcTime,
"mcTime/D");
169 otree->Branch(
"t0ConstRaw", &t0ConstRaw,
"t0ConstRaw/D");
170 otree->Branch(
"mcCorrection", &mcCorrection,
"mcCorrection/D");
171 otree->Branch(
"t0Const", &t0_const,
"t0_const/D");
172 otree->Branch(
"t0ConstError", &t0ConstError,
"t0ConstError/D");
173 otree->Branch(
"channel", &channel,
"channel/I");
174 otree->Branch(
"slot", &
m_barID,
"slot/I");
176 for (
int i = 0; i < c_NumChannels; i++) {
178 fittedTime = dataT[i];
181 fittedTime = dataT[i] + dataT[
m_refCh];
182 mcTime = mcT[i] + mcT[
m_refCh];
184 fittedTimeError = dataTErr[i];
185 t0ConstRaw = dataT[i];
186 mcCorrection = mcT[i];
188 t0_const = dataT[i] - mcT[i];
190 t0ConstError = TMath::Sqrt(dataTErr[i] * dataTErr[i] + dataTErr[
m_refCh] * dataTErr[
m_refCh]);
193 t0ConstError = dataTErr[
m_refCh];
void setDescription(const std::string &description)
Sets the description of the module.
std::vector< double > m_fitRange
fit range [nbins, xmin, xmax]
int m_fitChannel
set 0 - 511 to a specific pixelID in the fit; set 512 to fit all pixels in one slot
int m_barID
ID of TOP module to calibrate.
std::string m_mcInput
Input root file from MC.
StoreArray< TOPDigit > m_digits
collection of digits
int m_refCh
reference channel of T0 constant
std::string m_chT0C
Output of channel T0 constant.
TH1F * m_histo[c_NumChannels]
profile histograms
std::string m_fitMethod
gauss: single gaussian; cb: single Crystal Ball; cb2: double Crystal Ball
std::string m_dataFitOutput
output root file for data
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 position 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 position after fit
void writeFile(const std::string &outfile)
write fit result to a root file
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
TOPLaserCalibratorModule()
Constructor.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void terminate() override
Termination action.
Abstract base class for different kinds of events.