Belle II Software  release-08-01-10
ECLShowerShapeModule.h
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 #pragma once
9 
10 //STL
11 #include <complex>
12 
13 //ROOT
14 #include <TGraph.h>
15 
16 // FRAMEWORK
17 #include <framework/core/Module.h>
18 #include <framework/database/DBArray.h>
19 #include <framework/database/DBObjPtr.h>
20 #include <framework/datastore/StoreArray.h>
21 #include <framework/gearbox/Unit.h>
22 
23 namespace Belle2 {
29  class DatabaseRepresentationOfWeightfile;
30  class ECLConnectedRegion;
31  class ECLShower;
32  class ECLShowerShapeSecondMomentCorrection;
33 
34  namespace MVA {
35  class Expert;
36  class SingleDataset;
37  }
38 
39  namespace ECL {
40  class ECLNeighbours;
41  }
42 
47  class ECLShowerShapeModule : public Module {
48 
49  public:
50 
52  enum {
54  c_phiType = 1,
55  };
56 
57 
60 
63 
65  virtual void initialize() override;
66 
68  virtual void beginRun() override;
69 
71  virtual void event() override;
72 
74  virtual void endRun() override;
75 
77  virtual void terminate() override;
78 
79  private:
80 
83 
85  double energy;
86 
88  double rho;
89 
91  double alpha;
92  };
93 
96 
97  // Module Parameters
103  const double m_BRLthetaMin = 32.2 * Unit::deg;
104  const double m_BRLthetaMax = 128.7 * Unit::deg;
106  const unsigned int m_numZernikeMVAvariables = 22;
111  std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile>>
113  std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile>>
115  std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile>>
117  std::unique_ptr<MVA::Expert> m_expert_FWD;
118  std::unique_ptr<MVA::Expert> m_expert_BRL;
119  std::unique_ptr<MVA::Expert> m_expert_BWD;
120  std::unique_ptr<MVA::SingleDataset>
124  std::unique_ptr<ECL::ECLNeighbours> m_neighbourMap9;
125 
127  std::unique_ptr<ECL::ECLNeighbours> m_neighbourMap21;
128 
131  void initializeMVAweightFiles(const std::string& identifier,
132  std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile>>& weightFileRepresentation);
133 
137  void initializeMVA(const std::string& identifier,
138  std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile>>& weightFileRepresentation, std::unique_ptr<MVA::Expert>& expert);
139 
146  void setShowerShapeVariables(ECLShower* eclShower, const bool calculateZernikeMVA) const;
147 
149  double computeLateralEnergy(const std::vector<ProjectedECLDigit>& projectedDigits, const double avgCrystalDimension) const;
150 
165  double computeAbsZernikeMoment(const std::vector<ProjectedECLDigit>& projectedDigits, const double totalEnergy, const int n,
166  const int m,
167  const double rho) const;
168 
172  double computeSecondMoment(const std::vector<ProjectedECLDigit>& shower, const double totalEnergy) const;
173 
175  std::vector<ProjectedECLDigit> projectECLDigits(const ECLShower& shower) const;
176 
180  double Rnm(const int n, const int m, const double rho) const;
181 
186  std::complex<double> zernikeValue(const double rho, const double alpha, const int n, const int m) const;
187 
191  double computeE9oE21(const ECLShower&) const;
192 
196  double computeE1oE9(const ECLShower&) const;
197 
203 
209 
212  double getSecondMomentCorrection(const double theta, const double phi, const int hypothesis) const;
213 
214  public:
218  virtual const char* eclShowerArrayName() const
219  { return "ECLShowers" ; }
220 
222  virtual const char* eclCalDigitArrayName() const
223  { return "ECLCalDigits" ; }
224 
226  virtual const char* eclConnectedRegionArrayName() const
227  { return "ECLConnectedRegions" ; }
228 
229  }; // end of ECLShowerShapeModule
230 
231 
234  public:
235 
237  virtual const char* eclShowerArrayName() const override
238  { return "ECLShowersPureCsI" ; }
239 
241  virtual const char* eclCalDigitArrayName() const override
242  { return "ECLCalDigitsPureCsI" ; }
243 
245  virtual const char* eclConnectedRegionArrayName() const override
246  { return "ECLConnectedRegionsPureCsI" ; }
247 
248  }; // end of ECLShowerShapePureCsIModule
249 
251 } // end of Belle2 namespace
Class for accessing arrays of objects in the database.
Definition: DBArray.h:26
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Class to perform the shower correction.
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfile_representation_BWD
Database pointer to the Database representation of the Zernike moment MVA weightfile for BWD.
double computeAbsZernikeMoment(const std::vector< ProjectedECLDigit > &projectedDigits, const double totalEnergy, const int n, const int m, const double rho) const
Compute the absolute value of the complex Zernike moment Znm.
const double m_BRLthetaMin
Minimum theta of barrel used for choosing which Zernike MVA to apply.
DBArray< ECLShowerShapeSecondMomentCorrection > m_secondMomentCorrectionArray
Shower shape corrections from DB.
std::string m_zernike_MVAidentifier_FWD
Zernike moment MVA - FWD endcap weight-file.
std::unique_ptr< MVA::Expert > m_expert_BRL
Pointer to the current MVA Expert for BRL.
StoreArray< ECLConnectedRegion > m_eclConnectedRegions
StoreArray ECLConnectedRegion.
std::unique_ptr< MVA::SingleDataset > m_dataset
Pointer to the current dataset.
virtual void initialize() override
Initialize.
double computeE1oE9(const ECLShower &) const
Shower shape variable: E1oE9 The energy ratio is calculated taking the weighted central (=1) and the ...
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfile_representation_BRL
Database pointer to the Database representation of the Zernike moment MVA weightfile for BRL.
virtual void event() override
Event.
std::unique_ptr< ECL::ECLNeighbours > m_neighbourMap9
Neighbour map 9 neighbours, for E9oE21 and E1oE9.
double getSecondMomentCorrection(const double theta, const double phi, const int hypothesis) const
Get corrections for second moment.
bool m_zernike_useFarCrystals
Determines if to include or ignore crystals with rho > rho0 in perpendicular plane,...
virtual const char * eclShowerArrayName() const
We need names for the data objects to differentiate between PureCsI and default.
virtual void endRun() override
End run.
std::vector< ProjectedECLDigit > projectECLDigits(const ECLShower &shower) const
Compute projections of the ECLCalDigits to the perpendicular plane.
void initializeMVAweightFiles(const std::string &identifier, std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile >> &weightFileRepresentation)
initialize MVA weight files from DB
virtual void terminate() override
Terminate.
std::unique_ptr< MVA::Expert > m_expert_FWD
Pointer to the current MVA Expert for FWD.
const double m_BRLthetaMax
Maximum theta of barrel used for choosing which Zernike MVA to apply.
const unsigned int m_numZernikeMVAvariables
number of variables expected in the Zernike MVA weightfile
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfile_representation_FWD
Database pointer to the Database representation of the Zernike moment MVA weightfile for FWD.
double computeSecondMoment(const std::vector< ProjectedECLDigit > &shower, const double totalEnergy) const
Compute the second moment in the plane perpendicular to the direction of the shower.
virtual void beginRun() override
Begin run.
std::complex< double > zernikeValue(const double rho, const double alpha, const int n, const int m) const
Return the complex value of the Zernike polynomial of rank n,m.
TGraph m_secondMomentCorrections[2][10]
TGraphs that hold the corrections.
std::unique_ptr< ECL::ECLNeighbours > m_neighbourMap21
Neighbour map 21 neighbours, for E9oE21.
double Rnm(const int n, const int m, const double rho) const
The radial part of the Zernike polynomial n,m - Zernike polynomial rank rho - radial distance
double m_zernike_n1_rho0
Scaling factor for radial distances in perpendicular plane, used in Zernike moment calculation for N1...
void prepareSecondMomentCorrectionsCallback()
Prepare corrections for second moment Will be called whenever the m_secondMomentCorrectionArray get u...
void setShowerShapeVariables(ECLShower *eclShower, const bool calculateZernikeMVA) const
Set showr shape variables.
double m_zernike_n2_rho0
Scaling factor for radial distances in perpendicular plane, used in Zernike moment calculation for N2...
std::string m_zernike_MVAidentifier_BRL
Zernike moment MVA - Barrel weight-file.
double m_avgCrystalDimension
Average crystal dimension [cm].
std::string m_zernike_MVAidentifier_BWD
Zernike moment MVA - BWD endcap weight-file.
double computeLateralEnergy(const std::vector< ProjectedECLDigit > &projectedDigits, const double avgCrystalDimension) const
Shower shape variable: Lateral energy.
virtual const char * eclCalDigitArrayName() const
Default name ECLCalDigits.
std::unique_ptr< MVA::Expert > m_expert_BWD
Pointer to the current MVA Expert for BWD.
double computeE9oE21(const ECLShower &) const
Shower shape variable: E9oE21 The energy ratio is calculated taking the weighted 3x3 (=9) and the wei...
@ c_phiType
type of phi identifier
@ c_thetaType
type of theta identifier
void initializeMVA(const std::string &identifier, std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile >> &weightFileRepresentation, std::unique_ptr< MVA::Expert > &expert)
Load MVA weight file and set pointer of expert.
virtual const char * eclConnectedRegionArrayName() const
Default name ECLConnectedRegions.
The very same module but for PureCsI.
virtual const char * eclConnectedRegionArrayName() const override
PureCsI name ECLConnectedRegionsPureCsI.
virtual const char * eclShowerArrayName() const override
PureCsI name ECLShowersPureCsI.
virtual const char * eclCalDigitArrayName() const override
PureCsI name ECLCalDigitsPureCsI.
Class to store ECL Showers.
Definition: ECLShower.h:30
Base class for Modules.
Definition: Module.h:72
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
static const double deg
degree to radians
Definition: Unit.h:109
Abstract base class for different kinds of events.
Struct used to hold information of the digits projected to a plane perpendicular to the shower direct...