17 void split(
const TString&
str, TString& sub1, TString& sub2);
21 std::cout <<
"Please provide a label:filename, variable, deltaR value, and an out directory." << std::endl;
22 std::cout <<
"You may also include a second file at the end." << std::endl;
23 std::cout <<
"Example: offsetStack label1:file1.root npv 0.4 plots" << std::endl;
24 std::cout <<
"Example: offsetStack label1:file1.root npv 0.4 plots label2:file2.root" << std::endl;
28 TString label1, fname1;
29 split(argv[1], label1, fname1);
30 TString
label = label1;
32 TString
var = argv[2];
33 float r = std::stof(argv[3]);
36 TFile*
file1 = TFile::Open(fname1);
38 std::cout <<
"Invalid file1: " << fname1 << std::endl;
42 TH1F*
h = (TH1F*)file1->FindObjectAny(var);
44 std::cout <<
"Could not find " + var +
" hist" << std::endl;
47 int avg = h->GetMean() + 0.5;
49 std::map<TString, TH1D*> hists1 = {{
"chm", 0}, {
"chu", 0}, {
"nh", 0}, {
"ne", 0}, {
"hfh", 0}, {
"hfe", 0}, {
"lep", 0}};
50 if (!
getHists(hists1, file1, var, avg, r))
54 TCanvas
c(
"c",
"c", 600, 600);
56 THStack* stack1 =
new THStack(
57 "stack1", Form(
";#eta;<Offset Energy_{T}(#pi%.1f^{2})>/<%s> [GeV]", r, var ==
"npv" ?
"N_{PV}" :
"#mu"));
62 TLegend* leg =
new TLegend(.4, .67, .65, .92);
66 TString label2, fname2;
67 split(argv[5], label2, fname2);
69 TFile* file2 = TFile::Open(fname2);
71 std::cout <<
"Invalid file2: " << fname2 << std::endl;
75 TH1F* h2 = (TH1F*)file2->FindObjectAny(var);
77 std::cout <<
"Could not find " + var +
" hist in file2" << std::endl;
80 int avg2 = h2->GetMean() + 0.5;
82 std::map<TString, TH1D*> hists2 = hists1;
83 if (!
getHists(hists2, file2, var, avg2, r))
86 THStack* stack2 =
new THStack(
"stack2",
"stack2");
88 stack2->Draw(
"samepe");
91 leg->SetHeader(Form(
"#bf{Markers: %s, Histograms: %s}", label2.Data(), label1.Data()));
92 label = label1 +
"_vs_" + label2;
95 TH1D* hfe_clone = (TH1D*)hists2[
"hfe"]->Clone(
"hfe_clone");
96 TH1D* hfh_clone = (TH1D*)hists2[
"hfh"]->Clone(
"hfh_clone");
98 THStack* cloneStack =
new THStack(
"cloneStack",
"cloneStack");
99 cloneStack->Add(hists2[
"ne"]);
100 cloneStack->Add(hfe_clone);
101 cloneStack->Add(hists2[
"nh"]);
102 cloneStack->Add(hfh_clone);
103 cloneStack->Draw(
"samepe");
105 hists2[
"ne"]->SetAxisRange(-2.9, 2.9);
106 hists2[
"hfe"]->SetAxisRange(-5, -2.6);
107 hists2[
"nh"]->SetAxisRange(-2.9, 2.9);
108 hists2[
"hfh"]->SetAxisRange(-5, -2.6);
109 hists2[
"chu"]->SetAxisRange(-2.9, 2.9);
110 hists2[
"chm"]->SetAxisRange(-2.9, 2.9);
112 hfe_clone->SetAxisRange(2.6, 5);
113 hfh_clone->SetAxisRange(2.6, 5);
116 leg->SetBorderSize(0);
117 leg->SetFillColor(0);
118 leg->SetFillStyle(0);
119 leg->SetTextSize(0.04);
120 leg->SetTextFont(42);
122 leg->AddEntry(hists1[
"ne"],
"Photons", legPF);
123 leg->AddEntry(hists1[
"hfe"],
"EM Deposits", legPF);
124 leg->AddEntry(hists1[
"nh"],
"Neutral Hadrons", legPF);
125 leg->AddEntry(hists1[
"hfh"],
"Hadronic Deposits", legPF);
126 leg->AddEntry(hists1[
"chu"],
"Unassoc. Charged Hadrons", legPF);
127 leg->AddEntry(hists1[
"chm"],
"Assoc. Charged Hadrons", legPF);
134 text.SetTextSize(0.065);
135 text.SetTextFont(61);
136 text.DrawLatex(0.2, 0.87,
"CMS");
138 text.SetTextSize(0.045);
139 text.SetTextFont(42);
140 text.DrawLatex(1 - label.Length() / 41., 0.96,
label);
142 c.Print(outdir +
"/stack_" + label +
".pdf");
146 for (
auto& pair : hists) {
147 TString
name = Form(
"p_offset_eta_%s%i_%s", var.Data(), var_val, pair.first.Data());
148 TProfile*
p = (TProfile*)file->FindObjectAny(name);
150 std::cout <<
"Could not find " + name << std::endl;
153 pair.second = p->ProjectionX(pair.first);
154 pair.second->Scale(r * r / 2 / var_val);
156 const double*
xbins = p->GetXaxis()->GetXbins()->GetArray();
157 for (
int i = 1,
n = p->GetNbinsX();
i <=
n;
i++) {
158 pair.second->SetBinContent(
i, pair.second->GetBinContent(
i) / (xbins[
i] - xbins[
i - 1]));
159 pair.second->SetBinError(
i, pair.second->GetBinError(
i) / (xbins[
i] - xbins[
i - 1]));
166 gStyle->SetPadTopMargin(0.05);
167 gStyle->SetPadBottomMargin(0.1);
168 gStyle->SetPadLeftMargin(0.16);
169 gStyle->SetPadRightMargin(0.02);
171 gStyle->SetOptStat(0);
172 gStyle->SetOptTitle(0);
174 gStyle->SetTitleFont(42,
"XYZ");
175 gStyle->SetTitleSize(0.05,
"XYZ");
176 gStyle->SetTitleXOffset(0.9);
177 gStyle->SetTitleYOffset(1.4);
179 gStyle->SetLabelFont(42,
"XYZ");
180 gStyle->SetLabelOffset(0.007,
"XYZ");
181 gStyle->SetLabelSize(0.04,
"XYZ");
183 gStyle->SetPadTickX(1);
184 gStyle->SetPadTickY(1);
188 stack->Add(hists[
"ne"]);
189 stack->Add(hists[
"hfe"]);
190 stack->Add(hists[
"nh"]);
191 stack->Add(hists[
"hfh"]);
192 stack->Add(hists[
"chu"]);
193 stack->Add(hists[
"chm"]);
195 hists[
"ne"]->SetMarkerStyle(kMultiply);
196 hists[
"hfe"]->SetMarkerStyle(kOpenStar);
197 hists[
"nh"]->SetMarkerStyle(kOpenDiamond);
198 hists[
"hfh"]->SetMarkerStyle(kOpenTriangleUp);
199 hists[
"chu"]->SetMarkerStyle(kOpenCircle);
200 hists[
"chm"]->SetMarkerStyle(kOpenCircle);
202 hists[
"ne"]->SetFillColor(kBlue);
203 hists[
"hfe"]->SetFillColor(kViolet + 2);
204 hists[
"nh"]->SetFillColor(kGreen);
205 hists[
"hfh"]->SetFillColor(kPink + 6);
206 hists[
"chu"]->SetFillColor(kRed - 9);
207 hists[
"chm"]->SetFillColor(kRed);
209 hists[
"ne"]->SetLineColor(kBlack);
210 hists[
"hfe"]->SetLineColor(kBlack);
211 hists[
"nh"]->SetLineColor(kBlack);
212 hists[
"hfh"]->SetLineColor(kBlack);
213 hists[
"chu"]->SetLineColor(kBlack);
214 hists[
"chm"]->SetLineColor(kBlack);
217 void split(
const TString&
str, TString& sub1, TString& sub2) {
218 int pos = str.First(
':');
220 sub2 =
str(pos + 1, str.Length());
const edm::EventSetup & c
list var
if using global norm cols_to_minmax = ['t_delta', 't_hmaxNearP','t_emaxNearP', 't_hAnnular', 't_eAnnular','t_pt','t_nVtx','t_ieta','t_eHcal10', 't_eHcal30','t_rhoh','t_eHcal'] df[cols_to_minmax] = df[cols_to_minmax].apply(lambda x: (x - x.min()) / (x.max() - x.min()) if (x.max() - x.min() > 0) else 1.0/200.0)
bool getHists(std::map< TString, TH1D * > &hists, TFile *&file, TString var, int var_val, float r)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
void setStack(THStack *&stack, std::map< TString, TH1D * > &hists)