test
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 
16 
17 namespace pat {
18 
19  class PATTauSlimmer : public edm::EDProducer {
20  public:
21  explicit PATTauSlimmer(const edm::ParameterSet & iConfig);
22  virtual ~PATTauSlimmer() { }
23 
24  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
25 
26  private:
33 
34 
35  };
36 
37 } // namespace
38 
40  src_(consumes<edm::View<pat::Tau> >(iConfig.getParameter<edm::InputTag>("src"))),
41  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates"))
42 {
43  produces<std::vector<pat::Tau> >();
44  if (linkToPackedPF_) pf2pc_ = consumes<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 
49 }
50 
51 void
53  using namespace edm;
54  using namespace std;
55 
57  iEvent.getByToken(src_, src);
58 
60  if (linkToPackedPF_) iEvent.getByToken(pf2pc_, pf2pc);
61 
62  auto_ptr<vector<pat::Tau> > out(new vector<pat::Tau>());
63  out->reserve(src->size());
64 
65  for (View<pat::Tau>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
66  out->push_back(*it);
67  pat::Tau & tau = out->back();
68  // clearing the pat isolation which is not used by taus
69  tau.isolations_.clear();
70  tau.isoDeposits_.clear();
71 
72  if (linkToPackedPF_) {
73 
74  reco::CandidatePtrVector signalChHPtrs, signalNHPtrs, signalGammaPtrs, isolationChHPtrs, isolationNHPtrs, isolationGammaPtrs;
75 
76  for (const reco::PFCandidatePtr &p : tau.signalPFChargedHadrCands()) {
77  signalChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
78  }
79  tau.setSignalChargedHadrCands(signalChHPtrs);
80 
81  for (const reco::PFCandidatePtr &p : tau.signalPFNeutrHadrCands()) {
82  signalNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
83  }
84  tau.setSignalNeutralHadrCands(signalNHPtrs);
85 
86  for (const reco::PFCandidatePtr &p : tau.signalPFGammaCands()) {
87  signalGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
88  }
89  tau.setSignalGammaCands(signalGammaPtrs);
90 
92  isolationChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
93  }
94  tau.setIsolationChargedHadrCands(isolationChHPtrs);
95 
96  for (const reco::PFCandidatePtr &p : tau.isolationPFNeutrHadrCands()) {
97  isolationNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
98  }
99  tau.setIsolationNeutralHadrCands(isolationNHPtrs);
100 
101  for (const reco::PFCandidatePtr &p : tau.isolationPFGammaCands()) {
102  isolationGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
103  }
104  tau.setIsolationGammaCands(isolationGammaPtrs);
105 
106  }
107  if(dropPiZeroRefs_){
108  tau.pfSpecific_[0].signalPiZeroCandidates_.clear();
109  tau.pfSpecific_[0].isolationPiZeroCandidates_.clear();
110  }
111  if(dropTauChargedHadronRefs_){
112  tau.pfSpecific_[0].signalTauChargedHadronCandidates_.clear();
113  tau.pfSpecific_[0].isolationTauChargedHadronCandidates_.clear();
114  }
115  if(dropPFSpecific_){ tau.pfSpecific_.clear();}
116 
117  }
118 
119  iEvent.put(out);
120 }
121 
123 using namespace pat;
T getParameter(std::string const &) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
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:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:138
Slimmer of PAT Taus.
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< edm::View< pat::Tau > > src_
const std::vector< reco::PFCandidatePtr > & isolationPFChargedHadrCands() const
Definition: Tau.cc:586
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:116
void setIsolationNeutralHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:301
void setIsolationChargedHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:300
const std::vector< reco::PFCandidatePtr > & isolationPFNeutrHadrCands() const
Definition: Tau.cc:608
PATTauSlimmer(const edm::ParameterSet &iConfig)
void setSignalChargedHadrCands(const reco::CandidatePtrVector &ptrs)
setters for the PtrVectors (for miniAOD)
Definition: Tau.h:297
virtual ~PATTauSlimmer()
Analysis-level tau class.
Definition: Tau.h:56
IsoDepositPairs isoDeposits_
Definition: Lepton.h:199
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
Definition: Tau.cc:488
tuple out
Definition: dbtoconf.py:99
void setSignalGammaCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:299
const std::vector< reco::PFCandidatePtr > & isolationPFGammaCands() const
Definition: Tau.cc:630
std::vector< float > isolations_
Definition: Lepton.h:200
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
const std::vector< reco::PFCandidatePtr > & signalPFGammaCands() const
Definition: Tau.cc:532
const std::vector< reco::PFCandidatePtr > & signalPFNeutrHadrCands() const
Definition: Tau.cc:510
std::vector< pat::tau::TauPFSpecific > pfSpecific_
holder for PFTau info, or empty vector if CaloTau
Definition: Tau.h:477
void setSignalNeutralHadrCands(const reco::CandidatePtrVector &ptrs)
Definition: Tau.h:298