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 
edm::StreamID
Definition: StreamID.h:30
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
edm::Association::Filler
Definition: Association.h:78
sistrip::View
View
Definition: ConstantsForView.h:26
PackedCandidateGenAssociationProducer::genToPrunedWSOToken_
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > genToPrunedWSOToken_
Definition: PackedCandidateGenAssociationProducer.cc:53
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
reco::GenParticleCollection
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Definition: GenParticleFwd.h:13
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
Association.h
GenParticle.h
PackedCandidateGenAssociationProducer::genToPrunedToken_
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > genToPrunedToken_
Definition: PackedCandidateGenAssociationProducer.cc:52
MakerMacros.h
PackedCandidateGenAssociationProducer::trackToPcToken_
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > trackToPcToken_
Definition: PackedCandidateGenAssociationProducer.cc:51
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
PackedCandidateGenAssociationProducer::tracksToken_
edm::EDGetTokenT< edm::View< reco::Track > > tracksToken_
Definition: PackedCandidateGenAssociationProducer.cc:54
PackedCandidateGenAssociationProducer
Definition: PackedCandidateGenAssociationProducer.cc:41
gen
Definition: PythiaDecays.h:13
genParticleAssociation_cff.trackToPackedCandidatesAssoc
trackToPackedCandidatesAssoc
Definition: genParticleAssociation_cff.py:9
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:176
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
PackedCandidate.h
PackedCandidateGenAssociationProducer::PackedCandidateGenAssociationProducer
PackedCandidateGenAssociationProducer(const edm::ParameterSet &)
Definition: PackedCandidateGenAssociationProducer.cc:56
iEvent
int iEvent
Definition: GenABIO.cc:224
PackedCandidateGenAssociationProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PackedCandidateGenAssociationProducer.cc:132
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
PackedCandidateGenAssociationProducer::trackToGenToken_
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > trackToGenToken_
Definition: PackedCandidateGenAssociationProducer.cc:50
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1131
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
PackedCandidateGenAssociationProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: PackedCandidateGenAssociationProducer.cc:69
or
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
relval_steps.gen
def gen(fragment, howMuch)
Production test section ####.
Definition: relval_steps.py:506
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ParameterSet.h
EDProducer.h
dqmdumpme.indices
indices
Definition: dqmdumpme.py:50
genParticleAssociation_cff.trackToGenAssoc
trackToGenAssoc
Definition: genParticleAssociation_cff.py:4
edm::Event
Definition: Event.h:73
StreamID.h
edm::InputTag
Definition: InputTag.h:15