Skip to content

Commit a2c649a

Browse files
mhemmer-cernshahor02
authored andcommitted
[EMCAL-688] Add exception for uninitilised lookup table
- Add exception class to throw when trying to determine exotic clusters but the neeed look up table is not initilised - The class UninitLookUpTableException is neseted within the cluster factory class - throw will happen inside of setIsExotic function which is called inside buildCluster function - throw will only happen if ecell < mExoticCellMinAmplitude is false - Add first step to merge set up function for the cluster, cell and index container together with the look up table - new setContainer function expects all three objects as span and will set them - next step would be to change the current calls of the three (four) setter everywhere with this one
1 parent bff9090 commit a2c649a

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

Detectors/EMCAL/base/include/EMCALBase/ClusterFactory.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ class ClusterFactory
311311
/// \param key: = 0(gamma, default); != 0(electron)
312312
Double_t tMaxInCm(const Double_t e = 0.0, const int key = 0) const;
313313

314+
bool getLookUpInit() const { return mLookUpInit; }
315+
void setLookUpInit(bool lookUpInit) { mLookUpInit = lookUpInit; }
316+
314317
bool getCoreRadius() const { return mCoreRadius; }
315318
void setCoreRadius(float radius) { mCoreRadius = radius; }
316319

@@ -343,12 +346,24 @@ class ClusterFactory
343346
{
344347
mCellsIndices = indicesContainer;
345348
}
349+
350+
void setContainer(gsl::span<const o2::emcal::Cluster> clusterContainer, gsl::span<const InputType> cellContainer, gsl::span<const int> indicesContainer)
351+
{
352+
mClustersContainer = clusterContainer;
353+
mInputsContainer = cellContainer;
354+
mCellsIndices = indicesContainer;
355+
if (!getLookUpInit()) {
356+
setLookUpTable();
357+
}
358+
}
359+
346360
void setLookUpTable(void)
347361
{
348362
mLoolUpTowerToIndex.fill(-1);
349363
for (auto iCellIndex : mCellsIndices) {
350364
mLoolUpTowerToIndex[mInputsContainer[iCellIndex].getTower()] = iCellIndex;
351365
}
366+
setLookUpInit(true);
352367
}
353368

354369
int getNumberOfClusters() const
@@ -360,6 +375,21 @@ class ClusterFactory
360375
/// \param geometry EMCAL geometry
361376
void setGeometry(o2::emcal::Geometry* geometry) { mGeomPtr = geometry; }
362377

378+
/// \class UninitLookUpTableException
379+
/// \brief Exception handling uninitialized look up table
380+
class UninitLookUpTableException final : public std::exception
381+
{
382+
public:
383+
/// \brief constructor
384+
UninitLookUpTableException() = default;
385+
386+
/// \brief Destructor
387+
~UninitLookUpTableException() noexcept final = default;
388+
389+
/// \brief Access to error message of the exception
390+
const char* what() const noexcept final { return "Lookup table not initialized, exotics evaluation not possible!"; }
391+
};
392+
363393
protected:
364394
///
365395
/// This function calculates energy in the core,
@@ -400,6 +430,7 @@ class ClusterFactory
400430
float mLogWeight = 4.5; ///< logarithmic weight for the cluster center of gravity calculation
401431

402432
bool mJustCluster = kFALSE; ///< Flag to evaluates local to "tracking" c.s. transformation (B.P.).
433+
bool mLookUpInit = false; ///< Flag to check if the mLoolUpTowerToIndex is currently set. Will be checked when needed and created if not set!
403434

404435
mutable int mSuperModuleNumber = 0; ///< number identifying supermodule containing cluster, reference is cell with maximum energy.
405436
float mDistToBadTower = -1; ///< Distance to nearest bad tower
@@ -413,7 +444,7 @@ class ClusterFactory
413444
gsl::span<const o2::emcal::Cluster> mClustersContainer; ///< Container for all the clusters in the event
414445
gsl::span<const InputType> mInputsContainer; ///< Container for all the cells/digits in the event
415446
gsl::span<const int> mCellsIndices; ///< Container for cells indices in the event
416-
std::array<short, 17664> mLoolUpTowerToIndex; ///< Lookup table to match tower id with and cell index, needed for exotic check
447+
std::array<short, 17664> mLoolUpTowerToIndex; ///< Lookup table to match tower id with cell index, needed for exotic check
417448

418449
ClassDefNV(ClusterFactory, 2);
419450
};

Detectors/EMCAL/base/src/ClusterFactory.cxx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ ClusterFactory<InputType>::ClusterFactory(gsl::span<const o2::emcal::Cluster> cl
3636
{
3737
mGeomPtr = o2::emcal::Geometry::GetInstance();
3838

39-
setClustersContainer(clustersContainer);
40-
setCellsContainer(inputsContainer);
41-
setCellsIndicesContainer(cellsIndices);
42-
setLookUpTable();
39+
setContainer(clustersContainer, inputsContainer, cellsIndices);
4340
}
4441

4542
template <class InputType>
@@ -48,6 +45,7 @@ void ClusterFactory<InputType>::reset()
4845
mClustersContainer = gsl::span<const o2::emcal::Cluster>();
4946
mInputsContainer = gsl::span<const InputType>();
5047
mCellsIndices = gsl::span<int>();
48+
mLookUpInit = false;
5149
}
5250

5351
///
@@ -80,7 +78,11 @@ o2::emcal::AnalysisCluster ClusterFactory<InputType>::buildCluster(int clusterIn
8078

8179
float exoticTime = mInputsContainer[inputIndMax].getTimeStamp();
8280

83-
clusterAnalysis.setIsExotic(isExoticCell(towerId, inputEnergyMax, exoticTime));
81+
try {
82+
clusterAnalysis.setIsExotic(isExoticCell(towerId, inputEnergyMax, exoticTime));
83+
} catch (UninitLookUpTableException& e) {
84+
LOG(error) << e.what();
85+
}
8486

8587
clusterAnalysis.setIndMaxInput(inputIndMax);
8688

@@ -595,6 +597,11 @@ bool ClusterFactory<InputType>::isExoticCell(short towerId, float ecell, float c
595597
return false; // do not reject low energy cells
596598
}
597599

600+
// if the look up table is not set yet (mostly due to a reset call) then set it up now.
601+
if (getLookUpInit()) {
602+
throw UninitLookUpTableException();
603+
}
604+
598605
float eCross = getECross(towerId, ecell, exoticTime);
599606

600607
if (1 - eCross / ecell > mExoticCellFraction) {

0 commit comments

Comments
 (0)