Project
Loading...
Searching...
No Matches
testPedestalProcessorData.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#define BOOST_TEST_MODULE Test_EMCAL_Calibration
12#define BOOST_TEST_MAIN
13#define BOOST_TEST_DYN_LINK
14
15#include <random>
16#include <boost/test/unit_test.hpp>
18#include <TH1.h>
19#include <TProfile.h>
20#include <TRandom.h>
21
22namespace o2
23{
24
25namespace emcal
26{
27
28const int NUMBERFECCHANNELS = 17664,
30
31void compare(const PedestalProcessorData& testobject, const TProfile& refFECHG, const TProfile& refFECLG, const TProfile& refLEDMONHG, const TProfile& refLEDMONLG, bool testCount, bool verbose)
32{
33 const double PRECISION = FLT_EPSILON;
34 const double PRECISIONMEAN = FLT_EPSILON;
35 for (std::size_t ichan = 0; ichan < NUMBERFECCHANNELS; ichan++) {
36 auto [meanHG, rmsHG] = testobject.getValue(ichan, false, false);
37 auto [meanLG, rmsLG] = testobject.getValue(ichan, true, false);
38 if (verbose) {
39 std::cout << "Channel " << ichan << ", mean HG " << meanHG << ", RMS HG " << std::sqrt(rmsHG) << ", entries HG " << testobject.getEntriesForChannel(ichan, false, false) << " ref(mean " << refFECHG.GetBinContent(ichan + 1) << ", RMS " << refFECHG.GetBinError(ichan + 1) << ", entries " << refFECHG.GetBinEntries(ichan + 1) << ")" << std::endl;
40 std::cout << "Channel " << ichan << ", mean LG " << meanLG << ", RMS LG " << std::sqrt(rmsLG) << ", entries LG " << testobject.getEntriesForChannel(ichan, true, false) << " ref(mean " << refFECLG.GetBinContent(ichan + 1) << ", RMS " << refFECLG.GetBinError(ichan + 1) << ", entries " << refFECLG.GetBinEntries(ichan + 1) << ")" << std::endl;
41 }
42 BOOST_CHECK_LE(std::abs(meanHG - refFECHG.GetBinContent(ichan + 1)), PRECISIONMEAN);
43 BOOST_CHECK_LE(std::abs(meanLG - refFECLG.GetBinContent(ichan + 1)), PRECISIONMEAN);
44 BOOST_CHECK_LE(std::abs(std::sqrt(rmsHG) - refFECHG.GetBinError(ichan + 1)), PRECISION);
45 BOOST_CHECK_LE(std::abs(std::sqrt(rmsLG) - refFECLG.GetBinError(ichan + 1)), PRECISION);
46 if (testCount) {
47 BOOST_CHECK_EQUAL(testobject.getEntriesForChannel(ichan, false, false), refFECHG.GetBinEntries(ichan + 1));
48 BOOST_CHECK_EQUAL(testobject.getEntriesForChannel(ichan, true, false), refFECLG.GetBinEntries(ichan + 1));
49 }
50 }
51 for (std::size_t ichan = 0; ichan < NUMBERLEDMONCHANNELS; ichan++) {
52 auto [meanHG, rmsHG] = testobject.getValue(ichan, false, true);
53 auto [meanLG, rmsLG] = testobject.getValue(ichan, true, true);
54 if (verbose) {
55 std::cout << "LEDMON " << ichan << ", mean HG " << meanHG << ", RMS HG " << std::sqrt(rmsHG) << ", entries HG " << testobject.getEntriesForChannel(ichan, false, true) << " ref(mean " << refLEDMONHG.GetBinContent(ichan + 1) << ", RMS " << refLEDMONHG.GetBinError(ichan + 1) << ", entries " << refLEDMONHG.GetBinEntries(ichan + 1) << ")" << std::endl;
56 std::cout << "LEDMON " << ichan << ", mean LG " << meanLG << ", RMS LG " << std::sqrt(rmsLG) << ", entries LG " << testobject.getEntriesForChannel(ichan, true, true) << " ref(mean " << refLEDMONLG.GetBinContent(ichan + 1) << ", RMS " << refLEDMONLG.GetBinError(ichan + 1) << ", entries " << refLEDMONLG.GetBinEntries(ichan + 1) << ")" << std::endl;
57 }
58 BOOST_CHECK_LE(std::abs(meanHG - refLEDMONHG.GetBinContent(ichan + 1)), PRECISIONMEAN);
59 BOOST_CHECK_LE(std::abs(meanLG - refLEDMONLG.GetBinContent(ichan + 1)), PRECISIONMEAN);
60 BOOST_CHECK_LE(std::abs(std::sqrt(rmsHG) - refLEDMONHG.GetBinError(ichan + 1)), PRECISION);
61 BOOST_CHECK_LE(std::abs(std::sqrt(rmsLG) - refLEDMONLG.GetBinError(ichan + 1)), PRECISION);
62 if (testCount) {
63 BOOST_CHECK_EQUAL(testobject.getEntriesForChannel(ichan, false, true), refLEDMONHG.GetBinEntries(ichan + 1));
64 BOOST_CHECK_EQUAL(testobject.getEntriesForChannel(ichan, true, true), refLEDMONLG.GetBinEntries(ichan + 1));
65 }
66 }
67}
68
69BOOST_AUTO_TEST_CASE(testPedestalProcessorData)
70{
71 // we compare with RMS, so the
72 TProfile refFECHG("refFECHG", "Reference FEC HG", NUMBERFECCHANNELS, -0.5, NUMBERFECCHANNELS - 0.5, "s"),
73 refFECLG("refFECLG", "Reference FEC LG", NUMBERFECCHANNELS, -0.5, NUMBERFECCHANNELS - 0.5, "s"),
74 refLEDMONHG("refLEDMONHG", "Reference LEDMON HG", NUMBERLEDMONCHANNELS, -0.5, NUMBERLEDMONCHANNELS - 0.5, "s"),
75 refLEDMONLG("refLEDMONLG", "Reference LEDMON LG", NUMBERLEDMONCHANNELS, -0.5, NUMBERLEDMONCHANNELS - 0.5, "s");
76 refFECHG.Sumw2();
77 refFECLG.Sumw2();
78 refLEDMONHG.Sumw2();
79 refLEDMONLG.Sumw2();
80
81 PedestalProcessorData testobject;
82
83 const int NUMBERALTROSAMPLES = 15;
84 for (auto iev = 0; iev < 1000; iev++) {
85 for (int ichan = 0; ichan < NUMBERFECCHANNELS; ichan++) {
86 for (int isample = 0; isample < 15; isample++) {
87 // short adc_hg = static_cast<short>(adcGeneratorHG(gen)),
88 // adc_lg = static_cast<short>(adcGeneratorLG(gen));
89 auto raw_hg = gRandom->Gaus(40, 6),
90 raw_lg = gRandom->Gaus(36, 10);
91 unsigned short adc_hg = static_cast<unsigned short>(raw_hg > 0 ? raw_hg : 0),
92 adc_lg = static_cast<unsigned short>(raw_lg > 0 ? raw_lg : 0);
93 refFECHG.Fill(ichan, adc_hg);
94 refFECLG.Fill(ichan, adc_lg);
95 testobject.fillADC(adc_hg, ichan, false, false);
96 testobject.fillADC(adc_lg, ichan, true, false);
97 }
98 }
99 }
100 for (auto iev = 0; iev < 1000; iev++) {
101 for (int ichan = 0; ichan < NUMBERLEDMONCHANNELS; ichan++) {
102 for (int isample = 0; isample < 15; isample++) {
103 // short adc_hg = static_cast<short>(adcGeneratorLEDMONHG(gen)),
104 // adc_lg = static_cast<short>(adcGeneratorLEDMONLG(gen));
105 auto raw_hg = gRandom->Gaus(40, 6),
106 raw_lg = gRandom->Gaus(36, 10);
107 unsigned short adc_hg = static_cast<unsigned short>(raw_hg > 0 ? raw_hg : 0),
108 adc_lg = static_cast<unsigned short>(raw_lg > 0 ? raw_lg : 0);
109 refLEDMONHG.Fill(ichan, adc_hg);
110 refLEDMONLG.Fill(ichan, adc_lg);
111 testobject.fillADC(adc_hg, ichan, false, true);
112 testobject.fillADC(adc_lg, ichan, true, true);
113 }
114 }
115 }
116
117 // Compare channels
118 compare(testobject, refFECHG, refFECLG, refLEDMONHG, refLEDMONLG, true, false);
119
120 // Test operator+
121 auto testdoubled = testobject + testobject;
122 TProfile refFECHGdouble(refFECHG),
123 refFECLGdouble(refFECLG),
124 refLEDMONHGdouble(refLEDMONHG),
125 refLEDMONLGdouble(refLEDMONLG);
126 refFECHGdouble.Add(&refFECHG);
127 refFECLGdouble.Add(&refFECLG);
128 refLEDMONHGdouble.Add(&refLEDMONHG);
129 refLEDMONLGdouble.Add(&refLEDMONLG);
130 compare(testdoubled, refFECHGdouble, refFECLGdouble, refLEDMONHGdouble, refLEDMONLGdouble, false, false);
131
132 // Test reset function
133 auto testreset = testobject;
134 testreset.reset();
135 for (std::size_t ichan = 0; ichan < NUMBERFECCHANNELS; ichan++) {
136 auto [meanHG, rmsHG] = testreset.getValue(ichan, false, false);
137 auto [meanLG, rmsLG] = testreset.getValue(ichan, true, false);
138 BOOST_CHECK_EQUAL(meanHG, 0.);
139 BOOST_CHECK_EQUAL(meanLG, 0.);
140 BOOST_CHECK_EQUAL(testreset.getEntriesForChannel(ichan, false, false), 0);
141 BOOST_CHECK_EQUAL(testreset.getEntriesForChannel(ichan, true, false), 0);
142 }
143 for (std::size_t ichan = 0; ichan < NUMBERLEDMONCHANNELS; ichan++) {
144 auto [meanHG, rmsHG] = testreset.getValue(ichan, false, true);
145 auto [meanLG, rmsLG] = testreset.getValue(ichan, true, true);
146 BOOST_CHECK_EQUAL(meanHG, 0.);
147 BOOST_CHECK_EQUAL(meanLG, 0.);
148 BOOST_CHECK_EQUAL(testreset.getEntriesForChannel(ichan, false, true), 0);
149 BOOST_CHECK_EQUAL(testreset.getEntriesForChannel(ichan, true, true), 0);
150 }
151}
152
153} // namespace emcal
154
155} // namespace o2
Exchange container between PedestalProcessorDevice and PedestalAggregatorDevice.
int getEntriesForChannel(unsigned short tower, bool lowGain, bool LEDMON) const
Get number of entries for a certain channel.
void fillADC(unsigned short adc, unsigned short tower, bool lowGain, bool LEDMON)
Fill ADC value for certain channel.
PedestalValue getValue(unsigned short tower, bool lowGain, bool LEDMON) const
Get mean ADC and RMS for a certain channel.
BOOST_AUTO_TEST_CASE(asynch_schedule_test)
void compare(const PedestalProcessorData &testobject, const TProfile &refFECHG, const TProfile &refFECLG, const TProfile &refLEDMONHG, const TProfile &refLEDMONLG, bool testCount, bool verbose)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())