Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-25 09:24:25

0001 #include <TH1D.h>
0002 #include <TH2D.h>
0003 #include <TF1.h>
0004 
0005 TH1D* extractResolution(TString outputHistoName, TH2D* twoDHisto, bool saveOutput = false){
0006 
0007     int num_bins  = twoDHisto->GetNbinsX();
0008     double xBinWidth = twoDHisto->GetXaxis()->GetBinWidth(1); 
0009     double xMin = twoDHisto->GetXaxis()->GetBinCenter(1) - xBinWidth*0.5;
0010     double xMax = twoDHisto->GetXaxis()->GetBinCenter(num_bins) + xBinWidth*0.5;
0011 
0012     TH1D * finalResoHisto = new TH1D(outputHistoName, outputHistoName, num_bins, xMin, xMax);
0013 
0014     TH1D* tmp;
0015     double rmsReso = 0.0;
0016     double rmsErr = 0.0;
0017     for(int bin = 0; bin < num_bins+1; bin++){
0018     
0019         rmsReso = 0.0;
0020         tmp = (TH1D*)twoDHisto->ProjectionY("NEIN", bin, bin+1);
0021         TF1 * func = new TF1("fitFunc", "gaus", -1.0, 1.0);
0022         tmp->Fit(func, "Q0");
0023         
0024         //TCanvas * canRes = new TCanvas("canRes1", "canRes1", 500, 500);
0025         //tmp->Draw();
0026         //if(saveOutput){
0027         //  if(outputHistoName == "b0_extracted_pt_resolution"){
0028         //      canRes->SaveAs(Form("./resolutionFitOutput/pt_resolution_fits_bin_%d.pdf", bin));
0029         //  }
0030         //  else canRes->SaveAs(Form("./resolutionFitOutput/p_resolution_fits_bin_%d.pdf", bin));
0031         //}
0032         //rmsReso = tmp->GetRMS();
0033         //rmsErr  = tmp->GetRMSError();
0034 
0035         rmsReso = func->GetParameter(2);
0036         rmsErr  = func->GetParError(2);
0037 
0038         cout << "resolution from Gaussian fit = " << rmsReso << endl;
0039         cout << "error on resolution = " << rmsErr << endl;
0040     
0041         if(rmsErr/rmsReso > 0.5){ continue; }
0042     
0043         if(rmsErr > rmsReso){
0044             rmsReso = tmp->GetRMS();
0045             rmsErr  = tmp->GetRMSError();
0046         }
0047         
0048         finalResoHisto->SetBinContent(bin, rmsReso);
0049         finalResoHisto->SetBinError(bin, rmsErr);
0050         
0051         delete func;
0052     } 
0053 
0054 
0055     return finalResoHisto;
0056 
0057 }