CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenTrackMatcher.cc
Go to the documentation of this file.
1 
14 
15 namespace edm
16 {
17 class ParameterSet;
18 }
19 
21 {
22 public:
25 
26 private:
27  void produce( edm::Event& evt, const edm::EventSetup& es ) override;
31 };
32 
38 
39 using namespace edm;
40 using namespace std;
41 using namespace reco;
42 
44  tracer_(p,consumesCollector()),
45  tracks_(p.getUntrackedParameter<edm::InputTag>("trackProducer")),
46  genParticles_(p.getUntrackedParameter<edm::InputTag>("genParticles"))
47 {
48  consumes<View<Track>>(tracks_);
49  consumes<vector<int>>(genParticles_);
50  consumes<GenParticleCollection>(genParticles_);
51  produces<GenParticleMatch>();
52 }
53 
55 {
57  evt.getByLabel(tracks_, tracks);
58  Handle<vector<int> > barCodes;
59  evt.getByLabel(genParticles_, barCodes);
61  evt.getByLabel(genParticles_, genParticles);
62  auto_ptr<GenParticleMatch> match(new GenParticleMatch(GenParticleRefProd(genParticles)));
63  GenParticleMatch::Filler filler(*match);
64  size_t n = tracks->size();
65  vector<int> indices(n,-1);
66  tracer_.newEvent(evt, es);
67  for (size_t i = 0; i < n; ++ i )
68  {
69  RefToBase<Track> track(tracks, i);
70  if (tracer_.evaluate(track))
71  {
72  const HepMC::GenParticle * particle = tracer_.genParticle();
73  if (particle)
74  {
75  int barCode = particle->barcode();
76  vector<int>::const_iterator b = barCodes->begin(), e = barCodes->end(), f = find( b, e, barCode );
78  << "found matching particle with barcode" << *f
79  << " which has not been found in " << genParticles_;
80  indices[i] = *f;
81  }
82  }
83  }
84  filler.insert(tracks, indices.begin(), indices.end());
85  filler.fill();
86  evt.put(match);
87 }
88 
90 
92 
int i
Definition: DBlmapReader.cc:9
void newEvent(const edm::Event &, const edm::EventSetup &)
Pre-process event information (for accessing reconstruction information)
Definition: TrackHistory.cc:39
void produce(edm::Event &evt, const edm::EventSetup &es) override
const std::vector< reco::PFCandidatePtr > & tracks_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
edm::RefProd< GenParticleCollection > GenParticleRefProd
persistent reference to a GenParticle collection
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::InputTag genParticles_
GenTrackMatcher(const edm::ParameterSet &)
constructor
double f[11][100]
This class traces the simulated and generated history of a given track.
Definition: TrackHistory.h:17
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
tuple tracks
Definition: testEve_cfg.py:39
double b
Definition: hdecay.h:120
edm::InputTag tracks_
TrackHistory tracer_
bool evaluate(TrackingParticleRef tpr)
Evaluate track history using a TrackingParticleRef.
Definition: TrackHistory.h:41
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
edm::Association< reco::GenParticleCollection > GenParticleMatch
const HepMC::GenParticle * genParticle() const
Returns a pointer to most primitive status 1 or 2 particle.
Definition: HistoryBase.h:89