1 #if !defined(__CINT__) || defined(__MAKECINT__) 14 #include <TPaveStats.h> 21 void SetHStyle(
TH1* hst,
int col=kRed,
int mark=20,
float mrsize=0.7);
24 TLatex*
AddLabel(
const char*txt,
float x=0.1,
float y=0.9,
int color=kBlack,
float size=0.04);
25 void wAv(
double v1,
double v2,
double err1=0,
double err2=0,
double* wv=0,
double *we=0);
26 void wSum(
double v1,
double v2,
double err1=0,
double err2=0,
double* wv=0,
double *we=0);
34 if (name0.IsNull()) name0 =
"defCanv";
37 if (fr) fr->SetBorderMode(0);
38 if (opt.Contains(
"c")) {
39 name = name0; name+=
".C";
40 canv->Print(name.Data());
43 if (opt.Contains(
"e")) {
44 name = name0; name+=
".eps";
45 canv->Print(name.Data());
48 if (opt.Contains(
"n")) {
49 name = name0; name+=
".png";
50 canv->Print(name.Data());
53 if (opt.Contains(
"p")) {
54 name = name0; name+=
".ps";
55 canv->Print(name.Data());
63 TLatex* lt =
new TLatex(x,y,txt);
65 lt->SetTextColor(color);
66 lt->SetTextSize(size);
73 if (!pad) pad = (TPad*)gPad;
75 TList* lst = pad->GetListOfPrimitives();
76 int size = lst->GetSize();
78 for (
int i=0;i<size;i++) {
81 if (obj->InheritsFrom(
"TH1")) {hst = (
TH1*)obj;
break;}
88 if (!pad) pad = (TPad*)gPad;
90 TList* lst = pad->GetListOfPrimitives();
91 int size = lst->GetSize();
93 for (
int i=0;i<size;i++) {
96 if (obj->InheritsFrom(
"TFrame")) {frm = (TFrame*)obj;
break;}
103 TList *lst = hst->GetListOfFunctions();
105 int nf = lst->GetSize();
106 for (
int i=0;i<nf;i++) {
107 TPaveStats *fnc = (TPaveStats*) lst->At(i);
108 if (fnc->InheritsFrom(
"TPaveStats"))
return fnc;
123 if (stl>=0) pad->SetFillStyle(stl);
124 if (col>=0) pad->SetFillColor(col);
132 hst->SetLineColor(col);
133 hst->SetMarkerColor(col);
135 hst->SetMarkerStyle(mark);
136 hst->SetMarkerSize(mrsize);
137 TList *lst = hst->GetListOfFunctions();
139 int nf = lst->GetSize();
140 for (
int i=0;i<nf;i++) {
142 if (fnc->InheritsFrom(
"TF1")) {
143 ((TF1*)fnc)->SetLineColor(col);
144 ((TF1*)fnc)->SetLineWidth(1);
145 ((TF1*)fnc)->ResetBit(TF1::kNotDraw);
147 else if (fnc->InheritsFrom(
"TPaveStats")) {
148 ((TPaveStats*)fnc)->SetTextColor(col);
156 hst->SetLineColor(col);
157 hst->SetMarkerColor(col);
158 hst->SetFillColor(col);
159 hst->SetMarkerStyle(mark);
160 hst->SetMarkerSize(mrsize);
161 TList *lst = hst->GetListOfFunctions();
163 int nf = lst->GetSize();
164 for (
int i=0;i<nf;i++) {
166 if (fnc->InheritsFrom(
"TF1")) {
167 ((TF1*)fnc)->SetLineColor(col);
168 ((TF1*)fnc)->SetLineWidth(1);
169 ((TF1*)fnc)->ResetBit(TF1::kNotDraw);
171 else if (fnc->InheritsFrom(
"TPaveStats")) {
172 ((TPaveStats*)fnc)->SetTextColor(col);
182 if (nname.IsNull()) {
183 nname = histo->GetName();
186 TH1* cml = (
TH1*) histo->Clone(nname.Data());
187 int nb = histo->GetNbinsX();
191 for (
int i=1;i<=nb;i++) {
192 sm += histo->GetBinContent(i);
193 cml->SetBinContent(i,sm);
194 if (!doErr)
continue;
195 double ee = histo->GetBinError(i);
197 cml->SetBinError(i, sme>0 ? TMath::Sqrt(sme):0.);
203 void wAv(
double v1,
double v2,
double err1,
double err2,
double* wv,
double *we)
207 if (err1<=0 || err2<=0) {
211 sum = v1/(err1*err1) + v2/(err2*err2);
212 err = 1./(err1*err1) + 1./(err2*err2);
214 err = 1./TMath::Sqrt(err);
216 printf(
"wAv %+e(%+e) | %+e(%+e) -> %+e +- %e\n",v1,err1,v2,err2,sum,err);
222 void wSum(
double v1,
double v2,
double err1,
double err2,
double* wv,
double *we)
227 if (err1>0 && err2>0) err = TMath::Sqrt(err1*err1 + err2*err2);
228 printf(
"wSum %+e(%+e) + %+e(%+e) -> %+e +- %e\n",v1,err1,v2,err2,sum,err);
237 if (xMn<=0 || xMx<=xMn || nbin<2) {
238 printf(
"Wrong axis request: %f %f %d\n",xMn,xMx,nbin);
241 double dx = log(xMx/xMn)/nbin;
243 for (
int i=0;i<=nbin;i++) xax[i]= xMn*exp(dx*i);
254 if (!histo)
return 0;
255 if (!histo->InheritsFrom(
"TH2")) {printf(
"Not a TH2\n");
return 0;}
258 if (nmstr.IsNull()) nmstr = Form(
"%s_nrm%s",histo->GetName(),cumul ?
"_cml" :
"");
259 TH2* cln = (
TH2*)histo->Clone(nmstr.Data());
261 TAxis* xax = histo->GetXaxis();
262 TAxis* yax = histo->GetYaxis();
263 int yb0 = under ? 0:1;
264 int yb1 = over ? yax->GetNbins() : 1+yax->GetNbins();;
266 for (
int ix=0;ix<=xax->GetNbins()+1;ix++) {
268 for (
int iy=0;iy<=yax->GetNbins()+1;iy++) {
269 double val = histo->GetBinContent(ix,iy);
272 if (totb<=0)
continue;
275 for (
int iy=yb0;iy<=yb1;iy++) {
276 double val = histo->GetBinContent(ix,iy);
277 double err = histo->GetBinError(ix,iy);
278 cln->SetBinContent(ix,iy,val/totb);
279 cln->SetBinError(ix,iy,err/totb);
282 if (!cumul)
continue;
284 for (
int iy=yb0+1;iy<=yb1;iy++) {
285 double val = cln->GetBinContent(ix,iy);
286 double err = cln->GetBinError(ix,iy);
287 double valP = cln->GetBinContent(ix,iy-1);
288 double errP = cln->GetBinError(ix,iy-1);
289 err = err*err+errP*errP;
290 err = err >0 ? TMath::Sqrt(err) : 0;
291 cln->SetBinContent(ix,iy,val + valP);
292 cln->SetBinError(ix,iy,err);
Int_t color[]
print message on plot with ok/not ok
TLatex * AddLabel(const char *txt, float x=0.1, float y=0.9, int color=kBlack, float size=0.04)
void SaveCanvas(TCanvas *canv, const char *path="canv", const Option_t *option="ecn")
Double_t * defLogAx(double xMn, double xMx, int nbin)
TPaveStats * SetStatPad(TH1 *hst, float x1, float x2, float y1, float y2, Int_t stl=-1, Int_t col=-1)
void SetGStyle(TGraph *hst, int col=kRed, int mark=20, float mrsize=0.7)
TH1 * Cumulate(TH1 *histo, Bool_t doErr=kTRUE, const char *copyName=0)
void wAv(double v1, double v2, double err1=0, double err2=0, double *wv=0, double *we=0)
TH1 * GetBaseHisto(TPad *pad=0)
TH2 * manip2d(TH2 *histo, Bool_t cumul, const char *newname, Bool_t over, Bool_t under)
TPaveStats * GetStatPad(TH1 *hst)
void wSum(double v1, double v2, double err1=0, double err2=0, double *wv=0, double *we=0)
void SetHStyle(TH1 *hst, int col=kRed, int mark=20, float mrsize=0.7)
TFrame * GetFrame(TPad *pad=0)