8#include "CLHEP/Units/SystemOfUnits.h"
20constexpr int neta = 5;
22constexpr int nphi = 2;
24constexpr int STRIP_ARRAY_SIZE = 8 * neta;
27proxim(
const double b,
const double a)
33dim(
const double a,
const double b)
35 return a - std::min(
a, b);
38struct StripArrayHelper
47 bool operator<(
const StripArrayHelper& cell2)
const
49 return etaraw < cell2.etaraw;
82 sam == CaloSampling::EMB1 ? CaloCell_ID::EMB1 : CaloCell_ID::EME1,
94 double etamin = etaraw - deta;
95 double etamax = etaraw + deta;
96 double phimin = phiraw - dphi;
97 double phimax = phiraw + dphi;
103 std::vector<StripArrayHelper> stripArray;
104 stripArray.reserve(2 * STRIP_ARRAY_SIZE);
106 double eta_cell = 0.;
107 double phi_cell0 = 0.;
108 double phi_cell = 0.;
121 phi_cell =
proxim(phi_cell0, phiraw);
123 if (eta_cell >= etamin && eta_cell <= etamax) {
124 if (phi_cell >= phimin && phi_cell <= phimax) {
125 StripArrayHelper stripHelp;
127 stripHelp.energy = theCell->
energy() * (
first.weight());
129 stripHelp.eta = theCell->
eta();
136 stripArray.push_back(stripHelp);
141 const size_t elementCount = stripArray.size();
143 if (elementCount == 0) {
147 std::sort(stripArray.begin(), stripArray.end());
152 for (
size_t i = 0;
i < (elementCount - 1); ++
i) {
154 if (ieta < STRIP_ARRAY_SIZE) {
156 enecell[ieta] += stripArray[
i].energy;
158 etacell[ieta] = stripArray[
i].eta;
160 gracell[ieta] = stripArray[
i].deta;
165 if (std::abs(stripArray[i].etaraw - stripArray[i + 1].etaraw) > 1e-05)
176 int index = elementCount - 1;
179 if (
index == 0 || std::abs(stripArray[
index].etaraw -
180 stripArray[
index - 1].etaraw) > 1e-05) {
182 enecell[ieta] = stripArray[
index].energy;
184 if (
index != 0 && std::abs(stripArray[
index].etaraw -
185 stripArray[
index - 1].etaraw) < 1e-05) {
187 enecell[ieta] += stripArray[
index].energy;
190 etacell[ieta] = stripArray[
index].eta;
192 gracell[ieta] = stripArray[
index].deta;
200 const double* etacell,
201 const double* gracell)
206 double demi_eta = 0.;
209 for (
int ieta = 0; ieta < STRIP_ARRAY_SIZE - 1; ieta++) {
212 demi_eta = gracell[ieta] / 2.;
213 eta_min = etacell[ieta] - demi_eta;
214 eta_max = etacell[ieta] + demi_eta;
216 if ((std::abs(
info.etaseed) > std::abs(eta_min) &&
217 std::abs(
info.etaseed) <= std::abs(eta_max)) ||
218 (std::abs(
info.etaseed) <= std::abs(eta_min) &&
219 std::abs(
info.etaseed) > std::abs(eta_max)))
220 info.ncetaseed = ieta;
228 const double* enecell,
229 const double* etacell,
237 double etamax =
info.etamax + deta / 2.;
242 for (
int ieta = 0; ieta < STRIP_ARRAY_SIZE; ieta++) {
243 if (ncell[ieta] == 0)
245 if (etacell[ieta] >= etamin && etacell[ieta] <= etamax) {
246 wtot += enecell[ieta] * (ieta -
info.ncetamax) * (ieta -
info.ncetamax);
247 mean += enecell[ieta] * (ieta -
info.ncetamax);
248 etot += enecell[ieta];
256 info.wstot = wtot > 0 ? std::sqrt(wtot) : -9999.;
263 const double* enecell,
264 const double eallsamples)
271 double eleft =
info.ncetamax > 0 ? enecell[
info.ncetamax - 1] : 0;
274 info.ncetamax < STRIP_ARRAY_SIZE - 1 ? enecell[
info.ncetamax + 1] : 0;
276 double e2 = std::max(eleft, eright);
278 info.f2 = eallsamples > 0. ? (
e1 +
e2) / eallsamples : 0.;
289 if (
info.ncetamax < 0 ||
info.ncetamax > STRIP_ARRAY_SIZE)
292 int nlo = std::max(
info.ncetamax - 1, 0);
293 int nhi = std::min(
info.ncetamax + 1, STRIP_ARRAY_SIZE - 1);
294 for (
int ieta = nlo; ieta <= nhi; ieta++) {
300 nlo = std::max(
info.ncetamax - 7, 0);
301 nhi = std::min(
info.ncetamax + 7, STRIP_ARRAY_SIZE - 1);
302 for (
int ieta = nlo; ieta <= nhi; ieta++) {
316 if (
info.ncetamax < 0 ||
info.ncetamax > STRIP_ARRAY_SIZE)
322 int nlo = std::max(
info.ncetamax - 1, 0);
324 int nhi = std::min(
info.ncetamax + 1, STRIP_ARRAY_SIZE - 1);
325 for (
int ieta = nlo; ieta <=
info.ncetamax; ieta++)
326 asl += enecell[ieta];
327 for (
int ieta =
info.ncetamax; ieta <= nhi; ieta++)
328 asr += enecell[ieta];
331 info.asymmetrys3 = (asl - asr) / (asl + asr);
339 const double* enecell,
340 const double* etacell,
351 int nlo = std::max(
info.ncetamax - 1, 0);
352 int nhi = std::min(
info.ncetamax + 1, STRIP_ARRAY_SIZE - 1);
353 for (
int ieta = nlo; ieta <= nhi; ieta++) {
354 if (ncell[ieta] == 0)
356 width3 += enecell[ieta] * (ieta -
info.ncetamax) * (ieta -
info.ncetamax);
357 eta1 += enecell[ieta] * etacell[ieta];
363 info.ws3 = std::sqrt(width3 / energy);
377setDeltaEtaTrackShower(
int nstrips,
int ieta,
const double* enecell)
389 int nlo = std::max(ieta - nstrips, 0);
391 int nhi = std::min(ieta + nstrips, STRIP_ARRAY_SIZE - 1);
393 for (
int i = nlo;
i <= nhi;
i++) {
395 pos += enecell[
i] * (
i - ieta);
416 double Small = 1.e-10;
421 int nlo = std::max(
info.ncetamax - 2, 0);
423 int nhi = std::min(
info.ncetamax + 2, STRIP_ARRAY_SIZE - 1);
425 for (
int ieta = nlo; ieta <= nhi; ieta++) {
426 if (ieta >= 0 && ieta < STRIP_ARRAY_SIZE) {
428 eall += enecell[ieta];
430 eave += enecell[ieta] * (ieta -
info.ncetamax);
432 width5 += enecell[ieta] * (ieta -
info.ncetamax) * (ieta -
info.ncetamax);
440 width5 = width5 / eall;
441 width5 = width5 - eave * eave;
446 info.widths5 = std::sqrt(width5);
456 for (
int ieta = 0; ieta < STRIP_ARRAY_SIZE; ieta++) {
457 if (enecell[ieta] >
info.emaxs1) {
458 info.emaxs1 = enecell[ieta];
459 info.ncetamax = ieta;
467 const double* enecell,
468 const double* gracell,
478 double escalesec = 0;
479 double escalesec1 = 0;
481 for (
int ieta = 1; ieta < STRIP_ARRAY_SIZE - 1; ieta++) {
482 if (ncell[ieta] == 0)
485 int ieta_left = ieta - 1;
486 while (ieta_left >= 0 && ncell[ieta_left] == 0) {
493 int ieta_right = ieta + 1;
494 while (ieta_right < STRIP_ARRAY_SIZE && ncell[ieta_right] == 0) {
497 if (ieta_right >= STRIP_ARRAY_SIZE) {
501 double e = enecell[ieta] / gracell[ieta];
502 double e_left = enecell[ieta_left] / gracell[ieta_left];
503 double e_right = enecell[ieta_right] / gracell[ieta_right];
505 if (e > e_left && e > e_right) {
509 if (ieta !=
info.ncetamax) {
510 ecand = enecell[ieta] + enecell[ieta_left] + enecell[ieta_right];
511 double escalecand =
e + e_left + e_right;
512 ecand1 = enecell[ieta];
515 if (escalecand > escalesec) {
516 escalesec = escalecand;
521 if (e > escalesec1) {
536 const double* enecell,
537 const double* gracell,
546 double escalemin =
info.emaxs1 / 0.001;
552 int nlo = std::min(
info.ncetamax, ncsec1) + 1;
554 int nhi = std::max(
info.ncetamax, ncsec1) - 1;
556 for (
int ieta = nlo; ieta <= nhi; ieta++) {
557 if (ncell[ieta] == 0)
562 double escale = enecell[ieta] / gracell[ieta];
563 if (escale < escalemin) {
565 info.emins1 = enecell[ieta];
579 double Ehsthr = 0.06 *
GeV;
583 for (
int ieta =
info.ncetamax + 2; ieta < STRIP_ARRAY_SIZE - 1; ieta++) {
584 if (enecell[ieta] > Ehsthr &&
585 enecell[ieta] > std::max(enecell[ieta - 1], enecell[ieta + 1])) {
587 for (
int jc =
info.ncetamax; jc <= ieta - 1; jc++) {
588 valley +=
dim(enecell[ieta], enecell[jc]);
596 for (
int ieta = 1; ieta <=
info.ncetamax - 2; ieta++) {
597 if (enecell[ieta] > Ehsthr &&
598 enecell[ieta] > std::max(enecell[ieta - 1], enecell[ieta + 1])) {
600 for (
int jc = ieta + 1; jc <=
info.ncetamax; jc++) {
601 valley +=
dim(enecell[ieta], enecell[jc]);
611 double eleft =
info.ncetamax > 0 ? enecell[
info.ncetamax - 1] : 0;
614 info.ncetamax < STRIP_ARRAY_SIZE - 1 ? enecell[
info.ncetamax + 1] : 0;
616 double e2 = std::max(eleft, eright);
618 if (std::abs(e1 + e2) > 0.)
626 const double* enecell,
627 const double* gracell,
636 double Ehsthr = 0.06 *
GeV;
640 int ileft =
info.ncetamax - 1;
641 while (ileft > 0 && ncell[ileft] == 0) {
644 double eleft = ileft >= 0 ? enecell[ileft] : 0;
647 int iright =
info.ncetamax + 1;
648 while (iright < STRIP_ARRAY_SIZE - 1 && ncell[iright] == 0) {
651 double eright = iright < STRIP_ARRAY_SIZE ? enecell[iright] : 0;
656 int nlo = std::max(
info.ncetamax - 3, 0);
658 int nhi = std::min(
info.ncetamax + 3, STRIP_ARRAY_SIZE - 1);
661 for (
int ieta = nlo; ieta <= nhi; ieta++) {
662 if (ncell[ieta] == 0)
664 fracm += (gracell[ieta] > DBL_MIN) ? (enecell[ieta] / gracell[ieta]) : 0.;
666 if (std::abs(eleft + eright + e1) > 0.) {
667 if ((e1 != 0) && (gracell[
info.ncetamax] > DBL_MIN))
668 e1 /= gracell[
info.ncetamax];
670 eleft /= gracell[ileft];
672 eright /= gracell[iright];
674 info.fside = (std::abs(eleft + eright + e1) > 0.)
675 ? fracm / (eleft + eright + e1) - 1.
694 if (std::abs(energy) > 0. && e132 >
x) {
705 bool ExecAllVariables)
715 return StatusCode::SUCCESS;
740 info.etamax = cluster.
etamax(samgran);
741 info.phimax = cluster.
phimax(samgran);
743 if ((info.etamax == 0. && info.phimax == 0.) ||
744 std::abs(info.etamax) > 100.) {
745 return StatusCode::SUCCESS;
748 if (std::abs(info.etamax) > 2.4) {
749 return StatusCode::SUCCESS;
751 if (std::abs(info.etamax) > 1.4 && std::abs(info.etamax) < 1.5) {
752 return StatusCode::SUCCESS;
759 int sampling_or_module = 0;
763 subcalo, sampling_or_module,
barrel, info.etamax, info.phimax);
766 return StatusCode::SUCCESS;
769 deta = dde->
deta() * neta / 2.0;
774 subcalo, sampling_or_module,
barrel, info.etamax, info.phimax);
777 return StatusCode::SUCCESS;
780 dphi = dde->
dphi() * nphi / 2.0;
783 double enecell[STRIP_ARRAY_SIZE] = { 0 };
784 double etacell[STRIP_ARRAY_SIZE] = { 0 };
785 double gracell[STRIP_ARRAY_SIZE] = { 0 };
786 int ncell[STRIP_ARRAY_SIZE] = { 0 };
803 setIndexSeed(info, etacell, gracell);
805 info.f1 = std::abs(eallsamples) > 0. ? e1 / eallsamples : 0.;
807 setEmax(info, enecell);
809 setWstot(info, deta, enecell, etacell, ncell);
811 setWs3(info, sam, cluster, enecell, etacell, ncell);
813 if (ExecAllVariables) {
814 setEnergy(info, enecell);
815 setF1core(info, cluster);
817 setAsymmetry(info, enecell);
820 info.deltaEtaTrackShower =
821 setDeltaEtaTrackShower(1, info.ncetamax, enecell);
824 info.deltaEtaTrackShower7 =
825 setDeltaEtaTrackShower(7, info.ncetaseed, enecell);
827 setF2(info, enecell, eallsamples);
829 setWidths5(info, enecell);
831 int ncsec1 = setEmax2(info, enecell, gracell, ncell);
833 setEmin(ncsec1, info, enecell, gracell, ncell);
835 setValley(info, enecell);
837 setFside(info, enecell, gracell, ncell);
840 return StatusCode::SUCCESS;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Calculate total energy, position, etc. for a given layer of a cluster.
bool operator<(const DataVector< T > &a, const DataVector< T > &b)
Vector ordering relation.
CaloCell_Base_ID::SUBCALO SUBCALO
CaloSampling::CaloSample CaloSample
Data object for each calorimeter readout cell.
double energy() const
get energy (data member)
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
virtual double eta() const override final
get eta (through CaloDetDescrElement)
This class groups all DetDescr information related to a CaloCell.
float eta_raw() const
cell eta_raw
float dphi() const
cell dphi
CaloCell_ID::CaloSample getSampling() const
cell sampling
float phi_raw() const
cell phi_raw
float deta() const
cell deta
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
static void decode_sample(CaloCell_ID::SUBCALO &subCalo, bool &barrel, int &sampling_or_module, CaloCell_ID::CaloSample sample)
translate between the 2 ways to label a sub-detector:
This class provides the client interface for accessing the detector description information common to...
float phiSample(const CaloSample sampling) const
Retrieve barycenter in a given sample.
virtual double e() const
The total energy of the particle.
CaloClusterCellLink::const_iterator const_cell_iterator
Iterator of the underlying CaloClusterCellLink (explicitly const version)
const_cell_iterator cell_end() const
bool inBarrel() const
Returns true if at least one clustered cell in the barrel.
bool inEndcap() const
Returns true if at least one clustered cell in the endcap.
float etamax(const CaloSample sampling) const
Retrieve of cell with maximum energy in given sampling.
const_cell_iterator cell_begin() const
Iterator of the underlying CaloClusterCellLink (const version)
float etaSample(const CaloSample sampling) const
Retrieve barycenter in a given sample.
float phimax(const CaloSample sampling) const
Retrieve of cell with maximum energy in given sampling.
CaloSampling::CaloSample CaloSample
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
float round(const float toRound, const unsigned int decimals)
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
bool inBarrel(const xAOD::CaloCluster &cluster, int is)
return boolean to know if we are in barrel/end-cap
double e(const xAOD::CaloCluster &cluster)
return the uncorrected sum of energy in all samples
double RelPosition(const float eta, const float etacell)
returns relative position within the cell
float Correct(const float eta, const float etacell, const float width)
returns corrected width at eta
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
@ e132
uncalibrated energy (sum of cells) in strips in a 3x2 window in cells in eta X phi
setEt setPhi setE277 setWeta2 eta1
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
double proxim(double b, double a)
static StatusCode execute(const xAOD::CaloCluster &cluster, const CaloDetDescrManager &cmgr, Info &info, bool ExecAllVariables=true)
AlgTool main method.