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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines