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.
2 
4 
13 
15 
16 // replacementMode =
17 // 0 - remove Muons from existing HepMCProduct and implant taus (and tau decay products)
18 // 1 - build new HepMCProduct only with taus (and tau decay products)
20  : src_(cfg.getParameter<edm::InputTag>("src")),
21  srcHepMC_(cfg.getParameter<edm::InputTag>("hepMcSrc")),
22  hepMcMode_(stringToHepMcMode(cfg.getParameter<std::string>("hepMcMode"))),
23  replacer_(0),
24  evt_(0)
25 {
26  std::string algorithm = cfg.getParameter<std::string>("algorithm");
28  std::string pluginType = cfg.getParameter<std::string>("pluginType");
29  replacer_ = ParticleReplacerPluginFactory::get()->create(pluginType, cfgAlgorithm);
30 
31  verbosity_ = ( cfg.exists("verbosity") ) ?
32  cfg.getParameter<int>("verbosity") : 0;
33 
34  produces<edm::HepMCProduct>();
35  produces<GenFilterInfo>("minVisPtFilter");
36  replacer_->declareExtraProducts(this);
37 }
38 
40 {
41  delete replacer_;
42 }
43 
45 {
46  if ( name == "new" ) return kNew;
47  else if ( name == "replace" ) return kReplace;
48  else throw cms::Exception("Configuration")
49  << "Unsupported hepMcMode " << name << ": should be either 'new' or 'replace' !!\n" << std::endl;
50 }
51 
52 void
54 {
55  std::vector<reco::CandidateBaseRef> selMuons = getSelMuons(evt, src_);
56  const reco::CandidateBaseRef muPlus = getTheMuPlus(selMuons);
57  const reco::CandidateBaseRef muMinus = getTheMuMinus(selMuons);
58 
59  std::vector<reco::Particle> muons;
60  if ( muPlus.isNonnull() ) muons.push_back(reco::Particle(muPlus->charge(), muPlus->p4(), muPlus->vertex(), -15, 0, true));
61  if ( muMinus.isNonnull() ) muons.push_back(reco::Particle(muMinus->charge(), muMinus->p4(), muMinus->vertex(), +15, 0, true));
62 
63  if ( muons.size() == 0 ) {
64  edm::LogError("MCParticleReplacer")
65  << "No Z->mumu candidates or muons found !!" << std::endl;
66  return;
67  }
68 
69  evt_ = &evt;
70 
71  std::auto_ptr<HepMC::GenEvent> hepMC;
72  if ( hepMcMode_ == kReplace ) {
73  edm::Handle<edm::HepMCProduct> HepMCHandle;
74  evt.getByLabel(srcHepMC_, HepMCHandle);
75  hepMC = replacer_->produce(muons, 0, HepMCHandle->GetEvent(), this);
76  } else if( hepMcMode_ == kNew ) {
77  hepMC = replacer_->produce(muons, 0, 0, this);
78  } else
79  throw cms::Exception("LogicError")
80  << "Invalid hepMcMode " << hepMcMode_ << " !!" << std::endl;
81 
82  if ( hepMC.get() != 0 ) {
83  std::auto_ptr<edm::HepMCProduct> bare_product(new edm::HepMCProduct());
84  bare_product->addHepMCData(hepMC.release()); // transfer ownership of the HepMC:GenEvent to bare_product
85 
86  evt.put(bare_product);
87 
88  std::auto_ptr<GenFilterInfo> info(new GenFilterInfo(replacer_->tried_, replacer_->passed_));
89  evt.put(info, std::string("minVisPtFilter"));
90  }
91 }
92 
94 {
95  replacer_->beginRun(run, es);
96 }
97 
99 {
100  replacer_->endRun();
101 }
102 
103 void
105 {
106 
107  replacer_->beginJob();
108 }
109 
110 void
112 {
113  replacer_->endJob();
114 }
115 
117 
T getParameter(std::string const &) const
reco::CandidateBaseRef getTheMuMinus(const std::vector< reco::CandidateBaseRef > &)
static const TGPicture * info(bool iBackgroundIsBlack)
tuple cfg
Definition: looper.py:293
virtual void beginRun(edm::Run &run, const edm::EventSetup &es)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:337
MCParticleReplacer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
static HepMcMode stringToHepMcMode(const std::string &name)
virtual std::auto_ptr< HepMC::GenEvent > produce(const std::vector< reco::Particle > &, const reco::Vertex *evtVtx=0, const HepMC::GenEvent *genEvt=0, MCParticleReplacer *=0)=0
virtual const Point & vertex() const =0
vertex position
edm::InputTag srcHepMC_
virtual int charge() const =0
electric charge
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
ParticleReplacerBase * replacer_
virtual void beginRun(edm::Run &, const edm::EventSetup &)
tuple muons
Definition: patZpeak.py:38
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< reco::CandidateBaseRef > getSelMuons(const edm::Event &, const edm::InputTag &)
reco::CandidateBaseRef getTheMuPlus(const std::vector< reco::CandidateBaseRef > &)
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:43
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector