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);
82 using namespace HepMC;
89 abortOnUnknownPDGCode_( cfg.getUntrackedParameter<bool>(
"abortOnUnknownPDGCode",
true ) ),
90 saveBarCodes_( cfg.getUntrackedParameter<bool>(
"saveBarCodes",
false ) ),
92 doSubEvent_(cfg.getUntrackedParameter<bool>(
"doSubEvent",
false )),
93 useCF_(cfg.getUntrackedParameter<bool>(
"useCrossingFrame",
false ))
95 produces<GenParticleCollection>();
98 produces<vector<int> >().setBranchAlias( alias +
"BarCodes" );
111 map<int, int>::const_iterator
f =
chargeMap_.find(
id );
115 <<
"invalid PDG id: " <<
id << endl;
127 for( HepPDT::ParticleDataTable::const_iterator
p = pdt->begin();
p != pdt->end(); ++
p ) {
130 int q3 =
id.threeCharge();
131 if ( apdgId < PDGCacheMax && pdgId > 0 ) {
147 size_t totalSize = 0;
148 const GenEvent * mc = 0;
156 npiles = cfhepmcprod->
size();
157 LogDebug(
"GenParticleProducer")<<
"npiles : "<<npiles<<endl;
158 for(
unsigned int icf = 0; icf < npiles; ++icf){
162 LogDebug(
"GenParticleProducer")<<
"totalSize : "<<totalSize<<endl;
166 mc = mcp->GetEvent();
169 <<
"HepMC has null pointer to GenEvent" << endl;
170 totalSize = mc->particles_size();
174 const size_t size = totalSize;
175 vector<const HepMC::GenParticle *> particles( size );
177 auto_ptr<vector<int> > barCodeVector(
new vector<int>( size ) );
181 size_t suboffset = 0;
185 for(
size_t ipile = 0; ipile < npiles; ++ipile){
186 LogDebug(
"GenParticleProducer")<<
"mixed object ipile : "<<ipile<<endl;
192 const HepMC::HeavyIon * hi = mc->heavy_ion();
193 if(hi && hi->Ncoll_hard() > 1) isHI =
true;
194 size_t num_particles = mc->particles_size();
195 LogDebug(
"GenParticleProducer")<<
"num_particles : "<<num_particles<<endl;
196 fillIndices(mc, particles, *barCodeVector, offset);
198 for(
size_t ipar = offset; ipar < offset + num_particles; ++ ipar ) {
206 for(
size_t d = offset; d < offset + num_particles; ++ d ) {
208 const GenVertex * productionVertex = part->production_vertex();
210 if ( productionVertex != 0 ) {
211 sub_id = productionVertex->id();
212 if(!isHI) sub_id = 0;
216 const GenVertex * endVertex = part->end_vertex();
217 if(endVertex != 0) sub_id = endVertex->id();
218 else throw cms::Exception(
"SubEventID" )<<
"SubEvent not determined. Particle has no production and no end vertex!"<<endl;
220 if(sub_id < 0) sub_id = 0;
221 int new_id = sub_id + suboffset;
223 cands[d].setCollisionId(new_id);
224 LogDebug(
"VertexId")<<
"SubEvent offset 3 : "<<suboffset;
228 nsub = hi->Ncoll_hard()+1;
233 offset += num_particles;
239 for(
size_t i = 0;
i < particles.size(); ++
i ) {
248 for(
size_t d = 0; d < cands.size(); ++ d ) {
250 const GenVertex * productionVertex = part->production_vertex();
253 cands[d].setCollisionId(0);
259 if(cfhepmcprod)
delete cfhepmcprod;
265 int pdgId = part->pdg_id();
271 const GenVertex *
v = part->production_vertex();
273 ThreeVector vtx = v->point3d();
285 const GenVertex * productionVertex = part->production_vertex();
287 if ( numberOfMothers > 0 ) {
288 GenVertex::particles_in_const_iterator motherIt = productionVertex->particles_in_const_begin();
289 for( ; motherIt != productionVertex->particles_in_const_end(); motherIt++) {
302 HepMC::GenEvent::particle_const_iterator
begin = mc->particles_begin(),
end = mc->particles_end();
303 for( HepMC::GenEvent::particle_const_iterator
p = begin;
p !=
end; ++
p ) {
305 size_t barCode_this_event = particle->barcode();
306 size_t barCode = barCode_this_event +
offset;
309 <<
"barcodes are duplicated! " << endl;
310 particles[
idx] = particle;
311 barCodeVector[
idx] = barCode;
312 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
unsigned int numberOfMothers(const reco::GenParticle &p)
bool fillDaughters(reco::GenParticleCollection &cand, const HepMC::GenParticle *part, size_t index)
void setCollisionId(int s)
std::vector< int > chargeP_
charge indices
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_
const reco::GenParticle * mother(const reco::GenParticle &p, unsigned int imoth=0)
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
void fillGenStatusFlags(const P &p, reco::GenStatusFlags &statusFlags)
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