25 #include "TGraphErrors.h"
66 for (
int bi = 1; bi <=
p->GetNbinsX(); ++bi) {
67 double c =
p->GetBinCenter(bi);
69 double N =
p->GetBinEntries(bi);
70 double Sy =
p->GetBinContent(bi) *
N;
71 double Syy =
p->GetSumw2()->At(bi);
73 double si_sq = Syy /
N - Sy * Sy /
N /
N;
74 double si = (si_sq >= 0.) ?
sqrt(si_sq) : 0.;
75 double si_unc_sq = si_sq / 2. /
N;
76 double si_unc = (si_unc_sq >= 0.) ?
sqrt(si_unc_sq) : 0.;
79 g->SetPoint(
idx,
c, si);
80 g->SetPointError(
idx, 0., si_unc);
90 struct SingleRPPlots {
92 std::unique_ptr<TH1D>
h_xi;
101 h_xi(new TH1D(
"",
";#xi", 100, 0., 0.3)),
102 h2_th_y_vs_xi(new TH2D(
"",
";#xi;#theta_{y} (rad)", 100, 0., 0.3, 100, -500E-6, +500E-6)),
103 p_th_y_vs_xi(new TProfile(
"",
";#xi;#theta_{y} (rad)", 100, 0., 0.3)),
104 h_xi_n1f1(new TH1D(
"",
";#xi", 100, 0., 0.3)) {
105 for (
unsigned int n = 2;
n <= 10; ++
n)
113 const double th_y =
p.thetaY();
119 it->second->Fill(
p.xi());
133 TDirectory *d_top = gDirectory;
135 gDirectory = d_top->mkdir(
"h_xi_nTracks");
138 sprintf(
buf,
"h_xi_nTracks_%u",
p.first);
139 p.second->Write(
buf);
171 :
h_multiplicity(new TH1D(
"",
";reconstructed protons per event", 11, -0.5, 10.5)),
172 h_xi(new TH1D(
"",
";#xi", 100, 0., 0.3)),
173 h_th_x(new TH1D(
"",
";#theta_{x} (rad)", 250, -500E-6, +500E-6)),
174 h_th_y(new TH1D(
"",
";#theta_{y} (rad)", 500, -1000E-6, +1000E-6)),
175 h_vtx_y(new TH1D(
"",
";vtx_{y} (cm)", 100, -100E-3, +100E-3)),
176 h_chi_sq(new TH1D(
"",
";#chi^{2}", 100, 0., 10.)),
177 h_log_chi_sq(new TH1D(
"",
";log_{10} #chi^{2}", 100, -20., 5.)),
179 h_time(new TH1D(
"",
";time", 100, -2., +2.)),
182 h2_th_x_vs_xi(new TH2D(
"",
";#xi;#theta_{x} (rad)", 100, 0., 0.3, 100, -500E-6, +500E-6)),
183 h2_th_y_vs_xi(new TH2D(
"",
";#xi;#theta_{y} (rad)", 100, 0., 0.3, 100, -500E-6, +500E-6)),
184 h2_vtx_y_vs_xi(new TH2D(
"",
";#xi;vtx_{y} (cm)", 100, 0., 0.3, 100, -100E-3, +100E-3)),
185 p_th_x_vs_xi(new TProfile(
"",
";#xi;#theta_{x} (rad)", 100, 0., 0.3)),
186 p_th_y_vs_xi(new TProfile(
"",
";#xi;#theta_{y} (rad)", 100, 0., 0.3)),
187 p_vtx_y_vs_xi(new TProfile(
"",
";#xi;vtx_{y} (cm)", 100, 0., 0.3)),
189 new TH2D(
"",
";reco protons per event;timing tracks per event", 11, -0.5, 10.5, 11, -0.5, 10.5)),
190 h_xi_n1f1(new TH1D(
"",
";#xi", 100, 0., 0.3)),
199 new TH1D(
"",
";match between tracking and timing tracks", 2, -0.5, +1.5)),
204 std::vector<double> v_t_bin_edges;
205 for (
double t = 0;
t <= 5.;) {
206 v_t_bin_edges.push_back(
t);
207 const double de_t = 0.05 + 0.09 *
t + 0.02 *
t *
t;
210 h_t_unif.reset(
new TH1D(
"",
";|t| (GeV^2)", 100, 0., 5.));
211 h_t.reset(
new TH1D(
"",
";|t| (GeV^2)", v_t_bin_edges.size() - 1, v_t_bin_edges.data()));
212 h_t_xi_range1.reset(
new TH1D(
"",
";|t| (GeV^2)", v_t_bin_edges.size() - 1, v_t_bin_edges.data()));
213 h_t_xi_range2.reset(
new TH1D(
"",
";|t| (GeV^2)", v_t_bin_edges.size() - 1, v_t_bin_edges.data()));
214 h_t_xi_range3.reset(
new TH1D(
"",
";|t| (GeV^2)", v_t_bin_edges.size() - 1, v_t_bin_edges.data()));
216 new TH2D(
"",
";#xi;|t| (GeV^2)", 100, 0., 0.3, v_t_bin_edges.size() - 1, v_t_bin_edges.data()));
218 for (
unsigned int n = 2;
n <= 10; ++
n)
226 unsigned int n_contrib_tracking_tracks = 0, n_contrib_timing_tracks = 0;
227 for (
const auto &tr :
p.contributingLocalTracks()) {
230 n_contrib_tracking_tracks++;
232 n_contrib_timing_tracks++;
235 const double th_x =
p.thetaX();
236 const double th_y =
p.thetaY();
237 const double mt = -
p.t();
256 if (
p.xi() > 0.04 &&
p.xi() < 0.07)
258 if (
p.xi() > 0.07 &&
p.xi() < 0.10)
260 if (
p.xi() > 0.10 &&
p.xi() < 0.13)
276 it->second->Fill(
p.xi());
299 auto g_th_x_RMS_vs_xi = std::make_unique<TGraphErrors>();
301 g_th_x_RMS_vs_xi->Write(
"g_th_x_RMS_vs_xi");
306 auto g_th_y_RMS_vs_xi = std::make_unique<TGraphErrors>();
308 g_th_y_RMS_vs_xi->Write(
"g_th_y_RMS_vs_xi");
313 auto g_vtx_y_RMS_vs_xi = std::make_unique<TGraphErrors>();
315 g_vtx_y_RMS_vs_xi->Write(
"g_vtx_y_RMS_vs_xi");
317 h_t->Scale(1.,
"width");
329 TDirectory *d_top = gDirectory;
331 gDirectory = d_top->mkdir(
"h_xi_nTracks");
334 sprintf(
buf,
"h_xi_nTracks_%u",
p.first);
335 p.second->Write(
buf);
369 h_xi_diff_mu_si(new TH1D(
"",
";#xi_{multi} - #xi_{single}", 100, -0.1, +0.1)),
370 h_xi_diff_si_mu(new TH1D(
"",
";#xi_{single} - #xi_{multi}", 100, -0.1, +0.1)),
372 new TH2D(
"",
";#xi_{multi};#xi_{single} - #xi_{multi}", 100, 0., 0.3, 100, -0.10, 0.10)),
375 new TH2D(
"",
";#theta^{*}_{y,si};#theta^{*}_{y,mu}", 100, -500E-6, +500E-6, 100, -500E-6, +500E-6)) {}
386 const double th_y_si = p_single.
thetaY();
387 const double th_y_mu = p_multi.
thetaY();
419 h_th_y_si_diffNF(new TH1D(
"",
";#theta_{y,sF} - #theta_{y,sN}", 100, -100E-6, +100E-6)),
426 const double th_y_s_N = p_s_N.
thetaY();
427 const double th_y_s_F = p_s_F.
thetaY();
464 tokenRecoProtonsSingleRP_(
466 tokenRecoProtonsMultiRP_(
469 rpId_45_N_(ps.getParameter<unsigned
int>(
"rpId_45_N")),
470 rpId_45_F_(ps.getParameter<unsigned
int>(
"rpId_45_F")),
471 rpId_56_N_(ps.getParameter<unsigned
int>(
"rpId_56_N")),
472 rpId_56_F_(ps.getParameter<unsigned
int>(
"rpId_56_F")),
474 outputFile_(ps.getParameter<
string>(
"outputFile")),
475 maxNonEmptyEvents_(ps.getUntrackedParameter<signed
int>(
"maxNonEmptyEvents", -1)),
477 p_x_L_diffNF_vs_x_L_N_(new TProfile(
"p_x_L_diffNF_vs_x_L_N",
";x_{LN};x_{LF} - x_{LN}", 100, 0., +20.)),
478 p_x_R_diffNF_vs_x_R_N_(new TProfile(
"p_x_R_diffNF_vs_x_R_N",
";x_{RN};x_{RF} - x_{RN}", 100, 0., +20.)),
480 p_y_L_diffNF_vs_y_L_N_(new TProfile(
"p_y_L_diffNF_vs_y_L_N",
";y_{LN};y_{LF} - y_{LN}", 100, -20., +20.)),
481 p_y_R_diffNF_vs_y_R_N_(new TProfile(
"p_y_R_diffNF_vs_y_R_N",
";y_{RN};y_{RF} - y_{RN}", 100, -20., +20.)),
483 n_non_empty_events_(0) {
485 const unsigned int arm = (sector ==
"45") ? 0 : 1;
501 const double z_i =
geometry.rpTranslation(tr_i.rpId()).
z();
502 const double z_j =
geometry.rpTranslation(tr_j.rpId()).
z();
505 const double z_ti = -
geometry.rpTranslation(tr_ti.
rpId()).
z();
506 const double f_i = (z_ti - z_j) / (z_i - z_j), f_j = (z_i - z_ti) / (z_i - z_j);
507 const double x_inter = f_i * tr_i.x() + f_j * tr_j.x();
508 const double x_inter_unc_sq = f_i * f_i * tr_i.xUnc() * tr_i.xUnc() + f_j * f_j * tr_j.xUnc() * tr_j.xUnc();
511 de_x = tr_ti.
x() - x_inter;
512 de_x_unc =
sqrt(tr_ti.
xUnc() * tr_ti.
xUnc() + x_inter_unc_sq);
528 if (!hRecoProtonsSingleRP->empty())
532 throw cms::Exception(
"CTPPSProtonReconstructionPlotter") <<
"Number of non empty events reached maximum.";
543 std::map<unsigned int, unsigned int> armTrackCounter, armTimingTrackCounter;
544 std::map<unsigned int, unsigned int> armTrackCounter_N, armTrackCounter_F;
546 for (
const auto &tr : *hTracks) {
548 unsigned int decRPId =
rpId.arm() * 100 +
rpId.station() * 10 +
rpId.rp();
552 armTrackCounter_N[0]++;
556 armTrackCounter_F[0]++;
560 armTrackCounter_N[1]++;
564 armTrackCounter_F[1]++;
567 armTrackCounter[
rpId.arm()]++;
569 const bool trackerRP =
572 armTimingTrackCounter[
rpId.arm()]++;
575 if (tr_L_N && tr_L_F) {
580 if (tr_R_N && tr_R_F) {
586 std::map<unsigned int, unsigned int> singleRPMultiplicity, multiRPMultiplicity;
589 multiRPMultiplicity[0] = multiRPMultiplicity[1] = 0;
592 for (
const auto &proton : *hRecoProtonsSingleRP) {
594 unsigned int decRPId =
rpId.arm() * 100 +
rpId.station() * 10 +
rpId.rp();
596 const bool n1f1 = (armTrackCounter_N[
rpId.arm()] == 1 && armTrackCounter_F[
rpId.arm()] == 1);
600 if (proton.validFit())
601 singleRPMultiplicity[decRPId]++;
604 for (
const auto it : singleRPMultiplicity)
608 for (
const auto &proton : *hRecoProtonsMultiRP) {
610 unsigned int armId =
rpId.arm();
612 const bool n1f1 = (armTrackCounter_N[armId] == 1 && armTrackCounter_F[armId] == 1);
614 multiRPPlots_[armId].fill(proton, armTrackCounter[armId], n1f1);
616 if (proton.validFit())
617 multiRPMultiplicity[armId]++;
620 for (
const auto it : multiRPMultiplicity) {
622 pl.h_multiplicity->Fill(it.second);
623 pl.h2_timing_tracks_vs_prot_mult->Fill(it.second, armTimingTrackCounter[it.first]);
627 map<unsigned int, bool> clCo;
628 clCo[0] = (singleRPMultiplicity[
rpId_45_N_] && singleRPMultiplicity[
rpId_45_F_] && multiRPMultiplicity[0] == 1);
629 clCo[1] = (singleRPMultiplicity[
rpId_56_N_] && singleRPMultiplicity[
rpId_56_F_] && multiRPMultiplicity[1] == 1);
632 for (
const auto &proton : *hRecoProtonsMultiRP) {
633 if (!proton.validFit())
636 CTPPSDetId rpId_proton((*proton.contributingLocalTracks().begin())->
rpId());
637 unsigned int armId = rpId_proton.
arm();
640 for (
const auto &tr : *hTracks) {
642 if (rpId_tr.arm() != armId)
645 const bool trackerRP =
650 double de_x = 0., de_x_unc = 0.;
653 const double rd = (de_x_unc > 0.) ?
de_x / de_x_unc : -1E10;
655 const bool match = (ac.ti_tr_min <= fabs(rd) && fabs(rd) <= ac.ti_tr_max);
657 pl.h_de_x_timing_vs_tracking->Fill(
de_x);
658 pl.h_de_x_rel_timing_vs_tracking->Fill(rd);
659 pl.h_de_x_match_timing_vs_tracking->Fill(
match ? 1. : 0.);
661 if (clCo[armId] && armTimingTrackCounter[armId] == 1) {
662 pl.h_de_x_timing_vs_tracking_ClCo->Fill(
de_x);
663 pl.h_de_x_rel_timing_vs_tracking_ClCo->Fill(rd);
664 pl.h_de_x_match_timing_vs_tracking_ClCo->Fill(
match ? 1. : 0.);
670 for (
const auto &proton : *hRecoProtonsMultiRP) {
671 if (!proton.validFit())
675 unsigned int armId =
rpId.arm();
677 const auto &nTimingTracks = armTimingTrackCounter[armId];
682 double x_ref = 0., y_ref = 0.;
692 if (nTimingTracks == 0)
693 pl.h2_y_vs_x_tt0_ClCo->Fill(x_ref, y_ref);
694 if (nTimingTracks == 1)
695 pl.h2_y_vs_x_tt1_ClCo->Fill(x_ref, y_ref);
696 if (nTimingTracks > 1)
697 pl.h2_y_vs_x_ttm_ClCo->Fill(x_ref, y_ref);
701 for (
const auto &proton_m : *hRecoProtonsMultiRP) {
702 CTPPSDetId rpId_m((*proton_m.contributingLocalTracks().begin())->
rpId());
703 unsigned int arm = rpId_m.
arm();
707 for (
const auto &proton_s : *hRecoProtonsSingleRP) {
710 bool compatible =
false;
711 for (
const auto &tr_m : proton_m.contributingLocalTracks()) {
712 if (tr_m.key() == key_s) {
722 CTPPSDetId rpId_s((*proton_s.contributingLocalTracks().begin())->
rpId());
723 const unsigned int idx = rpId_s.arm() * 1000 + rpId_s.station() * 100 + rpId_s.rp() * 10 + rpId_s.arm();
727 const unsigned int rpDecId_s = rpId_s.arm() * 100 + rpId_s.station() * 10 + rpId_s.rp();
745 auto f_out = std::make_unique<TFile>(
outputFile_.c_str(),
"recreate");
753 TDirectory *d_singleRPPlots = f_out->mkdir(
"singleRPPlots");
755 gDirectory = d_singleRPPlots->mkdir(Form(
"rp%u", it.first));
759 TDirectory *d_multiRPPlots = f_out->mkdir(
"multiRPPlots");
761 gDirectory = d_multiRPPlots->mkdir(Form(
"arm%u", it.first));
765 TDirectory *d_singleMultiCorrelationPlots = f_out->mkdir(
"singleMultiCorrelationPlots");
767 unsigned int si_rp = it.first / 10;
768 unsigned int mu_arm = it.first % 10;
770 gDirectory = d_singleMultiCorrelationPlots->mkdir(Form(
"si_rp%u_mu_arm%u", si_rp, mu_arm));
774 TDirectory *d_armCorrelationPlots = f_out->mkdir(
"armCorrelationPlots");
776 gDirectory = d_armCorrelationPlots->mkdir(Form(
"arm%u", it.first));