Project
Loading...
Searching...
No Matches
MIDDigitizerSpec.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 "MIDDigitizerSpec.h"
13#include "TChain.h"
19#include "Framework/Lifetime.h"
20#include "Framework/Task.h"
21#include "Steer/HitProcessingManager.h" // for DigitizationContext
36
37using namespace o2::framework;
39using DPMAP = std::unordered_map<o2::dcs::DataPointIdentifier, std::vector<o2::dcs::DataPointValue>>;
40
41namespace o2
42{
43namespace mid
44{
45
47{
48 public:
49 MIDDPLDigitizerTask() : o2::base::BaseDPLDigitizer(o2::base::InitServices::GEOM) {}
50
52 {
53 LOG(info) << "initializing MID digitization";
54
55 mDigitizer = std::make_unique<Digitizer>(createDefaultChamberResponse(), createDefaultChamberEfficiencyResponse(), createTransformationFromManager(gGeoManager));
56 }
57
59 {
60 if (matcher == ConcreteDataMatcher(header::gDataOriginMID, "CHAMBER_EFF", 0)) {
61 auto* chEffCounters = static_cast<std::vector<ChEffCounter>*>(obj);
62 mDigitizer->setChamberEfficiency(*chEffCounters);
63 return;
64 }
65 if (matcher == ConcreteDataMatcher(header::gDataOriginMID, "CHAMBER_HV", 0)) {
66 auto* dpMap = static_cast<DPMAP*>(obj);
67 mDigitizer->getChamberResponse().setHV(*dpMap);
68 return;
69 }
70 }
71
73 {
74 static bool finished = false;
75 if (finished) {
76 return;
77 }
78 LOG(debug) << "Doing MID digitization";
79
80 // read collision context from input
81 auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
82 // Triggers reading from CCDB
83 pc.inputs().get<std::vector<ChEffCounter>*>("mid_ch_eff");
84 pc.inputs().get<DPMAP*>("mid_ch_hv");
85 context->initSimChains(o2::detectors::DetID::MID, mSimChains);
86 auto& irecords = context->getEventRecords();
87
89 auto delay = InteractionRecord(mElectronicsDelay.localToBC, 0);
90 auto firstTimeTF = InteractionTimeRecord(firstTF + delay, 0);
91
92 auto& eventParts = context->getEventParts();
93 std::vector<o2::mid::ColumnData> digits, digitsAccum;
94 std::vector<o2::mid::ROFRecord> rofRecords;
96
97 // loop over all composite collisions given from context
98 // (aka loop over all the interaction records)
99 for (int collID = 0; collID < irecords.size(); ++collID) {
100 // for each collision, loop over the constituents event and source IDs
101 // (background signal merging is basically taking place here)
102
103 // Skip digits produced before the first orbit
104 if (irecords[collID] < firstTimeTF) {
105 continue;
106 }
107 auto firstEntry = digitsAccum.size();
108 for (auto& part : eventParts[collID]) {
109 mDigitizer->setEventID(part.entryID);
110 mDigitizer->setSrcID(part.sourceID);
111
112 // get the hits for this event and this source
113 std::vector<o2::mid::Hit> hits;
114 context->retrieveHits(mSimChains, "MIDHit", part.sourceID, part.entryID, &hits);
115 LOG(debug) << "For collision " << collID << " eventID " << part.entryID << " found MID " << hits.size() << " hits ";
116
117 mDigitizer->process(hits, digits, labels);
118 if (digits.empty()) {
119 continue;
120 }
121 digitsAccum.insert(digitsAccum.end(), digits.begin(), digits.end());
122 labelsAccum.mergeAtBack(labels);
123 }
124 auto nEntries = digitsAccum.size() - firstEntry;
125 rofRecords.emplace_back(irecords[collID], EventType::Standard, firstEntry, nEntries);
126 }
127
128 mDigitsMerger.process(digitsAccum, labelsAccum, rofRecords);
129
130 LOG(debug) << "MID: Sending " << digitsAccum.size() << " digits.";
131 pc.outputs().snapshot(Output{"MID", "DIGITS", 0}, mDigitsMerger.getColumnData());
132 pc.outputs().snapshot(Output{"MID", "DIGITSROF", 0}, mDigitsMerger.getROFRecords());
133 if (pc.outputs().isAllowed({"MID", "DIGITLABELS", 0})) {
134 pc.outputs().snapshot(Output{"MID", "DIGITLABELS", 0}, mDigitsMerger.getMCContainer());
135 }
136 LOG(debug) << "MID: Sending ROMode= " << mROMode << " to GRPUpdater";
137 pc.outputs().snapshot(Output{"MID", "ROMode", 0}, mROMode);
138
139 // we should be only called once; tell DPL that this process is ready to exit
140 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
141 finished = true;
142 }
143
144 private:
145 std::unique_ptr<Digitizer> mDigitizer;
146 DigitsMerger mDigitsMerger;
147 std::vector<TChain*> mSimChains;
148 // RS: at the moment using hardcoded flag for continuos readout
150 ElectronicsDelay mElectronicsDelay; // Electronics delay
151};
152
154{
155 // create the full data processor spec using
156 // a name identifier
157 // input description
158 // algorithmic description (here a lambda getting called once to setup the actual processing function)
159 // options that can be used for this processor (here: input file names where to take the hits)
160
161 std::vector<InputSpec> inputSpecs;
162 inputSpecs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<SubSpecificationType>(channel), Lifetime::Timeframe);
163 inputSpecs.emplace_back("mid_ch_eff", header::gDataOriginMID, "CHAMBER_EFF", 0, Lifetime::Condition, ccdbParamSpec("MID/Calib/ChamberEfficiency"));
164 inputSpecs.emplace_back("mid_ch_hv", header::gDataOriginMID, "CHAMBER_HV", 0, Lifetime::Condition, ccdbParamSpec("MID/Calib/HV"));
165
166 std::vector<OutputSpec> outputs;
167 outputs.emplace_back("MID", "DIGITS", 0, Lifetime::Timeframe);
168 outputs.emplace_back("MID", "DIGITSROF", 0, Lifetime::Timeframe);
169 if (mctruth) {
170 outputs.emplace_back("MID", "DIGITLABELS", 0, Lifetime::Timeframe);
171 }
172 outputs.emplace_back("MID", "ROMode", 0, Lifetime::Timeframe);
173
174 return DataProcessorSpec{
175 "MIDDigitizer",
176 inputSpecs,
177 outputs,
178 AlgorithmSpec{adaptFromTask<MIDDPLDigitizerTask>()},
179 Options{}};
180}
181
182} // namespace mid
183} // namespace o2
Definition of the base digitizer task class.
Chamber efficiency counters.
MID RPC effciency response.
MID RPC response.
Strip pattern (aka digits)
Label for MID.
Digits merger for MID.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
Delay parameters for MID electronics.
Header of the General Run Parameters object.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Digitizer for MID.
Implementation of the trigger-stations geometry.
Definition of the MID event record.
std::ostringstream debug
A container to hold and manage MC truth information/labels.
void mergeAtBack(MCTruthContainer< TruthElement > const &other)
static constexpr ID MID
Definition DetID.h:73
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
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.
const std::vector< ColumnData > & getColumnData() const
Gets the merged column data.
void process(const std::vector< ColumnData > &inDigitStore, const o2::dataformats::MCTruthContainer< MCLabel > &inMCContainer, const std::vector< ROFRecord > &inROFRecords, bool mergeInBunchPileup=true)
Merges the MC digits that are provided per hit into the format that we expect from data.
const o2::dataformats::MCTruthContainer< MCLabel > & getMCContainer() const
Gets the merged MC labels.
const std::vector< ROFRecord > & getROFRecords() const
Gets the merged RO frame records.
void initDigitizerTask(framework::InitContext &ic) override
void run(framework::ProcessingContext &pc)
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
std::unordered_map< DPID, std::vector< DPVAL > > DPMAP
Definition dcs-ccdb.cxx:37
constexpr o2::header::DataOrigin gDataOriginMID
Definition DataHeader.h:573
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
header::DataHeader::SubSpecificationType SubSpecificationType
GeometryTransformer createTransformationFromManager(const TGeoManager *geoManager)
ChamberEfficiencyResponse createDefaultChamberEfficiencyResponse()
o2::framework::DataProcessorSpec getMIDDigitizerSpec(int channel, bool mctruth)
ChamberResponse createDefaultChamberResponse()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
int16_t localToBC
Delay between collision BC and local clock.
IR getFirstSampledTFIR() const
get TF and HB (abs) for this IR
Definition HBFUtils.h:74
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits