8#include "cdc/modules/cdcInitialT0Determination/CDCInitialT0Determination.h"
9#include <cdc/geometry/CDCGeometryPar.h>
10#include <framework/gearbox/Const.h>
12#include "TDirectory.h"
14#include "TGraphErrors.h"
31 addParam(
"Cosmic",
m_cosmic,
"true; tof negative for upper part of cdc",
true);
47 for (
int il = 0; il < 56; ++il) {
48 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
52 for (
int ib = 0; ib < 300; ++ib) {
55 m_hT0All =
new TH1D(
"hT0All",
"", 8500, 0, 8500);
62 WireID wireid(hit.getID());
63 unsigned short lay = wireid.getICLayer();
64 unsigned short w = wireid.getIWire();
66 m_hTDC[lay][w]->Fill(hit.getTDCCount());
74 std::vector<double> sb;
75 std::vector<double> dsb;
76 std::vector<double> t0b;
77 std::vector<double> dt0b;
78 std::vector<double> b;
79 std::vector<double> db;
80 TH1D* hs =
new TH1D(
"hs",
"sigma", 100, 0, 20);
83 TF1* f1 =
new TF1(
"f1",
"[0]+[1]*(exp([2]*(x-[3]))/(1+exp(-([4]-x)/[5])))",
m_tdcMin,
m_tdcMax);
84 f1->SetParLimits(0, 0., 1000.);
85 f1->SetLineColor(kRed);
88 for (
int ib = 1; ib < 300; ++ib) {
90 B2DEBUG(199,
"Warning: this board low statistic: " <<
m_hTDCBoard[ib]->GetEntries());
99 if ((fabs(f1->GetParameter(4) -
m_initT0) > 100)
100 || (fabs(f1->GetParameter(5)) < 0.01)
101 || (fabs(f1->GetParameter(5)) > 16)) {
109 m_t0b[ib] = f1->GetParameter(4) * tdcBinWidth;
111 sb.push_back(f1->GetParameter(5));
112 dsb.push_back(f1->GetParError(5));
113 t0b.push_back(f1->GetParameter(4));
114 dt0b.push_back(f1->GetParError(4));
119 for (
int il = 0; il < 56; ++il) {
120 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
121 B2DEBUG(99,
"fitting for channel: " << il <<
" - " << w);
122 B2DEBUG(99,
"number of entries" <<
m_hTDC[il][w]->GetEntries());
126 B2DEBUG(99,
"Warning: low statistic channel: " <<
m_hTDC[il][w]->GetEntries());
127 if (bflag[bid] != 0) {
130 }
else {
m_flag[il][w] =
false;}
132 double p3 =
m_hTDC[il][w]->GetXaxis()->GetBinCenter(
m_hTDC[il][w]->GetMaximumBin());
133 f1->SetParameters(0,
m_hTDC[il][w]->GetMaximum(), -0.001, p3,
m_initT0, 2.5);
135 B2DEBUG(99,
"prob of fit : " << f1->GetProb());
136 if ((f1->GetProb() < 1
E-150) || (fabs(f1->GetParameter(4) -
m_initT0) > 100) || (f1->GetParameter(5) < 0.1)
137 || (f1->GetParameter(5) > 20)) {
138 if (bflag[bid] != 0) {
141 }
else {
m_flag[il][w] =
false;}
143 m_t0[il][w] = f1->GetParameter(4) * tdcBinWidth;
144 hs->Fill(f1->GetParameter(5));
148 B2DEBUG(99,
"P4 = " <<
m_t0[il][w]);
155 m_t0[il][w] += 6.122;
163 for (
int il = 0; il < 56; ++il) {
164 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
165 if (
m_flag[il][w] !=
true) {
168 ofs << il <<
"\t" << w <<
"\t" <<
m_t0[il][w] << endl;
175 TDirectory* top = gDirectory;
176 TDirectory* Direct[56];
177 for (
int il = 0; il < 56; ++il) {
179 Direct[il] = gDirectory->mkdir(Form(
"lay_%d", il));
181 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
182 if (
m_flag[il][w] ==
true) {
188 TDirectory* board = gDirectory->mkdir(
"board");
190 for (
int ib = 0; ib < 300; ++ib) {
199 TGraphErrors* gr =
new TGraphErrors(b.size(), &b.at(0), &sb.at(0), &db.at(0), &dsb.at(0));
202 TGraphErrors* grT0b =
new TGraphErrors(b.size(), &b.at(0), &t0b.at(0), &db.at(0), &dt0b.at(0));
203 grT0b->SetName(
"T0Board");
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
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.
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.
CDCInitialT0DeterminationModule()
Constructor.
double m_t0b[300]
T0 for each board.
virtual ~CDCInitialT0DeterminationModule()
Destructor.
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.
StoreArray< CDCHit > m_CDCHits
CDC hits.
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]
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Class to identify a wire inside the CDC.
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.
Abstract base class for different kinds of events.