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::ProductRegistryHelper

Public Member Functions

virtual void beginJob ()
 
virtual void beginRun (edm::Run &iRun, const edm::EventSetup &iSetup)
 
virtual void endJob ()
 
virtual void endRun ()
 
 MCParticleReplacer (const edm::ParameterSet &)
 
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 
 ~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 &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

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
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

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 12 of file MCParticleReplacer.cc.

12  :
13  src_(pset.getParameter<edm::InputTag>("src")),
14  srcHepMC_(pset.getParameter<edm::InputTag>("hepMcSrc")),
15  hepMcMode_(stringToHepMcMode(pset.getParameter<std::string>("hepMcMode"))),
16  replacer_(ParticleReplacerFactory::create(pset.getParameter<std::string>("algorithm"), pset)) {
17 
18  produces<edm::HepMCProduct>();
19  produces<double>("weight");
20 }
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 22 of file MCParticleReplacer.cc.

23 {}

Member Function Documentation

void MCParticleReplacer::beginJob ( void  )
virtual

Reimplemented from edm::EDProducer.

Definition at line 111 of file MCParticleReplacer.cc.

References replacer_.

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

Reimplemented from edm::EDProducer.

Definition at line 99 of file MCParticleReplacer.cc.

References replacer_.

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

Reimplemented from edm::EDProducer.

Definition at line 118 of file MCParticleReplacer.cc.

References replacer_.

119 {
120  replacer_->endJob();
121 }
boost::shared_ptr< ParticleReplacerBase > replacer_
void MCParticleReplacer::endRun ( void  )
virtual

Definition at line 104 of file MCParticleReplacer.cc.

References replacer_.

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

Implements edm::EDProducer.

Definition at line 36 of file MCParticleReplacer.cc.

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

37 {
38  std::vector<reco::Muon> muons;
39 
41  if (iEvent.getByLabel(src_, combCandidatesHandle))
42  {
43  if (combCandidatesHandle->size()==0)
44  return;
45  for (size_t idx = 0; idx < combCandidatesHandle->at(0).numberOfDaughters(); ++idx)
46  {
47  int charge = combCandidatesHandle->at(0).daughter(idx)->charge();
48  reco::Particle::LorentzVector p4 = combCandidatesHandle->at(0).daughter(idx)->p4();
49  reco::Particle::Point vtx = combCandidatesHandle->at(0).daughter(idx)->vertex();
50  muons.push_back( reco::Muon(charge, p4, vtx));
51  }
52  }
53  else
54  {
56  if (iEvent.getByLabel(src_, candsHandle))
57  {
58  for (size_t idx = 0; idx < candsHandle->size(); ++idx)
59  {
60  int charge = candsHandle->at(idx).charge();
61  reco::Particle::LorentzVector p4 = candsHandle->at(idx).p4();
62  reco::Particle::Point vtx = candsHandle->at(idx).vertex();
63  muons.push_back( reco::Muon(charge, p4, vtx));
64  }
65  }
66  }
67  if (muons.size() == 0)
68  {
69  edm::LogError("MCParticleReplacer") << "No candidates or muons found!";
70  return;
71  }
72 
73  std::auto_ptr<HepMC::GenEvent> evt;
74  if(hepMcMode_ == kReplace) {
75  edm::Handle<edm::HepMCProduct> HepMCHandle;
76  iEvent.getByLabel(srcHepMC_, HepMCHandle);
77 
78  evt = replacer_->produce(muons, 0, HepMCHandle->GetEvent());
79  }
80  else if(hepMcMode_ == kNew) {
81  evt = replacer_->produce(muons);
82  }
83  else
84  throw cms::Exception("LogicError") << "Invalid hepMcMode " << hepMcMode_ << std::endl;
85 
86 
87  if(evt.get() != 0) {
88  std::auto_ptr<edm::HepMCProduct> bare_product(new edm::HepMCProduct());
89  bare_product->addHepMCData(evt.release()); // transfer ownership of the HepMC:GenEvent to bare_product
90 
91  iEvent.put(bare_product);
92 
93  std::auto_ptr<double> bare_weight(new double(replacer_->eventWeight));
94  iEvent.put(bare_weight, std::string("weight"));
95  }
96 
97 }
double charge(const std::vector< uint8_t > &Ampls)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
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:356
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 25 of file MCParticleReplacer.cc.

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

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

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().