CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
GenParticleProducer Class Reference
Inheritance diagram for GenParticleProducer:
edm::global::EDProducer< edm::RunCache< IDto3Charge > > edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

bool convertParticle (reco::GenParticle &cand, const HepMC::GenParticle *part, const IDto3Charge &id2Charge) const
 
bool fillDaughters (reco::GenParticleCollection &cand, const HepMC::GenParticle *part, reco::GenParticleRefProd const &ref, size_t index, std::unordered_map< int, size_t > &barcodes) const
 
bool fillIndices (const HepMC::GenEvent *mc, std::vector< const HepMC::GenParticle * > &particles, std::vector< int > &barCodeVector, int offset, std::unordered_map< int, size_t > &barcodes) const
 
 GenParticleProducer (const edm::ParameterSet &)
 constructor More...
 
virtual std::shared_ptr< IDto3Charge > globalBeginRun (const edm::Run &, const edm::EventSetup &) const override
 
virtual void globalEndRun (edm::Run const &, edm::EventSetup const &) const override
 
virtual void produce (edm::StreamID, edm::Event &e, const edm::EventSetup &) const override
 process one event More...
 
 ~GenParticleProducer ()
 destructor More...
 
- Public Member Functions inherited from edm::global::EDProducer< edm::RunCache< IDto3Charge > >
 EDProducer ()=default
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

bool abortOnUnknownPDGCode_
 unknown code treatment flag More...
 
bool doSubEvent_
 input & output modes More...
 
MCTruthHelper< HepMC::GenParticle > mcTruthHelper_
 
MCTruthHelper< reco::GenParticlemcTruthHelperGenParts_
 
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > mixToken_
 
bool saveBarCodes_
 save bar-codes More...
 
edm::EDGetTokenT< edm::HepMCProductsrcToken_
 source collection name More...
 
bool useCF_
 
std::vector< edm::EDGetTokenT< edm::HepMCProduct > > vectorSrcTokens_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 79 of file GenParticleProducer.cc.

Constructor & Destructor Documentation

GenParticleProducer::GenParticleProducer ( const edm::ParameterSet cfg)

constructor

Definition at line 138 of file GenParticleProducer.cc.

References egammaCTFFinalFitWithMaterial_cff::alias, edm::ParameterSet::getParameter(), mixToken_, saveBarCodes_, srcToken_, AlCaHLTBitMon_QueryRunRegistry::string, and useCF_.

138  :
139  abortOnUnknownPDGCode_( cfg.getUntrackedParameter<bool>( "abortOnUnknownPDGCode", true ) ),
140  saveBarCodes_( cfg.getUntrackedParameter<bool>( "saveBarCodes", false ) ),
141  doSubEvent_(cfg.getUntrackedParameter<bool>( "doSubEvent", false )),
142  useCF_(cfg.getUntrackedParameter<bool>( "useCrossingFrame", false ))
143 {
144  produces<GenParticleCollection>();
145  produces<math::XYZPointF>("xyz0");
146  produces<float>("t0");
147  if( saveBarCodes_ ) {
148  std::string alias( cfg.getParameter<std::string>( "@module_label" ) );
149  produces<vector<int> >().setBranchAlias( alias + "BarCodes" );
150  }
151 
152  if(useCF_) mixToken_ = mayConsume<CrossingFrame<HepMCProduct> >(InputTag(cfg.getParameter<std::string>( "mix" ),"generatorSmeared"));
153  else srcToken_ = mayConsume<HepMCProduct>(cfg.getParameter<InputTag>( "src" ));
154 }
T getParameter(std::string const &) const
bool abortOnUnknownPDGCode_
unknown code treatment flag
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > mixToken_
edm::EDGetTokenT< edm::HepMCProduct > srcToken_
source collection name
bool doSubEvent_
input & output modes
bool saveBarCodes_
save bar-codes
GenParticleProducer::~GenParticleProducer ( )

destructor

Definition at line 156 of file GenParticleProducer.cc.

156  {
157 }

