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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
32 
36 
37 //
38 // class declaration
39 //
40 
42  public:
44  srcIsoTracks_(consumes<edm::View<pat::IsolatedTrack>>(iConfig.getParameter<edm::InputTag>("srcIsoTracks"))), // final isolated tracks
45  pc_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))), // pf candidates
46  lt_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("lostTracks"))) // lost tracks
47  {
48  produces<edm::ValueMap<bool>>("isFromLostTrack"); // name of the value map that I want to actually produce
49  }
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54  private:
55  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
56 
57 
58  // ----------member data ---------------------------
62 };
63 
64 //
65 // constants, enums and typedefs
66 //
67 
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // member functions
75 //
76 
77 // ------------ method called to produce the data ------------
79 {
80 
81  // isolated tracks
83  iEvent.getByToken(srcIsoTracks_, srcIsoTracks);
84 
85  // packedPFCandidate collection
87  iEvent.getByToken( pc_, pc_handle );
88 
89  // lostTracks collection
91  iEvent.getByToken( lt_, lt_handle );
92 
93  // the map cannot be filled straight away, so create an intermediate vector
94  unsigned int Nit = srcIsoTracks->size();
95  std::vector<bool> v_isFromLostTrack(Nit,false);
96 
97  for (unsigned int iit=0; iit<Nit; iit++){
98 
99  auto isotrack = srcIsoTracks->ptrAt(iit);
100  pat::PackedCandidateRef pcref = isotrack->packedCandRef(); // this is either the reference to the pf candidate or to the lost track
101  bool isFromLostTrack = (pcref.isNonnull() && pcref.id()==lt_handle.id());
102  v_isFromLostTrack[iit] = isFromLostTrack;
103 
104  }
105 
106 
107  std::unique_ptr<edm::ValueMap<bool>> vm_isFromLostTrack(new edm::ValueMap<bool>());
108  edm::ValueMap<bool>::Filler filler(*vm_isFromLostTrack);
109  filler.insert(srcIsoTracks,v_isFromLostTrack.begin(),v_isFromLostTrack.end());
110  filler.fill();
111  iEvent.put(std::move(vm_isFromLostTrack),"isFromLostTrack");
112 
113 }
114 
115 
116 
117 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
119 
121  desc.add<edm::InputTag>("srcIsoTracks")->setComment("isolated track input collection");
122  desc.add<edm::InputTag>("packedPFCandidates")->setComment("packed PF Candidates collection ");
123  desc.add<edm::InputTag>("lostTracks")->setComment("lost tracks collection");
124 
125  std::string modname;
126  modname="isFromLostTrack map producer";
127  descriptions.add(modname,desc);
128 
129 }
130 
131 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:259
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< pat::PackedCandidateCollection > lt_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< edm::View< pat::IsolatedTrack > > srcIsoTracks_
HLT enums.
IsFromLostTrackMapProducer(const edm::ParameterSet &iConfig)
def move(src, dest)
Definition: eostools.py:510
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)