1 |
mstein |
1.1 |
#include <iostream>
|
2 |
|
|
#include <map>
|
3 |
|
|
#include <vector>
|
4 |
|
|
|
5 |
|
|
#include "TString.h"
|
6 |
|
|
#include "TH1.h"
|
7 |
|
|
#include "TH1D.h"
|
8 |
|
|
#include "TFile.h"
|
9 |
|
|
//#include "TObject.h"
|
10 |
|
|
|
11 |
|
|
#include "plotMaker.h"
|
12 |
|
|
|
13 |
|
|
// #include "TDirectory.h"
|
14 |
|
|
#include "tools.h"
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
//================================================================================= constructor: plotMaker
|
18 |
|
|
plotMaker::plotMaker(){
|
19 |
|
|
TH1::SetDefaultSumw2();
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
//================================================================================= destructor: plotMaker
|
24 |
|
|
plotMaker::~plotMaker(){
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
//here the new histogram is created
|
29 |
|
|
//================================================================================= addh1d
|
30 |
|
|
void plotMaker::addh1d(TString name, TString title, TString xtitle, TString ytitle, Int_t bin, Double_t low, Double_t up){
|
31 |
|
|
if(isNewh1d(name)){
|
32 |
|
|
TH1D* temp = new TH1D(name, title, bin, low, up);
|
33 |
|
|
h1d[name] = temp;
|
34 |
|
|
h1d[name]->GetXaxis()->SetTitle(xtitle);
|
35 |
|
|
h1d[name]->GetYaxis()->SetTitle(ytitle);
|
36 |
|
|
h1d[name]->Sumw2();
|
37 |
|
|
}
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
//add a new histogram if its not present yet, and fill it
|
42 |
|
|
//================================================================================= addh1d
|
43 |
|
|
void plotMaker::addh1d(TString name, TString title, TString xtitle, TString ytitle, Int_t bin, Double_t low, Double_t up, Double_t value, Double_t weight){
|
44 |
|
|
if(isNewh1d(name)) addh1d(name, title, xtitle, ytitle, bin, low, up);
|
45 |
|
|
h1d[name]->Fill(value, weight);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
//add external histogram to the collection
|
50 |
|
|
//================================================================================= addh1d
|
51 |
|
|
void plotMaker::addh1d(TH1D* h){
|
52 |
|
|
if(!isNewh1d(h->GetName())) cout<<"WARNING: a TH1D with this name (" << h->GetName() << ") exists already! You are overwriting histograms!" << endl;
|
53 |
|
|
else{h1d[h->GetName()]=h; h->Sumw2();}
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
//add external histogram to the collection and rename it
|
58 |
|
|
//================================================================================= addh1d
|
59 |
|
|
void plotMaker::addh1d(TString newName, TH1D* h){
|
60 |
|
|
if(!isNewh1d(newName)) cout<<"WARNING: name (" << h->GetName() << ") already exists! You are overwriting histograms!" << endl;
|
61 |
|
|
else{
|
62 |
|
|
h->SetName(newName);
|
63 |
|
|
h->SetTitle(newName);
|
64 |
|
|
addh1d(h);
|
65 |
|
|
}
|
66 |
|
|
//else {cout<<"TH1D name changed: " << h->GetName() << "--> " << newName << endl; h->SetName(newName); h1d[h->GetName()] = h;}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
//add multiple external histograms to the collection
|
71 |
|
|
//================================================================================= addh1d
|
72 |
|
|
void plotMaker::addh1d(vector<TH1D*> h){
|
73 |
|
|
for(UInt_t i=0,N=h.size(); i<N; ++i){
|
74 |
|
|
addh1d(h.at(i));
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
//add histogram from external root file
|
80 |
|
|
//================================================================================= addh1d
|
81 |
|
|
void plotMaker::addh1d(TString fileName, TString name){
|
82 |
|
|
TH1D *h = tools::GetHistFromFile<TH1D>(fileName, name);
|
83 |
|
|
addh1d(h);
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
//add histogram from external root file and rename it
|
88 |
|
|
//================================================================================= addh1d
|
89 |
|
|
void plotMaker::addh1d(TString newName, TString fileName, TString name){
|
90 |
|
|
TH1D *h = tools::GetHistFromFile<TH1D>(fileName, name);
|
91 |
|
|
addh1d(newName, h);
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
//add multiple histograms from external root file
|
96 |
|
|
//================================================================================= addh1d
|
97 |
|
|
void plotMaker::addh1d(TString fileName, vector<TString> names){
|
98 |
|
|
for(Int_t i=0,N=names.size(); i<N; ++i) addh1d(fileName, names[i]);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
//================================================================================= isNewh1d
|
103 |
|
|
bool plotMaker::isNewh1d(TString name){
|
104 |
|
|
return (h1d.find(name) == h1d.end());
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
//================================================================================= savePlots
|
109 |
|
|
void plotMaker::savePlots(TString fileName, TString option, TString dirName){
|
110 |
|
|
TFile *outputFile = new TFile(fileName, option);
|
111 |
|
|
outputFile->mkdir(dirName);
|
112 |
|
|
outputFile->cd(dirName);
|
113 |
|
|
for(typename map<TString, TH1D*>::iterator it = h1d.begin(); it != h1d.end(); ++it){
|
114 |
|
|
//cout<<"name = " << it->second->GetName()<< endl;
|
115 |
|
|
it->second->Write(it->second->GetName());
|
116 |
|
|
}
|
117 |
|
|
outputFile->Close();
|
118 |
|
|
delete outputFile;
|
119 |
|
|
if(option=="RECREATE") cout<<"-----> Created File: \"" << fileName << "\" --------> \"" << dirName << "\"" <<endl;
|
120 |
|
|
if(option=="UPDATE") cout<<"-----> Updated File: \"" << fileName << "\" --------> \"" << dirName << "\"" <<endl;
|
121 |
|
|
|
122 |
|
|
//system("ps2pdf "+outputFileDir+".ps "+ "outputFileDir"+".pdf");
|
123 |
|
|
//cout<<"output File created (*.ps and *.pdf): " << outputFileDir << endl;
|
124 |
|
|
//system("sleep 1");
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
// //================================================================================= saveSinglePlots
|
129 |
|
|
// template <typename T>
|
130 |
|
|
// void plotMaker::savePlotsAsImage(TFile *file, map<TString, T> m, TString dir, TDirectory *myDir){
|
131 |
|
|
//
|
132 |
|
|
// // TCanvas *c = new TCanvas("temp","temp",0,0,1200,1200);
|
133 |
|
|
// // for(typename map<TString, T >::iterator it = m.begin(); it != m.end(); ++it){
|
134 |
|
|
// // //cout<<"name = " << it->second->GetName()<< endl;
|
135 |
|
|
// // it->second->Write(it->second->GetName());
|
136 |
|
|
// // it->second->Draw("");
|
137 |
|
|
// // c->Update();
|
138 |
|
|
// // //Double_t x = it->second->GetXaxis()->GetXmin() + fabs(it->second->GetXaxis()->GetXmax()-it->second->GetXaxis()->GetXmin())/4;
|
139 |
|
|
// // //Double_t y = (it->second->GetMaximum());
|
140 |
|
|
// // }
|
141 |
|
|
// // c->Close();
|
142 |
|
|
// }
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
// //================================================================================= saveSingleFiles
|
165 |
|
|
// //Usage saveSingleFiles(pl1.h1d, 1, 0, 1);
|
166 |
|
|
// template <typename T>
|
167 |
|
|
// void plotMaker::saveSingleFiles(map<TString, T > m, Bool_t root_flg, Bool_t eps_flg, Bool_t gif_flg, TString dir){
|
168 |
|
|
// Int_t dummy = system("mkdir " + dir); dummy=0;
|
169 |
|
|
// if(root_flg || eps_flg || gif_flg){
|
170 |
|
|
// for(typename map<TString, T>::iterator it = m.begin(); it != m.end(); ++it){
|
171 |
|
|
// it->second->Draw();
|
172 |
|
|
// TString name=dir; name += it->second->GetName();
|
173 |
|
|
// if(root_flg){it->second->Print(name+".root");}
|
174 |
|
|
// if(eps_flg){it->second->Print(name+".eps");}
|
175 |
|
|
// if(gif_flg){it->second->Print(name+".gif");
|
176 |
|
|
// }
|
177 |
|
|
// }
|
178 |
|
|
// }
|
179 |
|
|
// }
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
|