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 
10 
11 // replacementMode =
12 // 0 - remove Myons from existing HepMCProduct and implant taus (+decay products)
13 // 1 - build new HepMCProduct only with taus (+decay products)
15  src_(pset.getParameter<edm::InputTag>("src")),
16  srcHepMC_(pset.getParameter<edm::InputTag>("hepMcSrc")),
17  hepMcMode_(stringToHepMcMode(pset.getParameter<std::string>("hepMcMode"))),
18  replacer_(ParticleReplacerFactory::create(pset.getParameter<std::string>("algorithm"), pset)) {
19 
20  produces<edm::HepMCProduct>();
21  produces<GenFilterInfo>("minVisPtFilter");
22 }
23 
25 {}
26 
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 }
35 
36 // ------------ method called to produce the data ------------
37 void
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 }
100 
102 {
103  replacer_->beginRun(iRun, iSetup);
104 }
105 
106 void MCParticleReplacer::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup)
107 {
108  replacer_->endRun();
109 }
110 
111 // ------------ method called once each job just before starting event loop ------------
112 void
114 {
115  replacer_->beginJob();
116 }
117 
118 // ------------ method called once each job just after ending the event loop ------------
119 void
121 {
122  replacer_->endJob();
123 }
124 
125 //define this as a plug-in
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
virtual void endRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
double charge(const std::vector< uint8_t > &Ampls)
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:94
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: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
SurfaceDeformation * create(int type, const std::vector< double > &params)
Definition: Run.h:36