CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCParticleReplacer.cc
Go to the documentation of this file.
3 
8 
9 // replacementMode =
10 // 0 - remove Myons from existing HepMCProduct and implant taus (+decay products)
11 // 1 - build new HepMCProduct only with taus (+decay products)
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 }
21 
23 {}
24 
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 }
33 
34 // ------------ method called to produce the data ------------
35 void
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 }
98 
100 {
101  replacer_->beginRun(iRun, iSetup);
102 }
103 
105 {
106  replacer_->endRun();
107 }
108 
109 // ------------ method called once each job just before starting event loop ------------
110 void
112 {
113  replacer_->beginJob();
114 }
115 
116 // ------------ method called once each job just after ending the event loop ------------
117 void
119 {
120  replacer_->endJob();
121 }
122 
123 //define this as a plug-in
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double charge(const std::vector< uint8_t > &Ampls)
virtual void beginRun(edm::Run &iRun, const edm::EventSetup &iSetup)
MCParticleReplacer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
static HepMcMode stringToHepMcMode(const std::string &name)
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
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
boost::shared_ptr< ParticleReplacerBase > replacer_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
SurfaceDeformation * create(int type, const std::vector< double > &params)
Definition: Run.h:33