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 
20 
21 namespace pat {
22 
24  public:
25  explicit PATMuonSlimmer(const edm::ParameterSet & iConfig);
26  virtual ~PATMuonSlimmer() { }
27 
28  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
29 
30  private:
35  };
36 
37 } // namespace
38 
40  src_(consumes<pat::MuonCollection>(iConfig.getParameter<edm::InputTag>("src"))),
41  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates"))
42 {
43  produces<std::vector<pat::Muon> >();
44  if (linkToPackedPF_) {
45  pf_ = consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandidates"));
46  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
47  }
48 }
49 
50 void
52  using namespace edm;
53  using namespace std;
54 
56  iEvent.getByToken(src_, src);
57 
58  auto_ptr<vector<pat::Muon> > out(new vector<pat::Muon>());
59  out->reserve(src->size());
60 
61  std::map<reco::CandidatePtr,pat::PackedCandidateRef> mu2pc;
62  if (linkToPackedPF_) {
65  iEvent.getByToken(pf_, pf);
66  iEvent.getByToken(pf2pc_, pf2pc);
67  for (unsigned int i = 0, n = pf->size(); i < n; ++i) {
68  const reco::PFCandidate &p = (*pf)[i];
69  if (p.muonRef().isNonnull()) mu2pc[refToPtr(p.muonRef())] = (*pf2pc)[reco::PFCandidateRef(pf, i)];
70  }
71  }
72 
73  for (vector<pat::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
74  out->push_back(*it);
75  pat::Muon & mu = out->back();
76  if (linkToPackedPF_) {
77  mu.refToOrig_ = refToPtr(mu2pc[mu.refToOrig_]);
78  }
79  }
80 
81  iEvent.put(out);
82 }
83 
85 using namespace pat;
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
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
edm::EDGetTokenT< pat::MuonCollection > src_
PATMuonSlimmer(const edm::ParameterSet &iConfig)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
const int mu
Definition: Constants.h:22
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:446
Slimmer of PAT Muons.
tuple out
Definition: dbtoconf.py:99
std::vector< Muon > MuonCollection
Definition: Muon.h:34
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:38
edm::EDGetTokenT< reco::PFCandidateCollection > pf_
Analysis-level muon class.
Definition: Muon.h:50
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:407