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  virtual ~PATTauSlimmer() { }
24 
25  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
26  virtual void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override final;
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 {
51  if( modifyTau_ ) {
52  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
53  tauModifier_.reset(new pat::ObjectModifier<pat::Tau>(mod_config) );
54  tauModifier_->setConsumes(sumes);
55  } else {
56  tauModifier_.reset(nullptr);
57  }
58  produces<std::vector<pat::Tau> >();
59 }
60 
61 void
63  if( modifyTau_ ) tauModifier_->setEventContent(iSetup);
64 }
65 
66 void
68  using namespace edm;
69  using namespace std;
70 
72  iEvent.getByToken(src_, src);
73 
75  if (linkToPackedPF_) iEvent.getByToken(pf2pc_, pf2pc);
76 
77  auto out = std::make_unique<std::vector<pat::Tau>>();
78  out->reserve(src->size());
79 
80  if( modifyTau_ ) { tauModifier_->setEvent(iEvent); }
81 
82  for (View<pat::Tau>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
83  out->push_back(*it);
84  pat::Tau & tau = out->back();
85 
86  if( modifyTau_ ) { tauModifier_->modify(tau); }
87 
88  // clearing the pat isolation which is not used by taus
89  tau.isolations_.clear();
90  tau.isoDeposits_.clear();
91 
92  if (linkToPackedPF_) {
93 
94  reco::CandidatePtrVector signalChHPtrs, signalNHPtrs, signalGammaPtrs, isolationChHPtrs, isolationNHPtrs, isolationGammaPtrs;
95 
96  for (const reco::PFCandidatePtr &p : tau.signalPFChargedHadrCands()) {
97  signalChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
98  }
99  tau.setSignalChargedHadrCands(signalChHPtrs);
100 
101  for (const reco::PFCandidatePtr &p : tau.signalPFNeutrHadrCands()) {
102  signalNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
103  }
104  tau.setSignalNeutralHadrCands(signalNHPtrs);
105 
106  for (const reco::PFCandidatePtr &p : tau.signalPFGammaCands()) {
107  signalGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
108  }
109  tau.setSignalGammaCands(signalGammaPtrs);
110 
111  for (const reco::PFCandidatePtr &p : tau.isolationPFChargedHadrCands()) {
112  isolationChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
113  }
114  tau.setIsolationChargedHadrCands(isolationChHPtrs);
115 
116  for (const reco::PFCandidatePtr &p : tau.isolationPFNeutrHadrCands()) {
117  isolationNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
118  }
119  tau.setIsolationNeutralHadrCands(isolationNHPtrs);
120 
121  for (const reco::PFCandidatePtr &p : tau.isolationPFGammaCands()) {
122  isolationGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
123  }
124  tau.setIsolationGammaCands(isolationGammaPtrs);
125 
126  }
127  if(dropPiZeroRefs_){
128  tau.pfSpecific_[0].signalPiZeroCandidates_.clear();
129  tau.pfSpecific_[0].isolationPiZeroCandidates_.clear();
130  }
132  tau.pfSpecific_[0].signalTauChargedHadronCandidates_.clear();
133  tau.pfSpecific_[0].isolationTauChargedHadronCandidates_.clear();
134  }
135  if(dropPFSpecific_){ tau.pfSpecific_.clear();}
136 
137  }
138 
139  iEvent.put(std::move(out));
140 }
141 
143 using namespace pat;
T getParameter(std::string const &) const
virtual 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:127
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:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
const edm::EDGetTokenT< edm::View< pat::Tau > > src_
const bool dropPFSpecific_
const bool dropPiZeroRefs_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
void setIsolationGammaCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:301
int iEvent
Definition: GenABIO.cc:230
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void setIsolationNeutralHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:300
void setIsolationChargedHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:299
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override final
PATTauSlimmer(const edm::ParameterSet &iConfig)
void setSignalChargedHadrCands(const reco::CandidatePtrVector &ptrs)
setters for the PtrVectors (for miniAOD)
Definition: Tau.h:296
virtual ~PATTauSlimmer()
Analysis-level tau class.
Definition: Tau.h:55
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:298
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
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
def move(src, dest)
Definition: eostools.py:510
std::vector< pat::tau::TauPFSpecific > pfSpecific_
holder for PFTau info, or empty vector if CaloTau
Definition: Tau.h:505
const std::vector< reco::PFCandidatePtr > & isolationPFNeutrHadrCands() const
void setSignalNeutralHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:297
std::unique_ptr< pat::ObjectModifier< pat::Tau > > tauModifier_