22#include <fairlogger/Logger.h>
36 LOG(info) <<
"Clusterizer parameters";
52 std::vector<Cluster>&
clusters, std::vector<CluElement>& cluelements, std::vector<TriggerRecord>& trigRec,
57 cluelements.reserve(
digits.size());
62 for (
const auto& tr : dtr) {
66 int firstDigitInEvent = tr.getFirstEntry();
67 int lastDigitInEvent = firstDigitInEvent + tr.getNumberOfObjects();
71 for (
int i = firstDigitInEvent;
i < lastDigitInEvent;
i++) {
74 if (digitSeed.
isTRU()) {
95 LOG(
debug) <<
"Found clusters from " << indexStart <<
" to " <<
clusters.size();
96 trigRec.emplace_back(tr.getBCData(), indexStart,
clusters.size() - indexStart);
105 std::vector<Cluster>&
clusters, std::vector<CluElement>& cluelements, std::vector<TriggerRecord>& trigRec,
111 cluelements.reserve(
cells.size());
116 for (
const auto& tr : ctr) {
117 int firstCellInEvent = tr.getFirstEntry();
118 int lastCellInEvent = firstCellInEvent + tr.getNumberOfObjects();
124 for (
int i = firstCellInEvent;
i < lastCellInEvent;
i++) {
128 mTrigger.emplace_back(
c.getTRUId(),
c.getEnergy(),
c.getTime(), 0);
134 float energy =
calibrate(
c.getEnergy(), absId,
c.getHighGain());
138 float x = 0.,
z = 0.;
140 mCluEl.emplace_back(absId,
c.getHighGain(), energy,
calibrateT(
c.getTime(), absId,
c.getHighGain(), tr.getBCData().bc),
145 trigRec.emplace_back(tr.getBCData(), indexStart,
clusters.size() - indexStart);
160 for (
int i = iFirst;
i <
n;
i++) {
169 int iDigitInCluster = 0;
175 cluelements.emplace_back(digitSeed);
183 while (
index < iDigitInCluster) {
186 for (
int j = iFirst;
j <
n;
j++) {
201 cluelements.emplace_back(digitN);
222 cluelements.pop_back();
246 cluelements.pop_back();
264 std::vector<std::vector<float>> eInClusters(mult, std::vector<float>(nMax));
268 mProp.reserve(mult * nMax);
270 for (
int iclu = nMax; iclu--;) {
285 bool insuficientAccuracy =
true;
286 double chi2Previous = 1.e+6;
289 insuficientAccuracy =
false;
294 for (
int iclu = nMax; iclu--;) {
300 for (uint32_t idig = firstCE; idig < lastCE; idig++) {
303 for (
int iclu = nMax; iclu--;) {
306 double r2 = lx * lx + lz * lz;
313 sumA += ss *
meMax[iclu];
314 C(iclu) += ce.
energy * ss;
316 double dE = ce.
energy - sumA;
318 for (
int iclu = 0; iclu < nMax; iclu++) {
319 for (
int jclu = iclu; jclu < nMax; jclu++) {
320 B(iclu, jclu) +=
mfij[iclu] *
mfij[jclu];
325 mProp[(idig - firstCE) * nMax + iclu] =
mfij[iclu] *
meMax[iclu] / sumA;
328 if (nIterations > 0 && chi2 > chi2Previous) {
330 for (
int iclu = nMax; iclu--;) {
335 insuficientAccuracy =
true;
341 for (
int iclu = nMax; iclu--;) {
348 for (
int iclu = 1; iclu < nMax; iclu++) {
349 for (
int jclu = 0; jclu < iclu; jclu++) {
350 B(iclu, jclu) =
B(jclu, iclu);
353 for (
int iclu = nMax; iclu--;) {
360 for (
int iclu = nMax; iclu--;) {
373 if (bk.Decompose()) {
375 for (
int iclu = 0; iclu < nMax; iclu++) {
376 meMax[iclu] = C(iclu);
391 for (
int iclu = 0; iclu < nMax; iclu++) {
393 int start = cluelements.size();
395 for (uint32_t idig = firstCE; idig < lastCE; idig++) {
397 float ei = el.
energy *
mProp[(idig - firstCE) * nMax + iclu];
399 cluelements.emplace_back(el);
400 cluelements.back().energy = ei;
401 cluelements.back().fraction =
mProp[(idig - firstCE) * nMax + iclu];
412 cluelements.pop_back();
425 cluelements.pop_back();
449 gsl::span<const MCLabel> spDigList = dmc->
getLabels(
i);
450 if (spDigList.size() == 0 || spDigList.begin()->isFake()) {
453 gsl::span<MCLabel> spCluList = cluMC.
getLabels(labelIndex);
454 auto digL = spDigList.begin();
455 while (digL != spDigList.end()) {
456 if (digL->isFake()) {
461 auto cluL = spCluList.begin();
462 while (cluL != spCluList.end()) {
463 if (*digL == *cluL) {
464 (*cluL).add(*digL, sc);
500 double r295 = TMath::Power(r2, 2.95 / 2.);
501 double a = 2.32 + 0.26 * r4;
502 double b = 31.645570 + 2.0632911 * r295;
503 double s = TMath::Exp(-r4 * ((
a +
b) / (
a *
b)));
504 deriv = -2. * s * r2 * (2.32 / (
a *
a) + (0.54161392 * r295 + 31.645570) / (
b *
b));
516 float fullEnergy = 0.;
522 for (uint32_t
i = iFirst;
i < iLast;
i++) {
523 float ei = cluel[
i].energy;
529 time = cluel[
i].time;
534 if (fullEnergy <= 0) {
540 float localPosX = 0., localPosZ = 0.;
542 float invE = 1. / fullEnergy;
543 for (uint32_t
i = iFirst;
i < iLast;
i++) {
562 coreRadius2 *= coreRadius2;
564 float dispersion = 0.;
565 float dxx = 0., dxz = 0., dzz = 0., lambdaLong = 0., lambdaShort = 0.;
566 for (uint32_t
i = iFirst;
i < iLast;
i++) {
572 float x = ce.
localX - localPosX;
573 float z = ce.
localZ - localPosZ;
593 lambdaLong = 0.5 * (dxx + dzz) + std::sqrt(0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz);
594 if (lambdaLong > 0) {
595 lambdaLong = std::sqrt(lambdaLong);
598 lambdaShort = 0.5 * (dxx + dzz) - std::sqrt(0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz);
599 if (lambdaShort > 0) {
600 lambdaShort = std::sqrt(lambdaShort);
605 if (dispersion >= 0) {
618 short trtype = trd.is2x2Tile() ? 0 : 1;
622 int dx = relId[1] - trurelid[1];
623 int dz = relId[2] - trurelid[2];
625 if (dx >= 0 && dx < 2 && dz >= 0 && dz < 2) {
630 if (dx >= 0 && dx < 4 && dz >= 0 && dz < 4) {
649 for (uint32_t
i = iFirst;
i < iLast;
i++) {
653 for (uint32_t
i = iFirst;
i < iLast - 1;
i++) {
654 for (uint32_t
j =
i + 1;
j < iLast;
j++) {
657 if (cluel[
i].energy > cluel[
j].energy) {
660 if (cluel[
j].energy > cluel[
i].energy - locMaxCut) {
666 if (cluel[
i].energy > cluel[
j].energy - locMaxCut) {
680 static int nAlarms = 0;
682 LOG(alarm) <<
"Too many local maxima, cluster multiplicity " <<
mIsLocalMax.size();
Definition of the PHOS cluster finder.
static const PHOSSimParams & Instance()
Contains PHOS cluster parameters.
uint32_t getFirstCluEl() const
void setFirstCluEl(uint32_t first)
void setCoreEnergy(float ec)
int getMultiplicity() const
void setNExMax(char nmax=1)
void setDispersion(float d)
void setFiredTrigger(char t)
void setLocalPosition(float posX, float posZ)
void setLastCluEl(uint32_t last)
void setElipsAxis(float lambdaShort, float lambdaLong)
uint32_t getLastCluEl() const
static constexpr short NLOCMAX
void makeUnfolding(Cluster &clu, std::vector< Cluster > &clusters, std::vector< o2::phos::CluElement > &cluel)
bool isBadChannel(short absId)
void processCells(gsl::span< const Cell > digits, gsl::span< const TriggerRecord > dtr, const o2::dataformats::MCTruthContainer< MCLabel > *dmc, std::vector< Cluster > &clusters, std::vector< CluElement > &cluel, std::vector< TriggerRecord > &rigRec, o2::dataformats::MCTruthContainer< MCLabel > &cluMC)
int mLastElementInEvent
Range of digits from one event.
std::array< double, NLOCMAX > mfijz
transient variable for derivative calculation
std::array< int, NLOCMAX > mMaxAt
indexes of local maxima
char getNumberOfLocalMax(Cluster &clu, std::vector< CluElement > &cluel)
std::array< float, NLOCMAX > meMax
currecnt amplitude in unfoding
void evalLabels(std::vector< Cluster > &clusters, std::vector< CluElement > &cluel, const o2::dataformats::MCTruthContainer< MCLabel > *dmc, o2::dataformats::MCTruthContainer< MCLabel > &cluMC)
float calibrateT(float time, short absId, bool isHighGain, int bc)
std::array< float, NLOCMAX > mdz
step on current minimization iteration
void process(gsl::span< const Digit > digits, gsl::span< const TriggerRecord > dtr, const o2::dataformats::MCTruthContainer< MCLabel > *dmc, std::vector< Cluster > &clusters, std::vector< CluElement > &cluel, std::vector< TriggerRecord > &rigRec, o2::dataformats::MCTruthContainer< MCLabel > &cluMC)
int mFirstElememtInEvent
Range of digits from one event.
std::array< float, NLOCMAX > mdzprev
step on previoud minimization iteration
double showerShape(double r2, double &deriv)
std::array< double, NLOCMAX > mxB
transient variable for derivative calculation
void makeClusters(std::vector< Cluster > &clusters, std::vector< o2::phos::CluElement > &cluel)
std::array< float, NLOCMAX > mdxprev
step on previoud minimization iteration
std::array< double, NLOCMAX > mfij
transient variable for derivative calculation
Geometry * mPHOSGeom
packed shifts for 14 ddls
std::vector< Digit > mTrigger
internal vector of clusters
void unfoldOneCluster(Cluster &iniClu, char nMax, std::vector< Cluster > &clusters, std::vector< CluElement > &cluelements)
std::array< float, NLOCMAX > mdx
step on current minimization iteration
std::vector< CluElement > mCluEl
! Bad map, Clusterizer not owner
float calibrate(float amp, short absId, bool isHighGain)
std::array< double, NLOCMAX > mA
transient variable for derivative calculation
std::vector< float > mProp
proportion of clusters in the current digit
std::array< float, NLOCMAX > mxMax
current maximum coordinate
std::array< double, NLOCMAX > mzB
transient variable for derivative calculation
void evalAll(Cluster &clu, std::vector< CluElement > &cluel) const
std::vector< bool > mIsLocalMax
transient array for local max finding
std::array< double, NLOCMAX > mfijr
transient variable for derivative calculation
std::array< float, NLOCMAX > mzMax
in the unfolding procedure
std::array< double, NLOCMAX > mfijx
transient variable for derivative calculation
std::array< float, NLOCMAX > mxMaxPrev
coordunates at previous step
std::array< float, NLOCMAX > mzMaxPrev
coordunates at previous step
short getAbsId() const
Absolute sell id.
float getAmplitude() const
Energy deposited in a cell.
bool isHighGain() const
Checks if this digit is produced in High Gain or Low Gain channels.
int getLabel() const
index of entry in MCLabels array
float getTime() const
time measured in digit w.r.t. photon to PHOS arrival
static void relPosToRelId(short module, float x, float z, char *relId)
static char absIdToModule(short absId)
static int areNeighbours(short absId1, short absId2)
static void absIdToRelPosInModule(short absId, float &x, float &z)
static bool truAbsToRelNumbering(short truId, short trigType, char *relid)
static Geometry * GetInstance()
GLboolean GLboolean GLboolean b
GLsizei GLsizei GLfloat distance
GLboolean GLboolean GLboolean GLboolean a
GLubyte GLubyte GLubyte GLubyte w
GLdouble GLdouble GLdouble z
float mUnfogingChi2Accuracy
critical chi2/NDF
float mCoreR
Radius to caluclate core energy.
bool mUnfoldClusters
To perform cluster unfolding.
float mLogWeight
Cutoff used in log. weight calculation.
int mUnfoldMaxSize
maximal number of cells in cluster to be unfolded
float mDigitMinEnergy
Minimal energy of digits to be used in cluster (GeV)
float mClusteringThreshold
Minimal energy of digit to start clustering (GeV)
float mUnfogingXZAccuracy
Accuracy of position calculation in unfolding procedure (cm)
float mLocalMaximumCut
Minimal height of local maximum over neighbours.
float mUnfogingEAccuracy
Accuracy of energy calculation in unfoding prosedure (GeV)
int mNMaxIterations
Maximal number of iterations in unfolding procedure.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters
std::vector< Cell > cells
std::vector< Digit > digits