CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
ProductID id() const
Definition: HandleBase.cc:29
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< pat::PackedCandidate > PackedCandidateCollection
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
edm::EDGetTokenT< pat::PackedCandidateCollection > lt_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
edm::EDGetTokenT< edm::View< pat::IsolatedTrack > > srcIsoTracks_
IsFromLostTrackMapProducer(const edm::ParameterSet &iConfig)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)