ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/tschum/FWlite_Analysis/PlotTool.cc
(Generate patch)

Comparing UserCode/tschum/FWlite_Analysis/PlotTool.cc (file contents):
Revision 1.1.1.1 by tschum, Wed Nov 11 15:36:55 2009 UTC vs.
Revision 1.21 by tschum, Fri Feb 19 10:33:39 2010 UTC

# Line 1 | Line 1
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 >        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 <  this->SetClass("TChain",100);
15 >        showLegend = false;
16 >        logY = true;
17 >        verbose = true;
18  
19 <  samePad_trees = true;
10 <  samePad_vars  = false;
11 <  samePad_cuts  = false;
12 <  sameCanv_trees = false;
13 <  sameCanv_vars  = false;
14 <  sameCanv_cuts  = false;
19 >        globalCuts="";
20  
21 <  showLegend = false;
21 >        varBlockNames = "";   //Set to "ALL" or add Names, i.e. varBlockNames += "CaloTower"
22 >        recreateTree = false; //force recreation of friend tree
23 >
24 >        normHists = false; //scale all histos intergrals to 1
25  
26   }
27  
28   //------------------------------------------------------------------
29   //Fill object PlotTool with Chains constructed from files from given source
30 < int PlotTool::init(string fileName, string dirPath, string treeName)
31 < {
32 <  this->New( this->GetEntries() );
30 >
31 > int PlotTool::init(string fileName, string dirPath, string treeName,
32 >                   string fileLabel) {
33 >  this->New(this->GetEntries() );
34    int currChain = this->GetEntries() - 1;
35  
36 <  if(currChain < 0 ) return currChain;
36 >  if (currChain < 0)
37 >    return currChain;
38 >
39 >  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  
64 <  ((TChain*) this->At(currChain))->SetName(fileName.c_str());
65 <  TSystemDirectory dir("sourceDir",dirPath.c_str());
66 <  TList *files = dir.GetListOfFiles();
67 <  if (files) {
68 <    TIter next(files);
69 <    TSystemFile *file;
64 >
65 >  } 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 <    cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: "<<fileName.c_str()<<endl;
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")) continue;
84 <      if (!fname.Contains(fileName.c_str())) continue;
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 <      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;
91 <      else return -1;
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 >                                                   treeName.c_str()) ) {
95 >        if(verbose)     cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl;
96 >      } else {
97 >        return -1;
98 >      }
99  
100      }
101 <  } else return -1;
101 >  } else
102 >    return -1;
103  
104 <  for(int i=0;i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries();++i){
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 <    size_t a =  s.find("_");
108 <    if(a == string::npos) a = 0;
59 <    size_t b =  s.find("_", a+1);
60 <    if(b == string::npos) b = 50;
61 <    string branch_alias = s.substr(a+1,b-a-1);
107 >
108 >    string branch_alias = s;
109      string branch_name = s;
110 <    if(s.find(".",s.size()-1) != string::npos ) branch_name += "obj";
111 <    ((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),branch_name.c_str());
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 >        }
133 >      }
134 >    }
135 >
136 >    ((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),
137 >                                              branch_name.c_str());
138  
139    }
140  
141 +
142 +
143 +
144 +    
145 +  string friendTreeName("friendTree");
146 +
147 +  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 +    ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
161 +                                               friendFileName.c_str());
162 +  } else {
163 +    if(verbose)   cout<<"No additional variables added."<<endl;
164 +  }
165 +
166 +  
167 +    
168 +
169 +
170 +  timer.Stop();
171 +  if(verbose) timer.Print();
172 +      
173    return this->GetEntries();
174  
175   }
176   //------------------------------------------------------------------
177   //Draw given Chain with given variable and given cuts
178 < int  PlotTool::plot(int chainIndex, string histName, string cutName, int nEntries, string drwOpt)
179 < {
178 > TH1* PlotTool::plot(int chainIndex, string histName, string cutName,
179 >                int nEntries, string bins, string drwOpt) {
180  
181 <  if( chainIndex >= this->GetEntries() ) return -1;
181 >        TH1* thisHist = 0;
182  
183 <  int currN = nEntries;
184 <  if(nEntries < 0) currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted!
183 >        if (chainIndex >= this->GetEntries() )
184 >                return thisHist;
185  
186 <  //++++ Create and name Canvases according to global variables +++++++++++++
187 <  ostringstream currHistName;
188 <  if( samePad_trees) currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":";
189 <  if( samePad_vars)  currHistName<<histName;
190 <  if( samePad_cuts)  currHistName<<"{"<<cutName<<"}";
86 <
87 <   ostringstream currPadName;
88 <  if(! samePad_trees) currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":";
89 <  if(! samePad_vars)  currPadName<<histName;
90 <  if(! samePad_cuts)  currPadName<<"{"<<cutName<<"}";
91 <
92 <  ostringstream currCanvName;
93 <  if(! sameCanv_trees && ! samePad_trees ) currCanvName<<((TChain*) this->At(chainIndex))->GetName()<<":";
94 <  if(! sameCanv_vars  && ! samePad_vars)  currCanvName<<histName;
95 <  if(! sameCanv_cuts  && ! samePad_cuts)  currCanvName<<"{"<<cutName<<"}";
186 >        TStopwatch timer;
187 >        if(verbose) {
188 >          cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl;
189 >          timer.Start();
190 >        }
191  
192 <  if( (sameCanv_trees || samePad_trees) && (sameCanv_vars  || samePad_vars) && (sameCanv_cuts  || samePad_cuts) )  currCanvName<<"All";
192 >        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 >                if ( !canvases_[currCanvName.str()] || !gROOT->GetListOfCanvases()->FindObject(currCanvName.str().c_str()) ) {
231 >                        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  
237 <    
238 <  string currOpt = drwOpt;
239 <  bool useSubPads = (sameCanv_trees && !samePad_trees) || (sameCanv_vars  && !samePad_vars) || (sameCanv_cuts  && !samePad_cuts);
237 >        if ( !pads_[currPadName.str()] || !gROOT->GetListOfCanvases()->FindObject(currPadName.str().c_str()) ) {
238 >                pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str());
239 >                //              if (logY)
240 >                //                      pads_[currPadName.str()]->SetLogy(1);
241 >        } 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 >
249 >
250 >        //Draw histogram:
251 >        string cutNameWithGlobal = "";
252 >        if(cutName!="" && globalCuts!="")    cutNameWithGlobal += "(";
253 >        if(cutName!="")                      cutNameWithGlobal += cutName;
254 >        if(cutName!="" && globalCuts!="")    cutNameWithGlobal += ")";
255 >        if(cutName!="" && globalCuts!="")    cutNameWithGlobal += "&&";
256 >        if(cutName!="" && globalCuts!="")    cutNameWithGlobal += "(";
257 >        if(globalCuts!="")                   cutNameWithGlobal += globalCuts;
258 >        if(cutName!="" && globalCuts!="")    cutNameWithGlobal += ")";
259 >
260 >        histName += ">>htemp";
261 >        if(bins != "") histName += bins;
262  
103  if( useSubPads ) {
104    if( ! canvases_[currCanvName.str()] || ! gROOT->FindObject(currCanvName.str().c_str()) ) {
105      canvases_[currCanvName.str()] = new TCanvas(currCanvName.str().c_str(), currCanvName.str().c_str());
106    } else if ( canvases_[currCanvName.str()]->GetNumber() >= 0 ) {
107      canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()+1);
108    }
109  }
110  
111  if( ! pads_[currPadName.str()] || ! gROOT->FindObject(currPadName.str().c_str()) ) {
112    pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str());
113  } else {
114    pads_[currPadName.str()]->cd();
115    currOpt += "SAMES";
116    if(useSubPads) canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1);
117  }
118  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
263  
264  
121  //Draw histogram:
122  int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(), currOpt.c_str(), currN);
123  if( draw_err < 0 ) return draw_err;
124
125  //++++ Fix for histos with no entries +++++++++++++
126  if( draw_err == 0 ) {
127    if( currOpt.find("SAMES") == string::npos ) {
128      pads_[currPadName.str()]->Close();
129      pads_.erase( currPadName.str() );
130      if(useSubPads) canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1);
131    }
132    cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str()<<" has no entries and is not drawn!"<<endl;
133    return draw_err;
134  }
135  //++++++++++++++++++++++++++++++++++++++++++++++++++
265  
266 <  ((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram
266 >        int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutNameWithGlobal.c_str(),
267 >                        currOpt.c_str(), currN);
268 >        if (draw_err < 0)
269 >                return thisHist;
270 >
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 >                if(verbose) cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str()
280 >                                <<" has no entries and is not drawn!"<<endl;
281 >                return thisHist;
282 >        }
283 >        //++++++++++++++++++++++++++++++++++++++++++++++++++
284 >
285 >        thisHist = (TH1*) pads_[currPadName.str()]->GetPrimitive("htemp");
286  
287 +        thisHist->SetName(currHistName.str().c_str());
288  
289 <  return draw_err;
289 >        // Update for 2D histograms
290 >        if( thisHist->InheritsFrom("TH2") ) {
291 >                        pads_[currPadName.str()]->Draw();
292 >                        setCanvas( pads_[currPadName.str()] );
293 >        }
294 >
295 >
296 >        if(verbose && draw_err > 0) {
297 >          timer.Stop();
298 >          cout<<"Done: Selected "<<draw_err<<" objects in "<< currN <<" processed events."<<endl;
299 >          timer.Print();
300 >        }
301 >        return thisHist;
302  
303   }
304   //------------------------------------------------------------------
305   //Standard loop to draw all chains and multiple variables and cuts
306 < int  PlotTool::loop(vector<string> _histName, vector<string> _cutName, int nEntries, string drwOpt, bool correspond)
307 < {
306 > int PlotTool::loop(vector<string> _histName, vector<string> _cutName,
307 >                int nEntries, string bins, string drwOpt, bool correspond) {
308  
309 +        int numProcessed = 0;
310  
311 +        TH1* currHist = 0;
312  
150  int numProcessed = 0;
313  
314 <  if( correspond == false ) {
314 >        if (correspond == false) {
315  
316 <    for(int i=0; i<this->GetEntries(); ++i) {
317 <      for(vector<string>::iterator it1 =_histName.begin(); it1 != _histName.end(); ++it1) {
318 <        for(vector<string>::iterator it2 =_cutName.begin(); it2 != _cutName.end(); ++it2) {
316 >                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  
322 <          numProcessed += plot(i, *it1, *it2, nEntries, drwOpt);
323 <        
324 <        }
161 <      }
162 <    }
163 <  } else {
322 >                                  currHist = plot(i, *it1, *it2, nEntries, bins, drwOpt);
323 >                                  if(currHist) numProcessed += int(currHist->GetEntries());
324 >                                
325  
326 <    if( _histName.size() != _cutName.size() ) return -1;
326 >                                }
327 >                        }
328 >                }
329 >        } else {
330  
331 <    for(int i=0; i<this->GetEntries(); ++i) {
332 <      for(vector<string>::iterator it1 =_histName.begin(),it2 =_cutName.begin(); it1 != _cutName.end()&&it2 != _cutName.end(); ++it1, ++it2) {
331 >                if (_histName.size() != _cutName.size() )
332 >                        return -1;
333  
334 <        numProcessed += plot(i, *it1, *it2, nEntries, drwOpt);
334 >                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  
339 +                          currHist = plot(i, *it1, *it2, nEntries, bins, drwOpt);
340 +                          if(currHist) numProcessed += int(currHist->GetEntries());
341  
342 <      }
343 <    }
344 <  }
342 >                        }
343 >                }
344 >        }
345  
346 <  updatePads();
347 <  fillCanvases();
346 >        updatePads();
347 >        fillCanvases();
348  
349 <  return numProcessed;
349 >        return numProcessed;
350   }
351  
352   //Helper methods to allow for using simple strings as input
353 < int  PlotTool::loop(string histName, string cutName, int nEntries, string drwOpt)
185 < {
353 > int PlotTool::loop(string histName, string cutName, int nEntries, string bins, string drwOpt) {
354  
355 <  vector<string> _histName;
356 <  _histName.push_back( histName );
357 <  vector<string> _cutName;
358 <  _cutName.push_back( cutName );
355 >        vector<string> _histName;
356 >        _histName.push_back(histName);
357 >        vector<string> _cutName;
358 >        _cutName.push_back(cutName);
359  
360 <  return loop(_histName, _cutName, nEntries, drwOpt);
360 >        return loop(_histName, _cutName, nEntries, bins, drwOpt);
361  
362   }
363  
364 < int  PlotTool::loop(vector<string> _histName, string cutName, int nEntries, string drwOpt)
365 < {
364 > int PlotTool::loop(vector<string> _histName, string cutName, int nEntries, string bins,
365 >                string drwOpt) {
366  
367 <  vector<string> _cutName;
368 <  _cutName.push_back( cutName );
367 >        vector<string> _cutName;
368 >        _cutName.push_back(cutName);
369  
370 <  return loop(_histName, _cutName, nEntries, drwOpt);
370 >        return loop(_histName, _cutName, nEntries, bins, drwOpt);
371  
372   }
373  
374 < int  PlotTool::loop(string histName, vector<string> _cutName, int nEntries, string drwOpt)
375 < {
374 > int PlotTool::loop(string histName, vector<string> _cutName, int nEntries, string bins,
375 >                string drwOpt) {
376  
377 <  vector<string> _histName;
378 <  _histName.push_back( histName );
377 >        vector<string> _histName;
378 >        _histName.push_back(histName);
379  
380 <  return loop(_histName, _cutName, nEntries, drwOpt);
380 >        return loop(_histName, _cutName, nEntries, bins, drwOpt);
381   }
382   //------------------------------------------------------------------
383   //redraw the canvas to make changes in style visible
384 < int  PlotTool::updatePads() {
384 > int PlotTool::updatePads() {
385 >
386 >        for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) {
387 >                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 <  for(map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it ) {
219 <    if( gROOT->FindObject( (*it).first.c_str() ) ) {
220 <      (*it).second->Draw();
221 <      setCanvas( (*it).second );
222 <    } else pads_.erase( it );  
223 <  }
399 >        }
400  
401 <  return pads_.size();
401 >        return pads_.size();
402  
403   }
404  
405   int PlotTool::fillCanvases() {
406  
407 +        for (map< string, TCanvas* >::iterator it=canvases_.begin() ; it
408 +                        != canvases_.end(); ++it) {
409 +                string canvName = (*it).first;
410 +                if (gROOT->GetListOfCanvases()->FindObject(canvName.c_str()) ) {
411 +
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 +
429 +                        (*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 +                                if (gROOT->GetListOfCanvases()->FindObject(padName.c_str() ) ) {
435 +                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 +                                                (*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  
451 <  for(map< string, TCanvas* >::iterator it=canvases_.begin() ; it != canvases_.end(); ++it ) {
452 <    const char* canvName = (*it).first.c_str();
453 <    if( gROOT->FindObject( canvName ) ) {
235 <
236 <      int numP = (*it).second->GetNumber()+1;
237 <
238 <      if( numP <= 0 ) continue;
239 <
240 <      int x = int( sqrt(numP) );
241 <      int y = x;
242 <      if( x*y     < numP )  x += 1;
243 <      if( x*y     < numP )  x += 1;
244 <      if( x*y     < numP ) {
245 <        x -= 1;
246 <        y += 1;
247 <      }
248 <
249 <      (*it).second->Divide(x,y);
250 <      int padIndex = 1;
251 <      for(map< string, TCanvas* >::iterator it2=pads_.begin() ; it2 != pads_.end(); ++it2 ) {
252 <        string padName = (*it2).first;
253 <        if( gROOT->FindObject( padName.c_str() ) ) {
254 <          if( ( padName.find(canvName) != string::npos ) || !strcmp(canvName,"All") ) {
255 <            (*it).second->cd(padIndex);
256 <            (*it2).second->DrawClonePad();
257 <            (*it2).second->Close();
258 <            pads_.erase( it2 );
259 <            ++padIndex;
260 <          }
261 <        } else pads_.erase( it2 );
262 <      }
263 <      (*it).second->SetNumber(-1);
264 <
265 <    } else canvases_.erase( it );      
266 <  }
451 >                } else
452 >                        canvases_.erase(it);
453 >        }
454  
455 <  return canvases_.size();
455 >        return canvases_.size();
456  
457   }
458   //------------------------------------------------------------------
459   void PlotTool::setCanvas(TCanvas* thisCanvas) {
460  
461  
462 <  TH1* thisHist = 0;
463 <  TPaveStats* thisStatsBox = 0;
464 <  TPaletteAxis* palette =0;
465 <  TLegend* thisLeg = 0;
466 <  int counter =0;
467 <  double maxEntry=0;
462 >        TH1* thisHist = 0;
463 >        TPaveStats* thisStatsBox = 0;
464 >        TPaletteAxis* palette =0;
465 >        TLegend* thisLeg = 0;
466 >        int counter =0;
467 >        double maxEntry=0;
468  
469 +        ((TFrame*) thisCanvas->GetFrame())->Delete();
470 +        thisCanvas->GetFrame()->SetLineWidth(gStyle->GetLineWidth() );
471  
472 <  ((TFrame*) thisCanvas->GetFrame())->Delete();
473 <  thisCanvas->GetFrame()->SetLineWidth( gStyle->GetLineWidth() );
472 >        thisCanvas->SetLeftMargin(0.2);
473 >        thisCanvas->SetRightMargin(0.06);
474 >        thisCanvas->SetBottomMargin(0.2);
475 >        thisCanvas->SetTopMargin(0.1);
476  
477 <  thisCanvas->SetLeftMargin(0.2);
478 <  thisCanvas->SetRightMargin(0.06);
479 <  thisCanvas->SetBottomMargin(0.2);
480 <  thisCanvas->SetTopMargin(0.1);
477 >        if (logY)
478 >                thisCanvas->SetLogy(1);
479 >        else
480 >                thisCanvas->SetLogy(0);
481  
482 +        if (showLegend)
483 +                thisLeg = new TLegend();
484  
485 <  if(showLegend)  thisLeg = new TLegend();
293 <
485 >        for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) {
486  
295  for(int i = 0; i !=  thisCanvas->GetListOfPrimitives()->GetSize(); ++i){
487  
488  
489 <    if( ! thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1")) continue;
489 >                if ( !thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1"))
490 >                        continue;
491  
300      thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i));
301      setColor(thisHist, counter);
302      setMathLabels(thisHist);
492  
493 <      if(thisHist->GetMaximum() > maxEntry) maxEntry = thisHist->GetMaximum();
493 >                thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i));
494  
495 <      thisStatsBox = (TPaveStats*) thisHist->GetListOfFunctions()->FindObject("stats");
496 <      if(thisStatsBox) setStats(thisCanvas, thisStatsBox, thisHist, counter);
495 >                TString testString( thisHist->GetName() );
496 >                if( testString.BeginsWith("frame_") ) continue;
497  
498 <      palette = (TPaletteAxis*) thisHist->GetListOfFunctions()->FindObject("palette");
499 <      if(palette) setPalette(thisCanvas, palette);
498 >                setColor(thisHist, counter);
499 >                setMathLabels(thisHist);
500  
501 <      if(thisLeg) thisLeg->AddEntry(thisHist,thisHist->GetName())->SetTextSize(0.04);
501 >                if(normHists) thisHist->Scale(1/thisHist->GetSumOfWeights());
502  
503 +                if (thisHist->GetMaximum() > maxEntry)
504 +                        maxEntry = thisHist->GetMaximum();
505  
506 <      ++counter;
507 <  
508 <  }
506 >                thisStatsBox = (TPaveStats*) thisHist->GetListOfFunctions()->FindObject("stats");
507 >                if (thisStatsBox)
508 >                        setStats(thisCanvas, thisStatsBox, thisHist, counter);
509  
510 <  if( maxEntry != 0) setHistMax(thisCanvas, maxEntry);
511 <
510 >                palette = (TPaletteAxis*) thisHist->GetListOfFunctions()->FindObject("palette");
511 >                if (palette)
512 >                        setPalette(thisCanvas, palette);
513  
514 <  thisCanvas->cd();
515 <  thisCanvas->Update();
514 >                if (thisLeg)
515 >                        thisLeg->AddEntry(thisHist,thisHist->GetName())->SetTextSize(0.04);
516 >
517 >                ++counter;
518 >
519 >        }
520 >
521 >        if (maxEntry != 0)
522 >                setHistMax(thisCanvas, maxEntry);
523 >
524 >        thisCanvas->cd();
525 >        thisCanvas->Update();
526 >
527 >        if (thisLeg)
528 >                setLegend(thisCanvas, thisLeg, counter);
529  
325  if(thisLeg) setLegend( thisCanvas, thisLeg, counter);
326  
327        
530   }
531   //------------------------------------------------------------------
532   //private helper classes to set the canvas and hist style
533 < void PlotTool::setStats(TCanvas* thisCanvas, TPaveStats* thisStatsBox, TH1* thisHist, int counter) {
533 > void PlotTool::setStats(TCanvas* thisCanvas, TPaveStats* thisStatsBox,
534 >                TH1* thisHist, int counter) {
535  
536 +        if (thisCanvas->GetRightMargin() < .2)
537 +                thisCanvas->SetRightMargin(.2);
538  
539 <  if(thisCanvas->GetRightMargin() < .2) thisCanvas->SetRightMargin(.2);
539 >        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  
545 <  thisStatsBox->SetLineColor(thisHist->GetLineColor());
337 <  thisStatsBox->SetX2NDC(1.);
338 <  thisStatsBox->SetY2NDC(1-thisCanvas->GetTopMargin()-0.16*counter);
339 <  thisStatsBox->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01);
340 <  thisStatsBox->SetY1NDC(thisStatsBox->GetY2NDC()-.15);
545 > }
546  
547 + void PlotTool::setMathLabels(TH1* thisHist) {
548  
549 +        string t = thisHist ->GetTitle();
550 +        string x = thisHist->GetXaxis()->GetTitle();
551 +        string y = thisHist->GetYaxis()->GetTitle();
552 +
553 + //      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 +        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 +        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 +        if (x.find(".pt()") != string::npos)
579 +                x.replace(x.find(".pt()"), 5, " p_{T} [GeV]");
580 +        if (y.find(".pt()") != string::npos)
581 +                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 +
602 +        thisHist ->SetTitle(t.c_str());
603 +        thisHist->GetXaxis()->SetTitle(x.c_str());
604 +        thisHist->GetYaxis()->SetTitle(y.c_str());
605  
606   }
607  
608 < void PlotTool::setMathLabels(TH1* thisHist) {
608 > void PlotTool::setColor(TH1* thisHist, int counter) {
609  
610 +  thisHist->SetLineWidth(gStyle->GetLineWidth());
611  
612 <  string t = thisHist            ->GetTitle();
613 <  string x = thisHist->GetXaxis()->GetTitle();
614 <  string y = thisHist->GetYaxis()->GetTitle();
615 <
616 <  if(t.find(".phi()") != string::npos ) t.replace(t.find(".phi()"),6," #phi");
617 <  if(x.find(".phi()") != string::npos ) x.replace(x.find(".phi()"),6," #phi");
618 <  if(y.find(".phi()") != string::npos ) y.replace(y.find(".phi()"),6," #phi");
619 <
620 <  if(t.find(".eta()") != string::npos ) t.replace(t.find(".eta()"),6," #eta");
621 <  if(x.find(".eta()") != string::npos ) x.replace(x.find(".eta()"),6," #eta");
622 <  if(y.find(".eta()") != string::npos ) y.replace(y.find(".eta()"),6," #eta");
623 <
624 <  if(t.find(".pt()") != string::npos ) t.replace(t.find(".pt()"),5," p_{T}");
625 <  if(x.find(".pt()") != string::npos ) x.replace(x.find(".pt()"),5," p_{T}");
626 <  if(y.find(".pt()") != string::npos ) y.replace(y.find(".pt()"),5," p_{T}");
627 <
628 <  thisHist            ->SetTitle(t.c_str());
629 <  thisHist->GetXaxis()->SetTitle(x.c_str());
630 <  thisHist->GetYaxis()->SetTitle(y.c_str());
612 >        if (counter == 0) {
613 >
614 >                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 >
654 >        }
655  
656  
657   }
658  
659 + void PlotTool::setPalette(TCanvas* thisCanvas, TPaletteAxis* palette) {
660  
661 < void PlotTool::setColor(TH1* thisHist, int counter) {
661 >        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  
669 + }
670  
671 <      if(counter == 0) {
671 > void PlotTool::setHistMax(TCanvas* thisCanvas, double maxEntry) {
672  
673 <        thisHist->SetLineColor  (kRed+1);
379 <        if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor  (kRed+1);
380 <        else thisHist->SetFillStyle(0);
381 <        thisHist->SetMarkerColor(kRed+1);
382 <      } else if(counter == 1) {
383 <        thisHist->SetLineColor  (kBlue+1);
384 <        if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor  (kBlue+1);
385 <        else thisHist->SetFillStyle(0);
386 <        thisHist->SetMarkerColor(kBlue+1);
387 <
388 <      } else if(counter == 2) {
389 <        thisHist->SetLineColor  (kGreen+2);
390 <        if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor  (kGreen+2);
391 <        else thisHist->SetFillStyle(0);
392 <        thisHist->SetMarkerColor(kGreen+2);
393 <
394 <      } else if(counter == 3) {
395 <        thisHist->SetLineColor  (kMagenta+2);
396 <        if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor  (kMagenta+2);
397 <        else thisHist->SetFillStyle(0);
398 <        thisHist->SetMarkerColor(kMagenta+2);
399 <
400 <      } else if(counter == 4) {
401 <        thisHist->SetLineColor  (kCyan+2);
402 <        if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor  (kCyan+2);
403 <        else thisHist->SetFillStyle(0);
404 <        thisHist->SetMarkerColor(kCyan+2);
673 >        TH1* thisHist = 0;
674  
675 <      } else {
407 <        thisHist->SetLineColor  (kBlack);
408 <        if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor  (kBlack);
409 <        else thisHist->SetFillStyle(0);
410 <        thisHist->SetMarkerColor(kBlack);
675 >        for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) {
676  
677 <      }
677 >                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 >
690 >        }
691  
692   }
693  
694 < void PlotTool::setPalette(TCanvas* thisCanvas, TPaletteAxis* palette) {
694 > void PlotTool::setLegend(TCanvas* thisCanvas, TLegend* thisLeg, int counter) {
695  
696 +        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  
704 <  palette->SetLabelSize(0.045);
420 <  if(thisCanvas->GetRightMargin() < .15) thisCanvas->SetRightMargin(.15);
421 <  palette->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01);
422 <  palette->SetY1NDC(thisCanvas->GetBottomMargin());
423 <  palette->SetX2NDC(palette->GetX1NDC()+0.05);
424 <  palette->SetY2NDC(1-thisCanvas->GetTopMargin());
704 > }
705  
706 + 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  
717   }
718  
719 < void PlotTool::setHistMax(TCanvas* thisCanvas, double maxEntry) {
719 > //------------------------------------------------------------------
720  
721 <  TH1* thisHist = 0;
721 > int PlotTool::saveCanvases(string name, string path) {
722  
723 <  for(int i = 0; i !=  thisCanvas->GetListOfPrimitives()->GetSize(); ++i){
723 >        TSystemDirectory d("", path.c_str());
724 >        if (!d.GetListOfFiles())
725 >                return -1;
726  
727 <    if( ! thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1") ) continue;
728 <    thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i));
437 <    if( thisHist->GetMaximum() < maxEntry ) thisHist->GetYaxis()->SetRangeUser(thisHist->GetMinimum(),maxEntry*1.2);
438 <    break;
727 >        string namePs = path +"/" + name;
728 >        string nameRt = path +"/" + name;
729  
730 <  }
730 >        if (name.find(".ps") == string::npos)
731 >                namePs += ".ps";
732  
733 +        if (name.find(".root") == string::npos)
734 +                nameRt += ".root";
735  
736 < }
736 >        int savedCanvs =0;
737  
445 void PlotTool::setLegend(TCanvas* thisCanvas, TLegend* thisLeg, int counter) {
738  
739 <  thisLeg->SetFillStyle(0);
740 <  thisLeg->SetX1NDC(1-thisCanvas->GetRightMargin()-0.5);
741 <  thisLeg->SetY1NDC(1-thisCanvas->GetTopMargin()-0.05*counter);
742 <  thisLeg->SetX2NDC(1-thisCanvas->GetRightMargin());
743 <  thisLeg->SetY2NDC(1-thisCanvas->GetTopMargin());
744 <  thisLeg->SetEntrySeparation(0.5);
453 <  thisLeg->Draw("NDC");
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 < }
746 >        }
747  
457 void PlotTool::createColors()
458 {
459    const Int_t NRGBs = 5;
460    const Int_t NCont = 255;
748  
749 <    Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
750 <    Double_t red[NRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
751 <    Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
752 <    Double_t blue[NRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
753 <    TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
754 <    gStyle->SetNumberContours(NCont);
749 >        TPostScript ps(namePs.c_str(),112);
750 >        TFile rt(nameRt.c_str(),"recreate");
751 >
752 >        next.Reset();
753 >        while ((canv=(TCanvas*)next())) {
754 >          ps.NewPage();
755 >
756 >
757 >          (*canv).Write();
758 >          (*canv).Draw();
759 >          (*canv).Update();
760  
469 }
761  
762 +          ++savedCanvs;
763  
764 +        }
765 +
766 +        ps.Close();
767 +        rt.Close();
768 +
769 +
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 +        return savedCanvs;
775 +
776 + }
777   //------------------------------------------------------------------
778  
779 < int PlotTool::saveCanvases(string type, string path) {
779 > int PlotTool::clearCanvases()
780 > {
781  
782 +  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 <  TSystemDirectory d("",path.c_str());
788 <  if(!d.GetListOfFiles()) return -1;
789 <  if(type.find(".") == string::npos) return -1;
787 > }
788 > //------------------------------------------------------------------
789 > int PlotTool::setVariables(string label)
790 > {
791  
792 <  int savedFiles =0;
792 >        for (int i=0; i< this->GetEntries(); ++i) {
793 >          cout<<"--------------------------------"<<endl;
794 >          cout<<((TChain*) this->At(i))->GetName()<<endl;
795 >          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 <  TIter next(gROOT->GetListOfCanvases());
484 <  TCanvas* canv;
485 <  while ((canv=(TCanvas*)next())) {
486 <    
487 <    string s = "";
488 <    s += path;
489 <    s += canv->GetName();
490 <    s += type;
843 >          }
844  
845 <    canv->SaveAs(s.c_str());
493 <    ++savedFiles;
845 >        }
846  
847 <  }
496 <
497 <  return savedFiles;  
847 >        return autoVars.size();
848  
849   }
850 +
851   //------------------------------------------------------------------

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines