-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplotstacks.cpp
110 lines (108 loc) · 3.7 KB
/
plotstacks.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <ROOT/RDataFrame.hxx>// big guns
#include <TCanvas.h>
#include <TLegend.h>
#include <THStack.h>
#include "src/tdrstyle.C"
#include "src/calchisto.hpp"
int plotstacks(){
gROOT->SetBatch(kTRUE);// no open canvas window
setTDRStyle();
TFile cf("plots/components.root","RECREATE");
TCanvas canv("name to reset","title to reset",10,10,900,900);
TH1D *hobj;
// now we open ALL the files
std::map<std::pair<channel,dataSource>,TFile*> hFd;
for(channel ch:channelAll){
std::string chN;
switch (ch){
case elnu: {chN ="elnu_";break;}
case munu: {chN ="munu_";break;}
}
for(dataSource ds:dataSourceAll){
std::string opener = chN ;
switch (ds){
case tzq:{opener += "tzq";break;}
case ww:{opener += "_ww";break;}
case wz:{opener += "_wz";break;}
case zz:{opener += "_zz";break;}
case ttz:{opener += "ttz";break;}
case ttb:{opener += "ttb";break;}
case met:{opener += "met";break;}
case cms:{opener += "cms";break;}
}
hFd[std::make_pair(ch,ds)]
= new TFile(("histo/" + opener + ".root").c_str());
}}// now we have a histogram file dictionary of all the files miahahaha
for(std::string particle:{"fin_jets","lep","bjet"}){
for(PtEtaPhiM k:PtEtaPhiMall){
//if ( e == k ) continue;
std::string kstring = "_", tkstr = " ", xAxisStr;
switch(k){
case pt :{kstring += "_pt";
tkstr = " p_{T}";
xAxisStr = " p_{T}/GeV";
break;}
case eta:{kstring += "eta";
tkstr += "eta";
xAxisStr = "PseudoRapidity #eta";
break;}
case phi:{kstring += "phi";
tkstr += "phi";
xAxisStr = "Azimuthal angle #varphi/rad";
break;}
case m :{kstring += "mas";
tkstr += "mass";
xAxisStr = "\\text{mass GeV/}c^{2}";
break;}
}
for(channel ch:channelAll){
std::string chN;
switch (ch){
case elnu: {chN ="elnu";break;}
case munu: {chN ="munu";break;}
}
std::string title = chN + " " + particle;
if("fin_jets" == particle) title = chN + " jets";
std::string stname =(chN+"_"+particle + kstring).c_str() ;
canv.SetName(stname.c_str());canv.SetTitle(stname.c_str());
THStack stac(stname.c_str(),(title + tkstr).c_str());
for(dataSource ds:dataSourceAll){
std::string opener = chN + "_";
int colour;
switch (ds){
case tzq:{opener += "tzq";colour = 6;break;}// magenta
case ww:{opener += "_ww";colour = 2;break;}// red
case wz:{opener += "_wz";colour = 3;break;}// green
case zz:{opener += "_zz";colour = 4;break;}// blue
case ttz:{opener += "ttz";colour = 5;break;}// yellow
case ttb:{opener += "ttb";colour = 7;break;}// cyan
case met:{opener += "met";colour = 9;break;}// violet
case cms:{opener += "cms";colour = 1;break;}// black
}
std::string hobjN = opener + "_" + particle + kstring ;
hFd[std::make_pair(ch,ds)]->GetObject(hobjN.c_str(),hobj);
hobj->SetDirectory(nullptr);
if( cms == ds || met == ds ) hobj->SetLineColor( colour);
else hobj->SetFillColor( colour);
stac .Add( hobj);
}// dataSource
canv .cd();// pick me to draw?
stac .Draw("HIST");// must draw before set axes
stac .GetXaxis()->SetTitle(xAxisStr.c_str());
stac .GetYaxis()->SetTitle("Event");
canv .BuildLegend();
canv .Update();
cf .WriteTObject(&canv);
// canv .SaveAs(("plots/" + stname + ".root").c_str());// slow
// canv .SaveAs(("plots/" + stname + ".pdf" ).c_str());
canv .Clear();// clear rather than delete, reusable!
// stac will auto clean up since it is not new-ed
}}}// channel, particle, component
for(auto &x : hFd){
x.second->Close(); x.second = nullptr;
}
hobj = nullptr;
// file cf will automatically close
gROOT->SetBatch(kFALSE);// re-enable TBrowser
return 0;
}