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);
81 using namespace HepMC;
88 abortOnUnknownPDGCode_( cfg.getUntrackedParameter<bool>(
"abortOnUnknownPDGCode",
true ) ),
89 saveBarCodes_( cfg.getUntrackedParameter<bool>(
"saveBarCodes",
false ) ),
91 doSubEvent_(cfg.getUntrackedParameter<bool>(
"doSubEvent",
false )),
92 useCF_(cfg.getUntrackedParameter<bool>(
"useCrossingFrame",
false ))
94 produces<GenParticleCollection>();
97 produces<vector<int> >().setBranchAlias( alias +
"BarCodes" );
104 mixToken_ = mayConsume<CrossingFrame<HepMCProduct> >(
InputTag(cfg.getParameter<
std::string>(
"mix" ),
"generator"));
105 srcToken_ = mayConsume<HepMCProduct>(cfg.getUntrackedParameter<
InputTag>(
"src" ,
InputTag(cfg.getParameter<
std::string>(
"mix" ),
"generator")));
106 }
else srcToken_ = mayConsume<HepMCProduct>(cfg.getParameter<
InputTag>(
"src" ));
115 map<int, int>::const_iterator
f =
chargeMap_.find(
id );
119 <<
"invalid PDG id: " <<
id << endl;
131 for( HepPDT::ParticleDataTable::const_iterator
p = pdt->begin();
p != pdt->end(); ++
p ) {
134 int q3 =
id.threeCharge();
135 if ( apdgId < PDGCacheMax && pdgId > 0 ) {
151 size_t totalSize = 0;
152 const GenEvent * mc = 0;
153 std::vector<Handle<HepMCProduct> > heps;
161 npiles = cfhepmcprod->
size();
162 for(
unsigned int icf = 0; icf < npiles; ++icf){
166 for(
size_t i = 0;
i < npiles; ++
i){
168 heps.push_back(handle);
170 totalSize += heps[
i]->GetEvent()->particles_size();
175 mc = mcp->GetEvent();
178 <<
"HepMC has null pointer to GenEvent" << endl;
179 totalSize = mc->particles_size();
183 const size_t size = totalSize;
184 vector<const HepMC::GenParticle *> particles( size );
187 auto_ptr<vector<int> > barCodeVector(
new vector<int>( size ) );
192 size_t suboffset = 0;
196 for(
size_t i = 0;
i < npiles; ++
i){
199 else mc = heps[
i]->GetEvent();
203 const HepMC::HeavyIon * hi = mc->heavy_ion();
204 if(hi && hi->Ncoll_hard() > 1) isHI =
true;
205 size_t num_particles = mc->particles_size();
206 fillIndices(mc, particles, *barCodeVector, offset);
208 for(
size_t i = offset;
i < offset + num_particles; ++
i ) {
217 for(
size_t d = offset; d < offset + num_particles; ++ d ) {
219 const GenVertex * productionVertex = part->production_vertex();
221 if ( productionVertex != 0 ) {
222 sub_id = productionVertex->id();
223 if(!isHI) sub_id = 0;
227 const GenVertex * endVertex = part->end_vertex();
228 if(endVertex != 0) sub_id = endVertex->id();
229 else throw cms::Exception(
"SubEventID" )<<
"SubEvent not determined. Particle has no production and no end vertex!"<<endl;
231 if(sub_id < 0) sub_id = 0;
232 int new_id = sub_id + suboffset;
235 cands[d].setCollisionId(new_id);
236 LogDebug(
"VertexId")<<
"SubEvent offset 3 : "<<suboffset;
240 nsub = hi->Ncoll_hard()+1;
245 offset += num_particles;
251 for(
size_t i = 0;
i < particles.size(); ++
i ) {
260 for(
size_t d = 0; d < cands.size(); ++ d ) {
262 const GenVertex * productionVertex = part->production_vertex();
265 cands[d].setCollisionId(0);
272 if(cfhepmcprod)
delete cfhepmcprod;
278 int pdgId = part->pdg_id();
284 const GenVertex *
v = part->production_vertex();
286 ThreeVector vtx = v->point3d();
297 const GenVertex * productionVertex = part->production_vertex();
298 size_t numberOfMothers = productionVertex->particles_in_size();
299 if ( numberOfMothers > 0 ) {
300 GenVertex::particles_in_const_iterator motherIt = productionVertex->particles_in_const_begin();
301 for( ; motherIt != productionVertex->particles_in_const_end(); motherIt++) {
314 HepMC::GenEvent::particle_const_iterator
begin = mc->particles_begin(),
end = mc->particles_end();
315 for( HepMC::GenEvent::particle_const_iterator
p = begin;
p !=
end; ++
p ) {
317 size_t barCode_this_event = particle->barcode();
318 size_t barCode = barCode_this_event +
offset;
321 <<
"barcodes are duplicated! " << endl;
322 particles[
idx] = particle;
323 barCodeVector[
idx] = barCode;
324 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
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_
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
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
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)
unsigned int offset(bool)
virtual void setVertex(const Point &vertex)
set vertex
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
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
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
volatile std::atomic< bool > shutdown_flag false
tuple size
Write out results.
static const int PDGCacheMax