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 
21 
22 namespace pat {
23 
25  public:
26  explicit PATMuonSlimmer(const edm::ParameterSet & iConfig);
27  virtual ~PATMuonSlimmer() { }
28 
29  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
30 
31  private:
37  };
38 
39 } // namespace
40 
42  src_(consumes<pat::MuonCollection>(iConfig.getParameter<edm::InputTag>("src"))),
43  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
44  saveTeVMuons_(iConfig.getParameter<std::string>("saveTeVMuons"))
45 {
46  produces<std::vector<pat::Muon> >();
47  if (linkToPackedPF_) {
48  pf_ = consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandidates"));
49  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
50  }
51 }
52 
53 void
55  using namespace edm;
56  using namespace std;
57 
59  iEvent.getByToken(src_, src);
60 
61  auto_ptr<vector<pat::Muon> > out(new vector<pat::Muon>());
62  out->reserve(src->size());
63 
64  std::map<reco::CandidatePtr,pat::PackedCandidateRef> mu2pc;
65  if (linkToPackedPF_) {
68  iEvent.getByToken(pf_, pf);
69  iEvent.getByToken(pf2pc_, pf2pc);
70  for (unsigned int i = 0, n = pf->size(); i < n; ++i) {
71  const reco::PFCandidate &p = (*pf)[i];
72  if (p.muonRef().isNonnull()) mu2pc[refToPtr(p.muonRef())] = (*pf2pc)[reco::PFCandidateRef(pf, i)];
73  }
74  }
75 
76  for (vector<pat::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
77  out->push_back(*it);
78  pat::Muon & mu = out->back();
79  if (saveTeVMuons_(mu)){mu.embedPickyMuon(); mu.embedTpfmsMuon(); mu.embedDytMuon();}
80  if (linkToPackedPF_) {
81  mu.refToOrig_ = refToPtr(mu2pc[mu.refToOrig_]);
82  }
83  }
84 
85  iEvent.put(out);
86 }
87 
89 using namespace pat;
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:250
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
edm::EDGetTokenT< pat::MuonCollection > src_
PATMuonSlimmer(const edm::ParameterSet &iConfig)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
StringCutObjectSelector< pat::Muon > saveTeVMuons_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
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.
tuple out
Definition: dbtoconf.py:99
std::vector< Muon > MuonCollection
Definition: Muon.h:34
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
edm::EDGetTokenT< reco::PFCandidateCollection > pf_
void embedPickyMuon()
embed reference to the above picky Track
Analysis-level muon class.
Definition: Muon.h:50
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:407