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;
89 static const double mmToNs = 1.0/299792458
e-6;
93 abortOnUnknownPDGCode_( cfg.getUntrackedParameter<bool>(
"abortOnUnknownPDGCode",
true ) ),
94 saveBarCodes_( cfg.getUntrackedParameter<bool>(
"saveBarCodes",
false ) ),
96 doSubEvent_(cfg.getUntrackedParameter<bool>(
"doSubEvent",
false )),
97 useCF_(cfg.getUntrackedParameter<bool>(
"useCrossingFrame",
false ))
99 produces<GenParticleCollection>();
100 produces<math::XYZPointF>(
"xyz0");
101 produces<float>(
"t0");
104 produces<vector<int> >().setBranchAlias( alias +
"BarCodes" );
117 map<int, int>::const_iterator
f =
chargeMap_.find(
id );
121 <<
"invalid PDG id: " <<
id << endl;
123 return HepPDT::ParticleID(
id).threeCharge();
133 for( HepPDT::ParticleDataTable::const_iterator
p = pdt->begin();
p != pdt->end(); ++
p ) {
134 const HepPDT::ParticleID &
id =
p->first;
136 int q3 =
id.threeCharge();
137 if ( apdgId < PDGCacheMax && pdgId > 0 ) {
153 size_t totalSize = 0;
154 const GenEvent * mc = 0;
162 npiles = cfhepmcprod->
size();
163 LogDebug(
"GenParticleProducer")<<
"npiles : "<<npiles<<endl;
164 for(
unsigned int icf = 0; icf < npiles; ++icf){
168 LogDebug(
"GenParticleProducer")<<
"totalSize : "<<totalSize<<endl;
172 mc = mcp->GetEvent();
175 <<
"HepMC has null pointer to GenEvent" << endl;
176 totalSize = mc->particles_size();
180 const size_t size = totalSize;
181 vector<const HepMC::GenParticle *> particles( size );
182 auto candsPtr = std::make_unique<GenParticleCollection>(
size);
183 auto barCodeVector = std::make_unique<vector<int>>(
size);
184 std::unique_ptr<math::XYZPointF> xyz0Ptr(
new math::XYZPointF(0.,0.,0.));
185 std::unique_ptr<float> t0Ptr(
new float(0.
f));
189 size_t suboffset = 0;
193 for(
size_t ipile = 0; ipile < npiles; ++ipile){
194 LogDebug(
"GenParticleProducer")<<
"mixed object ipile : "<<ipile<<endl;
200 const HepMC::HeavyIon * hi = mc->heavy_ion();
201 if(hi && hi->Ncoll_hard() > 1) isHI =
true;
202 size_t num_particles = mc->particles_size();
203 LogDebug(
"GenParticleProducer")<<
"num_particles : "<<num_particles<<endl;
205 auto origin = (*mc->vertices_begin())->
position();
207 *t0Ptr = origin.t() *
mmToNs;
209 fillIndices(mc, particles, *barCodeVector, offset);
211 for(
size_t ipar = offset; ipar < offset + num_particles; ++ ipar ) {
219 for(
size_t d = offset;
d < offset + num_particles; ++
d ) {
221 const GenVertex * productionVertex = part->production_vertex();
223 if ( productionVertex != 0 ) {
224 sub_id = productionVertex->id();
225 if(!isHI) sub_id = 0;
229 const GenVertex * endVertex = part->end_vertex();
230 if(endVertex != 0) sub_id = endVertex->id();
231 else throw cms::Exception(
"SubEventID" )<<
"SubEvent not determined. Particle has no production and no end vertex!"<<endl;
233 if(sub_id < 0) sub_id = 0;
234 int new_id = sub_id + suboffset;
236 cands[
d].setCollisionId(new_id);
237 LogDebug(
"VertexId")<<
"SubEvent offset 3 : "<<suboffset;
241 nsub = hi->Ncoll_hard()+1;
246 offset += num_particles;
249 auto origin = (*mc->vertices_begin())->
position();
251 *t0Ptr = origin.t() *
mmToNs;
255 for(
size_t i = 0;
i < particles.size(); ++
i ) {
264 for(
size_t d = 0;
d < cands.size(); ++
d ) {
266 const GenVertex * productionVertex = part->production_vertex();
269 cands[
d].setCollisionId(0);
275 if(cfhepmcprod)
delete cfhepmcprod;
282 int pdgId = part->pdg_id();
288 const GenVertex *
v = part->production_vertex();
290 ThreeVector vtx = v->point3d();
302 const GenVertex * productionVertex = part->production_vertex();
303 size_t numberOfMothers = productionVertex->particles_in_size();
304 if ( numberOfMothers > 0 ) {
305 GenVertex::particles_in_const_iterator motherIt = productionVertex->particles_in_const_begin();
306 for( ; motherIt != productionVertex->particles_in_const_end(); motherIt++) {
319 HepMC::GenEvent::particle_const_iterator
begin = mc->particles_begin(),
end = mc->particles_end();
320 for( HepMC::GenEvent::particle_const_iterator
p = begin;
p !=
end; ++
p ) {
322 size_t barCode_this_event = particle->barcode();
323 size_t barCode = barCode_this_event +
offset;
326 <<
"barcodes are duplicated! " << endl;
327 particles[idx] = particle;
328 barCodeVector[idx] = barCode;
329 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)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool fillDaughters(reco::GenParticleCollection &cand, const HepMC::GenParticle *part, size_t index)
void setCollisionId(int s)
static const double mmToNs
std::vector< int > chargeP_
charge indices
MCTruthHelper< reco::GenParticle > mcTruthHelperGenParts_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::map< int, size_t > barcodes_
#define DEFINE_FWK_MODULE(type)
virtual void setPdgId(int pdgId) final
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
std::vector< edm::EDGetTokenT< edm::HepMCProduct > > vectorSrcTokens_
~GenParticleProducer()
destructor
virtual void produce(edm::Event &e, const edm::EventSetup &) override
process one event
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > mixToken_
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
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
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)
virtual void setStatus(int status) final
set status word
const T & getObject(unsigned int ip) const
const HepMC::GenEvent * GetEvent() const
T const * product() const
static const double mmToCm
std::map< int, int > chargeMap_
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
math::XYZTLorentzVector LorentzVector
Lorentz vector.
bool doSubEvent_
input & output modes
std::vector< int > chargeM_
static int position[264][3]
ProductID id() const
Accessor for product ID.
math::XYZPoint Point
point in the space
bool saveBarCodes_
save bar-codes
volatile std::atomic< bool > shutdown_flag false
virtual void setThreeCharge(Charge qx3) final
set electric charge
tuple size
Write out results.
static const int PDGCacheMax