Belle II Software  release-08-01-10
ECLCovarianceMatrixModule.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 // THIS MODULE
10 #include <ecl/modules/eclCovarianceMatrix/ECLCovarianceMatrixModule.h>
11 
12 // ROOT
13 #include "TMath.h"
14 
15 // MDST
16 #include <mdst/dataobjects/EventLevelClusteringInfo.h>
17 
18 // ECL
19 #include <ecl/dataobjects/ECLShower.h>
20 
21 // NAMESPACES
22 using namespace Belle2;
23 
24 //-----------------------------------------------------------------
25 // Register the Module
26 //-----------------------------------------------------------------
27 REG_MODULE(ECLCovarianceMatrix);
28 REG_MODULE(ECLCovarianceMatrixPureCsI);
29 
30 //-----------------------------------------------------------------
31 // Implementation
32 //-----------------------------------------------------------------
34  m_eclShowers(eclShowerArrayName()),
35  m_eventLevelClusteringInfo(eventLevelClusteringInfoName())
36 {
37  // Set description
38  setDescription("ECLCovarianceMatrix: Sets the ECL photon shower covariance matrix.");
40 
41 }
42 
44 {
45 }
46 
48 {
49  // Register in datastore
50  m_eclShowers.registerInDataStore(eclShowerArrayName());
52 }
53 
55 {
56  // TODO: callback
57  ;
58 }
59 
61 {
62 
63  // Get the event background level
64  const int bkgdcount = m_eventLevelClusteringInfo->getNECLCalDigitsOutOfTime();
65  double background = 0.0; // from out of time digit counting
66  if (m_fullBkgdCount > 0) {
67  background = static_cast<double>(bkgdcount) / m_fullBkgdCount;
68  }
69 
70  // loop over all ECLShowers
71  for (auto& eclShower : m_eclShowers) {
72 
73  // Only calculate for photon showers
74  if (eclShower.getHypothesisId() == ECLShower::c_nPhotons) {
75 
76  const double energy = eclShower.getEnergy();
77 
78  // 1/energy
79  double invEnergy = 0;
80  if (energy > 0.) invEnergy = 1. / energy;
81 
82  //1/energy^0.5
83  double invRoot2Energy = 0;
84  if (energy > 0.) invRoot2Energy = 1. / TMath::Power(energy, 0.5);
85 
86  //1/energy^0.25
87  double invRoot4Energy = 0;
88  if (energy > 0.) invRoot4Energy = 1. / TMath::Power(energy, 0.25);
89 
90  int detregion = eclShower.getDetectorRegion(); // FWD: 1, Barrel: 2, BWD: 3
91  if (detregion == 11 or detregion == 13) detregion = 2;
92 
93  double sigmaEnergy = 0.;
94  double sigmaTheta = 0.;
95  double sigmaPhi = 0.;
96 
97  // three background levels, three detector regions, energy, theta and phi (needs to be revisited soon!)
98  if (detregion == 1 and background < 0.05) {
99  if (energy <= 0.022) {sigmaEnergy = energy * (0.0449188); }
100  else {sigmaEnergy = energy * (-0.0912379 * invEnergy + 1.91849 * invRoot2Energy + -2.82169 * invRoot4Energy + 3.03119) / 100.;}
101  } else if (detregion == 1 and background <= 0.3) {
102  if (energy <= 0.022) {sigmaEnergy = energy * (0.100769); }
103  else {sigmaEnergy = energy * (-0.0725928 * invEnergy + 3.4685 * invRoot2Energy + -5.44127 * invRoot4Energy + 4.12045) / 100.;}
104  } else if (detregion == 1 and background > 0.3) {
105  if (energy <= 0.022) {sigmaEnergy = energy * (0.148462); }
106  else {sigmaEnergy = energy * (-0.239931 * invEnergy + 6.94958 * invRoot2Energy + -10.4085 * invRoot4Energy + 5.92412) / 100.;}
107  }
108 
109  if (detregion == 1 and background < 0.05) {
110  if (energy <= 0.0289609) { sigmaTheta = 1e-3 * (6.4008);}
111  else {sigmaTheta = 1e-3 * (-0.110397 * invEnergy + 0.753603 * invRoot2Energy + 2.63652 * invRoot4Energy + -0.606703);}
112  } else if (detregion == 1 and background <= 0.3) {
113  if (energy <= 0.0274562) { sigmaTheta = 1e-3 * (7.39868);}
114  else {sigmaTheta = 1e-3 * (-0.207278 * invEnergy + 2.68616 * invRoot2Energy + -0.905487 * invRoot4Energy + 0.961485);}
115  } else if (detregion == 1 and background > 0.3) {
116  if (energy <= 0.022) { sigmaTheta = 1e-3 * (8.83505);}
117  else {sigmaTheta = 1e-3 * (-0.160921 * invEnergy + 2.35311 * invRoot2Energy + -0.107975 * invRoot4Energy + 0.565367);}
118  }
119 
120  if (detregion == 1 and background < 0.05) {
121  if (energy <= 0.0391279) {sigmaPhi = 1e-3 * (15.4147);}
122  else {sigmaPhi = 1e-3 * (-0.35934 * invEnergy + 2.01807 * invRoot2Energy + 7.26313 * invRoot4Energy + -1.93438);}
123  } else if (detregion == 1 and background <= 0.3) {
124  if (energy <= 0.022) {sigmaPhi = 1e-3 * (18.1096);}
125  else {sigmaPhi = 1e-3 * (-0.178258 * invEnergy + 1.39155 * invRoot2Energy + 6.97462 * invRoot4Energy + -1.2795);}
126  } else if (detregion == 1 and background > 0.3) {
127  if (energy <= 0.0224565) {sigmaPhi = 1e-3 * (20.1605);}
128  else {sigmaPhi = 1e-3 * (-0.344617 * invEnergy + 3.80823 * invRoot2Energy + 4.08729 * invRoot4Energy + -0.464714);}
129  }
130 
131  if (detregion == 2 and background < 0.05) {
132  if (energy <= 0.022) {sigmaEnergy = energy * (0.0466552); }
133  else {sigmaEnergy = energy * (-0.0473491 * invEnergy + 1.02015 * invRoot2Energy + -0.705164 * invRoot4Energy + 1.77086) / 100.;}
134  } else if (detregion == 2 and background <= 0.3) {
135  if (energy <= 0.022) {sigmaEnergy = energy * (0.112299); }
136  else {sigmaEnergy = energy * (0.0469588 * invEnergy + 1.81959 * invRoot2Energy + -2.13666 * invRoot4Energy + 2.37568) / 100.;}
137  } else if (detregion == 2 and background > 0.3) {
138  if (energy <= 0.022) {sigmaEnergy = energy * (0.164881); }
139  else {sigmaEnergy = energy * (-0.267069 * invEnergy + 7.6176 * invRoot2Energy + -11.0341 * invRoot4Energy + 5.9203) / 100.;}
140  }
141 
142  if (detregion == 2 and background < 0.05) {
143  if (energy <= 0.0309077) { sigmaTheta = 1e-3 * (9.31098);}
144  else {sigmaTheta = 1e-3 * (-0.221073 * invEnergy + 2.19876 * invRoot2Energy + 1.50833 * invRoot4Energy + 0.359609);}
145  } else if (detregion == 2 and background <= 0.3) {
146  if (energy <= 0.022) { sigmaTheta = 1e-3 * (11.6166);}
147  else {sigmaTheta = 1e-3 * (-0.126603 * invEnergy + 1.81898 * invRoot2Energy + 1.85132 * invRoot4Energy + 0.300728);}
148  } else if (detregion == 2 and background > 0.3) {
149  if (energy <= 0.022) { sigmaTheta = 1e-3 * (13.159);}
150  else {sigmaTheta = 1e-3 * (-0.316561 * invEnergy + 4.94686 * invRoot2Energy + -3.12199 * invRoot4Energy + 2.30275);}
151  }
152 
153  if (detregion == 2 and background < 0.05) {
154  if (energy <= 0.0381178) {sigmaPhi = 1e-3 * (10.7661);}
155  else {sigmaPhi = 1e-3 * (-0.21842 * invEnergy + 0.648976 * invRoot2Energy + 7.1901 * invRoot4Energy + -3.10025);}
156  } else if (detregion == 2 and background <= 0.3) {
157  if (energy <= 0.022237) {sigmaPhi = 1e-3 * (12.6804);}
158  else {sigmaPhi = 1e-3 * (-0.141507 * invEnergy + 0.488293 * invRoot2Energy + 7.30055 * invRoot4Energy + -3.13591);}
159  } else if (detregion == 2 and background > 0.3) {
160  if (energy <= 0.024905) {sigmaPhi = 1e-3 * (14.8726);}
161  else {sigmaPhi = 1e-3 * (-0.323752 * invEnergy + 3.60933 * invRoot2Energy + 2.48526 * invRoot4Energy + -1.25493);}
162  }
163 
164  if (detregion == 3 and background < 0.05) {
165  if (energy <= 0.022) {sigmaEnergy = energy * (0.0466662); }
166  else {sigmaEnergy = energy * (-0.106729 * invEnergy + 2.38163 * invRoot2Energy + -4.11299 * invRoot4Energy + 4.14056) / 100.;}
167  } else if (detregion == 3 and background <= 0.3) {
168  if (energy <= 0.022) {sigmaEnergy = energy * (0.128851); }
169  else {sigmaEnergy = energy * (-0.204362 * invEnergy + 6.43 * invRoot2Energy + -10.8673 * invRoot4Energy + 7.04059) / 100.;}
170  } else if (detregion == 3 and background > 0.3) {
171  if (energy <= 0.022) {sigmaEnergy = energy * (0.255153); }
172  else {sigmaEnergy = energy * (-0.316245 * invEnergy + 11.5211 * invRoot2Energy + -18.3626 * invRoot4Energy + 9.89422) / 100.;}
173  }
174 
175  if (detregion == 3 and background < 0.05) {
176  if (energy <= 0.0318079) { sigmaTheta = 1e-3 * (10.4446);}
177  else {sigmaTheta = 1e-3 * (-0.295827 * invEnergy + 3.37748 * invRoot2Energy + -0.284446 * invRoot4Energy + 1.48098);}
178  } else if (detregion == 3 and background <= 0.3) {
179  if (energy <= 0.022) { sigmaTheta = 1e-3 * (13.828);}
180  else {sigmaTheta = 1e-3 * (-0.252479 * invEnergy + 4.18833 * invRoot2Energy + -2.04822 * invRoot4Energy + 2.38486);}
181  } else if (detregion == 3 and background > 0.3) {
182  if (energy <= 0.022) { sigmaTheta = 1e-3 * (17.0354);}
183  else {sigmaTheta = 1e-3 * (-0.420215 * invEnergy + 7.08904 * invRoot2Energy + -5.88269 * invRoot4Energy + 3.61643);}
184  }
185 
186  if (detregion == 3 and background < 0.05) {
187  if (energy <= 0.022) {sigmaPhi = 1e-3 * (15.129);}
188  else {sigmaPhi = 1e-3 * (-0.0534441 * invEnergy + -1.72466 * invRoot2Energy + 12.8625 * invRoot4Energy + -4.21203);}
189  } else if (detregion == 3 and background <= 0.3) {
190  if (energy <= 0.022) {sigmaPhi = 1e-3 * (20.1408);}
191  else {sigmaPhi = 1e-3 * (0.0869293 * invEnergy + -1.93352 * invRoot2Energy + 12.8105 * invRoot4Energy + -4.03756);}
192  } else if (detregion == 3 and background > 0.3) {
193  if (energy <= 0.022) {sigmaPhi = 1e-3 * (23.2771);}
194  else {sigmaPhi = 1e-3 * (-0.439611 * invEnergy + 5.74196 * invRoot2Energy + 1.76693 * invRoot4Energy + -0.0407866);}
195  }
196 
197  B2DEBUG(175, "energy=" << energy << ", detector region=" << detregion);
198  B2DEBUG(175, "sigmaEnergy=" << sigmaEnergy << ", sigmaPhi=" << sigmaPhi << ", sigmaTheta=" << sigmaTheta);
199 
200  double covMatrix[6] = {sigmaEnergy * sigmaEnergy, 0.0, sigmaPhi * sigmaPhi, 0.0, 0.0, sigmaTheta * sigmaTheta};
201  eclShower.setCovarianceMatrix(covMatrix);
202  }
203  }
204 }
205 
207 {
208  ;
209 }
210 
212 {
213  ;
214 }
const double m_fullBkgdCount
Nominal Background at BGx1.0 (MC12)
StoreArray< ECLShower > m_eclShowers
Store array: ECLShower.
virtual void initialize() override
Initialize.
virtual const char * eclShowerArrayName() const
Default name ECLShowers.
virtual void endRun() override
End run.
virtual void terminate() override
Terminate.
virtual void beginRun() override
Begin run.
virtual const char * eventLevelClusteringInfoName() const
Name to be used for default option: EventLevelClusteringInfo.
StoreObjPtr< EventLevelClusteringInfo > m_eventLevelClusteringInfo
Store object pointer: EventLevelClusteringInfo.
@ c_nPhotons
CR is split into n photons (N1)
Definition: ECLShower.h:42
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
REG_MODULE(arichBtest)
Register the Module.
Abstract base class for different kinds of events.