Member Function Documentation

bool GenParticleProducer::convertParticle ( reco::GenParticle cand,
const HepMC::GenParticle *  part,
const IDto3Charge &  id2Charge 
) const

Definition at line 297 of file GenParticleProducer.cc.

References MCTruthHelper< P >::fillGenStatusFlags(), mcTruthHelper_, mmToCm, p4, cosmictrackingParticleSelector_cfi::pdgId, reco::GenParticle::setCollisionId(), reco::LeafCandidate::setP4(), reco::LeafCandidate::setPdgId(), reco::LeafCandidate::setStatus(), reco::LeafCandidate::setThreeCharge(), reco::LeafCandidate::setVertex(), reco::GenParticle::statusFlags(), findQualityFiles::v, and badGlobalMuonTaggersAOD_cff::vtx.

Referenced by produce().

297  {
298  Candidate::LorentzVector p4( part->momentum() );
299  int pdgId = part->pdg_id();
300  cand.setThreeCharge( id2Charge.chargeTimesThree( pdgId ) );
301  cand.setPdgId( pdgId );
302  cand.setStatus( part->status() );
303  cand.setP4( p4 );
304  cand.setCollisionId(0);
305  const GenVertex * v = part->production_vertex();
306  if ( v != 0 ) {
307  ThreeVector vtx = v->point3d();
308  Candidate::Point vertex( vtx.x() * mmToCm, vtx.y() * mmToCm, vtx.z() * mmToCm );
309  cand.setVertex( vertex );
310  } else {
311  cand.setVertex( Candidate::Point( 0, 0, 0 ) );
312  }
314  return true;
315 }
MCTruthHelper< HepMC::GenParticle > mcTruthHelper_
void setCollisionId(int s)
Definition: GenParticle.h:38
virtual void setPdgId(int pdgId) final
void fillGenStatusFlags(const P &p, reco::GenStatusFlags &statusFlags) const
double p4[4]
Definition: TauolaWrapper.h:92
virtual void setVertex(const Point &vertex)
set vertex
const GenStatusFlags & statusFlags() const
Definition: GenParticle.h:41
virtual void setStatus(int status) final
set status word
static const double mmToCm
part
Definition: HCALResponse.h:20
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
virtual void setThreeCharge(Charge qx3) final
set electric charge
Definition: LeafCandidate.h:97
bool GenParticleProducer::fillDaughters ( reco::GenParticleCollection cand,
const HepMC::GenParticle *  part,
reco::GenParticleRefProd const &  ref,
size_t  index,
std::unordered_map< int, size_t > &  barcodes 
) const

Definition at line 317 of file GenParticleProducer.cc.

References GenParticle::GenParticle, diffTreeTool::index, funct::m, and edm::second().

Referenced by produce().

317  {
318 
319  const GenVertex * productionVertex = part->production_vertex();
320  size_t numberOfMothers = productionVertex->particles_in_size();
321  if ( numberOfMothers > 0 ) {
322  GenVertex::particles_in_const_iterator motherIt = productionVertex->particles_in_const_begin();
323  for( ; motherIt != productionVertex->particles_in_const_end(); motherIt++) {
324  const HepMC::GenParticle * mother = * motherIt;
325  size_t m = barcodes.find( mother->barcode() )->second;
326  cands[ m ].addDaughter( GenParticleRef( ref, index ) );
327  cands[ index ].addMother( GenParticleRef( ref, m ) );
328  }
329  }
330 
331  return true;
332 }
U second(std::pair< T, U > const &p)
edm::Ref< edm::HepMCProduct, HepMC::GenParticle > GenParticleRef
part
Definition: HCALResponse.h:20
bool GenParticleProducer::fillIndices ( const HepMC::GenEvent *  mc,
std::vector< const HepMC::GenParticle * > &  particles,
std::vector< int > &  barCodeVector,
int  offset,
std::unordered_map< int, size_t > &  barcodes 
) const

Definition at line 334 of file GenParticleProducer.cc.

