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.14 by tschum, Thu Dec 10 18:29:27 2009 UTC

# Line 14 | Line 14 | PlotTool::PlotTool() {
14  
15          showLegend = false;
16          logY = true;
17 <        addTrackJets = true;
17 >        addTrackJets = false;
18 >        addEventInfo = false;
19 >        addTower = false;
20          verbose = true;
21  
22 +        globalCuts="";
23 +
24 +        recreateTree = false; //force recreation of friend tree
25 +
26   }
27  
28   //------------------------------------------------------------------
29   //Fill object PlotTool with Chains constructed from files from given source
30  
31   int PlotTool::init(string fileName, string dirPath, string treeName,
32 <                string fileLabel) {
33 <        this->New(this->GetEntries() );
34 <        int currChain = this->GetEntries() - 1;
32 >                   string fileLabel) {
33 >  this->New(this->GetEntries() );
34 >  int currChain = this->GetEntries() - 1;
35 >
36 >  if (currChain < 0)
37 >    return currChain;
38 >
39 >  TStopwatch timer;
40 >  timer.Start();
41 >
42 >
43 >  fileNames.clear();
44 >
45 >  //check if alternative label is different from default(searchString)
46 >  if (fileLabel=="") {
47 >    fileLabel=fileName;
48 >  }
49 >  ((TChain*) this->At(currChain))->SetName(fileLabel.c_str());
50 >
51 >  TList *files = new TList();
52 >  TSystemFile* sysFile = 0;
53 >  if(fileName.find(".") != string::npos) {
54 >    ifstream f(fileName.c_str());
55 >    if( ! f.is_open() ) return -1;
56 >    string line;
57 >
58 >    while (!f.eof()) {
59 >      getline(f,line);
60 >      sysFile = new TSystemFile(line.c_str(),dirPath.c_str());
61 >      files->Add(sysFile);
62 >    }
63 >
64 >
65 >  } else {
66 >    TSystemDirectory dir("sourceDir", dirPath.c_str());
67 >    files = dir.GetListOfFiles();
68 >  }
69 >  if (files->GetEntries()>0) {
70 >    TIter next(files);
71 >    TSystemFile *file;
72 >    TString fname;
73 >    string filePath;
74 >
75 >    if(verbose && fileName.find(".") == string::npos )  cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: "
76 >                                                            <<fileName.c_str()<<endl;
77 >    if(verbose && fileName.find(".") != string::npos )  cout<<"Open"<<dirPath.c_str()<<" Search lines with .root in: "
78 >                                                            <<fileName.c_str()<<endl;
79 >
80 >
81 >    while ((file=(TSystemFile*)next())) {
82 >      fname = file->GetName();
83 >      if (!fname.EndsWith(".root"))
84 >        continue;
85 >      if (!fname.Contains(fileName.c_str()) && fileName.find(".") == string::npos )
86 >        continue;
87 >
88 >      filePath = dirPath;
89 >      filePath += fname.Data();
90 >      //fwlite::ChainEvent to lop over events, jets, etc
91 >      fileNames.push_back(filePath.c_str());
92 >
93 >      if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1,
94 >                                                   treeName.c_str()) )
95 >        if(verbose)     cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl;
96 >        else
97 >          return -1;
98  
99 <        if (currChain < 0)
100 <                return currChain;
99 >    }
100 >  } else
101 >    return -1;
102 >
103 >  for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) {
104 >
105 >    string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName());
106 >
107 >    string branch_alias = s;
108 >    string branch_name = s;
109 >    if (s.find(".", s.size()-1) != string::npos)
110 >      branch_name += "obj";
111 >
112 >    size_t a = s.find("_");
113 >    if (a != string::npos) {
114 >      size_t b = s.find("_", a+1);
115 >      if (b != string::npos) {
116 >        size_t c = s.find("_", b+1);
117 >        if (c != string::npos) {
118 >          string _prod     =s.substr(0,a);
119 >          string _label    =s.substr(a+1, b-a-1);
120 >          string _instance =s.substr(b+1, c-b-1);
121 >          branch_alias = _label;
122 >          if(_instance.length() > 0 )  {
123 >            branch_alias += "_";
124 >            branch_alias += _instance;
125 >            ((TChain*) this->At(currChain))->SetAlias(_instance.c_str(),
126 >                                                      branch_name.c_str());
127 >          }
128 >          string branch_alias_full = _prod + "_" + branch_alias;
129 >          ((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(),
130 >                                                    branch_name.c_str());
131 >        }
132 >      }
133 >    }
134  
135 <        TStopwatch timer;
136 <        timer.Start();
135 >    ((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),
136 >                                              branch_name.c_str());
137  
138 +  }
139  
140 <        fileNames.clear();
140 >  if( addEventInfo || addTrackJets || addTower ) {
141  
142 <        //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());
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;
142 >    if(verbose)   cout<<"add friend tree with additional variables..."<<endl;
143  
144 <                        filePath = dirPath;
145 <                        filePath += fname.Data();
146 <                        //fwlite::ChainEvent to lop over events, jets, etc
147 <                        fileNames.push_back(filePath.c_str());
148 <
149 <                        if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1,
150 <                                        treeName.c_str()) )
151 <                if(verbose)     cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl;
70 <                        else
71 <                                return -1;
144 >    //make file for tree friends (adding additional, computed branches)
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 <                }
74 <        } else
75 <                return -1;
153 >    TFile *f = new TFile(friendFileName.c_str(),fileOpt.c_str());
154  
155 <        for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) {
155 >    if( f->IsZombie() ) return -1;
156  
157 <                string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName());
157 >    string friendTreeName("friendTree");
158 >    //char number = currChain;
159 >    //friendTreeName += number;
160 >    //TTree *friendTree = new TTree("friendTree","friendTree");
161  
162 <                string branch_alias = s;
163 <                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 _prod     =s.substr(0,a);
93 <                      string _label    =s.substr(a+1, b-a-1);
94 <                      string _instance =s.substr(b+1, c-b-1);
95 <                      branch_alias = _label;
96 <                      if(_instance.length() > 0 )  {
97 <                        branch_alias += "_";
98 <                        branch_alias += _instance;
99 <                        ((TChain*) this->At(currChain))->SetAlias(_instance.c_str(),
100 <                                                                  branch_name.c_str());
101 <                      }
102 <                      string branch_alias_full = _prod + "_" + branch_alias;
103 <                      ((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(),
104 <                                branch_name.c_str());
105 <                    }
106 <                  }
107 <                }
162 >    if(! f->FindKey(friendTreeName.c_str())) {
163 >      if(verbose)   cout<<"calculating additional variables..."<<endl;
164  
109                ((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),
110                                branch_name.c_str());
165  
166 <        }
166 >      TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str());
167 >      fwlite::ChainEvent ev(fileNames);
168 >      int _event, _run, _lumi;
169 >      int nJetsKT;
170 >      TrackJetKT = new float [100];
171 >
172 >      //tower data
173 >      const int kMAX = 10000;
174 >      int NobjTowCal;
175 >      towet  = new float [ kMAX ];
176 >      toweta = new float [ kMAX ];
177 >      towphi = new float [ kMAX ];
178 >      towen  = new float [ kMAX ];
179 >      towem  = new float [ kMAX ];
180 >      towhd  = new float [ kMAX ];
181 >      towoe  = new float [ kMAX ];
182 >      towid_phi = new int[ kMAX ];
183 >      towid_eta = new int[ kMAX ];
184 >      towid     = new int[ kMAX ];
185 >      
186 >
187 >      if( addEventInfo ) {
188 >
189 >
190 >        friendTree->Branch("event", &_event, "event/I");
191 >        friendTree->Branch("run", &_run, "run/I");
192 >        friendTree->Branch("lumi", &_lumi, "lumi/I");
193 >
194 >      }
195 >
196 >      if( addTrackJets ) {
197 >
198 >
199 >        friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I");
200 >        friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F");
201 >      }
202 >
203 >      if( addTower) {
204 >
205 >        // CaloTower branches
206 >        friendTree->Branch( "NobjTowCal",&NobjTowCal,"NobjTowCal/I"            );
207 >        friendTree->Branch( "TowId",     towid,      "TowId[NobjTowCal]/I"     );
208 >        friendTree->Branch( "TowId_phi", towid_phi,  "TowId_phi[NobjTowCal]/I" );
209 >        friendTree->Branch( "TowId_eta", towid_eta,  "TowId_eta[NobjTowCal]/I" );
210 >        friendTree->Branch( "TowEt",     towet,      "TowEt[NobjTowCal]/F"     );
211 >        friendTree->Branch( "TowEta",    toweta,     "TowEta[NobjTowCal]/F"    );
212 >        friendTree->Branch( "TowPhi",    towphi,     "TowPhi[NobjTowCal]/F"    );
213 >        friendTree->Branch( "TowE",      towen,      "TowE[NobjTowCal]/F"      );
214 >        friendTree->Branch( "TowEm",     towem,      "TowEm[NobjTowCal]/F"     );
215 >        friendTree->Branch( "TowHad",    towhd,      "TowHad[NobjTowCal]/F"    );
216 >        friendTree ->Branch( "TowOE",     towoe,      "TowOE[NobjTowCal]/F"     );
217 >
218  
219 <        // add branch with track  Jets
219 >      }
220 >
221 >
222 >      int tenth = ev.size() / 10;
223 >      int eventNum =0;
224 >      for (ev.toBegin(); !ev.atEnd(); ++ev, ++eventNum) {
225 >
226 >
227 >        if( addEventInfo ) {
228 >
229 >
230 >          if(eventNum==0) {
231 >            //    fwlite::Handle<edm::TriggerResults> hltHandle;
232 >            //    hltHandle.getByLabel(ev, "TriggerResults");
233 >
234 >            //    fwlite::Handle<edm::TriggerResults> hTriggerResults;
235 >
236 >            //    hTriggerResults.getByLabel(ev, "TriggerResults","","TEST");
237 >            //    fwlite::TriggerNames const&  triggerNames = ev.triggerNames(*hTriggerResults);
238 >
239 >
240 >            //    //      std::vector<std::string> const& names = triggerNames.triggerNames();
241 >            //    for (unsigned i = 0; i < triggerNames.size(); ++i) {
242 >            //    std::cout << i << "  " << triggerNames.triggerName(i) << std::endl;
243 >            //    }
244 >          }
245 >
246 >          _event = ev.id().event();
247 >          _run   = ev.id().run();
248 >          _lumi = ev.luminosityBlock();
249 >
250 >        }
251  
252          if( addTrackJets ) {
253  
254 <          //make file for tree friends (adding additional, computed branches)
255 <          string friendFileName("/scratch/hh/current/cms/user/");
256 <          friendFileName += gSystem->GetUserInfo()->fUser;
257 <          friendFileName += "/temp/",
258 <          friendFileName += fileName;
259 <          friendFileName += ".root";
260 <          TFile *f = new TFile(friendFileName.c_str(),"recreate");
261 <
262 <          if( f->IsZombie() ) return -1;
263 <
264 <          string friendTreeName("friendTree");
265 <          //char number = currChain;
266 <          //friendTreeName += number;
267 <          //TTree *friendTree = new TTree("friendTree","friendTree");
268 <          TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str());
269 <
270 <          int nJetsKT;
271 <          TrackJetKT = new float [100];
272 <          fwlite::ChainEvent ev(fileNames);
273 <
138 <          friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I");
139 <          friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F");
140 <
141 <          if(verbose)   cout<<"calculating additional variables..."<<endl;
142 <          
143 <          
144 <
145 <          int tenth = ev.size() / 10;
146 <          int eventNum =0;
147 <          for (ev.toBegin(); !ev.atEnd(); ++ev, ++eventNum) {
148 <
149 <            fwlite::Handle<reco::CaloJetCollection> jets;
150 <            jets.getByLabel(ev, "antikt5CaloJets");
151 <
152 <            fwlite::Handle<reco::TrackCollection> tracks;
153 <            tracks.getByLabel(ev, "generalTracks");
154 <
155 <            if (!jets.isValid())
156 <              continue;
157 <            if (!tracks.isValid())
158 <              continue;
159 <            double trackSum;
160 <            nJetsKT = 0;
161 <            for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet
162 <                   !=jets->end(); jet++) {
163 <              trackSum = 0;
164 <              for (reco::TrackCollection::const_iterator track = tracks->begin(); track
165 <                     !=tracks->end(); track++) {
166 <                if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi())
167 <                    < 0.5)
168 <                  trackSum += track->pt();
169 <              }
170 <              TrackJetKT[nJetsKT] = trackSum;
171 <              nJetsKT++;
254 >          fwlite::Handle<reco::CaloJetCollection> jets;
255 >          jets.getByLabel(ev, "ak5CaloJets");
256 >
257 >          fwlite::Handle<reco::TrackCollection> tracks;
258 >          tracks.getByLabel(ev, "generalTracks");
259 >
260 >          if (!jets.isValid())
261 >            continue;
262 >          if (!tracks.isValid())
263 >            continue;
264 >          double trackSum;
265 >          nJetsKT = 0;
266 >          for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet
267 >                 !=jets->end(); jet++) {
268 >            trackSum = 0;
269 >            for (reco::TrackCollection::const_iterator track = tracks->begin(); track
270 >                   !=tracks->end(); track++) {
271 >              if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi())
272 >                  < 0.5)
273 >                trackSum += track->pt();
274              }
275 <            friendTree->Fill();
275 >            TrackJetKT[nJetsKT] = trackSum;
276 >            nJetsKT++;
277 >          }
278 >        }
279 >        if( addTower) {
280  
281 <            if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl;
281 >          fwlite::Handle<CaloTowerCollection> towers;
282 >          towers.getByLabel(ev, "towerMaker");
283  
284 +          int jtow = 0;
285 +          NobjTowCal=towers->size();
286 +          for(CaloTowerCollection::const_iterator tow = towers->begin();
287 +              tow != towers->end(); ++tow, ++jtow){
288 +            towet [jtow] = tow->et();
289 +            toweta[jtow] = tow->eta();
290 +            towphi[jtow] = tow->phi();
291 +            towen [jtow] = tow->energy();
292 +            towem [jtow] = tow->emEnergy();
293 +            towhd [jtow] = tow->hadEnergy();
294 +            towoe [jtow] = tow->outerEnergy();
295 +            towid_phi[jtow] = tow->id().iphi();
296 +            towid_eta[jtow] = tow->id().ieta();
297 +            towid [jtow] = tow->id().rawId();
298            }
299 <          f->cd();
300 <          friendTree->Write();
180 <          f->Close();
181 <          ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
182 <                                                     friendFileName.c_str());
299 >
300 >
301          }
302 +        friendTree->Fill();
303 +
304 +        if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl;
305 +
306 +      }
307 +      f->cd();
308 +      friendTree->Write();
309 +    }
310 +    f->Close();
311 +    ((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(),
312 +                                               friendFileName.c_str());
313 +
314 +
315  
316 <        timer.Stop();
317 <        if(verbose) timer.Print();
316 >  }
317 >
318 >
319 >  timer.Stop();
320 >  if(verbose) timer.Print();
321        
322 <        return this->GetEntries();
322 >  return this->GetEntries();
323  
324   }
325   //------------------------------------------------------------------
# Line 197 | Line 331 | int PlotTool::plot(int chainIndex, strin
331                  return -1;
332  
333          TStopwatch timer;
334 <        timer.Start();
334 >        if(verbose) {
335 >          cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl;
336 >          timer.Start();
337 >        }
338  
339          int currN = nEntries;
340          if (nEntries < 0)
# Line 258 | Line 395 | int PlotTool::plot(int chainIndex, strin
395  
396  
397          //Draw histogram:
398 <        int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(),
398 >        string cutNameWithGlobal = cutName;
399 >        if(cutName!="" && globalCuts!="")    cutNameWithGlobal += "&&";
400 >        if(globalCuts!="")                   cutNameWithGlobal += globalCuts;
401 >
402 >        int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutNameWithGlobal.c_str(),
403                          currOpt.c_str(), currN);
404          if (draw_err < 0)
405                  return draw_err;
# Line 285 | Line 426 | int PlotTool::plot(int chainIndex, strin
426                          setCanvas( pads_[currPadName.str()] );
427          }
428  
429 <        timer.Stop();
430 <        if(verbose) {
431 <          cout<<"Done: "<<currN<<" events in "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl;
429 >
430 >        if(verbose && draw_err > 0) {
431 >          timer.Stop();
432 >          cout<<"Done: Selected "<<draw_err<<" objects in "<< currN <<" processed events."<<endl;
433            timer.Print();
434          }
435          return draw_err;
# Line 371 | Line 513 | int PlotTool::loop(string histName, vect
513   int PlotTool::updatePads() {
514  
515          for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) {
516 <                if (gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) {
517 <                        (*it).second->Draw();
518 <                        setCanvas((*it).second);
519 <                } else
520 <                        pads_.erase(it);
516 >                if ( ! gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) {
517 >                  pads_.erase(it);
518 >                  continue;
519 >                }
520 >                if( (*it).second->GetListOfPrimitives()->GetEntries() == 0 ) {
521 >                  (*it).second->Close();
522 >                  pads_.erase(it);
523 >                  continue;
524 >                }
525 >                (*it).second->Draw();
526 >                setCanvas((*it).second);
527 >
528          }
529  
530          return pads_.size();
# Line 520 | Line 669 | void PlotTool::setMathLabels(TH1* thisHi
669          string x = thisHist->GetXaxis()->GetTitle();
670          string y = thisHist->GetYaxis()->GetTitle();
671  
672 <        if (t.find(".phi()") != string::npos)
673 <                t.replace(t.find(".phi()"), 6, " #phi");
672 > //      if (x.find("__") != string::npos)
673 > //        x = x.substr(0,x.find("__"));
674 > //      if (y.find("__") != string::npos)
675 > //        y = y.substr(0,y.find("__"));
676 >
677          if (x.find(".phi()") != string::npos)
678                  x.replace(x.find(".phi()"), 6, " #phi");
679          if (y.find(".phi()") != string::npos)
680                  y.replace(y.find(".phi()"), 6, " #phi");
681  
530        if (t.find(".eta()") != string::npos)
531                t.replace(t.find(".eta()"), 6, " #eta");
682          if (x.find(".eta()") != string::npos)
683                  x.replace(x.find(".eta()"), 6, " #eta");
684          if (y.find(".eta()") != string::npos)
685                  y.replace(y.find(".eta()"), 6, " #eta");
686  
687 <        if (t.find(".pt()") != string::npos)
688 <                t.replace(t.find(".pt()"), 5, " p_{T}");
687 >        if (x.find(".theta()") != string::npos)
688 >                x.replace(x.find(".theta()"), 6, " #theta");
689 >        if (y.find(".theta()") != string::npos)
690 >                y.replace(y.find(".theta()"), 6, " #theta");
691 >
692 >        if (x.find(".chi2()") != string::npos)
693 >                x.replace(x.find(".chi2()"), 7, " #chi^{2}");
694 >        if (y.find(".chi2()") != string::npos)
695 >                y.replace(y.find(".chi2()"), 7, " #chi^{2}");
696 >
697          if (x.find(".pt()") != string::npos)
698 <                x.replace(x.find(".pt()"), 5, " p_{T}");
698 >                x.replace(x.find(".pt()"), 5, " p_{T} [GeV]");
699          if (y.find(".pt()") != string::npos)
700 <                y.replace(y.find(".pt()"), 5, " p_{T}");
700 >                y.replace(y.find(".pt()"), 5, " p_{T} [GeV]");
701 >
702 >        if (x.find(".et()") != string::npos)
703 >                x.replace(x.find(".et()"), 5, " E_{T} [GeV]");
704 >        if (y.find(".et()") != string::npos)
705 >                y.replace(y.find(".et()"), 5, " E_{T} [GeV]");
706 >
707 >        //splitlines for many cuts
708 >        string test1= "{" + globalCuts + "}";
709 >        string test2= "&&" + globalCuts;
710 >
711 >        if(t.find(test1) != string::npos) t.replace(t.find(test1),test1.length(),"");
712 >        if(t.find(test2) != string::npos) t.replace(t.find(test2),test2.length(),"");
713 >
714 >        if (t.find("{") != string::npos && t.find("#splitline") == string::npos) {
715 >          t.replace(t.find_last_of("{"), 1, "}{");
716 >          string t_old = t;
717 >          t = "#splitline{";
718 >          t +=  t_old;
719 >        }
720  
721          thisHist ->SetTitle(t.c_str());
722          thisHist->GetXaxis()->SetTitle(x.c_str());
# Line 674 | Line 851 | int PlotTool::saveCanvases(string name,
851  
852          int savedCanvs =0;
853  
677        TPostScript ps(namePs.c_str(),112);
678        TFile rt(nameRt.c_str(),"recreate");
854  
855          TIter next(gROOT->GetListOfCanvases());
856          TCanvas* canv;
857          while ((canv=(TCanvas*)next())) {
858 +          string modName = (*canv).GetName();
859 +          if(modName.find("{") != string::npos) modName = modName.substr(0,modName.find("{"));
860 +          (*canv).SetTitle( modName.c_str() );
861 +
862 +        }
863 +
864 +
865 +        TPostScript ps(namePs.c_str(),112);
866 +        TFile rt(nameRt.c_str(),"recreate");
867 +
868 +        next.Reset();
869 +        while ((canv=(TCanvas*)next())) {
870            ps.NewPage();
871 +
872 +
873 +          (*canv).Write();
874            (*canv).Draw();
875            (*canv).Update();
876 <          (*canv).Write();
876 >
877 >
878            ++savedCanvs;
879  
880          }
# Line 691 | Line 882 | int PlotTool::saveCanvases(string name,
882          ps.Close();
883          rt.Close();
884  
885 +
886 +        if(verbose && savedCanvs) {
887 +          cout<<"Saved file "<<rt.GetName()<<" with "<<savedCanvs<<" canvases."<<endl;
888 +          cout<<"Saved file "<<ps.GetName()<<" with "<<savedCanvs<<" pages."<<endl;
889 + }
890          return savedCanvs;
891  
892   }
893   //------------------------------------------------------------------
698 void PlotTool::showChainInfo()
699 {
700
894  
895 <  cout<<endl;
896 <  cout<<"****** Show Chain Information:"<<endl;
895 > int PlotTool::clearCanvases()
896 > {
897  
898 +  while(gROOT->GetListOfCanvases()->GetEntries()) ((TCanvas*) gROOT->GetListOfCanvases()->At(0))->Close();
899 +  pads_.clear();
900 +  autoVars.clear();
901 +  return pads_.size() + gROOT->GetListOfCanvases()->GetEntries();
902  
903 <  this->ls();
903 > }
904 > //------------------------------------------------------------------
905 > int PlotTool::setVariables(string label)
906 > {
907  
708  cout<<endl;
709  cout<<"We have "<<this->GetEntries()<<" TChains with following aliases set:"<<endl;
908          for (int i=0; i< this->GetEntries(); ++i) {
909 <          cout<<endl;
909 >          cout<<"--------------------------------"<<endl;
910            cout<<((TChain*) this->At(i))->GetName()<<endl;
911 <          ((TChain*) this->At(i))->GetListOfAliases()->ls();
911 >          cout<<"------------"<<endl;
912  
913 <        }
913 >          TList* leaves = (TList*) ((TChain*) this->At(i))->GetListOfLeaves();
914 >          for (int j=0; j< leaves->GetEntries(); ++j) {
915 >            TString leafName ( leaves->At(j)->GetName() );
916 >            if(! leafName.EndsWith(".") ) continue;
917 >            if(! leafName.Contains(label.c_str() ) ) continue;
918 >
919 >            TClass cl( ( (TLeafElement*) leaves->At(j) )->GetTypeName() );
920 >            cout<<"++++++"<<endl;
921 >            cout<< leafName.Data() <<endl;
922 >            for(int k=0;k<cl.GetListOfAllPublicMethods()->GetEntries();++k) {
923 >              string typeName ( ((TMethod*) cl.GetListOfAllPublicMethods()->At(k))->GetReturnTypeName() );
924 >              string methName ( cl.GetListOfAllPublicMethods()->At(k)->GetName() );
925 >              if( methName != "product") continue;
926 >                cout<< typeName <<endl;
927 >                string _type;
928 >                TString testString( typeName.c_str() );
929 >                if( testString.BeginsWith("vector<") ) {
930 >                  _type = typeName.substr(typeName.find("<")+1,typeName.find(">")-typeName.find("<")-1);
931 >                  string _varSize = leafName.Data();
932 >                  _varSize += "obj@.size()";
933 >                  autoVars.push_back( _varSize );
934 >                  }
935 >                else _type = typeName.substr(0,typeName.find("*"));
936 >                  TClass _cl( _type.c_str() );
937 >                  for(int l=0;l<_cl.GetListOfAllPublicMethods()->GetEntries();++l) {
938 >                    string _typeName ( ((TMethod*) _cl.GetListOfAllPublicMethods()->At(l))->GetReturnTypeName() );
939 >                    string _methName ( _cl.GetListOfAllPublicMethods()->At(l)->GetName() );
940 >                    //              if(_typeName.find("void") != string::npos ) continue;
941 >                    //              cout<<"   "<<_typeName<<"  "<<_methName<<endl;
942 >
943 >                    cout<<" "<<_typeName<<"  "<<_methName<<endl;
944 >                    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")) {
945 >
946 >                      cout<<"-->   "<<_typeName<<"  "<<_methName<<endl;
947 >
948 >                      string  _varName = leafName.Data();
949 >                      _varName += "obj.";
950 >                      _varName += _methName;
951 >                      _varName += "()";
952 >                      autoVars.push_back( _varName );
953 >                    }
954 >                  }
955 >                  
956 >              
957 >            }
958  
959 +          }
960 +
961 +        }
962  
963 +        return autoVars.size();
964  
965   }
966   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines