5 #include <FairLogger.h>
6 #include <FairRootManager.h>
9 #include <Math/ParamFunctor.h>
10 #include <TClonesArray.h>
15 #include <TTreeReader.h>
16 #include <TTreeReaderValue.h>
25 constexpr
auto cRED =
"\033[1;31m";
28 constexpr
auto cGREEN =
"\033[1;32m";
29 constexpr
auto cBLUE =
"\033[1;34m";
41 fMTDCObjRange.clear();
47 fS800TsGraph->Delete();
48 fS800TsFunc->Delete();
49 fS800CalcBr->Delete();
50 fRawEventArray->Delete();
56 fIsPersistence = value;
72 fcutPID1File.push_back(file);
76 fcutPID2File.push_back(file);
80 fcutPID3File.push_back(file);
104 fUseATTPCClock = value;
108 fATTPCClockFreq = value;
113 return fTsEvtS800Size;
124 if (ts1 > 0 && ts2 > 0 && fabs(ts1 - ts2) < fGlom)
132 FairRootManager *ioMan = FairRootManager::Instance();
133 if (ioMan ==
nullptr) {
134 LOG(error) <<
"Cannot find RootManager!";
138 fRawEventArray =
dynamic_cast<TClonesArray *
>(ioMan->GetObject(
"AtRawEvent"));
139 if (fRawEventArray ==
nullptr) {
140 LOG(error) <<
"Cannot find AtRawEvent array!";
147 Long64_t S800Ts0 = 0;
150 fS800file =
new TFile(fS800File);
151 TTreeReader reader1(
"caltree", fS800file);
152 TTreeReaderValue<Long64_t> ts(reader1,
"fts");
154 LOG(INFO) <<
cBLUE <<
"Loading S800 timestamps..." <<
cNORMAL;
155 while (reader1.Next()) {
156 fS800Ts.push_back((Long64_t)*ts);
158 fS800Evt.push_back((Double_t)fTsEvtS800Size);
161 if (fUseATTPCClock) {
162 if (fTsEvtS800Size == 0)
163 S800Ts0 = fS800Ts.at(0);
164 fS800Ts.at(fTsEvtS800Size) -= S800Ts0;
165 if (fTsEvtS800Size < 10)
166 std::cout <<
"Ts S800 " << fS800Ts.at(fTsEvtS800Size) <<
" S800Ts0 " << S800Ts0 << std::endl;
171 ioMan->Register(
"s800cal",
"S800", fS800CalcBr, fIsPersistence);
173 vector<Double_t> S800_ts(fS800Ts.begin(), fS800Ts.end());
177 new TGraph(fTsEvtS800Size, &S800_ts[0], &fS800Evt[0]);
180 fS800TsFunc =
new TF1(
181 "fS800TsFunc", [&](
double *x,
double *) {
return fS800TsGraph->Eval(x[0]); }, 0, S800_ts.back(), 0);
198 fS800CalcBr->
Clear();
200 if (fRawEventArray->GetEntriesFast() == 0)
203 auto *rawEvent =
dynamic_cast<AtRawEvent *
>(fRawEventArray->At(0));
204 Long64_t AtTPCTs = -1;
205 if (!fUseATTPCClock) {
206 if (rawEvent->GetTimestamps().size() == 1) {
209 <<
" AtMergeTask : only TS based on internal AT-TPC clock available, check fUseATTPCClock unpacking macro"
213 AtTPCTs = rawEvent->GetTimestamp(1);
215 if (fUseATTPCClock) {
216 AtTPCTs = rawEvent->GetTimestamp(0);
222 (AtTPCTs - fATTPCTs0) / fATTPCClockFreq;
224 if ((AtTPCTs - fATTPCTsPrev) > 1e+8)
225 AtTPCTs -= 429521035;
226 if ((AtTPCTs - fATTPCTsPrev) < -1e+8)
227 AtTPCTs += 429521035;
228 fATTPCTsPrev = AtTPCTs;
230 int minj = 0, maxj = 0;
231 Double_t S800EvtMatch = -1;
232 minj = (int)fS800TsFunc->Eval(AtTPCTs) - fEvtDelta;
234 maxj = (int)fS800TsFunc->Eval(AtTPCTs) + fEvtDelta;
236 std::cout <<
" TS AtTPC " << AtTPCTs << std::endl;
238 for (
int i = minj; i < maxj; i++) {
239 if (i >= 0 && i < fTsEvtS800Size) {
240 if (i > 0 &&
isInGlom(fS800Ts.at(i - 1), fS800Ts.at(i)))
241 std::cout <<
" -- Warning -- Timestamp of consecutive entries from S800 root file within the glom"
250 if (
isInGlom(fS800Ts.at(i) + fTsDelta, AtTPCTs)) {
253 S800EvtMatch = (int)fS800Evt.at(i);
254 std::cout <<
" in glom " << minj <<
" " << maxj <<
" " << i <<
" " << fS800Ts.at(i) <<
" " << AtTPCTs
255 <<
" " << S800EvtMatch <<
" " << fS800TsFunc->Eval(AtTPCTs) <<
" " << AtTPCTs - fS800Ts.at(i)
267 if (S800EvtMatch < 0)
268 LOG(WARNING) <<
cRED <<
"NO TS MATCHING !" <<
cNORMAL;
270 if (S800EvtMatch > 0) {
271 TTreeReader reader2(
"caltree", fS800file);
272 TTreeReaderValue<S800Calc> *readerValueS800Calc =
nullptr;
273 readerValueS800Calc =
new TTreeReaderValue<S800Calc>(reader2,
"s800calc");
275 reader2.SetEntry(S800EvtMatch);
277 *fS800CalcBr = (
S800Calc)*readerValueS800Calc->Get();
279 Bool_t isIn = kFALSE;
280 isIn = fS800Ana.
isInPID(fS800CalcBr);
282 rawEvent->SetIsExtGate(isIn);