File indexing completed on 2026-10-15 08:17:26
0001 #ifndef ZVTXAVERAGE_H
0002 #define ZVTXAVERAGE_H
0003
0004
0005
0006
0007 #include <cmath>
0008 #include "TH1.h"
0009
0010
0011
0012
0013
0014
0015
0016
0017 inline void ZvtxAverageValid(TH1* avg, TH1** sl, TH1** mask, const double* w, const bool* ok, int n, double sentinel){
0018 avg->Reset();
0019 double nent = 0;
0020 for (int z=0;z<n;z++) if (ok[z] && w[z]>0.) nent += w[z]*sl[z]->GetEntries();
0021 for (int ib=0;ib<avg->GetNcells();ib++){
0022 double sw=0, swv=0, sw2e2=0;
0023 for (int z=0;z<n;z++){
0024 if (!ok[z] || w[z]<=0.) continue;
0025 bool valid = mask ? (mask[z]->GetBinContent(ib)>0.) : (sl[z]->GetBinError(ib)>0.);
0026 if (!valid) continue;
0027 double e = sl[z]->GetBinError(ib);
0028 sw += w[z];
0029 swv += w[z]*sl[z]->GetBinContent(ib);
0030 sw2e2 += w[z]*w[z]*e*e;
0031 }
0032 if (sw>0.){ avg->SetBinContent(ib,swv/sw); avg->SetBinError(ib,sqrt(sw2e2)/sw); }
0033 else { avg->SetBinContent(ib,sentinel); avg->SetBinError(ib,0.); }
0034 }
0035 avg->SetEntries(nent);
0036 }
0037
0038 #endif