CMS 3D CMS Logo

GenTrackMatcher.cc
Go to the documentation of this file.
1 
14 
15 namespace edm
16 {
17 class ParameterSet;
18 }
19 
20 using namespace edm;
21 using namespace std;
22 using namespace reco;
23 
25 {
26 public:
29 
30 private:
31  void produce( edm::Event& evt, const edm::EventSetup& es ) override;
37 };
38 
44 
46  tracer_(p,consumesCollector()),
47  tracks_(consumes<View<Track>>(p.getUntrackedParameter<edm::InputTag>("trackProducer"))),
48  genParticles_(consumes<GenParticleCollection>(p.getUntrackedParameter<edm::InputTag>("genParticles"))),
49  genParticleInts_(consumes<vector<int>>(p.getUntrackedParameter<edm::InputTag>("genParticles")))
50 {
51  produces<GenParticleMatch>();
52 }
53 
55 {
57  evt.getByToken(tracks_, tracks);
58  Handle<vector<int> > barCodes;
59  evt.getByToken(genParticles_, barCodes);
61  evt.getByToken(genParticles_, genParticles);
62  unique_ptr<GenParticleMatch> match(new GenParticleMatch(GenParticleRefProd(genParticles)));
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 );
77  if (f == e) {
81  << "found matching particle with barcode" << *f
82  << " which has not been found in " << labels.module;
83  }
84  indices[i] = *f;
85  }
86  }
87  }
88  filler.insert(tracks, indices.begin(), indices.end());
89  filler.fill();
90  evt.put(std::move(match));
91 }
92 
94 
96 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
void newEvent(const edm::Event &, const edm::EventSetup &)
Pre-process event information (for accessing reconstruction information)
Definition: TrackHistory.cc:39
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
void produce(edm::Event &evt, const edm::EventSetup &es) override
const std::vector< reco::PFCandidatePtr > & tracks_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
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:20
edm::EDGetTokenT< GenParticleCollection > genParticles_
GenTrackMatcher(const edm::ParameterSet &)
constructor
double f[11][100]
edm::EDGetTokenT< vector< int > > genParticleInts_
This class traces the simulated and generated history of a given track.
Definition: TrackHistory.h:17
char const * module
Definition: ProductLabels.h:5
double b
Definition: hdecay.h:120
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
edm::EDGetTokenT< View< Track > > tracks_
fixed size matrix
TrackHistory tracer_
HLT enums.
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
def move(src, dest)
Definition: eostools.py:510
edm::Association< reco::GenParticleCollection > GenParticleMatch
const HepMC::GenParticle * genParticle() const
Returns a pointer to most primitive status 1 or 2 particle in the genParticleTrail_.
Definition: HistoryBase.h:101