Project
Loading...
Searching...
No Matches
StepTHn.h
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#ifndef StepTHn_H
13#define StepTHn_H
14
15// optimized data container reusing functionality of THn
16// A THnSparse is used to have the axis functionality "for free"
17
18#include "TNamed.h"
19#include "THnSparse.h"
20#include "TAxis.h"
21#include "TArray.h"
22
23#include "Framework/Logger.h"
24
25class TArray;
26class TArrayF;
27class TArrayD;
28class TCollection;
29
30class StepTHn : public TNamed
31{
32 public:
33 StepTHn();
34 StepTHn(const Char_t* name, const Char_t* title, const Int_t nSteps, const Int_t nAxes);
35 ~StepTHn() override;
36
37 template <typename... Ts>
38 void Fill(int iStep, const Ts&... valuesAndWeight);
39 void Fill(int iStep, int nParams, double positionAndWeight[]);
40
41 THnBase* getTHn(Int_t step, Bool_t sparse = kFALSE)
42 {
43 if (!mTarget || !mTarget[step]) {
44 createTarget(step, sparse);
45 }
46 return mTarget[step];
47 }
48 Int_t getNSteps() { return mNSteps; }
49 Int_t getNVar() { return mNVars; }
50
51 TArray* getValues(Int_t step) { return mValues[step]; }
52 TArray* getSumw2(Int_t step) { return mSumw2[step]; }
53
54 StepTHn(const StepTHn& c);
55 StepTHn& operator=(const StepTHn& corr);
56 void Copy(TObject& c) const override;
57
58 virtual Long64_t Merge(TCollection* list) = 0;
59
60 TAxis* GetAxis(int i) { return mPrototype->GetAxis(i); }
61 void Sumw2(){}; // TODO: added for compatibiltiy with registry, but maybe it would be useful also in StepTHn as toggle for error weights
62
63 protected:
64 void init();
65 virtual TArray* createArray(const TArray* src = nullptr) const = 0;
66 void createTarget(Int_t step, Bool_t sparse);
67 void deleteContainers();
68
69 Long64_t getGlobalBinIndex(const Int_t* binIdx);
70
71 Long64_t mNBins; // number of total bins
72 Int_t mNVars; // number of variables
73 Int_t mNSteps; // number of selection steps
74 TArray** mValues; //[mNSteps] data container
75 TArray** mSumw2; //[mNSteps] data container
76
77 THnBase** mTarget;
78
79 TAxis** mAxisCache;
80 Int_t* mNbinsCache;
81 Double_t* mLastVars;
82 Int_t* mLastBins;
83
84 THnSparse* mPrototype; // not filled used as prototype histogram for axis functionality etc.
85
86 ClassDef(StepTHn, 1) // THn like container
87};
88
89template <class TemplateArray>
90class StepTHnT : public StepTHn
91{
92 public:
94 StepTHnT(const Char_t* name, const Char_t* title, const Int_t nSteps, const Int_t nAxes, Int_t* nBins, std::vector<Double_t> binEdges[], const char** axisTitles);
95 StepTHnT(const char* name, const char* title, const int nSteps, const int nAxes, const int* nBins, const double* xmin, const double* xmax);
96 ~StepTHnT() override = default;
97
98 Long64_t Merge(TCollection* list) override;
99
100 protected:
101 TArray* createArray(const TArray* src = nullptr) const override
102 {
103 if (src == nullptr) {
104 return new TemplateArray(mNBins);
105 } else {
106 return new TemplateArray(*((TemplateArray*)src));
107 }
108 }
109
110 ClassDef(StepTHnT, 1) // THn like container
111};
112
115
116template <typename... Ts>
117void StepTHn::Fill(int iStep, const Ts&... valuesAndWeight)
118{
119 constexpr int nArgs = sizeof...(Ts);
120 double tempArray[] = {static_cast<double>(valuesAndWeight)...};
121 Fill(iStep, nArgs, tempArray);
122}
123
124#endif
int32_t i
uint32_t c
Definition RawData.h:2
StepTHnT< TArrayF > StepTHnF
Definition StepTHn.h:113
StepTHnT< TArrayD > StepTHnD
Definition StepTHn.h:114
StepTHnT()
Definition StepTHn.h:93
TArray * createArray(const TArray *src=nullptr) const override
Definition StepTHn.h:101
~StepTHnT() override=default
Long64_t Merge(TCollection *list) override
Definition StepTHn.cxx:225
Double_t * mLastVars
cache Nbins per axis
Definition StepTHn.h:81
Int_t * mLastBins
caching of last used bins (in many loops some vars are the same for a while)
Definition StepTHn.h:82
Int_t getNSteps()
Definition StepTHn.h:48
void Fill(int iStep, const Ts &... valuesAndWeight)
Definition StepTHn.h:117
Int_t getNVar()
Definition StepTHn.h:49
StepTHn()
Definition StepTHn.cxx:32
Long64_t mNBins
Definition StepTHn.h:71
TAxis * GetAxis(int i)
Definition StepTHn.h:60
TArray ** mValues
Definition StepTHn.h:74
TAxis ** mAxisCache
target histogram
Definition StepTHn.h:79
Long64_t getGlobalBinIndex(const Int_t *binIdx)
Definition StepTHn.cxx:281
Int_t mNSteps
Definition StepTHn.h:73
StepTHn & operator=(const StepTHn &corr)
Definition StepTHn.cxx:180
virtual TArray * createArray(const TArray *src=nullptr) const =0
Int_t * mNbinsCache
cache axis pointers (about 50% of the time in Fill is spent in GetAxis otherwise)
Definition StepTHn.h:80
virtual Long64_t Merge(TCollection *list)=0
void deleteContainers()
Definition StepTHn.cxx:158
void createTarget(Int_t step, Bool_t sparse)
Definition StepTHn.cxx:296
TArray * getValues(Int_t step)
Definition StepTHn.h:51
THnBase * getTHn(Int_t step, Bool_t sparse=kFALSE)
Definition StepTHn.h:41
THnSparse * mPrototype
caching of last used bins (in many loops some vars are the same for a while)
Definition StepTHn.h:84
TArray ** mSumw2
Definition StepTHn.h:75
TArray * getSumw2(Int_t step)
Definition StepTHn.h:52
void init()
Definition StepTHn.cxx:110
THnBase ** mTarget
Definition StepTHn.h:77
Int_t mNVars
Definition StepTHn.h:72
~StepTHn() override
Definition StepTHn.cxx:142
void Sumw2()
Definition StepTHn.h:61
GLenum src
Definition glcorearb.h:1767
GLuint const GLchar * name
Definition glcorearb.h:781
Definition list.h:40