-
Notifications
You must be signed in to change notification settings - Fork 508
Expand file tree
/
Copy pathIOTOFDigitizerSpec.cxx
More file actions
208 lines (178 loc) · 8.51 KB
/
Copy pathIOTOFDigitizerSpec.cxx
File metadata and controls
208 lines (178 loc) · 8.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "IOTOFDigitizerSpec.h"
#include "Framework/ControlService.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/CCDBParamSpec.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/DataRefUtils.h"
#include "Framework/Lifetime.h"
#include "Framework/Task.h"
#include "Steer/HitProcessingManager.h"
#include "DataFormatsITSMFT/Digit.h"
#include "SimulationDataFormat/ConstMCTruthContainer.h"
#include "DetectorsBase/BaseDPLDigitizer.h"
#include "DetectorsRaw/HBFUtils.h"
#include "DetectorsCommonDataFormats/DetID.h"
#include "DetectorsCommonDataFormats/SimTraits.h"
#include "DataFormatsParameters/GRPObject.h"
#include "DataFormatsITSMFT/ROFRecord.h"
#include "IOTOFSimulation/Digitizer.h"
#include "Headers/DataHeader.h"
#include "IOTOFBase/GeometryTGeo.h"
#include "IOTOFBase/IOTOFBaseParam.h"
#include <TChain.h>
#include <TStopwatch.h>
#include <algorithm>
#include <memory>
#include <string>
using namespace o2::framework;
namespace o2::iotof
{
class IOTOFDPLDigitizerTask : o2::base::BaseDPLDigitizer
{
public:
using BaseDPLDigitizer::init;
IOTOFDPLDigitizerTask(bool mctruth = true) : BaseDPLDigitizer(o2::base::InitServices::FIELD | o2::base::InitServices::GEOM),
mWithMCTruth(mctruth) {}
void initDigitizerTask(framework::InitContext& ic) override
{
mDisableQED = ic.options().get<bool>("disable-qed");
auto geom = GeometryTGeo::Instance();
geom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G)); // make sure L2G matrices are loaded
mDigitizer.setGeometry(geom);
mDigitizer.setChargeThreshold(-1000.f);
mDigitizer.init();
}
void run(framework::ProcessingContext& pc)
{
if (mFinished) {
return;
}
mFirstOrbitTF = pc.services().get<o2::framework::TimingInfo>().firstTForbit;
const o2::InteractionRecord firstIR(0, mFirstOrbitTF);
// read collision context from input
auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
context->initSimChains(mID, mSimChains);
const bool withQED = context->isQEDProvided() && !mDisableQED;
auto& timesview = context->getEventRecords();
LOG(info) << "GOT " << timesview.size() << " COLLISION TIMES";
LOG(info) << "SIMCHAINS " << mSimChains.size();
// if there is nothing to do ... return
if (timesview.empty()) {
return;
}
TStopwatch timer;
timer.Start();
LOG(info) << " CALLING TF3 DIGITIZATION ";
mDigitizer.setDigits(&mDigits);
mDigitizer.setROFRecords(&mROFRecords);
mDigitizer.setROFRecordIR(firstIR);
if (mWithMCTruth) {
mDigitizer.setMCLabels(&mLabels);
}
auto& eventParts = context->getEventParts(withQED);
// loop over all composite collisions given from context
// (aka loop over all the interaction records)
// o2::InteractionTimeRecord firstorbit(o2::InteractionRecord(0, o2::raw::HBFUtils::Instance().orbitFirstSampled), 0.0);
for (int collID = 0; collID < timesview.size(); ++collID) {
o2::InteractionTimeRecord orbit(timesview[collID]);
// orbit += firstorbit
mDigitizer.setEventTime(orbit);
// for each collision, loop over the constituents event and source IDs
// (background signal merging is basically taking place here)
for (const auto& part : eventParts[collID]) {
// get the hits for this event and this source
mHits.clear();
context->retrieveHits(mSimChains, o2::detectors::SimTraits::DETECTORBRANCHNAMES[mID][0].c_str(), part.sourceID, part.entryID, &mHits);
if (mHits.size() > 0) {
mDigits.clear();
if (mWithMCTruth) {
mLabels.clear();
}
LOG(debug) << "For collision " << collID << " eventID " << part.entryID << " found " << mHits.size() << " hits ";
mDigitizer.process(&mHits, part.entryID, part.sourceID); // call actual digitization procedure
}
}
}
if (mDigitizer.isContinuous()) {
LOG(debug) << "Number of digits before final flush: " << mDigits.size();
mDigits.clear();
if (mWithMCTruth) {
mLabels.clear();
}
LOG(debug) << "Final flushing for continuous mode";
mDigitizer.fillOutputContainer();
LOG(debug) << "Number of digits after final flush: " << mDigits.size();
}
// here we have all digits and we can send them to consumer (aka snapshot it onto output)
LOG(debug) << "Digitization finished with " << mDigits.size() << " digits and " << mROFRecords.size() << " ROF records";
pc.outputs().snapshot(Output{mOrigin, "DIGITS", 0}, mDigits);
pc.outputs().snapshot(Output{mOrigin, "DIGITSROF", 0}, mROFRecords);
if (mWithMCTruth) {
auto& sharedlabels = pc.outputs().make<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>(Output{mOrigin, "DIGITSMCTR", 0});
mLabels.flatten_to(sharedlabels);
// free space of existing label containers
mLabels.clear_andfreememory();
// write dummy MC2ROF vector to keep writer/readers backward compatible
// NOTE: Steer/DigitizerWorkflow/src/ITSMFTDigitizerSpec.cxx also uses dummy MC2ROF
static std::vector<o2::itsmft::MC2ROFRecord> dummyMC2ROF;
pc.outputs().snapshot(Output{mOrigin, "DIGITSMC2ROF", 0}, dummyMC2ROF);
}
timer.Stop();
LOG(info) << "Digitization took " << timer.CpuTime() << "s";
// we should be only called once; tell DPL that this process is ready to exit
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
mFinished = true;
}
private:
bool mDisableQED = false;
bool mWithMCTruth{true};
bool mFinished{false};
unsigned long mFirstOrbitTF = 0x0;
const o2::detectors::DetID mID{o2::detectors::DetID::TF3};
const o2::header::DataOrigin mOrigin{o2::header::gDataOriginTF3};
o2::iotof::Digitizer mDigitizer{};
std::vector<o2::iotof::Digit> mDigits{};
std::vector<o2::itsmft::ROFRecord> mROFRecords{};
std::vector<o2::itsmft::Hit> mHits{};
std::vector<o2::itsmft::Hit>* mHitsP{&mHits};
o2::dataformats::MCTruthContainer<o2::MCCompLabel> mLabels{};
std::vector<TChain*> mSimChains{};
o2::parameters::GRPObject::ROMode mROMode = o2::parameters::GRPObject::PRESENT; // readout mode
};
std::vector<o2::framework::OutputSpec> makeOutChannels(o2::header::DataOrigin detOrig, bool mctruth)
{
std::vector<o2::framework::OutputSpec> outputs;
outputs.emplace_back(detOrig, "DIGITS", o2::framework::Lifetime::Timeframe);
outputs.emplace_back(detOrig, "DIGITSROF", o2::framework::Lifetime::Timeframe);
if (mctruth) {
outputs.emplace_back(detOrig, "DIGITSMC2ROF", o2::framework::Lifetime::Timeframe);
outputs.emplace_back(detOrig, "DIGITSMCTR", o2::framework::Lifetime::Timeframe);
}
outputs.emplace_back(detOrig, "ROMode", 0, o2::framework::Lifetime::Timeframe);
return outputs;
}
o2::framework::DataProcessorSpec getIOTOFDigitizerSpec(int channel, bool mctruth)
{
std::vector<o2::framework::InputSpec> inputs;
inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<o2::header::DataHeader::SubSpecificationType>(channel), o2::framework::Lifetime::Timeframe);
inputs.emplace_back("IOTOF_aptsresp", "TF3", "APTSRESP", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("IT3/Calib/APTSResponse"));
const std::string detStr = o2::detectors::DetID::getName(o2::detectors::DetID::TF3);
return o2::framework::DataProcessorSpec{detStr + "Digitizer",
inputs,
makeOutChannels(o2::header::gDataOriginTF3, mctruth),
o2::framework::AlgorithmSpec{o2::framework::adaptFromTask<IOTOFDPLDigitizerTask>(mctruth)},
o2::framework::Options{
{"disable-qed", o2::framework::VariantType::Bool, false, {"disable QED handling"}},
{"local-response-file", o2::framework::VariantType::String, "", {"use response file saved locally at this path/filename"}}}};
}
} // namespace o2::iotof