-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridHelperMacros.H
130 lines (104 loc) · 3.8 KB
/
GridHelperMacros.H
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
/**
* File : GridHelperMacros.H
* Author : Anton Riedel <[email protected]>
* Date : 14.10.2021
* Last Modified Date: 03.03.2022
* Last Modified By : Anton Riedel <[email protected]>
*/
#include <boost/algorithm/string.hpp>
#include <iostream>
#include <nlohmann/json.hpp>
TObject *IterateList(TList *list, std::string searchString) {
if (!list) {
std::cout << "Passed nullptr to IterateList" << std::endl;
return nullptr;
}
TObject *obj = nullptr;
for (auto key : *list) {
obj = key;
if (boost::contains(std::string(key->GetName()), searchString)) {
break;
}
if (obj->IsFolder()) {
obj = IterateList(dynamic_cast<TList *>(obj), searchString);
}
if (boost::contains(std::string(obj->GetName()), searchString)) {
break;
}
}
return obj;
}
TObject *GetObjectFromOutputFile(TFile *file, std::string TopLevelListName,
std::string ObjectName) {
if (!file) {
std::cout << "File pointer is NULL" << std::endl;
return nullptr;
}
std::fstream ConfigFile("config.json");
nlohmann::json Jconfig = nlohmann::json::parse(ConfigFile);
// get list of all tasks
TDirectoryFile *tdirFile = dynamic_cast<TDirectoryFile *>(file->Get(
Jconfig["task"]["OutputTDirectory"].get<std::string>().c_str()));
TList *TopLevelList =
dynamic_cast<TList *>(tdirFile->Get(TopLevelListName.c_str()));
TObject *result = IterateList(TopLevelList, ObjectName)->Clone();
delete TopLevelList;
return result;
}
// TH1 *GetHistFromOutputFile(std::string observable, std::string FileName,
// std::string TaskName) {
//
// std::fstream ConfigFile("config.json");
// nlohmann::json Jconfig = nlohmann::json::parse(ConfigFile);
//
// // open file
// TFile *file = TFile::Open(FileName.c_str(), "READ");
//
// // open output directory
// TDirectoryFile *tdirFile = dynamic_cast<TDirectoryFile *>(file->Get(
// Jconfig["task"]["OutputTDirectory"].get<std::string>().c_str()));
//
// TList *TaskList = dynamic_cast<TList *>(tdirFile->Get(TaskName.c_str()));
//
// TH1 *result = dynamic_cast<TH1 *>(IterateList(TaskList, observable));
//
// // close the file
// file->Close();
//
// return result;
// }
Double_t BootstrapSigma(TProfile *p) {
// compute statistical uncertainty sigma from tprofile
// the first n-1 bins contain the subsample means and the nth bin contains
// the whole mean
Double_t sigma = 0.0;
Int_t N = p->GetNbinsX();
for (Int_t i = 1; i < N; i++) {
sigma += TMath::Power(2, p->GetBinContent(i) - p->GetBinContent(N));
}
return TMath::Sqrt(sigma / (N * (N - 1.)));
}
void *SetWeights(Int_t RunNumber, Double_t centerMin, Double_t centerMax,
AliAnalysisTaskAR *task, const char *id) {
// get pt and eta weights
TFile *filePtEtaWeights =
new TFile(Form("%s/weights/%i_PtEtaWeights.root",
std::getenv("GRID_UTILITY_SCRIPTS"), RunNumber),
"READ");
TList *listPtEtaWeights = dynamic_cast<TList *>(filePtEtaWeights->Get(
Form("SC_MC_WithoutWeights_%.1f-%.1f%s", centerMin, centerMax, id)));
task->SetWeightHistogram(
kPT, dynamic_cast<TH1D *>(listPtEtaWeights->FindObject("PtWeights")));
task->SetWeightHistogram(
kETA, dynamic_cast<TH1D *>(listPtEtaWeights->FindObject("EtaWeights")));
// get phi weights
TFile *filePhiWeights =
new TFile(Form("%s/weights/%i_PhiWeights.root",
std::getenv("GRID_UTILITY_SCRIPTS"), RunNumber),
"READ");
TList *listPhiWeights = dynamic_cast<TList *>(filePhiWeights->Get(
Form("SC_WithoutWeights_%.1f-%.1f%s", centerMin, centerMax, id)));
task->SetWeightHistogram(
kPHI, dynamic_cast<TH1D *>(listPhiWeights->FindObject("PhiWeights")));
return nullptr;
}