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.10 by tschum, Thu Dec 3 22:29:16 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;
32 <
33 <        TStopwatch timer;
34 <        timer.Start();
34 >  if (currChain < 0)
35 >    return currChain;
36  
37 +  TStopwatch timer;
38 +  timer.Start();
39  
37        fileNames.clear();
40  
41 <        //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());
41 >  fileNames.clear();
42  
43 <        TList *files = new TList();
44 <        TSystemFile* sysFile = 0;
45 <        if(fileName.find(".") != string::npos) {
46 <          ifstream f(fileName.c_str());
47 <          if( ! f.is_open() ) return -1;
50 <          string line;
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 <          while (!f.eof()) {
50 <            getline(f,line);
51 <            sysFile = new TSystemFile(line.c_str(),dirPath.c_str());
52 <            files->Add(sysFile);
53 <          }
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  
62  
63 <        } else {
64 <        TSystemDirectory dir("sourceDir", dirPath.c_str());
65 <        files = dir.GetListOfFiles();
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 <        if (files->GetEntries()>0) {
132 <                TIter next(files);
65 <                TSystemFile *file;
66 <                TString fname;
67 <                string filePath;
68 <
69 <                if(verbose && fileName.find(".") == string::npos )      cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: "
70 <                                <<fileName.c_str()<<endl;
71 <                if(verbose && fileName.find(".") != string::npos )      cout<<"Open"<<dirPath.c_str()<<" Search lines with .root in: "
72 <                                <<fileName.c_str()<<endl;
73 <
74 <
75 <                while ((file=(TSystemFile*)next())) {
76 <                        fname = file->GetName();
77 <                        if (!fname.EndsWith(".root"))
78 <                                continue;
79 <                        if (!fname.Contains(fileName.c_str()) && fileName.find(".") == string::npos )
80 <                                continue;
81 <
82 <                        filePath = dirPath;
83 <                        filePath += fname.Data();
84 <                        //fwlite::ChainEvent to lop over events, jets, etc
85 <                        fileNames.push_back(filePath.c_str());
86 <
87 <                        if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1,
88 <                                        treeName.c_str()) )
89 <                if(verbose)     cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl;
90 <                        else
91 <                                return -1;
92 <
93 <                }
94 <        } else
95 <                return -1;
131 >      }
132 >    }
133  
134 <        for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) {
134 >    ((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),
135 >                                              branch_name.c_str());
136  
137 <                string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName());
100 <
101 <                string branch_alias = s;
102 <                string branch_name = s;
103 <                if (s.find(".", s.size()-1) != string::npos)
104 <                        branch_name += "obj";
105 <
106 <                size_t a = s.find("_");
107 <                if (a != string::npos) {
108 <                  size_t b = s.find("_", a+1);
109 <                  if (b != string::npos) {
110 <                    size_t c = s.find("_", b+1);
111 <                    if (c != string::npos) {
112 <                      string _prod     =s.substr(0,a);
113 <                      string _label    =s.substr(a+1, b-a-1);
114 <                      string _instance =s.substr(b+1, c-b-1);
115 <                      branch_alias = _label;
116 <                      if(_instance.length() > 0 )  {
117 <                        branch_alias += "_";
118 <                        branch_alias += _instance;
119 <                        ((TChain*) this->At(currChain))->SetAlias(_instance.c_str(),
120 <                                                                  branch_name.c_str());
121 <                      }
122 <                      string branch_alias_full = _prod + "_" + branch_alias;
123 <                      ((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(),
124 <                                branch_name.c_str());
125 <                    }
126 <                  }
127 <                }
137 >  }
138  
129                ((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),
130                                branch_name.c_str());
139  
132        }
140  
141 <        // add branch with track  Jets
142 <
143 <        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];
156 <          fwlite::ChainEvent ev(fileNames);
157 <
158 <          friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I");
159 <          friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F");
160 <
161 <          if(verbose)   cout<<"calculating additional variables..."<<endl;
162 <          
163 <          
164 <
165 <          int tenth = ev.size() / 10;
166 <          int eventNum =0;
167 <          for (ev.toBegin(); !ev.atEnd(); ++ev, ++eventNum) {
168 <
169 <            fwlite::Handle<reco::CaloJetCollection> jets;
170 <            jets.getByLabel(ev, "antikt5CaloJets");
171 <
172 <            fwlite::Handle<reco::TrackCollection> tracks;
173 <            tracks.getByLabel(ev, "generalTracks");
174 <
175 <            if (!jets.isValid())
176 <              continue;
177 <            if (!tracks.isValid())
178 <              continue;
179 <            double trackSum;
180 <            nJetsKT = 0;
181 <            for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet
182 <                   !=jets->end(); jet++) {
183 <              trackSum = 0;
184 <              for (reco::TrackCollection::const_iterator track = tracks->begin(); track
185 <                     !=tracks->end(); track++) {
186 <                if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi())
187 <                    < 0.5)
188 <                  trackSum += track->pt();
189 <              }
190 <              TrackJetKT[nJetsKT] = trackSum;
191 <              nJetsKT++;
192 <            }
193 <            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  
197          }
198          f->cd();
199          friendTree->Write();
200          f->Close();
201          ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
202                                                     friendFileName.c_str());
203        }
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 217 | 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 278 | 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 305 | Line 275 | int PlotTool::plot(int chainIndex, strin
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 391 | 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 540 | 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  
550        if (t.find(".eta()") != string::npos)
551                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 694 | Line 700 | int PlotTool::saveCanvases(string name,
700  
701          int savedCanvs =0;
702  
697        TPostScript ps(namePs.c_str(),112);
698        TFile rt(nameRt.c_str(),"recreate");
703  
704          TIter next(gROOT->GetListOfCanvases());
705          TCanvas* canv;
706          while ((canv=(TCanvas*)next())) {
707 <          ps.NewPage();
708 <          (*canv).Draw();
709 <          (*canv).Update();
706 <          (*canv).Write();
707 <          ++savedCanvs;
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  
711        ps.Close();
712        rt.Close();
713  
714 <        return savedCanvs;
715 <
716 < }
717 < //------------------------------------------------------------------
718 < void PlotTool::showChainInfo()
719 < {
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  
722  cout<<endl;
723  cout<<"****** Show Chain Information:"<<endl;
721  
722 +          (*canv).Write();
723 +          (*canv).Draw();
724 +          (*canv).Update();
725  
726  this->ls();
726  
727 <  cout<<endl;
729 <  cout<<"We have "<<this->GetEntries()<<" TChains with following aliases set:"<<endl;
730 <        for (int i=0; i< this->GetEntries(); ++i) {
731 <          cout<<endl;
732 <          cout<<((TChain*) this->At(i))->GetName()<<endl;
733 <          ((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 < //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
741 < //Draw efficiencies
742 < int  PlotTool::plotEff(int chainIndex, string histName, string cutName, int nEntries, double fitXmin, double fitXmax, string fitFormula)
743 < {
744 <
745 <  if( chainIndex >= this->GetEntries() ) return -1;
746 <
747 <  int currN = nEntries;
748 <  if(nEntries < 0) currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted!
749 <
750 <  //++++ Create and name Canvases according to global variables +++++++++++++
751 <  ostringstream currHistName;
752 <  if( samePad_trees) currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":";
753 <  if( samePad_vars)  currHistName<<histName;
754 <  if( samePad_cuts)  currHistName<<"{"<<cutName<<"}";
755 <
756 <  ostringstream currPadName;
757 <  if(! samePad_trees) currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":";
758 <  if(! samePad_vars)  currPadName<<histName;
759 <  if(! samePad_cuts)  currPadName<<"{"<<cutName<<"}";
760 <
761 <
762 <  //Draw total histogram:
763 <  if( ! pads_["total"] || ! gROOT->FindObject("total") ) {
764 <    pads_["total"] = new TCanvas("total", "total");
765 <  } else {
766 <    pads_["total"]->cd();
767 <  }
768 <  ostringstream bins_total;
769 <  bins_total<<histName;
770 <  bins_total<<">>total(100,0,1000)";
771 <
772 <
773 <  int draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_total.str().c_str(), "", "", currN);
774 <  if( draw_err <= 0 ) return draw_err;
775 <
776 <
777 <  TH1* total = ((TH1*) pads_["total"]->GetPrimitive("total"));
778 <
779 <  ostringstream bins_bkg;
780 <  bins_bkg<<histName;
781 <  bins_bkg<<">>bkg(";
782 <  bins_bkg<<total->GetNbinsX();
783 <  bins_bkg<<",";
784 <  bins_bkg<<total->GetXaxis()->GetXmin();
785 <  bins_bkg<<",";
786 <  bins_bkg<<total->GetXaxis()->GetXmax();
787 <  bins_bkg<<")";
788 <
789 <  //Draw bkg histogram:
790 <  if( ! pads_["bkg"] || ! gROOT->FindObject("bkg") ) {
791 <    pads_["bkg"] = new TCanvas("bkg", currPadName.str().c_str());
792 <  } else {
793 <    pads_["bkg"]->cd();
794 <  }
795 <
796 <  draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_bkg.str().c_str(), cutName.c_str(),"" , currN);
797 <  if( draw_err <= 0 ) return draw_err;
798 <
799 <
800 <  TH1* bkg = ((TH1*) pads_["bkg"]->GetPrimitive("bkg"));
801 <
802 <  //Draw pass histogram:
803 <  ostringstream bins_pass;
804 <  bins_pass<<histName;
805 <  bins_pass<<">>pass(";
806 <  bins_pass<<total->GetNbinsX();
807 <  bins_pass<<",";
808 <  bins_pass<<total->GetXaxis()->GetXmin();
809 <  bins_pass<<",";
810 <  bins_pass<<total->GetXaxis()->GetXmax();
811 <  bins_pass<<")";
812 <
813 <  ostringstream cut_pass;
814 <  cut_pass<<"!(";
815 <  cut_pass<<cutName;
816 <  cut_pass<<")";
817 <  
818 <
819 <  if( ! pads_["pass"] || ! gROOT->FindObject("pass") ) {
820 <    pads_["pass"] = new TCanvas("pass", currPadName.str().c_str());
821 <  } else {
822 <    pads_["pass"]->cd();
823 <  }
824 <
825 <  draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_pass.str().c_str(),cut_pass.str().c_str() ,"" , currN);
826 <  if( draw_err <= 0 ) return draw_err;
827 <
828 <
829 <  TH1* pass = ((TH1*) pads_["pass"]->GetPrimitive("pass"));
830 <
831 <
832 <  currPadName<<"Eff";
833 <  //Draw Efficiency Graph:
834 <  if( ! pads_["EffGraph"] || ! gROOT->FindObject("EffGraph") ) {
835 <    pads_["EffGraph"] = new TCanvas("EffGraph", currPadName.str().c_str());
836 <  } else {
837 <    pads_["EffGraph"]->cd();
838 <  }
839 <
840 <  TGraphAsymmErrors* EffGraph = new TGraphAsymmErrors(bkg, total);
841 <  EffGraph->SetName(currHistName.str().c_str());
842 <
843 <  TF1* reverse = new TF2("reverse","1/y-1",total->GetXaxis()->GetXmin(),total->GetXaxis()->GetXmax());
844 <  EffGraph->Apply(reverse);
845 <  EffGraph->Draw("A*");
846 <
847 <  TF1* fitfunc = new TF1("fitfunc",fitFormula.c_str(),fitXmin,fitXmax);
848 <  EffGraph->Fit("fitfunc","R+");
849 <
850 <
851 <  //Save fit function
852 <
853 <  ostringstream savefuncName;
854 <  savefuncName<<histName;
855 <  savefuncName<<"_";
739 >        return savedCanvs;
740  
741 <  if(cutName.find("<") != std::string::npos ) cutName.replace(cutName.find("<"),1,"_");
742 <  if(cutName.find(">") != std::string::npos ) cutName.replace(cutName.find(">"),1,"_");
859 <  savefuncName<<cutName;
741 > }
742 > //------------------------------------------------------------------
743  
744 + int PlotTool::clearCanvases()
745 + {
746  
747 <  TFile file("ABCDFunctions.root","UPDATE");
748 <  TF1* savefunc = new TF1(savefuncName.str().c_str(), fitfunc->GetExpFormula().Data(),0,10000);
749 <  savefunc->SetParameters( fitfunc->GetParameters() );
750 <  savefunc->SetParErrors ( fitfunc->GetParErrors() );
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 <  //Show results
753 <  if( ! pads_["abcd"] || ! gROOT->FindObject("abcd") ) {
754 <    pads_["abcd"] = new TCanvas("abcd", "abcd");
755 <  } else {
871 <    pads_["abcd"]->cd();
872 <  }
873 <
874 <  bkg->Multiply(savefunc);
875 <  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();
884 <  //  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