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 SAMPAProcessing& sampaProcessing, std::vector<std::pair<MCCompLabel, int>>& labelCollector,
101 float commonMode = 0.f, const PrevDigitInfo& prevDigit = PrevDigitInfo(), Streamer* debugStream = nullptr, const CalDet<bool>* deadMap = nullptr);
102
103 private:
108 bool compareMClabels(const MCCompLabel& label1, const MCCompLabel& label2) const;
109
110 float mChargePad = 0.;
111 int mID = -1;
112};
113
114inline void DigitGlobalPad::addDigit(const MCCompLabel& label, float signal,
115 o2::dataformats::LabelContainer<std::pair<MCCompLabel, int>, false>& labels)
116{
117 bool isKnown = false;
118 auto view = labels.getLabels(mID);
119 for (auto& mcLabel : view) {
120 if (compareMClabels(label, mcLabel.first)) {
121 ++mcLabel.second;
122 isKnown = true;
123 break;
124 }
125 }
126
127 //
128 if (!isKnown) {
129 std::pair<MCCompLabel, int> newlabel(label, 1);
130 labels.addLabel(mID, newlabel);
131 }
132 mChargePad += signal;
133}
134
135inline void DigitGlobalPad::foldSignal(PrevDigitInfo& prevDigit, const int sector, const int pad, const TimeBin time, Streamer* debugStream, const CalPad* padParams[3])
136{
137 const auto& eleParam = ParameterElectronics::Instance();
138 const auto& itSettings = IonTailSettings::Instance();
139 const float kAmp = (padParams[0]) ? padParams[0]->getValue(sector, pad) * itSettings.ITMultFactor : itSettings.ITMultFactor * 0.1276;
140 const float expLambda = (padParams[1]) ? padParams[1]->getValue(sector, pad) : std::exp(-itSettings.kTime);
141 const PrevDigitInfo prevDigInf = prevDigit;
142
143 // Saturation tail simulation
144 if (eleParam.doSaturationTail) {
145 if (prevDigit.signal > 1023.f) {
146 prevDigit.tot += int(std::round(mChargePad * eleParam.adcToT));
147 }
148 if (prevDigit.tot > 0) {
149 prevDigit.tot -= 1;
150 }
151 }
152
153 // ion tail simulation
154 // not done in case we are in the saturation tail
155 float modCharge = mChargePad;
156 if ((prevDigit.tot == 0) && (eleParam.doIonTail || eleParam.doIonTailPerPad)) {
157 modCharge = mChargePad + kAmp * (1 - expLambda) * prevDigit.cumul;
158 prevDigit.cumul += prevDigInf.signal;
159 prevDigit.cumul *= expLambda;
160 if (prevDigit.cumul < 0.1) {
161 prevDigit.cumul = 0;
162 }
163 }
164 prevDigit.signal = modCharge;
165
166 if (debugStream && Streamer::checkStream(o2::utils::StreamFlags::streamDigitFolding)) {
167 // debugStream->setStreamer("debug_digits", "UPDATE");
168 float kAmpTmp = kAmp;
169 float tailSlopeUnitTmp = expLambda;
170 float cmKValue = (padParams[2]) ? padParams[2]->getValue(sector, pad) : 1.f;
171 int sec = sector;
172 int padn = pad;
173 unsigned int timeBin = time;
174 PrevDigitInfo prevDigInfTmp = prevDigInf;
175
176 // debugStream->getStreamer() << debugStream->getUniqueTreeName("foldSignal").data()
177 debugStream->getStreamer() << "foldSignal"
178 << "sector=" << sec
179 << "pad=" << padn
180 << "timeBin=" << timeBin
181 << "kAmp=" << kAmpTmp
182 << "tailSlopeUnit=" << tailSlopeUnitTmp
183 << "cmKValue=" << cmKValue
184 << "charge=" << mChargePad
185 << "prevDig=" << prevDigInfTmp
186 << "dig=" << prevDigit
187 << "\n";
188 }
189
190 mChargePad = modCharge;
191
192 // TODO: propagate labels for ion tail?
193}
194
196{
197 mChargePad = 0;
198}
199
200inline bool DigitGlobalPad::compareMClabels(const MCCompLabel& label1, const MCCompLabel& label2) const
201{
202 // we compare directly on the bare label (in which eventID, labelID etc. are encoded)
203 // this avoids any logical operator on the label; optimization motivated from an Intel VTune analysis
204 // (note that this is also faster than using the operator= of MCCompLabel)
205 return label1.getRawValue() == label2.getRawValue();
206}
207
208template <DigitzationMode MODE>
209inline void DigitGlobalPad::fillOutputContainer(std::vector<Digit>& output,
211 const CRU& cru, TimeBin timeBin,
212 GlobalPadNumber globalPad,
213 o2::dataformats::LabelContainer<std::pair<MCCompLabel, int>, false>& labels,
214 SAMPAProcessing& sampaProcessing, std::vector<std::pair<MCCompLabel, int>>& labelCollector,
215 float commonMode, const PrevDigitInfo& prevDigit, Streamer* debugStream, const CalDet<bool>* deadMap)
216{
217 const Mapper& mapper = Mapper::instance();
218 const PadPos pad = mapper.padPos(globalPad);
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
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual sector
std::vector< o2::MCCompLabel > labels
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
const Sector sector() const
Definition CRU.h:65
const T getValue(const int sec, const int globalPadInSector) const
Definition CalDet.h:160
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 > &)
o2::utils::DebugStreamer Streamer
DigitGlobalPad()=default
Constructor.
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, SAMPAProcessing &sampaProcessing, std::vector< std::pair< MCCompLabel, int > > &labelCollector, float commonMode=0.f, const PrevDigitInfo &prevDigit=PrevDigitInfo(), Streamer *debugStream=nullptr, const CalDet< bool > *deadMap=nullptr)
~DigitGlobalPad()=default
Destructor.
const PadPos & padPos(GlobalPadNumber padNumber) const
Definition Mapper.h:50
static Mapper & instance(const std::string mappingDir="")
Definition Mapper.h:44
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.
unsigned short GlobalPadNumber
global pad number
Definition Defs.h:114
@ streamDigits
stream digit information
@ streamDigitFolding
stream ion tail and saturatio information
double getValue(DPVAL dp)
float cumul
cumulative signal of prev time bins
ClassDefNV(PrevDigitInfo, 1)
int tot
remaining time over threshold
float signal
pad signal
ArrayADC adc