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>
30 addParam(
"Cosmic",
m_cosmic,
"true; tof negative for upper part of cdc",
true);
46 for (
int il = 0; il < 56; ++il) {
47 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
51 for (
int ib = 0; ib < 300; ++ib) {
54 m_hT0All =
new TH1D(
"hT0All",
"", 8500, 0, 8500);
61 WireID wireid(hit.getID());
63 unsigned short lay = wireid.getICLayer();
65 unsigned short w = wireid.getIWire();
67 m_hTDC[lay][w]->Fill(hit.getTDCCount());
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);
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);
89 for (
int ib = 1; ib < 300; ++ib) {
91 B2DEBUG(199,
"Warning: this board low statistic: " <<
m_hTDCBoard[ib]->GetEntries());
100 if ((fabs(f1->GetParameter(4) -
m_initT0) > 100)
101 || (fabs(f1->GetParameter(5)) < 0.01)
102 || (fabs(f1->GetParameter(5)) > 16)) {
110 m_t0b[ib] = f1->GetParameter(4) * tdcBinWidth;
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));
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());
127 B2DEBUG(99,
"Warning: low statistic channel: " <<
m_hTDC[il][w]->GetEntries());
128 if (bflag[bid] != 0) {
131 }
else {
m_flag[il][w] =
false;}
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);
136 B2DEBUG(99,
"prob of fit : " << f1->GetProb());
137 if ((f1->GetProb() < 1
E-150) || (fabs(f1->GetParameter(4) -
m_initT0) > 100) || (f1->GetParameter(5) < 0.1)
138 || (f1->GetParameter(5) > 20)) {
139 if (bflag[bid] != 0) {
142 }
else {
m_flag[il][w] =
false;}
144 m_t0[il][w] = f1->GetParameter(4) * tdcBinWidth;
145 hs->Fill(f1->GetParameter(5));
149 B2DEBUG(99,
"P4 = " <<
m_t0[il][w]);
156 m_t0[il][w] += 6.122;
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) {
169 ofs << il <<
"\t" << w <<
"\t" <<
m_t0[il][w] << endl;
176 TDirectory* top = gDirectory;
177 TDirectory* Direct[56];
178 for (
int il = 0; il < 56; ++il) {
180 Direct[il] = gDirectory->mkdir(Form(
"lay_%d", il));
182 for (
unsigned short w = 0; w < cdcgeo.
nWiresInLayer(il); ++w) {
183 if (
m_flag[il][w] ==
true) {
189 TDirectory* board = gDirectory->mkdir(
"board");
191 for (
int ib = 0; ib < 300; ++ib) {
200 TGraphErrors* gr =
new TGraphErrors(b.size(), &b.at(0), &sb.at(0), &db.at(0), &dsb.at(0));
203 TGraphErrors* grT0b =
new TGraphErrors(b.size(), &b.at(0), &t0b.at(0), &db.at(0), &dt0b.at(0));
204 grT0b->SetName(
"T0Board");
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.
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.
CDCInitialT0DeterminationModule()
Constructor.
double m_t0b[300]
T0 for each board.
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.