Public Member Functions | |
GenParticleProducer (const edm::ParameterSet &) | |
constructor | |
~GenParticleProducer () | |
destructor | |
Private Member Functions | |
void | beginJob (const edm::EventSetup &) |
module init at begin of job | |
int | chargeTimesThree (int) const |
void | produce (edm::Event &e, const edm::EventSetup &) |
process one event | |
Private Attributes | |
bool | abortOnUnknownPDGCode_ |
unknown code treatment flag | |
std::vector< int > | chargeM_ |
std::map< int, int > | chargeMap_ |
std::vector< int > | chargeP_ |
charge indices | |
bool | saveBarCodes_ |
save bar-codes | |
edm::InputTag | src_ |
source collection name |
Definition at line 22 of file GenParticleProducer.cc.
GenParticleProducer::GenParticleProducer | ( | const edm::ParameterSet & | cfg | ) |
constructor
Definition at line 65 of file GenParticleProducer.cc.
References edm::ParameterSet::getParameter(), and saveBarCodes_.
00065 : 00066 src_( cfg.getParameter<InputTag>( "src" ) ), 00067 abortOnUnknownPDGCode_( cfg.getUntrackedParameter<bool>( "abortOnUnknownPDGCode", true ) ), 00068 saveBarCodes_( cfg.getUntrackedParameter<bool>( "saveBarCodes", false ) ), 00069 chargeP_( PDGCacheMax, 0 ), chargeM_( PDGCacheMax, 0 ) { 00070 produces<GenParticleCollection>(); 00071 if( saveBarCodes_ ) { 00072 std::string alias( cfg.getParameter<std::string>( "@module_label" ) ); 00073 produces<vector<int> >().setBranchAlias( alias + "BarCodes" ); 00074 } 00075 }
GenParticleProducer::~GenParticleProducer | ( | ) |
void GenParticleProducer::beginJob | ( | const edm::EventSetup & | es | ) | [private, virtual] |
module init at begin of job
Reimplemented from edm::EDProducer.
Definition at line 94 of file GenParticleProducer.cc.
References funct::abs(), chargeM_, chargeMap_, chargeP_, edm::EventSetup::getData(), p, gen_jpsi2muons_cfg::ParticleID, and PDGCacheMax.
00094 { 00095 ESHandle<HepPDT::ParticleDataTable> pdt; 00096 es.getData( pdt ); 00097 for( HepPDT::ParticleDataTable::const_iterator p = pdt->begin(); p != pdt->end(); ++ p ) { 00098 const HepPDT::ParticleID & id = p->first; 00099 int pdgId = id.pid(), apdgId = abs( pdgId ); 00100 int q3 = id.threeCharge(); 00101 if ( apdgId < PDGCacheMax && pdgId > 0 ) { 00102 chargeP_[ apdgId ] = q3; 00103 chargeM_[ apdgId ] = -q3; 00104 } else if ( apdgId < PDGCacheMax ) { 00105 chargeP_[ apdgId ] = -q3; 00106 chargeM_[ apdgId ] = q3; 00107 } else { 00108 chargeMap_[ pdgId ] = q3; 00109 chargeMap_[ -pdgId ] = -q3; 00110 } 00111 } 00112 }
Definition at line 80 of file GenParticleProducer.cc.
References abortOnUnknownPDGCode_, funct::abs(), chargeM_, chargeMap_, chargeP_, lat::endl(), f, edm::errors::LogicError, gen_jpsi2muons_cfg::ParticleID, and PDGCacheMax.
Referenced by produce().
00080 { 00081 if( abs( id ) < PDGCacheMax ) 00082 return id > 0 ? chargeP_[ id ] : chargeM_[ - id ]; 00083 map<int, int>::const_iterator f = chargeMap_.find( id ); 00084 if ( f == chargeMap_.end() ) 00085 if ( abortOnUnknownPDGCode_ ) 00086 throw edm::Exception( edm::errors::LogicError ) 00087 << "invalid PDG id: " << id << endl; 00088 else { 00089 return HepPDT::ParticleID(id).threeCharge(); 00090 } 00091 return f->second; 00092 }
void GenParticleProducer::produce | ( | edm::Event & | e, | |
const edm::EventSetup & | es | |||
) | [private, virtual] |
process one event
fill indices
Implements edm::EDProducer.
Definition at line 114 of file GenParticleProducer.cc.
References begin, chargeTimesThree(), d, end, lat::endl(), edm::Event::getByLabel(), edm::Event::getRefBeforePut(), i, edm::RefProd< C >::id(), edm::errors::InvalidReference, m, mmToCm, p, p4, edm::Event::put(), reco::CompositeRefCandidateT< D >::resetDaughters(), saveBarCodes_, edm::second(), reco::Particle::setP4(), reco::Particle::setPdgId(), reco::Particle::setStatus(), reco::Particle::setThreeCharge(), reco::Particle::setVertex(), size, src_, and v.
00114 { 00115 Handle<HepMCProduct> mcp; 00116 evt.getByLabel( src_, mcp ); 00117 const GenEvent * mc = mcp->GetEvent(); 00118 if( mc == 0 ) 00119 throw edm::Exception( edm::errors::InvalidReference ) 00120 << "HepMC has null pointer to GenEvent" << endl; 00121 const size_t size = mc->particles_size(); 00122 00123 vector<const HepMC::GenParticle *> particles( size ); 00124 map<int, size_t> barcodes; 00125 00126 auto_ptr<GenParticleCollection> candsPtr( new GenParticleCollection( size ) ); 00127 auto_ptr<vector<int> > barCodeVector( new vector<int>( size ) ); 00128 const GenParticleRefProd ref = evt.getRefBeforePut<GenParticleCollection>(); 00129 GenParticleCollection & cands = * candsPtr; 00130 00132 GenEvent::particle_const_iterator begin = mc->particles_begin(), end = mc->particles_end(); 00133 size_t idx = 0; 00134 for( GenEvent::particle_const_iterator p = begin; p != end; ++ p ) { 00135 const HepMC::GenParticle * particle = * p; 00136 size_t barCode = particle->barcode(); 00137 if( barcodes.find(barCode) != barcodes.end() ) 00138 throw cms::Exception( "WrongReference" ) 00139 << "barcodes are duplicated! " << endl; 00140 particles[idx] = particle; 00141 (*barCodeVector)[idx] = barCode; 00142 barcodes.insert( make_pair(barCode, idx ++) ); 00143 } 00144 00145 // fill output collection and save association 00146 for( size_t i = 0; i < particles.size(); ++ i ) { 00147 const HepMC::GenParticle * part = particles[ i ]; 00148 Candidate::LorentzVector p4( part->momentum() ); 00149 int pdgId = part->pdg_id(); 00150 reco::GenParticle & cand = cands[ i ]; 00151 cand.setThreeCharge( chargeTimesThree( pdgId ) ); 00152 cand.setPdgId( pdgId ); 00153 cand.setStatus( part->status() ); 00154 cand.setP4( p4 ); 00155 const GenVertex * v = part->production_vertex(); 00156 if ( v != 0 ) { 00157 ThreeVector vtx = v->point3d(); 00158 Candidate::Point vertex( vtx.x() * mmToCm, vtx.y() * mmToCm, vtx.z() * mmToCm ); 00159 cand.setVertex( vertex ); 00160 } else { 00161 cand.setVertex( Candidate::Point( 0, 0, 0 ) ); 00162 } 00163 cand.resetDaughters( ref.id() ); 00164 } 00165 00166 // fill references to daughters 00167 for( size_t d = 0; d < cands.size(); ++ d ) { 00168 const HepMC::GenParticle * part = particles[ d ]; 00169 const GenVertex * productionVertex = part->production_vertex(); 00170 if ( productionVertex != 0 ) { 00171 size_t numberOfMothers = productionVertex->particles_in_size(); 00172 if ( numberOfMothers > 0 ) { 00173 GenVertex::particles_in_const_iterator motherIt = productionVertex->particles_in_const_begin(); 00174 for( ; motherIt != productionVertex->particles_in_const_end(); motherIt++) { 00175 const HepMC::GenParticle * mother = * motherIt; 00176 size_t m = barcodes.find( mother->barcode() )->second; 00177 cands[ m ].addDaughter( GenParticleRef( ref, d ) ); 00178 cands[ d ].addMother( GenParticleRef( ref, m ) ); 00179 } 00180 } 00181 } 00182 } 00183 00184 evt.put( candsPtr ); 00185 if(saveBarCodes_) evt.put( barCodeVector ); 00186 }
unknown code treatment flag
Definition at line 37 of file GenParticleProducer.cc.
Referenced by chargeTimesThree().
std::vector<int> GenParticleProducer::chargeM_ [private] |
Definition at line 41 of file GenParticleProducer.cc.
Referenced by beginJob(), and chargeTimesThree().
std::map<int, int> GenParticleProducer::chargeMap_ [private] |
Definition at line 42 of file GenParticleProducer.cc.
Referenced by beginJob(), and chargeTimesThree().
std::vector<int> GenParticleProducer::chargeP_ [private] |
charge indices
Definition at line 41 of file GenParticleProducer.cc.
Referenced by beginJob(), and chargeTimesThree().
bool GenParticleProducer::saveBarCodes_ [private] |
save bar-codes
Definition at line 39 of file GenParticleProducer.cc.
Referenced by GenParticleProducer(), and produce().
edm::InputTag GenParticleProducer::src_ [private] |
source collection name
Definition at line 35 of file GenParticleProducer.cc.
Referenced by produce().