forked from SridharaDasu/SimpleRootTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparisonPlots.C
81 lines (56 loc) · 2.25 KB
/
comparisonPlots.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
void comparisonPlots(std::string fileName1, std::string fileName2, std::string cut = "") {
TFile *file1 = new TFile(fileName1.c_str());
TFile *file2 = new TFile(fileName2.c_str());
if(file1->GetNkeys() != file2->GetNkeys()) {
std::cerr << "Files are dissimilar - can not be compared" << std::endl;
}
TIter next1(file1->GetListOfKeys());
TIter next2(file2->GetListOfKeys());
// Loop over directories
TKey *key1;
TKey *key2;
while( ( key1 = (TKey*) next1(), key2 = (TKey*) next2() ) ) {
auto dir1 = (TDirectoryFile*) file1->Get(key1->GetName());
auto dir2 = (TDirectoryFile*) file2->Get(key2->GetName());
TIter nextTree1(dir1->GetListOfKeys());
TIter nextTree2(dir2->GetListOfKeys());
TKey *treeKey1;
TKey *treeKey2;
while( ( treeKey1 = (TKey*) nextTree1(), treeKey2 = (TKey*) nextTree2() ) ) {
auto tree1 = (TTree*) dir1->Get(treeKey1->GetName());
auto tree2 = (TTree*) dir2->Get(treeKey2->GetName());
tree1->SetLineColor(kRed);
tree2->SetLineColor(kBlue);
TIter nextLeaf1(tree1->GetListOfLeaves());
TIter nextLeaf2(tree2->GetListOfLeaves());
TLeaf *leaf1;
TLeaf *leaf2;
while( ( leaf1 = (TLeaf*) nextLeaf1(), leaf2 = (TLeaf*) nextLeaf2() ) ) {
std::string stackName(tree1->GetName());
stackName += "-";
stackName += leaf1->GetName();
std::string hist1Name = stackName + "1";
TH1F *hist1 = new TH1F(hist1Name.c_str(), leaf1->GetName(), 100, 1, 0); // auto-bin
tree1->Project(hist1Name.c_str(), leaf1->GetName(), cut.c_str());
hist1->Scale(1./hist1->Integral());
hist1->SetLineColor(kRed);
std::string hist2Name = stackName + "2";
TH1F *hist2 = new TH1F(hist2Name.c_str(), leaf1->GetName(), 100, 1, 0); // auto-bin
tree2->Project(hist2Name.c_str(), leaf2->GetName(), cut.c_str());
hist2->Scale(1./hist2->Integral());
hist2->SetLineColor(kBlue);
THStack *stack = new THStack(stackName.c_str(), leaf1->GetName());
stack->Add(hist1);
stack->Add(hist2);
TCanvas *canvas = new TCanvas();
stack->Draw("nostack");
TLegend *lg=new TLegend(0.5,0.5,0.75,0.65);
lg->AddEntry(hist1, file1->GetName(), "l");
lg->AddEntry(hist2, file2->GetName(), "l");
lg->Draw();
std::string fileName = stackName + ".png";
canvas->SaveAs(fileName.c_str());
}
}
}
}