CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PATTauSlimmer.cc
Go to the documentation of this file.
1 
13 
16 
17 namespace pat {
18 
20  public:
21  explicit PATTauSlimmer(const edm::ParameterSet &iConfig);
22  ~PATTauSlimmer() override {}
23 
24  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
25 
26  private:
28  const bool linkToPackedPF_;
30  const bool dropPiZeroRefs_;
32  const bool dropPFSpecific_;
33  const bool modifyTau_;
34  std::unique_ptr<pat::ObjectModifier<pat::Tau>> tauModifier_;
35  };
36 
37 } // namespace pat
38 
40  : src_(consumes<edm::View<pat::Tau>>(iConfig.getParameter<edm::InputTag>("src"))),
41  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
42  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(
43  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
44  dropPiZeroRefs_(iConfig.exists("dropPiZeroRefs") ? iConfig.getParameter<bool>("dropPiZeroRefs") : true),
45  dropTauChargedHadronRefs_(
46  iConfig.exists("dropTauChargedHadronRefs") ? iConfig.getParameter<bool>("dropTauChargedHadronRefs") : true),
47  dropPFSpecific_(iConfig.exists("dropPFSpecific") ? iConfig.getParameter<bool>("dropPFSpecific") : true),
48  modifyTau_(iConfig.getParameter<bool>("modifyTaus")) {
49  if (modifyTau_) {
50  const edm::ParameterSet &mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
51  tauModifier_ = std::make_unique<pat::ObjectModifier<pat::Tau>>(mod_config, consumesCollector());
52  }
53  produces<std::vector<pat::Tau>>();
54 }
55 
57  using namespace edm;
58  using namespace std;
59 
60  if (modifyTau_)
61  tauModifier_->setEventContent(iSetup);
62 
64  iEvent.getByToken(src_, src);
65 
67  if (linkToPackedPF_)
68  iEvent.getByToken(pf2pc_, pf2pc);
69 
70  auto out = std::make_unique<std::vector<pat::Tau>>();
71  out->reserve(src->size());
72 
73  if (modifyTau_) {
74  tauModifier_->setEvent(iEvent);
75  }
76 
77  for (View<pat::Tau>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
78  out->push_back(*it);
79  pat::Tau &tau = out->back();
80 
81  if (modifyTau_) {
82  tauModifier_->modify(tau);
83  }
84 
85  // clearing the pat isolation which is not used by taus
86  tau.isolations_.clear();
87  tau.isoDeposits_.clear();
88 
89  if (linkToPackedPF_) {
90  reco::CandidatePtrVector signalChHPtrs, signalNHPtrs, signalGammaPtrs, isolationChHPtrs, isolationNHPtrs,
91  isolationGammaPtrs;
92 
93  for (const reco::PFCandidatePtr &p : tau.signalPFChargedHadrCands()) {
94  signalChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
95  }
96  tau.setSignalChargedHadrCands(signalChHPtrs);
97 
98  for (const reco::PFCandidatePtr &p : tau.signalPFNeutrHadrCands()) {
99  signalNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
100  }
101  tau.setSignalNeutralHadrCands(signalNHPtrs);
102 
103  for (const reco::PFCandidatePtr &p : tau.signalPFGammaCands()) {
104  signalGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
105  }
106  tau.setSignalGammaCands(signalGammaPtrs);
107 
108  for (const reco::PFCandidatePtr &p : tau.isolationPFChargedHadrCands()) {
109  isolationChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
110  }
111  tau.setIsolationChargedHadrCands(isolationChHPtrs);
112 
113  for (const reco::PFCandidatePtr &p : tau.isolationPFNeutrHadrCands()) {
114  isolationNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
115  }
116  tau.setIsolationNeutralHadrCands(isolationNHPtrs);
117 
118  for (const reco::PFCandidatePtr &p : tau.isolationPFGammaCands()) {
119  isolationGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
120  }
121  tau.setIsolationGammaCands(isolationGammaPtrs);
122  }
123  if (dropPiZeroRefs_) {
124  tau.pfSpecific_[0].signalPiZeroCandidates_.clear();
125  tau.pfSpecific_[0].isolationPiZeroCandidates_.clear();
126  }
127  if (dropTauChargedHadronRefs_) {
128  tau.pfSpecific_[0].signalTauChargedHadronCandidates_.clear();
129  tau.pfSpecific_[0].isolationTauChargedHadronCandidates_.clear();
130  }
131  if (dropPFSpecific_) {
132  tau.pfSpecific_.clear();
133  }
134  }
135 
136  iEvent.put(std::move(out));
137 }
138 
140 using namespace pat;
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
const std::vector< reco::PFCandidatePtr > & isolationPFChargedHadrCands() const
Slimmer of PAT Taus.
std::vector< pat::PackedCandidate > PackedCandidateCollection
~PATTauSlimmer() override
const edm::EDGetTokenT< edm::View< pat::Tau > > src_
const bool dropPFSpecific_
const bool dropPiZeroRefs_
void setIsolationGammaCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:265
int iEvent
Definition: GenABIO.cc:224
void setIsolationNeutralHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:264
void setIsolationChargedHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:263
def move
Definition: eostools.py:511
PATTauSlimmer(const edm::ParameterSet &iConfig)
void setSignalChargedHadrCands(const reco::CandidatePtrVector &ptrs)
setters for the PtrVectors (for miniAOD)
Definition: Tau.h:260
Analysis-level tau class.
Definition: Tau.h:53
IsoDepositPairs isoDeposits_
Definition: Lepton.h:222
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
const bool modifyTau_
void setSignalGammaCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:262
const std::vector< reco::PFCandidatePtr > & signalPFNeutrHadrCands() const
const std::vector< reco::PFCandidatePtr > & isolationPFGammaCands() const
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
std::vector< float > isolations_
Definition: Lepton.h:223
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const bool dropTauChargedHadronRefs_
const bool linkToPackedPF_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
const std::vector< reco::PFCandidatePtr > & signalPFGammaCands() const
std::vector< pat::tau::TauPFSpecific > pfSpecific_
holder for PFTau info, or empty vector if CaloTau
Definition: Tau.h:469
const std::vector< reco::PFCandidatePtr > & isolationPFNeutrHadrCands() const
void setSignalNeutralHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:261
std::unique_ptr< pat::ObjectModifier< pat::Tau > > tauModifier_