ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/tschum/FWlite_Analysis/PlotTool.cc
Revision: 1.6
Committed: Wed Nov 25 15:34:38 2009 UTC (15 years, 5 months ago) by gebbert
Content type: text/plain
Branch: MAIN
Changes since 1.5: +489 -432 lines
Log Message:
1. Bugfix SetLogY/SetRangeUser(0,x): range is now set to lowest binContent(>0)
2. extension of init function by optional parameter "fileLabel"

File Contents

# User Rev Content
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.1
18     }
19    
20     //------------------------------------------------------------------
21     //Fill object PlotTool with Chains constructed from files from given source
22 gebbert 1.6 int PlotTool::init(string fileName, string dirPath, string treeName,
23     string fileLabel) {
24     this->New(this->GetEntries() );
25     int currChain = this->GetEntries() - 1;
26    
27     if (currChain < 0)
28     return currChain;
29     //make file for tree friends (adding additional, computed branches)
30     string friendFileName("/scratch/hh/lustre/cms/user/thomsen/temp/");
31     friendFileName += fileName;
32     friendFileName += ".root";
33     TFile *f = new TFile(friendFileName.c_str(),"recreate");
34     string friendTreeName("friendTree");
35     //char number = currChain;
36     //friendTreeName += number;
37     //TTree *friendTree = new TTree("friendTree","friendTree");
38     TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str());
39    
40     fileNames.clear();
41    
42     //check if alternative label is different from default(searchString)
43     if (fileLabel=="") {
44     fileLabel=fileName;
45     }
46     ((TChain*) this->At(currChain))->SetName(fileLabel.c_str());
47     TSystemDirectory dir("sourceDir", dirPath.c_str());
48     TList *files = dir.GetListOfFiles();
49     if (files) {
50     TIter next(files);
51     TSystemFile *file;
52     TString fname;
53     string filePath;
54    
55     cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: "
56     <<fileName.c_str()<<endl;
57    
58     while ((file=(TSystemFile*)next())) {
59     fname = file->GetName();
60     if (!fname.EndsWith(".root"))
61     continue;
62     if (!fname.Contains(fileName.c_str()))
63     continue;
64    
65     filePath = dirPath;
66     filePath += fname.Data();
67     //fwlite::ChainEvent to lop over events, jets, etc
68     fileNames.push_back(filePath.c_str());
69    
70     if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1,
71     treeName.c_str()) )
72     cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl;
73     else
74     return -1;
75    
76     }
77     } else
78     return -1;
79    
80     for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) {
81    
82     string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName());
83     size_t a = s.find("_");
84     if (a == string::npos)
85     a = 0;
86     size_t b = s.find("_", a+1);
87     if (b == string::npos)
88     b = 50;
89     string branch_alias = s.substr(a+1, b-a-1);
90     string branch_name = s;
91     if (s.find(".", s.size()-1) != string::npos)
92     branch_name += "obj";
93     ((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),
94     branch_name.c_str());
95    
96     }
97    
98     // add branch with track Jets
99 thomsen 1.5
100 gebbert 1.6 int nJetsKT;
101     TrackJetKT = new float [100];
102     fwlite::ChainEvent ev(fileNames);
103    
104     friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I");
105     friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F");
106    
107     cout<<"calculating additional variables..."<<endl;
108     for (ev.toBegin(); !ev.atEnd(); ++ev) {
109    
110     fwlite::Handle<reco::CaloJetCollection> jets;
111     jets.getByLabel(ev, "antikt5CaloJets");
112    
113     fwlite::Handle<reco::TrackCollection> tracks;
114     tracks.getByLabel(ev, "generalTracks");
115    
116     if (!jets.isValid())
117     continue;
118     if (!tracks.isValid())
119     continue;
120     double trackSum;
121     nJetsKT = 0;
122     for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet
123     !=jets->end(); jet++) {
124     trackSum = 0;
125     for (reco::TrackCollection::const_iterator track = tracks->begin(); track
126     !=tracks->end(); track++) {
127     if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi())
128     < 0.5)
129     trackSum += track->pt();
130     }
131     TrackJetKT[nJetsKT] = trackSum;
132     nJetsKT++;
133     }
134     friendTree->Fill();
135     }
136     f->cd();
137     friendTree->Write();
138     f->Close();
139     ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
140     friendFileName.c_str());
141    
142     return this->GetEntries();
143 tschum 1.1
144     }
145     //------------------------------------------------------------------
146     //Draw given Chain with given variable and given cuts
147 gebbert 1.6 int PlotTool::plot(int chainIndex, string histName, string cutName,
148     int nEntries, string drwOpt) {
149 tschum 1.1
150 gebbert 1.6 if (chainIndex >= this->GetEntries() )
151     return -1;
152 tschum 1.1
153 gebbert 1.6 int currN = nEntries;
154     if (nEntries < 0)
155     currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted!
156    
157     //++++ Create and name Canvases according to global variables +++++++++++++
158     ostringstream currHistName;
159     if (samePad_trees)
160     currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":";
161     if (samePad_vars)
162     currHistName<<histName;
163     if (samePad_cuts)
164     currHistName<<"{"<<cutName<<"}";
165    
166     ostringstream currPadName;
167     if (!samePad_trees)
168     currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":";
169     if (!samePad_vars)
170     currPadName<<histName;
171     if (!samePad_cuts)
172     currPadName<<"{"<<cutName<<"}";
173    
174     ostringstream currCanvName;
175     if (!sameCanv_trees && !samePad_trees)
176     currCanvName<<((TChain*) this->At(chainIndex))->GetName()<<":";
177     if (!sameCanv_vars && !samePad_vars)
178     currCanvName<<histName;
179     if (!sameCanv_cuts && !samePad_cuts)
180     currCanvName<<"{"<<cutName<<"}";
181    
182     if ( (sameCanv_trees || samePad_trees) && (sameCanv_vars || samePad_vars)
183     && (sameCanv_cuts || samePad_cuts))
184     currCanvName<<"All";
185    
186     string currOpt = drwOpt;
187     bool useSubPads = (sameCanv_trees && !samePad_trees) || (sameCanv_vars
188     && !samePad_vars) || (sameCanv_cuts && !samePad_cuts);
189    
190     if (useSubPads) {
191     if ( !canvases_[currCanvName.str()] || !gROOT->FindObject(currCanvName.str().c_str()) ) {
192     canvases_[currCanvName.str()] = new TCanvas(currCanvName.str().c_str(), currCanvName.str().c_str());
193     } else if (canvases_[currCanvName.str()]->GetNumber() >= 0) {
194     canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()+1);
195     }
196     }
197 tschum 1.1
198 gebbert 1.6 if ( !pads_[currPadName.str()] || !gROOT->FindObject(currPadName.str().c_str()) ) {
199     pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str());
200     if (logY)
201     pads_[currPadName.str()]->SetLogy(1);
202     } else {
203     pads_[currPadName.str()]->cd();
204     currOpt += "SAMES";
205     if (useSubPads)
206     canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1);
207     }
208     //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
209 tschum 1.1
210    
211 gebbert 1.6 //Draw histogram:
212     int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(),
213     currOpt.c_str(), currN);
214     if (draw_err < 0)
215     return draw_err;
216    
217     //++++ Fix for histos with no entries +++++++++++++
218     if (draw_err == 0) {
219     if (currOpt.find("SAMES") == string::npos) {
220     pads_[currPadName.str()]->Close();
221     pads_.erase(currPadName.str() );
222     if (useSubPads)
223     canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1);
224     }
225     cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str()
226     <<" has no entries and is not drawn!"<<endl;
227     return draw_err;
228     }
229     //++++++++++++++++++++++++++++++++++++++++++++++++++
230 tschum 1.1
231 gebbert 1.6 ((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram
232    
233    
234     return draw_err;
235 tschum 1.1
236     }
237     //------------------------------------------------------------------
238     //Standard loop to draw all chains and multiple variables and cuts
239 gebbert 1.6 int PlotTool::loop(vector<string> _histName, vector<string> _cutName,
240     int nEntries, string drwOpt, bool correspond) {
241 tschum 1.1
242 gebbert 1.6 int numProcessed = 0;
243 tschum 1.1
244 gebbert 1.6 if (correspond == false) {
245 tschum 1.1
246 gebbert 1.6 for (int i=0; i<this->GetEntries(); ++i) {
247     for (vector<string>::iterator it1 =_histName.begin(); it1
248     != _histName.end(); ++it1) {
249     for (vector<string>::iterator it2 =_cutName.begin(); it2
250     != _cutName.end(); ++it2) {
251 tschum 1.1
252 gebbert 1.6 numProcessed += plot(i, *it1, *it2, nEntries, drwOpt);
253     updatePads();
254 tschum 1.1
255 gebbert 1.6 }
256     }
257     }
258     } else {
259 tschum 1.1
260 gebbert 1.6 if (_histName.size() != _cutName.size() )
261     return -1;
262 tschum 1.1
263 gebbert 1.6 for (int i=0; i<this->GetEntries(); ++i) {
264     for (vector<string>::iterator it1 =_histName.begin(), it2 =
265     _cutName.begin(); it1 != _cutName.end()&&it2
266     != _cutName.end(); ++it1, ++it2) {
267 tschum 1.1
268 gebbert 1.6 numProcessed += plot(i, *it1, *it2, nEntries, drwOpt);
269 tschum 1.1
270 gebbert 1.6 }
271     }
272     }
273 tschum 1.1
274 gebbert 1.6 // updatePads();
275     fillCanvases();
276 tschum 1.1
277 gebbert 1.6 return numProcessed;
278 tschum 1.1 }
279    
280     //Helper methods to allow for using simple strings as input
281 gebbert 1.6 int PlotTool::loop(string histName, string cutName, int nEntries, string drwOpt) {
282 tschum 1.1
283 gebbert 1.6 vector<string> _histName;
284     _histName.push_back(histName);
285     vector<string> _cutName;
286     _cutName.push_back(cutName);
287 tschum 1.1
288 gebbert 1.6 return loop(_histName, _cutName, nEntries, drwOpt);
289 tschum 1.1
290     }
291    
292 gebbert 1.6 int PlotTool::loop(vector<string> _histName, string cutName, int nEntries,
293     string drwOpt) {
294 tschum 1.1
295 gebbert 1.6 vector<string> _cutName;
296     _cutName.push_back(cutName);
297 tschum 1.1
298 gebbert 1.6 return loop(_histName, _cutName, nEntries, drwOpt);
299 tschum 1.1
300     }
301    
302 gebbert 1.6 int PlotTool::loop(string histName, vector<string> _cutName, int nEntries,
303     string drwOpt) {
304 tschum 1.1
305 gebbert 1.6 vector<string> _histName;
306     _histName.push_back(histName);
307 tschum 1.1
308 gebbert 1.6 return loop(_histName, _cutName, nEntries, drwOpt);
309 tschum 1.1 }
310     //------------------------------------------------------------------
311     //redraw the canvas to make changes in style visible
312 gebbert 1.6 int PlotTool::updatePads() {
313 tschum 1.1
314 gebbert 1.6 for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) {
315     if (gROOT->FindObject((*it).first.c_str() ) ) {
316     (*it).second->Draw();
317     setCanvas((*it).second);
318     } else
319     pads_.erase(it);
320     }
321 tschum 1.1
322 gebbert 1.6 return pads_.size();
323 tschum 1.1
324     }
325    
326     int PlotTool::fillCanvases() {
327    
328 gebbert 1.6 for (map< string, TCanvas* >::iterator it=canvases_.begin() ; it
329     != canvases_.end(); ++it) {
330     const char* canvName = (*it).first.c_str();
331     if (gROOT->FindObject(canvName) ) {
332    
333     int numP = (*it).second->GetNumber()+1;
334    
335     if (numP <= 0)
336     continue;
337    
338     int x = int( sqrt(numP) );
339     int y = x;
340     if (x*y < numP)
341     x += 1;
342     if (x*y < numP)
343     x += 1;
344     if (x*y < numP) {
345     x -= 1;
346     y += 1;
347     }
348    
349     (*it).second->Divide(x, y);
350     int padIndex = 1;
351     for (map< string, TCanvas* >::iterator it2=pads_.begin() ; it2
352     != pads_.end(); ++it2) {
353     string padName = (*it2).first;
354     if (gROOT->FindObject(padName.c_str() ) ) {
355     if ( (padName.find(canvName) != string::npos ) || !strcmp(
356     canvName, "All") ) {
357     (*it).second->cd(padIndex);
358     (*it2).second->DrawClonePad();
359     (*it2).second->Close();
360     pads_.erase(it2);
361     ++padIndex;
362     }
363     } else
364     pads_.erase(it2);
365     }
366     (*it).second->SetNumber(-1);
367 tschum 1.1
368 gebbert 1.6 } else
369     canvases_.erase(it);
370     }
371 tschum 1.1
372 gebbert 1.6 return canvases_.size();
373 tschum 1.1
374     }
375     //------------------------------------------------------------------
376     void PlotTool::setCanvas(TCanvas* thisCanvas) {
377    
378 gebbert 1.6 TH1* thisHist = 0;
379     TPaveStats* thisStatsBox = 0;
380     TPaletteAxis* palette =0;
381     TLegend* thisLeg = 0;
382     int counter =0;
383     double maxEntry=0;
384 tschum 1.1
385 gebbert 1.6 ((TFrame*) thisCanvas->GetFrame())->Delete();
386     thisCanvas->GetFrame()->SetLineWidth(gStyle->GetLineWidth() );
387 tschum 1.1
388 gebbert 1.6 thisCanvas->SetLeftMargin(0.2);
389     thisCanvas->SetRightMargin(0.06);
390     thisCanvas->SetBottomMargin(0.2);
391     thisCanvas->SetTopMargin(0.1);
392 tschum 1.1
393 gebbert 1.6 if (logY)
394     thisCanvas->SetLogy(1);
395     else
396     thisCanvas->SetLogy(0);
397 tschum 1.1
398 gebbert 1.6 if (showLegend)
399     thisLeg = new TLegend();
400 tschum 1.1
401 gebbert 1.6 for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) {
402 tschum 1.1
403 gebbert 1.6 if ( !thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1"))
404     continue;
405 tschum 1.1
406 gebbert 1.6 thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i));
407     setColor(thisHist, counter);
408     setMathLabels(thisHist);
409 tschum 1.1
410 gebbert 1.6 if (thisHist->GetMaximum() > maxEntry)
411     maxEntry = thisHist->GetMaximum();
412 tschum 1.1
413 gebbert 1.6 thisStatsBox = (TPaveStats*) thisHist->GetListOfFunctions()->FindObject("stats");
414     if (thisStatsBox)
415     setStats(thisCanvas, thisStatsBox, thisHist, counter);
416 tschum 1.1
417 gebbert 1.6 palette = (TPaletteAxis*) thisHist->GetListOfFunctions()->FindObject("palette");
418     if (palette)
419     setPalette(thisCanvas, palette);
420 tschum 1.1
421 gebbert 1.6 if (thisLeg)
422     thisLeg->AddEntry(thisHist,thisHist->GetName())->SetTextSize(0.04);
423 tschum 1.1
424 gebbert 1.6 ++counter;
425 tschum 1.1
426 gebbert 1.6 }
427 tschum 1.1
428 gebbert 1.6 if (maxEntry != 0)
429     setHistMax(thisCanvas, maxEntry);
430 tschum 1.1
431 gebbert 1.6 thisCanvas->cd();
432     thisCanvas->Update();
433 tschum 1.1
434 gebbert 1.6 if (thisLeg)
435     setLegend(thisCanvas, thisLeg, counter);
436 tschum 1.1
437     }
438     //------------------------------------------------------------------
439     //private helper classes to set the canvas and hist style
440 gebbert 1.6 void PlotTool::setStats(TCanvas* thisCanvas, TPaveStats* thisStatsBox,
441     TH1* thisHist, int counter) {
442 tschum 1.1
443 gebbert 1.6 if (thisCanvas->GetRightMargin() < .2)
444     thisCanvas->SetRightMargin(.2);
445 tschum 1.1
446 gebbert 1.6 thisStatsBox->SetLineColor(thisHist->GetLineColor());
447     thisStatsBox->SetX2NDC(1.);
448     thisStatsBox->SetY2NDC(1-thisCanvas->GetTopMargin()-0.16*counter);
449     thisStatsBox->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01);
450     thisStatsBox->SetY1NDC(thisStatsBox->GetY2NDC()-.15);
451 tschum 1.1
452     }
453    
454     void PlotTool::setMathLabels(TH1* thisHist) {
455    
456 gebbert 1.6 string t = thisHist ->GetTitle();
457     string x = thisHist->GetXaxis()->GetTitle();
458     string y = thisHist->GetYaxis()->GetTitle();
459    
460     if (t.find(".phi()") != string::npos)
461     t.replace(t.find(".phi()"), 6, " #phi");
462     if (x.find(".phi()") != string::npos)
463     x.replace(x.find(".phi()"), 6, " #phi");
464     if (y.find(".phi()") != string::npos)
465     y.replace(y.find(".phi()"), 6, " #phi");
466    
467     if (t.find(".eta()") != string::npos)
468     t.replace(t.find(".eta()"), 6, " #eta");
469     if (x.find(".eta()") != string::npos)
470     x.replace(x.find(".eta()"), 6, " #eta");
471     if (y.find(".eta()") != string::npos)
472     y.replace(y.find(".eta()"), 6, " #eta");
473    
474     if (t.find(".pt()") != string::npos)
475     t.replace(t.find(".pt()"), 5, " p_{T}");
476     if (x.find(".pt()") != string::npos)
477     x.replace(x.find(".pt()"), 5, " p_{T}");
478     if (y.find(".pt()") != string::npos)
479     y.replace(y.find(".pt()"), 5, " p_{T}");
480    
481     thisHist ->SetTitle(t.c_str());
482     thisHist->GetXaxis()->SetTitle(x.c_str());
483     thisHist->GetYaxis()->SetTitle(y.c_str());
484 tschum 1.1
485     }
486    
487     void PlotTool::setColor(TH1* thisHist, int counter) {
488    
489 gebbert 1.6 if (counter == 0) {
490 tschum 1.1
491 gebbert 1.6 thisHist->SetLineColor(kRed+1);
492     //if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kRed+1);
493     //else
494     thisHist->SetFillStyle(0);
495     thisHist->SetMarkerColor(kRed+1);
496     } else if (counter == 1) {
497     thisHist->SetLineColor(kBlue+1);
498     //if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlue+1);
499     //else
500     thisHist->SetFillStyle(0);
501     thisHist->SetMarkerColor(kBlue+1);
502    
503     } else if (counter == 2) {
504     thisHist->SetLineColor(kGreen+2);
505     //if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kGreen+2);
506     //else
507     thisHist->SetFillStyle(0);
508     thisHist->SetMarkerColor(kGreen+2);
509    
510     } else if (counter == 3) {
511     thisHist->SetLineColor(kMagenta+2);
512     //if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kMagenta+2);
513     //else
514     thisHist->SetFillStyle(0);
515     thisHist->SetMarkerColor(kMagenta+2);
516    
517     } else if (counter == 4) {
518     thisHist->SetLineColor(kCyan+2);
519     //if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kCyan+2);
520     //else
521     thisHist->SetFillStyle(0);
522     thisHist->SetMarkerColor(kCyan+2);
523    
524     } else {
525     thisHist->SetLineColor(kBlack);
526     //if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlack);
527     //else
528     thisHist->SetFillStyle(0);
529     thisHist->SetMarkerColor(kBlack);
530 tschum 1.1
531 gebbert 1.6 }
532 tschum 1.1
533     }
534    
535     void PlotTool::setPalette(TCanvas* thisCanvas, TPaletteAxis* palette) {
536    
537 gebbert 1.6 palette->SetLabelSize(0.045);
538     if (thisCanvas->GetRightMargin() < .15)
539     thisCanvas->SetRightMargin(.15);
540     palette->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01);
541     palette->SetY1NDC(thisCanvas->GetBottomMargin());
542     palette->SetX2NDC(palette->GetX1NDC()+0.05);
543     palette->SetY2NDC(1-thisCanvas->GetTopMargin());
544 tschum 1.1
545     }
546    
547     void PlotTool::setHistMax(TCanvas* thisCanvas, double maxEntry) {
548    
549 gebbert 1.6 TH1* thisHist = 0;
550 tschum 1.1
551 gebbert 1.6 for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) {
552 tschum 1.1
553 gebbert 1.6 if ( !thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1") )
554     continue;
555     thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i));
556     if (thisHist->GetMaximum() < maxEntry) {
557     double minEntry=thisHist->GetBinContent(thisHist->GetMinimumBin());
558     if (logY) {
559     int bin = (thisHist->GetMinimumBin()+1);
560     minEntry=thisHist->GetBinContent(bin);
561     }
562     thisHist->GetYaxis()->SetRangeUser(minEntry, maxEntry*1.2);
563     }
564     break;
565 tschum 1.1
566 gebbert 1.6 }
567 tschum 1.1
568     }
569    
570     void PlotTool::setLegend(TCanvas* thisCanvas, TLegend* thisLeg, int counter) {
571    
572 gebbert 1.6 thisLeg->SetFillStyle(0);
573     thisLeg->SetX1NDC(1-thisCanvas->GetRightMargin()-0.5);
574     thisLeg->SetY1NDC(1-thisCanvas->GetTopMargin()-0.05*counter);
575     thisLeg->SetX2NDC(1-thisCanvas->GetRightMargin());
576     thisLeg->SetY2NDC(1-thisCanvas->GetTopMargin());
577     thisLeg->SetEntrySeparation(0.5);
578     thisLeg->Draw("NDC");
579 tschum 1.1
580     }
581    
582 gebbert 1.6 void PlotTool::createColors() {
583     const Int_t NRGBs = 5;
584     const Int_t NCont = 255;
585    
586     Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
587     Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
588     Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
589     Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
590     TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
591     gStyle->SetNumberContours(NCont);
592 tschum 1.1
593     }
594    
595     //------------------------------------------------------------------
596    
597     int PlotTool::saveCanvases(string type, string path) {
598    
599 gebbert 1.6 TSystemDirectory d("", path.c_str());
600     if (!d.GetListOfFiles())
601     return -1;
602     if (type.find(".") == string::npos)
603     return -1;
604    
605     int savedFiles =0;
606    
607     TIter next(gROOT->GetListOfCanvases());
608     TCanvas* canv;
609     while ((canv=(TCanvas*)next())) {
610    
611     string s = "";
612     s += path;
613     s += canv->GetName();
614     s += type;
615    
616     canv->SaveAs(s.c_str());
617     ++savedFiles;
618    
619     }
620 tschum 1.1
621 gebbert 1.6 return savedFiles;
622 tschum 1.1
623     }
624     //------------------------------------------------------------------