Project
Loading...
Searching...
No Matches
IOTOFDigitizerSpec.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 "IOTOFDigitizerSpec.h"
18#include "Framework/Lifetime.h"
19#include "Framework/Task.h"
30#include "Headers/DataHeader.h"
33
34#include <TChain.h>
35#include <TStopwatch.h>
36
37#include <algorithm>
38#include <memory>
39#include <string>
40
41using namespace o2::framework;
42
43namespace o2::iotof
44{
45
47{
48 public:
49 using BaseDPLDigitizer::init;
50
51 IOTOFDPLDigitizerTask(bool mctruth = true) : BaseDPLDigitizer(o2::base::InitServices::FIELD | o2::base::InitServices::GEOM),
52 mWithMCTruth(mctruth) {}
53
55 {
56 mDisableQED = ic.options().get<bool>("disable-qed");
57
58 auto geom = GeometryTGeo::Instance();
59 geom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G)); // make sure L2G matrices are loaded
60
61 mDigitizer.setGeometry(geom);
62 mDigitizer.init();
63
65 }
66
68 {
69 if (mFinished) {
70 return;
71 }
72 mFirstOrbitTF = pc.services().get<o2::framework::TimingInfo>().firstTForbit;
73 const o2::InteractionRecord firstIR(0, mFirstOrbitTF);
74
75 // read collision context from input
76 auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
77 context->initSimChains(mID, mSimChains);
78 const bool withQED = context->isQEDProvided() && !mDisableQED;
79 auto& timesview = context->getEventRecords();
80 LOG(info) << "GOT " << timesview.size() << " COLLISION TIMES";
81 LOG(info) << "SIMCHAINS " << mSimChains.size();
82
83 // if there is nothing to do ... return
84 if (timesview.empty()) {
85 return;
86 }
87
88 TStopwatch timer;
89 timer.Start();
90 LOG(info) << " CALLING TF3 DIGITIZATION ";
91
92 mDigitizer.setDigits(&mDigits);
93 mDigitizer.setROFRecords(&mROFRecords);
94 mDigitizer.setROFRecordIR(firstIR);
95 if (mWithMCTruth) {
96 mDigitizer.setMCLabels(&mLabels);
97 }
98
99 auto& eventParts = context->getEventParts(withQED);
100 // loop over all composite collisions given from context
101 // (aka loop over all the interaction records)
102 // o2::InteractionTimeRecord firstorbit(o2::InteractionRecord(0, o2::raw::HBFUtils::Instance().orbitFirstSampled), 0.0);
103 for (int collID = 0; collID < timesview.size(); ++collID) {
104 o2::InteractionTimeRecord orbit(timesview[collID]);
105 // orbit += firstorbit
106 mDigitizer.setEventTime(orbit);
107
108 // for each collision, loop over the constituents event and source IDs
109 // (background signal merging is basically taking place here)
110 for (const auto& part : eventParts[collID]) {
111
112 // get the hits for this event and this source
113 mHits.clear();
114 context->retrieveHits(mSimChains, o2::detectors::SimTraits::DETECTORBRANCHNAMES[mID][0].c_str(), part.sourceID, part.entryID, &mHits);
115
116 if (mHits.size() > 0) {
117 mDigits.clear();
118 if (mWithMCTruth) {
119 mLabels.clear();
120 }
121
122 LOG(debug) << "For collision " << collID << " eventID " << part.entryID << " found " << mHits.size() << " hits ";
123 mDigitizer.process(&mHits, part.entryID, part.sourceID); // call actual digitization procedure
124 }
125 }
126 }
127 if (mDigitizer.isContinuous()) {
128 LOG(debug) << "Number of digits before final flush: " << mDigits.size();
129 mDigits.clear();
130 if (mWithMCTruth) {
131 mLabels.clear();
132 }
133 LOG(debug) << "Final flushing for continuous mode";
134 mDigitizer.fillOutputContainer();
135 LOG(debug) << "Number of digits after final flush: " << mDigits.size();
136 }
137
138 // here we have all digits and we can send them to consumer (aka snapshot it onto output)
139 LOG(debug) << "Digitization finished with " << mDigits.size() << " digits and " << mROFRecords.size() << " ROF records";
140 pc.outputs().snapshot(Output{mOrigin, "DIGITS", 0}, mDigits);
141 pc.outputs().snapshot(Output{mOrigin, "DIGITSROF", 0}, mROFRecords);
142 if (mWithMCTruth) {
143 auto& sharedlabels = pc.outputs().make<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>(Output{mOrigin, "DIGITSMCTR", 0});
144 mLabels.flatten_to(sharedlabels);
145 // free space of existing label containers
146 mLabels.clear_andfreememory();
147
148 // write dummy MC2ROF vector to keep writer/readers backward compatible
149 // NOTE: Steer/DigitizerWorkflow/src/ITSMFTDigitizerSpec.cxx also uses dummy MC2ROF
150 static std::vector<o2::itsmft::MC2ROFRecord> dummyMC2ROF;
151 pc.outputs().snapshot(Output{mOrigin, "DIGITSMC2ROF", 0}, dummyMC2ROF);
152 }
153
154 LOG(info) << mID.getName() << ": Sending ROMode= " << mROMode << " to GRPUpdater";
155 pc.outputs().snapshot(Output{mOrigin, "ROMode", 0}, mROMode);
156
157 timer.Stop();
158 LOG(info) << "Digitization took " << timer.CpuTime() << "s";
159
160 // we should be only called once; tell DPL that this process is ready to exit
161 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
162
163 mFinished = true;
164 }
165
166 private:
167 bool mDisableQED = false;
168 bool mWithMCTruth{true};
169 bool mFinished{false};
170 unsigned long mFirstOrbitTF = 0x0;
171 const o2::detectors::DetID mID{o2::detectors::DetID::TF3};
173 o2::iotof::Digitizer mDigitizer{};
174 std::vector<o2::iotof::Digit> mDigits{};
175 std::vector<o2::itsmft::ROFRecord> mROFRecords{};
176 std::vector<o2::itsmft::Hit> mHits{};
177 std::vector<o2::itsmft::Hit>* mHitsP{&mHits};
179 std::vector<TChain*> mSimChains{};
181};
182
183std::vector<o2::framework::OutputSpec> makeOutChannels(o2::header::DataOrigin detOrig, bool mctruth)
184{
185 std::vector<o2::framework::OutputSpec> outputs;
186 outputs.emplace_back(detOrig, "DIGITS", o2::framework::Lifetime::Timeframe);
187 outputs.emplace_back(detOrig, "DIGITSROF", o2::framework::Lifetime::Timeframe);
188 if (mctruth) {
189 outputs.emplace_back(detOrig, "DIGITSMC2ROF", o2::framework::Lifetime::Timeframe);
190 outputs.emplace_back(detOrig, "DIGITSMCTR", o2::framework::Lifetime::Timeframe);
191 }
192 outputs.emplace_back(detOrig, "ROMode", 0, o2::framework::Lifetime::Timeframe);
193 return outputs;
194}
195
197{
198 std::vector<o2::framework::InputSpec> inputs;
199 inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<o2::header::DataHeader::SubSpecificationType>(channel), o2::framework::Lifetime::Timeframe);
200 inputs.emplace_back("IOTOF_aptsresp", "TF3", "APTSRESP", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("IT3/Calib/APTSResponse"));
201
202 const std::string detStr = o2::detectors::DetID::getName(o2::detectors::DetID::TF3);
203 return o2::framework::DataProcessorSpec{detStr + "Digitizer",
204 inputs,
206 o2::framework::AlgorithmSpec{o2::framework::adaptFromTask<IOTOFDPLDigitizerTask>(mctruth)},
208 {"disable-qed", o2::framework::VariantType::Bool, false, {"disable QED handling"}},
209 {"local-response-file", o2::framework::VariantType::String, "", {"use response file saved locally at this path/filename"}}}};
210}
211
212} // namespace o2::iotof
Definition of the base digitizer task class.
A const (ready only) version of MCTruthContainer.
Definition of the ITSMFT digit.
std::ostringstream debug
uint64_t orbit
Definition RawEventData.h:6
Header of the General Run Parameters object.
Definition of the ITSMFT ROFrame (trigger) record.
Definition of the ALICE3 TOF digitizer.
A read-only version of MCTruthContainer allowing for storage optimisation.
A container to hold and manage MC truth information/labels.
size_t flatten_to(ContainerType &container) const
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:60
static constexpr const char * getName(ID id)
names of defined detectors
Definition DetID.h:148
static const std::array< std::vector< std::string >, DetID::nDetectors > DETECTORBRANCHNAMES
Definition SimTraits.h:39
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
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.
Digitizer for the ALICE3 Inner/Outer TOF detector.
Definition Digitizer.h:52
void setROFRecords(std::vector< o2::itsmft::ROFRecord > *rec)
Definition Digitizer.h:56
void setROFRecordIR(const o2::InteractionRecord &ir)
Definition Digitizer.h:66
void init()
Initialize the digitizer.
Definition Digitizer.cxx:42
void fillOutputContainer()
Flush the output container.
void setDigits(std::vector< o2::iotof::Digit > *dig)
Definition Digitizer.h:54
void process(const std::vector< o2::itsmft::Hit > *hits, int evID, int srcID)
Steer conversion of hits to digits.
Definition Digitizer.cxx:96
bool isContinuous() const
Definition Digitizer.h:70
void setEventTime(const o2::InteractionTimeRecord &irt)
Set the event time.
Definition Digitizer.h:65
void setMCLabels(o2::dataformats::MCTruthContainer< o2::MCCompLabel > *mclb)
Definition Digitizer.h:55
void setGeometry(const o2::iotof::GeometryTGeo *gm)
Definition Digitizer.h:76
static GeometryTGeo * Instance()
void run(framework::ProcessingContext &pc)
void initDigitizerTask(framework::InitContext &ic) override
bool initSimChains(o2::detectors::DetID detid, std::vector< TChain * > &simchains) const
constexpr o2::header::DataOrigin gDataOriginTF3
Definition DataHeader.h:590
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
std::vector< o2::framework::OutputSpec > makeOutChannels(o2::header::DataOrigin detOrig, bool mctruth)
o2::framework::DataProcessorSpec getIOTOFDigitizerSpec(int channel, bool mctruth)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
uint32_t SubSpecificationType
Definition DataHeader.h:625
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"