CMS 3D CMS Logo

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) override;
31  virtual void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override final;
32 
33  private:
35  std::vector<edm::EDGetTokenT<reco::PFCandidateCollection>> pf_;
36  std::vector<edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>>> pf2pc_;
37  const bool linkToPackedPF_;
39  const bool modifyMuon_;
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 {
51  if (linkToPackedPF_) {
52  const std::vector<edm::InputTag> & pf = iConfig.getParameter<std::vector<edm::InputTag>>("pfCandidates");
53  const std::vector<edm::InputTag> & pf2pc = iConfig.getParameter<std::vector<edm::InputTag>>("packedPFCandidates");
54  if (pf.size() != pf2pc.size()) throw cms::Exception("Configuration") << "Mismatching pfCandidates and packedPFCandidates\n";
55  for (const edm::InputTag &tag : pf) pf_.push_back(consumes<reco::PFCandidateCollection>(tag));
57  }
58 
60  if( modifyMuon_ ) {
61  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
62  muonModifier_.reset(new pat::ObjectModifier<pat::Muon>(mod_config) );
63  muonModifier_->setConsumes(sumes);
64  } else {
65  muonModifier_.reset(nullptr);
66  }
67  produces<std::vector<pat::Muon> >();
68 }
69 
70 void
72  if( modifyMuon_ ) muonModifier_->setEventContent(iSetup);
73 }
74 
75 void
77  using namespace edm;
78  using namespace std;
79 
81  iEvent.getByToken(src_, src);
82 
83  auto out = std::make_unique<std::vector<pat::Muon>>();
84  out->reserve(src->size());
85 
86  if( modifyMuon_ ) { muonModifier_->setEvent(iEvent); }
87 
88  std::map<reco::CandidatePtr,pat::PackedCandidateRef> mu2pc;
89  if (linkToPackedPF_) {
92  for (unsigned int ipfh = 0, npfh = pf_.size(); ipfh < npfh; ++ipfh) {
93  iEvent.getByToken(pf_[ipfh], pf);
94  iEvent.getByToken(pf2pc_[ipfh], pf2pc);
95  const auto & pfcoll = (*pf);
96  const auto & pfmap = (*pf2pc);
97  for (unsigned int i = 0, n = pf->size(); i < n; ++i) {
98  const reco::PFCandidate &p = pfcoll[i];
99  if (p.muonRef().isNonnull()) mu2pc[refToPtr(p.muonRef())] = pfmap[reco::PFCandidateRef(pf, i)];
100  }
101  }
102  }
103 
104  for (vector<pat::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
105  out->push_back(*it);
106  pat::Muon & mu = out->back();
107 
108  if( modifyMuon_ ) { muonModifier_->modify(mu); }
109 
110  if (saveTeVMuons_(mu)){mu.embedPickyMuon(); mu.embedTpfmsMuon(); mu.embedDytMuon();}
111  if (linkToPackedPF_) {
112  mu.refToOrig_ = refToPtr(mu2pc[mu.refToOrig_]);
113  }
114  }
115 
116  iEvent.put(std::move(out));
117 }
118 
120 using namespace pat;
const edm::EDGetTokenT< pat::MuonCollection > src_
T getParameter(std::string const &) const
void embedDytMuon()
embed reference to the above dyt Track
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
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:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const bool linkToPackedPF_
std::vector< edm::EDGetTokenT< reco::PFCandidateCollection > > pf_
std::unique_ptr< pat::ObjectModifier< pat::Muon > > muonModifier_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const int mu
Definition: Constants.h:22
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:455
Slimmer of PAT Muons.
std::vector< Muon > MuonCollection
Definition: Muon.h:33
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
HLT enums.
std::vector< edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > > pf2pc_
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override final
const StringCutObjectSelector< pat::Muon > saveTeVMuons_
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:421
def move(src, dest)
Definition: eostools.py:510