CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Static Private Member Functions | Private Attributes
MCParticleReplacer Class Reference

#include <MCParticleReplacer.h>

Inheritance diagram for MCParticleReplacer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

virtual void beginJob ()
 
virtual void beginRun (const edm::Run &iRun, const edm::EventSetup &iSetup) override
 
virtual void endJob ()
 
virtual void endRun (const edm::Run &iRun, const edm::EventSetup &iSetup) override
 
 MCParticleReplacer (const edm::ParameterSet &)
 
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~MCParticleReplacer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Types

enum  HepMcMode { kInvalid =0, kNew, kReplace }
 

Static Private Member Functions

static HepMcMode stringToHepMcMode (const std::string &name)
 

Private Attributes

HepMcMode hepMcMode_
 
boost::shared_ptr
< ParticleReplacerBase
replacer_
 
edm::InputTag src_
 
edm::InputTag srcHepMC_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- 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 31 of file MCParticleReplacer.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

MCParticleReplacer::MCParticleReplacer ( const edm::ParameterSet pset)
explicit

Definition at line 14 of file MCParticleReplacer.cc.

14  :
15  src_(pset.getParameter<edm::InputTag>("src")),
16  srcHepMC_(pset.getParameter<edm::InputTag>("hepMcSrc")),
19 
20  produces<edm::HepMCProduct>();
21  produces<GenFilterInfo>("minVisPtFilter");
22 }
T getParameter(std::string const &) const
static boost::shared_ptr< ParticleReplacerBase > create(const std::string &algo, const edm::ParameterSet &iConfig)
static HepMcMode stringToHepMcMode(const std::string &name)
edm::InputTag srcHepMC_
boost::shared_ptr< ParticleReplacerBase > replacer_
MCParticleReplacer::~MCParticleReplacer ( )

Definition at line 24 of file MCParticleReplacer.cc.

25 {}

Member Function Documentation

void MCParticleReplacer::beginJob ( void  )
virtual

Reimplemented from edm::EDProducer.

Definition at line 113 of file MCParticleReplacer.cc.

References replacer_.

114 {
115  replacer_->beginJob();
116 }
boost::shared_ptr< ParticleReplacerBase > replacer_
void MCParticleReplacer::beginRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
overridevirtual

Reimplemented from edm::EDProducer.

Definition at line 101 of file MCParticleReplacer.cc.

References replacer_.

102 {
103  replacer_->beginRun(iRun, iSetup);
104 }
boost::shared_ptr< ParticleReplacerBase > replacer_
void MCParticleReplacer::endJob ( void  )
virtual

Reimplemented from edm::EDProducer.

Definition at line 120 of file MCParticleReplacer.cc.

References replacer_.

121 {
122  replacer_->endJob();
123 }
boost::shared_ptr< ParticleReplacerBase > replacer_
void MCParticleReplacer::endRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
overridevirtual

Reimplemented from edm::EDProducer.

Definition at line 106 of file MCParticleReplacer.cc.

References replacer_.

107 {
108  replacer_->endRun();
109 }
boost::shared_ptr< ParticleReplacerBase > replacer_
void MCParticleReplacer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overridevirtual

Implements edm::EDProducer.

Definition at line 38 of file MCParticleReplacer.cc.

References DeDxDiscriminatorTools::charge(), edm::hlt::Exception, edm::Event::getByLabel(), hepMcMode_, customizeTrackingMonitorSeedNumber::idx, info, kNew, kReplace, patZpeak::muons, p4, edm::Event::put(), replacer_, src_, srcHepMC_, and AlCaHLTBitMon_QueryRunRegistry::string.

39 {
40  std::vector<reco::Muon> muons;
41 
43  if (iEvent.getByLabel(src_, combCandidatesHandle))
44  {
45  if (combCandidatesHandle->size()==0)
46  return;
47  for (size_t idx = 0; idx < combCandidatesHandle->at(0).numberOfDaughters(); ++idx)
48  {
49  int charge = combCandidatesHandle->at(0).daughter(idx)->charge();
50  reco::Particle::LorentzVector p4 = combCandidatesHandle->at(0).daughter(idx)->p4();
51  reco::Particle::Point vtx = combCandidatesHandle->at(0).daughter(idx)->vertex();
52  muons.push_back( reco::Muon(charge, p4, vtx));
53  }
54  }
55  else
56  {
58  if (iEvent.getByLabel(src_, candsHandle))
59  {
60  for (size_t idx = 0; idx < candsHandle->size(); ++idx)
61  {
62  int charge = candsHandle->at(idx).charge();
63  reco::Particle::LorentzVector p4 = candsHandle->at(idx).p4();
64  reco::Particle::Point vtx = candsHandle->at(idx).vertex();
65  muons.push_back( reco::Muon(charge, p4, vtx));
66  }
67  }
68  }
69  if (muons.size() == 0)
70  {
71  edm::LogError("MCParticleReplacer") << "No candidates or muons found!";
72  return;
73  }
74 
75  std::auto_ptr<HepMC::GenEvent> evt;
76  if(hepMcMode_ == kReplace) {
77  edm::Handle<edm::HepMCProduct> HepMCHandle;
78  iEvent.getByLabel(srcHepMC_, HepMCHandle);
79 
80  evt = replacer_->produce(muons, 0, HepMCHandle->GetEvent());
81  }
82  else if(hepMcMode_ == kNew) {
83  evt = replacer_->produce(muons);
84  }
85  else
86  throw cms::Exception("LogicError") << "Invalid hepMcMode " << hepMcMode_ << std::endl;
87 
88 
89  if(evt.get() != 0) {
90  std::auto_ptr<edm::HepMCProduct> bare_product(new edm::HepMCProduct());
91  bare_product->addHepMCData(evt.release()); // transfer ownership of the HepMC:GenEvent to bare_product
92 
93  iEvent.put(bare_product);
94 
95  std::auto_ptr<GenFilterInfo> info(new GenFilterInfo(replacer_->tried, replacer_->passed));
96  iEvent.put(info, std::string("minVisPtFilter"));
97  }
98 
99 }
double charge(const std::vector< uint8_t > &Ampls)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
double p4[4]
Definition: TauolaWrapper.h:92
math::XYZPoint Point
point in the space
Definition: Particle.h:29
edm::InputTag srcHepMC_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
tuple muons
Definition: patZpeak.py:38
boost::shared_ptr< ParticleReplacerBase > replacer_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
MCParticleReplacer::HepMcMode MCParticleReplacer::stringToHepMcMode ( const std::string &  name)
staticprivate

Definition at line 27 of file MCParticleReplacer.cc.

References edm::hlt::Exception, kNew, and kReplace.

27  {
28  if(name == "new")
29  return kNew;
30  else if(name == "replace")
31  return kReplace;
32  else
33  throw cms::Exception("Configuration") << "Unsupported hepMcMode " << name << ", should be 'new' or 'replace'" << std::endl;
34 }

Member Data Documentation

HepMcMode MCParticleReplacer::hepMcMode_
private

Definition at line 49 of file MCParticleReplacer.h.

Referenced by produce().

boost::shared_ptr<ParticleReplacerBase> MCParticleReplacer::replacer_
private

Definition at line 50 of file MCParticleReplacer.h.

Referenced by beginJob(), beginRun(), endJob(), endRun(), and produce().

edm::InputTag MCParticleReplacer::src_
private

Definition at line 47 of file MCParticleReplacer.h.

Referenced by produce().

edm::InputTag MCParticleReplacer::srcHepMC_
private

Definition at line 48 of file MCParticleReplacer.h.

Referenced by produce().