Skip to content

Commit 8b9f263

Browse files
committed
Distribution of CTP trigger within CollisionContext
This gives the (preliminary) possibility to distribute CTPdigits (momentarily, trigger decisions for FT0 MVTX) for digitizers. This will work for MC that runs digitization in stages: *) First FT0 + CTP *) Then digitizers that trigger on FT0 MVTX In a future PR, this can be done with proper DPL-inputs, but this PR should already unblock work, where detectors need access to CTP trigger records. There is a small example in HMPID, showing how the CTP triggers can be accessed.
1 parent 0dac465 commit 8b9f263

9 files changed

Lines changed: 64 additions & 8 deletions

File tree

DataFormats/Detectors/CTP/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ o2_add_library(DataFormatsCTP
1717
src/TriggerOffsetsParam.cxx
1818
PUBLIC_LINK_LIBRARIES O2::CommonDataFormat
1919
O2::Headers
20-
O2::SimulationDataFormat
2120
O2::CommonUtils
21+
O2::DetectorsCommonDataFormats
22+
O2::DataFormatsParameters
2223
O2::CommonConstants)
2324
o2_target_root_dictionary(DataFormatsCTP
2425
HEADERS include/DataFormatsCTP/Digits.h

DataFormats/Detectors/CTP/src/DataFormatsCTPLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#pragma link off all globals;
1515
#pragma link off all classes;
1616
#pragma link off all functions;
17+
#pragma link C++ class std::bitset < 48> + ;
1718
#pragma link C++ class o2::ctp::CTPDigit + ;
1819
#pragma link C++ class vector < o2::ctp::CTPDigit> + ;
1920
#pragma link C++ class o2::ctp::CTPInputDigit + ;

DataFormats/simulation/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ o2_add_library(SimulationDataFormat
2626
O2::DetectorsCommonDataFormats
2727
O2::DataFormatsParameters
2828
O2::DataFormatsCalibration
29+
O2::DataFormatsCTP
2930
O2::GPUCommon
3031
ROOT::TreePlayer)
3132

DataFormats/simulation/include/SimulationDataFormat/DigitizationContext.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <unordered_map>
2424
#include <MathUtils/Cartesian.h>
2525
#include <DataFormatsCalibration/MeanVertexObject.h>
26+
#include <DataFormatsCTP/Digits.h>
2627

2728
namespace o2
2829
{
@@ -141,6 +142,17 @@ class DigitizationContext
141142

142143
static DigitizationContext* loadFromFile(std::string_view filename = "");
143144

145+
void setCTPDigits(std::vector<o2::ctp::CTPDigit> const* ctpdigits) const
146+
{
147+
mCTPTrigger = ctpdigits;
148+
if (mCTPTrigger) {
149+
mHasTrigger = true;
150+
}
151+
}
152+
153+
std::vector<o2::ctp::CTPDigit> const* getCTPDigits() const { return mCTPTrigger; }
154+
bool hasTriggerInput() const { return mHasTrigger; }
155+
144156
private:
145157
int mNofEntries = 0;
146158
int mMaxPartNumber = 0; // max number of parts in any given collision
@@ -169,7 +181,10 @@ class DigitizationContext
169181
std::string mQEDSimPrefix; // prefix for QED production/contribution
170182
mutable o2::parameters::GRPObject* mGRP = nullptr; //!
171183

172-
ClassDefNV(DigitizationContext, 4);
184+
mutable std::vector<o2::ctp::CTPDigit> const* mCTPTrigger = nullptr; // CTP trigger info associated to this digitization context
185+
mutable bool mHasTrigger = false; //
186+
187+
ClassDefNV(DigitizationContext, 5);
173188
};
174189

175190
/// function reading the hits from a chain (previously initialized with initSimChains

Steer/DigitizerWorkflow/src/CTPDigitizerSpec.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class CTPDPLDigitizerTask : public o2::base::BaseDPLDigitizer
5555
TStopwatch timer;
5656
timer.Start();
5757
LOG(info) << "CALLING CTP DIGITIZATION";
58-
// Input order: T0, V0, ... but O need also poisition of inputs DETInputs
58+
// Input order: T0, V0, ... but O need also position of inputs DETInputs
5959
for (const auto& inp : ft0inputs) {
6060
finputs.emplace_back(CTPInputDigit{inp.mIntRecord, inp.mInputs, o2::detectors::DetID::FT0});
6161
}

Steer/DigitizerWorkflow/src/HMPIDDigitizerSpec.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ class HMPIDDPLDigitizerTask : public o2::base::BaseDPLDigitizer
6060
// read collision context from input
6161
auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
6262

63+
if (context->hasTriggerInput()) {
64+
auto ctpdigits = context->getCTPDigits();
65+
LOG(info) << "Yes, we have CTP digits";
66+
LOG(info) << "We have " << ctpdigits->size() << " digits";
67+
} else {
68+
LOG(info) << "No trigger input available ... selftriggering";
69+
}
70+
6371
context->initSimChains(o2::detectors::DetID::HMP, mSimChains);
6472

6573
auto& irecords = context->getEventRecords();

Steer/DigitizerWorkflow/src/SimReaderSpec.cxx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,26 @@ namespace o2
4545
namespace steer
4646
{
4747

48-
DataProcessorSpec getSimReaderSpec(SubspecRange range, const std::vector<std::string>& simprefixes, const std::vector<int>& tpcsectors)
48+
std::vector<o2::ctp::CTPDigit>* ctptrigger = nullptr;
49+
50+
DataProcessorSpec getSimReaderSpec(SubspecRange range, const std::vector<std::string>& simprefixes, const std::vector<int>& tpcsectors, bool withTrigger)
4951
{
5052
uint64_t activeSectors = 0;
5153
for (const auto& tpcsector : tpcsectors) {
5254
activeSectors |= (uint64_t)0x1 << tpcsector;
5355
}
5456

55-
auto doit = [range, tpcsectors, activeSectors](ProcessingContext& pc) {
57+
auto doit = [range, tpcsectors, activeSectors, withTrigger](ProcessingContext& pc) {
5658
auto& mgr = steer::HitProcessingManager::instance();
5759
const auto& context = mgr.getDigitizationContext();
5860
auto eventrecords = context.getEventRecords();
5961

62+
if (withTrigger) {
63+
// fetch the digits and transport them as part of the context
64+
LOG(info) << "Setting CTP trigger object to " << ctptrigger;
65+
context.setCTPDigits(ctptrigger);
66+
}
67+
6068
for (auto const& sector : tpcsectors) {
6169
// Note: the TPC sector header was serving the sector to lane mapping before
6270
// now the only remaining purpose is to propagate the mask of valid sectors
@@ -88,10 +96,26 @@ DataProcessorSpec getSimReaderSpec(SubspecRange range, const std::vector<std::st
8896
};
8997

9098
// init function return a lambda taking a ProcessingContext
91-
auto initIt = [simprefixes, doit](InitContext& ctx) {
99+
auto initIt = [simprefixes, doit, withTrigger](InitContext& ctx) {
92100
// initialize fundamental objects
93101
auto& mgr = steer::HitProcessingManager::instance();
94102

103+
if (withTrigger) {
104+
// fetch the ctp trigger/digit information from the CTP file
105+
auto triggerf = TFile(ctx.options().get<std::string>("triggerfile").c_str(), "OPEN");
106+
auto tr = (TTree*)triggerf.Get("o2sim");
107+
if (!tr) {
108+
LOG(fatal) << "Did not find CTP TTree";
109+
}
110+
auto br = tr->GetBranch("CTPDigits");
111+
if (!br) {
112+
LOG(fatal) << "Did not find CTPDigit branch";
113+
}
114+
br->SetAddress(&ctptrigger);
115+
br->GetEntry(0);
116+
LOG(info) << " Read " << ctptrigger->size() << " CTP digits ";
117+
}
118+
95119
// init gRandom
96120
gRandom->SetSeed(ctx.options().get<int>("seed"));
97121

@@ -234,6 +258,7 @@ DataProcessorSpec getSimReaderSpec(SubspecRange range, const std::vector<std::st
234258
{"qed-x-section-ratio", VariantType::Float, -1.f, {"Ratio of cross sections QED/hadronic events. Determines QED interaction rate from hadronic interaction rate."}},
235259
{"outcontext", VariantType::String, "collisioncontext.root", {"Output file for collision context"}},
236260
{"incontext", VariantType::String, "", {"Take collision context from this file"}},
261+
{"triggerfile", VariantType::String, "ctpdigits.root", {"Name of the CTP trigger/digit file to use"}},
237262
{"seed", VariantType::Int, 0, {"Random seed for collision context generation"}},
238263
{"ncollisions,n",
239264
VariantType::Int,

Steer/DigitizerWorkflow/src/SimReaderSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct SubspecRange {
2323
int max = 0;
2424
};
2525

26-
o2::framework::DataProcessorSpec getSimReaderSpec(SubspecRange range, const std::vector<std::string>& simprefixes, const std::vector<int>& tpcsectors);
26+
o2::framework::DataProcessorSpec getSimReaderSpec(SubspecRange range, const std::vector<std::string>& simprefixes, const std::vector<int>& tpcsectors, bool withTrigger = false);
2727
}
2828
} // namespace o2
2929

Steer/DigitizerWorkflow/src/SimpleDigitizerWorkflow.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
202202
workflowOptions.push_back(ConfigParamSpec{"trd-digit-downscaling", VariantType::Int, 1, {"only keep TRD digits for every n-th trigger"}});
203203

204204
workflowOptions.push_back(ConfigParamSpec{"combine-devices", VariantType::Bool, false, {"combined multiple DPL worker/writer devices"}});
205+
206+
// to enable distribution of triggers
207+
workflowOptions.push_back(ConfigParamSpec{"with-trigger", VariantType::Bool, false, {"enable distribution of CTP trigger digits"}});
205208
}
206209

207210
void customize(std::vector<o2::framework::DispatchPolicy>& policies)
@@ -788,6 +791,8 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
788791
}
789792

790793
// The SIM Reader. NEEDS TO BE LAST
791-
specs[0] = o2::steer::getSimReaderSpec({firstOtherChannel, fanoutsize}, simPrefixes, tpcsectors);
794+
bool withTrigger = configcontext.options().get<bool>("with-trigger");
795+
LOG(info) << " TRIGGER " << withTrigger;
796+
specs[0] = o2::steer::getSimReaderSpec({firstOtherChannel, fanoutsize}, simPrefixes, tpcsectors, withTrigger);
792797
return specs;
793798
}

0 commit comments

Comments
 (0)