CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
GenProtonTableProducer Class Reference
Inheritance diagram for GenProtonTableProducer:
edm::stream::EDProducer<>

Public Member Functions

 GenProtonTableProducer (const edm::ParameterSet &)
 
 ~GenProtonTableProducer () override=default
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

const StringCutObjectSelector< reco::CandidateprotonsCut_
 
const edm::EDGetTokenT< reco::GenParticleCollectionprunedCandsToken_
 
const edm::EDGetTokenT< reco::GenParticleCollectionpuAltCandsToken_
 
const edm::EDGetTokenT< reco::GenParticleCollectionpuCandsToken_
 
const std::string table_name_
 
const double tolerance_
 
bool use_alt_coll_ {false}
 Are we using premix/mix collection name for PU protons? More...
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 26 of file GenProtonTableProducer.cc.

Constructor & Destructor Documentation

◆ GenProtonTableProducer()

GenProtonTableProducer::GenProtonTableProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 44 of file GenProtonTableProducer.cc.

45  : prunedCandsToken_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("srcPruned"))),
46  puCandsToken_(mayConsume<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("srcPUProtons"))),
47  puAltCandsToken_(mayConsume<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("srcAltPUProtons"))),
48  protonsCut_(iConfig.getParameter<std::string>("cut")),
49  table_name_(iConfig.getParameter<std::string>("name")),
50  tolerance_(iConfig.getParameter<double>("tolerance")) {
51  produces<nanoaod::FlatTable>();
52 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::EDGetTokenT< reco::GenParticleCollection > puAltCandsToken_
const StringCutObjectSelector< reco::Candidate > protonsCut_
const edm::EDGetTokenT< reco::GenParticleCollection > puCandsToken_
const edm::EDGetTokenT< reco::GenParticleCollection > prunedCandsToken_

◆ ~GenProtonTableProducer()

GenProtonTableProducer::~GenProtonTableProducer ( )
overridedefault

Member Function Documentation

◆ fillDescriptions()

void GenProtonTableProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 101 of file GenProtonTableProducer.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, HLT_2022v15_cff::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

101  {
103  desc.add<edm::InputTag>("srcPruned", edm::InputTag("prunedGenParticles"))
104  ->setComment("input source for pruned gen-level particle candidates");
105  desc.add<edm::InputTag>("srcPUProtons", edm::InputTag("genPUProtons"))
106  ->setComment("input source for pileup protons collection");
107  desc.add<edm::InputTag>("srcAltPUProtons", edm::InputTag("genPUProtons", "genPUProtons"))
108  ->setComment("alternative input source for pileup protons collection (for premix-mix backward compatibility)");
109  desc.add<std::string>("cut", "")->setComment("proton kinematic selection");
110  desc.add<std::string>("name", "GenProton")->setComment("flat table name");
111  desc.add<std::string>("doc", "generator level information on (signal+PU) protons")
112  ->setComment("flat table description");
113  desc.add<double>("tolerance", 1.e-3)->setComment("relative difference between the signal and pileup protons momenta");
114  descriptions.add("genProtonTable", desc);
115 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

void GenProtonTableProducer::produce ( edm::Event iEvent,
const edm::EventSetup  
)
overrideprivate

Definition at line 54 of file GenProtonTableProducer.cc.

References mps_fire::i, iEvent, eostools::move(), protonsCut_, prunedCandsToken_, puAltCandsToken_, puCandsToken_, table_name_, tolerance_, and use_alt_coll_.

54  {
55  // define the variables
56  std::vector<float> pxs, pys, pzs, vzs;
57  std::vector<bool> isPUs;
58  // first loop over signal protons
59  for (const auto& pruned_cand : iEvent.get(prunedCandsToken_)) {
60  if (!protonsCut_(pruned_cand))
61  continue;
62  pxs.emplace_back(pruned_cand.px());
63  pys.emplace_back(pruned_cand.py());
64  pzs.emplace_back(pruned_cand.pz());
65  vzs.emplace_back(pruned_cand.vz());
66  isPUs.emplace_back(false);
67  }
68  // then loop over pruned candidates ; if already in signal protons, discard
70  if (use_alt_coll_ || !iEvent.getByToken(puCandsToken_, hPUCands))
71  use_alt_coll_ = iEvent.getByToken(puAltCandsToken_, hPUCands);
72  for (const auto& pu_cand : *hPUCands) {
73  if (!protonsCut_(pu_cand))
74  continue;
75  bool associated{false};
76  for (size_t i = 0; i < pzs.size(); ++i) {
77  if (fabs(1. - pxs.at(i) / pu_cand.px()) < tolerance_ && fabs(1. - pys.at(i) / pu_cand.py()) < tolerance_ &&
78  fabs(1. - pzs.at(i) / pu_cand.pz()) < tolerance_) {
79  associated = true;
80  break;
81  }
82  }
83  if (associated)
84  continue;
85  pxs.emplace_back(pu_cand.px());
86  pys.emplace_back(pu_cand.py());
87  pzs.emplace_back(pu_cand.pz());
88  vzs.emplace_back(pu_cand.vz());
89  isPUs.emplace_back(true);
90  }
91 
92  auto protons_table = std::make_unique<nanoaod::FlatTable>(isPUs.size(), table_name_, false);
93  protons_table->addColumn<float>("px", pxs, "proton horizontal momentum", 8);
94  protons_table->addColumn<float>("py", pys, "proton vertical momentum", 8);
95  protons_table->addColumn<float>("pz", pzs, "proton longitudinal momentum", 8);
96  protons_table->addColumn<float>("vz", vzs, "proton vertex longitudinal coordinate", 8);
97  protons_table->addColumn<bool>("isPU", isPUs, "pileup proton?");
98  iEvent.put(std::move(protons_table));
99 }
const edm::EDGetTokenT< reco::GenParticleCollection > puAltCandsToken_
int iEvent
Definition: GenABIO.cc:224
const StringCutObjectSelector< reco::Candidate > protonsCut_
const edm::EDGetTokenT< reco::GenParticleCollection > puCandsToken_
bool use_alt_coll_
Are we using premix/mix collection name for PU protons?
const edm::EDGetTokenT< reco::GenParticleCollection > prunedCandsToken_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ protonsCut_

const StringCutObjectSelector<reco::Candidate> GenProtonTableProducer::protonsCut_
private

Definition at line 38 of file GenProtonTableProducer.cc.

Referenced by produce().

◆ prunedCandsToken_

const edm::EDGetTokenT<reco::GenParticleCollection> GenProtonTableProducer::prunedCandsToken_
private

Definition at line 36 of file GenProtonTableProducer.cc.

Referenced by produce().

◆ puAltCandsToken_

const edm::EDGetTokenT<reco::GenParticleCollection> GenProtonTableProducer::puAltCandsToken_
private

Definition at line 37 of file GenProtonTableProducer.cc.

Referenced by produce().

◆ puCandsToken_

const edm::EDGetTokenT<reco::GenParticleCollection> GenProtonTableProducer::puCandsToken_
private

Definition at line 37 of file GenProtonTableProducer.cc.

Referenced by produce().

◆ table_name_

const std::string GenProtonTableProducer::table_name_
private

Definition at line 39 of file GenProtonTableProducer.cc.

Referenced by produce().

◆ tolerance_

const double GenProtonTableProducer::tolerance_
private

Definition at line 40 of file GenProtonTableProducer.cc.

Referenced by produce().

◆ use_alt_coll_

bool GenProtonTableProducer::use_alt_coll_ {false}
private

Are we using premix/mix collection name for PU protons?

Definition at line 41 of file GenProtonTableProducer.cc.

Referenced by produce().