13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
16#include "trg/trg/Debug.h"
17#include "trg/cdc/Segment.h"
18#include "trg/cdc/TRGCDCTrack.h"
19#include "trg/cdc/EventTime.h"
26#include "trg/cdc/TRGCDC.h"
27#include "trg/cdc/Layer.h"
28#include "trg/cdc/Wire.h"
29#include "trg/cdc/WireHit.h"
30#include "trg/cdc/SegmentHit.h"
31#include "trg/trg/Utilities.h"
52 m_makeRootFile(makeRootFile),
56 if (m_makeRootFile) m_fileEvtTime =
new TFile(
"ETF.root",
"RECREATE");
58 m_evtOutputTs =
new TTree(
"m_evtOutsTs",
"EvtTime Outputs for TS");
59 m_evtOut =
new TTree(
"m_evtOut",
"EvtTime Outputs for 20 TS");
61 m_evtOutputTs->Branch(
"tsFastestTime", &m_fastestT,
"m_fastestT/I");
62 m_evtOutputTs->Branch(
"tsFoundTime", &m_foundT,
"m_foundT/I");
63 m_evtOutputTs->Branch(
"foundT_fastT_diff", &m_whdiff,
"m_whdiff/I");
65 m_evtOut->Branch(
"histTime", &m_histT,
"m_histT/I");
67 h =
new TH1D(
"h",
"h", 1000, -500, 499);
69 memset(cnt, 0,
sizeof cnt);
70 memset(ft, 0,
sizeof ft);
80 TRGCDCEventTime::~TRGCDCEventTime()
84 if (m_makeRootFile)
delete m_fileEvtTime;
88 void TRGCDCEventTime::initialize(
void)
95 void TRGCDCEventTime::doit(
int ver,
bool print)
97 TRGDebug::enterStage(
"Event Time");
103 }
else if (ver == 0) {
107 }
else if (ver == 2) {
112 cout <<
"verETF error" << endl;
113 cout <<
"choose 0:hist, 1:old, 2:trueT0" << endl;
115 if (print) printFirm();
116 TRGDebug::leaveStage(
"Event Time");
119 void TRGCDCEventTime::hitcount(
void)
121 TRGDebug::enterStage(
"Event Time");
123 memset(cnt, 0,
sizeof cnt);
124 memset(ft, 0,
sizeof ft);
126 const vector<const TCSHit*> tsh = _cdc.segmentHits();
128 for (
int iClk = 0; iClk < 64; iClk++) {
129 for (
int iTS = 0; iTS < (int)tsh.size(); iTS++) {
135 if (m_whdiff <= 256) {
136 if (iClk == fndC + 31) {
137 for (
int iSL = 0; iSL < 9; iSL++) {
138 if ((
int)ts.
layer().
id() == iSL) {
140 if (cnt[iSL][iClk] <= 10) {
142 m_evtOutputTs->Fill();
143 ft[iSL][iClk][cnt[iSL][iClk] - 1] = ts.
fastestTime();
151 TRGDebug::leaveStage(
"Event Time");
154 void TRGCDCEventTime::hist(
void)
156 TRGDebug::enterStage(
"Event Time");
162 for (
int i = 450; i < 600; i++) {
163 if (h->GetBinContent(i) > threshold) {
173 if (m_histT == 500) {
178 TRGDebug::leaveStage(
"Event Time");
181 void TRGCDCEventTime::oldVer(
void)
183 TRGDebug::enterStage(
"Event Time");
185 for (
unsigned i = 0; i < _cdc.nSegmentLayers(); i++) {
187 const unsigned nWires = l->
nCells();
188 for (
unsigned j = 0; j < nWires; j++) {
189 const TCSegment& s = (TCSegment&) * (*l)[j];
190 const vector<const TCWire*>& wires = s.wires();
192 if (timing.active()) {
193 for (
unsigned k = 0; k < wires.size(); k++) {
194 if (wires[k]->hit()) {
195 int dt = wires[k]->signal()[0]->time();
206 TRGDebug::leaveStage(
"Event Time");
209 void TRGCDCEventTime::printFirm(
void)
211 TRGDebug::enterStage(
"Event Time");
213 for (
int iClk = 0; iClk < 64; iClk++) {
214 for (
int iSL = 0; iSL < 9; iSL++) {
215 int hmbw = 160 + 32 * (iSL - 1);
216 if (iSL == 0) hmbw = 160;
220 sprintf(file,
"SL%d.coe", iSL);
221 string cnts = string(cnt[iSL][iClk],
'1');
223 string clk = bitset<9>(iClk + 64 * (m_eventN - 1)).to_string();
224 string clk2 = bitset<5>(iClk).to_string();
225 for (
int i = 0; i < 10; i++) {
226 hs[i] = bitset<4>(ft[iSL][iClk][i]).to_string();
227 if (cnt[iSL][iClk] > i) t[i] = clk2 + hs[i];
228 else t[i] =
"00000" + hs[i];
231 fout.open(file, ios::app);
233 fout << setfill(
'0') << setw(hmbw) << cnts;
234 fout << t[9] << t[8] << t[7] << t[6] << t[5] << t[4] << t[3] << t[2] << t[1] << t[0] << endl;
238 TRGDebug::leaveStage(
"Event Time");
242 int TRGCDCEventTime::getT0(
void)
const
245 if (m_foundT0 == 0) et = 9999;
249 void TRGCDCEventTime::terminate(
void)
252 if (m_makeRootFile) {
253 m_fileEvtTime->Write();
254 m_fileEvtTime->Close();
A class to represent a cell layer.
A class to represent a wire in CDC.
The instance of TRGCDC is a singleton.
A class to represent a digitized signal. Unit is nano second.
float fastestTime(void) const
return fastest time in TSHit.
unsigned id(void) const
returns id.
TRGCDCEventTime(const TRGCDC &, bool makeRootFile)
constructor of TRGCDCEventTime class
const TRGCDCLayer & layer(void) const
returns a pointer to a layer.
unsigned nCells(void) const
returns # of cells.
float foundTime(void) const
return found time in TSHit.
Abstract base class for different kinds of events.