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.6 by gebbert, Wed Nov 25 15:34:38 2009 UTC vs.
Revision 1.7 by tschum, Fri Nov 27 17:39:46 2009 UTC

# Line 14 | Line 14 | PlotTool::PlotTool() {
14  
15          showLegend = false;
16          logY = true;
17 +        addTrackJets = true;
18  
19   }
20  
21   //------------------------------------------------------------------
22   //Fill object PlotTool with Chains constructed from files from given source
23 +
24   int PlotTool::init(string fileName, string dirPath, string treeName,
25                  string fileLabel) {
26          this->New(this->GetEntries() );
# Line 26 | Line 28 | int PlotTool::init(string fileName, stri
28  
29          if (currChain < 0)
30                  return currChain;
29        //make file for tree friends (adding additional, computed branches)
30        string friendFileName("/scratch/hh/lustre/cms/user/thomsen/temp/");
31        friendFileName += fileName;
32        friendFileName += ".root";
33        TFile *f = new TFile(friendFileName.c_str(),"recreate");
34        string friendTreeName("friendTree");
35        //char number = currChain;
36        //friendTreeName += number;
37        //TTree *friendTree = new TTree("friendTree","friendTree");
38        TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str());
31  
32          fileNames.clear();
33  
# Line 80 | Line 72 | int PlotTool::init(string fileName, stri
72          for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) {
73  
74                  string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName());
75 <                size_t a = s.find("_");
76 <                if (a == string::npos)
85 <                        a = 0;
86 <                size_t b = s.find("_", a+1);
87 <                if (b == string::npos)
88 <                        b = 50;
89 <                string branch_alias = s.substr(a+1, b-a-1);
75 >
76 >                string branch_alias = s;
77                  string branch_name = s;
78                  if (s.find(".", s.size()-1) != string::npos)
79                          branch_name += "obj";
80 +
81 +                size_t a = s.find("_");
82 +                if (a != string::npos) {
83 +                  size_t b = s.find("_", a+1);
84 +                  if (b != string::npos) {
85 +                    size_t c = s.find("_", b+1);
86 +                    if (c != string::npos) {
87 +                      string _label    =s.substr(a+1, b-a-1);
88 +                      string _instance =s.substr(b+1, c-b-1);
89 +                      branch_alias = _label;
90 +                      if(_instance.length() > 0 )  {
91 +                        branch_alias += "_";
92 +                        branch_alias += _instance;
93 +                      }
94 +                    }
95 +                  }
96 +                }
97 +
98                  ((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),
99                                  branch_name.c_str());
100  
# Line 97 | Line 102 | int PlotTool::init(string fileName, stri
102  
103          // add branch with track  Jets
104  
105 <        int nJetsKT;
101 <        TrackJetKT = new float [100];
102 <        fwlite::ChainEvent ev(fileNames);
105 >        if( addTrackJets ) {
106  
107 <        friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I");
108 <        friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F");
109 <
110 <        cout<<"calculating additional variables..."<<endl;
111 <        for (ev.toBegin(); !ev.atEnd(); ++ev) {
112 <
113 <                fwlite::Handle<reco::CaloJetCollection> jets;
114 <                jets.getByLabel(ev, "antikt5CaloJets");
115 <
116 <                fwlite::Handle<reco::TrackCollection> tracks;
117 <                tracks.getByLabel(ev, "generalTracks");
118 <
119 <                if (!jets.isValid())
120 <                        continue;
121 <                if (!tracks.isValid())
122 <                        continue;
123 <                double trackSum;
124 <                nJetsKT = 0;
125 <                for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet
126 <                                !=jets->end(); jet++) {
127 <                        trackSum = 0;
128 <                        for (reco::TrackCollection::const_iterator track = tracks->begin(); track
129 <                                        !=tracks->end(); track++) {
130 <                                if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi())
131 <                                                < 0.5)
132 <                                        trackSum += track->pt();
133 <                        }
134 <                        TrackJetKT[nJetsKT] = trackSum;
135 <                        nJetsKT++;
136 <                }
137 <                friendTree->Fill();
107 >          //make file for tree friends (adding additional, computed branches)
108 >          string friendFileName("/scratch/hh/lustre/cms/user/thomsen/temp/");
109 >          friendFileName += fileName;
110 >          friendFileName += ".root";
111 >          TFile *f = new TFile(friendFileName.c_str(),"recreate");
112 >          string friendTreeName("friendTree");
113 >          //char number = currChain;
114 >          //friendTreeName += number;
115 >          //TTree *friendTree = new TTree("friendTree","friendTree");
116 >          TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str());
117 >
118 >          int nJetsKT;
119 >          TrackJetKT = new float [100];
120 >          fwlite::ChainEvent ev(fileNames);
121 >
122 >          friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I");
123 >          friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F");
124 >
125 >          cout<<"calculating additional variables..."<<endl;
126 >          for (ev.toBegin(); !ev.atEnd(); ++ev) {
127 >
128 >            fwlite::Handle<reco::CaloJetCollection> jets;
129 >            jets.getByLabel(ev, "antikt5CaloJets");
130 >
131 >            fwlite::Handle<reco::TrackCollection> tracks;
132 >            tracks.getByLabel(ev, "generalTracks");
133 >
134 >            if (!jets.isValid())
135 >              continue;
136 >            if (!tracks.isValid())
137 >              continue;
138 >            double trackSum;
139 >            nJetsKT = 0;
140 >            for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet
141 >                   !=jets->end(); jet++) {
142 >              trackSum = 0;
143 >              for (reco::TrackCollection::const_iterator track = tracks->begin(); track
144 >                     !=tracks->end(); track++) {
145 >                if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi())
146 >                    < 0.5)
147 >                  trackSum += track->pt();
148 >              }
149 >              TrackJetKT[nJetsKT] = trackSum;
150 >              nJetsKT++;
151 >            }
152 >            friendTree->Fill();
153 >          }
154 >          f->cd();
155 >          friendTree->Write();
156 >          f->Close();
157 >          ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
158 >                                                     friendFileName.c_str());
159          }
136        f->cd();
137        friendTree->Write();
138        f->Close();
139        ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
140                        friendFileName.c_str());
141
160          return this->GetEntries();
161  
162   }
# Line 188 | Line 206 | int PlotTool::plot(int chainIndex, strin
206                          && !samePad_vars) || (sameCanv_cuts && !samePad_cuts);
207  
208          if (useSubPads) {
209 <                if ( !canvases_[currCanvName.str()] || !gROOT->FindObject(currCanvName.str().c_str()) ) {
209 >                if ( !canvases_[currCanvName.str()] || !gROOT->GetListOfCanvases()->FindObject(currCanvName.str().c_str()) ) {
210                          canvases_[currCanvName.str()] = new TCanvas(currCanvName.str().c_str(), currCanvName.str().c_str());
211                  } else if (canvases_[currCanvName.str()]->GetNumber() >= 0) {
212                          canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()+1);
213                  }
214          }
215  
216 <        if ( !pads_[currPadName.str()] || !gROOT->FindObject(currPadName.str().c_str()) ) {
216 >        if ( !pads_[currPadName.str()] || !gROOT->GetListOfCanvases()->FindObject(currPadName.str().c_str()) ) {
217                  pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str());
218                  if (logY)
219                          pads_[currPadName.str()]->SetLogy(1);
# Line 312 | Line 330 | int PlotTool::loop(string histName, vect
330   int PlotTool::updatePads() {
331  
332          for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) {
333 <                if (gROOT->FindObject((*it).first.c_str() ) ) {
333 >                if (gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) {
334                          (*it).second->Draw();
335                          setCanvas((*it).second);
336                  } else
# Line 328 | Line 346 | int PlotTool::fillCanvases() {
346          for (map< string, TCanvas* >::iterator it=canvases_.begin() ; it
347                          != canvases_.end(); ++it) {
348                  const char* canvName = (*it).first.c_str();
349 <                if (gROOT->FindObject(canvName) ) {
349 >                if (gROOT->GetListOfCanvases()->FindObject(canvName) ) {
350  
351                          int numP = (*it).second->GetNumber()+1;
352  
# Line 351 | Line 369 | int PlotTool::fillCanvases() {
369                          for (map< string, TCanvas* >::iterator it2=pads_.begin() ; it2
370                                          != pads_.end(); ++it2) {
371                                  string padName = (*it2).first;
372 <                                if (gROOT->FindObject(padName.c_str() ) ) {
372 >                                if (gROOT->GetListOfCanvases()->FindObject(padName.c_str() ) ) {
373                                          if ( (padName.find(canvName) != string::npos ) || !strcmp(
374                                                          canvName, "All") ) {
375                                                  (*it).second->cd(padIndex);
# Line 622 | Line 640 | int PlotTool::saveCanvases(string type,
640  
641   }
642   //------------------------------------------------------------------
643 + void PlotTool::showChainInfo()
644 + {
645 +
646 +
647 +  cout<<endl;
648 +  cout<<"****** Show Chain Information:"<<endl;
649 +
650 +
651 +  this->ls();
652 +
653 +  cout<<endl;
654 +  cout<<"We have "<<this->GetEntries()<<" TChains with following aliases set:"<<endl;
655 +        for (int i=0; i< this->GetEntries(); ++i) {
656 +          cout<<endl;
657 +          cout<<((TChain*) this->At(i))->GetName()<<endl;
658 +          ((TChain*) this->At(i))->GetListOfAliases()->ls();
659 +
660 +        }
661 +
662 +
663 +
664 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines