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.7 by tschum, Fri Nov 27 17:39:46 2009 UTC vs.
Revision 1.12 by tschum, Tue Dec 8 10:04:35 2009 UTC

# Line 14 | Line 14 | PlotTool::PlotTool() {
14  
15          showLegend = false;
16          logY = true;
17 <        addTrackJets = true;
17 >        addTrackJets = false;
18 >        verbose = true;
19 >
20 >        globalCuts="";
21  
22   }
23  
# Line 29 | Line 32 | int PlotTool::init(string fileName, stri
32          if (currChain < 0)
33                  return currChain;
34  
35 +        TStopwatch timer;
36 +        timer.Start();
37 +
38 +
39          fileNames.clear();
40  
41          //check if alternative label is different from default(searchString)
# Line 36 | Line 43 | int PlotTool::init(string fileName, stri
43                  fileLabel=fileName;
44          }
45          ((TChain*) this->At(currChain))->SetName(fileLabel.c_str());
46 +
47 +        TList *files = new TList();
48 +        TSystemFile* sysFile = 0;
49 +        if(fileName.find(".") != string::npos) {
50 +          ifstream f(fileName.c_str());
51 +          if( ! f.is_open() ) return -1;
52 +          string line;
53 +
54 +          while (!f.eof()) {
55 +            getline(f,line);
56 +            sysFile = new TSystemFile(line.c_str(),dirPath.c_str());
57 +            files->Add(sysFile);
58 +          }
59 +
60 +
61 +        } else {
62          TSystemDirectory dir("sourceDir", dirPath.c_str());
63 <        TList *files = dir.GetListOfFiles();
64 <        if (files) {
63 >        files = dir.GetListOfFiles();
64 >        }
65 >        if (files->GetEntries()>0) {
66                  TIter next(files);
67                  TSystemFile *file;
68                  TString fname;
69                  string filePath;
70  
71 <                cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: "
71 >                if(verbose && fileName.find(".") == string::npos )      cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: "
72 >                                <<fileName.c_str()<<endl;
73 >                if(verbose && fileName.find(".") != string::npos )      cout<<"Open"<<dirPath.c_str()<<" Search lines with .root in: "
74                                  <<fileName.c_str()<<endl;
75  
76 +
77                  while ((file=(TSystemFile*)next())) {
78                          fname = file->GetName();
79                          if (!fname.EndsWith(".root"))
80                                  continue;
81 <                        if (!fname.Contains(fileName.c_str()))
81 >                        if (!fname.Contains(fileName.c_str()) && fileName.find(".") == string::npos )
82                                  continue;
83  
84                          filePath = dirPath;
# Line 61 | Line 88 | int PlotTool::init(string fileName, stri
88  
89                          if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1,
90                                          treeName.c_str()) )
91 <                                cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl;
91 >                if(verbose)     cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl;
92                          else
93                                  return -1;
94  
# Line 84 | Line 111 | int PlotTool::init(string fileName, stri
111                    if (b != string::npos) {
112                      size_t c = s.find("_", b+1);
113                      if (c != string::npos) {
114 +                      string _prod     =s.substr(0,a);
115                        string _label    =s.substr(a+1, b-a-1);
116                        string _instance =s.substr(b+1, c-b-1);
117                        branch_alias = _label;
118                        if(_instance.length() > 0 )  {
119                          branch_alias += "_";
120                          branch_alias += _instance;
121 +                        ((TChain*) this->At(currChain))->SetAlias(_instance.c_str(),
122 +                                                                  branch_name.c_str());
123                        }
124 +                      string branch_alias_full = _prod + "_" + branch_alias;
125 +                      ((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(),
126 +                                branch_name.c_str());
127                      }
128                    }
129                  }
# Line 105 | Line 138 | int PlotTool::init(string fileName, stri
138          if( addTrackJets ) {
139  
140            //make file for tree friends (adding additional, computed branches)
141 <          string friendFileName("/scratch/hh/lustre/cms/user/thomsen/temp/");
141 >          string friendFileName("/scratch/hh/current/cms/user/");
142 >          friendFileName += gSystem->GetUserInfo()->fUser;
143 >          friendFileName += "/temp/",
144            friendFileName += fileName;
145            friendFileName += ".root";
146            TFile *f = new TFile(friendFileName.c_str(),"recreate");
147 +
148 +          if( f->IsZombie() ) return -1;
149 +
150            string friendTreeName("friendTree");
151            //char number = currChain;
152            //friendTreeName += number;
# Line 122 | Line 160 | int PlotTool::init(string fileName, stri
160            friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I");
161            friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F");
162  
163 <          cout<<"calculating additional variables..."<<endl;
164 <          for (ev.toBegin(); !ev.atEnd(); ++ev) {
163 >          if(verbose)   cout<<"calculating additional variables..."<<endl;
164 >          
165 >          
166 >
167 >          int tenth = ev.size() / 10;
168 >          int eventNum =0;
169 >          for (ev.toBegin(); !ev.atEnd(); ++ev, ++eventNum) {
170  
171              fwlite::Handle<reco::CaloJetCollection> jets;
172              jets.getByLabel(ev, "antikt5CaloJets");
# Line 150 | Line 193 | int PlotTool::init(string fileName, stri
193                nJetsKT++;
194              }
195              friendTree->Fill();
196 +
197 +            if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl;
198 +
199            }
200            f->cd();
201            friendTree->Write();
# Line 157 | Line 203 | int PlotTool::init(string fileName, stri
203            ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
204                                                       friendFileName.c_str());
205          }
206 +
207 +        timer.Stop();
208 +        if(verbose) timer.Print();
209 +      
210          return this->GetEntries();
211  
212   }
# Line 168 | Line 218 | int PlotTool::plot(int chainIndex, strin
218          if (chainIndex >= this->GetEntries() )
219                  return -1;
220  
221 +        TStopwatch timer;
222 +        if(verbose) {
223 +          cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl;
224 +          timer.Start();
225 +        }
226 +
227          int currN = nEntries;
228          if (nEntries < 0)
229                  currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted!
# Line 215 | Line 271 | int PlotTool::plot(int chainIndex, strin
271  
272          if ( !pads_[currPadName.str()] || !gROOT->GetListOfCanvases()->FindObject(currPadName.str().c_str()) ) {
273                  pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str());
274 <                if (logY)
275 <                        pads_[currPadName.str()]->SetLogy(1);
274 >                //              if (logY)
275 >                //                      pads_[currPadName.str()]->SetLogy(1);
276          } else {
277                  pads_[currPadName.str()]->cd();
278                  currOpt += "SAMES";
# Line 227 | Line 283 | int PlotTool::plot(int chainIndex, strin
283  
284  
285          //Draw histogram:
286 <        int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(),
286 >        string cutNameWithGlobal = cutName;
287 >        if(cutName!="" && globalCuts!="")    cutNameWithGlobal += "&&";
288 >        if(globalCuts!="")                   cutNameWithGlobal += globalCuts;
289 >
290 >        int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutNameWithGlobal.c_str(),
291                          currOpt.c_str(), currN);
292          if (draw_err < 0)
293                  return draw_err;
# Line 248 | Line 308 | int PlotTool::plot(int chainIndex, strin
308  
309          ((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram
310  
311 +        // Update for 2D histograms
312 +        if( pads_[currPadName.str()]->GetPrimitive(currHistName.str().c_str())->InheritsFrom("TH2") ) {
313 +                        pads_[currPadName.str()]->Draw();
314 +                        setCanvas( pads_[currPadName.str()] );
315 +        }
316 +
317  
318 +        if(verbose && draw_err > 0) {
319 +          timer.Stop();
320 +          cout<<"Done: Selected "<<draw_err<<" of total "<< currN <<" events."<<endl;
321 +          timer.Print();
322 +        }
323          return draw_err;
324  
325   }
# Line 268 | Line 339 | int PlotTool::loop(vector<string> _histN
339                                                  != _cutName.end(); ++it2) {
340  
341                                          numProcessed += plot(i, *it1, *it2, nEntries, drwOpt);
342 <                                        updatePads();
342 >                                
343  
344                                  }
345                          }
# Line 289 | Line 360 | int PlotTool::loop(vector<string> _histN
360                  }
361          }
362  
363 <        //  updatePads();
363 >        updatePads();
364          fillCanvases();
365  
366          return numProcessed;
# Line 345 | Line 416 | int PlotTool::fillCanvases() {
416  
417          for (map< string, TCanvas* >::iterator it=canvases_.begin() ; it
418                          != canvases_.end(); ++it) {
419 <                const char* canvName = (*it).first.c_str();
420 <                if (gROOT->GetListOfCanvases()->FindObject(canvName) ) {
419 >                string canvName = (*it).first;
420 >                if (gROOT->GetListOfCanvases()->FindObject(canvName.c_str()) ) {
421  
422                          int numP = (*it).second->GetNumber()+1;
423  
# Line 364 | Line 435 | int PlotTool::fillCanvases() {
435                                  y += 1;
436                          }
437  
438 +
439                          (*it).second->Divide(x, y);
440                          int padIndex = 1;
441                          for (map< string, TCanvas* >::iterator it2=pads_.begin() ; it2
442                                          != pads_.end(); ++it2) {
443                                  string padName = (*it2).first;
444                                  if (gROOT->GetListOfCanvases()->FindObject(padName.c_str() ) ) {
445 <                                        if ( (padName.find(canvName) != string::npos ) || !strcmp(
446 <                                                        canvName, "All") ) {
445 >                string n1 = canvName.substr(0,canvName.find(":"));
446 >                string n2("");
447 >                if(canvName.find("{") != string::npos ) n2 = canvName.substr(canvName.find("{"),canvName.find("}"));
448 >
449 >                if ( (padName.find(canvName.c_str()) != string::npos ) || (padName.find(n1) != string::npos && padName.find(n2) != string::npos) || !strcmp( canvName.c_str(), "All") ) {
450                                                  (*it).second->cd(padIndex);
451                                                  (*it2).second->DrawClonePad();
452                                                  (*it2).second->Close();
# Line 475 | Line 550 | void PlotTool::setMathLabels(TH1* thisHi
550          string x = thisHist->GetXaxis()->GetTitle();
551          string y = thisHist->GetYaxis()->GetTitle();
552  
553 <        if (t.find(".phi()") != string::npos)
554 <                t.replace(t.find(".phi()"), 6, " #phi");
553 > //      if (x.find("__") != string::npos)
554 > //        x = x.substr(0,x.find("__"));
555 > //      if (y.find("__") != string::npos)
556 > //        y = y.substr(0,y.find("__"));
557 >
558          if (x.find(".phi()") != string::npos)
559                  x.replace(x.find(".phi()"), 6, " #phi");
560          if (y.find(".phi()") != string::npos)
561                  y.replace(y.find(".phi()"), 6, " #phi");
562  
485        if (t.find(".eta()") != string::npos)
486                t.replace(t.find(".eta()"), 6, " #eta");
563          if (x.find(".eta()") != string::npos)
564                  x.replace(x.find(".eta()"), 6, " #eta");
565          if (y.find(".eta()") != string::npos)
566                  y.replace(y.find(".eta()"), 6, " #eta");
567  
568 <        if (t.find(".pt()") != string::npos)
569 <                t.replace(t.find(".pt()"), 5, " p_{T}");
568 >        if (x.find(".theta()") != string::npos)
569 >                x.replace(x.find(".theta()"), 6, " #theta");
570 >        if (y.find(".theta()") != string::npos)
571 >                y.replace(y.find(".theta()"), 6, " #theta");
572 >
573 >        if (x.find(".chi2()") != string::npos)
574 >                x.replace(x.find(".chi2()"), 7, " #chi^{2}");
575 >        if (y.find(".chi2()") != string::npos)
576 >                y.replace(y.find(".chi2()"), 7, " #chi^{2}");
577 >
578          if (x.find(".pt()") != string::npos)
579 <                x.replace(x.find(".pt()"), 5, " p_{T}");
579 >                x.replace(x.find(".pt()"), 5, " p_{T} [GeV]");
580          if (y.find(".pt()") != string::npos)
581 <                y.replace(y.find(".pt()"), 5, " p_{T}");
581 >                y.replace(y.find(".pt()"), 5, " p_{T} [GeV]");
582 >
583 >        if (x.find(".et()") != string::npos)
584 >                x.replace(x.find(".et()"), 5, " E_{T} [GeV]");
585 >        if (y.find(".et()") != string::npos)
586 >                y.replace(y.find(".et()"), 5, " E_{T} [GeV]");
587 >
588 >        //splitlines for many cuts
589 >        string test1= "{" + globalCuts + "}";
590 >        string test2= "&&" + globalCuts;
591 >
592 >        if(t.find(test1) != string::npos) t.replace(t.find(test1),test1.length(),"");
593 >        if(t.find(test2) != string::npos) t.replace(t.find(test2),test2.length(),"");
594 >
595 >        if (t.find("{") != string::npos && t.find("#splitline") == string::npos) {
596 >          t.replace(t.find_last_of("{"), 1, "}{");
597 >          string t_old = t;
598 >          t = "#splitline{";
599 >          t +=  t_old;
600 >        }
601  
602          thisHist ->SetTitle(t.c_str());
603          thisHist->GetXaxis()->SetTitle(x.c_str());
# Line 612 | Line 715 | void PlotTool::createColors() {
715  
716   //------------------------------------------------------------------
717  
718 < int PlotTool::saveCanvases(string type, string path) {
718 > int PlotTool::saveCanvases(string name, string path) {
719  
720          TSystemDirectory d("", path.c_str());
721          if (!d.GetListOfFiles())
722                  return -1;
620        if (type.find(".") == string::npos)
621                return -1;
723  
724 <        int savedFiles =0;
724 >        string namePs = path +"/" + name;
725 >        string nameRt = path +"/" + name;
726 >
727 >        if (name.find(".ps") == string::npos)
728 >                namePs += ".ps";
729 >
730 >        if (name.find(".root") == string::npos)
731 >                nameRt += ".root";
732 >
733 >        int savedCanvs =0;
734 >
735  
736          TIter next(gROOT->GetListOfCanvases());
737          TCanvas* canv;
738          while ((canv=(TCanvas*)next())) {
739 +          string modName = (*canv).GetName();
740 +          if(modName.find("{") != string::npos) modName = modName.substr(0,modName.find("{"));
741 +          (*canv).SetTitle( modName.c_str() );
742 +
743 +        }
744 +
745  
746 <                string s = "";
747 <                s += path;
631 <                s += canv->GetName();
632 <                s += type;
746 >        TPostScript ps(namePs.c_str(),112);
747 >        TFile rt(nameRt.c_str(),"recreate");
748  
749 <                canv->SaveAs(s.c_str());
750 <                ++savedFiles;
749 >        next.Reset();
750 >        while ((canv=(TCanvas*)next())) {
751 >          ps.NewPage();
752 >
753 >
754 >          (*canv).Write();
755 >          (*canv).Draw();
756 >          (*canv).Update();
757 >
758 >
759 >          ++savedCanvs;
760  
761          }
762  
763 <        return savedFiles;
763 >        ps.Close();
764 >        rt.Close();
765 >
766  
767 +        if(verbose && savedCanvs) {
768 +          cout<<"Saved file "<<rt.GetName()<<" with "<<savedCanvs<<" canvases."<<endl;
769 +          cout<<"Saved file "<<ps.GetName()<<" with "<<savedCanvs<<" pages."<<endl;
770   }
771 < //------------------------------------------------------------------
643 < void PlotTool::showChainInfo()
644 < {
771 >        return savedCanvs;
772  
773 + }
774 + //------------------------------------------------------------------
775  
776 <  cout<<endl;
777 <  cout<<"****** Show Chain Information:"<<endl;
776 > int PlotTool::clearCanvases()
777 > {
778  
779 +  while(gROOT->GetListOfCanvases()->GetEntries()) ((TCanvas*) gROOT->GetListOfCanvases()->At(0))->Close();
780 +  pads_.clear();
781 +  autoVars.clear();
782 +  return pads_.size() + gROOT->GetListOfCanvases()->GetEntries();
783  
784 <  this->ls();
784 > }
785 > //------------------------------------------------------------------
786 > int PlotTool::setVariables(string label)
787 > {
788  
653  cout<<endl;
654  cout<<"We have "<<this->GetEntries()<<" TChains with following aliases set:"<<endl;
789          for (int i=0; i< this->GetEntries(); ++i) {
790 <          cout<<endl;
790 >          cout<<"--------------------------------"<<endl;
791            cout<<((TChain*) this->At(i))->GetName()<<endl;
792 <          ((TChain*) this->At(i))->GetListOfAliases()->ls();
792 >          cout<<"------------"<<endl;
793 >
794 >          TList* leaves = (TList*) ((TChain*) this->At(i))->GetListOfLeaves();
795 >          for (int j=0; j< leaves->GetEntries(); ++j) {
796 >            TString leafName ( leaves->At(j)->GetName() );
797 >            if(! leafName.EndsWith(".") ) continue;
798 >            if(! leafName.Contains(label.c_str() ) ) continue;
799 >
800 >            TClass cl( ( (TLeafElement*) leaves->At(j) )->GetTypeName() );
801 >            cout<<"++++++"<<endl;
802 >            cout<< leafName.Data() <<endl;
803 >            for(int k=0;k<cl.GetListOfAllPublicMethods()->GetEntries();++k) {
804 >              string typeName ( ((TMethod*) cl.GetListOfAllPublicMethods()->At(k))->GetReturnTypeName() );
805 >              string methName ( cl.GetListOfAllPublicMethods()->At(k)->GetName() );
806 >              if( methName != "product") continue;
807 >                cout<< typeName <<endl;
808 >                string _type;
809 >                TString testString( typeName.c_str() );
810 >                if( testString.BeginsWith("vector<") ) {
811 >                  _type = typeName.substr(typeName.find("<")+1,typeName.find(">")-typeName.find("<")-1);
812 >                  string _varSize = leafName.Data();
813 >                  _varSize += "obj@.size()";
814 >                  autoVars.push_back( _varSize );
815 >                  }
816 >                else _type = typeName.substr(0,typeName.find("*"));
817 >                  TClass _cl( _type.c_str() );
818 >                  for(int l=0;l<_cl.GetListOfAllPublicMethods()->GetEntries();++l) {
819 >                    string _typeName ( ((TMethod*) _cl.GetListOfAllPublicMethods()->At(l))->GetReturnTypeName() );
820 >                    string _methName ( _cl.GetListOfAllPublicMethods()->At(l)->GetName() );
821 >                    //              if(_typeName.find("void") != string::npos ) continue;
822 >                    //              cout<<"   "<<_typeName<<"  "<<_methName<<endl;
823 >
824 >                    cout<<" "<<_typeName<<"  "<<_methName<<endl;
825 >                    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")) {
826 >
827 >                      cout<<"-->   "<<_typeName<<"  "<<_methName<<endl;
828 >
829 >                      string  _varName = leafName.Data();
830 >                      _varName += "obj.";
831 >                      _varName += _methName;
832 >                      _varName += "()";
833 >                      autoVars.push_back( _varName );
834 >                    }
835 >                  }
836 >                  
837 >              
838 >            }
839 >
840 >          }
841  
842          }
843  
844 +        return autoVars.size();
845 +
846 + }
847 + //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
848 + //Draw efficiencies
849 + int  PlotTool::plotEff(int chainIndex, string histName, string cutName, int nEntries, double fitXmin, double fitXmax, string fitFormula)
850 + {
851 +
852 +  if( chainIndex >= this->GetEntries() ) return -1;
853 +
854 +  int currN = nEntries;
855 +  if(nEntries < 0) currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted!
856 +
857 +  //++++ Create and name Canvases according to global variables +++++++++++++
858 +  ostringstream currHistName;
859 +  if( samePad_trees) currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":";
860 +  if( samePad_vars)  currHistName<<histName;
861 +  if( samePad_cuts)  currHistName<<"{"<<cutName<<"}";
862 +
863 +  ostringstream currPadName;
864 +  if(! samePad_trees) currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":";
865 +  if(! samePad_vars)  currPadName<<histName;
866 +  if(! samePad_cuts)  currPadName<<"{"<<cutName<<"}";
867 +
868 +
869 +  //Draw total histogram:
870 +  if( ! pads_["total"] || ! gROOT->FindObject("total") ) {
871 +    pads_["total"] = new TCanvas("total", "total");
872 +  } else {
873 +    pads_["total"]->cd();
874 +  }
875 +  ostringstream bins_total;
876 +  bins_total<<histName;
877 +  bins_total<<">>total(100,0,1000)";
878 +
879 +
880 +  int draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_total.str().c_str(), "", "", currN);
881 +  if( draw_err <= 0 ) return draw_err;
882 +
883 +
884 +  TH1* total = ((TH1*) pads_["total"]->GetPrimitive("total"));
885 +
886 +  ostringstream bins_bkg;
887 +  bins_bkg<<histName;
888 +  bins_bkg<<">>bkg(";
889 +  bins_bkg<<total->GetNbinsX();
890 +  bins_bkg<<",";
891 +  bins_bkg<<total->GetXaxis()->GetXmin();
892 +  bins_bkg<<",";
893 +  bins_bkg<<total->GetXaxis()->GetXmax();
894 +  bins_bkg<<")";
895 +
896 +  //Draw bkg histogram:
897 +  if( ! pads_["bkg"] || ! gROOT->FindObject("bkg") ) {
898 +    pads_["bkg"] = new TCanvas("bkg", currPadName.str().c_str());
899 +  } else {
900 +    pads_["bkg"]->cd();
901 +  }
902 +
903 +  draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_bkg.str().c_str(), cutName.c_str(),"" , currN);
904 +  if( draw_err <= 0 ) return draw_err;
905 +
906 +
907 +  TH1* bkg = ((TH1*) pads_["bkg"]->GetPrimitive("bkg"));
908  
909 +  //Draw pass histogram:
910 +  ostringstream bins_pass;
911 +  bins_pass<<histName;
912 +  bins_pass<<">>pass(";
913 +  bins_pass<<total->GetNbinsX();
914 +  bins_pass<<",";
915 +  bins_pass<<total->GetXaxis()->GetXmin();
916 +  bins_pass<<",";
917 +  bins_pass<<total->GetXaxis()->GetXmax();
918 +  bins_pass<<")";
919 +
920 +  ostringstream cut_pass;
921 +  cut_pass<<"!(";
922 +  cut_pass<<cutName;
923 +  cut_pass<<")";
924 +  
925 +
926 +  if( ! pads_["pass"] || ! gROOT->FindObject("pass") ) {
927 +    pads_["pass"] = new TCanvas("pass", currPadName.str().c_str());
928 +  } else {
929 +    pads_["pass"]->cd();
930 +  }
931 +
932 +  draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_pass.str().c_str(),cut_pass.str().c_str() ,"" , currN);
933 +  if( draw_err <= 0 ) return draw_err;
934 +
935 +
936 +  TH1* pass = ((TH1*) pads_["pass"]->GetPrimitive("pass"));
937 +
938 +
939 +  currPadName<<"Eff";
940 +  //Draw Efficiency Graph:
941 +  if( ! pads_["EffGraph"] || ! gROOT->FindObject("EffGraph") ) {
942 +    pads_["EffGraph"] = new TCanvas("EffGraph", currPadName.str().c_str());
943 +  } else {
944 +    pads_["EffGraph"]->cd();
945 +  }
946 +
947 +  TGraphAsymmErrors* EffGraph = new TGraphAsymmErrors(bkg, total);
948 +  EffGraph->SetName(currHistName.str().c_str());
949 +
950 +  TF1* reverse = new TF2("reverse","1/y-1",total->GetXaxis()->GetXmin(),total->GetXaxis()->GetXmax());
951 +  EffGraph->Apply(reverse);
952 +  EffGraph->Draw("A*");
953 +
954 +  TF1* fitfunc = new TF1("fitfunc",fitFormula.c_str(),fitXmin,fitXmax);
955 +  EffGraph->Fit("fitfunc","R+");
956 +
957 +
958 +  //Save fit function
959 +
960 +  ostringstream savefuncName;
961 +  savefuncName<<histName;
962 +  savefuncName<<"_";
963 +
964 +  if(cutName.find("<") != std::string::npos ) cutName.replace(cutName.find("<"),1,"_");
965 +  if(cutName.find(">") != std::string::npos ) cutName.replace(cutName.find(">"),1,"_");
966 +  savefuncName<<cutName;
967 +
968 +
969 +  TFile file("ABCDFunctions.root","UPDATE");
970 +  TF1* savefunc = new TF1(savefuncName.str().c_str(), fitfunc->GetExpFormula().Data(),0,10000);
971 +  savefunc->SetParameters( fitfunc->GetParameters() );
972 +  savefunc->SetParErrors ( fitfunc->GetParErrors() );
973 +
974 +  //Show results
975 +  if( ! pads_["abcd"] || ! gROOT->FindObject("abcd") ) {
976 +    pads_["abcd"] = new TCanvas("abcd", "abcd");
977 +  } else {
978 +    pads_["abcd"]->cd();
979 +  }
980 +
981 +  bkg->Multiply(savefunc);
982 +  bkg->Draw();
983 +
984 +  //  total->Add(bkg,-1);
985 +  pass->SetLineColor(kRed);
986 +  pass->Draw("sames,e");
987 +  pads_["abcd"]->SetLogy();
988 +
989 +
990 +  savefunc->Write();
991 +  //  file.Close();
992 +
993 +
994 +  return draw_err;
995  
996   }
997 + //------------------------------------------------------------------

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines