Belle II Software  release-08-00-05
eclAutocovarianceCalibrationC3Collector.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/eclAutocovarianceCalibrationC3Collector/eclAutocovarianceCalibrationC3Collector.h>
11 
12 #include <iostream>
13 //Framework
14 #include <framework/dataobjects/EventMetaData.h>
15 
16 //ECL
17 #include <ecl/dataobjects/ECLDsp.h>
18 #include <ecl/dbobjects/ECLCrystalCalib.h>
19 
20 using namespace std;
21 using namespace Belle2;
22 
23 //-----------------------------------------------------------------
24 // Register the Modules
25 //-----------------------------------------------------------------
26 REG_MODULE(eclAutocovarianceCalibrationC3Collector);
27 //-----------------------------------------------------------------
28 // Implementation
29 //-----------------------------------------------------------------
30 
31 // constructor
32 eclAutocovarianceCalibrationC3CollectorModule::eclAutocovarianceCalibrationC3CollectorModule() : CalibrationCollectorModule(),
33  m_ECLAutocovarianceCalibrationC1Threshold("ECLAutocovarianceCalibrationC1Threshold"),
34  m_ECLAutocovarianceCalibrationC2Baseline("ECLAutocovarianceCalibrationC2Baseline")
35 {
36  // Set module properties
37  setDescription("Module to compute covarience matrix using waveforms from delayed Bhabha events");
39 }
40 
42 {
43 
46  CovarianceMatrixInfoVsCrysID = new TH2F("CovarianceMatrixInfoVsCrysID", "", ECLElementNumbers::c_NCrystals, 0,
48 
49  registerObject<TH2F>("CovarianceMatrixInfoVsCrysID", CovarianceMatrixInfoVsCrysID);
50 
51  m_eclDsps.isRequired();
52 
53 }
54 
56 {
58  B2INFO("eclAutocovarianceCalibrationC3Collector: Experiment = " << m_evtMetaData->getExperiment() << " run = " <<
59  m_evtMetaData->getRun());
60 
62 
64 
65 }
66 
67 
69 {
70 
71  std::vector<float> m_tempArray;
73  const int NumDsp = m_eclDsps.getEntries();
74 
75  //Random Trigger Events have waveform for each crystal
76  if (NumDsp == ECLElementNumbers::c_NCrystals) {
77 
78  for (auto& aECLDsp : m_eclDsps) {
79 
80  const int id = aECLDsp.getCellId() - 1;
81 
82  //Peak to peak amplitude used to gauge noise level
83  float PeakToPeak = (float) aECLDsp.computePeaktoPeakAmp();
84 
85  if (PeakToPeak < m_PeakToPeakThresholds[id]) {
86 
87  float baseline = m_Baselines[id];
88 
89  // Computing baseline subtracted waveform
90  m_tempArray.clear();
91  for (int i = 0; i < m_nADCWaveformPoints; i++) m_tempArray.push_back(aECLDsp.getDspA()[i] - baseline);
92 
93  /*
94  Info on convariance matrix calucation:
95 
96  We store only nADCWaveformPoints numbers because there are several symmetries:
97  - In general the matrix is nADCWaveformPointsxnADCWaveformPoints, however, the matrix symmetric so we only compute the upper part of the matrix.
98  - We also assume the noise is random in time. With this assumption the values of each matrix diagonal will be the same. This allows us to define the matrix with only nADCWaveformPoints numbers: One for each diagonal (starting with the main diagonal)
99  I divide by (nADCWaveformPoints - (i-j)) to average over the number of off-diagonal elements for each row.
100  Using the final nADCWaveformPoints numbers the full nADCWaveformPointsxnADCWaveformPoints matrix in constructed by:
101  Element 0 is the nADCWaveformPoints main diagonals
102  Element 1 is the value of the 30 off diagonals
103  */
104 
105  for (int i = 0; i < m_nADCWaveformPoints; i++) {
106 
107  float value_i = m_tempArray[i];
108 
109  for (int j = i; j < m_nADCWaveformPoints; j++) {
110 
111  int tempIndex = abs(i - j);
112 
113  m_CovarianceMatrixInfoVsCrysIDHistogram[id][tempIndex] += (value_i * m_tempArray[j]);
114 
115  }
116  }
118  }
119  }
120  }
121 
122 }
123 
125 {
126  for (int i = 0; i < ECLElementNumbers::c_NCrystals; i++) {
127  for (int j = 0; j < (m_nADCWaveformPoints + 1); j++) {
128  getObjectPtr<TH2>("CovarianceMatrixInfoVsCrysID")->SetBinContent(i + 1, j + 1, m_CovarianceMatrixInfoVsCrysIDHistogram[i][j]);
129  }
130  }
131 }
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
StoreArray< ECLDsp > m_eclDsps
Required input array of ECLDSPs.
float m_CovarianceMatrixInfoVsCrysIDHistogram[ECLElementNumbers::c_NCrystals][m_nADCWaveformPoints+1]
container for coveriance matrix
TH2F * CovarianceMatrixInfoVsCrysID
result returned by collector that contains the coveriance matrix for each crystal
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< 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.