CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PackedGenParticleSignalProducer.cc
Go to the documentation of this file.
1 #include <memory>
9 
10 namespace pat {
11 
13  public:
15  : genParticleToken_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("genParticles"))),
16  assoToken_(consumes<edm::Association<std::vector<pat::PackedGenParticle>>>(
17  iConfig.getParameter<edm::InputTag>("packedGenParticles"))) {
18  produces<pat::PackedGenParticleRefVector>();
19  }
20  ~PackedGenParticleSignalProducer() override = default;
21 
22  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
23 
25 
26  private:
29  };
30 
31 } // namespace pat
32 
35  const edm::EventSetup& iSetup) const {
36  const auto& genParticles = iEvent.getHandle(genParticleToken_);
37  const auto& orig2packed = iEvent.get(assoToken_);
38 
39  auto signalGenParticleRefs = std::make_unique<pat::PackedGenParticleRefVector>();
40 
41  for (auto it = genParticles->begin(); it != genParticles->end(); ++it) {
42  const auto& orig = reco::GenParticleRef(genParticles, it - genParticles->begin());
43  if (orig->collisionId() != 0)
44  continue;
45  const auto& packed = orig2packed[orig];
46  if (packed.isNonnull()) {
47  signalGenParticleRefs->push_back(packed);
48  }
49  }
50 
51  iEvent.put(std::move(signalGenParticleRefs));
52 }
53 
54 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
57  desc.add<edm::InputTag>("genParticles", edm::InputTag("genParticles"))->setComment("genParticles input collection");
58  desc.add<edm::InputTag>("packedGenParticles", edm::InputTag("packedGenParticles"))
59  ->setComment("packedGenParticles input collection");
60  descriptions.add("packedGenParticlesSignal", desc);
61 }
62 
64 using namespace pat;
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
~PackedGenParticleSignalProducer() override=default
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
const edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
PackedGenParticleSignalProducer(const edm::ParameterSet &iConfig)
static void fillDescriptions(edm::ConfigurationDescriptions &)
const edm::EDGetTokenT< edm::Association< std::vector< pat::PackedGenParticle > > > assoToken_