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/DBObjPtr.h>
21#include <framework/logging/Logger.h>
30 " -------------------------- T0 Calibration Algorithm -------------------------\n"
38 B2INFO(
"CreateHisto");
42 B2INFO(
"Changed ExpRun to: " << exprun[0].first <<
" " << exprun[0].second);
43 evtPtr->setExperiment(exprun[0].first);
44 evtPtr->setRun(exprun[0].second);
46 B2INFO(
"create TDChist");
48 for (
int il = 0; il < 56; ++il) {
49 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
54 B2INFO(
"create TDChist(board)");
55 for (
int ib = 0; ib < 300; ++ib) {
58 m_hT0All =
new TH1D(
"hT0All",
"", 8500, 0, 8500);
64 tree->SetBranchAddress(
"lay", &lay);
65 tree->SetBranchAddress(
"wire", &wire);
66 tree->SetBranchAddress(
"tdc", &tdc);
68 const int nEntries = tree->GetEntries();
70 for (
int i = 0; i < nEntries ; ++i) {
72 m_hTDC[lay][wire]->Fill(tdc);
76 B2INFO(
"end of filling hist");
81 B2INFO(
"Start calibration");
84 gErrorIgnoreLevel = 3001;
92 B2INFO(
"Registering EventMetaData object in DataStore");
95 B2INFO(
"Creating EventMetaData object");
98 B2INFO(
"A valid EventMetaData object already exists.");
104 B2INFO(
"ExpRun at init : " << evtPtr->getExperiment() <<
" " << evtPtr->getRun());
108 TH1D* hs =
new TH1D(
"hs",
"sigma", 100, 0, 20);
109 std::vector<double> sb;
110 std::vector<double> dsb;
111 std::vector<double> t0b;
112 std::vector<double> dt0b;
113 std::vector<double> b;
114 std::vector<double> db;
117 TF1* f1 =
new TF1(
"f1",
"[0]+[1]*(exp([2]*(x-[3]))/(1+exp(-([4]-x)/[5])))",
m_tdcMin,
m_tdcMax);
118 f1->SetParLimits(0, 0., 1000.);
119 f1->SetLineColor(kRed);
121 bool bflag[300] = {
false};
123 for (
int ib = 1; ib < 300; ++ib) {
125 B2DEBUG(199,
"Warning: this board low statistic: " <<
m_hTDCBoard[ib]->GetEntries());
134 if ((fabs(f1->GetParameter(4) -
m_initT0) > 100)
135 || (fabs(f1->GetParameter(5)) < 0.01)
136 || (fabs(f1->GetParameter(5)) > 16)) {
144 m_t0b[ib] = f1->GetParameter(4) * tdcBinWidth;
146 sb.push_back(f1->GetParameter(5));
147 dsb.push_back(f1->GetParError(5));
148 t0b.push_back(f1->GetParameter(4));
149 dt0b.push_back(f1->GetParError(4));
154 for (
int il = 0; il < 56; ++il) {
155 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
156 B2DEBUG(99,
"fitting for channel: " << il <<
" - " << w);
157 B2DEBUG(99,
"number of entries" <<
m_hTDC[il][w]->GetEntries());
161 B2DEBUG(99,
"Warning: low statistic channel: " <<
m_hTDC[il][w]->GetEntries());
162 if (bflag[bid] !=
false) {
169 double p3 =
m_hTDC[il][w]->GetXaxis()->GetBinCenter(
m_hTDC[il][w]->GetMaximumBin());
170 f1->SetParameters(0,
m_hTDC[il][w]->GetMaximum(), -0.001, p3,
m_initT0, 2.5);
172 B2DEBUG(99,
"prob of fit : " << f1->GetProb());
173 if ((f1->GetProb() < 1
E-150) || (fabs(f1->GetParameter(4) -
m_initT0) > 100) || (f1->GetParameter(5) < 0.1)
174 || (f1->GetParameter(5) > 20)) {
175 if (bflag[bid] != 0) {
182 m_t0[il][w] = f1->GetParameter(4) * tdcBinWidth;
183 hs->Fill(f1->GetParameter(5));
188 B2DEBUG(99,
"P4 = " <<
m_t0[il][w]);
195 m_t0[il][w] += 6.122;
200 B2INFO(
"Write constants");
210 B2INFO(
"Changed ExpRun to: " << exprun[0].first <<
" " << exprun[0].second);
211 evtPtr->setExperiment(exprun[0].first);
212 evtPtr->setRun(exprun[0].second);
216 for (
int ilay = 0; ilay < 56; ++ilay) {
217 for (
unsigned int iwire = 0; iwire < cdcgeo.
nWiresInLayer(ilay); ++iwire) {
218 WireID wireid(ilay, iwire);
228 TFile* fhist =
new TFile(
"histCrudeT0.root",
"recreate");
230 TDirectory* top = gDirectory;
231 TDirectory* Direct[56];
232 for (
int il = 0; il < 56; ++il) {
234 Direct[il] = gDirectory->mkdir(Form(
"lay_%d", il));
236 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
243 TDirectory* board = gDirectory->mkdir(
"board");
245 for (
int ib = 0; ib < 300; ++ib) {
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 output 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,
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.
CalibrationAlgorithm(const std::string &collectorModuleName)
Constructor - sets the prefix for collected objects (won't be accesses until execute(....
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.
std::shared_ptr< T > getObjectPtr(const std::string &name, const std::vector< Calibration::ExpRun > &requestedRuns)
Get calibration data object by name and list of runs, the Merge function will be called to generate t...
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.