28 #include "TGraphErrors.h" 45 const HepMC::FourVector &
vtx,
const HepMC::FourVector &mom,
const LHCInfo &lhcInfo);
76 h_de_xi(new TH1D(
"",
";#xi_{reco} - #xi_{simu}", 100, 0., 0.)),
77 p_de_xi_vs_xi_simu(new TProfile(
"",
";#xi_{simu};#xi_{reco} - #xi_{simu}", 19, 0.015, 0.205)),
78 h_xi_reco_vs_xi_simu(new TH2D(
"",
";#xi_{simu};#xi_{reco}", 100, 0., 0.30, 100, 0., 0.30)),
80 h_de_th_x(new TH1D(
"",
";#theta_{x,reco} - #theta_{x,simu}", 100, 0., 0.)),
81 p_de_th_x_vs_xi_simu(new TProfile(
"",
";#xi_{simu};#theta_{x,reco} - #theta_{x,simu}", 19, 0.015, 0.205)),
83 h_de_th_y(new TH1D(
"",
";#theta_{y,reco} - #theta_{y,simu}", 100, 0., 0.)),
84 p_de_th_y_vs_xi_simu(new TProfile(
"",
";#xi_{simu};#theta_{y,reco} - #theta_{y,simu}", 19, 0.015, 0.205)),
86 h_de_vtx_y(new TH1D(
"",
";vtx_{y,reco} - vtx_{y,simu} (mm)", 100, 0., 0.)),
87 p_de_vtx_y_vs_xi_simu(new TProfile(
"",
";#xi_{simu};vtx_{y,reco} - vtx_{y,simu} (mm)", 19, 0.015, 0.205)),
89 h_de_t(new TH1D(
"",
";t_{reco} - t_{simu}", 100, -1., +1.)),
90 p_de_t_vs_xi_simu(new TProfile(
"",
";xi_{simu};t_{reco} - t_{simu}", 19, 0.015, 0.205)),
91 p_de_t_vs_t_simu(new TProfile(
"",
";t_{simu};t_{reco} - t_{simu}", 20, 0., 5.))
99 for (
int bi = 1; bi <= p->GetNbinsX(); ++bi) {
100 double c = p->GetBinCenter(bi);
101 double w = p->GetBinWidth(bi);
103 double N = p->GetBinEntries(bi);
104 double Sy = p->GetBinContent(bi) *
N;
105 double Syy = p->GetSumw2()->At(bi);
107 double si_sq = Syy/N - Sy*Sy/N/
N;
108 double si = (si_sq >= 0.) ?
sqrt(si_sq) : 0.;
109 double si_unc_sq = si_sq / 2. /
N;
110 double si_unc = (si_unc_sq >= 0.) ?
sqrt(si_unc_sq) : 0.;
112 int idx = gr_err.GetN();
113 gr_err.SetPoint(idx, c, si);
114 gr_err.SetPointError(idx, w/2., si_unc);
122 h_xi_reco_vs_xi_simu->Write(
"h_xi_reco_vs_xi_simu");
123 h_de_xi->Write(
"h_de_xi");
124 p_de_xi_vs_xi_simu->Write(
"p_de_xi_vs_xi_simu");
127 h_de_th_x->Write(
"h_de_th_x");
128 p_de_th_x_vs_xi_simu->Write(
"p_de_th_x_vs_xi_simu");
129 profileToRMSGraph(p_de_th_x_vs_xi_simu.get(),
"g_rms_de_th_x_vs_xi_simu").Write();
131 h_de_th_y->Write(
"h_de_th_y");
132 p_de_th_y_vs_xi_simu->Write(
"p_de_th_y_vs_xi_simu");
133 profileToRMSGraph(p_de_th_y_vs_xi_simu.get(),
"g_rms_de_th_y_vs_xi_simu").Write();
135 h_de_vtx_y->Write(
"h_de_vtx_y");
136 p_de_vtx_y_vs_xi_simu->Write(
"p_de_vtx_y_vs_xi_simu");
137 profileToRMSGraph(p_de_vtx_y_vs_xi_simu.get(),
"g_rms_de_vtx_y_vs_xi_simu").Write();
139 h_de_t->Write(
"h_de_t");
140 p_de_t_vs_xi_simu->Write(
"p_de_t_vs_xi_simu");
142 p_de_t_vs_t_simu->Write(
"p_de_t_vs_t_simu");
147 std::map<unsigned int, std::map<unsigned int, PlotGroup>>
plots_;
154 using namespace HepMC;
191 bool vertex_set =
false;
193 for (
auto it = hepMCEventAfterSmearing->vertices_begin(); it != hepMCEventAfterSmearing->vertices_end(); ++it) {
195 LogError(
"CTPPSProtonReconstructionSimulationValidator") <<
"Multiple vertices found.";
200 vtx = (*it)->position();
204 bool proton_45_set =
false;
205 bool proton_56_set =
false;
206 FourVector mom_45, mom_56;
208 for (
auto it = hepMCEventBeforeSmearing->particles_begin(); it != hepMCEventBeforeSmearing->particles_end(); ++it) {
209 const auto &
part = *it;
212 if (
part->pdg_id() != 2212)
215 if (
part->status() != 1)
221 const auto &mom =
part->momentum();
229 LogError(
"CTPPSProtonReconstructionSimulationValidator") <<
"Found multiple protons in sector 45.";
233 proton_45_set =
true;
238 LogError(
"CTPPSProtonReconstructionSimulationValidator") <<
"Found multiple protons in sector 56.";
242 proton_56_set =
true;
248 for (
const auto&
handle : { hRecoProtonsSingleRP, hRecoProtonsMultiRP } ) {
249 for (
const auto& rec_pr : *
handle) {
250 if (! rec_pr.validFit())
255 bool mom_set =
false;
261 mom_set = proton_45_set;
265 mom_set = proton_56_set;
272 unsigned int meth_idx = 1234;
277 CTPPSDetId rpId((*rec_pr.contributingLocalTracks().begin())->getRPId());
278 idx = 100*rpId.
arm() + 10*rpId.station() + rpId.rp();
284 fillPlots(meth_idx, idx, rec_pr, vtx, mom, *hLHCInfo);
294 const double p_nom = lhcInfo.
energy();
295 const double xi_simu = (p_nom - mom.rho()) / p_nom;
296 const double th_x_simu = mom.x() / mom.rho();
297 const double th_y_simu = mom.y() / mom.rho();
298 const double vtx_y_simu = vtx.y();
299 const double th_simu =
sqrt(th_x_simu*th_x_simu + th_y_simu*th_y_simu);
302 const double xi_reco = rec_pr.
xi();
303 const double th_x_reco = rec_pr.
thetaX();
304 const double th_y_reco = rec_pr.
thetaY();
305 const double vtx_y_reco = rec_pr.
vertex().y() * 10.;
306 const double t_reco = - rec_pr.
t();
310 plt.h_xi_reco_vs_xi_simu->Fill(xi_simu, xi_reco);
311 plt.h_de_xi->Fill(xi_reco - xi_simu);
312 plt.p_de_xi_vs_xi_simu->Fill(xi_simu, xi_reco - xi_simu);
314 plt.h_de_th_x->Fill(th_x_reco - th_x_simu);
315 plt.p_de_th_x_vs_xi_simu->Fill(xi_simu, th_x_reco - th_x_simu);
317 plt.h_de_th_y->Fill(th_y_reco - th_y_simu);
318 plt.p_de_th_y_vs_xi_simu->Fill(xi_simu, th_y_reco - th_y_simu);
320 plt.h_de_vtx_y->Fill(vtx_y_reco - vtx_y_simu);
321 plt.p_de_vtx_y_vs_xi_simu->Fill(xi_simu, vtx_y_reco - vtx_y_simu);
323 plt.h_de_t->Fill(t_reco - t_simu);
324 plt.p_de_t_vs_xi_simu->Fill(xi_simu, t_reco - t_simu);
325 plt.p_de_t_vs_t_simu->Fill(t_simu, t_reco - t_simu);
332 auto f_out = std::make_unique<TFile>(
outputFile_.c_str(),
"recreate");
334 for (
const auto& mit :
plots_) {
335 const char*
method = (mit.first == 0) ?
"single rp" :
"multi rp";
336 TDirectory *d_method = f_out->mkdir(method);
338 for (
const auto& eit : mit.second) {
339 gDirectory = d_method->mkdir(Form(
"%i", eit.first));
const Point & vertex() const
fitted vertex position
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...
bool getByToken(EDGetToken token, Handle< PROD > &result) const
float t() const
four-momentum transfer squared, in GeV^2
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsSingleRP_
std::unique_ptr< TProfile > p_de_th_y_vs_xi_simu
float thetaX() const
vertical scattering angle, in rad
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::string lhcInfoLabel_
#define DEFINE_FWK_MODULE(type)
std::unique_ptr< TH1D > h_de_th_y
std::unique_ptr< TProfile > p_de_t_vs_xi_simu
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsMultiRP_
float xi() const
longitudinal fractional momentum loss
std::unique_ptr< TH1D > h_de_vtx_y
std::unique_ptr< TH1D > h_de_th_x
const HepMC::GenEvent * GetEvent() const
std::unique_ptr< TProfile > p_de_t_vs_t_simu
static TGraphErrors profileToRMSGraph(TProfile *p, const char *name="")
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
float const energy() const
edm::EDGetTokenT< edm::HepMCProduct > tokenHepMCBeforeSmearing_
float thetaY() const
horizontal scattering angle, in rad
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_
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