Project
Loading...
Searching...
No Matches
FV0DigitizerSpec.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
12#include "FV0DigitizerSpec.h"
20#include "Framework/Lifetime.h"
21#include "Headers/DataHeader.h"
22#include <TStopwatch.h>
23#include "Steer/HitProcessingManager.h" // for DigitizationContext
24#include <TChain.h>
26#include "Framework/Task.h"
35#include <TFile.h>
36
37using namespace o2::framework;
39
40namespace o2
41{
42namespace fv0
43{
44
46{
48
49 public:
50 FV0DPLDigitizerTask() : o2::base::BaseDPLDigitizer(), mDigitizer(), mSimChains(), mDigitsCh(), mDigitsBC(), mLabels() {}
51 ~FV0DPLDigitizerTask() override = default;
52
54 {
55 LOG(debug) << "FV0DPLDigitizerTask:init";
56 mDigitizer.init();
57 mDisableQED = ic.options().get<bool>("disable-qed"); //TODO: QED implementation to be tested
58 mUseDeadChannelMap = !ic.options().get<bool>("disable-dead-channel-map");
59 mUpdateDeadChannelMap = mUseDeadChannelMap;
60 }
61
62 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
63 {
64 // Initialize the dead channel map only once
65 if (matcher == ConcreteDataMatcher("FV0", "DeadChannelMap", 0)) {
66 mUpdateDeadChannelMap = false;
67 }
68 }
69
71 {
72 if (mFinished) {
73 return;
74 }
75 LOG(debug) << "FV0DPLDigitizerTask:run";
76
77 // read collision context from input
78 auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
79 context->initSimChains(o2::detectors::DetID::FV0, mSimChains);
80 const bool withQED = context->isQEDProvided() && !mDisableQED; //TODO: QED implementation to be tested
81
82 if (mUseDeadChannelMap && mUpdateDeadChannelMap) {
83 auto deadChannelMap = pc.inputs().get<o2::fit::DeadChannelMap*>("fv0deadchannelmap");
84 mDigitizer.setDeadChannelMap(deadChannelMap.get());
85 }
86
87 mDigitizer.setTimeStamp(context->getGRP().getTimeStart());
88
89 auto& irecords = context->getEventRecords(withQED); //TODO: QED implementation to be tested
90 auto& eventParts = context->getEventParts(withQED); //TODO: QED implementation to be tested
91
92 // the interaction record marking the timeframe start
93 auto firstTF = InteractionTimeRecord(o2::raw::HBFUtils::Instance().getFirstSampledTFIR(), 0);
94
95 // loop over all composite collisions given from context
96 // (aka loop over all the interaction records)
97 std::vector<o2::fv0::Hit> hits;
98 for (int collID = 0; collID < irecords.size(); ++collID) {
99 // Note: Very crude filter to neglect collisions coming before
100 // the first interaction record of the timeframe. Remove this, once these collisions can be handled
101 // within the digitization routine. Collisions before this timeframe might impact digits of this timeframe.
102 // See https://its.cern.ch/jira/browse/O2-5395.
103 if (irecords[collID] < firstTF) {
104 LOG(info) << "Too early: Not digitizing collision " << collID;
105 continue;
106 }
107
108 mDigitizer.clear();
109 const auto& irec = irecords[collID];
110 mDigitizer.setInteractionRecord(irec);
111 // for each collision, loop over the constituents event and source IDs
112 // (background signal merging is basically taking place here)
113 for (auto& part : eventParts[collID]) {
114 hits.clear();
115 context->retrieveHits(mSimChains, "FV0Hit", part.sourceID, part.entryID, &hits);
116 LOG(debug) << "[FV0] For collision " << collID << " eventID " << part.entryID << " found " << hits.size() << " hits ";
117
118 // call actual digitization procedure
119 mDigitizer.setEventId(part.entryID);
120 mDigitizer.setSrcId(part.sourceID);
121 mDigitizer.process(hits, mDigitsBC, mDigitsCh, mDigitsTrig, mLabels);
122 }
123 LOG(debug) << "[FV0] Has " << mDigitsBC.size() << " BC elements, " << mDigitsCh.size() << " mDigitsCh elements";
124 }
125
126 o2::InteractionTimeRecord terminateIR;
127 terminateIR.orbit = 0xffffffff; // supply IR in the infinite future to flush all cached BC
128 mDigitizer.setInteractionRecord(terminateIR);
129 mDigitizer.flush(mDigitsBC, mDigitsCh, mDigitsTrig, mLabels);
130
131 // here we have all digits and we can send them to consumer (aka snapshot it onto output)
132 LOG(info) << "FV0: Sending " << mDigitsBC.size() << " digitsBC and " << mDigitsCh.size() << " digitsCh.";
133
134 // send out to next stage
135 pc.outputs().snapshot(Output{"FV0", "DIGITSBC", 0}, mDigitsBC);
136 pc.outputs().snapshot(Output{"FV0", "DIGITSCH", 0}, mDigitsCh);
137 pc.outputs().snapshot(Output{"FV0", "TRIGGERINPUT", 0}, mDigitsTrig);
138 if (pc.outputs().isAllowed({"FV0", "DIGITLBL", 0})) {
139 pc.outputs().snapshot(Output{"FV0", "DIGITLBL", 0}, mLabels);
140 }
141 LOG(info) << "FV0: Sending ROMode= " << mROMode << " to GRPUpdater";
142 pc.outputs().snapshot(Output{"FV0", "ROMode", 0}, mROMode);
143
144 // we should be only called once; tell DPL that this process is ready to exit
145 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
146 mFinished = true;
147 }
148
149 private:
150 bool mFinished = false;
151 bool mUseDeadChannelMap = true;
152 bool mUpdateDeadChannelMap = true;
153 Digitizer mDigitizer;
154 std::vector<TChain*> mSimChains;
155 std::vector<o2::fv0::ChannelData> mDigitsCh;
156 std::vector<o2::fv0::Digit> mDigitsBC;
157 std::vector<o2::fv0::DetTrigInput> mDigitsTrig;
158 o2::dataformats::MCTruthContainer<o2::fv0::MCLabel> mLabels; // labels which get filled
159
160 // RS: at the moment using hardcoded flag for continuous readout
162 bool mDisableQED = false;
163};
164
166{
167 // create the full data processor spec using
168 // a name identifier
169 // input description
170 // algorithmic description (here a lambda getting called once to setup the actual processing function)
171 // options that can be used for this processor (here: input file names where to take the hits)
172 std::vector<OutputSpec> outputs;
173 outputs.emplace_back("FV0", "DIGITSBC", 0, Lifetime::Timeframe);
174 outputs.emplace_back("FV0", "DIGITSCH", 0, Lifetime::Timeframe);
175 outputs.emplace_back("FV0", "TRIGGERINPUT", 0, Lifetime::Timeframe);
176 if (mctruth) {
177 outputs.emplace_back("FV0", "DIGITLBL", 0, Lifetime::Timeframe);
178 }
179 outputs.emplace_back("FV0", "ROMode", 0, Lifetime::Timeframe);
180
181 std::vector<InputSpec> inputs;
182 inputs.emplace_back("fv0deadchannelmap", "FV0", "DeadChannelMap", 0, Lifetime::Condition, ccdbParamSpec("FV0/Calib/DeadChannelMap"));
183 inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<SubSpecificationType>(channel), Lifetime::Timeframe);
184 return DataProcessorSpec{
185 "FV0Digitizer",
186 inputs,
187 outputs,
188
189 AlgorithmSpec{adaptFromTask<FV0DPLDigitizerTask>()},
190 Options{{"pileup", VariantType::Int, 1, {"whether to run in continuous time mode"}},
191 {"disable-qed", o2::framework::VariantType::Bool, false, {"disable QED handling"}},
192 {"disable-dead-channel-map", o2::framework::VariantType::Bool, false, {"Don't mask dead channels"}}}};
193 // Options{{"pileup", VariantType::Int, 1, {"whether to run in continuous time mode"}}}};
194}
195
196} // end namespace fv0
197} // end namespace o2
Definition of the base digitizer task class.
Class to describe fired triggered and/or stored channels for the BC and to refer to channel data.
Dead channel map for FIT.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
std::ostringstream debug
Container class to store time and charge values of single FV0 channel.
Header of the General Run Parameters object.
Definition of a container to keep Monte Carlo truth external to simulation objects.
A container to hold and manage MC truth information/labels.
static constexpr ID FV0
Definition DetID.h:76
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.
void flush(std::vector< o2::fv0::Digit > &digitsBC, std::vector< o2::fv0::ChannelData > &digitsCh, std::vector< o2::fv0::DetTrigInput > &digitsTrig, o2::dataformats::MCTruthContainer< o2::fv0::MCLabel > &labels)
void setTimeStamp(long t)
Definition Digitizer.h:51
void setInteractionRecord(const InteractionTimeRecord &ir)
Definition Digitizer.h:54
void setEventId(Int_t id)
Definition Digitizer.h:52
void setSrcId(Int_t id)
Definition Digitizer.h:53
void setDeadChannelMap(o2::fit::DeadChannelMap const *deadChannelMap)
Definition Digitizer.h:55
void process(const std::vector< o2::fv0::Hit > &hits, std::vector< o2::fv0::Digit > &digitsBC, std::vector< o2::fv0::ChannelData > &digitsCh, std::vector< o2::fv0::DetTrigInput > &digitsTrig, o2::dataformats::MCTruthContainer< o2::fv0::MCLabel > &labels)
Definition Digitizer.cxx:83
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj)
~FV0DPLDigitizerTask() override=default
void initDigitizerTask(framework::InitContext &ic) override
void run(framework::ProcessingContext &pc)
bool initSimChains(o2::detectors::DetID detid, std::vector< TChain * > &simchains) const
Defining PrimaryVertex explicitly as messageable.
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 getFV0DigitizerSpec(int channel, bool mctruth)
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"