23 namespace HepMC {
class GenParticle;
class GenEvent; }
37 bool fillIndices(
const HepMC::GenEvent * mc, std::vector<const HepMC::GenParticle*>& particles, std::vector<int>& barCodeVector,
int offset);
80 using namespace HepMC;
87 abortOnUnknownPDGCode_( cfg.getUntrackedParameter<bool>(
"abortOnUnknownPDGCode",
true ) ),
88 saveBarCodes_( cfg.getUntrackedParameter<bool>(
"saveBarCodes",
false ) ),
90 doSubEvent_(cfg.getUntrackedParameter<bool>(
"doSubEvent",
false )),
91 useCF_(cfg.getUntrackedParameter<bool>(
"useCrossingFrame",
false ))
93 produces<GenParticleCollection>();
96 produces<vector<int> >().setBranchAlias( alias +
"BarCodes" );
113 map<int, int>::const_iterator
f =
chargeMap_.find(
id );
117 <<
"invalid PDG id: " <<
id << endl;
129 for( HepPDT::ParticleDataTable::const_iterator
p = pdt->begin();
p != pdt->end(); ++
p ) {
132 int q3 =
id.threeCharge();
133 if ( apdgId < PDGCacheMax && pdgId > 0 ) {
149 size_t totalSize = 0;
150 const GenEvent * mc = 0;
151 std::vector<Handle<HepMCProduct> > heps;
159 npiles = cfhepmcprod->
size();
160 for(
unsigned int icf = 0; icf < npiles; ++icf){
164 for(
size_t i = 0;
i < npiles; ++
i){
167 heps.push_back(handle);
169 totalSize += heps[
i]->GetEvent()->particles_size();
174 mc = mcp->GetEvent();
177 <<
"HepMC has null pointer to GenEvent" << endl;
178 totalSize = mc->particles_size();
182 const size_t size = totalSize;
183 vector<const HepMC::GenParticle *> particles( size );
186 auto_ptr<vector<int> > barCodeVector(
new vector<int>( size ) );
191 size_t suboffset = 0;
195 for(
size_t i = 0;
i < npiles; ++
i){
198 else mc = heps[
i]->GetEvent();
202 const HepMC::HeavyIon * hi = mc->heavy_ion();
203 if(hi && hi->Ncoll_hard() > 1) isHI =
true;
204 size_t num_particles = mc->particles_size();
205 fillIndices(mc, particles, *barCodeVector, offset);
207 for(
size_t i = offset;
i < offset + num_particles; ++
i ) {
216 for(
size_t d = offset; d < offset + num_particles; ++ d ) {
218 const GenVertex * productionVertex = part->production_vertex();
220 if ( productionVertex != 0 ) {
221 sub_id = productionVertex->id();
222 if(!isHI) sub_id = 0;
226 const GenVertex * endVertex = part->end_vertex();
227 if(endVertex != 0) sub_id = endVertex->id();
228 else throw cms::Exception(
"SubEventID" )<<
"SubEvent not determined. Particle has no production and no end vertex!"<<endl;
230 if(sub_id < 0) sub_id = 0;
231 int new_id = sub_id + suboffset;
234 cands[d].setCollisionId(new_id);
235 LogDebug(
"VertexId")<<
"SubEvent offset 3 : "<<suboffset;
239 nsub = hi->Ncoll_hard()+1;
244 offset += num_particles;
250 for(
size_t i = 0;
i < particles.size(); ++
i ) {
259 for(
size_t d = 0; d < cands.size(); ++ d ) {
261 const GenVertex * productionVertex = part->production_vertex();
264 cands[d].setCollisionId(0);
271 if(cfhepmcprod)
delete cfhepmcprod;
277 int pdgId = part->pdg_id();
283 const GenVertex *
v = part->production_vertex();
285 ThreeVector vtx = v->point3d();
296 const GenVertex * productionVertex = part->production_vertex();
297 size_t numberOfMothers = productionVertex->particles_in_size();
298 if ( numberOfMothers > 0 ) {
299 GenVertex::particles_in_const_iterator motherIt = productionVertex->particles_in_const_begin();
300 for( ; motherIt != productionVertex->particles_in_const_end(); motherIt++) {
313 HepMC::GenEvent::particle_const_iterator
begin = mc->particles_begin(),
end = mc->particles_end();
314 for( HepMC::GenEvent::particle_const_iterator
p = begin;
p !=
end; ++
p ) {
316 size_t barCode_this_event = particle->barcode();
317 size_t barCode = barCode_this_event +
offset;
320 <<
"barcodes are duplicated! " << endl;
321 particles[idx] = particle;
322 barCodeVector[idx] = barCode;
323 barcodes_.insert( make_pair(barCode_this_event, idx ++) );
GenParticleProducer(const edm::ParameterSet &)
constructor
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
bool abortOnUnknownPDGCode_
unknown code treatment flag
T getUntrackedParameter(std::string const &, T const &) const
bool fillDaughters(reco::GenParticleCollection &cand, const HepMC::GenParticle *part, size_t index)
edm::InputTag src_
source collection name
void setCollisionId(int s)
std::vector< int > chargeP_
charge indices
std::map< int, size_t > barcodes_
virtual void setStatus(int status)
set status word
#define DEFINE_FWK_MODULE(type)
virtual void setP4(const LorentzVector &p4)
set 4-momentum
~GenParticleProducer()
destructor
int chargeTimesThree(int) const
edm::Ref< edm::HepMCProduct, HepMC::GenParticle > GenParticleRef
void getData(T &iHolder) const
U second(std::pair< T, U > const &p)
reco::GenParticleRefProd ref_
virtual void produce(edm::Event &e, const edm::EventSetup &)
process one event
void resetDaughters(const edm::ProductID &id)
set daughters product ID
bool firstEvent_
whether the first event was looked at
virtual void setThreeCharge(Charge qx3)
set electric charge
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
unsigned int offset(bool)
virtual void setVertex(const Point &vertex)
set vertex
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
RefProd< PROD > getRefBeforePut()
bool fillIndices(const HepMC::GenEvent *mc, std::vector< const HepMC::GenParticle * > &particles, std::vector< int > &barCodeVector, int offset)
bool convertParticle(reco::GenParticle &cand, const HepMC::GenParticle *part)
const T & getObject(unsigned int ip) const
const HepMC::GenEvent * GetEvent() const
static const double mmToCm
std::map< int, int > chargeMap_
T const * product() const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
bool doSubEvent_
input & output modes
std::vector< int > chargeM_
ProductID id() const
Accessor for product ID.
virtual void setPdgId(int pdgId)
math::XYZPoint Point
point in the space
bool saveBarCodes_
save bar-codes
std::vector< std::string > vectorSrc_
tuple size
Write out results.
static const int PDGCacheMax