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.9 by tschum, Thu Dec 3 11:24:14 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  
24   //------------------------------------------------------------------
# Line 41 | 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 <                if(verbose)     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 197 | Line 219 | int PlotTool::plot(int chainIndex, strin
219                  return -1;
220  
221          TStopwatch timer;
222 <        timer.Start();
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)
# Line 258 | 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 285 | Line 314 | int PlotTool::plot(int chainIndex, strin
314                          setCanvas( pads_[currPadName.str()] );
315          }
316  
317 <        timer.Stop();
318 <        if(verbose) {
319 <          cout<<"Done: "<<currN<<" events in "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl;
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;
# Line 520 | 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  
530        if (t.find(".eta()") != string::npos)
531                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 674 | Line 732 | int PlotTool::saveCanvases(string name,
732  
733          int savedCanvs =0;
734  
677        TPostScript ps(namePs.c_str(),112);
678        TFile rt(nameRt.c_str(),"recreate");
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 +        TPostScript ps(namePs.c_str(),112);
747 +        TFile rt(nameRt.c_str(),"recreate");
748 +
749 +        next.Reset();
750 +        while ((canv=(TCanvas*)next())) {
751            ps.NewPage();
752 +
753 +
754 +          (*canv).Write();
755            (*canv).Draw();
756            (*canv).Update();
757 <          (*canv).Write();
757 >
758 >
759            ++savedCanvs;
760  
761          }
# Line 691 | Line 763 | int PlotTool::saveCanvases(string name,
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          return savedCanvs;
772  
773   }
774   //------------------------------------------------------------------
698 void PlotTool::showChainInfo()
699 {
775  
776 + int PlotTool::clearCanvases()
777 + {
778  
779 <  cout<<endl;
780 <  cout<<"****** Show Chain Information:"<<endl;
781 <
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  
708  cout<<endl;
709  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 <        }
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   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines