24 namespace HepMC {
class GenParticle;
class GenEvent; }
38 bool fillIndices(
const HepMC::GenEvent * mc, std::vector<const HepMC::GenParticle*>& particles, std::vector<int>& barCodeVector,
int offset);
85 using namespace HepMC;
92 abortOnUnknownPDGCode_( cfg.getUntrackedParameter<bool>(
"abortOnUnknownPDGCode",
true ) ),
93 saveBarCodes_( cfg.getUntrackedParameter<bool>(
"saveBarCodes",
false ) ),
95 doSubEvent_(cfg.getUntrackedParameter<bool>(
"doSubEvent",
false )),
96 useCF_(cfg.getUntrackedParameter<bool>(
"useCrossingFrame",
false ))
98 produces<GenParticleCollection>();
101 produces<vector<int> >().setBranchAlias( alias +
"BarCodes" );
114 map<int, int>::const_iterator
f =
chargeMap_.find(
id );
118 <<
"invalid PDG id: " <<
id << endl;
120 return HepPDT::ParticleID(
id).threeCharge();
130 for( HepPDT::ParticleDataTable::const_iterator
p = pdt->begin();
p != pdt->end(); ++
p ) {
131 const HepPDT::ParticleID &
id =
p->first;
133 int q3 =
id.threeCharge();
134 if ( apdgId < PDGCacheMax && pdgId > 0 ) {
150 size_t totalSize = 0;
151 const GenEvent * mc = 0;
159 npiles = cfhepmcprod->
size();
160 LogDebug(
"GenParticleProducer")<<
"npiles : "<<npiles<<endl;
161 for(
unsigned int icf = 0; icf < npiles; ++icf){
165 LogDebug(
"GenParticleProducer")<<
"totalSize : "<<totalSize<<endl;
169 mc = mcp->GetEvent();
172 <<
"HepMC has null pointer to GenEvent" << endl;
173 totalSize = mc->particles_size();
177 const size_t size = totalSize;
178 vector<const HepMC::GenParticle *> particles( size );
180 auto_ptr<vector<int> > barCodeVector(
new vector<int>( size ) );
184 size_t suboffset = 0;
188 for(
size_t ipile = 0; ipile < npiles; ++ipile){
189 LogDebug(
"GenParticleProducer")<<
"mixed object ipile : "<<ipile<<endl;
195 const HepMC::HeavyIon * hi = mc->heavy_ion();
196 if(hi && hi->Ncoll_hard() > 1) isHI =
true;
197 size_t num_particles = mc->particles_size();
198 LogDebug(
"GenParticleProducer")<<
"num_particles : "<<num_particles<<endl;
199 fillIndices(mc, particles, *barCodeVector, offset);
201 for(
size_t ipar = offset; ipar < offset + num_particles; ++ ipar ) {
209 for(
size_t d = offset;
d < offset + num_particles; ++
d ) {
211 const GenVertex * productionVertex = part->production_vertex();
213 if ( productionVertex != 0 ) {
214 sub_id = productionVertex->id();
215 if(!isHI) sub_id = 0;
219 const GenVertex * endVertex = part->end_vertex();
220 if(endVertex != 0) sub_id = endVertex->id();
221 else throw cms::Exception(
"SubEventID" )<<
"SubEvent not determined. Particle has no production and no end vertex!"<<endl;
223 if(sub_id < 0) sub_id = 0;
224 int new_id = sub_id + suboffset;
226 cands[
d].setCollisionId(new_id);
227 LogDebug(
"VertexId")<<
"SubEvent offset 3 : "<<suboffset;
231 nsub = hi->Ncoll_hard()+1;
236 offset += num_particles;
242 for(
size_t i = 0;
i < particles.size(); ++
i ) {
251 for(
size_t d = 0;
d < cands.size(); ++
d ) {
253 const GenVertex * productionVertex = part->production_vertex();
256 cands[
d].setCollisionId(0);
262 if(cfhepmcprod)
delete cfhepmcprod;
268 int pdgId = part->pdg_id();
274 const GenVertex *
v = part->production_vertex();
276 ThreeVector vtx = v->point3d();
288 const GenVertex * productionVertex = part->production_vertex();
289 size_t numberOfMothers = productionVertex->particles_in_size();
290 if ( numberOfMothers > 0 ) {
291 GenVertex::particles_in_const_iterator motherIt = productionVertex->particles_in_const_begin();
292 for( ; motherIt != productionVertex->particles_in_const_end(); motherIt++) {
305 HepMC::GenEvent::particle_const_iterator
begin = mc->particles_begin(),
end = mc->particles_end();
306 for( HepMC::GenEvent::particle_const_iterator
p = begin;
p !=
end; ++
p ) {
308 size_t barCode_this_event = particle->barcode();
309 size_t barCode = barCode_this_event +
offset;
312 <<
"barcodes are duplicated! " << endl;
313 particles[
idx] = particle;
314 barCodeVector[
idx] = barCode;
315 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
MCTruthHelper< HepMC::GenParticle > mcTruthHelper_
void fillGenStatusFlags(const P &p, reco::GenStatusFlags &statusFlags)
bool fillDaughters(reco::GenParticleCollection &cand, const HepMC::GenParticle *part, size_t index)
void setCollisionId(int s)
std::vector< int > chargeP_
charge indices
MCTruthHelper< reco::GenParticle > mcTruthHelperGenParts_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::map< int, size_t > barcodes_
virtual void setStatus(int status)
set status word
#define DEFINE_FWK_MODULE(type)
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
std::vector< edm::EDGetTokenT< edm::HepMCProduct > > vectorSrcTokens_
virtual void setP4(const LorentzVector &p4)
set 4-momentum
~GenParticleProducer()
destructor
virtual void produce(edm::Event &e, const edm::EventSetup &) override
process one event
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > mixToken_
int chargeTimesThree(int) const
edm::EDGetTokenT< edm::HepMCProduct > srcToken_
source collection name
void getData(T &iHolder) const
U second(std::pair< T, U > const &p)
reco::GenParticleRefProd ref_
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.
Abs< T >::type abs(const T &t)
virtual void setVertex(const Point &vertex)
set vertex
RefProd< PROD > getRefBeforePut()
const GenStatusFlags & statusFlags() const
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
T const * product() const
static const double mmToCm
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
std::map< int, int > chargeMap_
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
volatile std::atomic< bool > shutdown_flag false
tuple size
Write out results.
static const int PDGCacheMax