ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/dumpToPDF.C
Revision: 1.4
Committed: Fri Oct 26 12:06:54 2012 UTC (12 years, 6 months ago) by abrinke1
Content type: text/plain
Branch: MAIN
CVS Tags: V00-02-06, V00-02-05, HEAD
Changes since 1.3: +26 -3 lines
Log Message:
Allows fewer secondary plots than fitmaking plots

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     string outName = inName;
15     outName.replace(outName.find(".root"), 5, ".pdf");
16    
17 fantasia 1.2 //fitName = "HLT_10LS_delivered_vs_rate_Run190949-191090.root";
18     TFile *fFit = TFile::Open(fitName.c_str(), "read"); assert(fFit);
19    
20 fantasia 1.1 TCanvas c1;
21     c1.Print(Form("%s[", outName.c_str()), "pdf"); //Open .pdf
22    
23     //get list of keys
24     int nplots = fin->GetNkeys();
25 fantasia 1.2 int nfits = fFit->GetNkeys();
26     printf("nplots: %i, nfits: %i\n", nplots, nfits);
27 fantasia 1.3 if(nplots != nfits){
28     cout<<" PDF output will be wrong since different number of triggers in fit and current run"<<endl;
29 abrinke1 1.4 if (nplots > nfits) {
30     cout<<"Quitting"<<endl;
31     abort();
32     }
33 fantasia 1.3 }
34 fantasia 1.2 TList* plots = fin->GetListOfKeys();
35     TList* fits = fFit->GetListOfKeys();
36 abrinke1 1.4 int offset = 0; //Assumes nfits >= nplots
37     std::string inPlotName = "";
38     std::string inFitName = "";
39 fantasia 1.1 for(int i=0; i<nplots; ++i){
40 abrinke1 1.4
41 fantasia 1.2 TKey* plot = (TKey*) plots->At(i);
42 abrinke1 1.4 TKey* fit = (TKey*) fits->At(i+offset);//assume they're in the same order for now
43 fantasia 1.2
44     if(!fin->GetKey(plot->GetName())){
45     cout<<"Didn't find "<<plot<<". Removing."<<endl;
46     abort();
47     }
48     if(!fFit->GetKey(fit->GetName())){
49     cout<<"Didn't find "<<fit<<". Removing."<<endl;
50     abort();
51 fantasia 1.1 }
52 abrinke1 1.4 inPlotName = plot->GetName();
53     inFitName = fit->GetName();
54     inFitName.erase(inFitName.length()-17,inFitName.length());//Removes "rate_vs_delivered" from string
55    
56     //std::cout << inPlotName << " " << inFitName << std::endl;
57     while ((std::string::npos != inPlotName.find(inFitName)) == 0) { //While plot and fit names don't match
58     offset += 1;
59     fit = (TKey*) fits->At(i+offset);
60     if(!fFit->GetKey(fit->GetName())){
61     cout<<"Didn't find "<<fit<<". Removing."<<endl;
62     abort();
63     }
64     inFitName = fit->GetName();
65     inFitName.erase(inFitName.length()-17,inFitName.length());
66     //std::cout << inFitName << std::endl;
67     }
68    
69 fantasia 1.2 TCanvas* c = new TCanvas();
70     c->Divide(1,2);
71    
72     TCanvas* cPlot = (TCanvas*) fin->Get(plot->GetName());
73     c->cd(1);
74     cPlot->DrawClonePad();
75    
76     TCanvas* cFit = (TCanvas*) fFit->Get(fit->GetName());
77     c->cd(2);
78     cFit->DrawClonePad();
79    
80 fantasia 1.1 string bookmarkName = "Title: ";
81 fantasia 1.2 bookmarkName += plot->GetName();
82    
83 fantasia 1.1 c->Print(outName.c_str(), bookmarkName.c_str());
84     }
85    
86     c1.Print(Form("%s]", outName.c_str()), "pdf"); //Close .pdf
87    
88     }