32 #include "TGraphErrors.h"
73 :
p_eff_vs_xi(new TProfile(
"",
";#xi_{simu};efficiency", 19, 0.015, 0.205)),
74 h_n_part_acc_nr(new TH1D(
"",
";n particles in acceptance", 6, -0.5, +5.5)),
75 h_n_part_acc_fr(new TH1D(
"",
";n particles in acceptance", 6, -0.5, +5.5)) {}
84 std::map<unsigned int, std::map<unsigned int, PlotGroup>>
plots_;
91 using namespace HepMC;
97 : tokenHepMCAfterSmearing_(
100 iConfig.getParameter<
edm::
InputTag>(
"tagStripRecHitsPerParticle"))),
102 iConfig.getParameter<
edm::
InputTag>(
"tagPixelRecHitsPerParticle"))),
104 tokenRecoProtonsMultiRP_(
106 lhcInfoLabel_(iConfig.getParameter<
std::
string>(
"lhcInfoLabel")),
108 rpId_45_N_(iConfig.getParameter<unsigned
int>(
"rpId_45_N")),
109 rpId_45_F_(iConfig.getParameter<unsigned
int>(
"rpId_45_F")),
110 rpId_56_N_(iConfig.getParameter<unsigned
int>(
"rpId_56_N")),
111 rpId_56_F_(iConfig.getParameter<unsigned
int>(
"rpId_56_F")),
113 outputFile_(iConfig.getParameter<
string>(
"outputFile")),
115 verbosity_(iConfig.getUntrackedParameter<unsigned
int>(
"verbosity", 0)) {
123 for (
unsigned int arm = 0; arm < 2; ++arm) {
124 for (
unsigned int np = 1;
np <= 5; ++
np)
132 std::ostringstream os;
157 unsigned int arm = 2;
159 std::map<unsigned int, unsigned int> recHitsPerRP;
160 bool inAcceptanceNear =
false, inAcceptanceFar =
false, inAcceptance =
false;
163 std::map<int, ParticleInfo> particleInfo;
166 for (
auto it = hepMCEventAfterSmearing->particles_begin(); it != hepMCEventAfterSmearing->particles_end(); ++it) {
167 const auto &
part = *it;
170 if (
part->pdg_id() != 2212)
173 if (
part->status() != 1)
179 const auto &mom =
part->momentum();
186 info.arm = (mom.z() > 0.) ? 0 : 1;
188 const double p_nom = hLHCInfo->
energy();
189 info.xi = (p_nom - mom.rho()) / p_nom;
195 for (
const auto &
pp : *hStripRecHitsPerParticle) {
196 const auto barcode =
pp.first;
198 for (
const auto &ds :
pp.second) {
201 particleInfo[barcode].recHitsPerRP[
rpId] += ds.size();
205 for (
const auto &
pp : *hPixelRecHitsPerParticle) {
206 const auto barcode =
pp.first;
208 for (
const auto &ds :
pp.second) {
211 particleInfo[barcode].recHitsPerRP[
rpId] += ds.size();
215 std::map<unsigned int, bool> isStripRPNear, isStripRPFar;
217 for (
auto &
pp : particleInfo) {
219 os <<
"* barcode=" <<
pp.first <<
", arm=" <<
pp.second.arm <<
", xi=" <<
pp.second.xi << std::endl;
221 for (
const auto &rpp :
pp.second.recHitsPerRP) {
223 unsigned int needed_rec_hits = 1000;
229 unsigned int rpDecId =
rpId.arm() * 100 +
rpId.station() * 10 +
rpId.rp();
233 isStripRPNear[
rpId.arm()] =
true;
235 isStripRPFar[
rpId.arm()] =
true;
238 if (rpp.second >= needed_rec_hits) {
240 pp.second.inAcceptanceNear =
true;
242 pp.second.inAcceptanceFar =
true;
246 os <<
" RP " << rpDecId <<
": " << rpp.second <<
" hits" << std::endl;
249 pp.second.inAcceptance =
pp.second.inAcceptanceNear &&
pp.second.inAcceptanceFar;
252 os <<
" inAcceptance: near=" <<
pp.second.inAcceptanceNear <<
", far=" <<
pp.second.inAcceptanceFar
253 <<
", global=" <<
pp.second.inAcceptance << std::endl;
258 unsigned int near = 0, far = 0, global = 0;
260 std::map<unsigned int, ArmCounter> nParticlesInAcceptance;
261 for (
auto &
pp : particleInfo) {
262 auto &
counter = nParticlesInAcceptance[
pp.second.arm];
263 if (
pp.second.inAcceptanceNear)
265 if (
pp.second.inAcceptanceFar)
267 if (
pp.second.inAcceptance)
272 std::map<unsigned int, ArmCounter> nReconstructedTracks;
273 for (
const auto &tr : *
tracks) {
275 unsigned int rpDecId =
rpId.arm() * 100 +
rpId.station() * 10 +
rpId.rp();
278 nReconstructedTracks[
rpId.arm()].near++;
280 nReconstructedTracks[
rpId.arm()].far++;
284 std::map<unsigned int, unsigned int> nReconstructedProtons;
285 for (
const auto &
pr : *hRecoProtonsMultiRP) {
289 unsigned int arm = 2;
295 nReconstructedProtons[arm]++;
299 for (
unsigned int arm = 0; arm < 2; arm++) {
300 const auto &npa = nParticlesInAcceptance[arm];
301 const auto &nrt = nReconstructedTracks[arm];
304 os <<
"* arm " << arm <<
": nRecoProtons=" << nReconstructedProtons[arm]
305 <<
" (tracks near=" << nReconstructedTracks[arm].near <<
", far=" << nReconstructedTracks[arm].far
306 <<
"), nAcc=" << npa.global <<
" (near=" << npa.near <<
", far=" << npa.far <<
")" << std::endl;
312 const auto &
p =
plots_[arm][npa.global];
314 p.h_n_part_acc_nr->Fill(npa.near);
315 p.h_n_part_acc_fr->Fill(npa.far);
318 if (nrt.near != npa.near || nrt.far != npa.far)
321 const double eff = double(nReconstructedProtons[arm]) / npa.global;
324 os <<
" eff=" << eff << std::endl;
326 for (
auto &
pp : particleInfo) {
327 if (
pp.second.arm != arm || !
pp.second.inAcceptance)
330 p.p_eff_vs_xi->Fill(
pp.second.xi, eff);
335 edm::LogInfo(
"CTPPSProtonReconstructionEfficiencyEstimatorMC") << os.str();
341 auto f_out = std::make_unique<TFile>(
outputFile_.c_str(),
"recreate");
343 for (
const auto &ait :
plots_) {
345 sprintf(
buf,
"arm%u", ait.first);
346 TDirectory *d_arm = f_out->mkdir(
buf);
348 for (
const auto &npit : ait.second) {
349 sprintf(
buf,
"%u", npit.first);
350 TDirectory *d_np = d_arm->mkdir(
buf);