References begin, DEFINE_FWK_MODULE, end, GenParticle::GenParticle, training_settings::idx, PFRecoTauDiscriminationByIsolation_cfi::offset, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by produce().

334  {
335  size_t idx = offset;
336  HepMC::GenEvent::particle_const_iterator begin = mc->particles_begin(), end = mc->particles_end();
337  for( HepMC::GenEvent::particle_const_iterator p = begin; p != end; ++ p ) {
338  const HepMC::GenParticle * particle = * p;
339  size_t barCode_this_event = particle->barcode();
340  size_t barCode = barCode_this_event + offset;
341  if( barcodes.find(barCode) != barcodes.end() )
342  throw cms::Exception( "WrongReference" )
343  << "barcodes are duplicated! " << endl;
344  particles[idx] = particle;
345  barCodeVector[idx] = barCode;
346  barcodes.insert( make_pair(barCode_this_event, idx ++) );
347  }
348  return true;
349 }
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
std::shared_ptr< IDto3Charge > GenParticleProducer::globalBeginRun ( const edm::Run ,
const edm::EventSetup es 
) const
overridevirtual

Definition at line 159 of file GenParticleProducer.cc.

References abortOnUnknownPDGCode_, and edm::EventSetup::getData().

159  {
161  es.getData( pdt );
162  return std::make_shared<IDto3Charge>(*pdt, abortOnUnknownPDGCode_);
163 }
bool abortOnUnknownPDGCode_
unknown code treatment flag
void getData(T &iHolder) const
Definition: EventSetup.h:79
virtual void GenParticleProducer::globalEndRun ( edm::Run const &  ,
edm::EventSetup const &   
) const
inlineoverridevirtual
void GenParticleProducer::produce ( edm::StreamID  ,
edm::Event e,
const edm::EventSetup es 
) const
overridevirtual

process one event

fill indices

Definition at line 165 of file GenParticleProducer.cc.

References convertParticle(), edmIntegrityCheck::d, doSubEvent_, Exception, f, fillDaughters(), fillIndices(), GenParticle::GenParticle, edm::Event::getByToken(), edm::HepMCProduct::GetEvent(), MixCollection< T >::getObject(), edm::Event::getRefBeforePut(), edm::Event::getRun(), mps_fire::i, edm::RefProd< C >::id(), edm::Run::index(), edm::errors::InvalidReference, LogDebug, CaloTowersParam_cfi::mc, mixToken_, mmToCm, mmToNs, eostools::move(), PFRecoTauDiscriminationByIsolation_cfi::offset, HadronAndPartonSelector_cfi::particles, position, edm::Handle< T >::product(), edm::Event::put(), reco::CompositeRefCandidateT< D >::resetDaughters(), saveBarCodes_, MixCollection< T >::size(), findQualityFiles::size, srcToken_, and useCF_.

165  {
166 
167  std::unordered_map<int, size_t> barcodes;
168 
169  size_t totalSize = 0;
170  const GenEvent * mc = 0;
171  MixCollection<HepMCProduct>* cfhepmcprod = 0;
172  size_t npiles = 1;
173 
174  if(useCF_){
176  evt.getByToken(mixToken_,cf);
177  cfhepmcprod = new MixCollection<HepMCProduct>(cf.product());
178  npiles = cfhepmcprod->size();
179  LogDebug("GenParticleProducer")<<"npiles : "<<npiles<<endl;
180  for(unsigned int icf = 0; icf < npiles; ++icf){
181  LogDebug("GenParticleProducer")<<"subSize : "<<cfhepmcprod->getObject(icf).GetEvent()->particles_size()<<endl;
182  totalSize += cfhepmcprod->getObject(icf).GetEvent()->particles_size();
183  }
184  LogDebug("GenParticleProducer")<<"totalSize : "<<totalSize<<endl;
185  }else{
187  evt.getByToken( srcToken_, mcp );
188  mc = mcp->GetEvent();
189  if( mc == 0 )
191  << "HepMC has null pointer to GenEvent" << endl;
192  totalSize = mc->particles_size();
193  }
194 
195  // initialise containers
196  const size_t size = totalSize;
197  vector<const HepMC::GenParticle *> particles( size );
198  auto candsPtr = std::make_unique<GenParticleCollection>(size);
199  auto barCodeVector = std::make_unique<vector<int>>(size);
200  std::unique_ptr<math::XYZPointF> xyz0Ptr(new math::XYZPointF(0.,0.,0.));
201  std::unique_ptr<float> t0Ptr(new float(0.f));
202  reco::GenParticleRefProd ref = evt.getRefBeforePut<GenParticleCollection>();
203  GenParticleCollection & cands = * candsPtr;
204  size_t offset = 0;
205  size_t suboffset = 0;
206 
207  IDto3Charge const& id2Charge = *runCache(evt.getRun().index());
209  if(doSubEvent_ || useCF_){
210  for(size_t ipile = 0; ipile < npiles; ++ipile){
211  LogDebug("GenParticleProducer")<<"mixed object ipile : "<<ipile<<endl;
212  barcodes.clear();
213  if(useCF_) mc = cfhepmcprod->getObject(ipile).GetEvent();
214 
215  //Look whether heavy ion/signal event
216  bool isHI = false;
217  const HepMC::HeavyIon * hi = mc->heavy_ion();
218  if(hi && hi->Ncoll_hard() > 1) isHI = true;
219  size_t num_particles = mc->particles_size();
220  LogDebug("GenParticleProducer")<<"num_particles : "<<num_particles<<endl;
221  if (ipile == 0) {
222  auto origin = (*mc->vertices_begin())->position();
223  xyz0Ptr->SetXYZ(origin.x() * mmToCm, origin.y() * mmToCm, origin.z() * mmToCm);
224  *t0Ptr = origin.t() * mmToNs;
225  }
226  fillIndices(mc, particles, *barCodeVector, offset,barcodes);
227  // fill output collection and save association
228  for( size_t ipar = offset; ipar < offset + num_particles; ++ ipar ) {
229  const HepMC::GenParticle * part = particles[ ipar ];
230  reco::GenParticle & cand = cands[ ipar ];
231  // convert HepMC::GenParticle to new reco::GenParticle
232  convertParticle(cand, part,id2Charge);
233  cand.resetDaughters( ref.id() );
234  }
235 
236  for( size_t d = offset; d < offset + num_particles; ++ d ) {
237  const HepMC::GenParticle * part = particles[ d ];
238  const GenVertex * productionVertex = part->production_vertex();
239  int sub_id = 0;
240  if ( productionVertex != 0 ) {
241  sub_id = productionVertex->id();
242  if(!isHI) sub_id = 0;
243  // search barcode map and attach daughters
244  fillDaughters(cands,part,ref,d,barcodes);
245  }else{
246  const GenVertex * endVertex = part->end_vertex();
247  if(endVertex != 0) sub_id = endVertex->id();
248  else throw cms::Exception( "SubEventID" )<<"SubEvent not determined. Particle has no production and no end vertex!"<<endl;
249  }
250  if(sub_id < 0) sub_id = 0;
251  int new_id = sub_id + suboffset;
252  GenParticleRef dref( ref, d );
253  cands[d].setCollisionId(new_id); // For new GenParticle
254  LogDebug("VertexId")<<"SubEvent offset 3 : "<<suboffset;
255  }
256  int nsub = -2;
257  if(isHI){
258  nsub = hi->Ncoll_hard()+1;
259  suboffset += nsub;
260  }else{
261  suboffset += 1;
262  }
263  offset += num_particles;
264  }
265  }else{
266  auto origin = (*mc->vertices_begin())->position();
267  xyz0Ptr->SetXYZ(origin.x() * mmToCm, origin.y() * mmToCm, origin.z() * mmToCm);
268  *t0Ptr = origin.t() * mmToNs;
269  fillIndices(mc, particles, *barCodeVector, 0,barcodes);
270 
271  // fill output collection and save association
272  for( size_t i = 0; i < particles.size(); ++ i ) {
273  const HepMC::GenParticle * part = particles[ i ];
274  reco::GenParticle & cand = cands[ i ];
275  // convert HepMC::GenParticle to new reco::GenParticle
276  convertParticle(cand, part,id2Charge);
277  cand.resetDaughters( ref.id() );
278  }
279 
280  // fill references to daughters
281  for( size_t d = 0; d < cands.size(); ++ d ) {
282  const HepMC::GenParticle * part = particles[ d ];
283  const GenVertex * productionVertex = part->production_vertex();
284  // search barcode map and attach daughters
285  if ( productionVertex != 0 ) fillDaughters(cands,part,ref,d,barcodes);
286  cands[d].setCollisionId(0);
287  }
288  }
289 
290  evt.put(std::move(candsPtr));
291  if(saveBarCodes_) evt.put(std::move(barCodeVector));
292  if(cfhepmcprod) delete cfhepmcprod;
293  evt.put(std::move(xyz0Ptr),"xyz0");
294  evt.put(std::move(t0Ptr),"t0");
295 }
#define LogDebug(id)
size
Write out results.
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
static const double mmToNs
bool fillDaughters(reco::GenParticleCollection &cand, const HepMC::GenParticle *part, reco::GenParticleRefProd const &ref, size_t index, std::unordered_map< int, size_t > &barcodes) const
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > mixToken_
bool fillIndices(const HepMC::GenEvent *mc, std::vector< const HepMC::GenParticle * > &particles, std::vector< int > &barCodeVector, int offset, std::unordered_map< int, size_t > &barcodes) const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
edm::EDGetTokenT< edm::HepMCProduct > srcToken_
source collection name
bool convertParticle(reco::GenParticle &cand, const HepMC::GenParticle *part, const IDto3Charge &id2Charge) const
int size() const
Definition: MixCollection.h:24
void resetDaughters(const edm::ProductID &id)
set daughters product ID
double f[11][100]
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:137
const T & getObject(unsigned int ip) const
Definition: MixCollection.h:31
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
T const * product() const
Definition: Handle.h:81
static const double mmToCm
part
Definition: HCALResponse.h:20
bool doSubEvent_
input & output modes
static int position[264][3]
Definition: ReadPGInfo.cc:509
bool saveBarCodes_
save bar-codes
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

