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  edm::EDGetTokenT<pat::MuonCollection> src_;
35  edm::EDGetTokenT<reco::PFCandidateCollection> pf_;
36  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  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
48  saveTeVMuons_(iConfig.getParameter<std::string>("saveTeVMuons")),
49  modifyMuon_(iConfig.getParameter<bool>("modifyMuons"))
50 {
52  if( modifyMuon_ ) {
53  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
54  muonModifier_.reset(new pat::ObjectModifier<pat::Muon>(mod_config) );
55  muonModifier_->setConsumes(sumes);
56  } else {
57  muonModifier_.reset(nullptr);
58  }
59  produces<std::vector<pat::Muon> >();
60  if (linkToPackedPF_) {
61  pf_ = consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandidates"));
62  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
63  }
64 }
65 
66 void
68  if( modifyMuon_ ) muonModifier_->setEventContent(iSetup);
69 }
70 
71 void
73  using namespace edm;
74  using namespace std;
75 
77  iEvent.getByToken(src_, src);
78 
79  auto_ptr<vector<pat::Muon> > out(new vector<pat::Muon>());
80  out->reserve(src->size());
81 
82  if( modifyMuon_ ) { muonModifier_->setEvent(iEvent); }
83 
84  std::map<reco::CandidatePtr,pat::PackedCandidateRef> mu2pc;
85  if (linkToPackedPF_) {
88  iEvent.getByToken(pf_, pf);
89  iEvent.getByToken(pf2pc_, pf2pc);
90  for (unsigned int i = 0, n = pf->size(); i < n; ++i) {
91  const reco::PFCandidate &p = (*pf)[i];
92  if (p.muonRef().isNonnull()) mu2pc[refToPtr(p.muonRef())] = (*pf2pc)[reco::PFCandidateRef(pf, i)];
93  }
94  }
95 
96  for (vector<pat::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
97  out->push_back(*it);
98  pat::Muon & mu = out->back();
99 
100  if( modifyMuon_ ) { muonModifier_->modify(mu); }
101 
102  if (saveTeVMuons_(mu)){mu.embedPickyMuon(); mu.embedTpfmsMuon(); mu.embedDytMuon();}
103  if (linkToPackedPF_) {
104  mu.refToOrig_ = refToPtr(mu2pc[mu.refToOrig_]);
105  }
106  }
107 
108  iEvent.put(out);
109 }
110 
112 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:449
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)
std::vector< pat::PackedCandidate > PackedCandidateCollection
std::unique_ptr< pat::ObjectModifier< pat::Muon > > muonModifier_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
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.
tuple out
Definition: dbtoconf.py:99
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
string const
Definition: compareJSON.py:14
std::vector< Muon > MuonCollection
Definition: Muon.h:33
#define private
Definition: FWFileEntry.h:17
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:49
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:407
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) overridefinal