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"
19#include "Framework/Lifetime.h"
20#include "Headers/DataHeader.h"
21#include <TStopwatch.h>
22#include "Steer/HitProcessingManager.h" // for DigitizationContext
23#include <TChain.h>
25#include "Framework/Task.h"
33#include <TFile.h>
34
35using namespace o2::framework;
37
38namespace o2
39{
40namespace fv0
41{
42
44{
46
47 public:
48 FV0DPLDigitizerTask() : o2::base::BaseDPLDigitizer(), mDigitizer(), mSimChains(), mDigitsCh(), mDigitsBC(), mLabels() {}
49 ~FV0DPLDigitizerTask() override = default;
50
52 {
53 LOG(debug) << "FV0DPLDigitizerTask:init";
54 mDigitizer.init();
55 mDisableQED = ic.options().get<bool>("disable-qed"); //TODO: QED implementation to be tested
56 }
57
59 {
60 if (mFinished) {
61 return;
62 }
63 LOG(debug) << "FV0DPLDigitizerTask:run";
64
65 // read collision context from input
66 auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
67 context->initSimChains(o2::detectors::DetID::FV0, mSimChains);
68 const bool withQED = context->isQEDProvided() && !mDisableQED; //TODO: QED implementation to be tested
69
70 mDigitizer.setTimeStamp(context->getGRP().getTimeStart());
71
72 auto& irecords = context->getEventRecords(withQED); //TODO: QED implementation to be tested
73 auto& eventParts = context->getEventParts(withQED); //TODO: QED implementation to be tested
74
75 // the interaction record marking the timeframe start
76 auto firstTF = InteractionTimeRecord(o2::raw::HBFUtils::Instance().getFirstSampledTFIR(), 0);
77
78 // loop over all composite collisions given from context
79 // (aka loop over all the interaction records)
80 std::vector<o2::fv0::Hit> hits;
81 for (int collID = 0; collID < irecords.size(); ++collID) {
82 // Note: Very crude filter to neglect collisions coming before
83 // the first interaction record of the timeframe. Remove this, once these collisions can be handled
84 // within the digitization routine. Collisions before this timeframe might impact digits of this timeframe.
85 // See https://its.cern.ch/jira/browse/O2-5395.
86 if (irecords[collID] < firstTF) {
87 LOG(info) << "Too early: Not digitizing collision " << collID;
88 continue;
89 }
90
91 mDigitizer.clear();
92 const auto& irec = irecords[collID];
93 mDigitizer.setInteractionRecord(irec);
94 // for each collision, loop over the constituents event and source IDs
95 // (background signal merging is basically taking place here)
96 for (auto& part : eventParts[collID]) {
97 hits.clear();
98 context->retrieveHits(mSimChains, "FV0Hit", part.sourceID, part.entryID, &hits);
99 LOG(debug) << "[FV0] For collision " << collID << " eventID " << part.entryID << " found " << hits.size() << " hits ";
100
101 // call actual digitization procedure
102 mDigitizer.setEventId(part.entryID);
103 mDigitizer.setSrcId(part.sourceID);
104 mDigitizer.process(hits, mDigitsBC, mDigitsCh, mDigitsTrig, mLabels);
105 }
106 LOG(debug) << "[FV0] Has " << mDigitsBC.size() << " BC elements, " << mDigitsCh.size() << " mDigitsCh elements";
107 }
108
109 o2::InteractionTimeRecord terminateIR;
110 terminateIR.orbit = 0xffffffff; // supply IR in the infinite future to flush all cached BC
111 mDigitizer.setInteractionRecord(terminateIR);
112 mDigitizer.flush(mDigitsBC, mDigitsCh, mDigitsTrig, mLabels);
113
114 // here we have all digits and we can send them to consumer (aka snapshot it onto output)
115 LOG(info) << "FV0: Sending " << mDigitsBC.size() << " digitsBC and " << mDigitsCh.size() << " digitsCh.";
116
117 // send out to next stage
118 pc.outputs().snapshot(Output{"FV0", "DIGITSBC", 0}, mDigitsBC);
119 pc.outputs().snapshot(Output{"FV0", "DIGITSCH", 0}, mDigitsCh);
120 pc.outputs().snapshot(Output{"FV0", "TRIGGERINPUT", 0}, mDigitsTrig);
121 if (pc.outputs().isAllowed({"FV0", "DIGITLBL", 0})) {
122 pc.outputs().snapshot(Output{"FV0", "DIGITLBL", 0}, mLabels);
123 }
124 LOG(info) << "FV0: Sending ROMode= " << mROMode << " to GRPUpdater";
125 pc.outputs().snapshot(Output{"FV0", "ROMode", 0}, mROMode);
126
127 // we should be only called once; tell DPL that this process is ready to exit
128 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
129 mFinished = true;
130 }
131
132 private:
133 bool mFinished = false;
134 Digitizer mDigitizer;
135 std::vector<TChain*> mSimChains;
136 std::vector<o2::fv0::ChannelData> mDigitsCh;
137 std::vector<o2::fv0::Digit> mDigitsBC;
138 std::vector<o2::fv0::DetTrigInput> mDigitsTrig;
139 o2::dataformats::MCTruthContainer<o2::fv0::MCLabel> mLabels; // labels which get filled
140
141 // RS: at the moment using hardcoded flag for continuous readout
143 bool mDisableQED = false;
144};
145
147{
148 // create the full data processor spec using
149 // a name identifier
150 // input description
151 // algorithmic description (here a lambda getting called once to setup the actual processing function)
152 // options that can be used for this processor (here: input file names where to take the hits)
153 std::vector<OutputSpec> outputs;
154 outputs.emplace_back("FV0", "DIGITSBC", 0, Lifetime::Timeframe);
155 outputs.emplace_back("FV0", "DIGITSCH", 0, Lifetime::Timeframe);
156 outputs.emplace_back("FV0", "TRIGGERINPUT", 0, Lifetime::Timeframe);
157 if (mctruth) {
158 outputs.emplace_back("FV0", "DIGITLBL", 0, Lifetime::Timeframe);
159 }
160 outputs.emplace_back("FV0", "ROMode", 0, Lifetime::Timeframe);
161
162 return DataProcessorSpec{
163 "FV0Digitizer",
164 Inputs{InputSpec{"collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<SubSpecificationType>(channel), Lifetime::Timeframe}},
165
166 outputs,
167
168 AlgorithmSpec{adaptFromTask<FV0DPLDigitizerTask>()},
169 Options{{"pileup", VariantType::Int, 1, {"whether to run in continuous time mode"}},
170 {"disable-qed", o2::framework::VariantType::Bool, false, {"disable QED handling"}}}};
171 //Options{{"pileup", VariantType::Int, 1, {"whether to run in continuous time mode"}}}};
172}
173
174} // end namespace fv0
175} // 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.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
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.
std::ostringstream debug
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:50
void setInteractionRecord(const InteractionTimeRecord &ir)
Definition Digitizer.h:53
void setEventId(Int_t id)
Definition Digitizer.h:51
void setSrcId(Int_t id)
Definition Digitizer.h:52
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
~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.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
header::DataHeader::SubSpecificationType SubSpecificationType
std::vector< InputSpec > Inputs
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"