8#include <cdc/calibration/CrudeT0CalibrationAlgorithm.h>
9#include <calibration/CalibrationAlgorithm.h>
10#include <cdc/geometry/CDCGeometryPar.h>
11#include <cdc/dbobjects/CDCTimeZeros.h>
12#include <framework/gearbox/Const.h>
19#include <framework/datastore/StoreObjPtr.h>
20#include <framework/database/Database.h>
21#include <framework/database/DBObjPtr.h>
22#include <framework/database/IntervalOfValidity.h>
23#include <framework/database/DBImportObjPtr.h>
24#include <framework/logging/Logger.h>
33 " -------------------------- T0 Calibration Algorithm -------------------------\n"
41 B2INFO(
"CreateHisto");
45 B2INFO(
"Changed ExpRun to: " << exprun[0].first <<
" " << exprun[0].second);
46 evtPtr->setExperiment(exprun[0].first);
47 evtPtr->setRun(exprun[0].second);
49 B2INFO(
"create TDChist");
51 for (
int il = 0; il < 56; ++il) {
52 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
57 B2INFO(
"create TDChist(board)");
58 for (
int ib = 0; ib < 300; ++ib) {
61 m_hT0All =
new TH1D(
"hT0All",
"", 8500, 0, 8500);
66 auto tree = getObjectPtr<TTree>(
"tree");
67 tree->SetBranchAddress(
"lay", &lay);
68 tree->SetBranchAddress(
"wire", &wire);
69 tree->SetBranchAddress(
"tdc", &tdc);
71 const int nEntries = tree->GetEntries();
73 for (
int i = 0; i < nEntries ; ++i) {
75 m_hTDC[lay][wire]->Fill(tdc);
79 B2INFO(
"end of filling hist");
84 B2INFO(
"Start calibration");
87 gErrorIgnoreLevel = 3001;
95 B2INFO(
"Registering EventMetaData object in DataStore");
98 B2INFO(
"Creating EventMetaData object");
101 B2INFO(
"A valid EventMetaData object already exists.");
107 B2INFO(
"ExpRun at init : " << evtPtr->getExperiment() <<
" " << evtPtr->getRun());
111 TH1D* hs =
new TH1D(
"hs",
"sigma", 100, 0, 20);
112 std::vector<double> sb;
113 std::vector<double> dsb;
114 std::vector<double> t0b;
115 std::vector<double> dt0b;
116 std::vector<double> b;
117 std::vector<double> db;
120 TF1* f1 =
new TF1(
"f1",
"[0]+[1]*(exp([2]*(x-[3]))/(1+exp(-([4]-x)/[5])))",
m_tdcMin,
m_tdcMax);
121 f1->SetParLimits(0, 0., 1000.);
122 f1->SetLineColor(kRed);
124 bool bflag[300] = {
false};
126 for (
int ib = 1; ib < 300; ++ib) {
128 B2DEBUG(199,
"Warning: this board low statistic: " <<
m_hTDCBoard[ib]->GetEntries());
137 if ((fabs(f1->GetParameter(4) -
m_initT0) > 100)
138 || (fabs(f1->GetParameter(5)) < 0.01)
139 || (fabs(f1->GetParameter(5)) > 16)) {
147 m_t0b[ib] = f1->GetParameter(4) * tdcBinWidth;
149 sb.push_back(f1->GetParameter(5));
150 dsb.push_back(f1->GetParError(5));
151 t0b.push_back(f1->GetParameter(4));
152 dt0b.push_back(f1->GetParError(4));
157 for (
int il = 0; il < 56; ++il) {
158 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
159 B2DEBUG(99,
"fitting for channel: " << il <<
" - " << w);
160 B2DEBUG(99,
"number of entries" <<
m_hTDC[il][w]->GetEntries());
164 B2DEBUG(99,
"Warning: low statistic channel: " <<
m_hTDC[il][w]->GetEntries());
165 if (bflag[bid] !=
false) {
172 double p3 =
m_hTDC[il][w]->GetXaxis()->GetBinCenter(
m_hTDC[il][w]->GetMaximumBin());
173 f1->SetParameters(0,
m_hTDC[il][w]->GetMaximum(), -0.001, p3,
m_initT0, 2.5);
175 B2DEBUG(99,
"prob of fit : " << f1->GetProb());
176 if ((f1->GetProb() < 1
E-150) || (fabs(f1->GetParameter(4) -
m_initT0) > 100) || (f1->GetParameter(5) < 0.1)
177 || (f1->GetParameter(5) > 20)) {
178 if (bflag[bid] != 0) {
185 m_t0[il][w] = f1->GetParameter(4) * tdcBinWidth;
186 hs->Fill(f1->GetParameter(5));
191 B2DEBUG(99,
"P4 = " <<
m_t0[il][w]);
198 m_t0[il][w] += 6.122;
203 B2INFO(
"Write constants");
213 B2INFO(
"Changed ExpRun to: " << exprun[0].first <<
" " << exprun[0].second);
214 evtPtr->setExperiment(exprun[0].first);
215 evtPtr->setRun(exprun[0].second);
219 for (
int ilay = 0; ilay < 56; ++ilay) {
220 for (
unsigned int iwire = 0; iwire < cdcgeo.
nWiresInLayer(ilay); ++iwire) {
221 WireID wireid(ilay, iwire);
231 TFile* fhist =
new TFile(
"histCrudeT0.root",
"recreate");
233 TDirectory* top = gDirectory;
234 TDirectory* Direct[56];
235 for (
int il = 0; il < 56; ++il) {
237 Direct[il] = gDirectory->mkdir(Form(
"lay_%d", il));
239 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
246 TDirectory* board = gDirectory->mkdir(
"board");
248 for (
int ib = 0; ib < 300; ++ib) {
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
Database object for timing offset (t0).
void setT0(unsigned short iCLayer, unsigned short iWire, float t0)
Set t0 in the list.
The Class for CDC Geometry Parameters.
unsigned short getBoardID(const WireID &wID) const
Returns frontend board id. corresponding to the wire id.
const B2Vector3D wireBackwardPosition(uint layerId, int cellId, EWirePosition set=c_Base) const
Returns the backward position of the input sense wire.
double getTdcBinWidth() const
Return TDC bin width (nsec).
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
double senseWireR(int layerId) const
Returns radius of sense wire in each layer.
TH1D * m_hT0All
T0 distribution of all channel.
unsigned short m_tdcMax
maximum of TDC hist for fitting
TH1D * m_hTDCBoard[300]
T0 distribution of each board.
float m_initT0
Common initial T0 for fitting.
bool m_flag[56][400]
flag =1 for good, =0 for low statistic or bad fit
void saveHisto()
Save hitograms of the calibration results.
bool m_cosmic
for cosmic case, tof of upper sector will be negative
virtual void createHisto(StoreObjPtr< EventMetaData > &evtPtr)
create histo for each channel
CrudeT0CalibrationAlgorithm()
Constructor.
double m_t0[56][400]
T0 of each channel.
double m_t0b[300]
T0 for each board.
unsigned short m_tdcMin
minimum of TDC hist for fitting
virtual void write(StoreObjPtr< EventMetaData > &evtPtr)
write outut or store db
unsigned short m_minEntries
minimum entries required by histo.
EResult calibrate() override
Run algo on data.
TH1D * m_hTDC[56][400]
TDC distribution histo.
float m_zOffset
z offset for calculate prop time, it is position of trigger counter,
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 successfully =0 in Python.
static const double speedOfLight
[cm/ns]
Class for accessing objects in the database.
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Type-safe access to single objects in the data store.
bool isValid() const
Check whether the object was created.
Class to identify a wire inside the CDC.
static DBStore & Instance()
Instance of a singleton DBStore.
void update()
Updates all objects that are outside their interval of validity.
Abstract base class for different kinds of events.