12 auto ax = hg->GetXaxis();
13 for (
int i=1;
i<=
ax->GetNbins();++
i){
14 double _val = hg->GetBinContent(
i);
15 double _err = hg->GetBinError(
i);
16 double weight = 1./
ax->GetBinWidth(
i);
17 hg->SetBinContent(
i,_val*weight);
18 hg->SetBinError (
i,_err*weight);
25 while (_ <-M_PI) _ += 2*M_PI;
26 while (_ > M_PI) _ -= 2*M_PI;
30 TH1D*
rebin_TH1D(TH1D* hg_in, vector<int> i_bins,
string _name=
"",
bool delete_hg_in=
true,
bool norm_by_cnt=
true,
bool norm_by_width =
true) {
32 double cnt = hg_in->Integral();
34 auto ax = hg_in->GetXaxis();
36 int nbins = i_bins.size()-1;
38 if (nbins<1)
return hg_in;
40 edges.push_back(
ax->GetBinLowEdge(i_bins[
i]));
43 auto hg_out =
new TH1D(name.c_str(), Form(
"%s;%s;%s",hg_in->GetTitle(),
44 hg_in->GetXaxis()->GetTitle(), hg_in->GetYaxis()->GetTitle()),
50 for (
int k=i0;
k<i1;++
k) {
51 sum += hg_in->GetBinContent(
k);
53 hg_out->SetBinContent(
i+1, sum);
54 hg_out->SetBinError(
i+1, pow(sum,0.5));
58 auto c = hg_out->GetBinContent(
i);
59 auto e = hg_out->GetBinError (
i);
60 auto w = hg_out->GetXaxis()->GetBinWidth(
i);
61 hg_out->SetBinContent(
i,
c/w);
62 hg_out->SetBinError (
i,
e/w);
66 hg_out->Scale(1./cnt);
68 if (delete_hg_in)
delete hg_in;
73 for (
int i=1;
i<=hg->GetNbinsX(); ++
i) {
74 double W = w->GetBinContent(
i);
76 hg->SetBinContent(
i, 0.);
77 hg->SetBinError (
i, 0.);
79 hg->SetBinContent(
i, hg->GetBinContent(
i)/W);
80 hg->SetBinError (
i, hg->GetBinError (
i)/W);
85 void set_range(
int axis,
int bin0,
int bin1, vector<THnSparseD*> vec_sparse,
bool print=
false) {
87 for (
auto& sparse : vec_sparse) {
88 TAxis*
ax = sparse->GetAxis(axis);
89 sparse->GetAxis(axis)->SetRange(bin0, bin1);
92 cout << Form(
"Set range(%2i) to %7.2f-%7.2f",axis,ax->GetBinLowEdge(bin0),ax->GetBinUpEdge(bin1)) << endl;
98 auto hg = sp->Projection(0);
100 _val = hg->IntegralAndError(1, hg->GetNbinsX(), _err);
105 TH1D*
sparse_proj(THnSparseD* sp,
int i_ax,
string name=
"",
bool norm_bin_width=
false) {
106 auto hg = (TH1D*) sp->Projection(i_ax);
107 if (
name !=
"") hg->SetName(
name.c_str());
120 array<int,5> i0_zdcx { 5, 8, 11, 14, 17 };
121 array<int,5> i1_zdcx { 7, 10, 13, 16, 19 };
123 tuBinVec bins_5by3to20 {{ 5000., 5000., 5, 20000 }};
129 TH1D* hg_out =
new TH1D(name.c_str(),
";ZDCx;Tracking Efficiency", bins_5by3to20, bins_5by3to20 );
131 for (
int i=0;
i<5; ++
i) {
133 auto h_reco = (TH1D*) reco->Projection(
_pt); h_reco ->SetName(
noiUniqueName());
134 auto h_truth = (TH1D*) truth->Projection(
_pt); h_truth->SetName(
noiUniqueName());
136 _val = h_reco->IntegralAndError(3,h_reco->GetNbinsX(),_err);
137 cout <<
" i("<<i<<
") val("<<_val<<
" +/- "<<_err<<
") ----> " << _err/_val << endl;
138 double norm = h_truth->Integral(3,h_truth->GetNbinsX());
141 if (norm == 0)
continue;
144 hg_out->SetBinContent(i+1,_val);
145 hg_out->SetBinError (i+1,_err);
151 if (vdat.size()==0)
return nullptr;
153 for (
auto bin=1; bin<=hg_new->GetNbinsX(); ++bin) {
154 double val0 = abs(hg_new->GetBinContent(bin));
155 for (
auto ihg=0; ihg<vdat.size(); ++ihg) {
156 double val1 = abs(vdat[ihg]->GetBinContent(bin));
157 if (val1>val0) val0 = val1;
159 hg_new->SetBinContent(bin,val0);
160 hg_new->SetBinError(bin,0);
168 for (
int i=1;
i<=nom->GetNbinsX(); ++
i) {
169 if (nom->GetBinContent(
i) != 0) {
170 auto v_nom = nom->GetBinContent(
i);
171 auto v_comp = comp->GetBinContent(
i);
172 hg_new->SetBinContent(
i, TMath::Abs(v_comp-v_nom)/v_nom);
181 for (
int i=1;
i<=nom->GetNbinsX(); ++
i) {
183 auto v_nom = nom->GetBinContent(
i);
184 auto v_comp = comp->GetBinContent(
i);
185 hg_new->SetBinContent(
i, TMath::Abs(v_comp-v_nom));
192 auto hg_new = (TH1D*) nom->Clone(name.c_str());
194 for (
int i=1;
i<=hg_new->GetNbinsX(); ++
i) {
195 hg_new->SetBinContent(
i, val);
201 auto hg_new = (TH1D*) vec[0]->Clone(name.c_str());
203 for (
auto& hg : vec) {
204 for (
int i=1;
i<=hg_new->GetNbinsX(); ++
i) {
205 hg_new->SetBinContent(
i, hg_new->GetBinContent(
i) + TMath::Sq(hg->GetBinContent(
i)));
208 for (
int i=1;
i<=hg_new->GetNbinsX(); ++
i) {
209 hg_new->SetBinContent(
i, TMath::Sqrt(hg_new->GetBinContent(
i)));
215 auto hg_new = (TH1D*) hg_nom->Clone(name.c_str());
216 for (
int i=1;
i<=hg_new->GetNbinsX(); ++
i) {
217 hg_new->SetBinError(
i, hg_nom->GetBinContent(
i) * hg_rss->GetBinContent(
i));