Project
Loading...
Searching...
No Matches
ClusterFactory.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#ifndef DETECTORS_EMCAL_BASE_INCLUDE_EMCALBASE_CLUSTERFACTORY_H_
12#define DETECTORS_EMCAL_BASE_INCLUDE_EMCALBASE_CLUSTERFACTORY_H_
13
14#include "EMCALBase/Geometry.h"
16#include "DataFormatsEMCAL/Cell.h" // IWYU pragma: keep
20#include "DataFormatsEMCAL/Digit.h" // IWYU pragma: keep
21// #include "MathUtils/Cartesian.h"
22
23#include <Rtypes.h>
24
25#include <fmt/format.h>
26
27#include <array>
28#include <span>
29#include <string>
30#include <tuple>
31#include <vector>
32
33namespace o2::emcal
34{
35
43template <class InputType>
45{
46
47 public:
48 class ClusterRangeException final : public std::exception
49 {
50 public:
54 ClusterRangeException(int clusterIndex, int maxClusters) : std::exception(),
55 mClusterID(clusterIndex),
56 mMaxClusters(maxClusters),
57 mErrorMessage(fmt::format("Cluster out of range: %d, max %d", mClusterID, mMaxClusters))
58 {
59 }
60
62 ~ClusterRangeException() noexcept final = default;
63
66 [[nodiscard]] const char* what() const noexcept final { return mErrorMessage.data(); }
67
70 [[nodiscard]] int getClusterID() const { return mClusterID; }
71
74 [[nodiscard]] int getMaxNumberOfClusters() const { return mMaxClusters; }
75
76 private:
77 int mClusterID = 0;
78 int mMaxClusters = 0;
79 std::string mErrorMessage;
80 };
81
82 class CellIndexRangeException final : public std::exception
83 {
84 public:
88 CellIndexRangeException(int cellIndex, int maxCellIndex) : std::exception(),
89 mCellIndex(cellIndex),
90 mMaxCellIndex(maxCellIndex),
91 mErrorMessage(fmt::format("Cell Index out of range: %d, max %d", mCellIndex, mMaxCellIndex))
92 {
93 }
94
96 ~CellIndexRangeException() noexcept final = default;
97
100 [[nodiscard]] const char* what() const noexcept final { return mErrorMessage.data(); }
101
104 [[nodiscard]] int getCellIndex() const { return mCellIndex; }
105
108 [[nodiscard]] int getMaxNumberOfCellIndexs() const { return mMaxCellIndex; }
109
110 private:
111 int mCellIndex = 0;
112 int mMaxCellIndex = 0;
113 std::string mErrorMessage;
114 };
115
118 class GeometryNotSetException final : public std::exception
119 {
120 public:
124 ~GeometryNotSetException() noexcept final = default;
125
128 [[nodiscard]] const char* what() const noexcept final { return "Geometry not set"; }
129 };
130
132 {
133 public:
138 ClusterIterator(const ClusterFactory& factory, int clusterIndex, bool forward);
139
141 ~ClusterIterator() = default;
142
148 bool operator==(const ClusterIterator& rhs) const;
149
155 bool operator!=(const ClusterIterator& rhs) const { return !(*this == rhs); }
156
160
164
168
172
175 AnalysisCluster* operator*() { return &mCurrentCluster; }
176
179 [[nodiscard]] int current_index() const { return mClusterID; }
180
181 private:
182 const ClusterFactory* mClusterFactory;
183 AnalysisCluster mCurrentCluster;
184 int mClusterID = 0;
185 bool mForward = true;
186 };
187
190 ClusterFactory() = default;
191
197 ClusterFactory(std::span<const o2::emcal::Cluster> clustersContainer, std::span<const InputType> inputsContainer, std::span<const int> cellsIndices);
198
201 ClusterFactory(const ClusterFactory& rp) = default;
202
206
209 ~ClusterFactory() = default;
210
213 ClusterIterator begin() const { return ClusterIterator(*this, 0, true); }
214
217 ClusterIterator end() const { return ClusterIterator(*this, getNumberOfClusters(), true); }
218
221 ClusterIterator rbegin() const { return ClusterIterator(*this, getNumberOfClusters() - 1, false); }
222
225 ClusterIterator rend() const { return ClusterIterator(*this, -1, false); }
226
228 void reset();
229
232 AnalysisCluster buildCluster(int index, o2::emcal::ClusterLabel* clusterLabel = nullptr) const;
233
234 void SetECALogWeight(Float_t w) { mLogWeight = w; }
235 float GetECALogWeight() const { return mLogWeight; }
236
237 void doEvalLocal2tracking(bool justCluster)
238 {
239 mJustCluster = justCluster;
240 }
241
244 void evalLocalPosition(std::span<const int> inputsIndices, AnalysisCluster& cluster) const;
245
248 void evalGlobalPosition(std::span<const int> inputsIndices, AnalysisCluster& cluster) const;
249
251
254 void evalLocalPositionFit(double deff, double mLogWeight, double phiSlope, std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
255
261 static void getDeffW0(const Double_t esum, Double_t& deff, Double_t& w0);
262
270 std::tuple<int, float, float, bool> getMaximalEnergyIndex(std::span<const int> inputsIndices) const;
271
278 bool isExoticCell(int16_t towerId, float ecell, float const exoticTime, float& fCross) const;
279
285 float getECross(int16_t absID, float energy, float const exoticTime) const;
286
290 float GetCellWeight(float eCell, float eCluster) const;
291
294 int getMultiplicityAtLevel(float level, std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
295
296 int getSuperModuleNumber() const { return mSuperModuleNumber; }
297
298 // searches for the local maxima
299 // energy above relative level
300 // int getNumberOfLocalMax(int nInputMult,
301 // float locMaxCut, std::span<InputType> inputs) const;
302
303 // int getNumberOfLocalMax(std::vector<InputType>& maxAt, std::vector<float>& maxAtEnergy,
304 // float locMaxCut, std::span<InputType> inputs) const;
305
306 bool sharedCluster() const { return mSharedCluster; }
307 void setSharedCluster(bool s) { mSharedCluster = s; }
308
312 Double_t tMaxInCm(const Double_t e = 0.0, const int key = 0) const;
313
314 bool getLookUpInit() const { return mLookUpInit; }
315
316 float getCoreRadius() const { return mCoreRadius; }
317 void setCoreRadius(float radius) { mCoreRadius = radius; }
318
319 float getExoticCellFraction() const { return mExoticCellFraction; }
320 void setExoticCellFraction(float exoticCellFraction) { mExoticCellFraction = exoticCellFraction; }
321
322 float getExoticCellDiffTime() const { return mExoticCellDiffTime; }
323 void setExoticCellDiffTime(float exoticCellDiffTime) { mExoticCellDiffTime = exoticCellDiffTime; }
324
325 float getExoticCellMinAmplitude() const { return mExoticCellMinAmplitude; }
326 void setExoticCellMinAmplitude(float exoticCellMinAmplitude) { mExoticCellMinAmplitude = exoticCellMinAmplitude; }
327
328 float getExoticCellInCrossMinAmplitude() const { return mExoticCellInCrossMinAmplitude; }
329 void setExoticCellInCrossMinAmplitude(float exoticCellInCrossMinAmplitude) { mExoticCellInCrossMinAmplitude = exoticCellInCrossMinAmplitude; }
330
331 bool getUseWeightExotic() const { return mUseWeightExotic; }
332 void setUseWeightExotic(bool useWeightExotic) { mUseWeightExotic = useWeightExotic; }
333
334 void setContainer(std::span<const o2::emcal::Cluster> clusterContainer, std::span<const InputType> cellContainer, std::span<const int> indicesContainer, std::span<const o2::emcal::CellLabel> cellLabelContainer = {})
335 {
336 mClustersContainer = clusterContainer;
337 mInputsContainer = cellContainer;
338 mCellsIndices = indicesContainer;
339 if (!getLookUpInit()) {
341 }
342 if (!cellLabelContainer.empty()) {
343 mCellLabelContainer = cellLabelContainer;
344 }
345 }
346
348 {
349 mLoolUpTowerToIndex.fill(-1);
350 for (auto iCellIndex : mCellsIndices) {
351 mLoolUpTowerToIndex[mInputsContainer[iCellIndex].getTower()] = iCellIndex;
352 }
353 mLookUpInit = true;
354 }
355
357 {
358 return mClustersContainer.size();
359 }
360
363 void setGeometry(o2::emcal::Geometry* geometry) { mGeomPtr = geometry; }
364
367 class UninitLookUpTableException final : public std::exception
368 {
369 public:
372
374 ~UninitLookUpTableException() noexcept final = default;
375
377 [[nodiscard]] const char* what() const noexcept final { return "Lookup table not initialized, exotics evaluation not possible!"; }
378 };
379
380 protected:
388 void evalCoreEnergy(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
389
393 void evalDispersion(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
394
398 void evalElipsAxis(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
399
402 void evalNExMax(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
403
406 void evalTime(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
407
411 float thetaToEta(float theta) const;
412
416 float etaToTheta(float eta) const;
417
418 private:
419 struct CellGeomInfo {
420 int8_t nSupMod;
421 int8_t iphi;
422 int8_t ieta;
423 int8_t ietaShared;
424 int16_t row;
425 int16_t col;
426 };
427
428 o2::emcal::Geometry* mGeomPtr = nullptr;
429
430 float mCoreRadius = 10;
431
432 float mLogWeight = 4.5;
433
434 bool mJustCluster = kFALSE;
435 bool mLookUpInit = false;
436
437 mutable int mSuperModuleNumber = 0;
438 float mDistToBadTower = -1;
439 mutable bool mSharedCluster = false;
440 float mExoticCellFraction = 0.97;
441 float mExoticCellDiffTime = 1e6;
442 float mExoticCellMinAmplitude = 4.;
443 float mExoticCellInCrossMinAmplitude = 0.1;
444 bool mUseWeightExotic = false;
445
446 mutable std::vector<CellGeomInfo> mCellGeomBuffer;
447 std::span<const o2::emcal::Cluster> mClustersContainer;
448 std::span<const InputType> mInputsContainer;
449 std::span<const int> mCellsIndices;
450 std::array<int16_t, 17664> mLoolUpTowerToIndex{};
451 std::span<const o2::emcal::CellLabel> mCellLabelContainer;
452
453 ClassDefNV(ClusterFactory, 3);
454};
455
456} // namespace o2::emcal
457#endif // DETECTORS_EMCAL_BASE_INCLUDE_EMCALBASE_CLUSTERFACTORY_H_
uint32_t col
Definition RawData.h:4
StringRef key
Cluster class for kinematic cluster parametersported from AliVCluster in AliRoot.
int getMaxNumberOfCellIndexs() const
Get the maximum number of cell indices handled by the cluster factory.
CellIndexRangeException(int cellIndex, int maxCellIndex)
Constructor defining the error.
~CellIndexRangeException() noexcept final=default
Destructor.
const char * what() const noexcept final
Provide error message.
int getCellIndex() const
Get the index of the cell raising the exception.
ClusterIterator & operator--()
Prefix decrementation operator.
AnalysisCluster * operator*()
Get pointer to the current cluster.
bool operator!=(const ClusterIterator &rhs) const
Check for not equalness.
int current_index() const
Get the index of the current event.
bool operator==(const ClusterIterator &rhs) const
Check for equalness.
ClusterIterator & operator++()
Prefix incrementation operator.
const char * what() const noexcept final
Provide error message.
int getMaxNumberOfClusters() const
Get the maximum number of events handled by the event handler.
~ClusterRangeException() noexcept final=default
Destructor.
int getClusterID() const
Get the ID of the event raising the exception.
ClusterRangeException(int clusterIndex, int maxClusters)
Constructor defining the error.
const char * what() const noexcept final
Provide error message.
~GeometryNotSetException() noexcept final=default
Destructor.
Exception handling uninitialized look up table.
const char * what() const noexcept final
Access to error message of the exception.
~UninitLookUpTableException() noexcept final=default
Destructor.
EMCal clusters factory Ported from class AliEMCALcluster.
ClusterIterator rend() const
Get backward end iteration marker.
ClusterIterator rbegin() const
Get backward start iterator.
void reset()
Reset containers.
float GetCellWeight(float eCell, float eCluster) const
return weight of cell for shower shape calculation
~ClusterFactory()=default
Destructor.
ClusterFactory(const ClusterFactory &rp)=default
Copy constructor.
float etaToTheta(float eta) const
Converts Eta (Radians) to Theta (Radians)
void doEvalLocal2tracking(bool justCluster)
void evalGlobalPosition(std::span< const int > inputsIndices, AnalysisCluster &cluster) const
Calculates the center of gravity in the global ALICE coordinates.
bool isExoticCell(int16_t towerId, float ecell, float const exoticTime, float &fCross) const
Look to cell neighbourhood and reject if it seems exotic.
std::tuple< int, float, float, bool > getMaximalEnergyIndex(std::span< const int > inputsIndices) const
Finds the maximum energy in the cluster and computes the Summed amplitude of digits/cells.
float getExoticCellDiffTime() const
void setGeometry(o2::emcal::Geometry *geometry)
Initialize Cluster Factory with geometry.
float getECross(int16_t absID, float energy, float const exoticTime) const
Calculate the energy in the cross around the energy of a given cell.
int getMultiplicityAtLevel(float level, std::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
Calculates the multiplicity of digits/cells with energy larger than level*energy.
Double_t tMaxInCm(const Double_t e=0.0, const int key=0) const
void evalTime(std::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
Time is set to the time of the digit with the maximum energy.
void setExoticCellFraction(float exoticCellFraction)
void evalLocalPosition(std::span< const int > inputsIndices, AnalysisCluster &cluster) const
Calculates the center of gravity in the local EMCAL-module coordinates.
static void getDeffW0(const Double_t esum, Double_t &deff, Double_t &w0)
ClusterFactory()=default
Dummy constructor.
void setContainer(std::span< const o2::emcal::Cluster > clusterContainer, std::span< const InputType > cellContainer, std::span< const int > indicesContainer, std::span< const o2::emcal::CellLabel > cellLabelContainer={})
ClusterIterator end() const
Get forward end iteration marker.
void setExoticCellInCrossMinAmplitude(float exoticCellInCrossMinAmplitude)
void evalLocalPositionFit(double deff, double mLogWeight, double phiSlope, std::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
evaluates local position of clusters in SM
void setExoticCellMinAmplitude(float exoticCellMinAmplitude)
void evalCoreEnergy(std::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
ClusterFactory & operator=(const ClusterFactory &cf)=default
Assignment operator.
void evalDispersion(std::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
Calculates the dispersion of the shower at the origin of the cluster in cell units.
void setUseWeightExotic(bool useWeightExotic)
ClusterIterator begin() const
Get forward start iterator.
void evalElipsAxis(std::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
Calculates the axis of the shower ellipsoid in eta and phi in cell units.
void setCoreRadius(float radius)
float getExoticCellInCrossMinAmplitude() const
float getExoticCellMinAmplitude() const
void evalLocal2TrackingCSTransform() const
float thetaToEta(float theta) const
Converts Theta (Radians) to Eta (Radians)
float getExoticCellFraction() const
void SetECALogWeight(Float_t w)
AnalysisCluster buildCluster(int index, o2::emcal::ClusterLabel *clusterLabel=nullptr) const
evaluates cluster parameters: position, shower shape, primaries ...
void evalNExMax(std::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
Calculate the number of local maxima in the cluster.
void setExoticCellDiffTime(float exoticCellDiffTime)
cluster class for MC particle IDs and their respective energy fraction
EMCAL geometry definition.
Definition Geometry.h:42
GLuint index
Definition glcorearb.h:781
GLint level
Definition glcorearb.h:275
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
GLint GLint GLsizei GLint GLenum format
Definition glcorearb.h:275
std::vector< int > row