27 #include "TGraphErrors.h"
69 for (
int bi = 1; bi <=
p->GetNbinsX(); ++bi) {
70 double c =
p->GetBinCenter(bi);
72 double N =
p->GetBinEntries(bi);
73 double Sy =
p->GetBinContent(bi) *
N;
74 double Syy =
p->GetSumw2()->At(bi);
76 double si_sq = Syy /
N - Sy * Sy /
N /
N;
77 double si = (si_sq >= 0.) ?
sqrt(si_sq) : 0.;
78 double si_unc_sq = si_sq / 2. /
N;
79 double si_unc = (si_unc_sq >= 0.) ?
sqrt(si_unc_sq) : 0.;
82 g->SetPoint(
idx,
c, si);
83 g->SetPointError(
idx, 0., si_unc);
95 struct SingleRPPlots {
97 std::unique_ptr<TH1D>
h_xi;
106 h_xi(new TH1D(
"",
";#xi", 100, 0., 0.3)),
107 h2_th_y_vs_xi(new TH2D(
"",
";#xi;#theta_{y} (rad)", 100, 0., 0.3, 100, -500E-6, +500E-6)),
108 p_th_y_vs_xi(new TProfile(
"",
";#xi;#theta_{y} (rad)", 100, 0., 0.3)),
109 h_xi_n1f1(new TH1D(
"",
";#xi", 100, 0., 0.3)) {
110 for (
unsigned int n = 2;
n <= 10; ++
n)
118 const double th_y =
p.thetaY();
124 it->second->Fill(
p.xi());
138 TDirectory *d_top = gDirectory;
140 gDirectory = d_top->mkdir(
"h_xi_nTracks");
143 sprintf(
buf,
"h_xi_nTracks_%u",
p.first);
144 p.second->Write(
buf);
179 :
h_multiplicity(new TH1D(
"",
";reconstructed protons per event", 11, -0.5, 10.5)),
180 h_xi(new TH1D(
"",
";#xi", 100, 0., 0.3)),
181 h_th_x(new TH1D(
"",
";#theta_{x} (rad)", 250, -500E-6, +500E-6)),
182 h_th_y(new TH1D(
"",
";#theta_{y} (rad)", 500, -1000E-6, +1000E-6)),
183 h_vtx_y(new TH1D(
"",
";vtx_{y} (cm)", 100, -100E-3, +100E-3)),
184 h_chi_sq(new TH1D(
"",
";#chi^{2}", 100, 0., 10.)),
185 h_log_chi_sq(new TH1D(
"",
";log_{10} #chi^{2}", 100, -20., 5.)),
187 h_time(new TH1D(
"",
";time (ns)", 100, -2., +2.)),
188 h_time_unc(new TH1D(
"",
";time unc (ns)", 100, -1., +1.)),
193 h2_th_x_vs_xi(new TH2D(
"",
";#xi;#theta_{x} (rad)", 100, 0., 0.3, 100, -500E-6, +500E-6)),
194 h2_th_y_vs_xi(new TH2D(
"",
";#xi;#theta_{y} (rad)", 100, 0., 0.3, 100, -500E-6, +500E-6)),
195 h2_vtx_y_vs_xi(new TH2D(
"",
";#xi;vtx_{y} (cm)", 100, 0., 0.3, 100, -100E-3, +100E-3)),
196 p_th_x_vs_xi(new TProfile(
"",
";#xi;#theta_{x} (rad)", 100, 0., 0.3)),
197 p_th_y_vs_xi(new TProfile(
"",
";#xi;#theta_{y} (rad)", 100, 0., 0.3)),
198 p_vtx_y_vs_xi(new TProfile(
"",
";#xi;vtx_{y} (cm)", 100, 0., 0.3)),
200 new TH2D(
"",
";reco protons per event;timing tracks per event", 11, -0.5, 10.5, 11, -0.5, 10.5)),
201 h_xi_n1f1(new TH1D(
"",
";#xi", 100, 0., 0.3)),
204 new TH2D(
"",
";x_tracking (mm);x_timing (mm)", 100, 0., 20., 100, 0., 20.)),
211 new TH1D(
"",
";match between tracking and timing tracks", 2, -0.5, +1.5)),
216 std::vector<double> v_t_bin_edges;
217 for (
double t = 0;
t <= 5.;) {
218 v_t_bin_edges.push_back(
t);
219 const double de_t = 0.05 + 0.09 *
t + 0.02 *
t *
t;
222 h_t_unif = std::make_unique<TH1D>(
"",
";|t| (GeV^2)", 100, 0., 5.);
223 h_t = std::make_unique<TH1D>(
"",
";|t| (GeV^2)", v_t_bin_edges.size() - 1, v_t_bin_edges.data());
224 h_t_xi_range1 = std::make_unique<TH1D>(
"",
";|t| (GeV^2)", v_t_bin_edges.size() - 1, v_t_bin_edges.data());
225 h_t_xi_range2 = std::make_unique<TH1D>(
"",
";|t| (GeV^2)", v_t_bin_edges.size() - 1, v_t_bin_edges.data());
226 h_t_xi_range3 = std::make_unique<TH1D>(
"",
";|t| (GeV^2)", v_t_bin_edges.size() - 1, v_t_bin_edges.data());
228 "",
";#xi;|t| (GeV^2)", 100, 0., 0.3, v_t_bin_edges.size() - 1, v_t_bin_edges.data());
230 for (
unsigned int n = 2;
n <= 10; ++
n)
238 unsigned int n_contrib_tracking_tracks = 0, n_contrib_timing_tracks = 0;
239 for (
const auto &tr :
p.contributingLocalTracks()) {
242 n_contrib_tracking_tracks++;
244 n_contrib_timing_tracks++;
247 const double th_x =
p.thetaX();
248 const double th_y =
p.thetaY();
249 const double mt = -
p.t();
268 if (
p.xi() > 0.04 &&
p.xi() < 0.07)
270 if (
p.xi() > 0.07 &&
p.xi() < 0.10)
272 if (
p.xi() > 0.10 &&
p.xi() < 0.13)
275 if (
p.timeError() > 0.) {
293 it->second->Fill(
p.xi());
316 auto g_th_x_RMS_vs_xi = std::make_unique<TGraphErrors>();
318 g_th_x_RMS_vs_xi->Write(
"g_th_x_RMS_vs_xi");
323 auto g_th_y_RMS_vs_xi = std::make_unique<TGraphErrors>();
325 g_th_y_RMS_vs_xi->Write(
"g_th_y_RMS_vs_xi");
330 auto g_vtx_y_RMS_vs_xi = std::make_unique<TGraphErrors>();
332 g_vtx_y_RMS_vs_xi->Write(
"g_vtx_y_RMS_vs_xi");
334 h_t->Scale(1.,
"width");
349 TDirectory *d_top = gDirectory;
351 gDirectory = d_top->mkdir(
"h_xi_nTracks");
354 sprintf(
buf,
"h_xi_nTracks_%u",
p.first);
355 p.second->Write(
buf);
391 h_xi_diff_mu_si(new TH1D(
"",
";#xi_{multi} - #xi_{single}", 100, -0.1, +0.1)),
392 h_xi_diff_si_mu(new TH1D(
"",
";#xi_{single} - #xi_{multi}", 100, -0.1, +0.1)),
394 new TH2D(
"",
";#xi_{multi};#xi_{single} - #xi_{multi}", 100, 0., 0.3, 100, -0.10, 0.10)),
397 new TH2D(
"",
";#theta^{*}_{y,si};#theta^{*}_{y,mu}", 100, -500E-6, +500E-6, 100, -500E-6, +500E-6)) {}
408 const double th_y_si = p_single.
thetaY();
409 const double th_y_mu = p_multi.
thetaY();
441 h_th_y_si_diffNF(new TH1D(
"",
";#theta_{y,sF} - #theta_{y,sN}", 100, -100E-6, +100E-6)),
448 const double th_y_s_N = p_s_N.
thetaY();
449 const double th_y_s_F = p_s_F.
thetaY();
486 tokenRecoProtonsSingleRP_(
488 tokenRecoProtonsMultiRP_(
492 rpId_45_N_(ps.getParameter<unsigned
int>(
"rpId_45_N")),
493 rpId_45_F_(ps.getParameter<unsigned
int>(
"rpId_45_F")),
494 rpId_56_N_(ps.getParameter<unsigned
int>(
"rpId_56_N")),
495 rpId_56_F_(ps.getParameter<unsigned
int>(
"rpId_56_F")),
497 outputFile_(ps.getParameter<
string>(
"outputFile")),
498 maxNonEmptyEvents_(ps.getUntrackedParameter<signed
int>(
"maxNonEmptyEvents", -1)),
500 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.)),
501 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.)),
503 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.)),
504 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.)),
506 n_non_empty_events_(0) {
508 const unsigned int arm = (sector ==
"45") ? 0 : 1;
526 const double z_i =
geometry.rpTranslation(tr_i.rpId()).
z();
527 const double z_j =
geometry.rpTranslation(tr_j.rpId()).
z();
530 const double z_ti = -
geometry.rpTranslation(tr_ti.
rpId()).
z();
531 const double f_i = (z_ti - z_j) / (z_i - z_j), f_j = (z_i - z_ti) / (z_i - z_j);
532 const double x_inter = f_i * tr_i.x() + f_j * tr_j.x();
533 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();
539 de_x = tr_ti.
x() - x_inter;
540 de_x_unc =
sqrt(tr_ti.
xUnc() * tr_ti.
xUnc() + x_inter_unc_sq);
556 if (!hRecoProtonsSingleRP->empty())
560 throw cms::Exception(
"CTPPSProtonReconstructionPlotter") <<
"Number of non empty events reached maximum.";
570 std::map<unsigned int, unsigned int> armTrackCounter, armTimingTrackCounter;
571 std::map<unsigned int, unsigned int> armTrackCounter_N, armTrackCounter_F;
573 for (
const auto &tr : *hTracks) {
579 armTrackCounter_N[0]++;
583 armTrackCounter_F[0]++;
587 armTrackCounter_N[1]++;
591 armTrackCounter_F[1]++;
594 armTrackCounter[
rpId.arm()]++;
596 const bool trackerRP =
599 armTimingTrackCounter[
rpId.arm()]++;
602 if (tr_L_N && tr_L_F) {
607 if (tr_R_N && tr_R_F) {
613 std::map<unsigned int, unsigned int> singleRPMultiplicity, multiRPMultiplicity;
616 multiRPMultiplicity[0] = multiRPMultiplicity[1] = 0;
619 for (
const auto &proton : *hRecoProtonsSingleRP) {
623 const bool n1f1 = (armTrackCounter_N[
rpId.arm()] == 1 && armTrackCounter_F[
rpId.arm()] == 1);
627 if (proton.validFit())
628 singleRPMultiplicity[
decRPId]++;
631 for (
const auto it : singleRPMultiplicity)
635 for (
const auto &proton : *hRecoProtonsMultiRP) {
637 unsigned int armId =
rpId.arm();
639 const bool n1f1 = (armTrackCounter_N[armId] == 1 && armTrackCounter_F[armId] == 1);
641 multiRPPlots_[armId].fill(proton, armTrackCounter[armId], n1f1);
643 if (proton.validFit())
644 multiRPMultiplicity[armId]++;
647 for (
const auto it : multiRPMultiplicity) {
649 pl.h_multiplicity->Fill(it.second);
650 pl.h2_timing_tracks_vs_prot_mult->Fill(it.second, armTimingTrackCounter[it.first]);
654 map<unsigned int, bool> clCo;
655 clCo[0] = (singleRPMultiplicity[
rpId_45_N_] && singleRPMultiplicity[
rpId_45_F_] && multiRPMultiplicity[0] == 1);
656 clCo[1] = (singleRPMultiplicity[
rpId_56_N_] && singleRPMultiplicity[
rpId_56_F_] && multiRPMultiplicity[1] == 1);
659 for (
const auto &proton : *hRecoProtonsMultiRP) {
660 if (!proton.validFit())
663 CTPPSDetId rpId_proton((*proton.contributingLocalTracks().begin())->
rpId());
664 unsigned int armId = rpId_proton.
arm();
667 for (
const auto &tr : *hTracks) {
669 if (rpId_tr.arm() != armId)
672 const bool trackerRP =
677 double x_tr = -1., x_ti = -1.;
678 double de_x = 0., de_x_unc = 0.;
681 const double rd = (de_x_unc > 0.) ?
de_x / de_x_unc : -1E10;
683 const bool match = (ac.ti_tr_min <= fabs(rd) && fabs(rd) <= ac.ti_tr_max);
685 pl.h_de_x_timing_vs_tracking->Fill(
de_x);
686 pl.h_de_x_rel_timing_vs_tracking->Fill(rd);
687 pl.h_de_x_match_timing_vs_tracking->Fill(
match ? 1. : 0.);
689 if (clCo[armId] && armTimingTrackCounter[armId] == 1) {
690 pl.h2_x_timing_vs_x_tracking_ClCo->Fill(x_tr, x_ti);
692 pl.h_de_x_timing_vs_tracking_ClCo->Fill(
de_x);
693 pl.h_de_x_rel_timing_vs_tracking_ClCo->Fill(rd);
694 pl.h_de_x_match_timing_vs_tracking_ClCo->Fill(
match ? 1. : 0.);
696 pl.p_time_unc_vs_x_ClCo->Fill(x_tr, proton.timeError());
702 for (
const auto &proton : *hRecoProtonsMultiRP) {
703 if (!proton.validFit())
707 unsigned int armId =
rpId.arm();
709 const auto &nTimingTracks = armTimingTrackCounter[armId];
714 double x_ref = 0., y_ref = 0.;
724 if (nTimingTracks == 0)
725 pl.h2_y_vs_x_tt0_ClCo->Fill(x_ref, y_ref);
726 if (nTimingTracks == 1)
727 pl.h2_y_vs_x_tt1_ClCo->Fill(x_ref, y_ref);
728 if (nTimingTracks > 1)
729 pl.h2_y_vs_x_ttm_ClCo->Fill(x_ref, y_ref);
733 for (
const auto &proton_m : *hRecoProtonsMultiRP) {
734 CTPPSDetId rpId_m((*proton_m.contributingLocalTracks().begin())->
rpId());
735 unsigned int arm = rpId_m.arm();
739 for (
const auto &proton_s : *hRecoProtonsSingleRP) {
742 bool compatible =
false;
743 for (
const auto &tr_m : proton_m.contributingLocalTracks()) {
744 if (tr_m.key() == key_s) {
754 CTPPSDetId rpId_s((*proton_s.contributingLocalTracks().begin())->
rpId());
755 const unsigned int idx = rpId_s.arm() * 1000 + rpId_s.station() * 100 + rpId_s.rp() * 10 + rpId_s.arm();
759 const unsigned int rpDecId_s = rpId_s.arm() * 100 + rpId_s.station() * 10 + rpId_s.rp();
777 auto f_out = std::make_unique<TFile>(
outputFile_.c_str(),
"recreate");
785 TDirectory *d_singleRPPlots = f_out->mkdir(
"singleRPPlots");
787 gDirectory = d_singleRPPlots->mkdir(Form(
"rp%u", it.first));
791 TDirectory *d_multiRPPlots = f_out->mkdir(
"multiRPPlots");
793 gDirectory = d_multiRPPlots->mkdir(Form(
"arm%u", it.first));
797 TDirectory *d_singleMultiCorrelationPlots = f_out->mkdir(
"singleMultiCorrelationPlots");
799 unsigned int si_rp = it.first / 10;
800 unsigned int mu_arm = it.first % 10;
802 gDirectory = d_singleMultiCorrelationPlots->mkdir(Form(
"si_rp%u_mu_arm%u", si_rp, mu_arm));
806 TDirectory *d_armCorrelationPlots = f_out->mkdir(
"armCorrelationPlots");
808 gDirectory = d_armCorrelationPlots->mkdir(Form(
"arm%u", it.first));