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