Project
Loading...
Searching...
No Matches
ZDCDigitizerSpec.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
14#include "CCDB/CcdbApi.h"
15#include "ZDCDigitizerSpec.h"
25#include "Framework/Lifetime.h"
26#include "TStopwatch.h"
27#include "Steer/HitProcessingManager.h" // for DigitizationContext
28#include "TChain.h"
30#include "Framework/Task.h"
39
40using namespace o2::framework;
42
43namespace o2
44{
45namespace zdc
46{
47
49{
51 bool mUseMC = true;
52
53 public:
54 ZDCDPLDigitizerTask(bool useMC) : o2::base::BaseDPLDigitizer(o2::base::InitServices::GEOM), mUseMC(useMC) {}
55
57 {
58 LOG(info) << "Initializing ZDC digitization";
59 auto& dopt = o2::conf::DigiParams::Instance();
60 auto enableHitInfo = ic.options().get<bool>("enable-hit-info");
61 mDigitizer.setMaskTriggerBits(!enableHitInfo);
62 mDigitizer.setSkipMCLabels(not mUseMC);
63 }
64
66 {
67 if (matcher == ConcreteDataMatcher("ZDC", "MODULECONFIG", 0)) {
68 auto* config = (const o2::zdc::ModuleConfig*)obj;
69 mDigitizer.setModuleConfig(config);
70 return;
71 }
72 if (matcher == ConcreteDataMatcher("ZDC", "SIMCONFIG", 0)) {
73 auto* config = (const o2::zdc::SimCondition*)obj;
74 mDigitizer.setSimCondition(config);
75 return;
76 }
77 }
78
79 bool mInitialized = false;
80
82 {
83 LOG(info) << "Doing ZDC digitization";
84
85 if (!mInitialized) {
86 mInitialized = true;
87 // we call these methods just to trigger finaliseCCDB callback
88 pc.inputs().get<o2::zdc::ModuleConfig*>("moduleconfig");
89 pc.inputs().get<o2::zdc::SimCondition*>("simconfig");
90 mDigitizer.init();
92 }
93
94 // read collision context from input
95 auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
96 context->initSimChains(o2::detectors::DetID::ZDC, mSimChains);
97
98 const auto& grp = context->getGRP();
99 mDigitizer.setTimeStamp(grp.getTimeStart());
100 if (mDigitizer.getNEmptyBunches() < 0) {
101 mDigitizer.findEmptyBunches(context->getBunchFilling().getPattern());
102 }
103 auto& irecords = context->getEventRecords();
104 auto& eventParts = context->getEventParts();
105 if (irecords.empty()) {
106 return;
107 }
108 // loop over all composite collisions given from context
109 // (aka loop over all the interaction records)
110 std::vector<o2::zdc::Hit> hits;
111
112 // the interaction record marking the timeframe start
113 auto firstTF = InteractionTimeRecord(o2::raw::HBFUtils::Instance().getFirstSampledTFIR(), 0);
114
115 for (int collID = 0; collID < irecords.size(); ++collID) {
116 // Note: Very crude filter to neglect collisions coming before
117 // the first interaction record of the timeframe. Remove this, once these collisions can be handled
118 // within the digitization routine. Collisions before this timeframe might impact digits of this timeframe.
119 // See https://its.cern.ch/jira/browse/O2-5395.
120 if (irecords[collID] < firstTF) {
121 LOG(info) << "Too early: Not digitizing collision " << collID;
122 continue;
123 }
124
125 const auto& irec = irecords[collID];
126 mDigitizer.setInteractionRecord(irec);
127
128 for (auto& part : eventParts[collID]) {
129
130 context->retrieveHits(mSimChains, "ZDCHit", part.sourceID, part.entryID, &hits);
131 LOG(info) << "For collision " << collID << " eventID " << part.entryID << " found ZDC " << hits.size() << " hits ";
132
133 mDigitizer.setEventID(part.entryID);
134 mDigitizer.setSrcID(part.sourceID);
135
136 mDigitizer.process(hits, mDigitsBC, mDigitsCh, mLabels);
137 }
138 }
139
140 o2::InteractionTimeRecord terminateIR;
141 terminateIR.orbit = 0xffffffff; // supply IR in the infinite future to flush all cached BC
142 mDigitizer.setInteractionRecord(terminateIR);
143 mDigitizer.flush(mDigitsBC, mDigitsCh, mLabels);
144
145 for (uint32_t ib = 0; ib < mDigitsBC.size(); ib++) {
146 mDigitizer.assignTriggerBits(ib, mDigitsBC);
147 }
148
149 const auto &irFirst = irecords.front(), irLast = irecords.back();
151 int norbits = irLast.orbit - irFirst.orbit + 1;
152 mOrbitData.resize(norbits);
153 for (int i = 0; i < norbits; i++) {
154 mDigitizer.updatePedestalReference(mOrbitData[i]);
155 mOrbitData[i].ir = irPed;
156 irPed.orbit++;
157 }
158
159 mDigitizer.Finalize(mDigitsBC, mOrbitData);
160
161 // send out to next stage
162 pc.outputs().snapshot(Output{"ZDC", "DIGITSBC", 0}, mDigitsBC);
163 pc.outputs().snapshot(Output{"ZDC", "DIGITSCH", 0}, mDigitsCh);
164 pc.outputs().snapshot(Output{"ZDC", "DIGITSPD", 0}, mOrbitData);
165 if (pc.outputs().isAllowed({"ZDC", "DIGITSLBL", 0})) {
166 pc.outputs().snapshot(Output{"ZDC", "DIGITSLBL", 0}, mLabels);
167 }
168
169 LOG(info) << "ZDC: Sending ROMode= " << mROMode << " to GRPUpdater";
170 pc.outputs().snapshot(Output{"ZDC", "ROMode", 0}, mROMode);
171
172 // we should be only called once; tell DPL that this process is ready to exit
173 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
174 }
175
176 private:
177 Digitizer mDigitizer;
178 std::vector<TChain*> mSimChains;
179 std::vector<o2::zdc::ChannelData> mDigitsCh;
180 std::vector<o2::zdc::BCData> mDigitsBC;
181 std::vector<o2::zdc::OrbitData> mOrbitData;
182 o2::dataformats::MCTruthContainer<o2::zdc::MCLabel> mLabels; // labels which get filled
183
184 // RS: at the moment using hardcoded flag for continuous readout
186};
187
189{
190 // create the full data processor spec using
191 // a name identifier
192 // input description
193 // algorithmic description (here a lambda getting called once to setup the actual processing function)
194 // options that can be used for this processor (here: input file names where to take the hits)
195
196 std::vector<InputSpec> inputs;
197 inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<SubSpecificationType>(channel), Lifetime::Timeframe);
198 inputs.emplace_back("moduleconfig", "ZDC", "MODULECONFIG", 0, Lifetime::Condition, o2::framework::ccdbParamSpec(o2::zdc::CCDBPathConfigModule.data()));
199 inputs.emplace_back("simconfig", "ZDC", "SIMCONFIG", 0, Lifetime::Condition, o2::framework::ccdbParamSpec(o2::zdc::CCDBPathConfigSim.data()));
200
201 std::vector<OutputSpec> outputs;
202 outputs.emplace_back("ZDC", "DIGITSBC", 0, Lifetime::Timeframe);
203 outputs.emplace_back("ZDC", "DIGITSCH", 0, Lifetime::Timeframe);
204 outputs.emplace_back("ZDC", "DIGITSPD", 0, Lifetime::Timeframe);
205 if (mctruth) {
206 outputs.emplace_back("ZDC", "DIGITSLBL", 0, Lifetime::Timeframe);
207 }
208 outputs.emplace_back("ZDC", "ROMode", 0, Lifetime::Timeframe);
209
210 return DataProcessorSpec{
211 "ZDCDigitizer",
212 inputs,
213 outputs,
214 AlgorithmSpec{adaptFromTask<ZDCDPLDigitizerTask>(mctruth)},
215 Options{{"enable-hit-info", o2::framework::VariantType::Bool, false, {"enable hit info of unread channels"}}}};
216}
217
218} // end namespace zdc
219} // end namespace o2
Class to describe fired triggered and/or stored channels for the BC and to refer to channel data.
Definition of the base digitizer task class.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
int32_t i
Header of the General Run Parameters object.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Class to describe pedestal data accumulated over the orbit.
Container class to store NTimeBinsPerBC ADC values of single ZDC channel.
A container to hold and manage MC truth information/labels.
static constexpr ID ZDC
Definition DetID.h:74
void snapshot(const Output &spec, T const &object)
o2::header::DataHeader::SubSpecificationType SubSpecificationType
bool isAllowed(Output const &query)
check if a certain output is allowed
ConfigParamRegistry const & options()
Definition InitContext.h:33
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
bool initSimChains(o2::detectors::DetID detid, std::vector< TChain * > &simchains) const
void updatePedestalReference(OrbitData &pdata)
void flush(std::vector< o2::zdc::BCData > &digitsBC, std::vector< o2::zdc::ChannelData > &digitsCh, o2::dataformats::MCTruthContainer< o2::zdc::MCLabel > &labels)
void setEventID(int eventID)
Definition Digitizer.h:81
void setInteractionRecord(const o2::InteractionTimeRecord &ir)
Definition Digitizer.h:83
void setSkipMCLabels(bool v=true)
Definition Digitizer.h:117
void setSrcID(int sID)
Definition Digitizer.h:82
void process(const std::vector< o2::zdc::Hit > &hits, std::vector< o2::zdc::BCData > &digitsBC, std::vector< o2::zdc::ChannelData > &digitsCh, o2::dataformats::MCTruthContainer< o2::zdc::MCLabel > &labels)
Definition Digitizer.cxx:50
void setTimeStamp(long t)
Definition Digitizer.h:84
void Finalize(std::vector< BCData > &bcData, std::vector< o2::zdc::OrbitData > &pData)
void assignTriggerBits(uint32_t ibc, std::vector< BCData > &bcData)
void setMaskTriggerBits(bool v=true)
Definition Digitizer.h:115
void setModuleConfig(const ModuleConfig *cfg)
Definition Digitizer.h:106
void setSimCondition(const SimCondition *cfg)
Definition Digitizer.h:105
int getNEmptyBunches() const
Definition Digitizer.h:112
void findEmptyBunches(const std::bitset< o2::constants::lhc::LHCMaxBunches > &bunchPattern)
bool isContinuous() const
Definition Digitizer.h:109
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
void run(framework::ProcessingContext &pc)
void initDigitizerTask(framework::InitContext &ic) override
GLboolean * data
Definition glcorearb.h:298
constexpr int LHCMaxBunches
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
header::DataHeader::SubSpecificationType SubSpecificationType
o2::framework::DataProcessorSpec getZDCDigitizerSpec(int channel, bool mctruth)
const std::string CCDBPathConfigSim
Definition Constants.h:218
const std::string CCDBPathConfigModule
Definition Constants.h:219
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
uint32_t orbit
LHC orbit.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord irPed(o2::constants::lhc::LHCMaxBunches - 1, irFirst.orbit)
const auto irLast
const auto & irFirst
int norbits