28 #include "TGraphErrors.h" 30 #include "CLHEP/Units/GlobalPhysicalConstants.h" 48 const HepMC::FourVector &
vtx,
49 const HepMC::FourVector &mom,
81 :
h_de_xi(new TH1D(
"",
";#xi_{reco} - #xi_{simu}", 100, 0., 0.)),
82 p_de_xi_vs_xi_simu(new TProfile(
"",
";#xi_{simu};#xi_{reco} - #xi_{simu}", 50, 0., 0.25)),
85 h_de_th_x(new TH1D(
"",
";#theta_{x,reco} - #theta_{x,simu}", 100, 0., 0.)),
86 p_de_th_x_vs_xi_simu(new TProfile(
"",
";#xi_{simu};#theta_{x,reco} - #theta_{x,simu}", 50, 0., 0.25)),
88 h_de_th_y(new TH1D(
"",
";#theta_{y,reco} - #theta_{y,simu}", 100, 0., 0.)),
89 p_de_th_y_vs_xi_simu(new TProfile(
"",
";#xi_{simu};#theta_{y,reco} - #theta_{y,simu}", 50, 0., 0.25)),
91 h_de_vtx_y(new TH1D(
"",
";vtx_{y,reco} - vtx_{y,simu} (mm)", 100, 0., 0.)),
92 p_de_vtx_y_vs_xi_simu(new TProfile(
"",
";#xi_{simu};vtx_{y,reco} - vtx_{y,simu} (mm)", 50, 0., 0.25)),
94 h_de_t(new TH1D(
"",
";t_{reco} - t_{simu}", 100, -1., +1.)),
95 p_de_t_vs_xi_simu(new TProfile(
"",
";xi_{simu};t_{reco} - t_{simu}", 50, 0., 0.25)),
96 p_de_t_vs_t_simu(new TProfile(
"",
";t_{simu};t_{reco} - t_{simu}", 20, 0., 5.)),
97 h2_de_t_vs_t_simu(new TH2D(
"",
";t_{simu};t_{reco} - t_{simu}", 150, 0., 5., 300, -2., +2.)) {}
101 gr_err.SetName(
name);
103 for (
int bi = 1; bi <=
p->GetNbinsX(); ++bi) {
104 double c =
p->GetBinCenter(bi);
105 double w =
p->GetBinWidth(bi);
107 double N =
p->GetBinEntries(bi);
108 double Sy =
p->GetBinContent(bi) *
N;
109 double Syy =
p->GetSumw2()->At(bi);
111 double si_sq = Syy /
N - Sy * Sy /
N /
N;
112 double si = (si_sq >= 0.) ?
sqrt(si_sq) : 0.;
113 double si_unc_sq = si_sq / 2. /
N;
114 double si_unc = (si_unc_sq >= 0.) ?
sqrt(si_unc_sq) : 0.;
116 int idx = gr_err.GetN();
117 gr_err.SetPoint(
idx,
c, si);
118 gr_err.SetPointError(
idx,
w / 2., si_unc);
151 std::map<unsigned int, std::map<unsigned int, PlotGroup>>
plots_;
158 :
h2_t_sh_vs_vtx_t(new TH2D(
"",
";vtx_t (mm);(t_56 + t_45)/2 (mm)", 100, -250., +250., 100, -250., +250.)),
159 h2_t_dh_vs_vtx_z(new TH2D(
"",
";vtx_z (mm);(t_56 - t_45)/2 (mm)", 100, -250., +250., 100, -250., +250.)),
161 h_t_dh_minus_vtx_z(new TH1D(
"",
";(t_56 - t_45)/2 - vtx_z (mm)", 100, -100., +100.)) {}
163 void fill(
double time_45,
double time_56,
double vtx_z,
double vtx_t) {
164 const double t_sum_half = (time_56 + time_45) / 2. * CLHEP::c_light;
165 const double t_dif_half = (time_56 - time_45) / 2. * CLHEP::c_light;
190 using namespace HepMC;
196 : tokenHepMCBeforeSmearing_(
198 tokenHepMCAfterSmearing_(
200 tokenRecoProtonsSingleRP_(
202 tokenRecoProtonsMultiRP_(
205 outputFile_(iConfig.getParameter<
string>(
"outputFile")) {}
229 bool vertex_set =
false;
231 for (
auto it = hepMCEventAfterSmearing->vertices_begin(); it != hepMCEventAfterSmearing->vertices_end(); ++it) {
233 LogError(
"CTPPSProtonReconstructionSimulationValidator") <<
"Multiple vertices found.";
238 vtx = (*it)->position();
242 bool proton_45_set =
false;
243 bool proton_56_set =
false;
244 FourVector mom_45, mom_56;
246 for (
auto it = hepMCEventBeforeSmearing->particles_begin(); it != hepMCEventBeforeSmearing->particles_end(); ++it) {
247 const auto &
part = *it;
250 if (
part->pdg_id() != 2212)
253 if (
part->status() != 1)
259 const auto &mom =
part->momentum();
267 LogError(
"CTPPSProtonReconstructionSimulationValidator") <<
"Found multiple protons in sector 45.";
271 proton_45_set =
true;
276 LogError(
"CTPPSProtonReconstructionSimulationValidator") <<
"Found multiple protons in sector 56.";
280 proton_56_set =
true;
286 for (
const auto &
handle : {hRecoProtonsSingleRP, hRecoProtonsMultiRP}) {
287 for (
const auto &rec_pr : *
handle) {
288 if (!rec_pr.validFit())
291 unsigned int idx = 12345;
293 bool mom_set =
false;
298 mom_set = proton_45_set;
303 mom_set = proton_56_set;
310 unsigned int meth_idx = 1234;
315 CTPPSDetId rpId((*rec_pr.contributingLocalTracks().begin())->rpId());
316 idx = 100 * rpId.arm() + 10 * rpId.station() + rpId.rp();
327 bool time_set_45 =
false, time_set_56 =
false;
328 double time_45 = 0., time_56 = 0.;
329 for (
const auto &rec_pr : *hRecoProtonsMultiRP) {
330 if (!rec_pr.validFit())
334 if (rec_pr.timeError() < 1E-3)
339 time_45 = rec_pr.time();
343 time_56 = rec_pr.time();
347 if (time_set_45 && time_set_56)
356 const HepMC::FourVector &
vtx,
357 const HepMC::FourVector &mom,
359 const double p_nom = lhcInfo.
energy();
360 const double xi_simu = (p_nom - mom.rho()) / p_nom;
361 const double th_x_simu = mom.x() / mom.rho();
362 const double th_y_simu = mom.y() / mom.rho();
363 const double vtx_y_simu =
vtx.y();
364 const double th_simu =
sqrt(th_x_simu * th_x_simu + th_y_simu * th_y_simu);
367 const double xi_reco = rec_pr.
xi();
368 const double th_x_reco = rec_pr.
thetaX();
369 const double th_y_reco = rec_pr.
thetaY();
370 const double vtx_y_reco = rec_pr.
vertex().y() * 10.;
371 const double t_reco = -rec_pr.
t();
375 plt.h_xi_reco_vs_xi_simu->Fill(xi_simu, xi_reco);
376 plt.h_de_xi->Fill(xi_reco - xi_simu);
377 plt.p_de_xi_vs_xi_simu->Fill(xi_simu, xi_reco - xi_simu);
379 plt.h_de_th_x->Fill(th_x_reco - th_x_simu);
380 plt.p_de_th_x_vs_xi_simu->Fill(xi_simu, th_x_reco - th_x_simu);
382 plt.h_de_th_y->Fill(th_y_reco - th_y_simu);
383 plt.p_de_th_y_vs_xi_simu->Fill(xi_simu, th_y_reco - th_y_simu);
385 plt.h_de_vtx_y->Fill(vtx_y_reco - vtx_y_simu);
386 plt.p_de_vtx_y_vs_xi_simu->Fill(xi_simu, vtx_y_reco - vtx_y_simu);
388 plt.h_de_t->Fill(t_reco - t_simu);
389 plt.p_de_t_vs_xi_simu->Fill(xi_simu, t_reco - t_simu);
390 plt.p_de_t_vs_t_simu->Fill(t_simu, t_reco - t_simu);
391 plt.h2_de_t_vs_t_simu->Fill(t_simu, t_reco - t_simu);
397 auto f_out = std::make_unique<TFile>(
outputFile_.c_str(),
"recreate");
399 for (
const auto &mit :
plots_) {
400 const char *
method = (mit.first == 0) ?
"single rp" :
"multi rp";
401 TDirectory *d_method = f_out->mkdir(
method);
403 for (
const auto &eit : mit.second) {
404 gDirectory = d_method->mkdir(Form(
"%i", eit.first));
409 gDirectory = f_out->mkdir(
"double arm");
std::unique_ptr< TH1D > h_de_t
CTPPSProtonReconstructionSimulationValidator(const edm::ParameterSet &)
std::unique_ptr< TProfile > p_de_th_x_vs_xi_simu
static float calculateT(double beam_mom, double proton_mom, double theta)
compute the squared four-momentum transfer from incident and scattered momenta, and angular informati...
#define DEFINE_FWK_MODULE(type)
float thetaY() const
horizontal scattering angle, in rad
std::unique_ptr< TH1D > h_t_dh_minus_vtx_z
float const energy() const
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsSingleRP_
float thetaX() const
vertical scattering angle, in rad
Log< level::Error, false > LogError
std::unique_ptr< TProfile > p_de_th_y_vs_xi_simu
std::unique_ptr< TH2D > h2_t_dh_vs_vtx_z
std::unique_ptr< TH1D > h_de_th_y
std::unique_ptr< TProfile > p_de_t_vs_xi_simu
edm::ESGetToken< LHCInfo, LHCInfoRcd > lhcInfoESToken_
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsMultiRP_
bool getData(T &iHolder) const
float xi() const
longitudinal fractional momentum loss
std::unique_ptr< TH1D > h_de_vtx_y
const HepMC::GenEvent * GetEvent() const
std::unique_ptr< TH1D > h_de_th_x
std::unique_ptr< TH2D > h2_t_sh_vs_vtx_t
std::unique_ptr< TProfile > p_de_t_vs_t_simu
static TGraphErrors profileToRMSGraph(TProfile *p, const char *name="")
const Point & vertex() const
fitted vertex position
std::unique_ptr< TH1D > h_t_sh_minus_vtx_t
void fill(double time_45, double time_56, double vtx_z, double vtx_t)
void analyze(const edm::Event &, const edm::EventSetup &) override
Base class for CTPPS detector IDs.
std::unique_ptr< TH2D > h_xi_reco_vs_xi_simu
edm::EDGetTokenT< edm::HepMCProduct > tokenHepMCBeforeSmearing_
DoubleArmPlotGroup double_arm_plots_
std::unique_ptr< TH1D > h_de_xi
std::unique_ptr< TProfile > p_de_xi_vs_xi_simu
std::vector< ForwardProton > ForwardProtonCollection
Collection of ForwardProton objects.
edm::EDGetTokenT< edm::HepMCProduct > tokenHepMCAfterSmearing_
float t() const
four-momentum transfer squared, in GeV^2
std::unique_ptr< TH2D > h2_de_t_vs_t_simu
void fillPlots(unsigned int meth_idx, unsigned int idx, const reco::ForwardProton &rec_pr, const HepMC::FourVector &vtx, const HepMC::FourVector &mom, const LHCInfo &lhcInfo)
std::map< unsigned int, std::map< unsigned int, PlotGroup > > plots_
std::unique_ptr< TProfile > p_de_vtx_y_vs_xi_simu