Project
Loading...
Searching...
No Matches
testFlatHisto.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
12#define BOOST_TEST_MODULE Test FlatHisto class
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
18#include <TFile.h>
19#include <TRandom.h>
20#include <TFitResult.h>
21#include <TH1F.h>
22#include <TH2F.h>
23
24namespace o2
25{
26
27// basic Vertex tests
29{
30 o2::dataformats::FlatHisto1D_f h1(100, -100., 100.);
31 o2::dataformats::FlatHisto2D_f h2(100, -100., 100., 50, -5., 45.);
32 for (int i = 0; i < 1000000; i++) {
33 h1.fill(gRandom->Gaus(10, 30));
34 }
35 auto h2ref = h2.createTH2F("h2ref");
36 for (int i = 0; i < 10000000; i++) {
37 auto x = gRandom->Gaus(10, 40), y = gRandom->Gaus(10, 10);
38 h2.fill(x, y);
39 h2ref->Fill(x, y);
40 }
41 auto th1f = h1.createTH1F();
42 auto res = th1f->Fit("gaus", "S");
43 BOOST_CHECK_CLOSE(res->GetParams()[1], 10, 0.2);
44
45 printf("%e %e\n", h2.getSum(), h2ref->Integral());
46 BOOST_CHECK(h2.getSum() == h2ref->Integral());
47
49
50 BOOST_CHECK_CLOSE(h1.getBinStart(0), -100, 1e-5);
51 BOOST_CHECK_CLOSE(h1.getBinEnd(h1.getNBins() - 1), 100, 1e-5);
52
53 BOOST_CHECK_CLOSE(h2.getBinXStart(0), -100, 1e-5);
54 BOOST_CHECK_CLOSE(h2.getBinYEnd(h2.getNBinsY() - 1), 45, 1e-5);
55 BOOST_CHECK_CLOSE(h2.getBinYStart(h2.getNBinsY() - 1), 45 - h2.getBinSizeY(), 1e-5);
56
57 BOOST_CHECK(h1.canFill() && h1v.canFill());
58 BOOST_CHECK(h1.getSum() == h1v.getSum());
59 {
60 TFile flout("flathisto.root", "recreate");
61 flout.WriteObjectAny(&h1, "o2::dataformats::FlatHisto1D_f", "h1");
62 flout.WriteObjectAny(&h2, "o2::dataformats::FlatHisto2D_f", "h2");
63 flout.Close();
64 }
65
66 TFile flin("flathisto.root");
67 o2::dataformats::FlatHisto1D_f* h1r = (o2::dataformats::FlatHisto1D_f*)flin.GetObjectUnchecked("h1");
68 o2::dataformats::FlatHisto2D_f* h2r = (o2::dataformats::FlatHisto2D_f*)flin.GetObjectUnchecked("h2");
69 flin.Close();
70 h1r->init();
71 h2r->init();
72
74 h1vv.adoptExternal(h1r->getView());
75 BOOST_CHECK(h1.getSum() == h1vv.getSum());
76 h1.add(h1vv);
77 h2.subtract(*h2r);
78 BOOST_CHECK(h1.getSum() == 2 * h1vv.getSum());
79 BOOST_CHECK(h2.getSum() == 0.);
80}
81
82} // namespace o2
1D messeageable histo class
2D messeageable histo class
int32_t i
uint32_t res
Definition RawData.h:0
void adoptExternal(const gsl::span< const T > ext)
std::unique_ptr< TH1F > createTH1F(const std::string &name="histo1d") const
void add(const FlatHisto1D &other)
T getBinStart(uint32_t i) const
Definition FlatHisto1D.h:98
T getBinEnd(uint32_t i) const
uint32_t getNBins() const
Definition FlatHisto1D.h:72
gsl::span< const T > getView() const
uint32_t getNBinsY() const
Definition FlatHisto2D.h:78
T getBinYEnd(uint32_t i) const
T getBinXStart(uint32_t i) const
void subtract(const FlatHisto2D &other)
std::unique_ptr< TH2F > createTH2F(const std::string &name="histo2d") const
T getBinYStart(uint32_t i) const
GLint GLenum GLint x
Definition glcorearb.h:403
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_AUTO_TEST_CASE(FlatHisto)
BOOST_CHECK(tree)