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.8 by tschum, Wed Dec 2 15:57:44 2009 UTC vs.
Revision 1.18 by tschum, Wed Feb 10 11:41:57 2010 UTC

# Line 14 | Line 14 | PlotTool::PlotTool() {
14  
15          showLegend = false;
16          logY = true;
17        addTrackJets = true;
17          verbose = true;
18  
19 +        globalCuts="";
20 +
21 +        varBlockNames = "";   //Set to "ALL" or add Names, i.e. varBlockNames += "CaloTower"
22 +        recreateTree = false; //force recreation of friend tree
23 +
24   }
25  
26   //------------------------------------------------------------------
27   //Fill object PlotTool with Chains constructed from files from given source
28  
29   int PlotTool::init(string fileName, string dirPath, string treeName,
30 <                string fileLabel) {
31 <        this->New(this->GetEntries() );
32 <        int currChain = this->GetEntries() - 1;
30 >                   string fileLabel) {
31 >  this->New(this->GetEntries() );
32 >  int currChain = this->GetEntries() - 1;
33  
34 <        if (currChain < 0)
35 <                return currChain;
34 >  if (currChain < 0)
35 >    return currChain;
36  
37 <        TStopwatch timer;
38 <        timer.Start();
37 >  TStopwatch timer;
38 >  timer.Start();
39  
40  
41 <        fileNames.clear();
41 >  fileNames.clear();
42  
43 <        //check if alternative label is different from default(searchString)
44 <        if (fileLabel=="") {
45 <                fileLabel=fileName;
46 <        }
47 <        ((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;
43 >  //check if alternative label is different from default(searchString)
44 >  if (fileLabel=="") {
45 >    fileLabel=fileName;
46 >  }
47 >  ((TChain*) this->At(currChain))->SetName(fileLabel.c_str());
48  
49 <                        filePath = dirPath;
50 <                        filePath += fname.Data();
51 <                        //fwlite::ChainEvent to lop over events, jets, etc
52 <                        fileNames.push_back(filePath.c_str());
53 <
54 <                        if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1,
55 <                                        treeName.c_str()) )
56 <                if(verbose)     cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl;
57 <                        else
58 <                                return -1;
49 >  TList *files = new TList();
50 >  TSystemFile* sysFile = 0;
51 >  if(fileName.find(".") != string::npos) {
52 >    ifstream f(fileName.c_str());
53 >    if( ! f.is_open() ) return -1;
54 >    string line;
55 >
56 >    while (!f.eof()) {
57 >      getline(f,line);
58 >      sysFile = new TSystemFile(line.c_str(),dirPath.c_str());
59 >      files->Add(sysFile);
60 >    }
61  
73                }
74        } else
75                return -1;
62  
63 <        for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) {
63 >  } else {
64 >    TSystemDirectory dir("sourceDir", dirPath.c_str());
65 >    files = dir.GetListOfFiles();
66 >  }
67 >  if (files->GetEntries()>0) {
68 >    TIter next(files);
69 >    TSystemFile *file;
70 >    TString fname;
71 >    string filePath;
72 >
73 >    if(verbose && fileName.find(".") == string::npos )  cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: "
74 >                                                            <<fileName.c_str()<<endl;
75 >    if(verbose && fileName.find(".") != string::npos )  cout<<"Open"<<dirPath.c_str()<<" Search lines with .root in: "
76 >                                                            <<fileName.c_str()<<endl;
77 >
78 >
79 >    while ((file=(TSystemFile*)next())) {
80 >      fname = file->GetName();
81 >      if (!fname.EndsWith(".root"))
82 >        continue;
83 >      if (!fname.Contains(fileName.c_str()) && fileName.find(".") == string::npos )
84 >        continue;
85 >
86 >      filePath = dirPath;
87 >      filePath += fname.Data();
88 >      //fwlite::ChainEvent to lop over events, jets, etc
89 >      fileNames.push_back(filePath.c_str());
90 >
91 >      if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1,
92 >                                                   treeName.c_str()) ) {
93 >        if(verbose)     cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl;
94 >      } else {
95 >        return -1;
96 >      }
97 >
98 >    }
99 >  } else
100 >    return -1;
101 >
102 >  for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) {
103 >
104 >    string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName());
105 >
106 >    string branch_alias = s;
107 >    string branch_name = s;
108 >    if (s.find(".", s.size()-1) != string::npos)
109 >      branch_name += "obj";
110 >
111 >    size_t a = s.find("_");
112 >    if (a != string::npos) {
113 >      size_t b = s.find("_", a+1);
114 >      if (b != string::npos) {
115 >        size_t c = s.find("_", b+1);
116 >        if (c != string::npos) {
117 >          string _prod     =s.substr(0,a);
118 >          string _label    =s.substr(a+1, b-a-1);
119 >          string _instance =s.substr(b+1, c-b-1);
120 >          branch_alias = _label;
121 >          if(_instance.length() > 0 )  {
122 >            branch_alias += "_";
123 >            branch_alias += _instance;
124 >            ((TChain*) this->At(currChain))->SetAlias(_instance.c_str(),
125 >                                                      branch_name.c_str());
126 >          }
127 >          string branch_alias_full = _prod + "_" + branch_alias;
128 >          ((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(),
129 >                                                    branch_name.c_str());
130 >        }
131 >      }
132 >    }
133  
134 <                string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName());
134 >    ((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),
135 >                                              branch_name.c_str());
136  
137 <                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());
137 >  }
138  
106        }
139  
108        // add branch with track  Jets
140  
141 <        if( addTrackJets ) {
141 >
142 >    
143 >  string friendTreeName("friendTree");
144  
145 <          //make file for tree friends (adding additional, computed branches)
146 <          string friendFileName("/scratch/hh/current/cms/user/");
147 <          friendFileName += gSystem->GetUserInfo()->fUser;
148 <          friendFileName += "/temp/",
149 <          friendFileName += fileName;
150 <          friendFileName += ".root";
151 <          TFile *f = new TFile(friendFileName.c_str(),"recreate");
152 <
153 <          if( f->IsZombie() ) return -1;
154 <
155 <          string friendTreeName("friendTree");
156 <          //char number = currChain;
157 <          //friendTreeName += number;
158 <          //TTree *friendTree = new TTree("friendTree","friendTree");
159 <          TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str());
160 <
161 <          int nJetsKT;
162 <          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();
145 >  string friendFileName("/scratch/hh/current/cms/user/");
146 >  friendFileName += gSystem->GetUserInfo()->fUser;
147 >  friendFileName += "/temp/";
148 >  friendFileName += fileLabel;
149 >  friendFileName += ".root";
150 >  string fileOpt = "update";
151 >  if( recreateTree )    fileOpt = "recreate";
152 >
153 >  FWliteVariables fwVars(friendTreeName, friendFileName, fileOpt);
154 >
155 >  if(varBlockNames.length() > 1 ) {
156 >    fwVars.loop(fileNames, varBlockNames);
157 >    if(verbose)   cout<<"add friend tree with additional variables: "<<varBlockNames<<endl;
158 >    ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
159 >                                               friendFileName.c_str());
160 >  } else {
161 >    if(verbose)   cout<<"No additional variables added."<<endl;
162 >  }
163  
164 <            if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl;
164 >  
165 >    
166  
171          }
172          f->cd();
173          friendTree->Write();
174          f->Close();
175          ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
176                                                     friendFileName.c_str());
177        }
167  
168 <        timer.Stop();
169 <        if(verbose) timer.Print();
168 >  timer.Stop();
169 >  if(verbose) timer.Print();
170        
171 <        return this->GetEntries();
171 >  return this->GetEntries();
172  
173   }
174   //------------------------------------------------------------------
# Line 191 | Line 180 | int PlotTool::plot(int chainIndex, strin
180                  return -1;
181  
182          TStopwatch timer;
183 <        timer.Start();
183 >        if(verbose) {
184 >          cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl;
185 >          timer.Start();
186 >        }
187  
188          int currN = nEntries;
189          if (nEntries < 0)
# Line 240 | Line 232 | int PlotTool::plot(int chainIndex, strin
232  
233          if ( !pads_[currPadName.str()] || !gROOT->GetListOfCanvases()->FindObject(currPadName.str().c_str()) ) {
234                  pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str());
235 <                if (logY)
236 <                        pads_[currPadName.str()]->SetLogy(1);
235 >                //              if (logY)
236 >                //                      pads_[currPadName.str()]->SetLogy(1);
237          } else {
238                  pads_[currPadName.str()]->cd();
239                  currOpt += "SAMES";
# Line 252 | Line 244 | int PlotTool::plot(int chainIndex, strin
244  
245  
246          //Draw histogram:
247 <        int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(),
247 >        string cutNameWithGlobal = cutName;
248 >        if(cutName!="" && globalCuts!="")    cutNameWithGlobal += "&&";
249 >        if(globalCuts!="")                   cutNameWithGlobal += globalCuts;
250 >
251 >        int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutNameWithGlobal.c_str(),
252                          currOpt.c_str(), currN);
253          if (draw_err < 0)
254                  return draw_err;
# Line 275 | Line 271 | int PlotTool::plot(int chainIndex, strin
271  
272          // Update for 2D histograms
273          if( pads_[currPadName.str()]->GetPrimitive(currHistName.str().c_str())->InheritsFrom("TH2") ) {
278
274                          pads_[currPadName.str()]->Draw();
275                          setCanvas( pads_[currPadName.str()] );
276          }
277  
278 <        timer.Stop();
279 <        if(verbose) {
280 <          cout<<"Done: "<<currN<<" events in "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl;
278 >
279 >        if(verbose && draw_err > 0) {
280 >          timer.Stop();
281 >          cout<<"Done: Selected "<<draw_err<<" objects in "<< currN <<" processed events."<<endl;
282            timer.Print();
283          }
284          return draw_err;
# Line 366 | Line 362 | int PlotTool::loop(string histName, vect
362   int PlotTool::updatePads() {
363  
364          for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) {
365 <                if (gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) {
366 <                        (*it).second->Draw();
367 <                        setCanvas((*it).second);
368 <                } else
369 <                        pads_.erase(it);
365 >                if ( ! gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) {
366 >                  pads_.erase(it);
367 >                  continue;
368 >                }
369 >                if( (*it).second->GetListOfPrimitives()->GetEntries() == 0 ) {
370 >                  (*it).second->Close();
371 >                  pads_.erase(it);
372 >                  continue;
373 >                }
374 >                (*it).second->Draw();
375 >                setCanvas((*it).second);
376 >
377          }
378  
379          return pads_.size();
# Line 515 | Line 518 | void PlotTool::setMathLabels(TH1* thisHi
518          string x = thisHist->GetXaxis()->GetTitle();
519          string y = thisHist->GetYaxis()->GetTitle();
520  
521 <        if (t.find(".phi()") != string::npos)
522 <                t.replace(t.find(".phi()"), 6, " #phi");
521 > //      if (x.find("__") != string::npos)
522 > //        x = x.substr(0,x.find("__"));
523 > //      if (y.find("__") != string::npos)
524 > //        y = y.substr(0,y.find("__"));
525 >
526          if (x.find(".phi()") != string::npos)
527                  x.replace(x.find(".phi()"), 6, " #phi");
528          if (y.find(".phi()") != string::npos)
529                  y.replace(y.find(".phi()"), 6, " #phi");
530  
525        if (t.find(".eta()") != string::npos)
526                t.replace(t.find(".eta()"), 6, " #eta");
531          if (x.find(".eta()") != string::npos)
532                  x.replace(x.find(".eta()"), 6, " #eta");
533          if (y.find(".eta()") != string::npos)
534                  y.replace(y.find(".eta()"), 6, " #eta");
535  
536 <        if (t.find(".pt()") != string::npos)
537 <                t.replace(t.find(".pt()"), 5, " p_{T}");
536 >        if (x.find(".theta()") != string::npos)
537 >                x.replace(x.find(".theta()"), 6, " #theta");
538 >        if (y.find(".theta()") != string::npos)
539 >                y.replace(y.find(".theta()"), 6, " #theta");
540 >
541 >        if (x.find(".chi2()") != string::npos)
542 >                x.replace(x.find(".chi2()"), 7, " #chi^{2}");
543 >        if (y.find(".chi2()") != string::npos)
544 >                y.replace(y.find(".chi2()"), 7, " #chi^{2}");
545 >
546          if (x.find(".pt()") != string::npos)
547 <                x.replace(x.find(".pt()"), 5, " p_{T}");
547 >                x.replace(x.find(".pt()"), 5, " p_{T} [GeV]");
548          if (y.find(".pt()") != string::npos)
549 <                y.replace(y.find(".pt()"), 5, " p_{T}");
549 >                y.replace(y.find(".pt()"), 5, " p_{T} [GeV]");
550 >
551 >        if (x.find(".et()") != string::npos)
552 >                x.replace(x.find(".et()"), 5, " E_{T} [GeV]");
553 >        if (y.find(".et()") != string::npos)
554 >                y.replace(y.find(".et()"), 5, " E_{T} [GeV]");
555 >
556 >        //splitlines for many cuts
557 >        string test1= "{" + globalCuts + "}";
558 >        string test2= "&&" + globalCuts;
559 >
560 >        if(t.find(test1) != string::npos) t.replace(t.find(test1),test1.length(),"");
561 >        if(t.find(test2) != string::npos) t.replace(t.find(test2),test2.length(),"");
562 >
563 >        if (t.find("{") != string::npos && t.find("#splitline") == string::npos) {
564 >          t.replace(t.find_last_of("{"), 1, "}{");
565 >          string t_old = t;
566 >          t = "#splitline{";
567 >          t +=  t_old;
568 >        }
569  
570          thisHist ->SetTitle(t.c_str());
571          thisHist->GetXaxis()->SetTitle(x.c_str());
# Line 652 | Line 683 | void PlotTool::createColors() {
683  
684   //------------------------------------------------------------------
685  
686 < int PlotTool::saveCanvases(string type, string path) {
686 > int PlotTool::saveCanvases(string name, string path) {
687  
688          TSystemDirectory d("", path.c_str());
689          if (!d.GetListOfFiles())
690                  return -1;
660        if (type.find(".") == string::npos)
661                return -1;
691  
692 <        int savedFiles =0;
692 >        string namePs = path +"/" + name;
693 >        string nameRt = path +"/" + name;
694 >
695 >        if (name.find(".ps") == string::npos)
696 >                namePs += ".ps";
697 >
698 >        if (name.find(".root") == string::npos)
699 >                nameRt += ".root";
700 >
701 >        int savedCanvs =0;
702 >
703  
704          TIter next(gROOT->GetListOfCanvases());
705          TCanvas* canv;
706          while ((canv=(TCanvas*)next())) {
707 <
708 <                string s = "";
709 <                s += path;
671 <                s += canv->GetName();
672 <                s += type;
673 <
674 <                canv->SaveAs(s.c_str());
675 <                ++savedFiles;
707 >          string modName = (*canv).GetName();
708 >          if(modName.find("{") != string::npos) modName = modName.substr(0,modName.find("{"));
709 >          (*canv).SetTitle( modName.c_str() );
710  
711          }
712  
679        return savedFiles;
713  
714 < }
715 < //------------------------------------------------------------------
683 < void PlotTool::showChainInfo()
684 < {
714 >        TPostScript ps(namePs.c_str(),112);
715 >        TFile rt(nameRt.c_str(),"recreate");
716  
717 +        next.Reset();
718 +        while ((canv=(TCanvas*)next())) {
719 +          ps.NewPage();
720  
687  cout<<endl;
688  cout<<"****** Show Chain Information:"<<endl;
721  
722 +          (*canv).Write();
723 +          (*canv).Draw();
724 +          (*canv).Update();
725  
691  this->ls();
726  
727 <  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();
727 >          ++savedCanvs;
728  
729          }
730  
731 +        ps.Close();
732 +        rt.Close();
733  
734  
735 +        if(verbose && savedCanvs) {
736 +          cout<<"Saved file "<<rt.GetName()<<" with "<<savedCanvs<<" canvases."<<endl;
737 +          cout<<"Saved file "<<ps.GetName()<<" with "<<savedCanvs<<" pages."<<endl;
738   }
739 < //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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 <  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 <
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 <  //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;
739 >        return savedCanvs;
740  
741 + }
742 + //------------------------------------------------------------------
743  
744 <  TFile file("ABCDFunctions.root","UPDATE");
745 <  TF1* savefunc = new TF1(savefuncName.str().c_str(), fitfunc->GetExpFormula().Data(),0,10000);
829 <  savefunc->SetParameters( fitfunc->GetParameters() );
830 <  savefunc->SetParErrors ( fitfunc->GetParErrors() );
744 > int PlotTool::clearCanvases()
745 > {
746  
747 <  //Show results
748 <  if( ! pads_["abcd"] || ! gROOT->FindObject("abcd") ) {
749 <    pads_["abcd"] = new TCanvas("abcd", "abcd");
750 <  } else {
836 <    pads_["abcd"]->cd();
837 <  }
747 >  while(gROOT->GetListOfCanvases()->GetEntries()) ((TCanvas*) gROOT->GetListOfCanvases()->At(0))->Close();
748 >  pads_.clear();
749 >  autoVars.clear();
750 >  return pads_.size() + gROOT->GetListOfCanvases()->GetEntries();
751  
752 <  bkg->Multiply(savefunc);
753 <  bkg->Draw();
752 > }
753 > //------------------------------------------------------------------
754 > int PlotTool::setVariables(string label)
755 > {
756  
757 <  //  total->Add(bkg,-1);
758 <  pass->SetLineColor(kRed);
759 <  pass->Draw("sames,e");
760 <  pads_["abcd"]->SetLogy();
757 >        for (int i=0; i< this->GetEntries(); ++i) {
758 >          cout<<"--------------------------------"<<endl;
759 >          cout<<((TChain*) this->At(i))->GetName()<<endl;
760 >          cout<<"------------"<<endl;
761  
762 +          TList* leaves = (TList*) ((TChain*) this->At(i))->GetListOfLeaves();
763 +          for (int j=0; j< leaves->GetEntries(); ++j) {
764 +            TString leafName ( leaves->At(j)->GetName() );
765 +            if(! leafName.EndsWith(".") ) continue;
766 +            if(! leafName.Contains(label.c_str() ) ) continue;
767 +
768 +            TClass cl( ( (TLeafElement*) leaves->At(j) )->GetTypeName() );
769 +            cout<<"++++++"<<endl;
770 +            cout<< leafName.Data() <<endl;
771 +            for(int k=0;k<cl.GetListOfAllPublicMethods()->GetEntries();++k) {
772 +              string typeName ( ((TMethod*) cl.GetListOfAllPublicMethods()->At(k))->GetReturnTypeName() );
773 +              string methName ( cl.GetListOfAllPublicMethods()->At(k)->GetName() );
774 +              if( methName != "product") continue;
775 +                cout<< typeName <<endl;
776 +                string _type;
777 +                TString testString( typeName.c_str() );
778 +                if( testString.BeginsWith("vector<") ) {
779 +                  _type = typeName.substr(typeName.find("<")+1,typeName.find(">")-typeName.find("<")-1);
780 +                  string _varSize = leafName.Data();
781 +                  _varSize += "obj@.size()";
782 +                  autoVars.push_back( _varSize );
783 +                  }
784 +                else _type = typeName.substr(0,typeName.find("*"));
785 +                  TClass _cl( _type.c_str() );
786 +                  for(int l=0;l<_cl.GetListOfAllPublicMethods()->GetEntries();++l) {
787 +                    string _typeName ( ((TMethod*) _cl.GetListOfAllPublicMethods()->At(l))->GetReturnTypeName() );
788 +                    string _methName ( _cl.GetListOfAllPublicMethods()->At(l)->GetName() );
789 +                    //              if(_typeName.find("void") != string::npos ) continue;
790 +                    //              cout<<"   "<<_typeName<<"  "<<_methName<<endl;
791 +
792 +                    cout<<" "<<_typeName<<"  "<<_methName<<endl;
793 +                    if(_methName.find("operator")==string::npos&&(_typeName=="float"||_typeName=="double"||_typeName=="int"||_typeName=="unsigned int"||_typeName=="bool"||_typeName=="unsigned short"||_typeName=="unsigned long"||_typeName=="unsigned long long")) {
794 +
795 +                      cout<<"-->   "<<_typeName<<"  "<<_methName<<endl;
796 +
797 +                      string  _varName = leafName.Data();
798 +                      _varName += "obj.";
799 +                      _varName += _methName;
800 +                      _varName += "()";
801 +                      autoVars.push_back( _varName );
802 +                    }
803 +                  }
804 +                  
805 +              
806 +            }
807  
808 <  savefunc->Write();
849 <  //  file.Close();
808 >          }
809  
810 +        }
811  
812 <  return draw_err;
812 >        return autoVars.size();
813  
814   }
815 +
816   //------------------------------------------------------------------

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines