forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathITSOffsStudy.cxx
More file actions
175 lines (155 loc) · 6.59 KB
/
Copy pathITSOffsStudy.cxx
File metadata and controls
175 lines (155 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "GlobalTrackingStudy/ITSOffsStudy.h"
#include <vector>
#include <TStopwatch.h>
#include "DataFormatsGlobalTracking/RecoContainer.h"
#include "DataFormatsGlobalTracking/RecoContainerCreateTracksVariadic.h"
#include "ReconstructionDataFormats/GlobalTrackID.h"
#include "CommonDataFormat/BunchFilling.h"
#include "CommonUtils/NameConf.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/CCDBParamSpec.h"
#include "DetectorsCommonDataFormats/DetID.h"
#include "ReconstructionDataFormats/PrimaryVertex.h"
#include "CommonUtils/TreeStreamRedirector.h"
#include "ReconstructionDataFormats/VtxTrackRef.h"
#include <TH1F.h>
namespace o2::trackstudy
{
using namespace o2::framework;
using DetID = o2::detectors::DetID;
using DataRequest = o2::globaltracking::DataRequest;
using PVertex = o2::dataformats::PrimaryVertex;
using V2TRef = o2::dataformats::VtxTrackRef;
using VTIndex = o2::dataformats::VtxTrackIndex;
using GTrackID = o2::dataformats::GlobalTrackID;
using timeEst = o2::dataformats::TimeStampWithError<float, float>;
class ITSOffsStudy final : public Task
{
public:
ITSOffsStudy(std::shared_ptr<DataRequest> dr, GTrackID::mask_t src) : mDataRequest(dr), mTracksSrc(src) {}
~ITSOffsStudy() final = default;
void init(InitContext& ic) final;
void run(ProcessingContext& pc) final;
void endOfStream(EndOfStreamContext& ec) final;
void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
void process(o2::globaltracking::RecoContainer& recoData);
private:
void updateTimeDependentParams(ProcessingContext& pc);
std::shared_ptr<DataRequest> mDataRequest;
std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut;
GTrackID::mask_t mTracksSrc{};
std::unique_ptr<TH1F> mDTHisto{};
const std::string mOutName{"its_offset_Study.root"};
};
void ITSOffsStudy::init(InitContext& ic)
{
mDBGOut = std::make_unique<o2::utils::TreeStreamRedirector>(mOutName.c_str(), "recreate");
mDTHisto = std::make_unique<TH1F>("dT", "T_{TOF} - T_{ITS-ROF}, #mus", 1000, 1, -1);
mDTHisto->SetDirectory(nullptr);
}
void ITSOffsStudy::run(ProcessingContext& pc)
{
o2::globaltracking::RecoContainer recoData;
recoData.collectData(pc, *mDataRequest.get()); // select tracks of needed type, with minimal cuts, the real selected will be done in the vertexer
updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
process(recoData);
}
void ITSOffsStudy::updateTimeDependentParams(ProcessingContext& pc)
{
static bool initOnceDone = false;
if (!initOnceDone) { // this params need to be queried only once
initOnceDone = true;
}
}
void ITSOffsStudy::process(o2::globaltracking::RecoContainer& recoData)
{
constexpr float PS2MUS = 1e-6;
auto trackIndex = recoData.getPrimaryVertexMatchedTracks(); // Global ID's for associated tracks
auto vtxRefs = recoData.getPrimaryVertexMatchedTrackRefs(); // references from vertex to these track IDs
auto tofClusters = recoData.getTOFClusters();
auto itsROFs = recoData.getITSTracksROFRecords();
std::vector<int> itsTr2ROFID;
std::unordered_map<GTrackID, char> ambigMap;
int cntROF = 0;
for (const auto& rof : itsROFs) {
size_t maxE = rof.getFirstEntry() + rof.getNEntries();
if (itsTr2ROFID.size() < maxE) {
itsTr2ROFID.resize(maxE, cntROF);
}
cntROF++;
}
int nv = vtxRefs.size();
for (int iv = 0; iv < nv; iv++) {
const auto& vtref = vtxRefs[iv];
for (int is = 0; is < GTrackID::NSources; is++) {
if (!mTracksSrc[is] || !(GTrackID::getSourceDetectorsMask(is)[GTrackID::ITS] && GTrackID::getSourceDetectorsMask(is)[GTrackID::TOF])) {
continue;
}
int idMin = vtxRefs[iv].getFirstEntryOfSource(is), idMax = idMin + vtxRefs[iv].getEntriesOfSource(is);
for (int i = idMin; i < idMax; i++) {
auto vid = trackIndex[i];
if (vid.isAmbiguous()) {
auto& ambEntry = ambigMap[vid];
if (ambEntry > 0) {
continue;
}
ambEntry = 1;
}
auto tofMatch = recoData.getTOFMatch(vid);
auto refs = recoData.getSingleDetectorRefs(vid);
if (!refs[GTrackID::ITS].isIndexSet()) { // might be an afterburner track
continue;
}
const auto& tofCl = tofClusters[refs[GTrackID::TOF]];
float timeTOFMUS = (tofCl.getTime() - recoData.getTOFMatch(vid).getLTIntegralOut().getTOF(o2::track::PID::Pion)) * PS2MUS;
int itsTrackID = refs[GTrackID::ITS].getIndex();
// find the ROF corresponding to this track
const auto& rof = itsROFs[itsTr2ROFID[itsTrackID]];
auto tsROF = rof.getBCData().differenceInBC(recoData.startIR) * o2::constants::lhc::LHCBunchSpacingMUS;
(*mDBGOut) << "itstof"
<< "gid=" << vid << "ttof=" << timeTOFMUS << "tits=" << tsROF << "itsROFID=" << itsTr2ROFID[itsTrackID] << "\n";
mDTHisto->Fill(timeTOFMUS - tsROF);
const auto& trc = recoData.getTrackParam(tofMatch.getTrackRef());
(*mDBGOut) << "dttof"
<< "refgid=" << tofMatch.getTrackRef() << "dtime=" << tofMatch.getDeltaT() << "phi=" << trc.getPhi() << "tgl=" << trc.getTgl() << "q2t=" << trc.getQ2Pt() << "\n";
}
}
}
}
void ITSOffsStudy::endOfStream(EndOfStreamContext& ec)
{
mDBGOut.reset();
TFile fout(mOutName.c_str(), "update");
fout.WriteTObject(mDTHisto.get());
LOGP(info, "Stored time differences histogram {} and tree {} into {}", mDTHisto->GetName(), "itstof", mOutName.c_str());
fout.Close();
}
void ITSOffsStudy::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
{
}
DataProcessorSpec getITSOffsStudy(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters)
{
std::vector<OutputSpec> outputs;
auto dataRequest = std::make_shared<DataRequest>();
bool useMC = false;
dataRequest->requestTracks(srcTracks, useMC);
dataRequest->requestClusters(srcClusters, useMC);
dataRequest->requestPrimaryVertices(useMC);
return DataProcessorSpec{
"its-offset-study",
dataRequest->inputs,
outputs,
AlgorithmSpec{adaptFromTask<ITSOffsStudy>(dataRequest, srcTracks)},
Options{}};
}
} // namespace o2::trackstudy