Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 08:10:29

0001 #ifndef GEOACCEPTANCECORRECTION_H
0002 #define GEOACCEPTANCECORRECTION_H
0003 
0004 #include "CorrectionHistogram1D.h"
0005 
0006 struct GeoAcceptanceCorrection : CorrectionHistogram1D
0007 {
0008   std::shared_ptr<TFile> f;
0009 
0010   GeoAcceptanceCorrection(std::string filename, std::string hname)
0011   {
0012     f = std::make_shared<TFile>(filename.c_str(),"READ");
0013     TCanvas* c = (TCanvas*)f->Get("myCanvas");
0014     h_corr = (TH1F*)c->GetPrimitive(hname.c_str())->Clone();
0015     // preserve histogram on file close
0016     h_corr->SetDirectory(nullptr);
0017     name = "geoacceptance";
0018     title = "geometric acceptance";
0019   }
0020 
0021   GeoAcceptanceCorrection(const GeoAcceptanceCorrection& g)
0022   {
0023     f = g.f;
0024     h_corr = g.h_corr;
0025     name = g.name;
0026     title = g.title;
0027   }
0028 
0029   void apply_correction(float xlow, float xhigh, TH1F* h, int bin) override
0030   {
0031     std::pair<double,double> corr_and_err = get_val_and_error(xlow,xhigh);
0032     float new_val = h->GetBinContent(bin)/corr_and_err.first;
0033     float new_err = new_val * sqrt(pow(h->GetBinError(bin)/h->GetBinContent(bin),2.)+pow(corr_and_err.second/corr_and_err.first,2.));
0034     h->SetBinContent(bin,new_val);
0035     h->SetBinError(bin,new_err);
0036   }
0037 
0038 };
0039 
0040 #endif