test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATMuonSlimmer.cc
Go to the documentation of this file.
1 
11 
15 
22 
23 namespace pat {
24 
26  public:
27  explicit PATMuonSlimmer(const edm::ParameterSet & iConfig);
28  virtual ~PATMuonSlimmer() { }
29 
30  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
31  virtual void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override final;
32 
33  private:
34  const edm::EDGetTokenT<pat::MuonCollection> src_;
35  const edm::EDGetTokenT<reco::PFCandidateCollection> pf_;
36  const edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>> pf2pc_;
40  std::unique_ptr<pat::ObjectModifier<pat::Muon> > muonModifier_;
41  };
42 
43 } // namespace
44 
46  src_(consumes<pat::MuonCollection>(iConfig.getParameter<edm::InputTag>("src"))),
47  pf_(mayConsume<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandidates"))),
48  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
49  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
50  saveTeVMuons_(iConfig.getParameter<std::string>("saveTeVMuons")),
51  modifyMuon_(iConfig.getParameter<bool>("modifyMuons"))
52 {
54  if( modifyMuon_ ) {
55  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
56  muonModifier_.reset(new pat::ObjectModifier<pat::Muon>(mod_config) );
57  muonModifier_->setConsumes(sumes);
58  } else {
59  muonModifier_.reset(nullptr);
60  }
61  produces<std::vector<pat::Muon> >();
62 }
63 
64 void
66  if( modifyMuon_ ) muonModifier_->setEventContent(iSetup);
67 }
68 
69 void
71  using namespace edm;
72  using namespace std;
73 
75  iEvent.getByToken(src_, src);
76 
77  auto_ptr<vector<pat::Muon> > out(new vector<pat::Muon>());
78  out->reserve(src->size());
79 
80  if( modifyMuon_ ) { muonModifier_->setEvent(iEvent); }
81 
82  std::map<reco::CandidatePtr,pat::PackedCandidateRef> mu2pc;
83  if (linkToPackedPF_) {
86  iEvent.getByToken(pf_, pf);
87  iEvent.getByToken(pf2pc_, pf2pc);
88  for (unsigned int i = 0, n = pf->size(); i < n; ++i) {
89  const reco::PFCandidate &p = (*pf)[i];
90  if (p.muonRef().isNonnull()) mu2pc[refToPtr(p.muonRef())] = (*pf2pc)[reco::PFCandidateRef(pf, i)];
91  }
92  }
93 
94  for (vector<pat::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
95  out->push_back(*it);
96  pat::Muon & mu = out->back();
97 
98  if( modifyMuon_ ) { muonModifier_->modify(mu); }
99 
100  if (saveTeVMuons_(mu)){mu.embedPickyMuon(); mu.embedTpfmsMuon(); mu.embedDytMuon();}
101  if (linkToPackedPF_) {
102  mu.refToOrig_ = refToPtr(mu2pc[mu.refToOrig_]);
103  }
104  }
105 
106  iEvent.put(out);
107 }
108 
110 using namespace pat;
const edm::EDGetTokenT< pat::MuonCollection > src_
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void embedDytMuon()
embed reference to the above dyt Track
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
void embedTpfmsMuon()
embed reference to the above tpfms Track
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
PATMuonSlimmer(const edm::ParameterSet &iConfig)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const bool linkToPackedPF_
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
std::vector< pat::PackedCandidate > PackedCandidateCollection
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
std::unique_ptr< pat::ObjectModifier< pat::Muon > > muonModifier_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
const edm::EDGetTokenT< reco::PFCandidateCollection > pf_
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const int mu
Definition: Constants.h:22
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:450
Slimmer of PAT Muons.
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
string const
Definition: compareJSON.py:14
std::vector< Muon > MuonCollection
Definition: Muon.h:33
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
const StringCutObjectSelector< pat::Muon > saveTeVMuons_
void embedPickyMuon()
embed reference to the above picky Track
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
Analysis-level muon class.
Definition: Muon.h:49
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:421
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) overridefinal