bool GenParticleProducer::abortOnUnknownPDGCode_
private

unknown code treatment flag

Definition at line 102 of file GenParticleProducer.cc.

Referenced by globalBeginRun().

bool GenParticleProducer::doSubEvent_
private

input & output modes

Definition at line 107 of file GenParticleProducer.cc.

Referenced by produce().

MCTruthHelper<HepMC::GenParticle> GenParticleProducer::mcTruthHelper_
private

Definition at line 110 of file GenParticleProducer.cc.

Referenced by convertParticle().

MCTruthHelper<reco::GenParticle> GenParticleProducer::mcTruthHelperGenParts_
private

Definition at line 111 of file GenParticleProducer.cc.

edm::EDGetTokenT<CrossingFrame<edm::HepMCProduct> > GenParticleProducer::mixToken_
private

Definition at line 99 of file GenParticleProducer.cc.

Referenced by GenParticleProducer(), and produce().

bool GenParticleProducer::saveBarCodes_
private

save bar-codes

Definition at line 104 of file GenParticleProducer.cc.

Referenced by GenParticleProducer(), and produce().

edm::EDGetTokenT<edm::HepMCProduct> GenParticleProducer::srcToken_
private

source collection name

Definition at line 97 of file GenParticleProducer.cc.

Referenced by GenParticleProducer(), and produce().

bool GenParticleProducer::useCF_
private

Definition at line 108 of file GenParticleProducer.cc.

Referenced by GenParticleProducer(), and produce().

std::vector<edm::EDGetTokenT<edm::HepMCProduct> > GenParticleProducer::vectorSrcTokens_
private

Definition at line 98 of file GenParticleProducer.cc.