 |
Belle II Software
release-05-01-25
|
1 #include <cdc/calibration/CrudeT0CalibrationAlgorithm.h>
2 #include <calibration/CalibrationAlgorithm.h>
3 #include <cdc/geometry/CDCGeometryPar.h>
4 #include <cdc/dbobjects/CDCTimeZeros.h>
5 #include <framework/gearbox/Const.h>
12 #include <framework/datastore/StoreObjPtr.h>
13 #include <framework/database/Database.h>
14 #include <framework/database/DBObjPtr.h>
15 #include <framework/database/IntervalOfValidity.h>
16 #include <framework/database/DBImportObjPtr.h>
17 #include <framework/logging/Logger.h>
26 " -------------------------- T0 Calibration Algorithm -------------------------\n"
34 B2INFO(
"CreateHisto");
38 B2INFO(
"Changed ExpRun to: " << exprun[0].first <<
" " << exprun[0].second);
39 evtPtr->setExperiment(exprun[0].first);
40 evtPtr->setRun(exprun[0].second);
42 B2INFO(
"create TDChist");
44 for (
int il = 0; il < 56; ++il) {
45 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
50 B2INFO(
"create TDChist(board)");
51 for (
int ib = 0; ib < 300; ++ib) {
54 m_hT0All =
new TH1D(
"hT0All",
"", 8500, 0, 8500);
59 auto tree = getObjectPtr<TTree>(
"tree");
60 tree->SetBranchAddress(
"lay", &lay);
61 tree->SetBranchAddress(
"wire", &wire);
62 tree->SetBranchAddress(
"tdc", &tdc);
64 const int nEntries = tree->GetEntries();
66 for (
int i = 0; i < nEntries ; ++i) {
68 m_hTDC[lay][wire]->Fill(tdc);
72 B2INFO(
"end of filling hist");
77 B2INFO(
"Start calibration");
80 gErrorIgnoreLevel = 3001;
88 B2INFO(
"Registering EventMetaData object in DataStore");
89 evtPtr.registerInDataStore();
91 B2INFO(
"Creating EventMetaData object");
94 B2INFO(
"A valid EventMetaData object already exists.");
100 B2INFO(
"ExpRun at init : " << evtPtr->getExperiment() <<
" " << evtPtr->getRun());
104 TH1D* hs =
new TH1D(
"hs",
"sigma", 100, 0, 20);
105 std::vector<double> sb;
106 std::vector<double> dsb;
107 std::vector<double> t0b;
108 std::vector<double> dt0b;
109 std::vector<double> b;
110 std::vector<double> db;
113 TF1* f1 =
new TF1(
"f1",
"[0]+[1]*(exp([2]*(x-[3]))/(1+exp(-([4]-x)/[5])))",
m_tdcMin,
m_tdcMax);
114 f1->SetParLimits(0, 0., 1000.);
115 f1->SetLineColor(kRed);
117 bool bflag[300] = {
false};
119 for (
int ib = 1; ib < 300; ++ib) {
121 B2DEBUG(199,
"Warning: this board low statistic: " <<
m_hTDCBoard[ib]->GetEntries());
130 if ((fabs(f1->GetParameter(4) -
m_initT0) > 100)
131 || (fabs(f1->GetParameter(5)) < 0.01)
132 || (fabs(f1->GetParameter(5)) > 16)) {
140 m_t0b[ib] = f1->GetParameter(4) * tdcBinWidth;
142 sb.push_back(f1->GetParameter(5));
143 dsb.push_back(f1->GetParError(5));
144 t0b.push_back(f1->GetParameter(4));
145 dt0b.push_back(f1->GetParError(4));
150 for (
int il = 0; il < 56; ++il) {
151 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
152 B2DEBUG(99,
"fitting for channel: " << il <<
" - " << w);
153 B2DEBUG(99,
"number of entries" <<
m_hTDC[il][w]->GetEntries());
157 B2DEBUG(99,
"Warning: low statistic channel: " <<
m_hTDC[il][w]->GetEntries());
158 if (bflag[bid] !=
false) {
165 double p3 =
m_hTDC[il][w]->GetXaxis()->GetBinCenter(
m_hTDC[il][w]->GetMaximumBin());
166 f1->SetParameters(0,
m_hTDC[il][w]->GetMaximum(), -0.001, p3,
m_initT0, 2.5);
168 B2DEBUG(99,
"prob of fit : " << f1->GetProb());
169 if ((f1->GetProb() < 1E-150) || (fabs(f1->GetParameter(4) -
m_initT0) > 100) || (f1->GetParameter(5) < 0.1)
170 || (f1->GetParameter(5) > 20)) {
171 if (bflag[bid] != 0) {
178 m_t0[il][w] = f1->GetParameter(4) * tdcBinWidth;
179 hs->Fill(f1->GetParameter(5));
184 B2DEBUG(99,
"P4 = " <<
m_t0[il][w]);
191 m_t0[il][w] += 6.122;
196 B2INFO(
"Write constants");
206 B2INFO(
"Changed ExpRun to: " << exprun[0].first <<
" " << exprun[0].second);
207 evtPtr->setExperiment(exprun[0].first);
208 evtPtr->setRun(exprun[0].second);
212 for (
int ilay = 0; ilay < 56; ++ilay) {
213 for (
unsigned int iwire = 0; iwire < cdcgeo.
nWiresInLayer(ilay); ++iwire) {
214 WireID wireid(ilay, iwire);
224 TFile* fhist =
new TFile(
"histCrudeT0.root",
"recreate");
226 TDirectory* top = gDirectory;
227 TDirectory* Direct[56];
228 for (
int il = 0; il < 56; ++il) {
230 Direct[il] = gDirectory->mkdir(Form(
"lay_%d", il));
232 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
239 TDirectory* board = gDirectory->mkdir(
"board");
241 for (
int ib = 0; ib < 300; ++ib) {
Class to identify a wire inside the CDC.
virtual void createHisto(StoreObjPtr< EventMetaData > &evtPtr)
create histo for each channel
bool m_cosmic
for cosmic case, tof of upper sector will be negative
static DataStore & Instance()
Instance of singleton Store.
TH1D * m_hTDC[56][400]
TDC distribution histo.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
void setInitializeActive(bool active)
Setter for m_initializeActive.
unsigned short m_minEntries
minimum entries required by histo.
void setT0(unsigned short iCLayer, unsigned short iWire, float t0)
Set t0 in the list.
float m_initT0
Common initial T0 for fitting.
EResult calibrate() override
Run algo on data.
double getTdcBinWidth() const
Return TDC bin width (nsec).
@ c_OK
Finished successfuly =0 in Python.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
float m_zOffset
z offset for calculate prop time, it is position of trigger counter,
Class for accessing objects in the database.
static const double speedOfLight
[cm/ns]
The Class for CDC Geometry Parameters.
double senseWireR(int layerId) const
Returns radius of sense wire in each layer.
const TVector3 wireBackwardPosition(int layerId, int cellId, EWirePosition set=c_Base) const
Returns the backward position of the input sense wire.
unsigned short m_tdcMax
maximum of TDC hist for fitting
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
Abstract base class for different kinds of events.
Type-safe access to single objects in the data store.
Database object for timing offset (t0).
unsigned short getBoardID(const WireID &wID) const
Returns frontend board id. corresponding to the wire id.
static DBStore & Instance()
Instance of a singleton DBStore.
double m_t0[56][400]
T0 of each channel.
double m_t0b[300]
T0 for each board.
EResult
The result of calibration.
unsigned short m_tdcMin
minimum of TDC hist for fitting
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
bool m_flag[56][400]
flag =1 for good, =0 for low statistic or bad fit
TH1D * m_hT0All
T0 distribution of all channel.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
TH1D * m_hTDCBoard[300]
T0 distribution of each board.
Base class for calibration algorithms.
virtual void write(StoreObjPtr< EventMetaData > &evtPtr)
write outut or store db
void update()
Updates all objects that are outside their interval of validity.
void saveHisto()
Save hitograms of the calibration results.
bool isValid() const
Check whether the object was created.