CMS 3D CMS Logo

PATTauSlimmer.cc
Go to the documentation of this file.
1 
14 
17 
18 namespace pat {
19 
21  public:
22  explicit PATTauSlimmer(const edm::ParameterSet & iConfig);
23  ~PATTauSlimmer() override { }
24 
25  void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
27 
28  private:
30  const bool linkToPackedPF_;
32  const bool dropPiZeroRefs_;
34  const bool dropPFSpecific_;
35  const bool modifyTau_;
36  std::unique_ptr<pat::ObjectModifier<pat::Tau> > tauModifier_;
37  };
38 
39 } // namespace
40 
42  src_(consumes<edm::View<pat::Tau> >(iConfig.getParameter<edm::InputTag>("src"))),
43  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
44  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
45  dropPiZeroRefs_(iConfig.exists("dropPiZeroRefs") ? iConfig.getParameter<bool>("dropPiZeroRefs") : true ),
46  dropTauChargedHadronRefs_(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 {
50  if( modifyTau_ ) {
51  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
52  tauModifier_ = std::make_unique<pat::ObjectModifier<pat::Tau>>(mod_config, consumesCollector());
53  }
54  produces<std::vector<pat::Tau> >();
55 }
56 
57 void
59  if( modifyTau_ ) tauModifier_->setEventContent(iSetup);
60 }
61 
62 void
64  using namespace edm;
65  using namespace std;
66 
68  iEvent.getByToken(src_, src);
69 
71  if (linkToPackedPF_) iEvent.getByToken(pf2pc_, pf2pc);
72 
73  auto out = std::make_unique<std::vector<pat::Tau>>();
74  out->reserve(src->size());
75 
76  if( modifyTau_ ) { tauModifier_->setEvent(iEvent); }
77 
78  for (View<pat::Tau>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
79  out->push_back(*it);
80  pat::Tau & tau = out->back();
81 
82  if( modifyTau_ ) { tauModifier_->modify(tau); }
83 
84  // clearing the pat isolation which is not used by taus
85  tau.isolations_.clear();
86  tau.isoDeposits_.clear();
87 
88  if (linkToPackedPF_) {
89 
90  reco::CandidatePtrVector signalChHPtrs, signalNHPtrs, signalGammaPtrs, isolationChHPtrs, isolationNHPtrs, isolationGammaPtrs;
91 
92  for (const reco::PFCandidatePtr &p : tau.signalPFChargedHadrCands()) {
93  signalChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
94  }
95  tau.setSignalChargedHadrCands(signalChHPtrs);
96 
97  for (const reco::PFCandidatePtr &p : tau.signalPFNeutrHadrCands()) {
98  signalNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
99  }
100  tau.setSignalNeutralHadrCands(signalNHPtrs);
101 
102  for (const reco::PFCandidatePtr &p : tau.signalPFGammaCands()) {
103  signalGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
104  }
105  tau.setSignalGammaCands(signalGammaPtrs);
106 
107  for (const reco::PFCandidatePtr &p : tau.isolationPFChargedHadrCands()) {
108  isolationChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
109  }
110  tau.setIsolationChargedHadrCands(isolationChHPtrs);
111 
112  for (const reco::PFCandidatePtr &p : tau.isolationPFNeutrHadrCands()) {
113  isolationNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
114  }
115  tau.setIsolationNeutralHadrCands(isolationNHPtrs);
116 
117  for (const reco::PFCandidatePtr &p : tau.isolationPFGammaCands()) {
118  isolationGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
119  }
120  tau.setIsolationGammaCands(isolationGammaPtrs);
121 
122  }
123  if(dropPiZeroRefs_){
124  tau.pfSpecific_[0].signalPiZeroCandidates_.clear();
125  tau.pfSpecific_[0].isolationPiZeroCandidates_.clear();
126  }
128  tau.pfSpecific_[0].signalTauChargedHadronCandidates_.clear();
129  tau.pfSpecific_[0].isolationTauChargedHadronCandidates_.clear();
130  }
131  if(dropPFSpecific_){ tau.pfSpecific_.clear();}
132 
133  }
134 
135  iEvent.put(std::move(out));
136 }
137 
139 using namespace pat;
T getParameter(std::string const &) const
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:125
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:517
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:140
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_
Definition: HeavyIon.h:7
void setIsolationGammaCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:302
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setIsolationNeutralHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:301
void setIsolationChargedHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:300
PATTauSlimmer(const edm::ParameterSet &iConfig)
void setSignalChargedHadrCands(const reco::CandidatePtrVector &ptrs)
setters for the PtrVectors (for miniAOD)
Definition: Tau.h:297
Analysis-level tau class.
Definition: Tau.h:56
IsoDepositPairs isoDeposits_
Definition: Lepton.h:202
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
Definition: Tau.py:1
const bool modifyTau_
void setSignalGammaCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:299
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:203
const bool dropTauChargedHadronRefs_
const bool linkToPackedPF_
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
const std::vector< reco::PFCandidatePtr > & signalPFGammaCands() const
def move(src, dest)
Definition: eostools.py:511
std::vector< pat::tau::TauPFSpecific > pfSpecific_
holder for PFTau info, or empty vector if CaloTau
Definition: Tau.h:508
const std::vector< reco::PFCandidatePtr > & isolationPFNeutrHadrCands() const
void setSignalNeutralHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:298
std::unique_ptr< pat::ObjectModifier< pat::Tau > > tauModifier_