Skip to content

Commit 79d148f

Browse files
committed
started including to digitization workflow
1 parent 3776c80 commit 79d148f

17 files changed

Lines changed: 691 additions & 10 deletions

File tree

DataFormats/Detectors/Upgrades/ALICE3/FD3/src/DataFormatsFD3LinkDef.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,18 @@
1717

1818
#pragma link C++ class o2::fd3::Hit + ;
1919
#pragma link C++ class vector < o2::fd3::Hit> + ;
20+
#include "SimulationDataFormat/MCTruthContainer.h"
21+
#pragma link C++ class o2::dataformats::MCTruthContainer < o2::fd3::MCLabel> + ;
22+
23+
#pragma link C++ class o2::fd3::ChannelData + ;
24+
#pragma link C++ class o2::fd3::Digit + ;
25+
#pragma link C++ class o2::fd3::DetTrigInput + ;
26+
#pragma link C++ class std::vector < o2::fd3::ChannelData> + ;
27+
#pragma link C++ class std::vector < o2::fd3::DetTrigInput> + ;
28+
#pragma link C++ class std::vector < o2::fd3::Digit> + ;
29+
30+
#pragma link C++ class o2::fd3::CTFHeader + ;
31+
#pragma link C++ class o2::fd3::CTF + ;
32+
#pragma link C++ class o2::ctf::EncodedBlocks < o2::fd3::CTFHeader, 8, uint32_t> + ;
2033

2134
#endif

Detectors/Upgrades/ALICE3/FD3/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111

1212
add_subdirectory(base)
1313
add_subdirectory(simulation)
14+
add_subdirectory(workflow)

