1 |
|
#include "PlotTool.h" |
2 |
|
//------------------------------------------------------------------ |
3 |
|
//Constructur: Set some global Variables to define canvas output |
4 |
< |
PlotTool::PlotTool() |
5 |
< |
{ |
4 |
> |
PlotTool::PlotTool() { |
5 |
> |
|
6 |
> |
this->SetClass("TChain", 100); |
7 |
|
|
8 |
< |
this->SetClass("TChain",100); |
8 |
> |
samePad_trees = true; |
9 |
> |
samePad_vars = false; |
10 |
> |
samePad_cuts = false; |
11 |
> |
sameCanv_trees = false; |
12 |
> |
sameCanv_vars = false; |
13 |
> |
sameCanv_cuts = false; |
14 |
|
|
15 |
< |
samePad_trees = true; |
16 |
< |
samePad_vars = false; |
17 |
< |
samePad_cuts = false; |
12 |
< |
sameCanv_trees = false; |
13 |
< |
sameCanv_vars = false; |
14 |
< |
sameCanv_cuts = false; |
15 |
> |
showLegend = false; |
16 |
> |
logY = true; |
17 |
> |
verbose = true; |
18 |
|
|
19 |
< |
showLegend = false; |
17 |
< |
logY = true; |
19 |
> |
globalCuts=""; |
20 |
|
|
21 |
+ |
varBlockNames = ""; //Set to "ALL" or add Names, i.e. varBlockNames += "CaloTower" |
22 |
+ |
recreateTree = false; //force recreation of friend tree |
23 |
|
|
24 |
|
} |
25 |
|
|
26 |
|
//------------------------------------------------------------------ |
27 |
|
//Fill object PlotTool with Chains constructed from files from given source |
24 |
– |
int PlotTool::init(string fileName, string dirPath, string treeName) |
25 |
– |
{ |
26 |
– |
//make file for tree friends (adding additional, computed branches) |
27 |
– |
string friendFileName("/scratch/hh/lustre/cms/user/thomsen/temp/"); |
28 |
– |
friendFileName += fileName; |
29 |
– |
friendFileName += ".root"; |
30 |
– |
TFile *f = new TFile(friendFileName.c_str(),"recreate"); |
31 |
– |
TTree *friendTree = new TTree("friendTree","friendTree"); |
28 |
|
|
29 |
+ |
int PlotTool::init(string fileName, string dirPath, string treeName, |
30 |
+ |
string fileLabel) { |
31 |
+ |
this->New(this->GetEntries() ); |
32 |
+ |
int currChain = this->GetEntries() - 1; |
33 |
|
|
34 |
+ |
if (currChain < 0) |
35 |
+ |
return currChain; |
36 |
|
|
37 |
< |
this->New( this->GetEntries() ); |
38 |
< |
int currChain = this->GetEntries() - 1; |
37 |
> |
TStopwatch timer; |
38 |
> |
timer.Start(); |
39 |
> |
|
40 |
> |
|
41 |
> |
fileNames.clear(); |
42 |
|
|
43 |
< |
if(currChain < 0 ) return currChain; |
43 |
> |
//check if alternative label is different from default(searchString) |
44 |
> |
if (fileLabel=="") { |
45 |
> |
fileLabel=fileName; |
46 |
> |
} |
47 |
> |
((TChain*) this->At(currChain))->SetName(fileLabel.c_str()); |
48 |
> |
|
49 |
> |
TList *files = new TList(); |
50 |
> |
TSystemFile* sysFile = 0; |
51 |
> |
if(fileName.find(".") != string::npos) { |
52 |
> |
ifstream f(fileName.c_str()); |
53 |
> |
if( ! f.is_open() ) return -1; |
54 |
> |
string line; |
55 |
> |
|
56 |
> |
while (!f.eof()) { |
57 |
> |
getline(f,line); |
58 |
> |
sysFile = new TSystemFile(line.c_str(),dirPath.c_str()); |
59 |
> |
files->Add(sysFile); |
60 |
> |
} |
61 |
|
|
62 |
|
|
63 |
< |
((TChain*) this->At(currChain))->SetName(fileName.c_str()); |
64 |
< |
TSystemDirectory dir("sourceDir",dirPath.c_str()); |
65 |
< |
TList *files = dir.GetListOfFiles(); |
66 |
< |
if (files) { |
67 |
< |
TIter next(files); |
68 |
< |
TSystemFile *file; |
63 |
> |
} else { |
64 |
> |
TSystemDirectory dir("sourceDir", dirPath.c_str()); |
65 |
> |
files = dir.GetListOfFiles(); |
66 |
> |
} |
67 |
> |
if (files->GetEntries()>0) { |
68 |
> |
TIter next(files); |
69 |
> |
TSystemFile *file; |
70 |
|
TString fname; |
71 |
|
string filePath; |
72 |
|
|
73 |
< |
cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: "<<fileName.c_str()<<endl; |
73 |
> |
if(verbose && fileName.find(".") == string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
74 |
> |
<<fileName.c_str()<<endl; |
75 |
> |
if(verbose && fileName.find(".") != string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search lines with .root in: " |
76 |
> |
<<fileName.c_str()<<endl; |
77 |
> |
|
78 |
|
|
79 |
< |
while ((file=(TSystemFile*)next())) { |
80 |
< |
fname = file->GetName(); |
81 |
< |
if (!fname.EndsWith(".root")) continue; |
82 |
< |
if (!fname.Contains(fileName.c_str())) continue; |
79 |
> |
while ((file=(TSystemFile*)next())) { |
80 |
> |
fname = file->GetName(); |
81 |
> |
if (!fname.EndsWith(".root")) |
82 |
> |
continue; |
83 |
> |
if (!fname.Contains(fileName.c_str()) && fileName.find(".") == string::npos ) |
84 |
> |
continue; |
85 |
|
|
86 |
|
filePath = dirPath; |
87 |
|
filePath += fname.Data(); |
88 |
|
//fwlite::ChainEvent to lop over events, jets, etc |
89 |
|
fileNames.push_back(filePath.c_str()); |
90 |
|
|
91 |
< |
if( ((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, treeName.c_str()) ) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
92 |
< |
else return -1; |
91 |
> |
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
92 |
> |
treeName.c_str()) ) { |
93 |
> |
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
94 |
> |
} else { |
95 |
> |
return -1; |
96 |
> |
} |
97 |
|
|
98 |
|
} |
99 |
< |
} else return -1; |
99 |
> |
} else |
100 |
> |
return -1; |
101 |
|
|
102 |
< |
for(int i=0;i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries();++i){ |
102 |
> |
for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) { |
103 |
|
|
104 |
|
string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName()); |
105 |
< |
size_t a = s.find("_"); |
106 |
< |
if(a == string::npos) a = 0; |
73 |
< |
size_t b = s.find("_", a+1); |
74 |
< |
if(b == string::npos) b = 50; |
75 |
< |
string branch_alias = s.substr(a+1,b-a-1); |
105 |
> |
|
106 |
> |
string branch_alias = s; |
107 |
|
string branch_name = s; |
108 |
< |
if(s.find(".",s.size()-1) != string::npos ) branch_name += "obj"; |
109 |
< |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),branch_name.c_str()); |
108 |
> |
if (s.find(".", s.size()-1) != string::npos) |
109 |
> |
branch_name += "obj"; |
110 |
> |
|
111 |
> |
size_t a = s.find("_"); |
112 |
> |
if (a != string::npos) { |
113 |
> |
size_t b = s.find("_", a+1); |
114 |
> |
if (b != string::npos) { |
115 |
> |
size_t c = s.find("_", b+1); |
116 |
> |
if (c != string::npos) { |
117 |
> |
string _prod =s.substr(0,a); |
118 |
> |
string _label =s.substr(a+1, b-a-1); |
119 |
> |
string _instance =s.substr(b+1, c-b-1); |
120 |
> |
branch_alias = _label; |
121 |
> |
if(_instance.length() > 0 ) { |
122 |
> |
branch_alias += "_"; |
123 |
> |
branch_alias += _instance; |
124 |
> |
((TChain*) this->At(currChain))->SetAlias(_instance.c_str(), |
125 |
> |
branch_name.c_str()); |
126 |
> |
} |
127 |
> |
string branch_alias_full = _prod + "_" + branch_alias; |
128 |
> |
((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(), |
129 |
> |
branch_name.c_str()); |
130 |
> |
} |
131 |
> |
} |
132 |
> |
} |
133 |
> |
|
134 |
> |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
135 |
> |
branch_name.c_str()); |
136 |
|
|
137 |
|
} |
81 |
– |
// add branch with track Jets |
82 |
– |
|
83 |
– |
int nJetsKT; |
84 |
– |
TrackJetKT = new float [100]; |
85 |
– |
fwlite::ChainEvent ev(fileNames); |
86 |
– |
|
87 |
– |
TBranch *BnJetsKT = friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
88 |
– |
TBranch *BTrackJetKT = friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
89 |
– |
//TBranch *BnJetsKT = ((TChain*) this->At(currChain))->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
90 |
– |
//TBranch *BTrackJetKT = ((TChain*) this->At(currChain))->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
138 |
|
|
139 |
|
|
140 |
< |
cout<<"calculating additional variables..."<<endl; |
141 |
< |
for( ev.toBegin();! ev.atEnd();++ev) { |
140 |
> |
|
141 |
> |
|
142 |
|
|
143 |
< |
fwlite::Handle<reco::CaloJetCollection> jets; |
97 |
< |
jets.getByLabel(ev,"antikt5CaloJets"); |
143 |
> |
string friendTreeName("friendTree"); |
144 |
|
|
145 |
< |
fwlite::Handle<reco::TrackCollection> tracks; |
146 |
< |
tracks.getByLabel(ev,"generalTracks"); |
145 |
> |
string friendFileName("/scratch/hh/current/cms/user/"); |
146 |
> |
friendFileName += gSystem->GetUserInfo()->fUser; |
147 |
> |
friendFileName += "/temp/"; |
148 |
> |
friendFileName += fileLabel; |
149 |
> |
friendFileName += ".root"; |
150 |
> |
string fileOpt = "update"; |
151 |
> |
if( recreateTree ) fileOpt = "recreate"; |
152 |
|
|
153 |
< |
if(!jets.isValid()) continue; |
154 |
< |
if(!tracks.isValid()) continue; |
155 |
< |
double trackSum; |
156 |
< |
nJetsKT = 0; |
157 |
< |
for(reco::CaloJetCollection::const_iterator jet = jets->begin(); jet!=jets->end();jet++) |
158 |
< |
{ |
159 |
< |
trackSum = 0; |
160 |
< |
for(reco::TrackCollection::const_iterator track = tracks->begin(); track!=tracks->end();track++) |
161 |
< |
{ |
111 |
< |
if( deltaR(jet->eta(),jet->phi(),track->eta(),track->phi()) < 0.5) trackSum += track->pt(); |
112 |
< |
} |
113 |
< |
TrackJetKT[nJetsKT] = trackSum; |
114 |
< |
nJetsKT++; |
115 |
< |
} |
116 |
< |
//((TChain*) this->At(currChain))->FindBranch("nJetsKT")->Fill(); |
117 |
< |
//((TChain*) this->At(currChain))->FindBranch("TrackJetKT")->Fill(); |
118 |
< |
BnJetsKT->Fill(); |
119 |
< |
BTrackJetKT->Fill(); |
153 |
> |
FWliteVariables fwVars(friendTreeName, friendFileName, fileOpt); |
154 |
> |
|
155 |
> |
if(varBlockNames.length() > 1 ) { |
156 |
> |
fwVars.loop(fileNames, varBlockNames); |
157 |
> |
if(verbose) cout<<"add friend tree with additional variables: "<<varBlockNames<<endl; |
158 |
> |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
159 |
> |
friendFileName.c_str()); |
160 |
> |
} else { |
161 |
> |
if(verbose) cout<<"No additional variables added."<<endl; |
162 |
|
} |
163 |
< |
f->cd(); |
122 |
< |
friendTree->Write(); |
123 |
< |
((TChain*) this->At(currChain))->AddFriend("friendTree",f); |
163 |
> |
|
164 |
|
|
165 |
+ |
|
166 |
+ |
|
167 |
+ |
|
168 |
+ |
timer.Stop(); |
169 |
+ |
if(verbose) timer.Print(); |
170 |
+ |
|
171 |
|
return this->GetEntries(); |
172 |
|
|
173 |
|
} |
174 |
|
//------------------------------------------------------------------ |
175 |
|
//Draw given Chain with given variable and given cuts |
176 |
< |
int PlotTool::plot(int chainIndex, string histName, string cutName, int nEntries, string drwOpt) |
177 |
< |
{ |
176 |
> |
int PlotTool::plot(int chainIndex, string histName, string cutName, |
177 |
> |
int nEntries, string drwOpt) { |
178 |
|
|
179 |
< |
if( chainIndex >= this->GetEntries() ) return -1; |
179 |
> |
if (chainIndex >= this->GetEntries() ) |
180 |
> |
return -1; |
181 |
|
|
182 |
< |
int currN = nEntries; |
183 |
< |
if(nEntries < 0) currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
184 |
< |
|
185 |
< |
//++++ Create and name Canvases according to global variables +++++++++++++ |
186 |
< |
ostringstream currHistName; |
140 |
< |
if( samePad_trees) currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
141 |
< |
if( samePad_vars) currHistName<<histName; |
142 |
< |
if( samePad_cuts) currHistName<<"{"<<cutName<<"}"; |
143 |
< |
|
144 |
< |
ostringstream currPadName; |
145 |
< |
if(! samePad_trees) currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
146 |
< |
if(! samePad_vars) currPadName<<histName; |
147 |
< |
if(! samePad_cuts) currPadName<<"{"<<cutName<<"}"; |
148 |
< |
|
149 |
< |
ostringstream currCanvName; |
150 |
< |
if(! sameCanv_trees && ! samePad_trees ) currCanvName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
151 |
< |
if(! sameCanv_vars && ! samePad_vars) currCanvName<<histName; |
152 |
< |
if(! sameCanv_cuts && ! samePad_cuts) currCanvName<<"{"<<cutName<<"}"; |
182 |
> |
TStopwatch timer; |
183 |
> |
if(verbose) { |
184 |
> |
cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
185 |
> |
timer.Start(); |
186 |
> |
} |
187 |
|
|
188 |
< |
if( (sameCanv_trees || samePad_trees) && (sameCanv_vars || samePad_vars) && (sameCanv_cuts || samePad_cuts) ) currCanvName<<"All"; |
188 |
> |
int currN = nEntries; |
189 |
> |
if (nEntries < 0) |
190 |
> |
currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
191 |
> |
|
192 |
> |
//++++ Create and name Canvases according to global variables +++++++++++++ |
193 |
> |
ostringstream currHistName; |
194 |
> |
if (samePad_trees) |
195 |
> |
currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
196 |
> |
if (samePad_vars) |
197 |
> |
currHistName<<histName; |
198 |
> |
if (samePad_cuts) |
199 |
> |
currHistName<<"{"<<cutName<<"}"; |
200 |
> |
|
201 |
> |
ostringstream currPadName; |
202 |
> |
if (!samePad_trees) |
203 |
> |
currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
204 |
> |
if (!samePad_vars) |
205 |
> |
currPadName<<histName; |
206 |
> |
if (!samePad_cuts) |
207 |
> |
currPadName<<"{"<<cutName<<"}"; |
208 |
> |
|
209 |
> |
ostringstream currCanvName; |
210 |
> |
if (!sameCanv_trees && !samePad_trees) |
211 |
> |
currCanvName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
212 |
> |
if (!sameCanv_vars && !samePad_vars) |
213 |
> |
currCanvName<<histName; |
214 |
> |
if (!sameCanv_cuts && !samePad_cuts) |
215 |
> |
currCanvName<<"{"<<cutName<<"}"; |
216 |
> |
|
217 |
> |
if ( (sameCanv_trees || samePad_trees) && (sameCanv_vars || samePad_vars) |
218 |
> |
&& (sameCanv_cuts || samePad_cuts)) |
219 |
> |
currCanvName<<"All"; |
220 |
> |
|
221 |
> |
string currOpt = drwOpt; |
222 |
> |
bool useSubPads = (sameCanv_trees && !samePad_trees) || (sameCanv_vars |
223 |
> |
&& !samePad_vars) || (sameCanv_cuts && !samePad_cuts); |
224 |
> |
|
225 |
> |
if (useSubPads) { |
226 |
> |
if ( !canvases_[currCanvName.str()] || !gROOT->GetListOfCanvases()->FindObject(currCanvName.str().c_str()) ) { |
227 |
> |
canvases_[currCanvName.str()] = new TCanvas(currCanvName.str().c_str(), currCanvName.str().c_str()); |
228 |
> |
} else if (canvases_[currCanvName.str()]->GetNumber() >= 0) { |
229 |
> |
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()+1); |
230 |
> |
} |
231 |
> |
} |
232 |
|
|
233 |
< |
|
234 |
< |
string currOpt = drwOpt; |
235 |
< |
bool useSubPads = (sameCanv_trees && !samePad_trees) || (sameCanv_vars && !samePad_vars) || (sameCanv_cuts && !samePad_cuts); |
233 |
> |
if ( !pads_[currPadName.str()] || !gROOT->GetListOfCanvases()->FindObject(currPadName.str().c_str()) ) { |
234 |
> |
pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str()); |
235 |
> |
// if (logY) |
236 |
> |
// pads_[currPadName.str()]->SetLogy(1); |
237 |
> |
} else { |
238 |
> |
pads_[currPadName.str()]->cd(); |
239 |
> |
currOpt += "SAMES"; |
240 |
> |
if (useSubPads) |
241 |
> |
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
242 |
> |
} |
243 |
> |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
244 |
|
|
160 |
– |
if( useSubPads ) { |
161 |
– |
if( ! canvases_[currCanvName.str()] || ! gROOT->FindObject(currCanvName.str().c_str()) ) { |
162 |
– |
canvases_[currCanvName.str()] = new TCanvas(currCanvName.str().c_str(), currCanvName.str().c_str()); |
163 |
– |
} else if ( canvases_[currCanvName.str()]->GetNumber() >= 0 ) { |
164 |
– |
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()+1); |
165 |
– |
} |
166 |
– |
} |
167 |
– |
|
168 |
– |
if( ! pads_[currPadName.str()] || ! gROOT->FindObject(currPadName.str().c_str()) ) { |
169 |
– |
pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str()); |
170 |
– |
if(logY) pads_[currPadName.str()]->SetLogy(1); |
171 |
– |
} else { |
172 |
– |
pads_[currPadName.str()]->cd(); |
173 |
– |
currOpt += "SAMES"; |
174 |
– |
if(useSubPads) canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
175 |
– |
} |
176 |
– |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
245 |
|
|
246 |
+ |
//Draw histogram: |
247 |
+ |
string cutNameWithGlobal = cutName; |
248 |
+ |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += "&&"; |
249 |
+ |
if(globalCuts!="") cutNameWithGlobal += globalCuts; |
250 |
+ |
|
251 |
+ |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutNameWithGlobal.c_str(), |
252 |
+ |
currOpt.c_str(), currN); |
253 |
+ |
if (draw_err < 0) |
254 |
+ |
return draw_err; |
255 |
+ |
|
256 |
+ |
//++++ Fix for histos with no entries +++++++++++++ |
257 |
+ |
if (draw_err == 0) { |
258 |
+ |
if (currOpt.find("SAMES") == string::npos) { |
259 |
+ |
pads_[currPadName.str()]->Close(); |
260 |
+ |
pads_.erase(currPadName.str() ); |
261 |
+ |
if (useSubPads) |
262 |
+ |
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
263 |
+ |
} |
264 |
+ |
cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str() |
265 |
+ |
<<" has no entries and is not drawn!"<<endl; |
266 |
+ |
return draw_err; |
267 |
+ |
} |
268 |
+ |
//++++++++++++++++++++++++++++++++++++++++++++++++++ |
269 |
|
|
270 |
< |
//Draw histogram: |
180 |
< |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(), currOpt.c_str(), currN); |
181 |
< |
if( draw_err < 0 ) return draw_err; |
182 |
< |
|
183 |
< |
//++++ Fix for histos with no entries +++++++++++++ |
184 |
< |
if( draw_err == 0 ) { |
185 |
< |
if( currOpt.find("SAMES") == string::npos ) { |
186 |
< |
pads_[currPadName.str()]->Close(); |
187 |
< |
pads_.erase( currPadName.str() ); |
188 |
< |
if(useSubPads) canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
189 |
< |
} |
190 |
< |
cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str()<<" has no entries and is not drawn!"<<endl; |
191 |
< |
return draw_err; |
192 |
< |
} |
193 |
< |
//++++++++++++++++++++++++++++++++++++++++++++++++++ |
270 |
> |
((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram |
271 |
|
|
272 |
< |
((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram |
272 |
> |
// Update for 2D histograms |
273 |
> |
if( pads_[currPadName.str()]->GetPrimitive(currHistName.str().c_str())->InheritsFrom("TH2") ) { |
274 |
> |
pads_[currPadName.str()]->Draw(); |
275 |
> |
setCanvas( pads_[currPadName.str()] ); |
276 |
> |
} |
277 |
|
|
278 |
|
|
279 |
< |
return draw_err; |
279 |
> |
if(verbose && draw_err > 0) { |
280 |
> |
timer.Stop(); |
281 |
> |
cout<<"Done: Selected "<<draw_err<<" objects in "<< currN <<" processed events."<<endl; |
282 |
> |
timer.Print(); |
283 |
> |
} |
284 |
> |
return draw_err; |
285 |
|
|
286 |
|
} |
287 |
|
//------------------------------------------------------------------ |
288 |
|
//Standard loop to draw all chains and multiple variables and cuts |
289 |
< |
int PlotTool::loop(vector<string> _histName, vector<string> _cutName, int nEntries, string drwOpt, bool correspond) |
290 |
< |
{ |
289 |
> |
int PlotTool::loop(vector<string> _histName, vector<string> _cutName, |
290 |
> |
int nEntries, string drwOpt, bool correspond) { |
291 |
|
|
292 |
+ |
int numProcessed = 0; |
293 |
|
|
294 |
+ |
if (correspond == false) { |
295 |
|
|
296 |
< |
int numProcessed = 0; |
296 |
> |
for (int i=0; i<this->GetEntries(); ++i) { |
297 |
> |
for (vector<string>::iterator it1 =_histName.begin(); it1 |
298 |
> |
!= _histName.end(); ++it1) { |
299 |
> |
for (vector<string>::iterator it2 =_cutName.begin(); it2 |
300 |
> |
!= _cutName.end(); ++it2) { |
301 |
|
|
302 |
< |
if( correspond == false ) { |
303 |
< |
|
212 |
< |
for(int i=0; i<this->GetEntries(); ++i) { |
213 |
< |
for(vector<string>::iterator it1 =_histName.begin(); it1 != _histName.end(); ++it1) { |
214 |
< |
for(vector<string>::iterator it2 =_cutName.begin(); it2 != _cutName.end(); ++it2) { |
215 |
< |
|
216 |
< |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
217 |
< |
updatePads(); |
218 |
< |
|
219 |
< |
} |
220 |
< |
} |
221 |
< |
} |
222 |
< |
} else { |
302 |
> |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
303 |
> |
|
304 |
|
|
305 |
< |
if( _histName.size() != _cutName.size() ) return -1; |
305 |
> |
} |
306 |
> |
} |
307 |
> |
} |
308 |
> |
} else { |
309 |
|
|
310 |
< |
for(int i=0; i<this->GetEntries(); ++i) { |
311 |
< |
for(vector<string>::iterator it1 =_histName.begin(),it2 =_cutName.begin(); it1 != _cutName.end()&&it2 != _cutName.end(); ++it1, ++it2) { |
310 |
> |
if (_histName.size() != _cutName.size() ) |
311 |
> |
return -1; |
312 |
|
|
313 |
< |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
313 |
> |
for (int i=0; i<this->GetEntries(); ++i) { |
314 |
> |
for (vector<string>::iterator it1 =_histName.begin(), it2 = |
315 |
> |
_cutName.begin(); it1 != _cutName.end()&&it2 |
316 |
> |
!= _cutName.end(); ++it1, ++it2) { |
317 |
|
|
318 |
+ |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
319 |
|
|
320 |
< |
} |
321 |
< |
} |
322 |
< |
} |
320 |
> |
} |
321 |
> |
} |
322 |
> |
} |
323 |
|
|
324 |
< |
// updatePads(); |
325 |
< |
fillCanvases(); |
324 |
> |
updatePads(); |
325 |
> |
fillCanvases(); |
326 |
|
|
327 |
< |
return numProcessed; |
327 |
> |
return numProcessed; |
328 |
|
} |
329 |
|
|
330 |
|
//Helper methods to allow for using simple strings as input |
331 |
< |
int PlotTool::loop(string histName, string cutName, int nEntries, string drwOpt) |
244 |
< |
{ |
331 |
> |
int PlotTool::loop(string histName, string cutName, int nEntries, string drwOpt) { |
332 |
|
|
333 |
< |
vector<string> _histName; |
334 |
< |
_histName.push_back( histName ); |
335 |
< |
vector<string> _cutName; |
336 |
< |
_cutName.push_back( cutName ); |
333 |
> |
vector<string> _histName; |
334 |
> |
_histName.push_back(histName); |
335 |
> |
vector<string> _cutName; |
336 |
> |
_cutName.push_back(cutName); |
337 |
|
|
338 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
338 |
> |
return loop(_histName, _cutName, nEntries, drwOpt); |
339 |
|
|
340 |
|
} |
341 |
|
|
342 |
< |
int PlotTool::loop(vector<string> _histName, string cutName, int nEntries, string drwOpt) |
343 |
< |
{ |
342 |
> |
int PlotTool::loop(vector<string> _histName, string cutName, int nEntries, |
343 |
> |
string drwOpt) { |
344 |
|
|
345 |
< |
vector<string> _cutName; |
346 |
< |
_cutName.push_back( cutName ); |
345 |
> |
vector<string> _cutName; |
346 |
> |
_cutName.push_back(cutName); |
347 |
|
|
348 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
348 |
> |
return loop(_histName, _cutName, nEntries, drwOpt); |
349 |
|
|
350 |
|
} |
351 |
|
|
352 |
< |
int PlotTool::loop(string histName, vector<string> _cutName, int nEntries, string drwOpt) |
353 |
< |
{ |
352 |
> |
int PlotTool::loop(string histName, vector<string> _cutName, int nEntries, |
353 |
> |
string drwOpt) { |
354 |
|
|
355 |
< |
vector<string> _histName; |
356 |
< |
_histName.push_back( histName ); |
355 |
> |
vector<string> _histName; |
356 |
> |
_histName.push_back(histName); |
357 |
|
|
358 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
358 |
> |
return loop(_histName, _cutName, nEntries, drwOpt); |
359 |
|
} |
360 |
|
//------------------------------------------------------------------ |
361 |
|
//redraw the canvas to make changes in style visible |
362 |
< |
int PlotTool::updatePads() { |
362 |
> |
int PlotTool::updatePads() { |
363 |
> |
|
364 |
> |
for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) { |
365 |
> |
if ( ! gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) { |
366 |
> |
pads_.erase(it); |
367 |
> |
continue; |
368 |
> |
} |
369 |
> |
if( (*it).second->GetListOfPrimitives()->GetEntries() == 0 ) { |
370 |
> |
(*it).second->Close(); |
371 |
> |
pads_.erase(it); |
372 |
> |
continue; |
373 |
> |
} |
374 |
> |
(*it).second->Draw(); |
375 |
> |
setCanvas((*it).second); |
376 |
|
|
377 |
< |
for(map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it ) { |
278 |
< |
if( gROOT->FindObject( (*it).first.c_str() ) ) { |
279 |
< |
(*it).second->Draw(); |
280 |
< |
setCanvas( (*it).second ); |
281 |
< |
} else pads_.erase( it ); |
282 |
< |
} |
377 |
> |
} |
378 |
|
|
379 |
< |
return pads_.size(); |
379 |
> |
return pads_.size(); |
380 |
|
|
381 |
|
} |
382 |
|
|
383 |
|
int PlotTool::fillCanvases() { |
384 |
|
|
385 |
+ |
for (map< string, TCanvas* >::iterator it=canvases_.begin() ; it |
386 |
+ |
!= canvases_.end(); ++it) { |
387 |
+ |
string canvName = (*it).first; |
388 |
+ |
if (gROOT->GetListOfCanvases()->FindObject(canvName.c_str()) ) { |
389 |
+ |
|
390 |
+ |
int numP = (*it).second->GetNumber()+1; |
391 |
+ |
|
392 |
+ |
if (numP <= 0) |
393 |
+ |
continue; |
394 |
+ |
|
395 |
+ |
int x = int( sqrt(numP) ); |
396 |
+ |
int y = x; |
397 |
+ |
if (x*y < numP) |
398 |
+ |
x += 1; |
399 |
+ |
if (x*y < numP) |
400 |
+ |
x += 1; |
401 |
+ |
if (x*y < numP) { |
402 |
+ |
x -= 1; |
403 |
+ |
y += 1; |
404 |
+ |
} |
405 |
+ |
|
406 |
+ |
|
407 |
+ |
(*it).second->Divide(x, y); |
408 |
+ |
int padIndex = 1; |
409 |
+ |
for (map< string, TCanvas* >::iterator it2=pads_.begin() ; it2 |
410 |
+ |
!= pads_.end(); ++it2) { |
411 |
+ |
string padName = (*it2).first; |
412 |
+ |
if (gROOT->GetListOfCanvases()->FindObject(padName.c_str() ) ) { |
413 |
+ |
string n1 = canvName.substr(0,canvName.find(":")); |
414 |
+ |
string n2(""); |
415 |
+ |
if(canvName.find("{") != string::npos ) n2 = canvName.substr(canvName.find("{"),canvName.find("}")); |
416 |
+ |
|
417 |
+ |
if ( (padName.find(canvName.c_str()) != string::npos ) || (padName.find(n1) != string::npos && padName.find(n2) != string::npos) || !strcmp( canvName.c_str(), "All") ) { |
418 |
+ |
(*it).second->cd(padIndex); |
419 |
+ |
(*it2).second->DrawClonePad(); |
420 |
+ |
(*it2).second->Close(); |
421 |
+ |
pads_.erase(it2); |
422 |
+ |
++padIndex; |
423 |
+ |
} |
424 |
+ |
} else |
425 |
+ |
pads_.erase(it2); |
426 |
+ |
} |
427 |
+ |
(*it).second->SetNumber(-1); |
428 |
|
|
429 |
< |
for(map< string, TCanvas* >::iterator it=canvases_.begin() ; it != canvases_.end(); ++it ) { |
430 |
< |
const char* canvName = (*it).first.c_str(); |
431 |
< |
if( gROOT->FindObject( canvName ) ) { |
294 |
< |
|
295 |
< |
int numP = (*it).second->GetNumber()+1; |
296 |
< |
|
297 |
< |
if( numP <= 0 ) continue; |
298 |
< |
|
299 |
< |
int x = int( sqrt(numP) ); |
300 |
< |
int y = x; |
301 |
< |
if( x*y < numP ) x += 1; |
302 |
< |
if( x*y < numP ) x += 1; |
303 |
< |
if( x*y < numP ) { |
304 |
< |
x -= 1; |
305 |
< |
y += 1; |
306 |
< |
} |
307 |
< |
|
308 |
< |
(*it).second->Divide(x,y); |
309 |
< |
int padIndex = 1; |
310 |
< |
for(map< string, TCanvas* >::iterator it2=pads_.begin() ; it2 != pads_.end(); ++it2 ) { |
311 |
< |
string padName = (*it2).first; |
312 |
< |
if( gROOT->FindObject( padName.c_str() ) ) { |
313 |
< |
if( ( padName.find(canvName) != string::npos ) || !strcmp(canvName,"All") ) { |
314 |
< |
(*it).second->cd(padIndex); |
315 |
< |
(*it2).second->DrawClonePad(); |
316 |
< |
(*it2).second->Close(); |
317 |
< |
pads_.erase( it2 ); |
318 |
< |
++padIndex; |
319 |
< |
} |
320 |
< |
} else pads_.erase( it2 ); |
321 |
< |
} |
322 |
< |
(*it).second->SetNumber(-1); |
323 |
< |
|
324 |
< |
} else canvases_.erase( it ); |
325 |
< |
} |
429 |
> |
} else |
430 |
> |
canvases_.erase(it); |
431 |
> |
} |
432 |
|
|
433 |
< |
return canvases_.size(); |
433 |
> |
return canvases_.size(); |
434 |
|
|
435 |
|
} |
436 |
|
//------------------------------------------------------------------ |
437 |
|
void PlotTool::setCanvas(TCanvas* thisCanvas) { |
438 |
|
|
439 |
+ |
TH1* thisHist = 0; |
440 |
+ |
TPaveStats* thisStatsBox = 0; |
441 |
+ |
TPaletteAxis* palette =0; |
442 |
+ |
TLegend* thisLeg = 0; |
443 |
+ |
int counter =0; |
444 |
+ |
double maxEntry=0; |
445 |
|
|
446 |
< |
TH1* thisHist = 0; |
447 |
< |
TPaveStats* thisStatsBox = 0; |
336 |
< |
TPaletteAxis* palette =0; |
337 |
< |
TLegend* thisLeg = 0; |
338 |
< |
int counter =0; |
339 |
< |
double maxEntry=0; |
340 |
< |
|
341 |
< |
|
342 |
< |
((TFrame*) thisCanvas->GetFrame())->Delete(); |
343 |
< |
thisCanvas->GetFrame()->SetLineWidth( gStyle->GetLineWidth() ); |
344 |
< |
|
345 |
< |
thisCanvas->SetLeftMargin(0.2); |
346 |
< |
thisCanvas->SetRightMargin(0.06); |
347 |
< |
thisCanvas->SetBottomMargin(0.2); |
348 |
< |
thisCanvas->SetTopMargin(0.1); |
446 |
> |
((TFrame*) thisCanvas->GetFrame())->Delete(); |
447 |
> |
thisCanvas->GetFrame()->SetLineWidth(gStyle->GetLineWidth() ); |
448 |
|
|
449 |
< |
if(logY) thisCanvas->SetLogy(1); |
450 |
< |
else thisCanvas->SetLogy(0); |
449 |
> |
thisCanvas->SetLeftMargin(0.2); |
450 |
> |
thisCanvas->SetRightMargin(0.06); |
451 |
> |
thisCanvas->SetBottomMargin(0.2); |
452 |
> |
thisCanvas->SetTopMargin(0.1); |
453 |
|
|
454 |
< |
if(showLegend) thisLeg = new TLegend(); |
455 |
< |
|
454 |
> |
if (logY) |
455 |
> |
thisCanvas->SetLogy(1); |
456 |
> |
else |
457 |
> |
thisCanvas->SetLogy(0); |
458 |
|
|
459 |
< |
for(int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i){ |
459 |
> |
if (showLegend) |
460 |
> |
thisLeg = new TLegend(); |
461 |
|
|
462 |
+ |
for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) { |
463 |
|
|
464 |
< |
if( ! thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1")) continue; |
464 |
> |
if ( !thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1")) |
465 |
> |
continue; |
466 |
|
|
467 |
< |
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
468 |
< |
setColor(thisHist, counter); |
469 |
< |
setMathLabels(thisHist); |
467 |
> |
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
468 |
> |
setColor(thisHist, counter); |
469 |
> |
setMathLabels(thisHist); |
470 |
|
|
471 |
< |
if(thisHist->GetMaximum() > maxEntry) maxEntry = thisHist->GetMaximum(); |
471 |
> |
if (thisHist->GetMaximum() > maxEntry) |
472 |
> |
maxEntry = thisHist->GetMaximum(); |
473 |
|
|
474 |
< |
thisStatsBox = (TPaveStats*) thisHist->GetListOfFunctions()->FindObject("stats"); |
475 |
< |
if(thisStatsBox) setStats(thisCanvas, thisStatsBox, thisHist, counter); |
474 |
> |
thisStatsBox = (TPaveStats*) thisHist->GetListOfFunctions()->FindObject("stats"); |
475 |
> |
if (thisStatsBox) |
476 |
> |
setStats(thisCanvas, thisStatsBox, thisHist, counter); |
477 |
|
|
478 |
< |
palette = (TPaletteAxis*) thisHist->GetListOfFunctions()->FindObject("palette"); |
479 |
< |
if(palette) setPalette(thisCanvas, palette); |
478 |
> |
palette = (TPaletteAxis*) thisHist->GetListOfFunctions()->FindObject("palette"); |
479 |
> |
if (palette) |
480 |
> |
setPalette(thisCanvas, palette); |
481 |
|
|
482 |
< |
if(thisLeg) thisLeg->AddEntry(thisHist,thisHist->GetName())->SetTextSize(0.04); |
482 |
> |
if (thisLeg) |
483 |
> |
thisLeg->AddEntry(thisHist,thisHist->GetName())->SetTextSize(0.04); |
484 |
|
|
485 |
+ |
++counter; |
486 |
|
|
487 |
< |
++counter; |
377 |
< |
|
378 |
< |
} |
487 |
> |
} |
488 |
|
|
489 |
< |
if( maxEntry != 0) setHistMax(thisCanvas, maxEntry); |
490 |
< |
|
489 |
> |
if (maxEntry != 0) |
490 |
> |
setHistMax(thisCanvas, maxEntry); |
491 |
|
|
492 |
< |
thisCanvas->cd(); |
493 |
< |
thisCanvas->Update(); |
492 |
> |
thisCanvas->cd(); |
493 |
> |
thisCanvas->Update(); |
494 |
> |
|
495 |
> |
if (thisLeg) |
496 |
> |
setLegend(thisCanvas, thisLeg, counter); |
497 |
|
|
386 |
– |
if(thisLeg) setLegend( thisCanvas, thisLeg, counter); |
387 |
– |
|
388 |
– |
|
498 |
|
} |
499 |
|
//------------------------------------------------------------------ |
500 |
|
//private helper classes to set the canvas and hist style |
501 |
< |
void PlotTool::setStats(TCanvas* thisCanvas, TPaveStats* thisStatsBox, TH1* thisHist, int counter) { |
501 |
> |
void PlotTool::setStats(TCanvas* thisCanvas, TPaveStats* thisStatsBox, |
502 |
> |
TH1* thisHist, int counter) { |
503 |
|
|
504 |
+ |
if (thisCanvas->GetRightMargin() < .2) |
505 |
+ |
thisCanvas->SetRightMargin(.2); |
506 |
|
|
507 |
< |
if(thisCanvas->GetRightMargin() < .2) thisCanvas->SetRightMargin(.2); |
507 |
> |
thisStatsBox->SetLineColor(thisHist->GetLineColor()); |
508 |
> |
thisStatsBox->SetX2NDC(1.); |
509 |
> |
thisStatsBox->SetY2NDC(1-thisCanvas->GetTopMargin()-0.16*counter); |
510 |
> |
thisStatsBox->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01); |
511 |
> |
thisStatsBox->SetY1NDC(thisStatsBox->GetY2NDC()-.15); |
512 |
|
|
513 |
< |
thisStatsBox->SetLineColor(thisHist->GetLineColor()); |
514 |
< |
thisStatsBox->SetX2NDC(1.); |
515 |
< |
thisStatsBox->SetY2NDC(1-thisCanvas->GetTopMargin()-0.16*counter); |
400 |
< |
thisStatsBox->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01); |
401 |
< |
thisStatsBox->SetY1NDC(thisStatsBox->GetY2NDC()-.15); |
513 |
> |
} |
514 |
> |
|
515 |
> |
void PlotTool::setMathLabels(TH1* thisHist) { |
516 |
|
|
517 |
+ |
string t = thisHist ->GetTitle(); |
518 |
+ |
string x = thisHist->GetXaxis()->GetTitle(); |
519 |
+ |
string y = thisHist->GetYaxis()->GetTitle(); |
520 |
+ |
|
521 |
+ |
// if (x.find("__") != string::npos) |
522 |
+ |
// x = x.substr(0,x.find("__")); |
523 |
+ |
// if (y.find("__") != string::npos) |
524 |
+ |
// y = y.substr(0,y.find("__")); |
525 |
+ |
|
526 |
+ |
if (x.find(".phi()") != string::npos) |
527 |
+ |
x.replace(x.find(".phi()"), 6, " #phi"); |
528 |
+ |
if (y.find(".phi()") != string::npos) |
529 |
+ |
y.replace(y.find(".phi()"), 6, " #phi"); |
530 |
+ |
|
531 |
+ |
if (x.find(".eta()") != string::npos) |
532 |
+ |
x.replace(x.find(".eta()"), 6, " #eta"); |
533 |
+ |
if (y.find(".eta()") != string::npos) |
534 |
+ |
y.replace(y.find(".eta()"), 6, " #eta"); |
535 |
+ |
|
536 |
+ |
if (x.find(".theta()") != string::npos) |
537 |
+ |
x.replace(x.find(".theta()"), 6, " #theta"); |
538 |
+ |
if (y.find(".theta()") != string::npos) |
539 |
+ |
y.replace(y.find(".theta()"), 6, " #theta"); |
540 |
+ |
|
541 |
+ |
if (x.find(".chi2()") != string::npos) |
542 |
+ |
x.replace(x.find(".chi2()"), 7, " #chi^{2}"); |
543 |
+ |
if (y.find(".chi2()") != string::npos) |
544 |
+ |
y.replace(y.find(".chi2()"), 7, " #chi^{2}"); |
545 |
+ |
|
546 |
+ |
if (x.find(".pt()") != string::npos) |
547 |
+ |
x.replace(x.find(".pt()"), 5, " p_{T} [GeV]"); |
548 |
+ |
if (y.find(".pt()") != string::npos) |
549 |
+ |
y.replace(y.find(".pt()"), 5, " p_{T} [GeV]"); |
550 |
+ |
|
551 |
+ |
if (x.find(".et()") != string::npos) |
552 |
+ |
x.replace(x.find(".et()"), 5, " E_{T} [GeV]"); |
553 |
+ |
if (y.find(".et()") != string::npos) |
554 |
+ |
y.replace(y.find(".et()"), 5, " E_{T} [GeV]"); |
555 |
+ |
|
556 |
+ |
//splitlines for many cuts |
557 |
+ |
string test1= "{" + globalCuts + "}"; |
558 |
+ |
string test2= "&&" + globalCuts; |
559 |
+ |
|
560 |
+ |
if(t.find(test1) != string::npos) t.replace(t.find(test1),test1.length(),""); |
561 |
+ |
if(t.find(test2) != string::npos) t.replace(t.find(test2),test2.length(),""); |
562 |
+ |
|
563 |
+ |
if (t.find("{") != string::npos && t.find("#splitline") == string::npos) { |
564 |
+ |
t.replace(t.find_last_of("{"), 1, "}{"); |
565 |
+ |
string t_old = t; |
566 |
+ |
t = "#splitline{"; |
567 |
+ |
t += t_old; |
568 |
+ |
} |
569 |
|
|
570 |
+ |
thisHist ->SetTitle(t.c_str()); |
571 |
+ |
thisHist->GetXaxis()->SetTitle(x.c_str()); |
572 |
+ |
thisHist->GetYaxis()->SetTitle(y.c_str()); |
573 |
|
|
574 |
|
} |
575 |
|
|
576 |
< |
void PlotTool::setMathLabels(TH1* thisHist) { |
576 |
> |
void PlotTool::setColor(TH1* thisHist, int counter) { |
577 |
|
|
578 |
+ |
if (counter == 0) { |
579 |
|
|
580 |
< |
string t = thisHist ->GetTitle(); |
581 |
< |
string x = thisHist->GetXaxis()->GetTitle(); |
582 |
< |
string y = thisHist->GetYaxis()->GetTitle(); |
583 |
< |
|
584 |
< |
if(t.find(".phi()") != string::npos ) t.replace(t.find(".phi()"),6," #phi"); |
585 |
< |
if(x.find(".phi()") != string::npos ) x.replace(x.find(".phi()"),6," #phi"); |
586 |
< |
if(y.find(".phi()") != string::npos ) y.replace(y.find(".phi()"),6," #phi"); |
587 |
< |
|
588 |
< |
if(t.find(".eta()") != string::npos ) t.replace(t.find(".eta()"),6," #eta"); |
589 |
< |
if(x.find(".eta()") != string::npos ) x.replace(x.find(".eta()"),6," #eta"); |
590 |
< |
if(y.find(".eta()") != string::npos ) y.replace(y.find(".eta()"),6," #eta"); |
591 |
< |
|
592 |
< |
if(t.find(".pt()") != string::npos ) t.replace(t.find(".pt()"),5," p_{T}"); |
593 |
< |
if(x.find(".pt()") != string::npos ) x.replace(x.find(".pt()"),5," p_{T}"); |
594 |
< |
if(y.find(".pt()") != string::npos ) y.replace(y.find(".pt()"),5," p_{T}"); |
595 |
< |
|
596 |
< |
thisHist ->SetTitle(t.c_str()); |
597 |
< |
thisHist->GetXaxis()->SetTitle(x.c_str()); |
598 |
< |
thisHist->GetYaxis()->SetTitle(y.c_str()); |
580 |
> |
thisHist->SetLineColor(kRed+1); |
581 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kRed+1); |
582 |
> |
//else |
583 |
> |
thisHist->SetFillStyle(0); |
584 |
> |
thisHist->SetMarkerColor(kRed+1); |
585 |
> |
} else if (counter == 1) { |
586 |
> |
thisHist->SetLineColor(kBlue+1); |
587 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlue+1); |
588 |
> |
//else |
589 |
> |
thisHist->SetFillStyle(0); |
590 |
> |
thisHist->SetMarkerColor(kBlue+1); |
591 |
> |
|
592 |
> |
} else if (counter == 2) { |
593 |
> |
thisHist->SetLineColor(kGreen+2); |
594 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kGreen+2); |
595 |
> |
//else |
596 |
> |
thisHist->SetFillStyle(0); |
597 |
> |
thisHist->SetMarkerColor(kGreen+2); |
598 |
> |
|
599 |
> |
} else if (counter == 3) { |
600 |
> |
thisHist->SetLineColor(kMagenta+2); |
601 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kMagenta+2); |
602 |
> |
//else |
603 |
> |
thisHist->SetFillStyle(0); |
604 |
> |
thisHist->SetMarkerColor(kMagenta+2); |
605 |
> |
|
606 |
> |
} else if (counter == 4) { |
607 |
> |
thisHist->SetLineColor(kCyan+2); |
608 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kCyan+2); |
609 |
> |
//else |
610 |
> |
thisHist->SetFillStyle(0); |
611 |
> |
thisHist->SetMarkerColor(kCyan+2); |
612 |
> |
|
613 |
> |
} else { |
614 |
> |
thisHist->SetLineColor(kBlack); |
615 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlack); |
616 |
> |
//else |
617 |
> |
thisHist->SetFillStyle(0); |
618 |
> |
thisHist->SetMarkerColor(kBlack); |
619 |
|
|
620 |
+ |
} |
621 |
|
|
622 |
|
} |
623 |
|
|
624 |
+ |
void PlotTool::setPalette(TCanvas* thisCanvas, TPaletteAxis* palette) { |
625 |
+ |
|
626 |
+ |
palette->SetLabelSize(0.045); |
627 |
+ |
if (thisCanvas->GetRightMargin() < .15) |
628 |
+ |
thisCanvas->SetRightMargin(.15); |
629 |
+ |
palette->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01); |
630 |
+ |
palette->SetY1NDC(thisCanvas->GetBottomMargin()); |
631 |
+ |
palette->SetX2NDC(palette->GetX1NDC()+0.05); |
632 |
+ |
palette->SetY2NDC(1-thisCanvas->GetTopMargin()); |
633 |
|
|
634 |
< |
void PlotTool::setColor(TH1* thisHist, int counter) { |
634 |
> |
} |
635 |
|
|
636 |
+ |
void PlotTool::setHistMax(TCanvas* thisCanvas, double maxEntry) { |
637 |
|
|
638 |
< |
if(counter == 0) { |
638 |
> |
TH1* thisHist = 0; |
639 |
|
|
640 |
< |
thisHist->SetLineColor (kRed+1); |
440 |
< |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kRed+1); |
441 |
< |
//else |
442 |
< |
thisHist->SetFillStyle(0); |
443 |
< |
thisHist->SetMarkerColor(kRed+1); |
444 |
< |
} else if(counter == 1) { |
445 |
< |
thisHist->SetLineColor (kBlue+1); |
446 |
< |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlue+1); |
447 |
< |
//else |
448 |
< |
thisHist->SetFillStyle(0); |
449 |
< |
thisHist->SetMarkerColor(kBlue+1); |
450 |
< |
|
451 |
< |
} else if(counter == 2) { |
452 |
< |
thisHist->SetLineColor (kGreen+2); |
453 |
< |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kGreen+2); |
454 |
< |
//else |
455 |
< |
thisHist->SetFillStyle(0); |
456 |
< |
thisHist->SetMarkerColor(kGreen+2); |
457 |
< |
|
458 |
< |
} else if(counter == 3) { |
459 |
< |
thisHist->SetLineColor (kMagenta+2); |
460 |
< |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kMagenta+2); |
461 |
< |
//else |
462 |
< |
thisHist->SetFillStyle(0); |
463 |
< |
thisHist->SetMarkerColor(kMagenta+2); |
464 |
< |
|
465 |
< |
} else if(counter == 4) { |
466 |
< |
thisHist->SetLineColor (kCyan+2); |
467 |
< |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kCyan+2); |
468 |
< |
//else |
469 |
< |
thisHist->SetFillStyle(0); |
470 |
< |
thisHist->SetMarkerColor(kCyan+2); |
640 |
> |
for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) { |
641 |
|
|
642 |
< |
} else { |
643 |
< |
thisHist->SetLineColor (kBlack); |
644 |
< |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlack); |
645 |
< |
//else |
646 |
< |
thisHist->SetFillStyle(0); |
647 |
< |
thisHist->SetMarkerColor(kBlack); |
642 |
> |
if ( !thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1") ) |
643 |
> |
continue; |
644 |
> |
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
645 |
> |
if (thisHist->GetMaximum() < maxEntry) { |
646 |
> |
double minEntry=thisHist->GetBinContent(thisHist->GetMinimumBin()); |
647 |
> |
if (logY) { |
648 |
> |
int bin = (thisHist->GetMinimumBin()+1); |
649 |
> |
minEntry=thisHist->GetBinContent(bin); |
650 |
> |
} |
651 |
> |
thisHist->GetYaxis()->SetRangeUser(minEntry, maxEntry*1.2); |
652 |
> |
} |
653 |
> |
break; |
654 |
|
|
655 |
< |
} |
655 |
> |
} |
656 |
|
|
657 |
|
} |
658 |
|
|
659 |
< |
void PlotTool::setPalette(TCanvas* thisCanvas, TPaletteAxis* palette) { |
659 |
> |
void PlotTool::setLegend(TCanvas* thisCanvas, TLegend* thisLeg, int counter) { |
660 |
|
|
661 |
+ |
thisLeg->SetFillStyle(0); |
662 |
+ |
thisLeg->SetX1NDC(1-thisCanvas->GetRightMargin()-0.5); |
663 |
+ |
thisLeg->SetY1NDC(1-thisCanvas->GetTopMargin()-0.05*counter); |
664 |
+ |
thisLeg->SetX2NDC(1-thisCanvas->GetRightMargin()); |
665 |
+ |
thisLeg->SetY2NDC(1-thisCanvas->GetTopMargin()); |
666 |
+ |
thisLeg->SetEntrySeparation(0.5); |
667 |
+ |
thisLeg->Draw("NDC"); |
668 |
|
|
669 |
< |
palette->SetLabelSize(0.045); |
487 |
< |
if(thisCanvas->GetRightMargin() < .15) thisCanvas->SetRightMargin(.15); |
488 |
< |
palette->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01); |
489 |
< |
palette->SetY1NDC(thisCanvas->GetBottomMargin()); |
490 |
< |
palette->SetX2NDC(palette->GetX1NDC()+0.05); |
491 |
< |
palette->SetY2NDC(1-thisCanvas->GetTopMargin()); |
669 |
> |
} |
670 |
|
|
671 |
+ |
void PlotTool::createColors() { |
672 |
+ |
const Int_t NRGBs = 5; |
673 |
+ |
const Int_t NCont = 255; |
674 |
+ |
|
675 |
+ |
Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; |
676 |
+ |
Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; |
677 |
+ |
Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; |
678 |
+ |
Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; |
679 |
+ |
TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); |
680 |
+ |
gStyle->SetNumberContours(NCont); |
681 |
|
|
682 |
|
} |
683 |
|
|
684 |
< |
void PlotTool::setHistMax(TCanvas* thisCanvas, double maxEntry) { |
684 |
> |
//------------------------------------------------------------------ |
685 |
|
|
686 |
< |
TH1* thisHist = 0; |
686 |
> |
int PlotTool::saveCanvases(string name, string path) { |
687 |
|
|
688 |
< |
for(int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i){ |
688 |
> |
TSystemDirectory d("", path.c_str()); |
689 |
> |
if (!d.GetListOfFiles()) |
690 |
> |
return -1; |
691 |
|
|
692 |
< |
if( ! thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1") ) continue; |
693 |
< |
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
504 |
< |
if( thisHist->GetMaximum() < maxEntry ) thisHist->GetYaxis()->SetRangeUser(thisHist->GetMinimum(),maxEntry*1.2); |
505 |
< |
break; |
692 |
> |
string namePs = path +"/" + name; |
693 |
> |
string nameRt = path +"/" + name; |
694 |
|
|
695 |
< |
} |
695 |
> |
if (name.find(".ps") == string::npos) |
696 |
> |
namePs += ".ps"; |
697 |
|
|
698 |
+ |
if (name.find(".root") == string::npos) |
699 |
+ |
nameRt += ".root"; |
700 |
|
|
701 |
< |
} |
701 |
> |
int savedCanvs =0; |
702 |
|
|
512 |
– |
void PlotTool::setLegend(TCanvas* thisCanvas, TLegend* thisLeg, int counter) { |
703 |
|
|
704 |
< |
thisLeg->SetFillStyle(0); |
705 |
< |
thisLeg->SetX1NDC(1-thisCanvas->GetRightMargin()-0.5); |
706 |
< |
thisLeg->SetY1NDC(1-thisCanvas->GetTopMargin()-0.05*counter); |
707 |
< |
thisLeg->SetX2NDC(1-thisCanvas->GetRightMargin()); |
708 |
< |
thisLeg->SetY2NDC(1-thisCanvas->GetTopMargin()); |
709 |
< |
thisLeg->SetEntrySeparation(0.5); |
520 |
< |
thisLeg->Draw("NDC"); |
704 |
> |
TIter next(gROOT->GetListOfCanvases()); |
705 |
> |
TCanvas* canv; |
706 |
> |
while ((canv=(TCanvas*)next())) { |
707 |
> |
string modName = (*canv).GetName(); |
708 |
> |
if(modName.find("{") != string::npos) modName = modName.substr(0,modName.find("{")); |
709 |
> |
(*canv).SetTitle( modName.c_str() ); |
710 |
|
|
711 |
< |
} |
711 |
> |
} |
712 |
|
|
524 |
– |
void PlotTool::createColors() |
525 |
– |
{ |
526 |
– |
const Int_t NRGBs = 5; |
527 |
– |
const Int_t NCont = 255; |
713 |
|
|
714 |
< |
Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; |
715 |
< |
Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; |
716 |
< |
Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; |
717 |
< |
Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; |
718 |
< |
TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); |
719 |
< |
gStyle->SetNumberContours(NCont); |
714 |
> |
TPostScript ps(namePs.c_str(),112); |
715 |
> |
TFile rt(nameRt.c_str(),"recreate"); |
716 |
> |
|
717 |
> |
next.Reset(); |
718 |
> |
while ((canv=(TCanvas*)next())) { |
719 |
> |
ps.NewPage(); |
720 |
|
|
536 |
– |
} |
721 |
|
|
722 |
+ |
(*canv).Write(); |
723 |
+ |
(*canv).Draw(); |
724 |
+ |
(*canv).Update(); |
725 |
+ |
|
726 |
+ |
|
727 |
+ |
++savedCanvs; |
728 |
+ |
|
729 |
+ |
} |
730 |
|
|
731 |
+ |
ps.Close(); |
732 |
+ |
rt.Close(); |
733 |
+ |
|
734 |
+ |
|
735 |
+ |
if(verbose && savedCanvs) { |
736 |
+ |
cout<<"Saved file "<<rt.GetName()<<" with "<<savedCanvs<<" canvases."<<endl; |
737 |
+ |
cout<<"Saved file "<<ps.GetName()<<" with "<<savedCanvs<<" pages."<<endl; |
738 |
+ |
} |
739 |
+ |
return savedCanvs; |
740 |
+ |
|
741 |
+ |
} |
742 |
|
//------------------------------------------------------------------ |
743 |
|
|
744 |
< |
int PlotTool::saveCanvases(string type, string path) { |
744 |
> |
int PlotTool::clearCanvases() |
745 |
> |
{ |
746 |
|
|
747 |
+ |
while(gROOT->GetListOfCanvases()->GetEntries()) ((TCanvas*) gROOT->GetListOfCanvases()->At(0))->Close(); |
748 |
+ |
pads_.clear(); |
749 |
+ |
autoVars.clear(); |
750 |
+ |
return pads_.size() + gROOT->GetListOfCanvases()->GetEntries(); |
751 |
|
|
752 |
< |
TSystemDirectory d("",path.c_str()); |
753 |
< |
if(!d.GetListOfFiles()) return -1; |
754 |
< |
if(type.find(".") == string::npos) return -1; |
752 |
> |
} |
753 |
> |
//------------------------------------------------------------------ |
754 |
> |
int PlotTool::setVariables(string label) |
755 |
> |
{ |
756 |
|
|
757 |
< |
int savedFiles =0; |
757 |
> |
for (int i=0; i< this->GetEntries(); ++i) { |
758 |
> |
cout<<"--------------------------------"<<endl; |
759 |
> |
cout<<((TChain*) this->At(i))->GetName()<<endl; |
760 |
> |
cout<<"------------"<<endl; |
761 |
> |
|
762 |
> |
TList* leaves = (TList*) ((TChain*) this->At(i))->GetListOfLeaves(); |
763 |
> |
for (int j=0; j< leaves->GetEntries(); ++j) { |
764 |
> |
TString leafName ( leaves->At(j)->GetName() ); |
765 |
> |
if(! leafName.EndsWith(".") ) continue; |
766 |
> |
if(! leafName.Contains(label.c_str() ) ) continue; |
767 |
> |
|
768 |
> |
TClass cl( ( (TLeafElement*) leaves->At(j) )->GetTypeName() ); |
769 |
> |
cout<<"++++++"<<endl; |
770 |
> |
cout<< leafName.Data() <<endl; |
771 |
> |
for(int k=0;k<cl.GetListOfAllPublicMethods()->GetEntries();++k) { |
772 |
> |
string typeName ( ((TMethod*) cl.GetListOfAllPublicMethods()->At(k))->GetReturnTypeName() ); |
773 |
> |
string methName ( cl.GetListOfAllPublicMethods()->At(k)->GetName() ); |
774 |
> |
if( methName != "product") continue; |
775 |
> |
cout<< typeName <<endl; |
776 |
> |
string _type; |
777 |
> |
TString testString( typeName.c_str() ); |
778 |
> |
if( testString.BeginsWith("vector<") ) { |
779 |
> |
_type = typeName.substr(typeName.find("<")+1,typeName.find(">")-typeName.find("<")-1); |
780 |
> |
string _varSize = leafName.Data(); |
781 |
> |
_varSize += "obj@.size()"; |
782 |
> |
autoVars.push_back( _varSize ); |
783 |
> |
} |
784 |
> |
else _type = typeName.substr(0,typeName.find("*")); |
785 |
> |
TClass _cl( _type.c_str() ); |
786 |
> |
for(int l=0;l<_cl.GetListOfAllPublicMethods()->GetEntries();++l) { |
787 |
> |
string _typeName ( ((TMethod*) _cl.GetListOfAllPublicMethods()->At(l))->GetReturnTypeName() ); |
788 |
> |
string _methName ( _cl.GetListOfAllPublicMethods()->At(l)->GetName() ); |
789 |
> |
// if(_typeName.find("void") != string::npos ) continue; |
790 |
> |
// cout<<" "<<_typeName<<" "<<_methName<<endl; |
791 |
> |
|
792 |
> |
cout<<" "<<_typeName<<" "<<_methName<<endl; |
793 |
> |
if(_methName.find("operator")==string::npos&&(_typeName=="float"||_typeName=="double"||_typeName=="int"||_typeName=="unsigned int"||_typeName=="bool"||_typeName=="unsigned short"||_typeName=="unsigned long"||_typeName=="unsigned long long")) { |
794 |
> |
|
795 |
> |
cout<<"--> "<<_typeName<<" "<<_methName<<endl; |
796 |
> |
|
797 |
> |
string _varName = leafName.Data(); |
798 |
> |
_varName += "obj."; |
799 |
> |
_varName += _methName; |
800 |
> |
_varName += "()"; |
801 |
> |
autoVars.push_back( _varName ); |
802 |
> |
} |
803 |
> |
} |
804 |
> |
|
805 |
> |
|
806 |
> |
} |
807 |
|
|
808 |
< |
TIter next(gROOT->GetListOfCanvases()); |
551 |
< |
TCanvas* canv; |
552 |
< |
while ((canv=(TCanvas*)next())) { |
553 |
< |
|
554 |
< |
string s = ""; |
555 |
< |
s += path; |
556 |
< |
s += canv->GetName(); |
557 |
< |
s += type; |
808 |
> |
} |
809 |
|
|
810 |
< |
canv->SaveAs(s.c_str()); |
560 |
< |
++savedFiles; |
810 |
> |
} |
811 |
|
|
812 |
< |
} |
563 |
< |
|
564 |
< |
return savedFiles; |
812 |
> |
return autoVars.size(); |
813 |
|
|
814 |
|
} |
815 |
+ |
|
816 |
|
//------------------------------------------------------------------ |