CMS 3D CMS Logo

MCTruthCompositeMatcherNew.cc
Go to the documentation of this file.
1 /* \class MCTruthCompositeMatcher
2  *
3  * \author Luca Lista, INFN
4  *
5  */
6 
19 
20 namespace reco {
21  namespace modulesNew {
22 
24  public:
26 
27  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
28 
29  private:
31  std::vector<edm::EDGetTokenT<reco::GenParticleMatch>> matchMapTokens_;
32  std::vector<int> pdgId_;
33  void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
34  };
35 
37  : srcToken_(consumes<CandidateView>(cfg.getParameter<edm::InputTag>("src"))),
38  matchMapTokens_(edm::vector_transform(
39  cfg.template getParameter<std::vector<edm::InputTag>>("matchMaps"),
40  [this](edm::InputTag const &tag) { return consumes<reco::GenParticleMatch>(tag); })),
41  pdgId_(cfg.getParameter<std::vector<int>>("matchPDGId")) {
42  produces<reco::GenParticleMatch>();
43  }
44 
47  desc.add<edm::InputTag>("src");
48  desc.add<std::vector<edm::InputTag>>("matchMaps");
49  desc.add<std::vector<int>>("matchPDGId");
50 
51  descriptions.addDefault(desc);
52  }
53 
55  using namespace edm;
56  using namespace std;
59  size_t nMaps = matchMapTokens_.size();
60  std::vector<const GenParticleMatch *> maps;
61  maps.reserve(nMaps);
62  for (size_t i = 0; i != nMaps; ++i) {
64  evt.getByToken(matchMapTokens_[i], matchMap);
65  maps.push_back(&*matchMap);
66  }
68  auto matchMap = std::make_unique<GenParticleMatch>(match.ref());
69  int size = cands->size();
70  vector<int>::const_iterator begin = pdgId_.begin(), end = pdgId_.end();
71  if (size != 0) {
73  vector<int> indices(size);
74  for (int i = 0; i != size; ++i) {
75  const Candidate &cand = (*cands)[i];
76  GenParticleRef mc = match[cand];
77  if (mc.isNull()) {
78  indices[i] = -1;
79  } else {
80  bool found = true;
81  if (begin != end)
82  found = find(begin, end, std::abs(mc->pdgId())) != end;
83  indices[i] = found ? int(mc.key()) : -1;
84  }
85  }
87  filler.insert(ref, indices.begin(), indices.end());
88  filler.fill();
89  }
90  evt.put(std::move(matchMap));
91  }
92 
93  } // namespace modulesNew
94 } // namespace reco
95 
98 
99 namespace reco {
100  namespace modulesNew {
101 
103 
105 
106  } // namespace modulesNew
107 } // namespace reco
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::vector< edm::EDGetTokenT< reco::GenParticleMatch > > matchMapTokens_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void addDefault(ParameterSetDescription const &psetDescription)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MCTruthCompositeMatcher MCTruthCompositeMatcherNew
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
fixed size matrix
HLT enums.
def move(src, dest)
Definition: eostools.py:511
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)