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.3 by tschum, Mon Nov 16 15:41:19 2009 UTC vs.
Revision 1.9 by tschum, Thu Dec 3 11:24:14 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines