CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCTruthCompositeMatcherNew.cc
Go to the documentation of this file.
1 /* \class MCTruthCompositeMatcher
2  *
3  * \author Luca Lista, INFN
4  *
5  */
6 
15 
16 namespace reco {
17  namespace modulesNew {
18 
20  public:
21  explicit MCTruthCompositeMatcher( const edm::ParameterSet & );
23  private:
25  std::vector<edm::InputTag> matchMaps_;
26  std::vector<int> pdgId_;
27  void produce( edm::Event & , const edm::EventSetup & );
28  };
29 
31  src_(cfg.getParameter<edm::InputTag>("src")),
32  matchMaps_(cfg.getParameter<std::vector<edm::InputTag> >("matchMaps")),
33  pdgId_(cfg.getParameter<std::vector<int> >("matchPDGId")) {
34  produces<reco::GenParticleMatch>();
35  }
36 
38  }
39 
41  using namespace edm;
42  using namespace std;
44  evt.getByLabel(src_, cands);
45  size_t nMaps = matchMaps_.size();
46  std::vector<const GenParticleMatch *> maps;
47  maps.reserve( nMaps );
48  for( size_t i = 0; i != nMaps; ++ i ) {
50  evt.getByLabel(matchMaps_[i], matchMap);
51  maps.push_back(& * matchMap);
52  }
54  auto_ptr<GenParticleMatch> matchMap(new GenParticleMatch(match.ref()));
55  int size = cands->size();
56  vector<int>::const_iterator begin = pdgId_.begin(), end = pdgId_.end();
57  if(size != 0) {
58  GenParticleMatch::Filler filler(*matchMap);
59  vector<int> indices(size);
60  for(int i = 0; i != size; ++ i) {
61  const Candidate & cand = (* cands)[i];
62  GenParticleRef mc = match[cand];
63  if(mc.isNull()) {
64  indices[i] = -1;
65  } else {
66  bool found = true;
67  if(begin!=end) found = find(begin, end, std::abs(mc->pdgId())) != end;
68  indices[i] = found ? int(mc.key()) : -1;
69  }
70  }
71  CandidateBaseRefProd ref(cands->refAt(0));
72  filler.insert(ref, indices.begin(), indices.end());
73  filler.fill();
74  }
75  evt.put(matchMap);
76  }
77 
78  }
79 }
80 
83 
84 namespace reco {
85  namespace modulesNew {
86 
88 
90 
91  }
92 }
int i
Definition: DBlmapReader.cc:9
DEFINE_FWK_MODULE(MCTruthCompositeMatcherNew)
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
#define abs(x)
Definition: mlp_lapack.h:159
map_type::refprod_type ref() const
reference to matched collection
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
bool isNull() const
Checks for null.
Definition: Ref.h:247
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
#define end
Definition: vmac.h:38
void produce(edm::Event &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
key_type key() const
Accessor for product key.
Definition: Ref.h:266
MCTruthCompositeMatcher MCTruthCompositeMatcherNew
#define begin
Definition: vmac.h:31
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
tuple size
Write out results.
edm::Association< GenParticleCollection > GenParticleMatch
vector of reference to GenParticle in the same collection