Project
Loading...
Searching...
No Matches
ITSOffsStudy.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
13
14#include <vector>
15#include <TStopwatch.h>
27#include <TH1F.h>
28
29namespace o2::trackstudy
30{
31
32using namespace o2::framework;
35
40
42
43class ITSOffsStudy : public Task
44{
45 public:
46 ITSOffsStudy(std::shared_ptr<DataRequest> dr, GTrackID::mask_t src) : mDataRequest(dr), mTracksSrc(src) {}
47 ~ITSOffsStudy() final = default;
48 void init(InitContext& ic) final;
49 void run(ProcessingContext& pc) final;
50 void endOfStream(EndOfStreamContext& ec) final;
51 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
52 void process(o2::globaltracking::RecoContainer& recoData);
53
54 private:
55 void updateTimeDependentParams(ProcessingContext& pc);
56 std::shared_ptr<DataRequest> mDataRequest;
57 std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut;
58 GTrackID::mask_t mTracksSrc{};
59 std::unique_ptr<TH1F> mDTHisto{};
60 const std::string mOutName{"its_offset_Study.root"};
61};
62
64{
65 mDBGOut = std::make_unique<o2::utils::TreeStreamRedirector>(mOutName.c_str(), "recreate");
66 mDTHisto = std::make_unique<TH1F>("dT", "T_{TOF} - T_{ITS-ROF}, #mus", 1000, 1, -1);
67 mDTHisto->SetDirectory(nullptr);
68}
69
71{
73 recoData.collectData(pc, *mDataRequest.get()); // select tracks of needed type, with minimal cuts, the real selected will be done in the vertexer
74 updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
75 process(recoData);
76}
77
78void ITSOffsStudy::updateTimeDependentParams(ProcessingContext& pc)
79{
80 static bool initOnceDone = false;
81 if (!initOnceDone) { // this params need to be queried only once
82 initOnceDone = true;
83 }
84}
85
87{
88 constexpr float PS2MUS = 1e-6;
89 auto trackIndex = recoData.getPrimaryVertexMatchedTracks(); // Global ID's for associated tracks
90 auto vtxRefs = recoData.getPrimaryVertexMatchedTrackRefs(); // references from vertex to these track IDs
91 auto tofClusters = recoData.getTOFClusters();
92 auto itsROFs = recoData.getITSTracksROFRecords();
93 std::vector<int> itsTr2ROFID;
94 std::unordered_map<GTrackID, char> ambigMap;
95
96 int cntROF = 0;
97 for (const auto& rof : itsROFs) {
98 size_t maxE = rof.getFirstEntry() + rof.getNEntries();
99 if (itsTr2ROFID.size() < maxE) {
100 itsTr2ROFID.resize(maxE, cntROF);
101 }
102 cntROF++;
103 }
104
105 int nv = vtxRefs.size();
106 for (int iv = 0; iv < nv; iv++) {
107 const auto& vtref = vtxRefs[iv];
108 for (int is = 0; is < GTrackID::NSources; is++) {
109 if (!mTracksSrc[is] || !(GTrackID::getSourceDetectorsMask(is)[GTrackID::ITS] && GTrackID::getSourceDetectorsMask(is)[GTrackID::TOF])) {
110 continue;
111 }
112 int idMin = vtxRefs[iv].getFirstEntryOfSource(is), idMax = idMin + vtxRefs[iv].getEntriesOfSource(is);
113 for (int i = idMin; i < idMax; i++) {
114 auto vid = trackIndex[i];
115 if (vid.isAmbiguous()) {
116 auto& ambEntry = ambigMap[vid];
117 if (ambEntry > 0) {
118 continue;
119 }
120 ambEntry = 1;
121 }
122 auto tofMatch = recoData.getTOFMatch(vid);
123 auto refs = recoData.getSingleDetectorRefs(vid);
124 if (!refs[GTrackID::ITS].isIndexSet()) { // might be an afterburner track
125 continue;
126 }
127 const auto& tofCl = tofClusters[refs[GTrackID::TOF]];
128 float timeTOFMUS = (tofCl.getTime() - recoData.getTOFMatch(vid).getLTIntegralOut().getTOF(o2::track::PID::Pion)) * PS2MUS;
129
130 int itsTrackID = refs[GTrackID::ITS].getIndex();
131 // find the ROF corresponding to this track
132 const auto& rof = itsROFs[itsTr2ROFID[itsTrackID]];
133 auto tsROF = rof.getBCData().differenceInBC(recoData.startIR) * o2::constants::lhc::LHCBunchSpacingMUS;
134 (*mDBGOut) << "itstof"
135 << "gid=" << vid << "ttof=" << timeTOFMUS << "tits=" << tsROF << "itsROFID=" << itsTr2ROFID[itsTrackID] << "\n";
136 mDTHisto->Fill(timeTOFMUS - tsROF);
137 const auto& trc = recoData.getTrackParam(tofMatch.getTrackRef());
138 (*mDBGOut) << "dttof"
139 << "refgid=" << tofMatch.getTrackRef() << "dtime=" << tofMatch.getDeltaT() << "phi=" << trc.getPhi() << "tgl=" << trc.getTgl() << "q2t=" << trc.getQ2Pt() << "\n";
140 }
141 }
142 }
143}
144
146{
147 mDBGOut.reset();
148 TFile fout(mOutName.c_str(), "update");
149 fout.WriteTObject(mDTHisto.get());
150 LOGP(info, "Stored time differences histogram {} and tree {} into {}", mDTHisto->GetName(), "itstof", mOutName.c_str());
151 fout.Close();
152}
153
155{
156}
157
159{
160 std::vector<OutputSpec> outputs;
161 auto dataRequest = std::make_shared<DataRequest>();
162 bool useMC = false;
163 dataRequest->requestTracks(srcTracks, useMC);
164 dataRequest->requestClusters(srcClusters, useMC);
165 dataRequest->requestPrimaryVertices(useMC);
166
167 return DataProcessorSpec{
168 "its-offset-study",
169 dataRequest->inputs,
170 outputs,
171 AlgorithmSpec{adaptFromTask<ITSOffsStudy>(dataRequest, srcTracks)},
172 Options{}};
173}
174
175} // namespace o2::trackstudy
Wrapper container for different reconstructed object types.
int32_t i
Global index for barrel track: provides provenance (detectors combination), index in respective array...
Definition of the Names Generator class.
Wrapper container for different reconstructed object types.
Referenc on track indices contributing to the vertex, with possibility chose tracks from specific sou...
o2::track::TrackLTIntegral & getLTIntegralOut()
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
static constexpr ID Pion
Definition PID.h:96
void init(InitContext &ic) final
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj) final
void endOfStream(EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
~ITSOffsStudy() final=default
ITSOffsStudy(std::shared_ptr< DataRequest > dr, GTrackID::mask_t src)
void process(o2::globaltracking::RecoContainer &recoData)
void run(ProcessingContext &pc) final
GLenum src
Definition glcorearb.h:1767
constexpr double LHCBunchSpacingMUS
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getITSOffsStudy(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcClus)
create a processor spec
o2::dataformats::VtxTrackRef V2TRef
o2::dataformats::VtxTrackIndex VTIndex
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
Common utility functions.
GlobalIDSet getSingleDetectorRefs(GTrackID gidx) const
const o2::track::TrackParCov & getTrackParam(GTrackID gidx) const
void collectData(o2::framework::ProcessingContext &pc, const DataRequest &request)
const o2::dataformats::MatchInfoTOF & getTOFMatch(GTrackID id) const