CMS 3D CMS Logo

IsFromLostTrackMapProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: IsFromLostTrackMapProducer
5 //
13 //
14 // Original Author: Maria Giulia Ratti (ETHZ) [mratti]
15 // Created: Thu, 22 Nov 2018 12:34:48 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
35 
36 //
37 // class declaration
38 //
39 
41 public:
43  : srcIsoTracks_(consumes<edm::View<pat::IsolatedTrack>>(
44  iConfig.getParameter<edm::InputTag>("srcIsoTracks"))), // final isolated tracks
46  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))), // pf candidates
47  lt_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("lostTracks"))) // lost tracks
48  {
49  produces<edm::ValueMap<bool>>("isFromLostTrack"); // name of the value map that I want to actually produce
50  }
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55 private:
56  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
57 
58  // ----------member data ---------------------------
62 };
63 
64 //
65 // constants, enums and typedefs
66 //
67 
68 //
69 // static data member definitions
70 //
71 
72 //
73 // member functions
74 //
75 
76 // ------------ method called to produce the data ------------
79  const edm::EventSetup& iSetup) const {
80  // isolated tracks
82  iEvent.getByToken(srcIsoTracks_, srcIsoTracks);
83 
84  // packedPFCandidate collection
86  iEvent.getByToken(pc_, pc_handle);
87 
88  // lostTracks collection
90  iEvent.getByToken(lt_, lt_handle);
91 
92  // the map cannot be filled straight away, so create an intermediate vector
93  unsigned int Nit = srcIsoTracks->size();
94  std::vector<bool> v_isFromLostTrack(Nit, false);
95 
96  for (unsigned int iit = 0; iit < Nit; iit++) {
97  auto isotrack = srcIsoTracks->ptrAt(iit);
99  isotrack->packedCandRef(); // this is either the reference to the pf candidate or to the lost track
100  bool isFromLostTrack = (pcref.isNonnull() && pcref.id() == lt_handle.id());
101  v_isFromLostTrack[iit] = isFromLostTrack;
102  }
103 
104  std::unique_ptr<edm::ValueMap<bool>> vm_isFromLostTrack(new edm::ValueMap<bool>());
105  edm::ValueMap<bool>::Filler filler(*vm_isFromLostTrack);
106  filler.insert(srcIsoTracks, v_isFromLostTrack.begin(), v_isFromLostTrack.end());
107  filler.fill();
108  iEvent.put(std::move(vm_isFromLostTrack), "isFromLostTrack");
109 }
110 
111 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
114  desc.add<edm::InputTag>("srcIsoTracks")->setComment("isolated track input collection");
115  desc.add<edm::InputTag>("packedPFCandidates")->setComment("packed PF Candidates collection ");
116  desc.add<edm::InputTag>("lostTracks")->setComment("lost tracks collection");
117 
118  descriptions.addWithDefaultLabel(desc);
119 }
120 
121 //define this as a plug-in
edm::StreamID
Definition: StreamID.h:30
IsFromLostTrackMapProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: IsFromLostTrackMapProducer.cc:112
IsFromLostTrackMapProducer::~IsFromLostTrackMapProducer
~IsFromLostTrackMapProducer() override
Definition: IsFromLostTrackMapProducer.cc:51
isotracks_cff.srcIsoTracks
srcIsoTracks
Definition: isotracks_cff.py:21
sistrip::View
View
Definition: ConstantsForView.h:26
PFCandidate.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
IsFromLostTrackMapProducer::srcIsoTracks_
edm::EDGetTokenT< edm::View< pat::IsolatedTrack > > srcIsoTracks_
Definition: IsFromLostTrackMapProducer.cc:59
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref< pat::PackedCandidateCollection >
MakerMacros.h
IsFromLostTrackMapProducer::lt_
edm::EDGetTokenT< pat::PackedCandidateCollection > lt_
Definition: IsFromLostTrackMapProducer.cc:61
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
IsolatedTrack.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
PackedCandidate.h
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
iEvent
int iEvent
Definition: GenABIO.cc:224
isotracks_cff.isFromLostTrack
isFromLostTrack
Definition: isotracks_cff.py:47
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
IsFromLostTrackMapProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: IsFromLostTrackMapProducer.cc:77
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1131
IsFromLostTrackMapProducer
Definition: IsFromLostTrackMapProducer.cc:40
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
IsFromLostTrackMapProducer::pc_
edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
Definition: IsFromLostTrackMapProducer.cc:60
Frameworkfwd.h
edm::ValueMap
Definition: ValueMap.h:107
IsFromLostTrackMapProducer::IsFromLostTrackMapProducer
IsFromLostTrackMapProducer(const edm::ParameterSet &iConfig)
Definition: IsFromLostTrackMapProducer.cc:42
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:155
EDProducer.h
edm::Event
Definition: Event.h:73
StreamID.h
edm::HandleBase::id
ProductID id() const
Definition: HandleBase.cc:29
edm::InputTag
Definition: InputTag.h:15
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87