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 Show latest version
1 file
+ 44
15
Compare changes
  • Side-by-side
  • Inline
@@ -20,6 +20,8 @@
@@ -20,6 +20,8 @@
#include "TF1.h"
#include "TF1.h"
#include "TH1D.h"
#include "TH1D.h"
#include <TFitResult.h>
#include <TFitResult.h>
 
#include "TSystem.h"
 
#include <fstream>
using ROOT::RDataFrame;
using ROOT::RDataFrame;
using namespace ROOT::VecOps;
using namespace ROOT::VecOps;
@@ -51,9 +53,17 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
@@ -51,9 +53,17 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
{"quantity", "resolution (in %)"},
{"quantity", "resolution (in %)"},
{"target", std::to_string(resolutionTarget)}}};
{"target", std::to_string(resolutionTarget)}}};
*/
*/
 
//gSystem->Exec("cp sim_output/sim_emcal_barrel_uniform_pions.root results/sim_emcal_barrel_uniform_pions.root");
ROOT::EnableImplicitMT();
ROOT::EnableImplicitMT();
ROOT::RDataFrame d0("events", input_fname);
ROOT::RDataFrame d0("events", input_fname);
 
auto colNames = d0.GetColumnNames();
 
 
ofstream out;
 
out.open("results/column_list.txt");
 
for (auto &&col : colNames){out << col << endl; cout << col << endl;}
 
out.close();
 
// Thrown Energy [GeV]
// Thrown Energy [GeV]
auto Ethr = [](std::vector<dd4pod::Geant4ParticleData> const& input) {
auto Ethr = [](std::vector<dd4pod::Geant4ParticleData> const& input) {
std::vector<double> result;
std::vector<double> result;
@@ -95,14 +105,36 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
@@ -95,14 +105,36 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
return result;
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)/Esampling
 
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("fsam", fsam2, {"Esim","Ethr"})
.Define("dE", "Ethr-Esim")
.Define("dE", eResol, {"Esim", "Ethr"})
.Define("dE_rel", "(Ethr - Esim)/Esim")
.Define("dE_rel", eResol_rel, {"Esim", "Ethr"})
;
;
// Define Histograms
// Define Histograms
@@ -156,12 +188,10 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
@@ -156,12 +188,10 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
c4->SaveAs("results/emcal_barrel_pions_fsam.pdf");
c4->SaveAs("results/emcal_barrel_pions_fsam.pdf");
//Energy Resolution Work
//Energy Resolution Work
auto hdE = d1.Histo1D({"hdE", "dE; dE[GeV]; Events", 100, -7.5, 7.5}, "dE");
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", 100, -7.5, 7.5}, "dE_rel");
auto hdE_rel = d1.Histo1D({"hdE_rel", "dE Relative; dE Relative; Events", 20, -7.5, 7.5}, "dE_rel");//changed from 100
TFitResultPtr f1 = hdE_rel->Fit("gaus", "S");
//hdE_rel->Fit("gaus", "", "", -7.5, 7.5);
const double* res = f1->GetParams();
//double* res = hdE_rel->GetFunction("gaus")->GetParameters();
auto tf1 = new TF1("", "TMath::Gaus(x, [0], [1], [2])", -7.5, 7.5);
tf1 -> SetParameters(res[0], res[1], res[2]);
//Pass/Fail
//Pass/Fail
/*
/*
@@ -171,7 +201,7 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
@@ -171,7 +201,7 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
pion0_energy_resolution.fail(res[2]);
pion0_energy_resolution.fail(res[2]);
}
}
*/
*/
std::printf("Energy Resolution is %f\n", res[2]);
//std::printf("Energy Resolution is %f\n", res[2]);
//Energy Resolution Histogram Plotting
//Energy Resolution Histogram Plotting
auto *cdE = new TCanvas("cdE", "cdE", 700, 500);
auto *cdE = new TCanvas("cdE", "cdE", 700, 500);
@@ -187,10 +217,9 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
@@ -187,10 +217,9 @@ void emcal_barrel_pions_analysis(const char* input_fname = "sim_output/sim_emcal
hdE_rel->GetYaxis()->SetTitleOffset(1.4);
hdE_rel->GetYaxis()->SetTitleOffset(1.4);
hdE_rel->SetLineWidth(2);
hdE_rel->SetLineWidth(2);
hdE_rel->SetLineColor(kBlue);
hdE_rel->SetLineColor(kBlue);
tf1->SetLineWidth(2);
//hdE_rel->GetFunction("gaus")->SetLineWidth(2);
tf1->SetLineColor(kRed);
//hdE_rel->GetFunction("gaus")->SetLineColor(kRed);
hdE_rel->DrawClone();
hdE_rel->DrawClone();
tf1->Draw("SAME");
cdE_rel->SaveAs("results/emcal_barrel_pi0_dE_rel.png");
cdE_rel->SaveAs("results/emcal_barrel_pi0_dE_rel.png");
cdE_rel->SaveAs("results/emcal_barrel_pi0_dE_rel.pdf");
cdE_rel->SaveAs("results/emcal_barrel_pi0_dE_rel.pdf");
Loading