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)) {}
78 p_eff_vs_xi->Write(
"p_eff_vs_xi");
79 h_n_part_acc_nr->Write(
"h_n_part_acc_nr");
80 h_n_part_acc_fr->Write(
"h_n_part_acc_fr");
84 std::map<unsigned int, std::map<unsigned int, PlotGroup>>
plots_;
91 using namespace HepMC;
100 iConfig.getParameter<
edm::
InputTag>(
"tagStripRecHitsPerParticle"))),
102 iConfig.getParameter<
edm::
InputTag>(
"tagPixelRecHitsPerParticle"))),
115 verbosity_(iConfig.getUntrackedParameter<unsigned
int>(
"verbosity", 0))
124 for (
unsigned int arm = 0;
arm < 2; ++
arm) {
125 for (
unsigned int np = 1;
np <= 5; ++
np)
133 std::ostringstream os;
158 unsigned int arm = 2;
160 std::map<unsigned int, unsigned int> recHitsPerRP;
161 bool inAcceptanceNear =
false, inAcceptanceFar =
false, inAcceptance =
false;
164 std::map<int, ParticleInfo> particleInfo;
167 for (
auto it = hepMCEventAfterSmearing->particles_begin(); it != hepMCEventAfterSmearing->particles_end(); ++it) {
168 const auto &
part = *it;
171 if (
part->pdg_id() != 2212)
174 if (
part->status() != 1)
180 const auto &mom =
part->momentum();
187 info.arm = (mom.z() > 0.) ? 0 : 1;
189 const double p_nom = hLHCInfo->
energy();
190 info.xi = (p_nom - mom.rho()) / p_nom;
196 for (
const auto &
pp : *hStripRecHitsPerParticle) {
197 const auto barcode =
pp.first;
199 for (
const auto &ds :
pp.second) {
202 particleInfo[barcode].recHitsPerRP[
rpId] += ds.size();
206 for (
const auto &
pp : *hPixelRecHitsPerParticle) {
207 const auto barcode =
pp.first;
209 for (
const auto &ds :
pp.second) {
212 particleInfo[barcode].recHitsPerRP[
rpId] += ds.size();
216 std::map<unsigned int, bool> isStripRPNear, isStripRPFar;
218 for (
auto &
pp : particleInfo) {
220 os <<
"* barcode=" <<
pp.first <<
", arm=" <<
pp.second.arm <<
", xi=" <<
pp.second.xi << std::endl;
222 for (
const auto &rpp :
pp.second.recHitsPerRP) {
224 unsigned int needed_rec_hits = 1000;
230 unsigned int rpDecId = rpId.
arm() * 100 + rpId.
station() * 10 + rpId.
rp();
234 isStripRPNear[rpId.
arm()] =
true;
236 isStripRPFar[rpId.
arm()] =
true;
239 if (rpp.second >= needed_rec_hits) {
241 pp.second.inAcceptanceNear =
true;
243 pp.second.inAcceptanceFar =
true;
247 os <<
" RP " << rpDecId <<
": " << rpp.second <<
" hits" << std::endl;
250 pp.second.inAcceptance =
pp.second.inAcceptanceNear &&
pp.second.inAcceptanceFar;
253 os <<
" inAcceptance: near=" <<
pp.second.inAcceptanceNear <<
", far=" <<
pp.second.inAcceptanceFar <<
", 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=" 305 << nReconstructedProtons[
arm] <<
" (tracks near=" << nReconstructedTracks[
arm].near <<
", far=" << nReconstructedTracks[
arm].far
306 <<
"), nAcc=" << npa.global <<
" (near=" << npa.near <<
", far=" << npa.far <<
")" << std::endl;
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);
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection > tracksToken_
std::unique_ptr< TH1D > h_n_part_acc_nr
CTPPSProtonReconstructionEfficiencyEstimatorMC(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::map< unsigned int, std::map< unsigned int, PlotGroup > > plots_
std::map< unsigned int, unsigned int > rpDecId_near_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsMultiRP_
edm::EDGetTokenT< std::map< int, edm::DetSetVector< CTPPSPixelRecHit > > > tokenPixelRecHitsPerParticle_
#define DEFINE_FWK_MODULE(type)
edm::EDGetTokenT< edm::HepMCProduct > tokenHepMCAfterSmearing_
void analyze(const edm::Event &, const edm::EventSetup &) override
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
Reconstructed hit in TOTEM RP.
std::unique_ptr< TProfile > p_eff_vs_xi
std::unique_ptr< TH1D > h_n_part_acc_fr
const HepMC::GenEvent * GetEvent() const
std::vector< CTPPSLocalTrackLite > CTPPSLocalTrackLiteCollection
Collection of CTPPSLocalTrackLite objects.
Base class for CTPPS detector IDs.
std::map< unsigned int, unsigned int > rpDecId_far_
float const energy() const
std::string lhcInfoLabel_
edm::EDGetTokenT< std::map< int, edm::DetSetVector< TotemRPRecHit > > > tokenStripRecHitsPerParticle_
std::vector< ForwardProton > ForwardProtonCollection
Collection of ForwardProton objects.