Project
Loading...
Searching...
No Matches
Digitizer.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
17
18#include <TRandom.h>
19#include <fairlogger/Logger.h> // for LOG
20
22
23using o2::cpv::Digit;
24using o2::cpv::Hit;
25
26using namespace o2::cpv;
27
28//_______________________________________________________________________
30{
31 if (!mPedestals || !mBadMap || !mGains) {
32 LOG(fatal) << "Digitizer::init() : ccdb objects were not setted yet!";
33 return;
34 }
35 // signal thresolds for digits
36 // note that digits are calibrated objects
37 for (int i = 0; i < NCHANNELS; i++) {
38 mDigitThresholds[i] = o2::cpv::CPVSimParams::Instance().mZSnSigmas *
39 mPedestals->getPedSigma(i) * mGains->getGain(i);
40 }
41}
42
43//_______________________________________________________________________
45
46//_______________________________________________________________________
47void Digitizer::processHits(const std::vector<Hit>* hits, const std::vector<Digit>& digitsBg,
48 std::vector<Digit>& digitsOut, o2::dataformats::MCTruthContainer<o2::MCCompLabel>& labels,
49 int collId, int source, double dt)
50{
51 // Convert list of hits to digits:
52 // Add hits with ampl deposition in same pad and same time
53 // Add ampl corrections
54 // Apply time smearing
55 // Despite sorting in Detector::EndEvent(), hits still can be unsorted due to splitting of processing different bunches of primary
56 for (int i = NCHANNELS; i--;) {
57 mArrayD[i].reset();
58 }
59
60 // First, add pedestal noise and BG digits
61 if (digitsBg.size() == 0) { // no digits provided: try simulate pedestal noise (do it only once)
62 for (int i = NCHANNELS; i--;) {
63 float amplitude = simulatePedestalNoise(i);
64 if (amplitude > mDigitThresholds[i]) { // add noise digit if its signal > threshold
65 mArrayD[i].setAmplitude(simulatePedestalNoise(i));
66 mArrayD[i].setAbsId(i);
67 // mArrayD[i].setLabel(-1); // noise marking (not needed to set as all mArrayD[i] elements are just resetted)
68 }
69 }
70 } else { // if digits exist, noise is already added
71 for (auto& dBg : digitsBg) { // digits are sorted and unique
72 mArrayD[dBg.getAbsId()] = dBg;
73 }
74 }
75
76 // Second, add Hits
77 for (auto& h : *hits) {
78 int i = h.GetDetectorID();
79 if (mArrayD[i].getAmplitude() > 0) {
80 mArrayD[i].setAmplitude(mArrayD[i].getAmplitude() + h.GetEnergyLoss()); // if amplitude > 0 then pedestal noise is already added
81 } else {
82 mArrayD[i].setAbsId(i);
83 mArrayD[i].setAmplitude(h.GetEnergyLoss() + simulatePedestalNoise(i)); // if not then add pedestal noise to signal
84 }
85 if (mArrayD[i].getAmplitude() > mDigitThresholds[i]) {
86 int labelIndex = mArrayD[i].getLabel();
87 if (labelIndex == -1) { // noise
88 labelIndex = labels.getIndexedSize();
89 o2::MCCompLabel label(true); // noise label
90 labels.addElement(labelIndex, label);
91 mArrayD[i].setLabel(labelIndex);
92 } else { // check if lable already exist
93 gsl::span<MCCompLabel> sp = labels.getLabels(labelIndex);
94 bool found = false;
95 for (MCCompLabel& te : sp) {
96 if (te.getTrackID() == h.GetTrackID() && te.getEventID() == collId && te.getSourceID() == source) {
97 found = true;
98 break;
99 }
100 }
101 if (!found) {
102 o2::MCCompLabel label(h.GetTrackID(), collId, source);
103 // Highly inefficient management of Labels: commenting line below reeduces WHOLE digitization time by factor ~30
104 labels.addElementRandomAccess(labelIndex, label);
105 }
106 }
107 }
108 }
109
110 // finalize output digits
111 for (int i = 0; i < NCHANNELS; i++) {
112 if (!mBadMap->isChannelGood(i)) {
113 continue; // bad channel -> skip this digit
114 }
115 if (mArrayD[i].getAmplitude() > mDigitThresholds[i]) {
116 digitsOut.push_back(mArrayD[i]);
117 }
118 }
119}
120
122{
123 // this function is to simulate pedestal and its noise (ADC counts)
124 if (absId < 0 || absId >= NCHANNELS) {
125 return 0.;
126 }
127 return gRandom->Gaus(0, mPedestals->getPedSigma(absId) * mGains->getGain(absId));
128}
ClassImp(o2::cpv::Digitizer)
int32_t i
Class for time synchronization of RawReader instances.
bool isChannelGood(unsigned short channelID) const
Get the status of a certain cell.
float getGain(unsigned short cellID) const
Get High Gain energy calibration coefficients.
Definition CalibParams.h:49
float simulatePedestalNoise(int absId)
void processHits(const std::vector< Hit > *mHits, const std::vector< Digit > &digitsBg, std::vector< Digit > &digitsOut, o2::dataformats::MCTruthContainer< o2::MCCompLabel > &mLabels, int source, int entry, double dt)
Steer conversion of hits to digits.
Definition Digitizer.cxx:47
CPV simulation hit information.
Definition Hit.h:25
float getPedSigma(short cellID) const
Definition Pedestals.h:50
A container to hold and manage MC truth information/labels.
gsl::span< TruthElement > getLabels(uint32_t dataindex)
void addElement(uint32_t dataindex, TruthElement const &element, bool noElement=false)
void addElementRandomAccess(uint32_t dataindex, TruthElement const &element)
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
float mZSnSigmas
Zero Suppression threshold.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"