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 ALICEO2_EMCAL_CLUSTERFACTORY_H_
12#define ALICEO2_EMCAL_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 <vector>
30// #include <utility>
31
32namespace o2::emcal
33{
34
42template <class InputType>
44{
45
46 public:
47 class ClusterRangeException final : public std::exception
48 {
49 public:
53 ClusterRangeException(int clusterIndex, int maxClusters) : std::exception(),
54 mClusterID(clusterIndex),
55 mMaxClusters(maxClusters),
56 mErrorMessage(fmt::format("Cluster out of range: %d, max %d", mClusterID, mMaxClusters))
57 {
58 }
59
61 ~ClusterRangeException() noexcept final = default;
62
65 [[nodiscard]] const char* what() const noexcept final { return mErrorMessage.data(); }
66
69 [[nodiscard]] int getClusterID() const { return mClusterID; }
70
73 [[nodiscard]] int getMaxNumberOfClusters() const { return mMaxClusters; }
74
75 private:
76 int mClusterID = 0;
77 int mMaxClusters = 0;
78 std::string mErrorMessage;
79 };
80
81 class CellIndexRangeException final : public std::exception
82 {
83 public:
87 CellIndexRangeException(int cellIndex, int maxCellIndex) : std::exception(),
88 mCellIndex(cellIndex),
89 mMaxCellIndex(maxCellIndex),
90 mErrorMessage(fmt::format("Cell Index out of range: %d, max %d", mCellIndex, mMaxCellIndex))
91 {
92 }
93
95 ~CellIndexRangeException() noexcept final = default;
96
99 [[nodiscard]] const char* what() const noexcept final { return mErrorMessage.data(); }
100
103 [[nodiscard]] int getCellIndex() const { return mCellIndex; }
104
107 [[nodiscard]] int getMaxNumberOfCellIndexs() const { return mMaxCellIndex; }
108
109 private:
110 int mCellIndex = 0;
111 int mMaxCellIndex = 0;
112 std::string mErrorMessage;
113 };
114
117 class GeometryNotSetException final : public std::exception
118 {
119 public:
123 ~GeometryNotSetException() noexcept final = default;
124
127 [[nodiscard]] const char* what() const noexcept final { return "Geometry not set"; }
128 };
129
131 {
132 public:
137 ClusterIterator(const ClusterFactory& factory, int clusterIndex, bool forward);
138
140 ~ClusterIterator() = default;
141
147 bool operator==(const ClusterIterator& rhs) const;
148
154 bool operator!=(const ClusterIterator& rhs) const { return !(*this == rhs); }
155
159
163
167
171
174 AnalysisCluster* operator*() { return &mCurrentCluster; }
175
178 AnalysisCluster& operator&() { return mCurrentCluster; }
179
182 [[nodiscard]] int current_index() const { return mClusterID; }
183
184 private:
185 const ClusterFactory* mClusterFactory;
186 AnalysisCluster mCurrentCluster;
187 int mClusterID = 0;
188 bool mForward = true;
189 };
190
193 ClusterFactory() = default;
194
200 ClusterFactory(std::span<const o2::emcal::Cluster> clustersContainer, std::span<const InputType> inputsContainer, std::span<const int> cellsIndices);
201
204 ClusterFactory(const ClusterFactory& rp) = default;
205
209
212 ~ClusterFactory() = default;
213
216 ClusterIterator begin() const { return ClusterIterator(*this, 0, true); }
217
220 ClusterIterator end() const { return ClusterIterator(*this, getNumberOfClusters(), true); }
221
224 ClusterIterator rbegin() const { return ClusterIterator(*this, getNumberOfClusters() - 1, false); };
225
228 ClusterIterator rend() const { return ClusterIterator(*this, -1, false); };
229
231 void reset();
232
235 AnalysisCluster buildCluster(int index, o2::emcal::ClusterLabel* clusterLabel = nullptr) const;
236
237 void SetECALogWeight(Float_t w) { mLogWeight = w; }
238 float GetECALogWeight() const { return mLogWeight; }
239
240 void doEvalLocal2tracking(bool justCluster)
241 {
242 mJustCluster = justCluster;
243 }
244
247 void evalLocalPosition(std::span<const int> inputsIndices, AnalysisCluster& cluster) const;
248
251 void evalGlobalPosition(std::span<const int> inputsIndices, AnalysisCluster& cluster) const;
252
254
257 void evalLocalPositionFit(double deff, double mLogWeight, double phiSlope, std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
258
264 static void getDeffW0(const Double_t esum, Double_t& deff, Double_t& w0);
265
273 std::tuple<int, float, float, bool> getMaximalEnergyIndex(std::span<const int> inputsIndices) const;
274
281 bool isExoticCell(short towerId, float ecell, float const exoticTime, float& fCross) const;
282
288 float getECross(short absID, float energy, float const exoticTime) const;
289
293 float GetCellWeight(float eCell, float eCluster) const;
294
297 int getMultiplicityAtLevel(float level, std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
298
299 int getSuperModuleNumber() const { return mSuperModuleNumber; }
300
301 // searches for the local maxima
302 // energy above relative level
303 // int getNumberOfLocalMax(int nInputMult,
304 // float locMaxCut, std::span<InputType> inputs) const;
305
306 // int getNumberOfLocalMax(std::vector<InputType>& maxAt, std::vector<float>& maxAtEnergy,
307 // float locMaxCut, std::span<InputType> inputs) const;
308
309 bool sharedCluster() const { return mSharedCluster; }
310 void setSharedCluster(bool s) { mSharedCluster = s; }
311
315 Double_t tMaxInCm(const Double_t e = 0.0, const int key = 0) const;
316
317 bool getLookUpInit() const { return mLookUpInit; }
318
319 float getCoreRadius() const { return mCoreRadius; }
320 void setCoreRadius(float radius) { mCoreRadius = radius; }
321
322 float getExoticCellFraction() const { return mExoticCellFraction; }
323 void setExoticCellFraction(float exoticCellFraction) { mExoticCellFraction = exoticCellFraction; }
324
325 float getExoticCellDiffTime() const { return mExoticCellDiffTime; }
326 void setExoticCellDiffTime(float exoticCellDiffTime) { mExoticCellDiffTime = exoticCellDiffTime; }
327
328 float getExoticCellMinAmplitude() const { return mExoticCellMinAmplitude; }
329 void setExoticCellMinAmplitude(float exoticCellMinAmplitude) { mExoticCellMinAmplitude = exoticCellMinAmplitude; }
330
331 float getExoticCellInCrossMinAmplitude() const { return mExoticCellInCrossMinAmplitude; }
332 void setExoticCellInCrossMinAmplitude(float exoticCellInCrossMinAmplitude) { mExoticCellInCrossMinAmplitude = exoticCellInCrossMinAmplitude; }
333
334 bool getUseWeightExotic() const { return mUseWeightExotic; }
335 void setUseWeightExotic(bool useWeightExotic) { mUseWeightExotic = useWeightExotic; }
336
337 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 = {})
338 {
339 mClustersContainer = clusterContainer;
340 mInputsContainer = cellContainer;
341 mCellsIndices = indicesContainer;
342 if (!getLookUpInit()) {
344 }
345 if (!cellLabelContainer.empty()) {
346 mCellLabelContainer = cellLabelContainer;
347 }
348 }
349
351 {
352 mLoolUpTowerToIndex.fill(-1);
353 for (auto iCellIndex : mCellsIndices) {
354 mLoolUpTowerToIndex[mInputsContainer[iCellIndex].getTower()] = iCellIndex;
355 }
356 mLookUpInit = true;
357 }
358
360 {
361 return mClustersContainer.size();
362 }
363
366 void setGeometry(o2::emcal::Geometry* geometry) { mGeomPtr = geometry; }
367
370 class UninitLookUpTableException final : public std::exception
371 {
372 public:
375
377 ~UninitLookUpTableException() noexcept final = default;
378
380 [[nodiscard]] const char* what() const noexcept final { return "Lookup table not initialized, exotics evaluation not possible!"; }
381 };
382
383 protected:
391 void evalCoreEnergy(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
392
396 void evalDispersion(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
397
401 void evalElipsAxis(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
402
405 void evalNExMax(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
406
409 void evalTime(std::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
410
413 float thetaToEta(float arg) const;
414
417 float etaToTheta(float arg) const;
418
419 private:
420 o2::emcal::Geometry* mGeomPtr = nullptr;
421
422 float mCoreRadius = 10;
423
424 float mLogWeight = 4.5;
425
426 bool mJustCluster = kFALSE;
427 bool mLookUpInit = false;
428
429 mutable int mSuperModuleNumber = 0;
430 float mDistToBadTower = -1;
431 bool mSharedCluster = false;
432 float mExoticCellFraction = 0.97;
433 float mExoticCellDiffTime = 1e6;
434 float mExoticCellMinAmplitude = 4.;
435 float mExoticCellInCrossMinAmplitude = 0.1;
436 bool mUseWeightExotic = false;
437
438 std::span<const o2::emcal::Cluster> mClustersContainer;
439 std::span<const InputType> mInputsContainer;
440 std::span<const int> mCellsIndices;
441 std::array<short, 17664> mLoolUpTowerToIndex{};
442 std::span<const o2::emcal::CellLabel> mCellLabelContainer;
443
444 ClassDefNV(ClusterFactory, 2);
445};
446
447} // namespace o2::emcal
448#endif // ALICEO2_EMCAL_CLUSTERFACTORY_H_
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.
AnalysisCluster & operator&()
Get reference to the current cluster.
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.
float thetaToEta(float arg) const
Converts Theta (Radians) to Eta (Radians)
ClusterFactory(const ClusterFactory &rp)=default
Copy constructor.
void doEvalLocal2tracking(bool justCluster)
void evalGlobalPosition(std::span< const int > inputsIndices, AnalysisCluster &cluster) const
Calculates the center of gravity in the global ALICE coordinates.
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(short 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
void setUseWeightExotic(bool useWeightExotic)
ClusterIterator begin() const
Get forward start iterator.
float etaToTheta(float arg) const
Converts Eta (Radians) to Theta (Radians)
bool isExoticCell(short towerId, float ecell, float const exoticTime, float &fCross) const
Look to cell neighbourhood and reject if it seems exotic.
void evalElipsAxis(std::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
void setCoreRadius(float radius)
float getExoticCellInCrossMinAmplitude() const
float getExoticCellMinAmplitude() const
void evalLocal2TrackingCSTransform() const
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
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
GLint GLint GLsizei GLint GLenum format
Definition glcorearb.h:275