ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/joshmt/HistHolder.h
Revision: 1.1
Committed: Mon Mar 29 16:06:36 2010 UTC (15 years, 1 month ago) by joshmt
Content type: text/plain
Branch: MAIN
Log Message:
more mature plotting utilities

File Contents

# User Rev Content
1 joshmt 1.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, TH1F* h) {histHolder_[name] = h;}
44     void put( TString name, TH1F* 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     TH1F* operator[](std::string name) {return histHolder_[name]; }
68     TH1F* operator[](const char* name) {return histHolder_[std::string(name)]; }
69     TH1F* operator[](TString name) {return histHolder_[std::string(name.Data())]; }
70    
71     TH1F* find(std::string name) {return histHolder_[name];}
72     TH1F* 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();
78    
79     //these are just to allow use of char* or TString
80     TH1F* find(TString name) {return find(std::string(name.Data()));}
81     TH1F* find(TString name, TFile* file) {return find( std::string(name.Data()),file); }
82     TH2F* find2(TString name) {return find2( std::string(name.Data()));}
83     TH2F* find2(TString name, TFile* file) {return find2( std::string(name.Data()),file); }
84    
85     TH1F* find(const char* name) {return find(std::string(name));}
86     TH1F* find(const char* name, TFile* file) {return find( std::string(name),file); }
87     TH2F* find2(const char* name) {return find2( std::string(name));}
88     TH2F* find2(const char* name, TFile* file) {return find2( std::string(name),file); }
89    
90     private :
91     bool passesFilter(const std::string mystr, TFile* filep=0);
92     bool passesFilter( std::pair<std::string , TFile*> mypair) {return passesFilter( mypair.first,mypair.second);}
93    
94     std::map< std::string, TH1F*> histHolder_;
95     std::map< std::string, TH2F*> histHolder2_;
96    
97     std::map< std::pair< std::string, TFile*>, TH1F* > histHolderP_;
98     std::map< std::pair< std::string, TFile*>, TH2F* > histHolderP2_;
99    
100     std::string select_;
101     std::string reject_;
102     };
103    
104     // an auxilliary class
105     // problem = in CINT I cannot use a std::vector<TFile*>
106     // this is supposed to be an easy solution, basically just a minimal interface to std::vector
107    
108     class FileHolder {
109     public :
110     FileHolder();
111     virtual ~FileHolder();
112    
113     void add(TFile* filep) {files_.push_back(filep);}
114     unsigned int size() {return files_.size();}
115    
116     TFile* at(unsigned int n) { return files_.at(n); }
117    
118     private :
119    
120     std::vector<TFile*> files_;
121    
122     };
123    
124     #endif