-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathStepTHn.h
More file actions
124 lines (98 loc) · 3.92 KB
/
StepTHn.h
File metadata and controls
124 lines (98 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef StepTHn_H
#define StepTHn_H
// optimized data container reusing functionality of THn
// A THnSparse is used to have the axis functionality "for free"
#include "TNamed.h"
#include "THnSparse.h"
#include "TAxis.h"
#include "TArray.h"
#include "Framework/Logger.h"
class TArray;
class TArrayF;
class TArrayD;
class TCollection;
class StepTHn : public TNamed
{
public:
StepTHn();
StepTHn(const Char_t* name, const Char_t* title, const Int_t nSteps, const Int_t nAxes);
~StepTHn() override;
template <typename... Ts>
void Fill(int iStep, const Ts&... valuesAndWeight);
void Fill(int iStep, int nParams, double positionAndWeight[]);
THnBase* getTHn(Int_t step, Bool_t sparse = kFALSE)
{
if (!mTarget || !mTarget[step]) {
createTarget(step, sparse);
}
return mTarget[step];
}
Int_t getNSteps() { return mNSteps; }
Int_t getNVar() { return mNVars; }
TArray* getValues(Int_t step) { return mValues[step]; }
TArray* getSumw2(Int_t step) { return mSumw2[step]; }
StepTHn(const StepTHn& c);
StepTHn& operator=(const StepTHn& corr);
void Copy(TObject& c) const override;
virtual Long64_t Merge(TCollection* list) = 0;
TAxis* GetAxis(int i) { return mPrototype->GetAxis(i); }
void Sumw2(){}; // TODO: added for compatibiltiy with registry, but maybe it would be useful also in StepTHn as toggle for error weights
protected:
void init();
virtual TArray* createArray(const TArray* src = nullptr) const = 0;
void createTarget(Int_t step, Bool_t sparse);
void deleteContainers();
Long64_t getGlobalBinIndex(const Int_t* binIdx);
Long64_t mNBins; // number of total bins
Int_t mNVars; // number of variables
Int_t mNSteps; // number of selection steps
TArray** mValues; //[mNSteps] data container
TArray** mSumw2; //[mNSteps] data container
THnBase** mTarget; //! target histogram
TAxis** mAxisCache; //! cache axis pointers (about 50% of the time in Fill is spent in GetAxis otherwise)
Int_t* mNbinsCache; //! cache Nbins per axis
Double_t* mLastVars; //! caching of last used bins (in many loops some vars are the same for a while)
Int_t* mLastBins; //! caching of last used bins (in many loops some vars are the same for a while)
THnSparse* mPrototype; // not filled used as prototype histogram for axis functionality etc.
ClassDef(StepTHn, 1) // THn like container
};
template <class TemplateArray>
class StepTHnT : public StepTHn
{
public:
StepTHnT() : StepTHn() {}
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);
StepTHnT(const char* name, const char* title, const int nSteps, const int nAxes, const int* nBins, const double* xmin, const double* xmax);
~StepTHnT() override = default;
Long64_t Merge(TCollection* list) override;
protected:
TArray* createArray(const TArray* src = nullptr) const override
{
if (src == nullptr) {
return new TemplateArray(mNBins);
} else {
return new TemplateArray(*((TemplateArray*)src));
}
}
ClassDef(StepTHnT, 1) // THn like container
};
typedef StepTHnT<TArrayF> StepTHnF;
typedef StepTHnT<TArrayD> StepTHnD;
template <typename... Ts>
void StepTHn::Fill(int iStep, const Ts&... valuesAndWeight)
{
constexpr int nArgs = sizeof...(Ts);
double tempArray[] = {static_cast<double>(valuesAndWeight)...};
Fill(iStep, nArgs, tempArray);
}
#endif