-
Notifications
You must be signed in to change notification settings - Fork 0
/
HistHolder.h
125 lines (93 loc) · 4.13 KB
/
HistHolder.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
/*
to do:
all sort of protections are needed...
also, i should make sure that all interfaces accept all 3 possibilites:
const char* ("hello world")
std::string
TString
*/
#ifndef _HistHolder_h_
#define _HistHolder_h_
#include <map>
#include <string>
#include <TString.h>
#include <TH1.h>
#include <TH2.h>
#include <TFile.h>
class HistHolder {
public :
HistHolder();
virtual ~HistHolder();
//convention is to use lowercase for methods that are custom to this class
//and uppercase for those that share a name with a normal ROOT method
void make(std::string name, std::string title, Int_t nbins, Double_t min, Double_t max);
void make(std::string name, std::string title, Int_t nbins, Double_t min, Double_t max,std::string xtitle);
void make(std::string name, std::string title, Int_t nbins, Double_t min, Double_t max,
std::string xtitle, std::string ytitle);
void make2(std::string name, std::string title, Int_t nx, Double_t minx, Double_t maxx,
Int_t ny, Double_t miny, Double_t maxy);
//load histograms from files
//note that if the file is closed, the histo pointer may go away
Int_t load(TString name, TFile* file); //return 1=1D, 2=2D, 0=failure
//add a histogram...
void put(std::string name, TH1D* h) {histHolder_[name] = h;}
void put( TString name, TH1D* h) {histHolder_[std::string(name.Data())] = h;}
//select a group of histograms for the next operation
void select(const std::string str) {select_=str;}
void reject(const std::string str) {reject_=str;}
//these methods operate on the selected histograms
//use * to work with all (default)
//this group only operates on 1D histograms
void normalize(); //scale to unit area
void Write();
void Sumw2();
void SetMinimum(Double_t min);
void SetMaximum(Double_t max);
Float_t GetMaximum();
TString getMaximumName();
//only for 2D histograms
//to be implemented!
// void ProjectionX(); //should add the custom name argument
TH1D* operator[](std::string name) {return histHolder_[name]; }
TH1D* operator[](const char* name) {return histHolder_[std::string(name)]; }
TH1D* operator[](TString name) {return histHolder_[std::string(name.Data())]; }
TH1D* find(std::string name) {return histHolder_[name];}
TH1D* find(std::string name, TFile* file) {return histHolderP_[make_pair(name,file)];}
TH2F* find2(std::string name) {return histHolder2_[name];}
TH2F* find2(std::string name, TFile* file) {return histHolderP2_[make_pair(name,file)];}
void Print(TString opt="");
void reset(); //this resets the class (clear the data members)
void Reset(); //this calls TH1::Reset()
//these are just to allow use of char* or TString
TH1D* find(TString name) {return find(std::string(name.Data()));}
TH1D* find(TString name, TFile* file) {return find( std::string(name.Data()),file); }
TH2F* find2(TString name) {return find2( std::string(name.Data()));}
TH2F* find2(TString name, TFile* file) {return find2( std::string(name.Data()),file); }
TH1D* find(const char* name) {return find(std::string(name));}
TH1D* find(const char* name, TFile* file) {return find( std::string(name),file); }
TH2F* find2(const char* name) {return find2( std::string(name));}
TH2F* find2(const char* name, TFile* file) {return find2( std::string(name),file); }
private :
bool passesFilter(const std::string mystr, TFile* filep=0);
bool passesFilter( std::pair<std::string , TFile*> mypair) {return passesFilter( mypair.first,mypair.second);}
std::map< std::string, TH1D*> histHolder_;
std::map< std::string, TH2F*> histHolder2_;
std::map< std::pair< std::string, TFile*>, TH1D* > histHolderP_;
std::map< std::pair< std::string, TFile*>, TH2F* > histHolderP2_;
std::string select_;
std::string reject_;
};
// an auxilliary class
// problem = in CINT I cannot use a std::vector<TFile*>
// this is supposed to be an easy solution, basically just a minimal interface to std::vector
class FileHolder {
public :
FileHolder();
virtual ~FileHolder();
void add(TFile* filep) {files_.push_back(filep);}
unsigned int size() {return files_.size();}
TFile* at(unsigned int n) { return files_.at(n); }
private :
std::vector<TFile*> files_;
};
#endif