Skip to content
Snippets Groups Projects

Resolve "pi0 resolution for ECal barrel"

Merged Marshall Scott requested to merge 19-pi0-resolution-for-ecal-barrel into master
Compare and
1 file
+ 98
3
Compare changes
  • Side-by-side
  • Inline
@@ -9,12 +9,17 @@
@@ -9,12 +9,17 @@
#include "dd4pod/Geant4ParticleCollection.h"
#include "dd4pod/Geant4ParticleCollection.h"
#include "dd4pod/CalorimeterHitCollection.h"
#include "dd4pod/CalorimeterHitCollection.h"
 
//#include <detector_benchmarks/include/benchmark.h>
 
//#include "mt.h"
 
//#include "util.h"
 
#include "TCanvas.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TStyle.h"
#include "TMath.h"
#include "TMath.h"
#include "TH1.h"
#include "TH1.h"
#include "TF1.h"
#include "TF1.h"
#include "TH1D.h"
#include "TH1D.h"
 
#include <TFitResult.h>
using ROOT::RDataFrame;
using ROOT::RDataFrame;
using namespace ROOT::VecOps;
using namespace ROOT::VecOps;
@@ -32,6 +37,20 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
@@ -32,6 +37,20 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
gStyle->SetPadLeftMargin(0.14);
gStyle->SetPadLeftMargin(0.14);
gStyle->SetPadRightMargin(0.14);
gStyle->SetPadRightMargin(0.14);
 
//Tests
 
std::string test_tag = "Barrel_emcal_pi0";
 
//TODO: Change test_tag to something else
 
std:string detector = "Barrel_emcal";
 
double resolutionTarget = 0.1;
 
/*
 
eic::util::Test pion0_Energy_resolution{
 
{{"name", fmt::format("{}_energy_resolution", test_tag)},
 
{"title", "Pion0 Energy resolution"},
 
{"description",
 
fmt::format("Pion0 energy resolution with {}, estimated using a Gaussian fit.", detector)},
 
{"quantity", "resolution (in %)"},
 
{"target", std::to_string(resolutionTarget)}}};
 
*/
ROOT::EnableImplicitMT();
ROOT::EnableImplicitMT();
ROOT::RDataFrame d0("events", input_fname);
ROOT::RDataFrame d0("events", input_fname);
@@ -65,11 +84,47 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
@@ -65,11 +84,47 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
return result;
return result;
};
};
 
// Sampling fraction = Esampling / Ethrown, revised
 
auto fsam2 = [](const std::vector<double>& sampled, const std::vector<double>& thrown) {
 
std::vector<double> result;
 
auto it_sam = sampled.cbegin();
 
auto it_thr = thrown.cbegin();
 
for (; it_sam != sampled.end() && it_thr != thrown.end(); ++it_sam, ++it_thr) {
 
result.push_back(*it_sam / *it_thr);
 
}
 
return result;
 
};
 
 
// Energy Resolution = Esampling - Ethrown
 
auto eResol = [](const std::vector<double>& sampled, const std::vector<double>& thrown) {
 
std::vector<double> result;
 
auto it_sam = sampled.cbegin();
 
auto it_thr = thrown.cbegin();
 
for (; it_sam != sampled.end() && it_thr != thrown.end(); ++it_sam, ++it_thr) {
 
result.push_back(*it_sam - *it_thr);
 
}
 
return result;
 
};
 
 
// Relative Energy Resolution = (Esampling - Ethrown)/Ethrown
 
auto eResol_rel = [](const std::vector<double>& sampled, const std::vector<double>& thrown) {
 
std::vector<double> result;
 
auto it_sam = sampled.cbegin();
 
auto it_thr = thrown.cbegin();
 
for (; it_sam != sampled.end() && it_thr != thrown.end(); ++it_sam, ++it_thr) {
 
result.push_back((*it_sam - *it_thr) / *it_sam);
 
}
 
return result;
 
};
 
// Define variables
// Define variables
auto d1 = d0.Define("Ethr", Ethr, {"mcparticles"})
auto d1 = d0.Define("Ethr", Ethr, {"mcparticles"})
.Define("nhits", nhits, {"EcalBarrelHits"})
.Define("nhits", nhits, {"EcalBarrelHits"})
.Define("Esim", Esim, {"EcalBarrelHits"})
.Define("Esim", Esim, {"EcalBarrelHits"})
.Define("fsam", fsam, {"Esim","Ethr"})
//.Define("fsam", fsam, {"Esim","Ethr"})
 
.Define("fsam", fsam2, {"Esim","Ethr"})
 
.Define("dE", eResol, {"Esim", "Ethr"})
 
.Define("dE_rel", eResol_rel, {"Esim", "Ethr"})
;
;
// Define Histograms
// Define Histograms
@@ -121,4 +176,44 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
@@ -121,4 +176,44 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
hfsam->DrawClone();
hfsam->DrawClone();
c4->SaveAs("results/emcal_barrel_pions_fsam.png");
c4->SaveAs("results/emcal_barrel_pions_fsam.png");
c4->SaveAs("results/emcal_barrel_pions_fsam.pdf");
c4->SaveAs("results/emcal_barrel_pions_fsam.pdf");
 
 
//Energy Resolution Work
 
auto hdE = d1.Histo1D({"hdE", "dE; dE[GeV]; Events", 20, -7.5, 7.5}, "dE");//changed from 100
 
auto hdE_rel = d1.Histo1D({"hdE_rel", "dE Relative; dE Relative; Events", 20, -7.5, 7.5}, "dE_rel");//changed from 100
 
hdE_rel->Fit("gaus", "", "", -7.5, 7.5);
 
//double* res = hdE_rel->GetFunction("gaus")->GetParameters();
 
 
//Pass/Fail
 
/*
 
if (res[2] <= resolutionTarget) {
 
pion0_energy_resolution.pass(res[2]);
 
} else {
 
pion0_energy_resolution.fail(res[2]);
 
}
 
*/
 
//std::printf("Energy Resolution is %f\n", res[2]);
 
 
//Energy Resolution Histogram Plotting
 
auto *cdE = new TCanvas("cdE", "cdE", 700, 500);
 
cdE->SetLogy(1);
 
hdE->GetYaxis()->SetTitleOffset(1.4);
 
hdE->SetLineWidth(2);
 
hdE->SetLineColor(kBlue);
 
hdE->DrawClone();
 
cdE->SaveAs("results/emcal_barrel_pi0_dE.png");
 
cdE->SaveAs("results/emcal_barrel_pi0_dE.pdf");
 
 
auto *cdE_rel = new TCanvas("cdE_rel", "cdE_rel", 700, 500);
 
hdE_rel->GetYaxis()->SetTitleOffset(1.4);
 
hdE_rel->SetLineWidth(2);
 
hdE_rel->SetLineColor(kBlue);
 
hdE_rel->GetFunction("gaus")->SetLineWidth(2);
 
hdE_rel->GetFunction("gaus")->SetLineColor(kRed);
 
hdE_rel->DrawClone();
 
cdE_rel->SaveAs("results/emcal_barrel_pi0_dE_rel.png");
 
cdE_rel->SaveAs("results/emcal_barrel_pi0_dE_rel.pdf");
 
 
//eic::util::write_test({pion0_energy_resolution}, fmt::format("{}_pions.json", detector));
 
 
}
}
Loading