Skip to content

Commit 768db4a

Browse files
shahor02sawenzel
authored andcommitted
ITS track readed DPL device
1 parent f8f221c commit 768db4a

3 files changed

Lines changed: 211 additions & 0 deletions

File tree

Detectors/ITSMFT/ITS/workflow/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(SRCS
1111
src/TrackerSpec.cxx
1212
src/CookedTrackerSpec.cxx
1313
src/TrackWriterSpec.cxx
14+
src/TrackReaderSpec.cxx
1415
)
1516

1617
set(LIBRARY_NAME ${MODULE_NAME})
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// @file TrackReaderSpec.h
12+
13+
#ifndef O2_ITS_TRACKREADER
14+
#define O2_ITS_TRACKREADER
15+
16+
#include "TFile.h"
17+
18+
#include "Framework/DataProcessorSpec.h"
19+
#include "Framework/Task.h"
20+
#include "Headers/DataHeader.h"
21+
#include "DataFormatsITS/TrackITS.h"
22+
#include "SimulationDataFormat/MCCompLabel.h"
23+
#include "SimulationDataFormat/MCTruthContainer.h"
24+
#include "DataFormatsITSMFT/ROFRecord.h"
25+
26+
using namespace o2::framework;
27+
28+
namespace o2
29+
{
30+
namespace ITS
31+
{
32+
33+
class TrackReader : public Task
34+
{
35+
public:
36+
TrackReader(bool useMC = true);
37+
~TrackReader() override = default;
38+
void init(InitContext& ic) final;
39+
void run(ProcessingContext& pc) final;
40+
41+
protected:
42+
void accumulate();
43+
44+
std::vector<o2::itsmft::ROFRecord>*mROFRecInp = nullptr, mROFRecOut;
45+
std::vector<o2::ITS::TrackITS>*mTracksInp = nullptr, mTracksOut;
46+
o2::dataformats::MCTruthContainer<o2::MCCompLabel>*mMCTruthInp = nullptr, mMCTruthOut;
47+
48+
o2::header::DataOrigin mOrigin = o2::header::gDataOriginITS;
49+
50+
bool mFinished = false;
51+
bool mUseMC = true; // use MC truth
52+
53+
std::string mInputFileName = "";
54+
std::string mTrackTreeName = "o2sim";
55+
std::string mROFTreeName = "ITSTracksROF";
56+
std::string mTrackBranchName = "ITSTrack";
57+
std::string mTrackMCTruthBranchName = "ITSTrackMCTruth";
58+
};
59+
60+
/// create a processor spec
61+
/// read ITS track data from a root file
62+
framework::DataProcessorSpec getITSTrackReaderSpec(bool useMC = true);
63+
64+
} // namespace ITS
65+
} // namespace o2
66+
67+
#endif /* O2_ITS_TRACKREADER */
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// @file TrackReaderSpec.cxx
12+
13+
#include <vector>
14+
15+
#include "TTree.h"
16+
17+
#include "Framework/ControlService.h"
18+
#include "ITSWorkflow/TrackReaderSpec.h"
19+
20+
using namespace o2::framework;
21+
using namespace o2::ITS;
22+
23+
namespace o2
24+
{
25+
namespace ITS
26+
{
27+
28+
TrackReader::TrackReader(bool useMC)
29+
{
30+
mUseMC = useMC;
31+
}
32+
33+
void TrackReader::init(InitContext& ic)
34+
{
35+
mInputFileName = ic.options().get<std::string>("its-tracks-infile");
36+
}
37+
38+
void TrackReader::run(ProcessingContext& pc)
39+
{
40+
41+
if (mFinished) {
42+
return;
43+
}
44+
accumulate();
45+
46+
LOG(INFO) << "ITSTrackReader pushes " << mROFRecOut.size() << " ROFRecords,"
47+
<< mTracksOut.size() << " tracks";
48+
pc.outputs().snapshot(Output{ mOrigin, "ITSTrackROF", 0, Lifetime::Timeframe }, mROFRecOut);
49+
pc.outputs().snapshot(Output{ mOrigin, "TRACKS", 0, Lifetime::Timeframe }, mTracksOut);
50+
if (mUseMC) {
51+
pc.outputs().snapshot(Output{ mOrigin, "TRACKSMCTR", 0, Lifetime::Timeframe }, mMCTruthOut);
52+
}
53+
54+
mFinished = true;
55+
pc.services().get<ControlService>().readyToQuit(false);
56+
}
57+
58+
void TrackReader::accumulate()
59+
{
60+
// load data from files
61+
TFile trFile(mInputFileName.c_str(), "read");
62+
if (trFile.IsZombie()) {
63+
LOG(FATAL) << "Failed to open tracks file " << mInputFileName;
64+
}
65+
TTree* trTree = (TTree*)trFile.Get(mTrackTreeName.c_str());
66+
if (!trTree) {
67+
LOG(FATAL) << "Failed to load tracks tree " << mTrackTreeName << " from " << mInputFileName;
68+
}
69+
TTree* rofTree = (TTree*)trFile.Get(mROFTreeName.c_str());
70+
if (!rofTree) {
71+
LOG(FATAL) << "Failed to load tracks ROF tree " << rofTree << " from " << mInputFileName;
72+
}
73+
LOG(INFO) << "Loaded tracks tree " << mTrackTreeName << " and ROFRecords " << mROFTreeName
74+
<< " from " << mInputFileName;
75+
76+
rofTree->SetBranchAddress(mROFTreeName.c_str(), &mROFRecInp);
77+
trTree->SetBranchAddress(mTrackBranchName.c_str(), &mTracksInp);
78+
if (mUseMC) {
79+
if (trTree->GetBranch(mTrackMCTruthBranchName.c_str())) {
80+
trTree->SetBranchAddress(mTrackMCTruthBranchName.c_str(), &mMCTruthInp);
81+
LOG(INFO) << "Will use MC-truth from " << mTrackMCTruthBranchName;
82+
} else {
83+
LOG(INFO) << "MC-truth is missing";
84+
mUseMC = false;
85+
}
86+
}
87+
// it is possible that the track data is stored in multiple entries, in this case we need to refill to 1 single vector
88+
if (rofTree->GetEntries() > 1) {
89+
LOG(FATAL) << "Tracks ROFRecords tree has " << rofTree->GetEntries() << " entries instead of 1";
90+
}
91+
rofTree->GetEntry(0);
92+
int nROFs = mROFRecInp->size();
93+
mROFRecOut.swap(*mROFRecInp);
94+
int nEnt = trTree->GetEntries();
95+
if (nEnt == 1) {
96+
trTree->GetEntry(0);
97+
mTracksOut.swap(*mTracksInp);
98+
if (mUseMC) {
99+
mMCTruthOut.mergeAtBack(*mMCTruthInp);
100+
}
101+
} else {
102+
int lastEntry = -1;
103+
int ntrAcc = 0;
104+
for (auto& rof : mROFRecOut) {
105+
auto rEntry = rof.getROFEntry().getEvent();
106+
if (lastEntry != rEntry) {
107+
trTree->GetEntry((lastEntry = rEntry));
108+
}
109+
auto tr0 = mTracksInp->begin() + rof.getROFEntry().getIndex();
110+
auto tr1 = tr0 + rof.getNROFEntries();
111+
std::copy(tr0, tr1, std::back_inserter(mTracksOut));
112+
// MC
113+
if (mUseMC) {
114+
mMCTruthOut.mergeAtBack(*mMCTruthInp);
115+
}
116+
rof.getROFEntry().setEvent(0);
117+
rof.getROFEntry().setIndex(ntrAcc);
118+
ntrAcc += rof.getNROFEntries();
119+
}
120+
}
121+
}
122+
123+
DataProcessorSpec getITSTrackReaderSpec(bool useMC)
124+
{
125+
std::vector<OutputSpec> outputSpec;
126+
outputSpec.emplace_back("ITS", "ITSTrackROF", 0, Lifetime::Timeframe);
127+
outputSpec.emplace_back("ITS", "TRACKS", 0, Lifetime::Timeframe);
128+
if (useMC) {
129+
outputSpec.emplace_back("ITS", "TRACKSMCTR", 0, Lifetime::Timeframe);
130+
}
131+
132+
return DataProcessorSpec{
133+
"its-track-reader",
134+
Inputs{},
135+
outputSpec,
136+
AlgorithmSpec{ adaptFromTask<TrackReader>(useMC) },
137+
Options{
138+
{ "its-tracks-infile", VariantType::String, "o2trac_its.root", { "Name of the input track file" } } }
139+
};
140+
}
141+
142+
} // namespace ITS
143+
} // namespace o2

0 commit comments

Comments
 (0)