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
45  lt_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("lostTracks"))) // lost tracks
46  {
47  produces<edm::ValueMap<bool>>("isFromLostTrack"); // name of the value map that I want to actually produce
48  }
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 private:
54  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
55 
56  // ----------member data ---------------------------
59 };
60 
61 //
62 // constants, enums and typedefs
63 //
64 
65 //
66 // static data member definitions
67 //
68 
69 //
70 // member functions
71 //
72 
73 // ------------ method called to produce the data ------------
76  const edm::EventSetup& iSetup) const {
77  // isolated tracks
78  auto srcIsoTracks = iEvent.getHandle(srcIsoTracks_);
79 
80  // lostTracks collection
81  auto ltHandle = iEvent.getHandle(lt_);
82 
83  // the map cannot be filled straight away, so create an intermediate vector
84  unsigned int Nit = srcIsoTracks->size();
85  std::vector<bool> v_isFromLostTrack(Nit, false);
86 
87  for (unsigned int iit = 0; iit < Nit; iit++) {
88  auto isotrack = srcIsoTracks->ptrAt(iit);
90  isotrack->packedCandRef(); // this is either the reference to the pf candidate or to the lost track
91  bool isFromLostTrack = (pcref.isNonnull() && pcref.id() == ltHandle.id());
92  v_isFromLostTrack[iit] = isFromLostTrack;
93  }
94 
95  auto vm_isFromLostTrack = std::make_unique<edm::ValueMap<bool>>();
96  edm::ValueMap<bool>::Filler filler(*vm_isFromLostTrack);
97  filler.insert(srcIsoTracks, v_isFromLostTrack.begin(), v_isFromLostTrack.end());
98  filler.fill();
99  iEvent.put(std::move(vm_isFromLostTrack), "isFromLostTrack");
100 }
101 
102 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
105  desc.add<edm::InputTag>("srcIsoTracks")->setComment("isolated track input collection");
106  desc.add<edm::InputTag>("lostTracks")->setComment("lost tracks collection");
107 
108  descriptions.addWithDefaultLabel(desc);
109 }
110 
111 //define this as a plug-in
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
std::vector< pat::PackedCandidate > PackedCandidateCollection
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< pat::PackedCandidateCollection > lt_
ProductIndex id() const
Definition: ProductID.h:35
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
edm::EDGetTokenT< edm::View< pat::IsolatedTrack > > srcIsoTracks_
HLT enums.
IsFromLostTrackMapProducer(const edm::ParameterSet &iConfig)
def move(src, dest)
Definition: eostools.py:511
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)