Project
Loading...
Searching...
No Matches
DigitGlobalPad.h
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
15
16#ifndef ALICEO2_TPC_DigitGlobalPad_H_
17#define ALICEO2_TPC_DigitGlobalPad_H_
18
19#include <map>
20#include <vector>
21#include <fmt/format.h>
22
23#include "TTree.h" // for TTree destructor
24
29#include "DataFormatsTPC/Defs.h"
31#include "TPCBase/Mapper.h"
32#include "TPCBase/Sector.h"
33#include "TPCBase/CalDet.h"
36
37namespace o2::tpc
38{
39
42 float signal{};
43 float cumul{};
44 int tot{};
45
46 bool hasSignal() const { return signal != 0 || cumul != 0 || tot != 0; }
47
49};
50
56
58{
59 public:
61
63 DigitGlobalPad() = default;
64
66 ~DigitGlobalPad() = default;
67
69 void reset();
70
73 float getChargePad() const { return mChargePad; }
74
79 void addDigit(const MCCompLabel& label, float signal,
80 o2::dataformats::LabelContainer<std::pair<MCCompLabel, int>, false>&);
81
83 void foldSignal(PrevDigitInfo& prevDigit, const int sector, const int pad, const TimeBin time, Streamer* debugStream = nullptr, const CalPad* padParams[3] = nullptr);
84
85 void setID(int id) { mID = id; }
86 int getID() const { return mID; }
87
95 template <DigitzationMode MODE>
97 const CRU& cru, TimeBin timeBin,
98 GlobalPadNumber globalPad,
99 o2::dataformats::LabelContainer<std::pair<MCCompLabel, int>, false>& labelContainer,
100 float commonMode = 0.f, const PrevDigitInfo& prevDigit = PrevDigitInfo(), Streamer* debugStream = nullptr, const CalDet<bool>* deadMap = nullptr);
101
102 private:
107 bool compareMClabels(const MCCompLabel& label1, const MCCompLabel& label2) const;
108
109 float mChargePad = 0.;
110 int mID = -1;
111};
112
113inline void DigitGlobalPad::addDigit(const MCCompLabel& label, float signal,
114 o2::dataformats::LabelContainer<std::pair<MCCompLabel, int>, false>& labels)
115{
116 bool isKnown = false;
117 auto view = labels.getLabels(mID);
118 for (auto& mcLabel : view) {
119 if (compareMClabels(label, mcLabel.first)) {
120 ++mcLabel.second;
121 isKnown = true;
122 break;
123 }
124 }
125
126 //
127 if (!isKnown) {
128 std::pair<MCCompLabel, int> newlabel(label, 1);
129 labels.addLabel(mID, newlabel);
130 }
131 mChargePad += signal;
132}
133
134inline void DigitGlobalPad::foldSignal(PrevDigitInfo& prevDigit, const int sector, const int pad, const TimeBin time, Streamer* debugStream, const CalPad* padParams[3])
135{
136 const auto& eleParam = ParameterElectronics::Instance();
137 const auto& itSettings = IonTailSettings::Instance();
138 const float kAmp = (padParams[0]) ? padParams[0]->getValue(sector, pad) * itSettings.ITMultFactor : itSettings.ITMultFactor * 0.1276;
139 const float expLambda = (padParams[1]) ? padParams[1]->getValue(sector, pad) : std::exp(-itSettings.kTime);
140 const PrevDigitInfo prevDigInf = prevDigit;
141
142 // Saturation tail simulation
143 if (eleParam.doSaturationTail) {
144 if (prevDigit.signal > 1023.f) {
145 prevDigit.tot += int(std::round(mChargePad * eleParam.adcToT));
146 }
147 if (prevDigit.tot > 0) {
148 prevDigit.tot -= 1;
149 }
150 }
151
152 // ion tail simulation
153 // not done in case we are in the saturation tail
154 float modCharge = mChargePad;
155 if ((prevDigit.tot == 0) && (eleParam.doIonTail || eleParam.doIonTailPerPad)) {
156 modCharge = mChargePad + kAmp * (1 - expLambda) * prevDigit.cumul;
157 prevDigit.cumul += prevDigInf.signal;
158 prevDigit.cumul *= expLambda;
159 if (prevDigit.cumul < 0.1) {
160 prevDigit.cumul = 0;
161 }
162 }
163 prevDigit.signal = modCharge;
164
165 if (debugStream && Streamer::checkStream(o2::utils::StreamFlags::streamDigitFolding)) {
166 // debugStream->setStreamer("debug_digits", "UPDATE");
167 float kAmpTmp = kAmp;
168 float tailSlopeUnitTmp = expLambda;
169 float cmKValue = (padParams[2]) ? padParams[2]->getValue(sector, pad) : 1.f;
170 int sec = sector;
171 int padn = pad;
172 unsigned int timeBin = time;
173 PrevDigitInfo prevDigInfTmp = prevDigInf;
174
175 // debugStream->getStreamer() << debugStream->getUniqueTreeName("foldSignal").data()
176 debugStream->getStreamer() << "foldSignal"
177 << "sector=" << sec
178 << "pad=" << padn
179 << "timeBin=" << timeBin
180 << "kAmp=" << kAmpTmp
181 << "tailSlopeUnit=" << tailSlopeUnitTmp
182 << "cmKValue=" << cmKValue
183 << "charge=" << mChargePad
184 << "prevDig=" << prevDigInfTmp
185 << "dig=" << prevDigit
186 << "\n";
187 }
188
189 mChargePad = modCharge;
190
191 // TODO: propagate labels for ion tail?
192}
193
195{
196 mChargePad = 0;
197}
198
199inline bool DigitGlobalPad::compareMClabels(const MCCompLabel& label1, const MCCompLabel& label2) const
200{
201 // we compare directly on the bare label (in which eventID, labelID etc. are encoded)
202 // this avoids any logical operator on the label; optimization motivated from an Intel VTune analysis
203 // (note that this is also faster than using the operator= of MCCompLabel)
204 return label1.getRawValue() == label2.getRawValue();
205}
206
207template <DigitzationMode MODE>
208inline void DigitGlobalPad::fillOutputContainer(std::vector<Digit>& output,
210 const CRU& cru, TimeBin timeBin,
211 GlobalPadNumber globalPad,
212 o2::dataformats::LabelContainer<std::pair<MCCompLabel, int>, false>& labels,
213 float commonMode, const PrevDigitInfo& prevDigit, Streamer* debugStream, const CalDet<bool>* deadMap)
214{
215 const Mapper& mapper = Mapper::instance();
216 SAMPAProcessing& sampaProcessing = SAMPAProcessing::instance();
217 const PadPos pad = mapper.padPos(globalPad);
218 static std::vector<std::pair<MCCompLabel, int>> labelCollector; // static workspace container for sorting
219
222
223 float noise, pedestal;
224 const float mADC = sampaProcessing.makeSignal<MODE>(mChargePad, cru.sector(), globalPad, commonMode, pedestal, noise, prevDigit.tot);
225 const bool isDead = (deadMap == nullptr) ? false : deadMap->getValue(cru.sector(), globalPad);
226
227 if (debugStream && Streamer::checkStream(o2::utils::StreamFlags::streamDigits)) {
228 int sector = cru.sector();
229 float adc = mADC;
230 PrevDigitInfo prevDigitTmp = prevDigit;
231 // debugStream->getStreamer() << debugStream->getUniqueTreeName("digit").data()
232 debugStream->getStreamer() << "digit"
233 << "sector=" << sector
234 << "pad=" << globalPad
235 << "timeBin=" << timeBin
236 << "charge=" << mChargePad
237 << "adc=" << adc
238 << "prevDig=" << prevDigitTmp
239 << "cm=" << commonMode
240 << "isDead=" << isDead
241 << "\n";
242 }
243
245 if (!isDead && (mADC > 0)) {
246
248 const auto digiPos = output.size();
249 output.emplace_back(cru, mADC, pad.getRow(), pad.getPad(), timeBin);
250
251 // if no id was assigned the digit is from IT, CM or saturation
252 if (mID == -1) {
253 mcTruth.addNoLabelIndex(digiPos);
254 } else {
255 auto labelview = labels.getLabels(mID);
256 labelCollector.clear();
257 for (auto& mcLabel : labelview) {
258 labelCollector.push_back(mcLabel);
259 }
260 if (labelview.size() > 1) {
262 using P = std::pair<MCCompLabel, int>;
263 std::sort(labelCollector.begin(), labelCollector.end(), [](const P& a, const P& b) { return a.second > b.second; });
264 }
265 for (auto& mcLabel : labelCollector) {
266 mcTruth.addElement(digiPos, mcLabel.first);
267 }
268 }
269 }
270}
271} // namespace o2::tpc
272
273#endif // ALICEO2_TPC_DigitGlobalPad_H_
Definition of the TPC Digit.
Definition of class for writing debug informations.
int16_t time
Definition RawEventData.h:4
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the SAMPA response.
uint64_t getRawValue() const
Definition MCCompLabel.h:95
const Sector sector() const
Definition CRU.h:65
const T getValue(const int sec, const int globalPadInSector) const
Definition CalDet.h:154
void foldSignal(PrevDigitInfo &prevDigit, const int sector, const int pad, const TimeBin time, Streamer *debugStream=nullptr, const CalPad *padParams[3]=nullptr)
Fold signal with previous pad signal add ion tail and ToT for sigmal saturation.
void reset()
Resets the container.
void addDigit(const MCCompLabel &label, float signal, o2::dataformats::LabelContainer< std::pair< MCCompLabel, int >, false > &)
void fillOutputContainer(std::vector< Digit > &output, dataformats::MCTruthContainer< MCCompLabel > &mcTruth, const CRU &cru, TimeBin timeBin, GlobalPadNumber globalPad, o2::dataformats::LabelContainer< std::pair< MCCompLabel, int >, false > &labelContainer, float commonMode=0.f, const PrevDigitInfo &prevDigit=PrevDigitInfo(), Streamer *debugStream=nullptr, const CalDet< bool > *deadMap=nullptr)
o2::utils::DebugStreamer Streamer
DigitGlobalPad()=default
Constructor.
~DigitGlobalPad()=default
Destructor.
const PadPos & padPos(GlobalPadNumber padNumber) const
Definition Mapper.h:50
static Mapper & instance(const std::string mappingDir="")
Definition Mapper.h:44
static SAMPAProcessing & instance()
float makeSignal(float ADCcounts, const int sector, const int globalPadInSector, const float commonMode, float &pedestal, float &noise, float tot=0)
class to enable streaming debug information to root files
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLuint id
Definition glcorearb.h:650
Global TPC definitions and constants.
Definition SimTraits.h:167
unsigned short GlobalPadNumber
global pad number
Definition Defs.h:129
unsigned int TimeBin
global time bin
Definition Defs.h:132
@ streamDigits
stream digit information
@ streamDigitFolding
stream ion tail and saturatio information
float cumul
cumulative signal of prev time bins
ClassDefNV(PrevDigitInfo, 1)
int tot
remaining time over threshold
float signal
pad signal
ArrayADC adc