ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/dumpToPDF.C
Revision: 1.3
Committed: Mon Sep 17 13:34:12 2012 UTC (12 years, 7 months ago) by fantasia
Content type: text/plain
Branch: MAIN
CVS Tags: V00-02-04, V00-02-03, V00-02-01
Changes since 1.2: +10 -2 lines
Log Message:
updates for ease of use

File Contents

# User Rev Content
1 fantasia 1.1 //This script will take all the rate comparison plots from a
2     //root file and print them into a single pdf for easy viewing
3 fantasia 1.3 //Usage: root -b -l -q 'dumpToPDF.C+("infile.root", "fitName")'
4    
5     #include <iostream>
6     #include "TFile.h"
7     #include "TCanvas.h"
8     #include "TKey.h"
9 fantasia 1.1
10     void
11 fantasia 1.2 dumpToPDF(string inName, string fitName){
12 fantasia 1.1 TFile *fin = TFile::Open(inName.c_str(), "read"); assert(fin);
13    
14 fantasia 1.2
15 fantasia 1.1 string outName = inName;
16     outName.replace(outName.find(".root"), 5, ".pdf");
17    
18 fantasia 1.2 //fitName = "HLT_10LS_delivered_vs_rate_Run190949-191090.root";
19     TFile *fFit = TFile::Open(fitName.c_str(), "read"); assert(fFit);
20    
21 fantasia 1.1 TCanvas c1;
22     c1.Print(Form("%s[", outName.c_str()), "pdf"); //Open .pdf
23    
24     //get list of keys
25     int nplots = fin->GetNkeys();
26 fantasia 1.2 int nfits = fFit->GetNkeys();
27     printf("nplots: %i, nfits: %i\n", nplots, nfits);
28 fantasia 1.3 if(nplots != nfits){
29     cout<<" PDF output will be wrong since different number of triggers in fit and current run"<<endl;
30     abort();
31     }
32 fantasia 1.2 TList* plots = fin->GetListOfKeys();
33     TList* fits = fFit->GetListOfKeys();
34 fantasia 1.1 for(int i=0; i<nplots; ++i){
35 fantasia 1.2 TKey* plot = (TKey*) plots->At(i);
36     TKey* fit = (TKey*) fits->At(i);//assume they're in the same order for now
37    
38     if(!fin->GetKey(plot->GetName())){
39     cout<<"Didn't find "<<plot<<". Removing."<<endl;
40     abort();
41     }
42     if(!fFit->GetKey(fit->GetName())){
43     cout<<"Didn't find "<<fit<<". Removing."<<endl;
44     abort();
45 fantasia 1.1 }
46 fantasia 1.2 TCanvas* c = new TCanvas();
47     c->Divide(1,2);
48    
49     TCanvas* cPlot = (TCanvas*) fin->Get(plot->GetName());
50     c->cd(1);
51     cPlot->DrawClonePad();
52    
53     TCanvas* cFit = (TCanvas*) fFit->Get(fit->GetName());
54     c->cd(2);
55     cFit->DrawClonePad();
56    
57 fantasia 1.1 string bookmarkName = "Title: ";
58 fantasia 1.2 bookmarkName += plot->GetName();
59    
60 fantasia 1.1 c->Print(outName.c_str(), bookmarkName.c_str());
61     }
62    
63     c1.Print(Form("%s]", outName.c_str()), "pdf"); //Close .pdf
64    
65     }