1 |
+ |
|
2 |
|
#include <iostream> |
3 |
|
#include <iomanip> |
4 |
|
#include <vector> |
5 |
|
#include <map> |
6 |
< |
#include <fstream> |
7 |
< |
#include <sstream> |
8 |
< |
#include <Rtypes.h> |
9 |
< |
#include "TChain.h" |
10 |
< |
#include "TFile.h" |
6 |
> |
// #include <fstream> |
7 |
> |
// #include <sstream> |
8 |
> |
// #include <stdio.h> |
9 |
> |
// #include <stdlib.h> |
10 |
> |
|
11 |
> |
// #include <Rtypes.h> |
12 |
> |
// #include "TChain.h" |
13 |
> |
// #include "TFile.h" |
14 |
|
#include "TString.h" |
15 |
< |
#include "TStopwatch.h" |
16 |
< |
#include "TCanvas.h" |
17 |
< |
#include "TH1D.h" |
18 |
< |
#include "TLeafC.h" |
19 |
< |
#include "TSystem.h" |
16 |
< |
#include <stdio.h> |
17 |
< |
#include <stdlib.h> |
15 |
> |
// #include "TStopwatch.h" |
16 |
> |
// #include "TCanvas.h" |
17 |
> |
// #include "TH1D.h" |
18 |
> |
// #include "TLeafC.h" |
19 |
> |
// #include "TSystem.h" |
20 |
|
|
21 |
|
|
22 |
|
using namespace std; |
24 |
|
#ifndef tools_h |
25 |
|
#define tools_h |
26 |
|
namespace tools{ |
25 |
– |
UInt_t toollevel = 0; |
26 |
– |
Int_t toolverbosity = 0; |
27 |
– |
TStopwatch tooltimer; |
28 |
– |
TChain *toolfChain; |
29 |
– |
|
30 |
– |
void adjusth1d(TH1D *h1, TH1D *h2); |
31 |
– |
void enterFcn(TString name, Int_t max, Int_t timer_flg=0); |
32 |
– |
void exitFcn(TString name, Int_t max, Int_t timer_flg=0); |
33 |
– |
void SetVerbosity(Int_t v){toolverbosity=v;} |
34 |
– |
void SetLevel(Int_t l){toollevel=l;} |
35 |
– |
void progress(Long64_t cnt); |
36 |
– |
void percent(Double_t arg1, Double_t arg2, ostream& os=cout); |
37 |
– |
void SetCurrentChain(TChain *chain){toolfChain = chain;} |
38 |
– |
template <typename T> |
39 |
– |
void Swap(T &value1, T &value2); |
40 |
– |
|
41 |
– |
TString create_number(Int_t number, Int_t number_max); |
42 |
– |
vector<TString> splitToWords(TString rawString, TString newWord=";"); |
43 |
– |
map<TString, TString> splitToWords(TString rawString, TString newWord, TString newValue); |
44 |
– |
TChain* GetCurrentChain(){return toolfChain;} |
45 |
– |
|
46 |
– |
template <typename T> |
47 |
– |
void printVector(TString name, vector<T> v, Int_t length=40, ostream& os=cout); |
48 |
– |
template <typename T> |
49 |
– |
void printVectorSize(TString name, vector<T> v, Int_t length=40, ostream& os=cout); |
50 |
– |
|
51 |
– |
template<typename T> |
52 |
– |
void addLeaf(TChain *chain, TString name, vector<T> **pt); |
53 |
– |
template<typename T> |
54 |
– |
void addLeaf(TChain *chain, TString name, vector<T> &pt); |
55 |
– |
template<typename T> |
56 |
– |
void addLeaf(TChain *chain, TString name, T **pt); |
57 |
– |
template <typename T> |
58 |
– |
void addLeaf(TChain *chain, TString name, T &pt); |
59 |
– |
|
60 |
– |
template<typename T> |
61 |
– |
void addLeaf(TString name, vector<T> **pt){addLeaf(toolfChain, name, &(*pt));} |
62 |
– |
template<typename T> |
63 |
– |
void addLeaf(TString name, vector<T> &pt){addLeaf(toolfChain, name, (pt));} |
64 |
– |
template<typename T> |
65 |
– |
void addLeaf(TString name, T **pt){addLeaf(toolfChain, name, &(*pt));} |
66 |
– |
template<typename T> |
67 |
– |
void addLeaf(TString name, T &pt){addLeaf(toolfChain, name, (pt));} |
68 |
– |
template <typename T> |
69 |
– |
|
70 |
– |
|
71 |
– |
void GetValueFromLeaf(TString fileName, TString branchName, TString leafName, vector<T> **pt, Long64_t entry=0); |
72 |
– |
template<typename T1, typename T2> |
73 |
– |
void printMap(map<T1, T2> m); |
74 |
– |
|
75 |
– |
//template <typename T> |
76 |
– |
//vector<T> GetValueFromLeaf(TString fileName, TString branchName, TString leafName, Long64_t entry=0); |
77 |
– |
|
78 |
– |
//TString GetStringFromLeaf(TString fileName, TString branchName, TString leafName, Long64_t entry=0); |
79 |
– |
|
80 |
– |
|
81 |
– |
|
82 |
– |
// // ------------------------------------------------------------------------------------- |
83 |
– |
// static std::string toString(double d) { |
84 |
– |
// std::stringstream ss; |
85 |
– |
// ss << d; |
86 |
– |
// return ss.str(); |
87 |
– |
// } |
88 |
– |
// |
89 |
– |
// // ------------------------------------------------------------------------------------- |
90 |
– |
// static std::string toString(double d, int decPlaces) { |
91 |
– |
// std::stringstream ss; |
92 |
– |
// ss << round(d,decPlaces); |
93 |
– |
// return ss.str(); |
94 |
– |
// } |
95 |
– |
// |
96 |
– |
// // ------------------------------------------------------------------------------------- |
97 |
– |
// static TString toTString(double d, int decPlaces) { |
98 |
– |
// return toString(d,decPlaces).c_str(); |
99 |
– |
// } |
100 |
– |
// |
101 |
– |
// |
102 |
– |
// // ------------------------------------------------------------------------------------- |
103 |
– |
// static TString toTString(double d) { |
104 |
– |
// return toString(d).c_str(); |
105 |
– |
// } |
106 |
– |
// |
107 |
– |
|
108 |
– |
|
109 |
– |
|
110 |
– |
|
111 |
– |
//================================================================================= addToCanvas |
112 |
– |
// template <typename T> |
113 |
– |
// void addToCanvas(TCanvas* c, T* h){ |
114 |
– |
// static map<TCanvas*, Bool_t> canExists; |
115 |
– |
// TCanvas *ich = new TCanvas(); |
116 |
– |
// |
117 |
– |
// canExists[ich] = 1; |
118 |
– |
// |
119 |
– |
// if(canExists.find(c) != canExists.end()) |
120 |
– |
// cout<<"jo den gibts schon" <<endl; |
121 |
– |
// else{ |
122 |
– |
// cout<<"ein neuer!"<<endl; |
123 |
– |
// } |
124 |
– |
// } |
125 |
– |
|
126 |
– |
|
127 |
– |
|
128 |
– |
/* |
129 |
– |
void addToCanvas(TCanvas *c, TH1D* h){ |
130 |
– |
static map<TCanvas* , Bool_t> canExists; |
131 |
– |
if(canExists.find(c) != canExists.end()) |
132 |
– |
cout<<"jo den gibts schon" <<endl; |
133 |
– |
else{ |
134 |
– |
canExists[c] = 1; |
135 |
– |
cout<<"ein neuer!"<<endl; |
136 |
– |
} |
137 |
– |
}*/ |
138 |
– |
|
139 |
– |
|
140 |
– |
|
141 |
– |
|
142 |
– |
//template <typename T> |
143 |
– |
//T GetHistFromFile(TString fileName, TString histName); |
144 |
– |
|
145 |
– |
//TH1D* GetHistFromFile(TString &fileName, TString &histName); |
146 |
– |
|
147 |
– |
//template <typename T> |
148 |
– |
//void addToCanvas(TCanvas* can, T* h); |
149 |
– |
|
150 |
– |
//template <typename T> |
151 |
– |
|
152 |
– |
//================================================================================= enterFcn |
153 |
– |
//Help for debugging and to measure running time of a function |
154 |
– |
//0: silent |
155 |
– |
//1: functions called once per run |
156 |
– |
//2: functions multiple times per event |
157 |
– |
//3: functions called once per event |
158 |
– |
//4: functions called multiple times per event |
159 |
– |
void enterFcn(TString name, Int_t max, Int_t timer_flg){ |
160 |
– |
++toollevel; |
161 |
– |
if(toolverbosity>=max){ |
162 |
– |
for(UInt_t ilevel=0; ilevel<toollevel; ++ilevel) cout << "++"; |
163 |
– |
cout << " enter " << name << endl; |
164 |
– |
} |
165 |
– |
if(timer_flg){tooltimer.Reset(); tooltimer.Start();} |
166 |
– |
} |
167 |
– |
|
168 |
– |
|
169 |
– |
//================================================================================= exitFcn |
170 |
– |
void exitFcn(TString name, Int_t max, Int_t timer_flg){ |
171 |
– |
if(timer_flg){ |
172 |
– |
tooltimer.Stop(); |
173 |
– |
cout<< name << ": Time (real|CPU) = "<<tooltimer.RealTime()<<" | "<<tooltimer.CpuTime()<<endl; |
174 |
– |
} |
175 |
– |
--toollevel; |
176 |
– |
if(toolverbosity>=max){ |
177 |
– |
for(UInt_t ilevel=0; ilevel<=toollevel; ++ilevel) cout << "++"; |
178 |
– |
cout << " exit " << name << endl; |
179 |
– |
} |
180 |
– |
} |
181 |
– |
|
182 |
– |
|
27 |
|
//================================================================================= progress |
28 |
|
void progress(Long64_t cnt){ |
29 |
|
static Long64_t step(1),next(1); |
36 |
|
} |
37 |
|
|
38 |
|
|
39 |
+ |
// //================================================================================= progressReset |
40 |
+ |
// void progressReset(){ |
41 |
+ |
// static Long64_t step(1),next(1); |
42 |
+ |
// step=next; |
43 |
+ |
// next=step; |
44 |
+ |
// } |
45 |
+ |
|
46 |
+ |
|
47 |
+ |
|
48 |
|
//================================================================================= printVector |
49 |
|
template <typename T> |
50 |
< |
void printVector(TString name, vector<T> v, Int_t length, ostream& os){ |
51 |
< |
printVectorSize(name,v); |
50 |
> |
void printVector(TString name, vector<T> v, Int_t length=40, ostream& os=cout){ |
51 |
> |
TString nameSize = name; |
52 |
> |
nameSize += ".size() "; |
53 |
> |
// os << setw(length) << name << ".size() = " << v.size() << endl; |
54 |
> |
//os << setw(length) << nameSize << "------> " << v.size() << endl; |
55 |
> |
os << setw(length) << "size " << "------> " << name << ": " << v.size() << endl; |
56 |
> |
|
57 |
|
if(v.size()>0){ |
58 |
|
for(Int_t i=0,N=v.size(); i<N; ++i){ |
59 |
|
TString temp_name = name; |
62 |
|
temp_name += "] = "; |
63 |
|
os << setw(length) << temp_name << v[i] << endl; |
64 |
|
} |
207 |
– |
os<<endl; |
65 |
|
} |
66 |
+ |
os<<endl; |
67 |
|
} |
68 |
< |
|
69 |
< |
|
70 |
< |
//================================================================================= printVectorSize |
68 |
> |
|
69 |
> |
|
70 |
> |
//================================================================================= printVector |
71 |
|
template <typename T> |
72 |
< |
void printVectorSize(TString name, vector<T> v, Int_t length, ostream& os){ |
73 |
< |
name += ".size() = "; |
216 |
< |
os << setw(length) << name << v.size(); |
217 |
< |
os << endl; |
72 |
> |
void printVector(TString name, vector<T> v, ostream& os, Int_t length=40){ |
73 |
> |
printVector<T>(name, v, length, os); |
74 |
|
} |
75 |
< |
|
76 |
< |
|
77 |
< |
//================================================================================= percent |
78 |
< |
void percent(Double_t arg1, Double_t arg2, ostream& os){ |
79 |
< |
os<<setw(5)<<setprecision(4)<<arg1/arg2*100<<"%"; |
80 |
< |
} |
81 |
< |
|
82 |
< |
|
83 |
< |
//================================================================================= create_number |
84 |
< |
TString create_number(Int_t number, Int_t number_max){ |
85 |
< |
TString name = ""; name+=number; |
86 |
< |
Int_t mag_number=1, mag_number_max=1; |
87 |
< |
Int_t n_zero=0; |
88 |
< |
if(number==0) mag_number=2; |
233 |
< |
while(number>=1){ |
234 |
< |
number/=10; |
235 |
< |
++mag_number; |
236 |
< |
} |
237 |
< |
while(number_max>=1){ |
238 |
< |
number_max/=10; |
239 |
< |
++mag_number_max; |
75 |
> |
|
76 |
> |
|
77 |
> |
//================================================================================= printMap |
78 |
> |
template<typename T1, typename T2, typename T3> |
79 |
> |
void printMap(TString name, map<T1, map<T2, T3> > m, Int_t width1=10, Int_t width2=10){ |
80 |
> |
cout<<"size = " << m.size() << endl; |
81 |
> |
for(typename map<T1, map<T2, T3> >::iterator it=m.begin(); it !=m.end(); ++it){ |
82 |
> |
for(typename map<T2, T3>::iterator it2=m[it->first].begin(); it2!=m[it->first].end(); ++it2){ |
83 |
> |
cout<<name<<"[" |
84 |
> |
<<setw(width1)<<it ->first << "][" |
85 |
> |
<<setw(width2)<<it2->first << "] = " |
86 |
> |
<<it2->second |
87 |
> |
<<endl; |
88 |
> |
} |
89 |
|
} |
241 |
– |
n_zero = mag_number_max - mag_number; |
242 |
– |
for(Int_t i=0; i<n_zero; ++i) name.Insert(0,"0"); |
243 |
– |
return name; |
244 |
– |
} |
245 |
– |
|
246 |
– |
|
247 |
– |
//================================================================================= addLeaf |
248 |
– |
template<typename T> |
249 |
– |
void addLeaf(TChain *chain, TString name, vector<T> **pt){ |
250 |
– |
*pt=0; |
251 |
– |
chain->SetBranchStatus(name + "*", 1); |
252 |
– |
chain->SetBranchAddress(name, &(*pt)); |
253 |
– |
//skim_data->Branch(name, &(*pt)); |
254 |
– |
} |
255 |
– |
|
256 |
– |
|
257 |
– |
|
258 |
– |
|
259 |
– |
|
260 |
– |
// //================================================================================= addLeaf |
261 |
– |
// template<typename T> |
262 |
– |
// void addLeaf(TChain *chain, TString name, vector<T> &pt){ |
263 |
– |
// //*pt=0; |
264 |
– |
// chain->SetBranchStatus(name + "*", 1); |
265 |
– |
// chain->SetBranchAddress(name, &pt); |
266 |
– |
// //skim_data->Branch(name, pt); |
267 |
– |
// } |
268 |
– |
|
269 |
– |
|
270 |
– |
//================================================================================= addLeaf |
271 |
– |
template<typename T> |
272 |
– |
void addLeaf(TChain *chain, TString name, T **pt){ |
273 |
– |
*pt=0; |
274 |
– |
chain->SetBranchStatus(name + "*", 1); |
275 |
– |
chain->SetBranchAddress(name, &(*pt)); |
276 |
– |
//skim_data->Branch(name, &(*pt)); |
277 |
– |
} |
278 |
– |
|
279 |
– |
|
280 |
– |
//================================================================================= addLeaf |
281 |
– |
template<typename T> |
282 |
– |
void addLeaf(TChain *chain, TString name, T &pt){ |
283 |
– |
//pt=0; |
284 |
– |
chain->SetBranchStatus(name + "*", 1); |
285 |
– |
chain->SetBranchAddress(name, &pt); |
286 |
– |
//skim_data->Branch(name + "*", &pt); |
287 |
– |
//skim_data->Branch(name, pt); |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
< |
//================================================================================= addLeafString |
94 |
< |
void addLeafString(TString name, TString &pt, Long64_t jentry=0){ |
95 |
< |
toolfChain->SetBranchStatus(name + "*", 1); |
96 |
< |
toolfChain->GetEntry(jentry); |
97 |
< |
TLeafC *l = dynamic_cast<TLeafC*>(toolfChain->GetLeaf(name)); |
98 |
< |
pt = l->GetValueString(); |
99 |
< |
} |
298 |
< |
|
299 |
< |
|
300 |
< |
//================================================================================= addLeafString |
301 |
< |
void addLeafString(TChain *chain, TString name, TString &pt, Long64_t jentry=0){ |
302 |
< |
chain->SetBranchStatus(name + "*", 1); |
303 |
< |
chain->GetEntry(jentry); |
304 |
< |
TLeafC *l = dynamic_cast<TLeafC*>(chain->GetLeaf(name)); |
305 |
< |
pt = l->GetValueString(); |
93 |
> |
//================================================================================= printMap |
94 |
> |
template<typename T1, typename T2> |
95 |
> |
void printMap(map<T1, T2> m, Int_t setWidth){ |
96 |
> |
cout<<"size = " << m.size() << endl; |
97 |
> |
for(typename map<T1, T2>::iterator it=m.begin(); it !=m.end(); ++it){ |
98 |
> |
cout<<setw(setWidth)<<left<<it->first << " = " << it->second << endl; |
99 |
> |
} |
100 |
|
} |
101 |
< |
|
101 |
> |
|
102 |
|
|
103 |
|
//================================================================================= splitToWords |
104 |
|
vector<TString> splitToWords(TString rawString, TString newWord){ |
149 |
|
T* GetHistFromFile(TString fileName, TString histName){ |
150 |
|
T *hist = new T(); |
151 |
|
|
152 |
< |
// TFile f(fileName); |
153 |
< |
// if (f.IsZombie()) { |
154 |
< |
// cout << "Error opening file" << endl; |
155 |
< |
// exit(-1); |
156 |
< |
// } |
152 |
> |
// TFile f(fileName); |
153 |
> |
// if (f.IsZombie()) { |
154 |
> |
// cout << "Error opening file" << endl; |
155 |
> |
// exit(-1); |
156 |
> |
// } |
157 |
|
TFile *file = new TFile(fileName,"READ"); |
158 |
|
if(file->FindObjectAny(histName)) hist = (T*) file->FindObjectAny(histName)->Clone(); |
159 |
|
else cout<<"Histogram does not exist! Creating empty histogram: "<< histName << endl; |
162 |
|
return hist; |
163 |
|
} |
164 |
|
|
165 |
< |
|
372 |
< |
// //================================================================================= GetHistFromFile |
373 |
< |
// template <typename T> |
374 |
< |
// T* GetHistFromFile(TString fileName, TString histName) { |
375 |
< |
// TFile *file = new TFile(fileName,"READ"); |
376 |
< |
// T* histo = (T*) file->FindObjectAny(histName)->Clone(); |
377 |
< |
// return histo; |
378 |
< |
// } |
379 |
< |
|
380 |
< |
|
381 |
< |
|
165 |
> |
|
166 |
|
//================================================================================= GetHistFromFile |
167 |
|
template <typename T> |
168 |
|
T* GetHistFromFile(TFile *file, TString histName){ |
174 |
|
return hist; |
175 |
|
} |
176 |
|
|
393 |
– |
|
394 |
– |
|
395 |
– |
|
396 |
– |
// //================================================================================= GetHistFromFile |
397 |
– |
// //Usage: TH1D* h = myplots.GetHistFromFile<TH1D*>("evaluation.root", "Multiplicity"); |
398 |
– |
// template <typename T> |
399 |
– |
// T GetHistFromFile(TString fileName, TString histName){ |
400 |
– |
// TFile *file = new TFile(fileName,"READ"); |
401 |
– |
// T hist = (T) file->FindObjectAny(histName); |
402 |
– |
// //file->Close(); |
403 |
– |
// return hist; |
404 |
– |
// } |
405 |
– |
// |
406 |
– |
// |
407 |
– |
// //================================================================================= GetHistFromFile |
408 |
– |
// template <typename T> |
409 |
– |
// T GetHistFromFile(TFile *f, TString histName){ |
410 |
– |
// f->cd(); |
411 |
– |
// T hist = (T) f->FindObjectAny(histName); |
412 |
– |
// //file->Close(); |
413 |
– |
// return hist; |
414 |
– |
// } |
415 |
– |
|
416 |
– |
|
417 |
– |
|
418 |
– |
|
419 |
– |
// //================================================================================= GetValueFromLeaf |
420 |
– |
// template <typename T> |
421 |
– |
// void GetValueFromLeaf(TString fileName, TString branchName, TString leafName, vector<T> **v, Long64_t entry){ |
422 |
– |
// TFile *file = new TFile(fileName,"READ"); |
423 |
– |
// TTree *fChain = (TTree*)file->Get(branchName); |
424 |
– |
// //fChain->AddFile(fileName); |
425 |
– |
// fChain->SetBranchStatus("*",0); |
426 |
– |
// fChain->SetBranchStatus(leafName, 1); |
427 |
– |
// *v=0; |
428 |
– |
// fChain->SetBranchAddress(leafName, &(*v)); |
429 |
– |
// fChain->GetEntry(entry); |
430 |
– |
// } |
431 |
– |
|
432 |
– |
|
433 |
– |
// //================================================================================= GetValueFromLeaf |
434 |
– |
// template <typename T> |
435 |
– |
// void GetValueFromLeaf(TString fileName, TString branchName, TString leafName, vector<T> &v, Long64_t entry){ |
436 |
– |
// TFile *file = new TFile(fileName,"READ"); |
437 |
– |
// TTree *fChain = (TTree*)file->Get(branchName); |
438 |
– |
// //fChain->AddFile(fileName); |
439 |
– |
// fChain->SetBranchStatus("*",0); |
440 |
– |
// fChain->SetBranchStatus(leafName, 1); |
441 |
– |
// vector<T> *pt=&v; |
442 |
– |
// fChain->SetBranchAddress(leafName, &(pt)); |
443 |
– |
// fChain->GetEntry(entry); |
444 |
– |
// } |
445 |
– |
|
446 |
– |
|
447 |
– |
// //================================================================================= GetValueFromLeaf |
448 |
– |
// template <typename T> |
449 |
– |
// void GetValueFromLeaf(TString fileName, TString branchName, TString leafName, T &v, Long64_t entry){ |
450 |
– |
// cout<<"leafName = "<< leafName<<endl; |
451 |
– |
// TFile *file = new TFile(fileName,"READ"); |
452 |
– |
// TTree *fChain = (TTree*)file->Get(branchName); |
453 |
– |
// //fChain->AddFile(fileName); |
454 |
– |
// fChain->SetBranchStatus("*",0); |
455 |
– |
// fChain->SetBranchStatus(leafName, 1); |
456 |
– |
// //T *pt=&v; |
457 |
– |
// T *pt=0; |
458 |
– |
// pt=&v; |
459 |
– |
// |
460 |
– |
// fChain->SetBranchAddress(leafName, &pt); |
461 |
– |
// fChain->GetEntry(entry); |
462 |
– |
// } |
463 |
– |
|
464 |
– |
|
465 |
– |
//================================================================================= GetValueFromLeaf |
466 |
– |
template <typename T> |
467 |
– |
void GetValueFromLeaf(TString fileName, TString branchName, TString leafName, T &v, Long64_t entry){ |
468 |
– |
TFile *file = new TFile(fileName,"READ"); |
469 |
– |
TTree *fChain = (TTree*)file->Get(branchName); |
470 |
– |
fChain->SetBranchStatus("*",0); |
471 |
– |
fChain->SetBranchStatus(leafName, 1); |
472 |
– |
fChain->SetBranchAddress(leafName, &v); |
473 |
– |
fChain->GetEntry(entry); |
474 |
– |
} |
475 |
– |
|
476 |
– |
//================================================================================= GetValueFromLeaf |
477 |
– |
template <typename T> |
478 |
– |
void GetValueFromLeaf(TString fileName, TString branchName, TString leafName, T **v, Long64_t entry){ |
479 |
– |
TFile *file = new TFile(fileName,"READ"); |
480 |
– |
TTree *fChain = (TTree*)file->Get(branchName); |
481 |
– |
fChain->SetBranchStatus("*",0); |
482 |
– |
fChain->SetBranchStatus(leafName, 1); |
483 |
– |
//*v=0; |
484 |
– |
fChain->SetBranchAddress(leafName, &(*v)); |
485 |
– |
fChain->GetEntry(entry); |
486 |
– |
} |
487 |
– |
|
488 |
– |
|
489 |
– |
//================================================================================= GetValueFromLeaf |
490 |
– |
template <typename T> |
491 |
– |
void GetVectorFromLeaf(TString fileName, TString brName, TString leafName, T &v, Long64_t entry){ |
492 |
– |
TFile *file = new TFile(fileName,"READ"); |
493 |
– |
TTree *fChain = (TTree*)file->Get(brName); |
494 |
– |
fChain->SetBranchStatus("*",0); |
495 |
– |
fChain->SetBranchStatus(leafName, 1); |
496 |
– |
T *pt=&v; |
497 |
– |
fChain->SetBranchAddress(leafName, &pt); |
498 |
– |
fChain->GetEntry(entry); |
499 |
– |
} |
500 |
– |
|
501 |
– |
|
502 |
– |
//================================================================================= GetValueFromLeaf |
503 |
– |
template <typename T> |
504 |
– |
void GetVectorFromLeaf(TString fileName, TString branchName, TString leafName, vector<T> **v, Long64_t entry){ |
505 |
– |
TFile *file = new TFile(fileName,"READ"); |
506 |
– |
TTree *fChain = (TTree*)file->Get(branchName); |
507 |
– |
fChain->SetBranchStatus("*",0); |
508 |
– |
fChain->SetBranchStatus(leafName, 1); |
509 |
– |
*v=0; |
510 |
– |
fChain->SetBranchAddress(leafName, &(*v)); |
511 |
– |
fChain->GetEntry(entry); |
512 |
– |
} |
513 |
– |
|
514 |
– |
//================================================================================= GetValueFromLeaf |
515 |
– |
template <typename T> |
516 |
– |
void GetVectorFromLeaf(TFile* file, TString branchName, TString leafName, vector<T> **v, Long64_t entry){ |
517 |
– |
TTree *fChain = (TTree*)file->Get(branchName); |
518 |
– |
fChain->SetBranchStatus("*",0); |
519 |
– |
fChain->SetBranchStatus(leafName, 1); |
520 |
– |
*v=0; |
521 |
– |
fChain->SetBranchAddress(leafName, &(*v)); |
522 |
– |
fChain->GetEntry(entry); |
523 |
– |
} |
524 |
– |
|
525 |
– |
|
526 |
– |
|
527 |
– |
//================================================================================= GetStringFromLeaf |
528 |
– |
void GetStringFromLeaf(TString fileName, TString branchName, TString leafName, TString &s, Long64_t entry){ |
529 |
– |
TFile *file = new TFile(fileName,"READ"); |
530 |
– |
TTree *t = (TTree*)file->Get(branchName); |
531 |
– |
t->GetEntry(entry); |
532 |
– |
TLeafC *l = dynamic_cast<TLeafC*>(t->GetLeaf(leafName)); |
533 |
– |
s = (l->GetValueString()); |
534 |
– |
} |
535 |
– |
|
536 |
– |
|
537 |
– |
//================================================================================= Swap |
538 |
– |
template <typename T> |
539 |
– |
void Swap(T &value1, T &value2){ |
540 |
– |
T dummy; |
541 |
– |
dummy = value1; |
542 |
– |
value1 = value2; |
543 |
– |
value2 = dummy; |
544 |
– |
} |
545 |
– |
|
546 |
– |
|
547 |
– |
//================================================================================= hist_maximum |
548 |
– |
double hist_maximum(TH1* h){ |
549 |
– |
const int i = h->GetMaximumBin(); |
550 |
– |
return h->GetBinContent(i) + h->GetBinError(i); |
551 |
– |
} |
552 |
– |
|
553 |
– |
|
554 |
– |
//================================================================================= removeDuplicates |
555 |
– |
template <typename T> |
556 |
– |
void removeDuplicates(vector<T> &v){ |
557 |
– |
for(UInt_t i=0; i<v.size(); ++i){ |
558 |
– |
for(UInt_t j=i+1; j<v.size(); ++j){ |
559 |
– |
if(v[j]==v[i]){ |
560 |
– |
v.erase(v.begin()+j); |
561 |
– |
--j; |
562 |
– |
} |
563 |
– |
} |
564 |
– |
} |
565 |
– |
} |
566 |
– |
|
177 |
|
|
178 |
< |
//================================================================================= GetMinimum |
178 |
> |
//================================================================================= createRatioPlot |
179 |
|
template <typename T> |
180 |
< |
T GetMinimum(vector<T> &v){ |
181 |
< |
T min = 9999999; |
182 |
< |
for(Int_t i=0,N=v.size(); i<N; ++i){ |
573 |
< |
if(min>v[i]) min = v[i]; |
574 |
< |
} |
575 |
< |
return min; |
576 |
< |
} |
577 |
< |
|
578 |
< |
|
579 |
< |
//================================================================================= GetMinimum |
580 |
< |
template <typename T1, typename T2> |
581 |
< |
T1 GetMinimum(map<T1, T2> &m){ |
582 |
< |
T1 minkey=0; |
583 |
< |
T2 min=9999999; |
584 |
< |
for(typename map<T1, T2>::iterator it=m.begin(); it !=m.end(); ++it){ |
585 |
< |
if(min>it->second){ |
586 |
< |
minkey = it->first; |
587 |
< |
min = it->second; |
588 |
< |
} |
589 |
< |
} |
590 |
< |
return minkey; |
591 |
< |
} |
592 |
< |
|
593 |
< |
|
594 |
< |
//================================================================================= GetMaximum |
595 |
< |
template <typename T> |
596 |
< |
T GetMaximum(vector<T> &v){ |
597 |
< |
T max = -9999999; |
598 |
< |
for(Int_t i=0,N=v.size(); i<N; ++i){ |
599 |
< |
if(max<v[i]) max = v[i]; |
600 |
< |
} |
601 |
< |
return max; |
602 |
< |
} |
603 |
< |
|
604 |
< |
|
605 |
< |
//================================================================================= GetMinimum |
606 |
< |
template <typename T1, typename T2> |
607 |
< |
T1 GetMaximum(map<T1, T2> &m){ |
608 |
< |
T1 maxkey=0; |
609 |
< |
T2 max=-9999999; |
610 |
< |
for(typename map<T1, T2>::iterator it=m.begin(); it !=m.end(); ++it){ |
611 |
< |
if(max<it->second){ |
612 |
< |
maxkey = it->first; |
613 |
< |
max = it->second; |
614 |
< |
} |
615 |
< |
} |
616 |
< |
return maxkey; |
617 |
< |
} |
618 |
< |
|
619 |
< |
|
620 |
< |
//================================================================================= adjusth1d |
621 |
< |
void adjusth1d(TH1D *h1, TH1D *h2){ |
622 |
< |
Double_t max1 = h1->GetMaximum(); |
623 |
< |
Double_t max2 = h2->GetMaximum(); |
624 |
< |
Double_t min1 = h1->GetMinimum(); |
625 |
< |
Double_t min2 = h2->GetMinimum(); |
626 |
< |
Double_t norm1 = h1->GetNormFactor(); |
627 |
< |
Double_t norm2 = h2->GetNormFactor(); |
628 |
< |
Double_t scale1 = 1.; //if the histo ist normed to some value, SetUserRange etc. depends on the normalization (which is, of course a root-bug) |
629 |
< |
Double_t scale2 = 1.; |
630 |
< |
|
631 |
< |
if(norm1) scale1 = norm1/h1->Integral(); |
632 |
< |
if(norm2) scale2 = norm2/h2->Integral(); |
633 |
< |
max1 *= scale1; |
634 |
< |
max2 *= scale2; |
635 |
< |
Double_t maximum = max(max1, max2)*1.1; |
636 |
< |
Double_t minimum = min(min1, min2)*1.1; |
637 |
< |
h1->GetYaxis()->SetRangeUser(minimum/scale1, maximum/scale1); |
638 |
< |
h2->GetYaxis()->SetRangeUser(minimum/scale2, maximum/scale2); |
639 |
< |
|
640 |
< |
// cout<<"max1 = " << max1 << endl; |
641 |
< |
// cout<<"max2 = " << max2 << endl; |
642 |
< |
// cout<<"norm1 = " << norm1 << endl; |
643 |
< |
// cout<<"norm2 = " << norm2 << endl; |
644 |
< |
// cout<<"h1->GetName() = " << h1->GetName() << endl; |
645 |
< |
// cout<<"h1->GetMaximum() = " << h1->GetMaximum() << endl; |
646 |
< |
// cout<<"h1->GetNormFactor() = " << h1->GetNormFactor() << endl; |
647 |
< |
// cout<<"h1->GetEntries() = " << h1->GetEntries() << endl; |
648 |
< |
// cout<<"h1->GetMaximumStored() = " << h1->GetMaximumStored() << endl; |
649 |
< |
// cout<<"h1->Integral() = " << h1->Integral() << endl; |
650 |
< |
// cout<<"hist_maximum(h1) = " << hist_maximum(h1) << endl; |
651 |
< |
// cout<<"h2->GetName() = " << h2->GetName() << endl; |
652 |
< |
// cout<<"h2->GetMaximum() = " << h2->GetMaximum() << endl; |
653 |
< |
// cout<<"h2->GetNormFactor() = " << h2->GetNormFactor() << endl; |
654 |
< |
// cout<<"h2->GetEntries() = " << h2->GetEntries() << endl; |
655 |
< |
// cout<<"h2->GetMaximumStored() = " << h2->GetMaximumStored() << endl; |
656 |
< |
// cout<<"h2->Integral() = " << h2->Integral() << endl; |
657 |
< |
// cout<<"hist_maximum(h2) = " << hist_maximum(h2) << endl; |
658 |
< |
// cout<<"maximum = " << maximum << endl; |
659 |
< |
// cout<<endl; |
660 |
< |
} |
661 |
< |
|
662 |
< |
|
663 |
< |
//================================================================================= adjusth1d |
664 |
< |
void adjusth1d(vector<TH1D*> h){ |
665 |
< |
vector<Double_t> max, min, norm, scale; |
666 |
< |
for(Int_t i=0,N=h.size(); i<N; ++i){ |
667 |
< |
max .push_back(h[i]->GetMaximum()); |
668 |
< |
min .push_back(h[i]->GetMinimum()); |
669 |
< |
norm.push_back(h[i]->GetNormFactor()); |
670 |
< |
scale.push_back(1.); |
671 |
< |
if(norm[i]) scale[i] = norm[i]/h[i]->Integral(); |
672 |
< |
max[i] *= scale[i]; |
673 |
< |
} |
674 |
< |
Double_t maximum = -99999999.; |
675 |
< |
Double_t minimum = 99999999.; |
676 |
< |
for(Int_t i=0,N=h.size(); i<N; ++i){ |
677 |
< |
if(maximum < max[i]) maximum = max[i]; |
678 |
< |
if(minimum > min[i]) minimum = min[i]; |
679 |
< |
} |
680 |
< |
maximum*=1.1; |
681 |
< |
minimum*=1.1; |
682 |
< |
for(Int_t i=0,N=h.size(); i<N; ++i){ |
683 |
< |
h[i]->GetYaxis()->SetRangeUser(minimum/scale[i], maximum/scale[i]); |
684 |
< |
} |
685 |
< |
} |
686 |
< |
|
687 |
< |
|
688 |
< |
//================================================================================= printMap |
689 |
< |
template<typename T1, typename T2> |
690 |
< |
void printMap(map<T1, T2> m){ |
691 |
< |
cout<<"size = " << m.size() << endl; |
692 |
< |
for(typename map<T1, T2>::iterator it=m.begin(); it !=m.end(); ++it){ |
693 |
< |
cout<<it->first << " = " << it->second << endl; |
694 |
< |
} |
695 |
< |
} |
696 |
< |
|
697 |
< |
//================================================================================= printMap |
698 |
< |
template<typename T1, typename T2, typename T3> |
699 |
< |
void printMap(TString name, map<T1, map<T2, T3> > m, Int_t width1=10, Int_t width2=10){ |
700 |
< |
cout<<"size = " << m.size() << endl; |
701 |
< |
for(typename map<T1, map<T2, T3> >::iterator it=m.begin(); it !=m.end(); ++it){ |
702 |
< |
for(typename map<T2, T3>::iterator it2=m[it->first].begin(); it2!=m[it->first].end(); ++it2){ |
703 |
< |
cout<<name<<"[" |
704 |
< |
<<setw(width1)<<it ->first << "][" |
705 |
< |
<<setw(width2)<<it2->first << "] = " |
706 |
< |
<<it2->second |
707 |
< |
<<endl; |
708 |
< |
} |
709 |
< |
} |
710 |
< |
} |
711 |
< |
|
712 |
< |
|
713 |
< |
//================================================================================= printMap |
714 |
< |
template<typename T1, typename T2> |
715 |
< |
void printMap(map<T1, T2> m, Int_t setWidth){ |
716 |
< |
cout<<"size = " << m.size() << endl; |
717 |
< |
for(typename map<T1, T2>::iterator it=m.begin(); it !=m.end(); ++it){ |
718 |
< |
cout<<setw(setWidth)<<it->first << " = " << it->second << endl; |
719 |
< |
} |
720 |
< |
} |
721 |
< |
|
722 |
< |
|
723 |
< |
//================================================================================= FillVectorFromFile |
724 |
< |
template<typename T> |
725 |
< |
vector<T> FillVectorFromFile(TString fileName){ |
726 |
< |
vector<T> v; |
727 |
< |
ifstream file(fileName); |
728 |
< |
TString s; |
729 |
< |
while(!file.eof()){ |
730 |
< |
file >> s; |
731 |
< |
stringstream xmorph; |
732 |
< |
xmorph << s; |
733 |
< |
T my; |
734 |
< |
xmorph >> my; |
735 |
< |
v.push_back(my); |
736 |
< |
//cout<<"myint = "<< my << endl; |
737 |
< |
} |
738 |
< |
return v; |
739 |
< |
} |
740 |
< |
|
741 |
< |
|
742 |
< |
//================================================================================= FillVectorFromFile |
743 |
< |
template<typename T> |
744 |
< |
vector<T> FillVectorFromLs(TString path, TString name){ |
745 |
< |
vector<T> v; |
746 |
< |
TString command=""; |
747 |
< |
command="ls "; |
748 |
< |
command+= path; |
749 |
< |
command+=name; |
750 |
< |
command+=" > tempLsCommand.txt"; |
751 |
< |
system(command); |
752 |
< |
//cout<<"command = " << command << endl; |
753 |
< |
v = tools::FillVectorFromFile<TString>("tempLsCommand.txt"); |
754 |
< |
v.erase(v.end()-1); |
755 |
< |
//------------------------------------ remove the path from file names |
756 |
< |
for(Int_t i=0,N=v.size(); i<N; ++i) v[i].ReplaceAll(path, ""); |
757 |
< |
// system("rm tempLsCommand.txt"); |
758 |
< |
return v; |
759 |
< |
} |
760 |
< |
|
761 |
< |
|
762 |
< |
//================================================================================= save |
763 |
< |
template<typename T> |
764 |
< |
void save(map<TString, T> m, TString fileName, TString option="RECREATE"){ |
765 |
< |
TFile *file = new TFile(fileName, option); |
766 |
< |
for(typename map<TString, T>::iterator it = m.begin(); it != m.end(); ++it){ |
767 |
< |
it->second->Write(it->second->GetName()); |
768 |
< |
} |
769 |
< |
file->Close(); |
770 |
< |
} |
771 |
< |
|
772 |
< |
//================================================================================= createDir |
773 |
< |
void createDir(TString folderName){ |
774 |
< |
Int_t dummy = system("mkdir " + folderName + " -p"); |
775 |
< |
dummy=1; |
776 |
< |
} |
777 |
< |
|
778 |
< |
|
779 |
< |
//================================================================================= createRatioPlot |
780 |
< |
template <typename T> |
781 |
< |
T* createRatioPlot(T* h1, T* h2, TString name="", TString yTitle=""){ |
782 |
< |
T* ratioPlot = (T*)h1->Clone(); |
783 |
< |
ratioPlot->Divide(h2); |
180 |
> |
T* createRatioPlot(T* h1, T* h2, TString name="", TString yTitle=""){ |
181 |
> |
T* ratioPlot = (T*)h1->Clone(); |
182 |
> |
ratioPlot->Divide(h2); |
183 |
|
if(name !=""){ |
184 |
|
ratioPlot->SetName(name); |
185 |
|
ratioPlot->SetTitle(name); |
190 |
|
return ratioPlot; |
191 |
|
} |
192 |
|
|
794 |
– |
|
795 |
– |
//================================================================================= isNew |
796 |
– |
template <typename T> |
797 |
– |
Bool_t isNew(TString name, map<TString, T> m){ |
798 |
– |
return (m.find(name) == m.end()); |
799 |
– |
} |
800 |
– |
|
801 |
– |
|
802 |
– |
//================================================================================= isNew |
803 |
– |
template <typename T1, typename T2> |
804 |
– |
Bool_t isNew(TString name, map<TString, map<T1, T2> > m){ |
805 |
– |
return (m.find(name) == m.end()); |
806 |
– |
} |
807 |
– |
|
808 |
– |
// map<TString, map<TString, map<Int_t, Double_t> > > eventYield; |
809 |
– |
|
810 |
– |
|
811 |
– |
|
812 |
– |
|
813 |
– |
//================================================================================= isNew |
814 |
– |
template <typename T> |
815 |
– |
Bool_t isNew(TString name, TString label, map<TString, map<TString, T> > m){ |
816 |
– |
return (m[name].find(label) == m[name].end()); |
817 |
– |
} |
818 |
– |
|
819 |
– |
|
820 |
– |
|
821 |
– |
//================================================================================= isNew |
822 |
– |
template <typename T> |
823 |
– |
Bool_t isNew(T find, vector<T> v){ |
824 |
– |
for(Int_t i=0,N=v.size(); i<N; ++i){ |
825 |
– |
if(v[i]==find) return false; |
826 |
– |
} |
827 |
– |
return true; |
828 |
– |
} |
829 |
– |
|
830 |
– |
|
831 |
– |
|
832 |
– |
//================================================================================= GetValueFromTH1 |
833 |
– |
template <typename T> |
834 |
– |
Double_t GetBinFromTH1(T *h, Double_t value){ |
835 |
– |
Double_t maxValue = h->GetXaxis()->GetXmax(); |
836 |
– |
Int_t xMaxBin = h->GetNbinsX(); |
837 |
– |
Int_t xBin = 0; |
838 |
– |
if(value > maxValue) xBin = xMaxBin; |
839 |
– |
else{while(value > h->GetXaxis()->GetBinLowEdge(xBin+1)) ++xBin;} |
840 |
– |
|
841 |
– |
for(Int_t i=0; i<xMaxBin; ++i){ |
842 |
– |
cout<<"bin[" <<i<< "] = " << h->GetBinContent(i)<< endl; |
843 |
– |
} |
844 |
– |
cout<<"xBin = " << endl; |
845 |
– |
return xBin; |
846 |
– |
} |
847 |
– |
|
848 |
– |
|
849 |
– |
//================================================================================= GetValueFromTH1 |
850 |
– |
template <typename T> |
851 |
– |
Double_t GetValueFromTH1(T *h, Double_t value){ |
852 |
– |
Int_t bin = GetBinFromTH1<T>(h, value); |
853 |
– |
return h->GetBinContent(bin); |
854 |
– |
} |
855 |
– |
|
856 |
– |
|
857 |
– |
//================================================================================= GetBinFromTH2 |
858 |
– |
template <typename T> |
859 |
– |
void GetBinFromTH2(T *h, Int_t &xBin, Int_t &yBin, Double_t value1, Double_t value2){ |
860 |
– |
Double_t xMaxValue = h->GetXaxis()->GetXmax(); |
861 |
– |
Double_t yMaxValue = h->GetYaxis()->GetXmax(); |
862 |
– |
Int_t xMaxBin = h->GetNbinsX(); |
863 |
– |
Int_t yMaxBin = h->GetNbinsY(); |
864 |
– |
xBin = 0; |
865 |
– |
yBin = 0; |
866 |
– |
if(value1 > xMaxValue) xBin = xMaxBin; |
867 |
– |
else{while(value1 > h->GetXaxis()->GetBinLowEdge(xBin+1)) ++xBin;} |
868 |
– |
if(value2 > yMaxValue) yBin = yMaxBin; |
869 |
– |
else{while(value2 > h->GetYaxis()->GetBinLowEdge(yBin+1)) ++yBin;} |
870 |
– |
} |
871 |
– |
|
872 |
– |
|
873 |
– |
//================================================================================= GetValueFromTH2 |
874 |
– |
template <typename T> |
875 |
– |
Double_t GetValueFromTH2(T *h, Double_t value1, Double_t value2){ |
876 |
– |
Int_t xBin = 0; |
877 |
– |
Int_t yBin = 0; |
878 |
– |
GetBinFromTH2<T>(h, xBin, yBin, value1, value2); |
879 |
– |
return h->GetBinContent(xBin, yBin); |
880 |
– |
} |
881 |
– |
|
882 |
– |
|
883 |
– |
|
884 |
– |
|
885 |
– |
|
193 |
|
|
194 |
|
|
195 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
895 |
– |
|
896 |
– |
|
897 |
– |
|
898 |
– |
|
899 |
– |
|
900 |
– |
|
901 |
– |
|
902 |
– |
|
903 |
– |
|
904 |
– |
|
905 |
– |
|
906 |
– |
|
907 |
– |
|
202 |
|
#endif |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
913 |
– |
// //================================================================================= GetValueFromLeaf |
914 |
– |
// template <typename T> |
915 |
– |
// void GetValueFromLeafPtr(TString fileName, TString branchName, TString leafName, vector<T> **ptr, Long64_t entry){ |
916 |
– |
// TFile *file = new TFile(fileName,"READ"); |
917 |
– |
// TTree *fChain = (TTree*)file->Get(branchName); |
918 |
– |
// //fChain->AddFile(fileName); |
919 |
– |
// fChain->SetBranchStatus("*",0); |
920 |
– |
// fChain->SetBranchStatus(leafName, 1); |
921 |
– |
// //*ptr=0; |
922 |
– |
// fChain->SetBranchAddress(leafName, &(*ptr)); |
923 |
– |
// fChain->GetEntry(entry); |
924 |
– |
// } |
925 |
– |
|
926 |
– |
// //================================================================================= GetValueFromLeaf |
927 |
– |
// template <typename T> |
928 |
– |
// vector<T> GetValueFromLeaf(TString fileName, TString branchName, TString leafName, Long64_t entry){ |
929 |
– |
// TFile *file = new TFile(fileName,"READ"); |
930 |
– |
// TTree *fChain = (TTree*)file->Get(branchName); |
931 |
– |
// vector<T> *value; |
932 |
– |
// //fChain->AddFile(fileName); |
933 |
– |
// fChain->SetBranchStatus("*",0); |
934 |
– |
// fChain->SetBranchStatus(leafName, 1); |
935 |
– |
// fChain->SetBranchAddress(leafName, &(*value)); |
936 |
– |
// fChain->GetEntry(entry); |
937 |
– |
// return &(*value); |
938 |
– |
// } |
939 |
– |
|
940 |
– |
|
941 |
– |
|
207 |
|
|
208 |
|
|
209 |
|
|