-
Notifications
You must be signed in to change notification settings - Fork 1
/
AliGMFHistogramManager.cxx
132 lines (124 loc) · 5.35 KB
/
AliGMFHistogramManager.cxx
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
125
126
127
128
129
130
131
132
// Redmer Alexander Bertens, 2017 (UTK, CERN)
#include "TH1D.h"
#include "TH2D.h"
#include "TH3D.h"
#include "THashList.h"
#include "TFile.h"
#include "TH1.h"
#include "AliGMFHistogramManager.h"
ClassImp(AliGMFHistogramManager)
using namespace std;
//_____________________________________________________________________________
AliGMFHistogramManager::AliGMFHistogramManager(TString name) : TObject(),
fOutputList(0x0),
fManagerName("") {
// default constructor
fOutputList = new THashList();
fOutputList->SetOwner(kTRUE);
fManagerName += name;
}
//_____________________________________________________________________________
TH1D* AliGMFHistogramManager::BookTH1D(const char* name, const char* x, Int_t bins, Double_t min, Double_t max, Bool_t append)
{
// book a TH1D and connect it to the output container
if(append && !fOutputList) return 0x0;
TString title(name);
title += Form(";%s;[counts]", x);
TH1D* histogram = new TH1D(Form("%s_%s", name, fManagerName.Data()), title.Data(), bins, min, max);
histogram->Sumw2();
if(append) fOutputList->Add(histogram);
return histogram;
}
//_____________________________________________________________________________
TH2D* AliGMFHistogramManager::BookTH2D(const char* name, const char* x, const char* y, Int_t binsx, Double_t minx, Double_t maxx, Int_t binsy, Double_t miny, Double_t maxy, Bool_t append)
{
// book a TH2D and connect it to the output container
if(append && !fOutputList) return 0x0;
TString title(name);
title += Form(";%s;%s", x, y);
TH2D* histogram = new TH2D(Form("%s_%s", name, fManagerName.Data()), title.Data(), binsx, minx, maxx, binsy, miny, maxy);
histogram->Sumw2();
if(append) fOutputList->Add(histogram);
return histogram;
}
//_____________________________________________________________________________
TH3D* AliGMFHistogramManager::BookTH3D(const char* name, const char* x, const char* y, const char* z, Int_t binsx, Double_t minx, Double_t maxx, Int_t binsy, Double_t miny, Double_t maxy, Int_t binsz, Double_t minz, Double_t maxz, Bool_t append)
{
// book a TH3D and connect it to the output container
if(append && !fOutputList) return 0x0;
TString title(name);
title += Form(";%s;%s;%s", x, y, z);
TH3D* histogram = new TH3D(Form("%s_%s", name, fManagerName.Data()), title.Data(), binsx, minx, maxx, binsy, miny, maxy, binsz, minz, maxz);
histogram->Sumw2();
if(append) fOutputList->Add(histogram);
return histogram;
}
//_____________________________________________________________________________
TH1* AliGMFHistogramManager::GetHistogram(const TString &name) {
// return a pointer to a histogram named 'name'
return static_cast<TH1*>(fOutputList->FindObject(Form("%s_%s", name.Data(), fManagerName.Data())));
}
//_____________________________________________________________________________
Bool_t AliGMFHistogramManager::StoreRatio(const TString &a, const TString &b, const TString &name) {
// take the ratio of histograms a and b, and add them to the manager
TH1* _ha = static_cast<TH1*>(GetHistogram(a));
TH1* _hb = static_cast<TH1*>(GetHistogram(b));
TH1* clone = static_cast<TH1*>(_ha->Clone(name.Data()));
if(clone && _hb) {
clone->Divide(_hb);
fOutputList->Add(clone);
return kTRUE;
} else return kFALSE;
}
//_____________________________________________________________________________
void AliGMFHistogramManager::StoreManager(TFile* of) {
// create output file and write the manager
of->cd();
fOutputList->Write();
}
//____________________________________________________________________________
void AliGMFHistogramManager::StoreManager(const char* title) {
// create output file and write the manager
TFile* of(new TFile(title, "RECREATE"));
fOutputList->Write();
of->Close();
}
//_____________________________________________________________________________
Bool_t AliGMFHistogramManager::Fill(const TString &name, const Double_t &valx) {
// find and fill histogram
TH1* _temp = static_cast<TH1*>(GetHistogram(name));
if (_temp) {
_temp->Fill(valx);
return kTRUE;
}
return kFALSE;
}
//_____________________________________________________________________________
Bool_t AliGMFHistogramManager::Fill(const TString &name, const Double_t &valx, const Double_t &valy) {
// find and fill histogram
TH2* _temp = static_cast<TH2*>(GetHistogram(name));
if (_temp) {
_temp->Fill(valx, valy);
return kTRUE;
}
return kFALSE;
}
//_____________________________________________________________________________
Bool_t AliGMFHistogramManager::Fill(const TString &name, const Double_t &valx, const Double_t &valy, const Double_t &valz) {
// find and fill histogram
TH3* _temp = static_cast<TH3*>(GetHistogram(name));
if (_temp) {
_temp->Fill(valx, valy, valz);
return kTRUE;
}
return kFALSE;
}
//_____________________________________________________________________________
void AliGMFHistogramManager::WeighAllHistograms(const Double_t weight) {
// weigh all histograms in this manager by a constant factor
for(Int_t i = 0; i < fOutputList->GetSize(); i++) {
TH1* _temp = static_cast<TH1*>(fOutputList->At(i));
if(_temp) _temp->Scale(weight);
}
}
//_____________________________________________________________________________