Project
Loading...
Searching...
No Matches
FullCluster.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
14#include "CPVBase/Geometry.h"
16
17#include <fairlogger/Logger.h> // for LOG
18
19using namespace o2::cpv;
20
22
23FullCluster::FullCluster(short digitAbsId, float energy, int label)
24 : Cluster()
25{
26 addDigit(digitAbsId, energy, label);
27}
28//____________________________________________________________________________
29void FullCluster::addDigit(short digitIndex, float energy, int label)
30{
31
32 // Adds digit to the FullCluster
33 // and accumulates the total amplitude and the multiplicity, list of primaries
34 float x = 0., z = 0.;
36
37 mElementList.emplace_back(digitIndex, energy, x, z, label);
38 mEnergy += energy; // To be updated when calculate cluster properties.
39 mMulDigit++;
40}
41//____________________________________________________________________________
43{
44 // Evaluate cluster parameters
46 // evalGlobalPosition();
47}
48//____________________________________________________________________________
50{
51 // Removes digits below threshold
52
54
55 std::vector<CluElement>::iterator itEl = mElementList.begin();
56 while (itEl != mElementList.end()) {
57 if ((*itEl).energy < threshold) { // very rare case
58 itEl = mElementList.erase(itEl);
59 } else {
60 ++itEl;
61 }
62 }
63
64 mMulDigit = mElementList.size();
65
66 if (mMulDigit == 0) { // too soft cluster
67 mEnergy = 0.;
68 return;
69 }
70
71 // Remove non-connected cells
72 if (mMulDigit > 1) {
73 mEnergy = 0.; // Recalculate total energy
74 auto it = mElementList.begin();
75 while (it != mElementList.end()) {
76 bool hasNeighbours = false;
77 for (auto jt = mElementList.begin(); jt != mElementList.end(); ++jt) {
78 if (it == jt) {
79 continue;
80 }
81 if (Geometry::areNeighbours((*it).absId, (*jt).absId) == 1) {
82 hasNeighbours = true;
83 break;
84 }
85 }
86 if (!hasNeighbours) { // Isolated digits are rare
87 it = mElementList.erase(it);
88 --mMulDigit;
89 } else {
90 mEnergy += (*it).energy;
91 ++it;
92 }
93 }
94 } else {
95 mEnergy = mElementList[0].energy;
96 }
97}
98//____________________________________________________________________________
100{
101 // Calculates the center of gravity in the local CPV-module coordinates
102 // Note that correction for non-perpendicular incidence will be applied later
103 // when vertex will be known.
104
105 if (mEnergy <= 0.) { // zero energy cluster, position undefined
106 mLocalPosX = -999.;
107 mLocalPosZ = -999.;
108 return;
109 }
110
111 // find module number
112 mModule = Geometry::absIdToModule(mElementList[0].absId);
113
114 float wtot = 0.;
115 mLocalPosX = 0.;
116 mLocalPosZ = 0.;
117 float invE = 1. / mEnergy;
118 for (auto it : mElementList) {
119 float w = std::max(float(0.), o2::cpv::CPVSimParams::Instance().mLogWeight + std::log(it.energy * invE));
120 mLocalPosX += it.localX * w;
121 mLocalPosZ += it.localZ * w;
122 wtot += w;
123 }
124 if (wtot > 0) {
125 wtot = 1. / wtot;
126 mLocalPosX *= wtot;
127 mLocalPosZ *= wtot;
128 }
129}
130
131//____________________________________________________________________________
132char FullCluster::getNumberOfLocalMax(gsl::span<int> maxAt) const
133{
134 // Calculates the number of local maxima in the cluster using LocalMaxCut as the minimum
135 // energy difference between maximum and surrounding digits
136
138
139 std::unique_ptr<bool[]> isLocalMax = std::make_unique<bool[]>(mMulDigit);
140
141 for (int i = 0; i < mMulDigit; i++) {
142 if (mElementList[i].energy > o2::cpv::CPVSimParams::Instance().mClusteringThreshold) {
143 isLocalMax[i] = true;
144 } else {
145 isLocalMax[i] = false;
146 }
147 }
148 for (int i = mMulDigit; i--;) {
149
150 for (int j = i; j--;) {
151
152 if (Geometry::areNeighbours(mElementList[i].absId, mElementList[j].absId) == 1) {
153 if (mElementList[i].energy > mElementList[j].energy) {
154 isLocalMax[j] = false;
155 // but may be digit too is not local max ?
156 if (mElementList[j].energy > mElementList[i].energy - locMaxCut) {
157 isLocalMax[i] = false;
158 }
159 } else {
160 isLocalMax[i] = false;
161 // but may be digitN is not local max too?
162 if (mElementList[i].energy > mElementList[j].energy - locMaxCut) {
163 isLocalMax[j] = false;
164 }
165 }
166 } // if areneighbours
167 } // digit j
168 } // digit i
169
170 unsigned int iDigitN = 0;
171 for (int i = mMulDigit; i--;) {
172 if (isLocalMax[i]) {
173 maxAt[iDigitN] = i;
174 iDigitN++;
175 if (iDigitN >= maxAt.size()) { // Note that size of output arrays is limited:
176 static int nAlarms = 0;
177 if (nAlarms++ < 5) {
178 LOG(warning) << "Too many local maxima, cluster multiplicity " << mMulDigit;
179 }
180 return 0;
181 }
182 }
183 }
184
185 return iDigitN;
186}
ClassImp(FullCluster)
int32_t i
uint32_t j
Definition RawData.h:0
Contains CPV cluster parameters.
Definition Cluster.h:33
unsigned char mMulDigit
Digit nultiplicity.
Definition Cluster.h:112
float mLocalPosX
Center of gravity position in local module coordunates (phi direction)
Definition Cluster.h:115
char mModule
Module number.
Definition Cluster.h:113
float mEnergy
full energy of a cluster
Definition Cluster.h:117
float mLocalPosZ
Center of gravity position in local module coordunates (z direction)
Definition Cluster.h:116
CPV cluster implementation.
Definition FullCluster.h:28
char getNumberOfLocalMax(gsl::span< int > maxAt) const
void addDigit(short digitAbsId, float energy, int label)
Method to add digit to a cluster.
static short absIdToModule(unsigned short absId)
Definition Geometry.cxx:43
static short areNeighbours(unsigned short absId1, unsigned short absId2)
Definition Geometry.cxx:49
static void absIdToRelPosInModule(unsigned short absId, float &x, float &z)
Definition Geometry.cxx:89
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
float mLocalMaximumCut
Threshold to separate local maxima.
float mDigitMinEnergy
Minimal amplitude of a digit to be used in cluster.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"