3 #include "TProfile2D.h"
10 TH1D* myProjectionX(TProfile2D* prof2d,
double lowBound,
double upBound,
bool absoluteBound=0,
bool reversedSign=0 ){
15 TString st(prof2d->GetName());
19 TH1D* projx = prof2d->ProjectionX(st.Data(), prof2d->GetYaxis()->FindBin(lowBound),prof2d->GetYaxis()->FindBin(upBound));
22 TH1D* projy = prof2d->ProjectionY();
27 for (
int i = 0; i<projx->GetNbinsX(); i++) {
31 double contentSqrSum=0.;
34 for (
int j=0; j<projy->GetNbinsX(); j++) {
37 float BinHighEdge = (projy->GetBinLowEdge(j) + projy->GetBinWidth(j));
38 float BinLowEdge = projy->GetBinLowEdge(j);
40 if (absoluteBound==0){
41 if ( BinHighEdge < lowBound)
continue;
42 if ( BinLowEdge > upBound)
continue;
43 }
else if (absoluteBound){
45 if ( BinHighEdge < 0. && BinLowEdge < 0. && BinHighEdge < -upBound)
continue;
46 if ( BinHighEdge < 0. && BinLowEdge < 0. && BinLowEdge > -lowBound)
continue;
47 if ( BinHighEdge > 0. && BinLowEdge > 0. && BinHighEdge < lowBound)
continue;
48 if ( BinHighEdge > 0. && BinLowEdge > 0. && BinLowEdge > upBound)
continue;
49 if ( BinHighEdge > 0. && BinLowEdge < 0. && (BinHighEdge-BinLowEdge)<lowBound)
continue;
56 double entries = prof2d->GetBinEntries(prof2d->GetBin(i,j));
57 if (entries==0)
continue;
58 double content = prof2d->GetBinContent(i,j);
59 if (reversedSign && (BinHighEdge+BinLowEdge)/2. < 0.) content *=-1.;
60 double error = prof2d->GetBinError(i,j);
62 entriesSum += entries;
63 contentSum += content * entries;
66 contentSqrSum += entries * (entries * error * error + content * content);
67 }
else if (entries ==1) {
69 contentSqrSum += content*content;
75 projx->SetBinContent(i,contentSum/entriesSum);
76 projx->SetBinError(i,(sqrt((contentSqrSum/entriesSum) - pow ( ( contentSum/entriesSum),2.)) / sqrt(entriesSum)));
82 if (projy)
delete projy;
87 TH1D* myProjectionY(TProfile2D* prof2d,
double lowBound,
double upBound ,
bool absoluteBound=0,
bool reversedSign=0 ){
89 TString st(prof2d->GetName());
94 TH1D* projy = prof2d->ProjectionY(st.Data(), prof2d->GetXaxis()->FindBin(lowBound),prof2d->GetXaxis()->FindBin(upBound));
97 TH1D* projx = prof2d->ProjectionX();
100 for (
int j=0; j<projy->GetNbinsX(); j++) {
102 double contentSum=0.;
103 double entriesSum=0.;
104 double contentSqrSum=0.;
106 for (
int i = 0; i<projx->GetNbinsX(); i++) {
109 float BinHighEdge = (projx->GetBinLowEdge(i) + projx->GetBinWidth(i));
110 float BinLowEdge = projx->GetBinLowEdge(i);
112 if (absoluteBound==0){
113 if ( BinHighEdge < lowBound)
continue;
114 if ( BinLowEdge > upBound)
continue;
115 }
else if (absoluteBound){
117 if ( BinHighEdge < 0. && BinLowEdge < 0. && BinHighEdge < -upBound)
continue;
118 if ( BinHighEdge < 0. && BinLowEdge < 0. && BinLowEdge > -lowBound)
continue;
119 if ( BinHighEdge > 0. && BinLowEdge > 0. && BinHighEdge < lowBound)
continue;
120 if ( BinHighEdge > 0. && BinLowEdge > 0. && BinLowEdge > upBound)
continue;
121 if ( BinHighEdge > 0. && BinLowEdge < 0. && (BinHighEdge-BinLowEdge)<lowBound)
continue;
127 double entries = prof2d->GetBinEntries(prof2d->GetBin(i,j));
128 if (entries==0)
continue;
129 double content = prof2d->GetBinContent(i,j);
130 if (reversedSign && (BinHighEdge+BinLowEdge)/2. < 0.) content *=-1.;
131 double error = prof2d->GetBinError(i,j);
133 entriesSum += entries;
134 contentSum += content * entries;
137 contentSqrSum += entries * (entries * error * error + content * content);
138 }
else if (entries ==1) {
140 contentSqrSum += content*content;
146 projy->SetBinContent(j,contentSum/entriesSum);
147 projy->SetBinError(j,(sqrt((contentSqrSum/entriesSum) - pow ( ( contentSum/entriesSum),2.)) / sqrt(entriesSum)));
152 if (projx)
delete projx;