1 |
#include "TROOT.h"
|
2 |
#include "TH1.h"
|
3 |
#include "TF1.h"
|
4 |
#include "TMath.h"
|
5 |
#include "TAxis.h"
|
6 |
#include "TString.h"
|
7 |
#include "TFile.h"
|
8 |
#include "TCanvas.h"
|
9 |
#include "TLegend.h"
|
10 |
#include "TStyle.h"
|
11 |
#include <map>
|
12 |
|
13 |
using namespace std;
|
14 |
struct rang {
|
15 |
double min;
|
16 |
double max;
|
17 |
rang(const double & x1 = 999, const double & x2 = -999) {min = x1; max = x2;}
|
18 |
};
|
19 |
|
20 |
map<TString,TString> histName;
|
21 |
map<TString,TH1*> hs;
|
22 |
map<TString,TCanvas*> ts;
|
23 |
map<TString,rang> ranges;
|
24 |
map<int,TFile*> fs;
|
25 |
map<int,TString> binlabel;
|
26 |
|
27 |
void makePlots() {
|
28 |
const int nvar_ = 6;
|
29 |
const int mergbin_[2] = {10,200};
|
30 |
// variables to plot
|
31 |
string coord[nvar_] = {"X","Y","Z","beamWidthX","beamWidthY","SigmaZ"};
|
32 |
// beammonitor module names
|
33 |
string dqmapp[2] = {"trk","pix"};
|
34 |
string label[2] = {"Track Based","Pix Vtx Based"};
|
35 |
|
36 |
gROOT->SetStyle("CMS");
|
37 |
gStyle->SetErrorX(0);
|
38 |
|
39 |
fs[0] = TFile::Open("fill_1089_trk.root");
|
40 |
fs[1] = TFile::Open("fill_1089_pix.root");
|
41 |
string appendix = "1089";
|
42 |
|
43 |
int nbins_ = 100;
|
44 |
int xmax_ = -99999;
|
45 |
int xmin_ = 99999;
|
46 |
|
47 |
for (int n1=0;n1<2;++n1) { // loop modules
|
48 |
TString histName = TString("X_"+dqmapp[n1]);
|
49 |
TH1F *htmp = (TH1F*) fs[n1]->Get("X");
|
50 |
TAxis *xtmp = htmp->GetXaxis();
|
51 |
TString tmplabel = xtmp->GetBinLabel(xtmp->GetXmax());
|
52 |
int widx=0;
|
53 |
for (int w=0;w<tmplabel.Length();w++) {
|
54 |
if (tmplabel(w,1) == "-" ||
|
55 |
tmplabel(w,1) == ":") // for TRK based: 13xxxx:yyy-zzzz;y and z not necessarily have same digits
|
56 |
widx = w + 1;
|
57 |
}
|
58 |
tmplabel.Remove(0,widx);
|
59 |
if (tmplabel.Atoi() > xmax_) xmax_ = tmplabel.Atoi();
|
60 |
|
61 |
tmplabel = xtmp->GetBinLabel(1);
|
62 |
for (int w=0;w<tmplabel.Length();w++) {
|
63 |
if (tmplabel(w,1) == "-" ||
|
64 |
tmplabel(w,1) == ":")
|
65 |
widx = w + 1;
|
66 |
}
|
67 |
tmplabel.Remove(0,widx);
|
68 |
if (tmplabel.Atoi() < xmin_) xmin_ = tmplabel.Atoi();
|
69 |
}
|
70 |
//cout << "xmin_ = " << xmin_ << " xmax = " << xmax_ << endl;
|
71 |
nbins_ = xmax_ - xmin_ - 1;
|
72 |
|
73 |
for (int n0=0;n0<nvar_;++n0) { // loop variables
|
74 |
for (int n1=0;n1<2;++n1) { // loop modules
|
75 |
TString histName = TString(coord[n0]+"_"+dqmapp[n1]);
|
76 |
|
77 |
TH1F *htmp = (TH1F*) fs[n1]->Get(TString(coord[n0]));
|
78 |
histName += "_new";
|
79 |
hs[histName] = new TH1F(histName,histName,nbins_,xmin_,xmax_);
|
80 |
|
81 |
for (int i=0;i<htmp->GetNbinsX();i++) {
|
82 |
int nthBin = 0;
|
83 |
binlabel[i+1] = htmp->GetXaxis()->GetBinLabel(i+1);
|
84 |
int widx = 0;
|
85 |
for (int w=0;w<binlabel[i+1].Length();w++) {
|
86 |
if (binlabel[i+1](w,1) == "-" ||
|
87 |
binlabel[i+1](w,1) == ":") // for TRK based: 13xxxx:yyy-zzzz;y and z not necessarily have same digits
|
88 |
widx = w + 1;
|
89 |
}
|
90 |
binlabel[i+1].Remove(0,widx);
|
91 |
int valxbin = binlabel[i+1].Atoi();
|
92 |
nthBin = valxbin - xmin_ + 1;
|
93 |
if (
|
94 |
nthBin > 0
|
95 |
&& nthBin <= nbins_
|
96 |
&& (
|
97 |
n0 < 3 || (n0 >=3 &&
|
98 |
(nthBin+1)%5 == 0
|
99 |
)
|
100 |
)
|
101 |
) {
|
102 |
hs[histName]->SetBinContent(nthBin,htmp->GetBinContent(i+1));
|
103 |
hs[histName]->SetBinError(nthBin,htmp->GetBinError(i+1));
|
104 |
}
|
105 |
// find good y-axis range
|
106 |
double yval = htmp->GetBinContent(i+1);
|
107 |
double yerr = htmp->GetBinError(i+1);
|
108 |
if (
|
109 |
n0<3 || (n0 >=3 &&
|
110 |
(nthBin+1)%5 == 0
|
111 |
)
|
112 |
) {
|
113 |
if (yval+2*yerr >= ranges[TString(coord[n0])].max)
|
114 |
ranges[TString(coord[n0])].max = yval + 2*yerr;
|
115 |
if (yval-2*yerr <= ranges[TString(coord[n0])].min)
|
116 |
ranges[TString(coord[n0])].min = yval - 2*yerr;
|
117 |
}
|
118 |
}
|
119 |
|
120 |
// Labeling
|
121 |
if (n1 ==0) {// execute once for each module
|
122 |
for (int i=0;i<nbins_;++i) {
|
123 |
if (
|
124 |
(n0 < 3 && (xmin_+i)%mergbin_[0] == 0)
|
125 |
|| (n0 >= 3 && (xmin_+i)%mergbin_[1] == 0)
|
126 |
) {
|
127 |
char buffer[5];
|
128 |
sprintf(buffer,"%i",xmin_+i);
|
129 |
hs[histName]->GetXaxis()->SetBinLabel(i,buffer);
|
130 |
hs[histName]->LabelsOption("h","x");
|
131 |
}
|
132 |
}
|
133 |
}
|
134 |
|
135 |
hs[histName]->SetMarkerStyle(8);
|
136 |
if (n0<3) {
|
137 |
hs[histName]->SetMarkerSize(0.8);
|
138 |
hs[histName]->SetLineWidth(0.4);
|
139 |
}
|
140 |
else {
|
141 |
hs[histName]->SetMarkerSize(0.4);
|
142 |
hs[histName]->SetLineWidth(0.2);
|
143 |
}
|
144 |
hs[histName]->GetXaxis()->SetTitle(htmp->GetXaxis()->GetTitle());
|
145 |
hs[histName]->GetXaxis()->SetTitleSize(0.065);
|
146 |
hs[histName]->GetXaxis()->SetTitleOffset(0.72);
|
147 |
hs[histName]->GetXaxis()->SetLabelSize(0.05);
|
148 |
hs[histName]->GetXaxis()->SetLabelOffset(0.01);
|
149 |
|
150 |
hs[histName]->GetYaxis()->SetTitle(htmp->GetYaxis()->GetTitle());
|
151 |
hs[histName]->GetYaxis()->SetTitleSize(0.065);
|
152 |
hs[histName]->GetYaxis()->SetTitleOffset(0.7);
|
153 |
hs[histName]->GetYaxis()->SetLabelSize(0.05);
|
154 |
|
155 |
}
|
156 |
// cout << "Ran max = " << ranges[TString(coord[n0])].max << "; ";
|
157 |
// cout << "Ran min = " << ranges[TString(coord[n0])].min << endl;;
|
158 |
}
|
159 |
|
160 |
|
161 |
gStyle->SetPadTickX(0);
|
162 |
gStyle->SetPadTickY(0);
|
163 |
|
164 |
// Position plots
|
165 |
ts["pos"] = new TCanvas("pos","positions",700,800);
|
166 |
ts["pos"]->Divide(1,3);
|
167 |
for (int n0=0;n0<3;++n0) {//X,Y,Z
|
168 |
ts["pos"]->cd(n0+1);
|
169 |
TLegend *tmpleg = new TLegend(0.55,0.7,0.7,0.88);
|
170 |
tmpleg->SetFillColor(0);
|
171 |
tmpleg->SetFillStyle(0);
|
172 |
|
173 |
for (int n1=0;n1<2;++n1) {//TRK,PIX
|
174 |
TString histName = TString(coord[n0]+"_"+dqmapp[n1]);
|
175 |
histName += "_new";
|
176 |
hs[histName]->SetLineColor(n1*2+2);
|
177 |
hs[histName]->SetMarkerColor(n1*2+2);
|
178 |
tmpleg->AddEntry(hs[histName],TString(label[n1]),"p");
|
179 |
if (n1==0) {
|
180 |
hs[histName]->GetXaxis()->SetRangeUser(560,700);
|
181 |
hs[histName]->GetYaxis()->SetRangeUser(ranges[TString(coord[n0])].min,ranges[TString(coord[n0])].max);
|
182 |
hs[histName]->Draw();
|
183 |
}
|
184 |
else
|
185 |
hs[histName]->Draw("same");
|
186 |
}
|
187 |
//if (n0 == 0)
|
188 |
tmpleg->Draw();
|
189 |
}
|
190 |
ts["pos"]->Print(TString("positions_"+ appendix +".png"));
|
191 |
|
192 |
// Width plots
|
193 |
ts["width"] = new TCanvas("width","widths",700,800);
|
194 |
ts["width"]->Divide(1,3);
|
195 |
for (int n0=3;n0<nvar_;++n0) {//X,Y,Z
|
196 |
ts["width"]->cd(n0-2);
|
197 |
TLegend *tmpleg = new TLegend(0.35,0.7,0.5,0.88);
|
198 |
tmpleg->SetFillColor(0);
|
199 |
tmpleg->SetFillStyle(0);
|
200 |
|
201 |
for (int n1=0;n1<2;++n1) {//TRK,PIX
|
202 |
TString histName = TString(coord[n0]+"_"+dqmapp[n1]);
|
203 |
histName += "_new";
|
204 |
hs[histName]->SetLineColor(n1*2+2);
|
205 |
hs[histName]->SetMarkerColor(n1*2+2);
|
206 |
tmpleg->AddEntry(hs[histName],TString(label[n1]),"p");
|
207 |
if (n1==0) {
|
208 |
//hs[histName]->GetXaxis()->SetRangeUser(1,int(hs[histName]->GetNbinsX()-40));
|
209 |
hs[histName]->GetYaxis()->SetRangeUser(ranges[TString(coord[n0])].min,ranges[TString(coord[n0])].max);
|
210 |
hs[histName]->Draw();
|
211 |
}
|
212 |
else
|
213 |
hs[histName]->Draw("same");
|
214 |
}
|
215 |
//if (n0 == 3)
|
216 |
tmpleg->Draw();
|
217 |
}
|
218 |
ts["width"]->Print(TString("widths_"+ appendix +".png"));
|
219 |
}
|