Belle II Software development
CDCInitialT0Determination.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include "cdc/modules/cdcInitialT0Determination/CDCInitialT0Determination.h"
9#include <cdc/geometry/CDCGeometryPar.h>
10#include <framework/gearbox/Const.h>
11#include <TF1.h>
12#include <TDirectory.h>
13#include <TFile.h>
14#include <TGraphErrors.h>
15#include <TROOT.h>
16
17using namespace std;
18using namespace Belle2;
19using namespace CDC;
20REG_MODULE(CDCInitialT0Determination);
21
23{
24 setDescription("Module to determine crude t0");
25 setPropertyFlags(c_ParallelProcessingCertified); // specify this flag if you need parallel processing
26 addParam("OutputFileName", m_outputFileName, "t0 file output file", std::string("t0.dat"));
27 addParam("LowTDC", m_tdcMin, "lower boundary of tdc histogram", m_tdcMin);
28 addParam("UpTDC", m_tdcMax, "Upper boundary of tdc histogram", m_tdcMax);
29 addParam("InitialT0", m_initT0, "initial t0 for fitting", 3579.);
30 addParam("Cosmic", m_cosmic, "true; tof negative for upper part of cdc", true);
31 addParam("Zoffset", m_zOffset, "z offset", 0.);
32 addParam("ADCCut", m_adcMin, "threshold of ADC", m_adcMin);
33 addParam("StoreFittedHisto", m_storeFittedHisto, "Store fitted histogram for each channel or not", true);
34 addParam("HistoFileName", m_histoFileName, "file contain TDC histo", std::string("TDC.root"));
35 addParam("MinEntries", m_minEntries, "minimum entries per channel", m_minEntries);
36}
37
41
42
44{
46 for (int il = 0; il < 56; ++il) {
47 for (unsigned short w = 0; w < cdcgeo.nWiresInLayer(il); ++w) {
48 m_hTDC[il][w] = new TH1D(Form("hLay%d_ch%d", il, w), "tdc", m_tdcMax - m_tdcMin, m_tdcMin, m_tdcMax);
49 }
50 }
51 for (int ib = 0; ib < 300; ++ib) {
52 m_hTDCBoard[ib] = new TH1D(Form("hTDCBoard%d", ib), "", m_tdcMax - m_tdcMin, m_tdcMin, m_tdcMax);
53 }
54 m_hT0All = new TH1D("hT0All", "", 8500, 0, 8500);
55 m_CDCHits.isRequired();
56}
58{
60 for (const auto& hit : m_CDCHits) {
61 WireID wireid(hit.getID());
62 // cppcheck-suppress variableScope ; kept next to the related declarations for readability
63 unsigned short lay = wireid.getICLayer();
64 // cppcheck-suppress variableScope ; kept next to the related declarations for readability
65 unsigned short w = wireid.getIWire();
66 if (hit.getADCCount() > m_adcMin) {
67 m_hTDC[lay][w]->Fill(hit.getTDCCount());
68 m_hTDCBoard[cdcgeo.getBoardID(WireID(lay, w))]->Fill(hit.getTDCCount());
69 }
70 }
71}
73{
74 gROOT->SetBatch(1);
75 std::vector<double> sb;
76 std::vector<double> dsb;
77 std::vector<double> t0b;
78 std::vector<double> dt0b;
79 std::vector<double> b;
80 std::vector<double> db;
81 TH1D* hs = new TH1D("hs", "sigma", 100, 0, 20);
82
84 TF1* f1 = new TF1("f1", "[0]+[1]*(exp([2]*(x-[3]))/(1+exp(-([4]-x)/[5])))", m_tdcMin, m_tdcMax);
85 f1->SetParLimits(0, 0., 1000.);
86 f1->SetLineColor(kRed);
87 double tdcBinWidth = cdcgeo.getTdcBinWidth();
88 double bflag[300];
89 for (int ib = 1; ib < 300; ++ib) {
90 if (m_hTDCBoard[ib]->GetEntries() < m_minEntries) {
91 B2DEBUG(199, "Warning: this board low statistic: " << m_hTDCBoard[ib]->GetEntries());
92 bflag[ib] = 0;
93 m_t0b[ib] = m_initT0;
94 continue;
95 }
96 double p3 = m_hTDCBoard[ib]->GetXaxis()->GetBinCenter(m_hTDCBoard[ib]->GetMaximumBin());
97 f1->SetParameters(0, m_hTDCBoard[ib]->GetMaximum(), -0.001, p3, m_initT0, 2.5);
98 m_hTDCBoard[ib]->Fit("f1", "QM", "", m_initT0 - 60, m_initT0 + 60);
99
100 if ((fabs(f1->GetParameter(4) - m_initT0) > 100)
101 || (fabs(f1->GetParameter(5)) < 0.01)
102 || (fabs(f1->GetParameter(5)) > 16)) {
103
104 bflag[ib] = 0;
105 m_t0b[ib] = m_initT0;
106 continue;
107 }
108
109 bflag[ib] = 1;
110 m_t0b[ib] = f1->GetParameter(4) * tdcBinWidth;
111
112 sb.push_back(f1->GetParameter(5));
113 dsb.push_back(f1->GetParError(5));
114 t0b.push_back(f1->GetParameter(4));
115 dt0b.push_back(f1->GetParError(4));
116 b.push_back(ib);
117 db.push_back(0);
118 }
119
120 for (int il = 0; il < 56; ++il) {
121 for (unsigned short w = 0; w < cdcgeo.nWiresInLayer(il); ++w) {
122 B2DEBUG(99, "fitting for channel: " << il << " - " << w);
123 B2DEBUG(99, "number of entries" << m_hTDC[il][w]->GetEntries());
124 m_t0[il][w] = m_initT0 * tdcBinWidth;
125 int bid = cdcgeo.getBoardID(WireID(il, w));
126 if (m_hTDC[il][w]->GetEntries() < m_minEntries) {
127 B2DEBUG(99, "Warning: low statistic channel: " << m_hTDC[il][w]->GetEntries());
128 if (bflag[bid] != 0) {
129 m_t0[il][w] = m_t0b[bid];
130 m_flag[il][w] = true;
131 } else {m_flag[il][w] = false;}
132 } else {
133 double p3 = m_hTDC[il][w]->GetXaxis()->GetBinCenter(m_hTDC[il][w]->GetMaximumBin());
134 f1->SetParameters(0, m_hTDC[il][w]->GetMaximum(), -0.001, p3, m_initT0, 2.5);
135 m_hTDC[il][w]->Fit("f1", "QM", "", m_initT0 - 60, m_initT0 + 60);
136 B2DEBUG(99, "prob of fit : " << f1->GetProb());
137 if ((f1->GetProb() < 1E-150) || (fabs(f1->GetParameter(4) - m_initT0) > 100) || (f1->GetParameter(5) < 0.1)
138 || (f1->GetParameter(5) > 20)) {
139 if (bflag[bid] != 0) {
140 m_t0[il][w] = m_t0b[bid];
141 m_flag[il][w] = true;
142 } else {m_flag[il][w] = false;}
143 } else {
144 m_t0[il][w] = f1->GetParameter(4) * tdcBinWidth;
145 hs->Fill(f1->GetParameter(5));
146 m_flag[il][w] = true;
147 }
148 }
149 B2DEBUG(99, "P4 = " << m_t0[il][w]);
150 if (m_cosmic && cdcgeo.wireBackwardPosition(il, w).Y() > 0) {
151 m_t0[il][w] -= cdcgeo.senseWireR(il) / Const::speedOfLight;
152 } else {
153 m_t0[il][w] += cdcgeo.senseWireR(il) / Const::speedOfLight;
154 }
155 m_t0[il][w] += (m_zOffset - cdcgeo.wireBackwardPosition(il, w).Z()) / 27.25;
156 m_t0[il][w] += 6.122;
157 m_hT0All->Fill(m_t0[il][w]);
158 // m_hT0b[cdcgeo.getBoardID(WireID(il, w))]->Fill(m_t0[il][w]);
159 }
160 }
161
162 //check t0, and add t0 for low static channel
163 ofstream ofs(m_outputFileName.c_str());
164 for (int il = 0; il < 56; ++il) {
165 for (unsigned short w = 0; w < cdcgeo.nWiresInLayer(il); ++w) {
166 if (m_flag[il][w] != true) {
167 m_t0[il][w] = m_hT0All->GetMean();
168 }
169 ofs << il << "\t" << w << "\t" << m_t0[il][w] << endl;
170 }
171 }
172 ofs.close();
173 if (m_storeFittedHisto) {
174 TFile* fhist = new TFile(m_histoFileName.c_str(), "recreate");
175 fhist->cd();
176 TDirectory* top = gDirectory;
177 TDirectory* Direct[56];
178 for (int il = 0; il < 56; ++il) {
179 top->cd();
180 Direct[il] = gDirectory->mkdir(Form("lay_%d", il));
181 Direct[il]->cd();
182 for (unsigned short w = 0; w < cdcgeo.nWiresInLayer(il); ++w) {
183 if (m_flag[il][w] == true) {
184 m_hTDC[il][w]->Write();
185 }
186 }
187 }
188 top->cd();
189 TDirectory* board = gDirectory->mkdir("board");
190 board->cd();
191 for (int ib = 0; ib < 300; ++ib) {
192 if (m_hTDCBoard[ib]) {
193 m_hTDCBoard[ib]->Write();
194 }
195 }
196 top->cd();
197 m_hT0All->Write();
198 hs->Write();
199 if (b.size() > 20) {
200 TGraphErrors* gr = new TGraphErrors(b.size(), &b.at(0), &sb.at(0), &db.at(0), &dsb.at(0));
201 gr->SetName("reso");
202 gr->Write();
203 TGraphErrors* grT0b = new TGraphErrors(b.size(), &b.at(0), &t0b.at(0), &db.at(0), &dt0b.at(0));
204 grT0b->SetName("T0Board");
205 grT0b->Write();
206 }
207 fhist->Close();
208 }
209}
210
R E
internal precision of FFTW codelets
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition B2Vector3.h:437
TH1D * m_hT0All
T0 distribution of all channel.
unsigned short m_tdcMax
Upper boundary TDC histogram.
void initialize() override
Initializes the Module.
TH1D * m_hTDCBoard[300]
T0 distribution of each board.
bool m_storeFittedHisto
Store fitted histogram or not.
virtual ~CDCInitialT0DeterminationModule() override
Destructor.
void event() override
Event action (main routine).
bool m_flag[56][400]
flag =1 for good, =0 for low statistic or bad fit
bool m_cosmic
for cosmic case, tof of upper sector will be negative
unsigned short m_adcMin
ADC cut to reject noise.
void terminate() override
Termination action, fit t0 and store histograms.
double m_t0[56][400]
T0 of each channel.
unsigned short m_tdcMin
Lower boundary TDC histogram.
double m_zOffset
z offset for calculate prop time, it is position of trigger counter,
double m_initT0
initial t0, use int fitting
std::string m_histoFileName
output file to store TDC histo after fit
unsigned short m_minEntries
min entries per histo.
TH1D * m_hTDC[56][400]
TDC distribution histo.
std::string m_outputFileName
output file name of t0 file.
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.
static const double speedOfLight
[cm/ns]
Definition Const.h:696
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
Module()
Constructor.
Definition Module.cc:30
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
Class to identify a wire inside the CDC.
Definition WireID.h:34
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.
STL namespace.