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 <utility>
16#include <gsl/span>
17#include "Rtypes.h"
18#include "fmt/format.h"
25#include "EMCALBase/Geometry.h"
26#include "MathUtils/Cartesian.h"
27
28namespace o2
29{
30
31namespace emcal
32{
33
41template <class InputType>
43{
44
45 public:
46 class ClusterRangeException final : public std::exception
47 {
48 public:
52 ClusterRangeException(int clusterIndex, int maxClusters) : std::exception(),
53 mClusterID(clusterIndex),
54 mMaxClusters(maxClusters),
55 mErrorMessage()
56 {
57 mErrorMessage = fmt::format("Cluster out of range: %d, max %d", mClusterID, mMaxClusters);
58 }
59
61 ~ClusterRangeException() noexcept final = default;
62
65 const char* what() const noexcept final { return mErrorMessage.data(); }
66
69 int getClusterID() const { return mClusterID; }
70
73 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()
91 {
92 mErrorMessage = Form("Cell Index out of range: %d, max %d", mCellIndex, mMaxCellIndex);
93 }
94
96 ~CellIndexRangeException() noexcept final = default;
97
100 const char* what() const noexcept final { return mErrorMessage.data(); }
101
104 int getCellIndex() const { return mCellIndex; }
105
108 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 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 AnalysisCluster& operator&() { return mCurrentCluster; }
180
183 int current_index() const { return mClusterID; }
184
185 private:
186 const ClusterFactory& mClusterFactory;
187 AnalysisCluster mCurrentCluster;
188 int mClusterID = 0;
189 bool mForward = true;
190 };
191
194 ClusterFactory() = default;
195
201 ClusterFactory(gsl::span<const o2::emcal::Cluster> clustersContainer, gsl::span<const InputType> inputsContainer, gsl::span<const int> cellsIndices);
202
205 ClusterFactory(const ClusterFactory& rp) = default;
206
210
213 ~ClusterFactory() = default;
214
217 ClusterIterator begin() const { return ClusterIterator(*this, 0, true); }
218
221 ClusterIterator end() const { return ClusterIterator(*this, getNumberOfClusters(), true); }
222
225 ClusterIterator rbegin() const { return ClusterIterator(*this, getNumberOfClusters() - 1, false); };
226
229 ClusterIterator rend() const { return ClusterIterator(*this, -1, false); };
230
232 void reset();
233
236 AnalysisCluster buildCluster(int index, o2::emcal::ClusterLabel* clusterLabel = nullptr) const;
237
238 void SetECALogWeight(Float_t w) { mLogWeight = w; }
239 float GetECALogWeight() const { return mLogWeight; }
240
241 void doEvalLocal2tracking(bool justCluster)
242 {
243 mJustCluster = justCluster;
244 }
245
248 void evalLocalPosition(gsl::span<const int> inputsIndices, AnalysisCluster& cluster) const;
249
252 void evalGlobalPosition(gsl::span<const int> inputsIndices, AnalysisCluster& cluster) const;
253
255
258 void evalLocalPositionFit(Double_t deff, Double_t w0, Double_t phiSlope, gsl::span<const int> inputsIndices, AnalysisCluster& cluster) const;
259
265 static void getDeffW0(const Double_t esum, Double_t& deff, Double_t& w0);
266
274 std::tuple<int, float, float, bool> getMaximalEnergyIndex(gsl::span<const int> inputsIndices) const;
275
282 bool isExoticCell(short towerId, float ecell, float const exoticTime, float& fCross) 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, gsl::span<const o2::emcal::CellLabel> cellLabelContainer = {})
339 {
340 mClustersContainer = clusterContainer;
341 mInputsContainer = cellContainer;
342 mCellsIndices = indicesContainer;
343 if (!getLookUpInit()) {
345 }
346 if (!cellLabelContainer.empty()) {
347 mCellLabelContainer = cellLabelContainer;
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
~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.
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)
bool isExoticCell(short towerId, float ecell, float const exoticTime, float &fCross) const
Look to cell neighbourhood and reject if it seems exotic.
void setCoreRadius(float radius)
float getExoticCellInCrossMinAmplitude() const
float getExoticCellMinAmplitude() const
void setContainer(gsl::span< const o2::emcal::Cluster > clusterContainer, gsl::span< const InputType > cellContainer, gsl::span< const int > indicesContainer, gsl::span< const o2::emcal::CellLabel > cellLabelContainer={})
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:42
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.