CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATTauSlimmer.cc
Go to the documentation of this file.
1 
14 
17 
18 namespace pat {
19 
20  class PATTauSlimmer : public edm::EDProducer {
21  public:
22  explicit PATTauSlimmer(const edm::ParameterSet & iConfig);
23  virtual ~PATTauSlimmer() { }
24 
25  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
26  virtual void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override final;
27 
28  private:
29  edm::EDGetTokenT<edm::View<pat::Tau> > src_;
31  edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>> pf2pc_;
35  bool modifyTau_;
36  std::unique_ptr<pat::ObjectModifier<pat::Tau> > tauModifier_;
37 
38  };
39 
40 } // namespace
41 
43  src_(consumes<edm::View<pat::Tau> >(iConfig.getParameter<edm::InputTag>("src"))),
44  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
45  modifyTau_(iConfig.getParameter<bool>("modifyTaus"))
46 {
48  if( modifyTau_ ) {
49  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
50  tauModifier_.reset(new pat::ObjectModifier<pat::Tau>(mod_config) );
51  tauModifier_->setConsumes(sumes);
52  } else {
53  tauModifier_.reset(nullptr);
54  }
55  produces<std::vector<pat::Tau> >();
56  if (linkToPackedPF_) pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
57  dropPiZeroRefs_ = iConfig.exists("dropPiZeroRefs") ? iConfig.getParameter<bool>("dropPiZeroRefs") : true;
58  dropTauChargedHadronRefs_ = iConfig.exists("dropTauChargedHadronRefs") ? iConfig.getParameter<bool>("dropTauChargedHadronRefs") : true;
59  dropPFSpecific_ = iConfig.exists("dropPFSpecific") ? iConfig.getParameter<bool>("dropPFSpecific"): true;
60 
61 }
62 
63 void
65  if( modifyTau_ ) tauModifier_->setEventContent(iSetup);
66 }
67 
68 void
70  using namespace edm;
71  using namespace std;
72 
74  iEvent.getByToken(src_, src);
75 
77  if (linkToPackedPF_) iEvent.getByToken(pf2pc_, pf2pc);
78 
79  auto_ptr<vector<pat::Tau> > out(new vector<pat::Tau>());
80  out->reserve(src->size());
81 
82  if( modifyTau_ ) { tauModifier_->setEvent(iEvent); }
83 
84  for (View<pat::Tau>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
85  out->push_back(*it);
86  pat::Tau & tau = out->back();
87 
88  if( modifyTau_ ) { tauModifier_->modify(tau); }
89 
90  // clearing the pat isolation which is not used by taus
91  tau.isolations_.clear();
92  tau.isoDeposits_.clear();
93 
94  if (linkToPackedPF_) {
95 
96  reco::CandidatePtrVector signalChHPtrs, signalNHPtrs, signalGammaPtrs, isolationChHPtrs, isolationNHPtrs, isolationGammaPtrs;
97 
98  for (const reco::PFCandidatePtr &p : tau.signalPFChargedHadrCands()) {
99  signalChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
100  }
101  tau.setSignalChargedHadrCands(signalChHPtrs);
102 
103  for (const reco::PFCandidatePtr &p : tau.signalPFNeutrHadrCands()) {
104  signalNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
105  }
106  tau.setSignalNeutralHadrCands(signalNHPtrs);
107 
108  for (const reco::PFCandidatePtr &p : tau.signalPFGammaCands()) {
109  signalGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
110  }
111  tau.setSignalGammaCands(signalGammaPtrs);
112 
113  for (const reco::PFCandidatePtr &p : tau.isolationPFChargedHadrCands()) {
114  isolationChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
115  }
116  tau.setIsolationChargedHadrCands(isolationChHPtrs);
117 
118  for (const reco::PFCandidatePtr &p : tau.isolationPFNeutrHadrCands()) {
119  isolationNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
120  }
121  tau.setIsolationNeutralHadrCands(isolationNHPtrs);
122 
123  for (const reco::PFCandidatePtr &p : tau.isolationPFGammaCands()) {
124  isolationGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
125  }
126  tau.setIsolationGammaCands(isolationGammaPtrs);
127 
128  }
129  if(dropPiZeroRefs_){
130  tau.pfSpecific_[0].signalPiZeroCandidates_.clear();
131  tau.pfSpecific_[0].isolationPiZeroCandidates_.clear();
132  }
134  tau.pfSpecific_[0].signalTauChargedHadronCandidates_.clear();
135  tau.pfSpecific_[0].isolationTauChargedHadronCandidates_.clear();
136  }
137  if(dropPFSpecific_){ tau.pfSpecific_.clear();}
138 
139  }
140 
141  iEvent.put(out);
142 }
143 
145 using namespace pat;
T getParameter(std::string const &) const
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:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:139
const std::vector< reco::PFCandidatePtr > & isolationPFChargedHadrCands() const
Slimmer of PAT Taus.
std::vector< pat::PackedCandidate > PackedCandidateCollection
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< edm::View< pat::Tau > > src_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void setIsolationGammaCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:302
int iEvent
Definition: GenABIO.cc:230
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
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.
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
virtual ~PATTauSlimmer()
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) overridefinal
Analysis-level tau class.
Definition: Tau.h:56
IsoDepositPairs isoDeposits_
Definition: Lepton.h:199
tuple out
Definition: dbtoconf.py:99
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
void setSignalGammaCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:299
const std::vector< reco::PFCandidatePtr > & signalPFNeutrHadrCands() const
const std::vector< reco::PFCandidatePtr > & isolationPFGammaCands() const
std::vector< float > isolations_
Definition: Lepton.h:200
string const
Definition: compareJSON.py:14
#define private
Definition: FWFileEntry.h:17
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
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:477
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_