Belle II Software development
ECLShowerVariables.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9/* Own header. */
10#include <ecl/dataobjects/ECLShower.h>
11
12/* Basf2 headers. */
13#include <analysis/dataobjects/Particle.h>
14#include <analysis/VariableManager/Manager.h>
15#include <framework/core/Module.h>
16#include <framework/datastore/StoreObjPtr.h>
17#include <framework/datastore/StoreArray.h>
18#include <mdst/dataobjects/ECLCluster.h>
19
20using namespace std;
21
22namespace Belle2 {
28 namespace Variable {
29
31 double getShowerNumberOfCrystalsForEnergy(const Particle* particle)
32 {
33 const ECLCluster* cluster = particle->getECLCluster();
34 if (cluster) {
35 auto clusterShowerRelations = cluster->getRelationsWith<ECLShower>();
36 if (clusterShowerRelations.size() == 1) {
37 return clusterShowerRelations.object(0)->getNumberOfCrystalsForEnergy();
38 } else {
39 B2ERROR("Somehow found more than 1 ECLShower matched to the ECLCluster. This should not be possible!");
40 }
41 }
42 return std::numeric_limits<double>::quiet_NaN();
43 }
44
46 double getShowerNominalNumberOfCrystalsForEnergy(const Particle* particle)
47 {
48 const ECLCluster* cluster = particle->getECLCluster();
49 if (cluster) {
50 auto clusterShowerRelations = cluster->getRelationsWith<ECLShower>();
51 if (clusterShowerRelations.size() == 1) {
52 return clusterShowerRelations.object(0)->getNominalNumberOfCrystalsForEnergy();
53 } else {
54 B2ERROR("Somehow found more than 1 ECLShower matched to the ECLCluster. This should not be possible!");
55 }
56 }
57 return std::numeric_limits<double>::quiet_NaN();
58 }
59
61 double getShowerHadronIntensity(const Particle* particle)
62 {
63 const ECLCluster* cluster = particle->getECLCluster();
64 if (cluster) {
65 auto clusterShowerRelations = cluster->getRelationsWith<ECLShower>();
66 if (clusterShowerRelations.size() == 1) {
67 return clusterShowerRelations.object(0)->getShowerHadronIntensity();
68 } else {
69 B2ERROR("Somehow found more than 1 ECLShower matched to the ECLCluster. This should not be possible!");
70 }
71 }
72 return std::numeric_limits<double>::quiet_NaN();
73 }
74
76 double getShowerNumberOfHadronDigits(const Particle* particle)
77 {
78 const ECLCluster* cluster = particle->getECLCluster();
79 if (cluster) {
80 auto clusterShowerRelations = cluster->getRelationsWith<ECLShower>();
81 if (clusterShowerRelations.size() == 1) {
82 return clusterShowerRelations.object(0)->getNumberOfHadronDigits();
83 } else {
84 B2ERROR("Somehow found more than 1 ECLShower matched to the ECLCluster. This should not be possible!");
85 }
86 }
87 return std::numeric_limits<double>::quiet_NaN();
88 }
89
90 // returns the nm zernike moment (between 10 and 55)
91 double getAbsZernikeMomentNM(const Particle* particle,
92 const std::vector<double>& arguments)
93 {
94 if (arguments.size() != 2) {
95 B2FATAL("Wrong number of arguments, 2 required for meta function absZernikeMoment");
96 }
97 const long n = std::lround(arguments[0]);
98 const long m = std::lround(arguments[1]);
99
100 if ((n < 1) or (n > 5)) {
101 B2FATAL("n must be between 1 and 5 for meta function absZernikeMoment");
102 }
103 if (m > n) {
104 B2FATAL("m must be less than or equal to n for meta function absZernikeMoment");
105 }
106
107 const ECLCluster* cluster = particle->getECLCluster();
108 if (cluster) {
109 auto clusterShowerRelations = cluster->getRelationsWith<ECLShower>();
110 if (clusterShowerRelations.size() == 1) {
111 return clusterShowerRelations.object(0)->getAbsZernikeMoment(n, m);
112 } else {
113 B2ERROR("Somehow found more than 1 ECLShower matched to the ECLCluster. This should not be possible!");
114 }
115 }
116 return std::numeric_limits<float>::quiet_NaN();
117 }
118
119
120 VARIABLE_GROUP("ECL Shower Debugging (cDST)");
121
122 REGISTER_VARIABLE("eclShowerNumberOfCrystalsForEnergy", getShowerNumberOfCrystalsForEnergy,
123 "[debugging] Returns the number of crystals ued to calculate the shower energy (optimized to minimize the energy resolution). This should not be confused with the number of crystals contained in the cluster. ");
124
125 REGISTER_VARIABLE("eclShowerNominalNumberOfCrystalsForEnergy", getShowerNominalNumberOfCrystalsForEnergy,
126 "[debugging] Returns the nominal number of crystals ued to calculate the shower energy (optimized to minimize the energy resolution). This should not be confused with the number of crystals contained in the cluster. ");
127
128 REGISTER_VARIABLE("eclShowerHadronIntensity", getShowerHadronIntensity,
129 "[debugging] Returns the hadron intensity of the shower associated with the particle.");
130
131 REGISTER_VARIABLE("eclShowerNumberOfHadronDigits", getShowerNumberOfHadronDigits,
132 "[debugging] Returns the number of hadron digits of the shower associated with the particle.");
133
134 VARIABLE_GROUP("ECL Shower Variables (cDST)");
135
136 REGISTER_VARIABLE("absZernikeMoment(n, m)", getAbsZernikeMomentNM,
137 "[eclChargedPIDExpert] the absolute value of zernike moment nm. Requires n <= 5 and m <= n.");
138 }
140}
Abstract base class for different kinds of events.
STL namespace.