Project
Loading...
Searching...
No Matches
TrackReaderSpec.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>
20
21using namespace o2::framework;
22
23namespace o2
24{
25namespace tpc
26{
27
29{
30 mUseMC = useMC;
31}
32
34{
35 mInputFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
36 ic.options().get<std::string>("infile"));
37 mSkipClusRefs = ic.options().get<bool>("skip-clusref");
38 connectTree(mInputFileName);
39}
40
42{
43 auto ent = mTree->GetReadEntry() + 1;
44 accumulate(ent, 1); // to really accumulate all, use accumulate(ent,mTree->GetEntries());
45 assert(ent < mTree->GetEntries()); // this should not happen
46 mTree->GetEntry(ent);
48 const auto& trackTune = TrackTunePar::Instance();
49 // Normally we should not apply tuning here as with sourceLevelTPC==true it is already applied in the tracking.
50 // Note that there is no way to apply lumi scaling here!!!
51 if ((trackTune.sourceLevelTPC && trackTune.applyWhenReading) &&
52 (trackTune.useTPCInnerCorr || trackTune.useTPCOuterCorr ||
53 trackTune.tpcCovInnerType != TrackTunePar::AddCovType::Disable || trackTune.tpcCovOuterType != TrackTunePar::AddCovType::Disable)) {
54 for (auto& trc : mTracksOut) {
55 if (trc.getNClusters() == 0) {
56 continue; // filtered/reduced track
57 }
58 if (trackTune.useTPCInnerCorr) {
59 trc.updateParams(trackTune.tpcParInner);
60 }
61 if (trackTune.tpcCovInnerType != TrackTunePar::AddCovType::Disable) {
62 trc.updateCov(trackTune.tpcCovInner, trackTune.tpcCovInnerType == TrackTunePar::AddCovType::WithCorrelations);
63 }
64 if (trackTune.useTPCOuterCorr) {
65 trc.getParamOut().updateParams(trackTune.tpcParOuter);
66 }
67 if (trackTune.tpcCovOuterType != TrackTunePar::AddCovType::Disable) {
68 trc.getParamOut().updateCov(trackTune.tpcCovOuter, trackTune.tpcCovOuterType == TrackTunePar::AddCovType::WithCorrelations);
69 }
70 }
71 }
72
73 pc.outputs().snapshot(Output{"TPC", "TRACKS", 0}, mTracksOut);
74 pc.outputs().snapshot(Output{"TPC", "CLUSREFS", 0}, mCluRefVecOut);
75 if (mUseMC) {
76 pc.outputs().snapshot(Output{"TPC", "TRACKSMCLBL", 0}, mMCTruthOut);
77 }
78 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
79 pc.services().get<ControlService>().endOfStream();
80 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
81 }
82}
83
84void TrackReader::accumulate(int from, int n)
85{
86 assert(from + n <= mTree->GetEntries());
87 if (n == 1) {
88 mTree->GetEntry(from);
89 mTracksOut.swap(*mTracksInp);
90 mCluRefVecOut.swap(*mCluRefVecInp);
91 if (mUseMC) {
92 std::copy(mMCTruthInp->begin(), mMCTruthInp->end(), std::back_inserter(mMCTruthOut));
93 }
94 } else {
95 for (int iev = 0; iev < n; iev++) {
96 mTree->GetEntry(from + iev);
97 //
98 uint32_t shift = mCluRefVecOut.size(); // during accumulation clusters refs need to be shifted
99
100 auto cl0 = mCluRefVecInp->begin();
101 auto cl1 = mCluRefVecInp->end();
102 std::copy(cl0, cl1, std::back_inserter(mCluRefVecOut));
103
104 auto tr0 = mTracksInp->begin();
105 auto tr1 = mTracksInp->end();
106 // fix cluster references
107 if (shift) {
108 for (auto tr = tr0; tr != tr1; tr++) {
109 tr->shiftFirstClusterRef(shift);
110 }
111 }
112 std::copy(tr0, tr1, std::back_inserter(mTracksOut));
113 // MC
114 if (mUseMC) {
115 std::copy(mMCTruthInp->begin(), mMCTruthInp->end(), std::back_inserter(mMCTruthOut));
116 }
117 }
118 }
119 LOG(info) << "TPCTrackReader pushes " << mTracksOut.size() << " tracks from entries " << from << " : " << from + n - 1;
120}
121
122void TrackReader::connectTree(const std::string& filename)
123{
124 mTree.reset(nullptr); // in case it was already loaded
125 mFile.reset(TFile::Open(filename.c_str()));
126 if (!(mFile && !mFile->IsZombie())) {
127 throw std::runtime_error("Error opening tree file");
128 }
129 mTree.reset((TTree*)mFile->Get(mTrackTreeName.c_str()));
130 if (!mTree) {
131 throw std::runtime_error("Error opening tree");
132 }
133
134 mTree->SetBranchAddress(mTrackBranchName.c_str(), &mTracksInp);
135 if (!mSkipClusRefs) {
136 mTree->SetBranchAddress(mClusRefBranchName.c_str(), &mCluRefVecInp);
137 } else {
138 mCluRefVecInp = new std::vector<o2::tpc::TPCClRefElem>;
139 }
140 if (mUseMC) {
141 if (mTree->GetBranch(mTrackMCTruthBranchName.c_str())) {
142 mTree->SetBranchAddress(mTrackMCTruthBranchName.c_str(), &mMCTruthInp);
143 LOG(info) << "Will use MC-truth from " << mTrackMCTruthBranchName;
144 } else {
145 LOG(info) << "MC-truth is missing";
146 mUseMC = false;
147 }
148 }
149 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
150}
151
153{
154 std::vector<OutputSpec> outputSpec;
155 outputSpec.emplace_back("TPC", "TRACKS", 0, Lifetime::Timeframe);
156 outputSpec.emplace_back("TPC", "CLUSREFS", 0, Lifetime::Timeframe);
157 if (useMC) {
158 outputSpec.emplace_back("TPC", "TRACKSMCLBL", 0, Lifetime::Timeframe);
159 }
160
161 return DataProcessorSpec{
162 "tpc-track-reader",
163 Inputs{},
164 outputSpec,
165 AlgorithmSpec{adaptFromTask<TrackReader>(useMC)},
166 Options{
167 {"infile", VariantType::String, "tpctracks.root", {"Name of the input track file"}},
168 {"input-dir", VariantType::String, "none", {"Input directory"}},
169 {"skip-clusref", VariantType::Bool, false, {"Skip reading cluster references"}}}};
170}
171
172} // namespace tpc
173} // namespace o2
Definition of the Names Generator class.
Configurable params for tracks ad hoc tuning.
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
ServiceRegistryRef services()
The services registry associated with this processing context.
void init(InitContext &ic) final
void run(ProcessingContext &pc) final
TrackReader(bool useMC=true)
GLdouble n
Definition glcorearb.h:1982
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getTPCTrackReaderSpec(bool useMC=true)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"