Skip to content

Commit 63eca50

Browse files
authored
TrackCosmicExtended reader, attach to InputHelper and RecoContainer (#16017)
1 parent 332034c commit 63eca50

10 files changed

Lines changed: 276 additions & 1 deletion

File tree

‎DataFormats/Detectors/GlobalTracking/include/DataFormatsGlobalTracking/RecoContainer.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ class Decay3Body;
172172
class Decay3BodyIndex;
173173
class StrangeTrack;
174174
class TrackCosmics;
175+
struct TrackCosmicsExtended;
176+
struct CosmicsTFInfo;
177+
struct TFIDInfo;
175178
class GlobalFwdTrack;
176179
class MatchInfoFwd;
177180
class TrackMCHMID;
@@ -253,6 +256,7 @@ struct DataRequest {
253256
void requestCPVClusters(bool mc);
254257

255258
void requestCoscmicTracks(bool mc);
259+
void requestCosmicExtTracks(bool mc); // MC is not supported, argument is for uniformity
256260

257261
void requestPrimaryVertices(bool mc);
258262
void requestPrimaryVerticesTMP(bool mc);
@@ -324,6 +328,9 @@ struct RecoContainer {
324328
// slots for cosmics
325329
enum CosmicsSlots { COSM_TRACKS,
326330
COSM_TRACKS_MC,
331+
COSMEXT_TRACKS, // extended cosmics (with clusters), no MC
332+
COSMEXT_TFINFO, // per-TF info of the extended cosmics
333+
COSMEXT_TFID, // TFIDInfo of the extended cosmics
327334
NCOSMSLOTS };
328335

329336
// slots to register ITS/MFT clusters data (per layer, or all layers together in the slot 0)
@@ -371,6 +378,7 @@ struct RecoContainer {
371378
std::unique_ptr<const std::vector<o2::MCCompLabel>> mcMIDTracks;
372379
o2::ctp::LumiInfo mCTPLumi;
373380

381+
std::shared_ptr<const void> cosmExtHolder[3]; // owners of the extended cosmics, TF info and TFID objects deserialized from the messages
374382
gsl::span<const unsigned char> clusterShMapTPC; ///< externally set TPC clusters sharing map
375383
gsl::span<const unsigned int> occupancyMapTPC; ///< externally set TPC clusters occupancy map
376384

@@ -429,6 +437,7 @@ struct RecoContainer {
429437
void addEMCALCells(o2::framework::ProcessingContext& pc, bool mc);
430438

431439
void addCosmicTracks(o2::framework::ProcessingContext& pc, bool mc);
440+
void addCosmicExtTracks(o2::framework::ProcessingContext& pc, bool mc);
432441

433442
void addPVertices(o2::framework::ProcessingContext& pc, bool mc);
434443
void addPVerticesTMP(o2::framework::ProcessingContext& pc, bool mc);
@@ -755,6 +764,12 @@ struct RecoContainer {
755764
auto getCosmicTracks() const { return cosmPool.getSpan<o2::dataformats::TrackCosmics>(COSM_TRACKS); }
756765
auto getCosmicTrackMCLabels() const { return cosmPool.getSpan<o2::MCCompLabel>(COSM_TRACKS_MC); }
757766

767+
// Extended cosmic tracks (with clusters); the user must include DataFormatsGlobalTracking/TrackCosmicsExtended.h and CommonDataFormat/TFIDInfo.h
768+
const o2::dataformats::TrackCosmicsExtended& getCosmicExtTrack(int i) const { return cosmPool.get_as<o2::dataformats::TrackCosmicsExtended>(COSMEXT_TRACKS, i); }
769+
auto getCosmicExtTracks() const { return cosmPool.getSpan<o2::dataformats::TrackCosmicsExtended>(COSMEXT_TRACKS); }
770+
const o2::dataformats::CosmicsTFInfo& getCosmicExtTFInfo() const { return cosmPool.get_as<o2::dataformats::CosmicsTFInfo>(COSMEXT_TFINFO, 0); }
771+
const o2::dataformats::TFIDInfo& getCosmicExtTFID() const { return cosmPool.get_as<o2::dataformats::TFIDInfo>(COSMEXT_TFID, 0); }
772+
758773
// IRFrames where ITS was reconstructed and tracks were seen (e.g. sync.w-flow mult. selection)
759774
auto getIRFramesITS() const { return getSpan<o2::dataformats::IRFrame>(GTrackID::ITS, VARIA); }
760775

‎DataFormats/Detectors/GlobalTracking/src/RecoContainer.cxx‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "ReconstructionDataFormats/VtxTrackIndex.h"
3232
#include "ReconstructionDataFormats/VtxTrackRef.h"
3333
#include "ReconstructionDataFormats/TrackCosmics.h"
34+
#include "DataFormatsGlobalTracking/TrackCosmicsExtended.h"
35+
#include "CommonDataFormat/TFIDInfo.h"
3436
#include "ReconstructionDataFormats/TrackMCHMID.h"
3537
#include "DataFormatsITSMFT/TrkClusRef.h"
3638
#include "DataFormatsITSMFT/TopologyDictionary.h"
@@ -429,6 +431,17 @@ void DataRequest::requestCoscmicTracks(bool mc)
429431
requestMap["Cosmics"] = mc;
430432
}
431433

434+
void DataRequest::requestCosmicExtTracks(bool mc)
435+
{
436+
addInput({"cosmicsExt", "GLO", "COSMFULL", 0, Lifetime::Timeframe});
437+
addInput({"cosmicsExtTF", "GLO", "COSMFULLTF", 0, Lifetime::Timeframe});
438+
addInput({"cosmicsExtTFID", "GLO", "COSMFULLTFID", 0, Lifetime::Timeframe});
439+
if (mc) {
440+
LOG(error) << "Extended cosmics do not support MC truth";
441+
}
442+
requestMap["CosmicsExt"] = false;
443+
}
444+
432445
void DataRequest::requestPrimaryVertices(bool mc)
433446
{
434447
addInput({"pvtx", "GLO", "PVTX", 0, Lifetime::Timeframe});
@@ -825,6 +838,11 @@ void RecoContainer::collectData(ProcessingContext& pc, const DataRequest& reques
825838
addCosmicTracks(pc, req->second);
826839
}
827840

841+
req = reqMap.find("CosmicsExt");
842+
if (req != reqMap.end()) {
843+
addCosmicExtTracks(pc, req->second);
844+
}
845+
828846
req = reqMap.find("PVertex");
829847
if (req != reqMap.end()) {
830848
addPVertices(pc, req->second);
@@ -903,6 +921,27 @@ void RecoContainer::addPVerticesTMP(ProcessingContext& pc, bool mc)
903921
}
904922
}
905923

924+
//____________________________________________________________
925+
void RecoContainer::addCosmicExtTracks(ProcessingContext& pc, bool mc)
926+
{
927+
using o2::dataformats::CosmicsTFInfo;
928+
using o2::dataformats::TFIDInfo;
929+
using o2::dataformats::TrackCosmicsExtended;
930+
// the messages are ROOT-serialized, keep the deserialized objects alive until the next TF
931+
std::shared_ptr<const std::vector<TrackCosmicsExtended>> cosm = pc.inputs().get<std::vector<TrackCosmicsExtended>*>("cosmicsExt");
932+
std::shared_ptr<const CosmicsTFInfo> tfInfo = pc.inputs().get<CosmicsTFInfo*>("cosmicsExtTF");
933+
std::shared_ptr<const TFIDInfo> tfID = pc.inputs().get<TFIDInfo*>("cosmicsExtTFID");
934+
cosmPool.registerContainer(*cosm, COSMEXT_TRACKS);
935+
cosmPool.registerContainer(gsl::span<const CosmicsTFInfo>(tfInfo.get(), 1), COSMEXT_TFINFO);
936+
cosmPool.registerContainer(gsl::span<const TFIDInfo>(tfID.get(), 1), COSMEXT_TFID);
937+
cosmExtHolder[0] = std::move(cosm);
938+
cosmExtHolder[1] = std::move(tfInfo);
939+
cosmExtHolder[2] = std::move(tfID);
940+
if (mc) {
941+
LOG(error) << "Extended cosmics do not support MC truth";
942+
}
943+
}
944+
906945
//____________________________________________________________
907946
void RecoContainer::addCosmicTracks(ProcessingContext& pc, bool mc)
908947
{

‎Detectors/GlobalTrackingWorkflow/CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ o2_add_executable(match-workflow
6767
SOURCES src/cosmics-match-workflow.cxx
6868
PUBLIC_LINK_LIBRARIES O2::GlobalTrackingWorkflow O2::TOFWorkflowIO)
6969

70+
o2_add_executable(reader-workflow
71+
COMPONENT_NAME cosmic-ext
72+
SOURCES src/cosmic-ext-reader-workflow.cxx
73+
PUBLIC_LINK_LIBRARIES O2::GlobalTrackingWorkflow)
74+
7075
o2_add_executable(vertexing-workflow
7176
COMPONENT_NAME primary
7277
SOURCES src/primary-vertexing-workflow.cxx

‎Detectors/GlobalTrackingWorkflow/helpers/include/GlobalTrackingWorkflowHelpers/InputHelper.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class InputHelper
4040
static int addInputSpecsSVertex(const o2::framework::ConfigContext& configcontext, o2::framework::WorkflowSpec& specs);
4141
static int addInputSpecsStrangeTrack(const o2::framework::ConfigContext& configcontext, o2::framework::WorkflowSpec& specs, bool mc);
4242
static int addInputSpecsCosmics(const o2::framework::ConfigContext& configcontext, o2::framework::WorkflowSpec& specs, bool mc);
43+
static int addInputSpecsCosmicsExtended(const o2::framework::ConfigContext& configcontext, o2::framework::WorkflowSpec& specs);
4344
static int addInputSpecsIRFramesITS(const o2::framework::ConfigContext& configcontext, o2::framework::WorkflowSpec& specs);
4445
};
4546

‎Detectors/GlobalTrackingWorkflow/helpers/src/GlobalTrackClusterReader.cxx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
3535
{"primary-vertices", VariantType::Bool, false, {"read primary vertices"}},
3636
{"secondary-vertices", VariantType::Bool, false, {"read secondary vertices"}},
3737
{"cosmic", VariantType::Bool, false, {"read cosmic tracks"}},
38+
{"cosmic-ext", VariantType::Bool, false, {"read extended cosmic tracks with clusters"}},
3839
{"ir-frames-its", VariantType::Bool, false, {"read ITS IR frames"}},
3940
{"disable-root-input", o2::framework::VariantType::Bool, false, {"disable reading root files, essentially making this workflow void, but needed for compatibility"}},
4041
{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}};
@@ -56,9 +57,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
5657
bool pv = cfgc.options().get<bool>("primary-vertices");
5758
bool sv = cfgc.options().get<bool>("secondary-vertices");
5859
bool cosm = cfgc.options().get<bool>("cosmic");
60+
bool cosmExt = cfgc.options().get<bool>("cosmic-ext");
5961
bool irits = cfgc.options().get<bool>("ir-frames-its");
6062

61-
if (!cfgc.helpOnCommandLine() && srcTrk.none() && srcCl.none() && !(pv || sv || cosm || irits)) {
63+
if (!cfgc.helpOnCommandLine() && srcTrk.none() && srcCl.none() && !(pv || sv || cosm || cosmExt || irits)) {
6264
throw std::runtime_error("nothing requested to read");
6365
}
6466
auto srcMtc = srcTrk & ~GlobalTrackID::getSourceMask(GlobalTrackID::MFTMCH); // Do not request MFTMCH matches
@@ -72,6 +74,9 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
7274
if (cosm) {
7375
InputHelper::addInputSpecsCosmics(cfgc, specs, useMC);
7476
}
77+
if (cosmExt) {
78+
InputHelper::addInputSpecsCosmicsExtended(cfgc, specs);
79+
}
7580
if (irits) {
7681
InputHelper::addInputSpecsIRFramesITS(cfgc, specs);
7782
}

‎Detectors/GlobalTrackingWorkflow/helpers/src/InputHelper.cxx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "GlobalTrackingWorkflowReaders/SecondaryVertexReaderSpec.h"
3232
#include "GlobalTrackingWorkflowReaders/StrangenessTrackingReaderSpec.h"
3333
#include "GlobalTrackingWorkflowReaders/TrackCosmicsReaderSpec.h"
34+
#include "GlobalTrackingWorkflowReaders/TrackCosmicsExtendedReaderSpec.h"
3435
#include "GlobalTrackingWorkflowReaders/IRFrameReaderSpec.h"
3536
#include "TOFWorkflowIO/ClusterReaderSpec.h"
3637
#include "TOFWorkflowIO/TOFMatchedReaderSpec.h"
@@ -225,6 +226,16 @@ int InputHelper::addInputSpecsCosmics(const o2::framework::ConfigContext& config
225226
return 0;
226227
}
227228

229+
// attach extended cosmic tracks reader
230+
int InputHelper::addInputSpecsCosmicsExtended(const o2::framework::ConfigContext& configcontext, o2::framework::WorkflowSpec& specs)
231+
{
232+
if (configcontext.options().get<bool>("disable-root-input")) {
233+
return 0;
234+
}
235+
specs.emplace_back(o2::globaltracking::getTrackCosmicsExtendedReaderSpec());
236+
return 0;
237+
}
238+
228239
// attach vector of ITS reconstructed IRFrames
229240
int InputHelper::addInputSpecsIRFramesITS(const o2::framework::ConfigContext& configcontext, o2::framework::WorkflowSpec& specs)
230241
{

‎Detectors/GlobalTrackingWorkflow/readers/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
o2_add_library(GlobalTrackingWorkflowReaders
1313
SOURCES src/TrackCosmicsReaderSpec.cxx
14+
src/TrackCosmicsExtendedReaderSpec.cxx
1415
src/SecondaryVertexReaderSpec.cxx
1516
src/PrimaryVertexReaderSpec.cxx
1617
src/StrangenessTrackingReaderSpec.cxx
@@ -20,6 +21,7 @@ o2_add_library(GlobalTrackingWorkflowReaders
2021
src/MatchedMCHMIDReaderSpec.cxx
2122
src/IRFrameReaderSpec.cxx
2223
PUBLIC_LINK_LIBRARIES O2::ReconstructionDataFormats
24+
O2::DataFormatsGlobalTracking
2325
O2::DataFormatsITSMFT
2426
O2::SimulationDataFormat)
2527

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
12+
/// @file TrackCosmicsExtendedReaderSpec.h
13+
14+
#ifndef O2_GLOBAL_TRACKCOSMICSEXTENDED_READER
15+
#define O2_GLOBAL_TRACKCOSMICSEXTENDED_READER
16+
17+
#include "TFile.h"
18+
#include "TTree.h"
19+
20+
#include "Framework/DataProcessorSpec.h"
21+
#include "Framework/Task.h"
22+
#include "DataFormatsGlobalTracking/TrackCosmicsExtended.h"
23+
#include "CommonDataFormat/TFIDInfo.h"
24+
25+
using namespace o2::framework;
26+
27+
namespace o2
28+
{
29+
namespace globaltracking
30+
{
31+
32+
class TrackCosmicsExtendedReader : public Task
33+
{
34+
public:
35+
TrackCosmicsExtendedReader() = default;
36+
~TrackCosmicsExtendedReader() override = default;
37+
void init(InitContext& ic) final;
38+
void run(ProcessingContext& pc) final;
39+
40+
private:
41+
void connectTree(const std::string& filename);
42+
std::unique_ptr<TFile> mFile;
43+
std::unique_ptr<TTree> mTree;
44+
std::string mFileName = "";
45+
std::vector<o2::dataformats::TrackCosmicsExtended> mCosmics, *mCosmicsPtr = &mCosmics;
46+
o2::dataformats::CosmicsTFInfo mTFInfo, *mTFInfoPtr = &mTFInfo;
47+
o2::dataformats::TFIDInfo mTFID, *mTFIDPtr = &mTFID;
48+
};
49+
50+
/// create a processor spec to read the extended cosmics (as written by cosmics-full-writer) from a root file
51+
framework::DataProcessorSpec getTrackCosmicsExtendedReaderSpec();
52+
53+
} // namespace globaltracking
54+
} // namespace o2
55+
56+
#endif /* O2_GLOBAL_TRACKCOSMICSEXTENDED_READER */
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
12+
/// @file TrackCosmicsExtendedReaderSpec.cxx
13+
14+
#include <vector>
15+
16+
#include "Framework/ConfigParamRegistry.h"
17+
#include "Framework/ControlService.h"
18+
#include "GlobalTrackingWorkflowReaders/TrackCosmicsExtendedReaderSpec.h"
19+
#include "CommonUtils/NameConf.h"
20+
#include "CommonUtils/StringUtils.h"
21+
22+
using namespace o2::framework;
23+
using namespace o2::globaltracking;
24+
25+
namespace o2
26+
{
27+
namespace globaltracking
28+
{
29+
void TrackCosmicsExtendedReader::init(InitContext& ic)
30+
{
31+
mFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
32+
ic.options().get<std::string>("cosmics-full-infile"));
33+
connectTree(mFileName);
34+
}
35+
36+
void TrackCosmicsExtendedReader::run(ProcessingContext& pc)
37+
{
38+
auto ent = mTree->GetReadEntry() + 1;
39+
// Same as in TrackCosmicsReader: publish empty containers if the tree has no entry left
40+
const bool noEntry = ent >= mTree->GetEntries();
41+
if (noEntry) {
42+
LOG(info) << "no entry to read, publishing empty output";
43+
mCosmics.clear();
44+
mTFInfo = {};
45+
mTFID = {};
46+
} else {
47+
mTree->GetEntry(ent);
48+
}
49+
LOG(info) << "Pushing " << mCosmics.size() << " cosmics with clusters at entry " << ent;
50+
51+
pc.outputs().snapshot(Output{"GLO", "COSMFULL", 0}, mCosmics);
52+
pc.outputs().snapshot(Output{"GLO", "COSMFULLTF", 0}, mTFInfo);
53+
pc.outputs().snapshot(Output{"GLO", "COSMFULLTFID", 0}, mTFID);
54+
55+
if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
56+
pc.services().get<ControlService>().endOfStream();
57+
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
58+
}
59+
}
60+
61+
void TrackCosmicsExtendedReader::connectTree(const std::string& filename)
62+
{
63+
mTree.reset(nullptr); // in case it was already loaded
64+
mFile.reset(TFile::Open(filename.c_str()));
65+
if (!mFile || mFile->IsZombie()) {
66+
LOGP(fatal, "Failed to open {}", filename);
67+
}
68+
mTree.reset((TTree*)mFile->Get("cosmicsFull"));
69+
if (!mTree) {
70+
LOGP(fatal, "Tree cosmicsFull is not found in {}", filename);
71+
}
72+
mTree->SetBranchAddress("cosmics", &mCosmicsPtr);
73+
mTree->SetBranchAddress("tfInfo", &mTFInfoPtr);
74+
mTree->SetBranchAddress("tfID", &mTFIDPtr);
75+
LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
76+
}
77+
78+
DataProcessorSpec getTrackCosmicsExtendedReaderSpec()
79+
{
80+
std::vector<OutputSpec> outputs;
81+
outputs.emplace_back("GLO", "COSMFULL", 0, Lifetime::Timeframe);
82+
outputs.emplace_back("GLO", "COSMFULLTF", 0, Lifetime::Timeframe);
83+
outputs.emplace_back("GLO", "COSMFULLTFID", 0, Lifetime::Timeframe);
84+
85+
return DataProcessorSpec{
86+
"cosmic-ext-reader",
87+
Inputs{},
88+
outputs,
89+
AlgorithmSpec{adaptFromTask<TrackCosmicsExtendedReader>()},
90+
Options{
91+
{"cosmics-full-infile", VariantType::String, "o2_cosmics_full.root", {"Name of the input file"}},
92+
{"input-dir", VariantType::String, "none", {"Input directory"}}}};
93+
}
94+
95+
} // namespace globaltracking
96+
} // namespace o2

0 commit comments

Comments
 (0)