CMS 3D CMS Logo

PackedCandidateGenAssociationProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MyTemporarySubSystem/PackedCandidateGenAssociationProducer
4 // Class: PackedCandidateGenAssociationProducer
5 //
13 //
14 // Original Author: Enrico Lusiani
15 // Created: Mon, 03 May 2021 13:40:39 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
36 
37 //
38 // class declaration
39 //
40 
42 public:
44 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47 private:
48  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
49 
55 };
57  : trackToGenToken_(consumes<edm::Association<reco::GenParticleCollection>>(
58  iConfig.getParameter<edm::InputTag>("trackToGenAssoc"))),
59  trackToPcToken_(consumes<edm::Association<pat::PackedCandidateCollection>>(
60  iConfig.getParameter<edm::InputTag>("trackToPackedCandidatesAssoc"))),
61  genToPrunedToken_(consumes<edm::Association<reco::GenParticleCollection>>(
62  iConfig.getParameter<edm::InputTag>("genToPrunedAssoc"))),
63  genToPrunedWSOToken_(consumes<edm::Association<reco::GenParticleCollection>>(
64  iConfig.getParameter<edm::InputTag>("genToPrunedAssocWithStatusOne"))),
65  tracksToken_(consumes<edm::View<reco::Track>>(iConfig.getParameter<edm::InputTag>("tracks"))) {
66  produces<edm::Association<reco::GenParticleCollection>>();
67 }
68 
71  const edm::EventSetup& iSetup) const {
72  using namespace edm;
73 
75  auto pcCollection = trackToPackedCandidatesAssoc.ref();
76 
77  const auto& genToPrunedAssoc = iEvent.get(genToPrunedToken_);
78  auto prunedCollection = genToPrunedAssoc.ref();
79 
80  const auto& genToPrunedAssocWSO = iEvent.get(genToPrunedWSOToken_);
81 
82  auto trackHandle = iEvent.getHandle(tracksToken_);
83  const auto& tracks = *trackHandle;
84 
85  auto out = std::make_unique<edm::Association<reco::GenParticleCollection>>(prunedCollection);
86 
87  auto trackToGenAssocHandle = iEvent.getHandle(trackToGenToken_);
88  if (not trackToGenAssocHandle.isValid() or not trackToGenAssocHandle->contains(trackHandle.id())) {
89  // not track to gen association available, possibly an old AODSIM, or a missing RECOSIM step
90  // alternatively, the track association may not contain our tracks, as in the case of RECOSIM run on an old RAWSIM
91  // early exit with an empty collection to avoid crash
92  iEvent.put(std::move(out));
93  return;
94  }
95 
96  const auto& trackToGenAssoc = *trackToGenAssocHandle;
97 
99 
100  std::vector<int> indices(pcCollection->size(), -1);
101 
102  for (size_t i = 0; i < tracks.size(); i++) {
103  auto track = tracks.refAt(i);
104 
106  if (pc.isNull()) {
107  continue;
108  }
109 
110  auto gen = trackToGenAssoc[track];
111  if (gen.isNull()) {
112  continue;
113  }
114 
115  auto newGenWSO = genToPrunedAssocWSO[gen];
116  if (newGenWSO.isNull()) {
117  continue;
118  }
119 
120  auto newGen = genToPrunedAssoc[newGenWSO];
121  if (newGen.isNull()) {
122  continue;
123  }
124 
125  indices[pc.index()] = newGen.index();
126  }
127  filler.insert(pcCollection, indices.begin(), indices.end());
128  filler.fill();
129  iEvent.put(std::move(out));
130 }
131 
134  desc.add<edm::InputTag>("genToPrunedAssoc", edm::InputTag("prunedGenParticles"));
135  desc.add<edm::InputTag>("genToPrunedAssocWithStatusOne", edm::InputTag("prunedGenParticlesWithStatusOne"));
136  desc.add<edm::InputTag>("trackToPackedCandidatesAssoc", edm::InputTag("packedPFCandidates"));
137  desc.add<edm::InputTag>("trackToGenAssoc");
138  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
139 
140  descriptions.add("packedCandidatesGenAssociationDefault", desc);
141 }
142 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > trackToPcToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > trackToGenToken_
std::vector< pat::PackedCandidate > PackedCandidateCollection
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > genToPrunedWSOToken_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
def gen(fragment, howMuch)
Production test section ####.
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > genToPrunedToken_
auto const & tracks
cannot be loose
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
edm::EDGetTokenT< edm::View< reco::Track > > tracksToken_
def move(src, dest)
Definition: eostools.py:511