Belle II Software  release-08-00-04
eclAutocovarianceCalibrationC4Collector.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/eclAutocovarianceCalibrationC4Collector/eclAutocovarianceCalibrationC4Collector.h>
11 
12 //Root
13 #include <TDecompChol.h>
14 
15 //Framework
16 #include <framework/dataobjects/EventMetaData.h>
17 
18 //ECL
19 #include <ecl/dataobjects/ECLDsp.h>
20 #include <ecl/dbobjects/ECLCrystalCalib.h>
21 
22 using namespace std;
23 using namespace Belle2;
24 
25 //-----------------------------------------------------------------
26 // Register the Modules
27 //-----------------------------------------------------------------
28 REG_MODULE(eclAutocovarianceCalibrationC4Collector);
29 
30 //-----------------------------------------------------------------
31 // Implementation
32 //-----------------------------------------------------------------
33 
34 // constructor
35 eclAutocovarianceCalibrationC4CollectorModule::eclAutocovarianceCalibrationC4CollectorModule() : CalibrationCollectorModule(),
36  m_ECLAutocovarianceCalibrationC1Threshold("ECLAutocovarianceCalibrationC1Threshold"),
37  m_ECLAutocovarianceCalibrationC2Baseline("ECLAutocovarianceCalibrationC2Baseline"),
38  m_ECLAutocovarianceCalibrationC3Autocovariances("ECLAutoCovariance")
39 {
40  // Set module properties
41  setDescription("Module to test covariance matrix calibrations using waveforms from delayed Bhabha events");
43 }
44 
46 {
47 
52  registerObject<TH2F>("Chi2VsCrysID", Chi2VsCrysID);
53 
54  m_eclDsps.isRequired();
55 
56 }
57 
59 {
61  B2INFO("eclAutocovarianceCalibrationC4Collector: Experiment = " << m_evtMetaData->getExperiment() << " run = " <<
62  m_evtMetaData->getRun());
63 
66 
67  std::vector<double> buf(m_numberofADCPoints);
68 
70 
71  for (int id = 0; id < ECLElementNumbers::c_NCrystals; id++) {
72  m_ECLAutocovarianceCalibrationC3Autocovariances->getAutoCovariance(id + 1, buf.data());
74  for (int i = 0; i < m_numberofADCPoints; i++) {
75  for (int j = 0; j < m_numberofADCPoints; j++) {
76  m_NoiseMatrix[id](i, j) = buf[abs(i - j)];
77  }
78  }
79  TDecompChol dc(m_NoiseMatrix[id]);
80  bool InvertStatus = dc.Invert(m_NoiseMatrix[id]);
81 
82  if (InvertStatus == 0) {
83  B2INFO("Invert Failed for " << id);
84  }
85 
86  }
87 
88 }
89 
90 
92 {
93 
94  const int NumDsp = m_eclDsps.getEntries();
95 
96  //Random Trigger Events have waveform for each crystal
97  if (NumDsp == ECLElementNumbers::c_NCrystals) {
98 
99  for (auto& aECLDsp : m_eclDsps) {
100 
101  const int id = aECLDsp.getCellId() - 1;
102 
103  //Peak to peak amplitude used to gauge noise level
104  float PeakToPeak = (float) aECLDsp.computePeaktoPeakAmp();
105 
106  if (PeakToPeak < m_PeakToPeakThresholds[id]) {
107 
108  //Computing baselinw subtracted waveform. aECLDsp.getDspA() is the raw ECLDsp waveform.
109  vector<double> waveform(m_numberofADCPoints);
110  //for (int i = 0; i < m_numberofADCPoints; i++) waveform[i] = aECLDsp.getDspA()[i] - baseline;
111  for (int i = 0; i < m_numberofADCPoints; i++) waveform[i] = aECLDsp.getDspA()[i];
112 
113  //After subtraccting baseline, expected value is 0. Assuming noise is properly modelld by the cov. mat. (computed by this calibration) then a "fit" to a constant should give a good chi2. Below computes the resulting chi2 for a fit to 0 and used the calibrated cov. mat. to model the noise.
114 
115  // chi^2(B) = a*B^2 - 2*B*b + c
116  double aconst = 0, bconst = 0, cconst = 0;
117  for (int i = 0; i < 31; i++) {
118  double sum = 0, sumQ = 0;
119  for (int j = 0; j < 31; j++) {
120  sum += m_NoiseMatrix[id](i, j);
121  sumQ += m_NoiseMatrix[id](i, j) * waveform[j];
122  }
123  aconst += sum;
124  bconst += sum * waveform[i];
125  cconst += sumQ * waveform[i];
126  }
127 
128  const double Bconst = bconst / aconst;
129  const double chi2val = ((aconst * Bconst - 2 * bconst) * Bconst + cconst);
130 
131  Chi2VsCrysID->Fill(id, chi2val);
132  }
133 
134  }
135  }
136 }
137 
139 {
140  for (int i = 0; i < ECLElementNumbers::c_NCrystals; i++) {
141  for (int j = 0; j < m_NbinsForChi2Histogram; j++) {
142  getObjectPtr<TH2>("Chi2VsCrysID")->SetBinContent(i + 1, j + 1, Chi2VsCrysID->GetBinContent(i + 1, j + 1));
143  }
144  }
145 }
Calibration collector module base class.
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
std::vector< TMatrixDSym > m_NoiseMatrix
Stores noise matrix derived from the input Autocovariances.
StoreArray< ECLDsp > m_eclDsps
Required input array of ECLDSPs.
std::vector< float > m_Baselines
vector of thresholds obtained from DB object
DBObjPtr< ECLCrystalCalib > m_ECLAutocovarianceCalibrationC1Threshold
thresholds obtained from C1 stage
void collect() override
Select events and crystals and accumulate histograms.
StoreObjPtr< EventMetaData > m_evtMetaData
dataStore EventMetaData
std::vector< float > m_PeakToPeakThresholds
vector of thresholds obtained from DB object
void closeRun() override
Transfer fom array container to ROOT histogram.
void prepare() override
Define histograms and read payloads from DB.
DBObjPtr< ECLAutoCovariance > m_ECLAutocovarianceCalibrationC3Autocovariances
Autocovariances obtained from C3 stage.
DBObjPtr< ECLCrystalCalib > m_ECLAutocovarianceCalibrationC2Baseline
baselines obtained from C2 stage
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.