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.setChargeThreshold(-1000.f);
63 mDigitizer.init();
64 }
65
67 {
68 if (mFinished) {
69 return;
70 }
71 mFirstOrbitTF = pc.services().get<o2::framework::TimingInfo>().firstTForbit;
72 const o2::InteractionRecord firstIR(0, mFirstOrbitTF);
73
74 // read collision context from input
75 auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
76 context->initSimChains(mID, mSimChains);
77 const bool withQED = context->isQEDProvided() && !mDisableQED;
78 auto& timesview = context->getEventRecords();
79 LOG(info) << "GOT " << timesview.size() << " COLLISION TIMES";
80 LOG(info) << "SIMCHAINS " << mSimChains.size();
81
82 // if there is nothing to do ... return
83 if (timesview.empty()) {
84 return;
85 }
86
87 TStopwatch timer;
88 timer.Start();
89 LOG(info) << " CALLING TF3 DIGITIZATION ";
90
91 mDigitizer.setDigits(&mDigits);
92 mDigitizer.setROFRecords(&mROFRecords);
93 if (mWithMCTruth) {
94 mDigitizer.setMCLabels(&mLabels);
95 }
96
97 auto& eventParts = context->getEventParts(withQED);
98 // loop over all composite collisions given from context
99 // (aka loop over all the interaction records)
100 // o2::InteractionTimeRecord firstorbit(o2::InteractionRecord(0, o2::raw::HBFUtils::Instance().orbitFirstSampled), 0.0);
101 for (int collID = 0; collID < timesview.size(); ++collID) {
102 o2::InteractionTimeRecord orbit(timesview[collID]);
103 // orbit += firstorbit
104 mDigitizer.setEventTime(orbit);
105
106 // for each collision, loop over the constituents event and source IDs
107 // (background signal merging is basically taking place here)
108 for (const auto& part : eventParts[collID]) {
109
110 // get the hits for this event and this source
111 mHits.clear();
112 context->retrieveHits(mSimChains, o2::detectors::SimTraits::DETECTORBRANCHNAMES[mID][0].c_str(), part.sourceID, part.entryID, &mHits);
113
114 if (mHits.size() > 0) {
115 mDigits.clear();
116 if (mWithMCTruth) {
117 mLabels.clear();
118 }
119
120 LOG(debug) << "For collision " << collID << " eventID " << part.entryID << " found " << mHits.size() << " hits ";
121 mDigitizer.process(&mHits, part.entryID, part.sourceID); // call actual digitization procedure
122 }
123 }
124 }
125 if (mDigitizer.isContinuous()) {
126 LOG(debug) << "Number of digits before final flush: " << mDigits.size();
127 mDigits.clear();
128 if (mWithMCTruth) {
129 mLabels.clear();
130 }
131 LOG(debug) << "Final flushing for continuous mode";
132 mDigitizer.fillOutputContainer();
133 LOG(debug) << "Number of digits after final flush: " << mDigits.size();
134 }
135
136 // here we have all digits and we can send them to consumer (aka snapshot it onto output)
137 LOG(debug) << "Digitization finished with " << mDigits.size() << " digits and " << mROFRecords.size() << " ROF records";
138 pc.outputs().snapshot(Output{mOrigin, "DIGITS", 0}, mDigits);
139 pc.outputs().snapshot(Output{mOrigin, "DIGITSROF", 0}, mROFRecords);
140 if (mWithMCTruth) {
141 auto& sharedlabels = pc.outputs().make<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>(Output{mOrigin, "DIGITSMCTR", 0});
142 mLabelsAccum.flatten_to(sharedlabels);
143 // free space of existing label containers
144 mLabels.clear_andfreememory();
145 mLabelsAccum.clear_andfreememory();
146
147 // write dummy MC2ROF vector to keep writer/readers backward compatible
148 // NOTE: Steer/DigitizerWorkflow/src/ITSMFTDigitizerSpec.cxx also uses dummy MC2ROF
149 static std::vector<o2::itsmft::MC2ROFRecord> dummyMC2ROF;
150 pc.outputs().snapshot(Output{mOrigin, "DIGITSMC2ROF", 0}, dummyMC2ROF);
151 }
152
153 timer.Stop();
154 LOG(info) << "Digitization took " << timer.CpuTime() << "s";
155
156 // we should be only called once; tell DPL that this process is ready to exit
157 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
158
159 mFinished = true;
160 }
161
162 private:
163 bool mDisableQED = false;
164 bool mWithMCTruth{true};
165 bool mFinished{false};
166 unsigned long mFirstOrbitTF = 0x0;
167 const o2::detectors::DetID mID{o2::detectors::DetID::TF3};
169 o2::iotof::Digitizer mDigitizer{};
170 std::vector<o2::iotof::Digit> mDigits{};
171 std::vector<o2::itsmft::ROFRecord> mROFRecords{};
172 std::vector<o2::itsmft::Hit> mHits{};
173 std::vector<o2::itsmft::Hit>* mHitsP{&mHits};
176 std::vector<TChain*> mSimChains{};
178};
179
180std::vector<o2::framework::OutputSpec> makeOutChannels(o2::header::DataOrigin detOrig, bool mctruth)
181{
182 std::vector<o2::framework::OutputSpec> outputs;
183 outputs.emplace_back(detOrig, "DIGITS", o2::framework::Lifetime::Timeframe);
184 outputs.emplace_back(detOrig, "DIGITSROF", o2::framework::Lifetime::Timeframe);
185 if (mctruth) {
186 outputs.emplace_back(detOrig, "DIGITSMC2ROF", o2::framework::Lifetime::Timeframe);
187 outputs.emplace_back(detOrig, "DIGITSMCTR", o2::framework::Lifetime::Timeframe);
188 }
189 outputs.emplace_back(detOrig, "ROMode", 0, o2::framework::Lifetime::Timeframe);
190 return outputs;
191}
192
194{
195 std::vector<o2::framework::InputSpec> inputs;
196 inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<o2::header::DataHeader::SubSpecificationType>(channel), o2::framework::Lifetime::Timeframe);
197 inputs.emplace_back("IOTOF_aptsresp", "TF3", "APTSRESP", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("IT3/Calib/APTSResponse"));
198
199 const std::string detStr = o2::detectors::DetID::getName(o2::detectors::DetID::TF3);
200 return o2::framework::DataProcessorSpec{detStr + "Digitizer",
201 inputs,
203 o2::framework::AlgorithmSpec{o2::framework::adaptFromTask<IOTOFDPLDigitizerTask>(mctruth)},
205 {"disable-qed", o2::framework::VariantType::Bool, false, {"disable QED handling"}},
206 {"local-response-file", o2::framework::VariantType::String, "", {"use response file saved locally at this path/filename"}}}};
207}
208
209} // 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:58
static constexpr const char * getName(ID id)
names of defined detectors
Definition DetID.h:146
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:51
void setROFRecords(std::vector< o2::itsmft::ROFRecord > *rec)
Definition Digitizer.h:55
void init()
Initialize the digitizer.
Definition Digitizer.cxx:35
void fillOutputContainer()
Flush the output container.
void setDigits(std::vector< o2::iotof::Digit > *dig)
Definition Digitizer.h:53
void process(const std::vector< o2::itsmft::Hit > *hits, int evID, int srcID)
Steer conversion of hits to digits.
Definition Digitizer.cxx:62
bool isContinuous() const
Definition Digitizer.h:68
void setEventTime(const o2::InteractionTimeRecord &irt)
Set the event time.
Definition Digitizer.h:64
void setChargeThreshold(float thr)
Definition Digitizer.h:77
void setMCLabels(o2::dataformats::MCTruthContainer< o2::MCCompLabel > *mclb)
Definition Digitizer.h:54
void setGeometry(const o2::iotof::GeometryTGeo *gm)
Definition Digitizer.h:74
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:587
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:622
static constexpr int L2G
Definition Cartesian.h:54
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"