Detectors/Upgrades/ALICE3/FD3/simulation/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ o2_add_library(FD3Simulation
1919
o2_target_root_dictionary(FD3Simulation
2020
HEADERS include/FD3Simulation/Detector.h
2121
include/FD3Simulation/DigitizationConstants.h
22+
include/FD3Simulation/FD3DigParam.h
2223
include/FD3Simulation/Digitizer.h)

Detectors/Upgrades/ALICE3/FD3/simulation/include/FD3Simulation/FD3DigParam.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ struct FD3DigParam : o2::conf::ConfigurableParamHelper<FD3DigParam> {
4141
float slopeRings = 4.7942e+08;
4242
float mpvRings = -6.38203e-08;
4343
float sigmaRings = 2.12167e-09;
44-
// For ring 5
45-
// float offsetRing5 = 16.38e-09;
46-
// float normRing5base = 1.1680805e-12;
47-
// float getNormRing5() const { return normRing5base * adcChannelsPerMip / 16; }
48-
// float constRing5 = -66.76;
49-
// float slopeRing5 = 9.43117e+08;
50-
// float mpvRing5 = -6.44167e-08;
51-
// float sigmaRing5 = 2.3621e-09;
5244

5345
float timeShiftCfd = 5.3; // TODO: adjust after FD3 with FEE measurements are done
5446
float singleMipThreshold = 3.0; // in [MeV] of deposited energy

Detectors/Upgrades/ALICE3/FD3/simulation/src/FD3SimulationLinkDef.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
1+
// Copyright 2019-2025 CERN and copyright holders of ALICE O2.
22
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
33
// All rights not expressly granted are reserved.
44
//
@@ -17,5 +17,7 @@
1717

1818
#pragma link C++ class o2::fd3::Detector + ;
1919
#pragma link C++ class o2::base::DetImpl < o2::fd3::Detector> + ;
20+
#pragma link C++ class o2::fd3::Digitizer + ;
21+
#pragma link C++ class o2::fd3::FD3DigParam + ;
2022

2123
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
o2_add_library(FD3Workflow
13+
SOURCES src/FD3DigitReaderSpec.cxx
14+
src/FD3DigitWriterSpec.cxx
15+
PUBLIC_LINK_LIBRARIES O2::DataFormatsFD3
16+
O2::DetectorsCommonDataFormats
17+
O2::Framework
18+
O2::DPLUtils
19+
O2::CommonUtils)
20+
21+
22+
o2_add_executable(digit-reader-workflow
23+
SOURCES src/digits-reader-workflow.cxx
24+
COMPONENT_NAME fd3
25+
PUBLIC_LINK_LIBRARIES O2::FD3Workflow)
26+
27+
o2_add_executable(digits-writer-workflow
28+
SOURCES src/digits-writer-workflow.cxx
29+
COMPONENT_NAME fd3
30+
PUBLIC_LINK_LIBRARIES O2::FD3Workflow)
31+
32+
33+
if(NOT APPLE)
34+
35+
set_property(TARGET ${fitrecoexe} PROPERTY LINK_WHAT_YOU_USE ON)
36+
37+
endif()
38+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2019-2025 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+
#ifndef O2_FD3_DIGITREADERSPEC_H
13+
#define O2_FD3_DIGITREADERSPEC_H
14+
15+
#include "TFile.h"
16+
#include "TTree.h"
17+
#include "Framework/DataProcessorSpec.h"
18+
#include "Framework/Task.h"
19+
20+
namespace o2
21+
{
22+
namespace fd3
23+
{
24+
25+
class DigitReader : public framework::Task
26+
{
27+
public:
28+
DigitReader(bool useMC, bool useTrgInput) : mUseMC(useMC), mUseTrgInput(useTrgInput) {}
29+
~DigitReader() override = default;
30+
void init(framework::InitContext& ic) final;
31+
void run(framework::ProcessingContext& pc) final;
32+
33+
private:
34+
bool mUseMC = false;
35+
bool mUseTrgInput = true;
36+
std::unique_ptr<TTree> mTree;
37+
std::unique_ptr<TFile> mFile;
38+
};
39+
40+
/// create a processor spec
41+
/// read simulated FD3 digits from a root file
42+
framework::DataProcessorSpec getDigitReaderSpec(bool useMC = false, bool useTrgInput = true);
43+
44+
} // end namespace fd3
45+
} // end namespace o2
46+
47+
#endif // O2_FD3_DIGITREADERSPEC_H
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2019-2025 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 FD3DigitWriterSpec.h
13+
14+
#ifndef O2_FD3DIGITWRITER_H
15+
#define O2_FD3DIGITWRITER_H
16+
17+
#include "Framework/DataProcessorSpec.h"
18+
#include "DPLUtils/MakeRootTreeWriterSpec.h"
19+
#include "Framework/InputSpec.h"
20+
#include "DataFormatsFD3/Digit.h"
21+
#include "DataFormatsFD3/MCLabel.h"
22+
#include "SimulationDataFormat/IOMCTruthContainerView.h"
23+
#include "SimulationDataFormat/ConstMCTruthContainer.h"
24+
#include "SimulationDataFormat/MCCompLabel.h"
25+
26+
using namespace o2::framework;
27+
28+
namespace o2
29+
{
30+
namespace fd3
31+
{
32+
33+
/// create a processor spec
34+
framework::DataProcessorSpec getFD3DigitWriterSpec(bool mctruth = true, bool trigInp = true);
35+
36+
} // namespace fd3
37+
} // namespace o2
38+
39+
#endif /* O2_FD3DIGITWRITER_H */
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2019-2025 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 DigitReaderSpec.cxx
13+
14+
#include <vector>
15+
#include <TTree.h>
16+
#include "Framework/ConfigParamRegistry.h"
17+
#include "Framework/ControlService.h"
18+
#include "Framework/Logger.h"
19+
#include "FD3Workflow/FD3DigitReaderSpec.h"
20+
#include "DataFormatsFD3/Digit.h"
21+
#include "DataFormatsFD3/ChannelData.h"
22+
#include "DataFormatsFD3/MCLabel.h"
23+
#include "SimulationDataFormat/MCTruthContainer.h"
24+
#include "CommonUtils/NameConf.h"
25+
26+
using namespace o2::framework;
27+
28+
namespace o2
29+
{
30+
namespace fd3
31+
{
32+
33+
void DigitReader::init(InitContext& ic)
34+
{
35+
auto filename = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
36+
ic.options().get<std::string>("fd3-digit-infile"));
37+
mFile.reset(TFile::Open(filename.c_str()));
38+
if (!mFile->IsOpen()) {
39+
LOG(error) << "Cannot open the " << filename.c_str() << " file !";
40+
throw std::runtime_error("cannot open input digits file");
41+
}
42+
mTree.reset((TTree*)mFile->Get("o2sim"));
43+
if (!mTree) {
44+
LOG(error) << "Did not find o2sim tree in " << filename.c_str();
45+
throw std::runtime_error("Did not fine o2sim file in FD3 digits tree");
46+
}
47+
}
48+
49+
void DigitReader::run(ProcessingContext& pc)
50+
{
51+
52+
std::vector<o2::fd3::Digit> digits, *pdigits = &digits;
53+
std::vector<o2::fd3::DetTrigInput> trgInput, *ptrTrgInput = &trgInput;
54+
std::vector<o2::fd3::ChannelData> channels, *pchannels = &channels;
55+
mTree->SetBranchAddress("FD3DigitBC", &pdigits);
56+
mTree->SetBranchAddress("FD3DigitCh", &pchannels);
57+
if (mUseTrgInput) {
58+
mTree->SetBranchAddress("TRIGGERINPUT", &ptrTrgInput);
59+
}
60+
o2::dataformats::MCTruthContainer<o2::fd3::MCLabel> labels, *plabels = &labels;
61+
if (mUseMC) {
62+
mTree->SetBranchAddress("FD3DigitLabels", &plabels);
63+
}
64+
auto ent = mTree->GetReadEntry() + 1;
65+
assert(ent < mTree->GetEntries()); // this should not happen
66+
mTree->GetEntry(ent);
67+
LOG(debug) << "FD3DigitReader pushed " << channels.size() << " channels in " << digits.size() << " digits";
68+
pc.outputs().snapshot(Output{"FD3", "DIGITSBC", 0}, digits);
69+
pc.outputs().snapshot(Output{"FD3", "DIGITSCH", 0}, channels);
70+
if (mUseMC) {
71+
pc.outputs().snapshot(Output{"FD3", "DIGITSMCTR", 0}, labels);
72+
}
73+
if (mUseTrgInput) {
74+
pc.outputs().snapshot(Output{"FD3", "TRIGGERINPUT", 0}, trgInput);
75+
}
76+
if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
77+
pc.services().get<ControlService>().endOfStream();
78+
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
79+
}
80+
}
81+
82+
DataProcessorSpec getDigitReaderSpec(bool useMC, bool useTrgInput)
83+
{
84+
std::vector<OutputSpec> outputs;
85+
outputs.emplace_back("FD3", "DIGITSBC", 0, Lifetime::Timeframe);
86+
outputs.emplace_back("FD3", "DIGITSCH", 0, Lifetime::Timeframe);
87+
if (useMC) {
88+
outputs.emplace_back("FD3", "DIGITSMCTR", 0, Lifetime::Timeframe);
89+
}
90+
if (useTrgInput) {
91+
outputs.emplace_back("FD3", "TRIGGERINPUT", 0, Lifetime::Timeframe);
92+
}
93+
return DataProcessorSpec{
94+
"fd3-digit-reader",
95+
Inputs{},
96+
outputs,
97+
AlgorithmSpec{adaptFromTask<DigitReader>(useMC, useTrgInput)},
98+
Options{
99+
{"fd3-digit-infile", VariantType::String, "fd3digits.root", {"Name of the input file"}},
100+
{"input-dir", VariantType::String, "none", {"Input directory"}}}};
101+
}
102+
103+
} // namespace fd3
104+
} // namespace o2
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2019-2025 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 FD3DigitWriterSpec.cxx
13+
#include "FD3Workflow/FD3DigitWriterSpec.h"
14+
15+
namespace o2
16+
{
17+
namespace fd3
18+
{
19+
20+
template <typename T>
21+
using BranchDefinition = framework::MakeRootTreeWriterSpec::BranchDefinition<T>;
22+
23+
o2::framework::DataProcessorSpec getFD3DigitWriterSpec(bool mctruth, bool trigInp)
24+
{
25+
using InputSpec = framework::InputSpec;
26+
using MakeRootTreeWriterSpec = framework::MakeRootTreeWriterSpec;
27+
// Spectators for logging
28+
auto logger = [](std::vector<o2::fd3::Digit> const& vecDigits) {
29+
LOG(debug) << "FD3DigitWriter pulled " << vecDigits.size() << " digits";
30+
};
31+
// the callback to be set as hook for custom action when the writer is closed
32+
auto finishWriting = [](TFile* outputfile, TTree* outputtree) {
33+
const auto* brArr = outputtree->GetListOfBranches();
34+
int64_t nent = 0;
35+
for (const auto* brc : *brArr) {
36+
int64_t n = ((const TBranch*)brc)->GetEntries();
37+
if (nent && (nent != n)) {
38+
LOG(error) << "Branches have different number of entries";
39+
}
40+
nent = n;
41+
}
42+
outputtree->SetEntries(nent);
43+
outputtree->Write();
44+
outputfile->Close();
45+
};
46+
47+
auto labelsdef = BranchDefinition<o2::dataformats::MCTruthContainer<o2::fd3::MCLabel>>{InputSpec{"labelinput", "FD3", "DIGITSMCTR"},
48+
"FD3DIGITSMCTR", mctruth ? 1 : 0};
49+
if (trigInp) {
50+
return MakeRootTreeWriterSpec("FD3DigitWriter",
51+
"fd3digits.root",
52+
"o2sim",
53+
MakeRootTreeWriterSpec::CustomClose(finishWriting),
54+
BranchDefinition<std::vector<o2::fd3::Digit>>{InputSpec{"digitBCinput", "FD3", "DIGITSBC"}, "FD3DigitBC", 1,
55+
logger},
56+
BranchDefinition<std::vector<o2::fd3::ChannelData>>{InputSpec{"digitChinput", "FD3", "DIGITSCH"}, "FD3DigitCh"},
57+
BranchDefinition<std::vector<o2::fd3::DetTrigInput>>{InputSpec{"digitTrinput", "FD3", "TRIGGERINPUT"}, "TRIGGERINPUT"},
58+
std::move(labelsdef))();
59+
} else {
60+
return MakeRootTreeWriterSpec("FD3DigitWriterRaw",
61+
"o2_fd3digits.root",
62+
"o2sim",
63+
MakeRootTreeWriterSpec::CustomClose(finishWriting),
64+
BranchDefinition<std::vector<o2::fd3::Digit>>{InputSpec{"digitBCinput", "FD3", "DIGITSBC"}, "FD3DigitBC", 1,
65+
logger},
66+
BranchDefinition<std::vector<o2::fd3::ChannelData>>{InputSpec{"digitChinput", "FD3", "DIGITSCH"}, "FD3DigitCh"},
67+
std::move(labelsdef))();
68+
}
69+
}
70+
71+
} // end namespace fd3
72+
} // end namespace o2

0 commit comments

Comments
 (0)