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
16
17#include <cstdio>
18#include <TRandom.h>
19#include <fairlogger/Logger.h>
20
22#include <ECalBase/Hit.h>
23#include <ECalBase/Geometry.h>
25
26using namespace o2::ecal;
27
28//==============================================================================
30{
31 auto& geo = Geometry::instance();
32 mArrayD.resize(geo.getNrows() * geo.getNcols());
33}
34
35//==============================================================================
36void Digitizer::processHits(const std::vector<Hit>* hits, std::vector<Digit>& digits, o2::dataformats::MCTruthContainer<MCLabel>& labels, int collId)
37{
38 digits.clear();
39 labels.clear();
40
41 LOGP(debug, "nHits = {}", hits->size());
42 auto& geo = Geometry::instance();
43
44 for (int i = 0; i < mArrayD.size(); i++) {
45 mArrayD[i].setAmplitude(0);
46 mArrayD[i].setTimeStamp(1000);
47 mArrayD[i].setTower(i);
48 mArrayD[i].setLabel(-1);
49 // TODO: simulate noise
50 }
51
52 for (auto& hit : *hits) {
53 int cellID = hit.GetCellID();
54 double eloss = hit.GetEnergyLoss();
55 double t = hit.GetTime();
56 double elossSmeared = eloss;
57 bool isCrystal = geo.isCrystal(cellID);
58 if (isCrystal) { // crystal
59 double elossSmearedNpe = gRandom->Poisson(eloss * mCrystalPePerGeV) / mCrystalPePerGeV;
60 if (mSmearCrystal) {
61 elossSmeared = elossSmearedNpe * gRandom->Gaus(1, 0.007); // light attenuation in crystals
62 }
63 } else { // sampling
64 elossSmeared *= mSamplingFraction;
65 }
66
67 Digit& digit = mArrayD[cellID];
68 digit.setAmplitude(digit.getAmplitude() + elossSmeared);
69 if (t < digit.getTimeStamp()) {
70 digit.setTimeStamp(t); // setting earliest time, TODO: add time smearing
71 }
72 LOGF(debug, " crystal: %d cellID = %5d, eloss = %8.5f elossSmeared = %8.5f time = %8.5f", isCrystal, cellID, eloss, elossSmeared, t);
73
74 // Adding MC info
75 MCLabel label(hit.GetTrackID(), collId, 0, false, hit.GetEnergyLoss());
76 int labelIndex = digit.getLabel();
77 if (labelIndex == -1) {
78 labelIndex = labels.getIndexedSize();
79 labels.addElement(labelIndex, label);
80 digit.setLabel(labelIndex);
81 } else {
82 labels.addElementRandomAccess(labelIndex, label);
83 }
84 } // hits
85
86 for (int i = 0; i < mArrayD.size(); i++) {
87 if (mArrayD[i].getAmplitude() > mThreshold) {
88 digits.push_back(mArrayD[i]);
89 }
90 }
91}
Definition of ECal digit class.
MC hit class to store energy loss per cell and per superparent.
int32_t i
Geometry helper class.
Digitization of ECal MC information.
std::ostringstream debug
A container to hold and manage MC truth information/labels.
void addElement(uint32_t dataindex, TruthElement const &element, bool noElement=false)
void addElementRandomAccess(uint32_t dataindex, TruthElement const &element)
double getAmplitude() const
Definition Digit.h:42
int getLabel() const
Definition Digit.h:44
void setAmplitude(double amplitude)
Definition Digit.h:36
void setLabel(int label)
Definition Digit.h:38
void processHits(const std::vector< Hit > *mHits, std::vector< Digit > &digits, o2::dataformats::MCTruthContainer< MCLabel > &labels, int collId)
Definition Digitizer.cxx:36
static Geometry & instance()
Definition Geometry.h:31
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
std::vector< Digit > digits