1 |
/*
|
2 |
to do:
|
3 |
all sort of protections are needed...
|
4 |
|
5 |
also, i should make sure that all interfaces accept all 3 possibilites:
|
6 |
const char* ("hello world")
|
7 |
std::string
|
8 |
TString
|
9 |
*/
|
10 |
#ifndef _HistHolder_h_
|
11 |
#define _HistHolder_h_
|
12 |
|
13 |
#include <map>
|
14 |
#include <string>
|
15 |
#include <TString.h>
|
16 |
#include <TH1.h>
|
17 |
#include <TH2.h>
|
18 |
#include <TFile.h>
|
19 |
|
20 |
class HistHolder {
|
21 |
public :
|
22 |
|
23 |
HistHolder();
|
24 |
virtual ~HistHolder();
|
25 |
|
26 |
//convention is to use lowercase for methods that are custom to this class
|
27 |
//and uppercase for those that share a name with a normal ROOT method
|
28 |
|
29 |
void make(std::string name, std::string title, Int_t nbins, Double_t min, Double_t max);
|
30 |
void make(std::string name, std::string title, Int_t nbins, Double_t min, Double_t max,std::string xtitle);
|
31 |
void make(std::string name, std::string title, Int_t nbins, Double_t min, Double_t max,
|
32 |
std::string xtitle, std::string ytitle);
|
33 |
|
34 |
void make2(std::string name, std::string title, Int_t nx, Double_t minx, Double_t maxx,
|
35 |
Int_t ny, Double_t miny, Double_t maxy);
|
36 |
|
37 |
//load histograms from files
|
38 |
//note that if the file is closed, the histo pointer may go away
|
39 |
Int_t load(TString name, TFile* file); //return 1=1D, 2=2D, 0=failure
|
40 |
|
41 |
//add a histogram...
|
42 |
|
43 |
void put(std::string name, TH1D* h) {histHolder_[name] = h;}
|
44 |
void put( TString name, TH1D* h) {histHolder_[std::string(name.Data())] = h;}
|
45 |
|
46 |
|
47 |
//select a group of histograms for the next operation
|
48 |
void select(const std::string str) {select_=str;}
|
49 |
void reject(const std::string str) {reject_=str;}
|
50 |
|
51 |
//these methods operate on the selected histograms
|
52 |
//use * to work with all (default)
|
53 |
|
54 |
//this group only operates on 1D histograms
|
55 |
void normalize(); //scale to unit area
|
56 |
void Write();
|
57 |
void Sumw2();
|
58 |
void SetMinimum(Double_t min);
|
59 |
void SetMaximum(Double_t max);
|
60 |
Float_t GetMaximum();
|
61 |
TString getMaximumName();
|
62 |
//only for 2D histograms
|
63 |
//to be implemented!
|
64 |
// void ProjectionX(); //should add the custom name argument
|
65 |
|
66 |
|
67 |
TH1D* operator[](std::string name) {return histHolder_[name]; }
|
68 |
TH1D* operator[](const char* name) {return histHolder_[std::string(name)]; }
|
69 |
TH1D* operator[](TString name) {return histHolder_[std::string(name.Data())]; }
|
70 |
|
71 |
TH1D* find(std::string name) {return histHolder_[name];}
|
72 |
TH1D* find(std::string name, TFile* file) {return histHolderP_[make_pair(name,file)];}
|
73 |
TH2F* find2(std::string name) {return histHolder2_[name];}
|
74 |
TH2F* find2(std::string name, TFile* file) {return histHolderP2_[make_pair(name,file)];}
|
75 |
|
76 |
void Print(TString opt="");
|
77 |
void reset(); //this resets the class (clear the data members)
|
78 |
void Reset(); //this calls TH1::Reset()
|
79 |
|
80 |
//these are just to allow use of char* or TString
|
81 |
TH1D* find(TString name) {return find(std::string(name.Data()));}
|
82 |
TH1D* find(TString name, TFile* file) {return find( std::string(name.Data()),file); }
|
83 |
TH2F* find2(TString name) {return find2( std::string(name.Data()));}
|
84 |
TH2F* find2(TString name, TFile* file) {return find2( std::string(name.Data()),file); }
|
85 |
|
86 |
TH1D* find(const char* name) {return find(std::string(name));}
|
87 |
TH1D* find(const char* name, TFile* file) {return find( std::string(name),file); }
|
88 |
TH2F* find2(const char* name) {return find2( std::string(name));}
|
89 |
TH2F* find2(const char* name, TFile* file) {return find2( std::string(name),file); }
|
90 |
|
91 |
private :
|
92 |
bool passesFilter(const std::string mystr, TFile* filep=0);
|
93 |
bool passesFilter( std::pair<std::string , TFile*> mypair) {return passesFilter( mypair.first,mypair.second);}
|
94 |
|
95 |
std::map< std::string, TH1D*> histHolder_;
|
96 |
std::map< std::string, TH2F*> histHolder2_;
|
97 |
|
98 |
std::map< std::pair< std::string, TFile*>, TH1D* > histHolderP_;
|
99 |
std::map< std::pair< std::string, TFile*>, TH2F* > histHolderP2_;
|
100 |
|
101 |
std::string select_;
|
102 |
std::string reject_;
|
103 |
};
|
104 |
|
105 |
// an auxilliary class
|
106 |
// problem = in CINT I cannot use a std::vector<TFile*>
|
107 |
// this is supposed to be an easy solution, basically just a minimal interface to std::vector
|
108 |
|
109 |
class FileHolder {
|
110 |
public :
|
111 |
FileHolder();
|
112 |
virtual ~FileHolder();
|
113 |
|
114 |
void add(TFile* filep) {files_.push_back(filep);}
|
115 |
unsigned int size() {return files_.size();}
|
116 |
|
117 |
TFile* at(unsigned int n) { return files_.at(n); }
|
118 |
|
119 |
private :
|
120 |
|
121 |
std::vector<TFile*> files_;
|
122 |
|
123 |
};
|
124 |
|
125 |
#endif
|