CMS 3D CMS Logo

MCTrackMatcher Class Reference

Author:
Luca Lista, INFN
More...

Inheritance diagram for MCTrackMatcher:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 MCTrackMatcher (const edm::ParameterSet &)
 constructor

Private Types

typedef edm::Association
< reco::GenParticleCollection
GenParticleMatch

Private Member Functions

void produce (edm::Event &evt, const edm::EventSetup &es)

Private Attributes

std::string associator_
edm::InputTag genParticles_
edm::InputTag trackingParticles_
edm::InputTag tracks_


Detailed Description

Author:
Luca Lista, INFN

Version:
Id
MCTrackMatcher.cc,v 1.5 2007/12/18 16:15:33 cerati Exp

Definition at line 15 of file MCTrackMatcher.cc.


Member Typedef Documentation

typedef edm::Association<reco::GenParticleCollection> MCTrackMatcher::GenParticleMatch [private]

Definition at line 24 of file MCTrackMatcher.cc.


Constructor & Destructor Documentation

MCTrackMatcher::MCTrackMatcher ( const edm::ParameterSet p  ) 

constructor

Definition at line 39 of file MCTrackMatcher.cc.

00039                                                      :
00040   associator_(p.getParameter<string>("associator")),
00041   tracks_(p.getParameter<InputTag>("tracks")),
00042   genParticles_( p.getParameter<InputTag>("genParticles")),
00043   trackingParticles_( p.getParameter<InputTag>("trackingParticles")) {
00044   produces<GenParticleMatch>();
00045 }


Member Function Documentation

void MCTrackMatcher::produce ( edm::Event evt,
const edm::EventSetup es 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 47 of file MCTrackMatcher.cc.

References TrackAssociatorBase::associateRecoToSim(), associator_, b, e, edm::AssociationMap< Tag >::end(), f, edm::helper::Filler< Map >::fill(), find(), edm::AssociationMap< Tag >::find(), genParticles_cfi::genParticles, genParticles_, edm::EventSetup::get(), edm::Event::getByLabel(), i, edm::helper::Filler< Map >::insert(), edm::errors::InvalidReference, j, edm::match(), n, p, edm::ESHandle< T >::product(), edm::Event::put(), tp, track, trackingParticles_cfi::trackingParticles, trackingParticles_, tracks, and tracks_.

00047                                                              {
00048   ESHandle<TrackAssociatorBase> assoc;  
00049   es.get<TrackAssociatorRecord>().get(associator_,assoc);
00050   const TrackAssociatorBase * associator = assoc.product();
00051   Handle<View<Track> > tracks;
00052   evt.getByLabel(tracks_, tracks);
00053   Handle<TrackingParticleCollection> trackingParticles;
00054   evt.getByLabel(trackingParticles_,trackingParticles);
00055   Handle<vector<int> > barCodes;
00056   evt.getByLabel(genParticles_,barCodes );
00057   Handle<GenParticleCollection> genParticles;
00058   evt.getByLabel(genParticles_, genParticles );
00059   RecoToSimCollection associations = associator->associateRecoToSim ( tracks, trackingParticles, & evt ); 
00060   auto_ptr<GenParticleMatch> match(new GenParticleMatch(GenParticleRefProd(genParticles)));
00061   GenParticleMatch::Filler filler(*match);
00062   size_t n = tracks->size();
00063   vector<int> indices(n,-1);
00064   for (size_t i = 0; i < n; ++ i ) {
00065     RefToBase<Track> track(tracks, i);
00066     RecoToSimCollection::const_iterator f = associations.find(track);
00067     if ( f != associations.end() ) {
00068       TrackingParticleRef tp = f->val.front().first;
00069       const HepMC::GenParticle * particle = 0;
00070       TrackingParticle::genp_iterator j, b = tp->genParticle_begin(), e = tp->genParticle_end();
00071       for( j = b; j != e; ++ j ) {
00072         const HepMC::GenParticle * p = j->get();
00073         if (p->status() == 1) {
00074           particle = p; break;
00075         }
00076       }
00077       if( particle != 0 ) {
00078         int barCode = particle->barcode();
00079         vector<int>::const_iterator 
00080           b = barCodes->begin(), e = barCodes->end(), f = find( b, e, barCode );
00081         if(f == e) throw edm::Exception(errors::InvalidReference)
00082           << "found matching particle with barcode" << *f
00083           << " which has not been found in " << genParticles_;
00084         indices[i] = *f;
00085       }
00086     }
00087   }
00088   filler.insert(tracks, indices.begin(), indices.end());
00089   filler.fill();
00090   evt.put(match);
00091 }


Member Data Documentation

std::string MCTrackMatcher::associator_ [private]

Definition at line 22 of file MCTrackMatcher.cc.

Referenced by produce().

edm::InputTag MCTrackMatcher::genParticles_ [private]

Definition at line 23 of file MCTrackMatcher.cc.

Referenced by produce().

edm::InputTag MCTrackMatcher::trackingParticles_ [private]

Definition at line 23 of file MCTrackMatcher.cc.

Referenced by produce().

edm::InputTag MCTrackMatcher::tracks_ [private]

Definition at line 23 of file MCTrackMatcher.cc.

Referenced by produce().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:28:09 2009 for CMSSW by  doxygen 1.5.4