forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFV0DigitizerSpec.cxx
More file actions
197 lines (171 loc) · 8.4 KB
/
FV0DigitizerSpec.cxx
File metadata and controls
197 lines (171 loc) · 8.4 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
// 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 "FV0DigitizerSpec.h"
#include "DataFormatsFV0/ChannelData.h"
#include "DataFormatsFIT/DeadChannelMap.h"
#include "DataFormatsFV0/Digit.h"
#include "Framework/ControlService.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/DataRefUtils.h"
#include "Framework/Lifetime.h"
#include "Headers/DataHeader.h"
#include <TStopwatch.h>
#include "Steer/HitProcessingManager.h" // for DigitizationContext
#include <TChain.h>
#include "SimulationDataFormat/MCTruthContainer.h"
#include "Framework/Task.h"
#include "DataFormatsParameters/GRPObject.h"
#include "FV0Simulation/Digitizer.h"
#include "FV0Simulation/DigitizationConstant.h"
#include "DataFormatsFV0/MCLabel.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "DetectorsBase/BaseDPLDigitizer.h"
#include "DetectorsRaw/HBFUtils.h"
#include "Framework/CCDBParamSpec.h"
#include <TFile.h>
using namespace o2::framework;
using SubSpecificationType = o2::framework::DataAllocator::SubSpecificationType;
namespace o2
{
namespace fv0
{
class FV0DPLDigitizerTask : public o2::base::BaseDPLDigitizer
{
using GRP = o2::parameters::GRPObject;
public:
FV0DPLDigitizerTask() : o2::base::BaseDPLDigitizer(), mDigitizer(), mSimChains(), mDigitsCh(), mDigitsBC(), mLabels() {}
~FV0DPLDigitizerTask() override = default;
void initDigitizerTask(framework::InitContext& ic) override
{
LOG(debug) << "FV0DPLDigitizerTask:init";
mDigitizer.init();
mDisableQED = ic.options().get<bool>("disable-qed"); //TODO: QED implementation to be tested
mUseDeadChannelMap = !ic.options().get<bool>("disable-dead-channel-map");
mUpdateDeadChannelMap = mUseDeadChannelMap;
}
void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
{
// Initialize the dead channel map only once
if (matcher == ConcreteDataMatcher("FV0", "DeadChannelMap", 0)) {
mUpdateDeadChannelMap = false;
}
}
void run(framework::ProcessingContext& pc)
{
if (mFinished) {
return;
}
LOG(debug) << "FV0DPLDigitizerTask:run";
// read collision context from input
auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
context->initSimChains(o2::detectors::DetID::FV0, mSimChains);
const bool withQED = context->isQEDProvided() && !mDisableQED; //TODO: QED implementation to be tested
if (mUseDeadChannelMap && mUpdateDeadChannelMap) {
auto deadChannelMap = pc.inputs().get<o2::fit::DeadChannelMap*>("fv0deadchannelmap");
mDigitizer.setDeadChannelMap(deadChannelMap.get());
}
mDigitizer.setTimeStamp(context->getGRP().getTimeStart());
auto& irecords = context->getEventRecords(withQED); //TODO: QED implementation to be tested
auto& eventParts = context->getEventParts(withQED); //TODO: QED implementation to be tested
// the interaction record marking the timeframe start
auto firstTF = InteractionTimeRecord(o2::raw::HBFUtils::Instance().getFirstSampledTFIR(), 0);
// loop over all composite collisions given from context
// (aka loop over all the interaction records)
std::vector<o2::fv0::Hit> hits;
for (int collID = 0; collID < irecords.size(); ++collID) {
// Note: Very crude filter to neglect collisions coming before
// the first interaction record of the timeframe. Remove this, once these collisions can be handled
// within the digitization routine. Collisions before this timeframe might impact digits of this timeframe.
// See https://its.cern.ch/jira/browse/O2-5395.
if (irecords[collID] < firstTF) {
LOG(info) << "Too early: Not digitizing collision " << collID;
continue;
}
mDigitizer.clear();
const auto& irec = irecords[collID];
mDigitizer.setInteractionRecord(irec);
// for each collision, loop over the constituents event and source IDs
// (background signal merging is basically taking place here)
for (auto& part : eventParts[collID]) {
hits.clear();
context->retrieveHits(mSimChains, "FV0Hit", part.sourceID, part.entryID, &hits);
LOG(debug) << "[FV0] For collision " << collID << " eventID " << part.entryID << " found " << hits.size() << " hits ";
// call actual digitization procedure
mDigitizer.setEventId(part.entryID);
mDigitizer.setSrcId(part.sourceID);
mDigitizer.process(hits, mDigitsBC, mDigitsCh, mDigitsTrig, mLabels);
}
LOG(debug) << "[FV0] Has " << mDigitsBC.size() << " BC elements, " << mDigitsCh.size() << " mDigitsCh elements";
}
o2::InteractionTimeRecord terminateIR;
terminateIR.orbit = 0xffffffff; // supply IR in the infinite future to flush all cached BC
mDigitizer.setInteractionRecord(terminateIR);
mDigitizer.flush(mDigitsBC, mDigitsCh, mDigitsTrig, mLabels);
// here we have all digits and we can send them to consumer (aka snapshot it onto output)
LOG(info) << "FV0: Sending " << mDigitsBC.size() << " digitsBC and " << mDigitsCh.size() << " digitsCh.";
// send out to next stage
pc.outputs().snapshot(Output{"FV0", "DIGITSBC", 0}, mDigitsBC);
pc.outputs().snapshot(Output{"FV0", "DIGITSCH", 0}, mDigitsCh);
pc.outputs().snapshot(Output{"FV0", "TRIGGERINPUT", 0}, mDigitsTrig);
if (pc.outputs().isAllowed({"FV0", "DIGITLBL", 0})) {
pc.outputs().snapshot(Output{"FV0", "DIGITLBL", 0}, mLabels);
}
LOG(info) << "FV0: Sending ROMode= " << mROMode << " to GRPUpdater";
pc.outputs().snapshot(Output{"FV0", "ROMode", 0}, mROMode);
// 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 mFinished = false;
bool mUseDeadChannelMap = true;
bool mUpdateDeadChannelMap = true;
Digitizer mDigitizer;
std::vector<TChain*> mSimChains;
std::vector<o2::fv0::ChannelData> mDigitsCh;
std::vector<o2::fv0::Digit> mDigitsBC;
std::vector<o2::fv0::DetTrigInput> mDigitsTrig;
o2::dataformats::MCTruthContainer<o2::fv0::MCLabel> mLabels; // labels which get filled
// RS: at the moment using hardcoded flag for continuous readout
o2::parameters::GRPObject::ROMode mROMode = o2::parameters::GRPObject::ROMode(o2::parameters::GRPObject::CONTINUOUS | o2::parameters::GRPObject::TRIGGERING); // readout mode
bool mDisableQED = false;
};
o2::framework::DataProcessorSpec getFV0DigitizerSpec(int channel, bool mctruth)
{
// create the full data processor spec using
// a name identifier
// input description
// algorithmic description (here a lambda getting called once to setup the actual processing function)
// options that can be used for this processor (here: input file names where to take the hits)
std::vector<OutputSpec> outputs;
outputs.emplace_back("FV0", "DIGITSBC", 0, Lifetime::Timeframe);
outputs.emplace_back("FV0", "DIGITSCH", 0, Lifetime::Timeframe);
outputs.emplace_back("FV0", "TRIGGERINPUT", 0, Lifetime::Timeframe);
if (mctruth) {
outputs.emplace_back("FV0", "DIGITLBL", 0, Lifetime::Timeframe);
}
outputs.emplace_back("FV0", "ROMode", 0, Lifetime::Timeframe);
std::vector<InputSpec> inputs;
inputs.emplace_back("fv0deadchannelmap", "FV0", "DeadChannelMap", 0, Lifetime::Condition, ccdbParamSpec("FV0/Calib/DeadChannelMap"));
inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<SubSpecificationType>(channel), Lifetime::Timeframe);
return DataProcessorSpec{
"FV0Digitizer",
inputs,
outputs,
AlgorithmSpec{adaptFromTask<FV0DPLDigitizerTask>()},
Options{{"pileup", VariantType::Int, 1, {"whether to run in continuous time mode"}},
{"disable-qed", o2::framework::VariantType::Bool, false, {"disable QED handling"}},
{"disable-dead-channel-map", o2::framework::VariantType::Bool, false, {"Don't mask dead channels"}}}};
// Options{{"pileup", VariantType::Int, 1, {"whether to run in continuous time mode"}}}};
}
} // end namespace fv0
} // end namespace o2