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#include <array>
14#include <vector>
15#include <optional>
16#include <utility>
17#include <gsl/span>
18#include "Rtypes.h"
19#include "fmt/format.h"
26#include "EMCALBase/Geometry.h"
27#include "MathUtils/Cartesian.h"
28
29namespace o2
30{
31
32namespace 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()
57 {
58 mErrorMessage = fmt::format("Cluster out of range: %d, max %d", mClusterID, mMaxClusters);
59 }
60
62 ~ClusterRangeException() noexcept final = default;
63
66 const char* what() const noexcept final { return mErrorMessage.data(); }
67
70 int getClusterID() const { return mClusterID; }
71
74 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()
92 {
93 mErrorMessage = Form("Cell Index out of range: %d, max %d", mCellIndex, mMaxCellIndex);
94 }
95
97 ~CellIndexRangeException() noexcept final = default;
98
101 const char* what() const noexcept final { return mErrorMessage.data(); }
102
105 int getCellIndex() const { return mCellIndex; }
106
109 int getMaxNumberOfCellIndexs() const { return mMaxCellIndex; }
110
111 private:
112 int mCellIndex = 0;
113 int mMaxCellIndex = 0;
114 std::string mErrorMessage;
115 };
116
119 class GeometryNotSetException final : public std::exception
120 {
121 public:
125 ~GeometryNotSetException() noexcept final = default;
126
129 const char* what() const noexcept final { return "Geometry not set"; }
130 };
131
133 {
134 public:
139 ClusterIterator(const ClusterFactory& factory, int clusterIndex, bool forward);
140
142 ~ClusterIterator() = default;
143
149 bool operator==(const ClusterIterator& rhs) const;
150
156 bool operator!=(const ClusterIterator& rhs) const { return !(*this == rhs); }
157
161
165
169
173
176 AnalysisCluster* operator*() { return &mCurrentCluster; }
177
180 AnalysisCluster& operator&() { return mCurrentCluster; }
181
184 int current_index() const { return mClusterID; }
185
186 private:
187 const ClusterFactory& mClusterFactory;
188 AnalysisCluster mCurrentCluster;
189 int mClusterID = 0;
190 bool mForward = true;
191 };
192
195 ClusterFactory() = default;
196
202 ClusterFactory(gsl::span<const o2::emcal::Cluster> clustersContainer, gsl::span<const InputType> inputsContainer, gsl::span<const int> cellsIndices);
203
206 ClusterFactory(const ClusterFactory& rp) = default;
207
211
214 ~ClusterFactory() = default;
215
218 ClusterIterator begin() const { return ClusterIterator(*this, 0, true); }
219
222 ClusterIterator end() const { return ClusterIterator(*this, getNumberOfClusters(), true); }
223
226 ClusterIterator rbegin() const { return ClusterIterator(*this, getNumberOfClusters() - 1, false); };
227
230 ClusterIterator rend() const { return ClusterIterator(*this, -1, false); };
231
233 void reset();
234
237 AnalysisCluster buildCluster(int index, o2::emcal::ClusterLabel* clusterLabel = nullptr) const;
238
239 void SetECALogWeight(Float_t w) { mLogWeight = w; }
240 float GetECALogWeight() const { return mLogWeight; }
241
242 void doEvalLocal2tracking(bool justCluster)
243 {
244 mJustCluster = justCluster;
245 }
246
249 void evalLocalPosition(gsl::span<const int> inputsIndices, AnalysisCluster& cluster) const;
250
253 void evalGlobalPosition(gsl::span<const int> inputsIndices, AnalysisCluster& cluster) const;
254
256
259 void evalLocalPositionFit(Double_t deff, Double_t w0, Double_t phiSlope, gsl::span<const int> inputsIndices, AnalysisCluster& cluster) const;
260
266 static void getDeffW0(const Double_t esum, Double_t& deff, Double_t& w0);
267
275 std::tuple<int, float, float, bool> getMaximalEnergyIndex(gsl::span<const int> inputsIndices) const;
276
282 bool isExoticCell(short towerId, float ecell, float const exoticTime) const;
283
289 float getECross(short absID, float energy, float const exoticTime) const;
290
294 float GetCellWeight(float eCell, float eCluster) const;
295
298 int getMultiplicityAtLevel(float level, gsl::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
299
300 int getSuperModuleNumber() const { return mSuperModuleNumber; }
301
302 // searches for the local maxima
303 // energy above relative level
304 // int getNumberOfLocalMax(int nInputMult,
305 // float locMaxCut, gsl::span<InputType> inputs) const;
306
307 // int getNumberOfLocalMax(std::vector<InputType>& maxAt, std::vector<float>& maxAtEnergy,
308 // float locMaxCut, gsl::span<InputType> inputs) const;
309
310 bool sharedCluster() const { return mSharedCluster; }
311 void setSharedCluster(bool s) { mSharedCluster = s; }
312
316 Double_t tMaxInCm(const Double_t e = 0.0, const int key = 0) const;
317
318 bool getLookUpInit() const { return mLookUpInit; }
319
320 bool getCoreRadius() const { return mCoreRadius; }
321 void setCoreRadius(float radius) { mCoreRadius = radius; }
322
323 float getExoticCellFraction() const { return mExoticCellFraction; }
324 void setExoticCellFraction(float exoticCellFraction) { mExoticCellFraction = exoticCellFraction; }
325
326 float getExoticCellDiffTime() const { return mExoticCellDiffTime; }
327 void setExoticCellDiffTime(float exoticCellDiffTime) { mExoticCellDiffTime = exoticCellDiffTime; }
328
329 float getExoticCellMinAmplitude() const { return mExoticCellMinAmplitude; }
330 void setExoticCellMinAmplitude(float exoticCellMinAmplitude) { mExoticCellMinAmplitude = exoticCellMinAmplitude; }
331
332 float getExoticCellInCrossMinAmplitude() const { return mExoticCellInCrossMinAmplitude; }
333 void setExoticCellInCrossMinAmplitude(float exoticCellInCrossMinAmplitude) { mExoticCellInCrossMinAmplitude = exoticCellInCrossMinAmplitude; }
334
335 bool getUseWeightExotic() const { return mUseWeightExotic; }
336 void setUseWeightExotic(float useWeightExotic) { mUseWeightExotic = useWeightExotic; }
337
338 void setContainer(gsl::span<const o2::emcal::Cluster> clusterContainer, gsl::span<const InputType> cellContainer, gsl::span<const int> indicesContainer, std::optional<gsl::span<const o2::emcal::CellLabel>> cellLabelContainer = std::nullopt)
339 {
340 mClustersContainer = clusterContainer;
341 mInputsContainer = cellContainer;
342 mCellsIndices = indicesContainer;
343 if (!getLookUpInit()) {
345 }
346 if (cellLabelContainer) {
347 mCellLabelContainer = cellLabelContainer.value();
348 }
349 }
350
351 void setLookUpTable(void)
352 {
353 mLoolUpTowerToIndex.fill(-1);
354 for (auto iCellIndex : mCellsIndices) {
355 mLoolUpTowerToIndex[mInputsContainer[iCellIndex].getTower()] = iCellIndex;
356 }
357 mLookUpInit = true;
358 }
359
361 {
362 return mClustersContainer.size();
363 }
364
367 void setGeometry(o2::emcal::Geometry* geometry) { mGeomPtr = geometry; }
368
371 class UninitLookUpTableException final : public std::exception
372 {
373 public:
376
378 ~UninitLookUpTableException() noexcept final = default;
379
381 const char* what() const noexcept final { return "Lookup table not initialized, exotics evaluation not possible!"; }
382 };
383
384 protected:
392 void evalCoreEnergy(gsl::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
393
397 void evalDispersion(gsl::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
398
402 void evalElipsAxis(gsl::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
403
406 void evalTime(gsl::span<const int> inputsIndices, AnalysisCluster& clusterAnalysis) const;
407
410 float thetaToEta(float arg) const;
411
414 float etaToTheta(float arg) const;
415
416 private:
417 o2::emcal::Geometry* mGeomPtr = nullptr;
418
419 float mCoreRadius = 10;
420
421 float mLogWeight = 4.5;
422
423 bool mJustCluster = kFALSE;
424 bool mLookUpInit = false;
425
426 mutable int mSuperModuleNumber = 0;
427 float mDistToBadTower = -1;
428 bool mSharedCluster = false;
429 float mExoticCellFraction = 0.97;
430 float mExoticCellDiffTime = 1e6;
431 float mExoticCellMinAmplitude = 4.;
432 float mExoticCellInCrossMinAmplitude = 0.1;
433 bool mUseWeightExotic = false;
434
435 gsl::span<const o2::emcal::Cluster> mClustersContainer;
436 gsl::span<const InputType> mInputsContainer;
437 gsl::span<const int> mCellsIndices;
438 std::array<short, 17664> mLoolUpTowerToIndex;
439 gsl::span<const o2::emcal::CellLabel> mCellLabelContainer;
440
441 ClassDefNV(ClusterFactory, 2);
442};
443
444} // namespace emcal
445} // namespace o2
446#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.
std::tuple< int, float, float, bool > getMaximalEnergyIndex(gsl::span< const int > inputsIndices) const
Finds the maximum energy in the cluster and computes the Summed amplitude of digits/cells.
float GetCellWeight(float eCell, float eCluster) const
return weight of cell for shower shape calculation
void setContainer(gsl::span< const o2::emcal::Cluster > clusterContainer, gsl::span< const InputType > cellContainer, gsl::span< const int > indicesContainer, std::optional< gsl::span< const o2::emcal::CellLabel > > cellLabelContainer=std::nullopt)
~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)
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.
void evalGlobalPosition(gsl::span< const int > inputsIndices, AnalysisCluster &cluster) const
Calculates the center of gravity in the global ALICE coordinates.
bool isExoticCell(short towerId, float ecell, float const exoticTime) const
Look to cell neighbourhood and reject if it seems exotic.
void evalLocalPosition(gsl::span< const int > inputsIndices, AnalysisCluster &cluster) const
Calculates the center of gravity in the local EMCAL-module coordinates.
Double_t tMaxInCm(const Double_t e=0.0, const int key=0) const
void setExoticCellFraction(float exoticCellFraction)
void setUseWeightExotic(float useWeightExotic)
static void getDeffW0(const Double_t esum, Double_t &deff, Double_t &w0)
void evalTime(gsl::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
Time is set to the time of the digit with the maximum energy.
int getMultiplicityAtLevel(float level, gsl::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
Calculates the multiplicity of digits/cells with energy larger than level*energy.
ClusterFactory()=default
Dummy constructor.
void evalLocalPositionFit(Double_t deff, Double_t w0, Double_t phiSlope, gsl::span< const int > inputsIndices, AnalysisCluster &cluster) const
evaluates local position of clusters in SM
void evalElipsAxis(gsl::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
ClusterIterator end() const
Get forward end iteration marker.
void evalCoreEnergy(gsl::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
void setExoticCellInCrossMinAmplitude(float exoticCellInCrossMinAmplitude)
void setExoticCellMinAmplitude(float exoticCellMinAmplitude)
ClusterFactory & operator=(const ClusterFactory &cf)=default
Assignment operator.
void evalDispersion(gsl::span< const int > inputsIndices, AnalysisCluster &clusterAnalysis) const
ClusterIterator begin() const
Get forward start iterator.
float etaToTheta(float arg) const
Converts Eta (Radians) to Theta (Radians)
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 setExoticCellDiffTime(float exoticCellDiffTime)
cluster class for MC particle IDs and their respective energy fraction
EMCAL geometry definition.
Definition Geometry.h:40
GLuint index
Definition glcorearb.h:781
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.