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 |
//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 |
|
10 |
void
|
11 |
dumpToPDF(string inName, string fitName){
|
12 |
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 |
//fitName = "HLT_10LS_delivered_vs_rate_Run190949-191090.root";
|
18 |
TFile *fFit = TFile::Open(fitName.c_str(), "read"); assert(fFit);
|
19 |
|
20 |
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 |
int nfits = fFit->GetNkeys();
|
26 |
printf("nplots: %i, nfits: %i\n", nplots, nfits);
|
27 |
if(nplots != nfits){
|
28 |
cout<<" PDF output will be wrong since different number of triggers in fit and current run"<<endl;
|
29 |
if (nplots > nfits) {
|
30 |
cout<<"Quitting"<<endl;
|
31 |
abort();
|
32 |
}
|
33 |
}
|
34 |
TList* plots = fin->GetListOfKeys();
|
35 |
TList* fits = fFit->GetListOfKeys();
|
36 |
int offset = 0; //Assumes nfits >= nplots
|
37 |
std::string inPlotName = "";
|
38 |
std::string inFitName = "";
|
39 |
for(int i=0; i<nplots; ++i){
|
40 |
|
41 |
TKey* plot = (TKey*) plots->At(i);
|
42 |
TKey* fit = (TKey*) fits->At(i+offset);//assume they're in the same order for now
|
43 |
|
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 |
}
|
52 |
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 |
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 |
string bookmarkName = "Title: ";
|
81 |
bookmarkName += plot->GetName();
|
82 |
|
83 |
c->Print(outName.c_str(), bookmarkName.c_str());
|
84 |
}
|
85 |
|
86 |
c1.Print(Form("%s]", outName.c_str()), "pdf"); //Close .pdf
|
87 |
|
88 |
}
|