Project
Loading...
Searching...
No Matches
CollectCalibInfoTOF.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#include <TTree.h>
12#include <cassert>
13
14#include <fairlogger/Logger.h>
15#include "TOFBase/Geo.h"
16
17#include <TFile.h>
19
20using namespace o2::globaltracking;
21
23
24//______________________________________________
26{
32
33 if (!mInitDone) {
34 LOG(fatal) << "init() was not done yet";
35 }
36
37 mTimerTot.Start();
38
39 while (loadTOFCalibInfo()) { // fill here all histos you need
40 for (int ihit = 0; ihit < mTOFCalibInfo->size(); ihit++) {
41 addHit((*mTOFCalibInfo)[ihit]);
42 }
43 }
44 fillTree(); // filling with whatever we have in memory
45
46 // fit and extract calibration parameters once histos are filled
47 // ...
48
49 mTimerTot.Stop();
50 printf("Timing:\n");
51 printf("Total: ");
52 mTimerTot.Print();
53}
54
55//______________________________________________
57{
59
60 if (mInitDone) {
61 LOG(error) << "Initialization was already done";
62 return;
63 }
64
65 attachInputTrees();
66
67 // create output branch with track-tof matching
68 if (mOutputTree) {
69 mOutputTree->Branch(mOutputBranchName.data(), &mTOFCalibInfoOut);
70 LOG(info) << "Accumulated calib info TOF will be stored in " << mOutputBranchName << " branch of tree "
71 << mOutputTree->GetName();
72 } else {
73 LOG(error) << "Output tree is not attached, accumulated CalibInfoTOFshort will not be stored";
74 }
75 mInitDone = true;
76
77 {
78 mTimerTot.Stop();
79 mTimerTot.Reset();
80 }
81
82 print();
83}
84
85//______________________________________________
87{
89
90 LOG(info) << "****** component for calibration of TOF channels ******";
91 if (!mInitDone) {
92 LOG(info) << "init is not done yet - nothing to print";
93 return;
94 }
95
96 LOG(info) << "**********************************************************************";
97}
98
99//______________________________________________
100void CollectCalibInfoTOF::attachInputTrees()
101{
103
104 if (!mTreeTOFCalibInfo) {
105 LOG(fatal) << "Input tree with TOF calib infos is not set";
106 }
107
108 if (!mTreeTOFCalibInfo->GetBranch(mTOFCalibInfoBranchName.data())) {
109 LOG(fatal) << "Did not find TOF calib info branch " << mTOFCalibInfoBranchName << " in the input tree";
110 }
111 mTreeTOFCalibInfo->SetBranchAddress(mTOFCalibInfoBranchName.data(), &mTOFCalibInfo);
112 LOG(info) << "Attached tracksTOF calib info " << mTOFCalibInfoBranchName << " branch with " << mTreeTOFCalibInfo->GetEntries()
113 << " entries";
114
115 mCurrTOFInfoTreeEntry = -1;
116}
117
118//______________________________________________
119bool CollectCalibInfoTOF::loadTOFCalibInfo()
120{
122 printf("Loading TOF calib infos: number of entries in tree = %lld\n", mTreeTOFCalibInfo->GetEntries());
123
124 while (++mCurrTOFInfoTreeEntry < mTreeTOFCalibInfo->GetEntries()) {
125 mTreeTOFCalibInfo->GetEntry(mCurrTOFInfoTreeEntry);
126 LOG(info) << "Loading TOF calib info entry " << mCurrTOFInfoTreeEntry << " -> " << mTOFCalibInfo->size() << " infos";
127
128 if (!mTOFCalibInfo->size()) {
129 continue;
130 }
131 return true;
132 }
133 --mCurrTOFInfoTreeEntry;
134
135 return false;
136}
137//______________________________________________
138void CollectCalibInfoTOF::addHit(o2::dataformats::CalibInfoTOF& calibInfo)
139{
140
143
144 mTOFCollectedCalibInfo[calibInfo.getTOFChIndex()].emplace_back(calibInfo.getTimestamp(), calibInfo.getDeltaTimePi(), calibInfo.getTot(), calibInfo.getFlags());
145 if (mTOFCollectedCalibInfo[calibInfo.getTOFChIndex()].size() == MAXNUMBEROFHITS) { // the current channel has arrived to the limit of hits that we can store between two fills --> filling the tree
146 fillTree();
147 }
148 if (calibInfo.getTimestamp() < mMinTimestamp.GetVal() || mMinTimestamp.GetVal() == -1) {
149 mMinTimestamp.SetVal(calibInfo.getTimestamp());
150 } else if (calibInfo.getTimestamp() > mMaxTimestamp.GetVal()) {
151 mMaxTimestamp.SetVal(calibInfo.getTimestamp());
152 }
153}
154//______________________________________________
155void CollectCalibInfoTOF::fillTree()
156{
157
159
160 for (int ich = 0; ich < Geo::NCHANNELS; ich++) {
161 mTOFCalibInfoOut = &mTOFCollectedCalibInfo[ich];
162 mOutputTree->Fill();
163 mTOFCollectedCalibInfo[ich].clear();
164 }
165}
ClassImp(CollectCalibInfoTOF)
unsigned char getFlags() const
void run()
perform all initializations
void init()
set tree/chain containing TOF calib info
static constexpr int NCHANNELS
Definition Geo.h:124
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"