CMS 3D CMS Logo

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  void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final;
26 
27  private:
29  const bool linkToPackedPF_;
31  const bool dropPiZeroRefs_;
33  const bool dropPFSpecific_;
34  const bool modifyTau_;
35  std::unique_ptr<pat::ObjectModifier<pat::Tau>> tauModifier_;
36  };
37 
38 } // namespace pat
39 
41  : src_(consumes<edm::View<pat::Tau>>(iConfig.getParameter<edm::InputTag>("src"))),
42  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
43  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(
44  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
45  dropPiZeroRefs_(iConfig.exists("dropPiZeroRefs") ? iConfig.getParameter<bool>("dropPiZeroRefs") : true),
46  dropTauChargedHadronRefs_(
47  iConfig.exists("dropTauChargedHadronRefs") ? iConfig.getParameter<bool>("dropTauChargedHadronRefs") : true),
48  dropPFSpecific_(iConfig.exists("dropPFSpecific") ? iConfig.getParameter<bool>("dropPFSpecific") : true),
49  modifyTau_(iConfig.getParameter<bool>("modifyTaus")) {
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 
58  if (modifyTau_)
59  tauModifier_->setEventContent(iSetup);
60 }
61 
63  using namespace edm;
64  using namespace std;
65 
67  iEvent.getByToken(src_, src);
68 
70  if (linkToPackedPF_)
71  iEvent.getByToken(pf2pc_, pf2pc);
72 
73  auto out = std::make_unique<std::vector<pat::Tau>>();
74  out->reserve(src->size());
75 
76  if (modifyTau_) {
77  tauModifier_->setEvent(iEvent);
78  }
79 
80  for (View<pat::Tau>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
81  out->push_back(*it);
82  pat::Tau &tau = out->back();
83 
84  if (modifyTau_) {
85  tauModifier_->modify(tau);
86  }
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  reco::CandidatePtrVector signalChHPtrs, signalNHPtrs, signalGammaPtrs, isolationChHPtrs, isolationNHPtrs,
94  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  if (dropPiZeroRefs_) {
127  tau.pfSpecific_[0].signalPiZeroCandidates_.clear();
128  tau.pfSpecific_[0].isolationPiZeroCandidates_.clear();
129  }
130  if (dropTauChargedHadronRefs_) {
131  tau.pfSpecific_[0].signalTauChargedHadronCandidates_.clear();
132  tau.pfSpecific_[0].isolationTauChargedHadronCandidates_.clear();
133  }
134  if (dropPFSpecific_) {
135  tau.pfSpecific_.clear();
136  }
137  }
138 
139  iEvent.put(std::move(out));
140 }
141 
143 using namespace pat;
ObjectModifier.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
sistrip::View
View
Definition: ConstantsForView.h:26
metsig::tau
Definition: SignAlgoResolutions.h:49
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
pat::Tau
Analysis-level tau class.
Definition: Tau.h:53
pat::PATTauSlimmer::modifyTau_
const bool modifyTau_
Definition: PATTauSlimmer.cc:34
EDProducer.h
pat::PATTauSlimmer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATTauSlimmer.cc:62
pat::PATTauSlimmer::pf2pc_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
Definition: PATTauSlimmer.cc:30
Tau
Definition: Tau.py:1
Association.h
edm::Handle
Definition: AssociativeIterator.h:50
Tau.h
pat::PATTauSlimmer::tauModifier_
std::unique_ptr< pat::ObjectModifier< pat::Tau > > tauModifier_
Definition: PATTauSlimmer.cc:35
pat::PATTauSlimmer::src_
const edm::EDGetTokenT< edm::View< pat::Tau > > src_
Definition: PATTauSlimmer.cc:28
edm::refToPtr
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
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::PtrVector< Candidate >
pat::PATTauSlimmer::linkToPackedPF_
const bool linkToPackedPF_
Definition: PATTauSlimmer.cc:29
pat::PATTauSlimmer::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
Definition: PATTauSlimmer.cc:57
pat::PATTauSlimmer::PATTauSlimmer
PATTauSlimmer(const edm::ParameterSet &iConfig)
Definition: PATTauSlimmer.cc:40
edm::PtrVector::push_back
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
pat::PATTauSlimmer::dropPiZeroRefs_
const bool dropPiZeroRefs_
Definition: PATTauSlimmer.cc:31
funct::true
true
Definition: Factorize.h:173
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
PackedCandidate.h
iEvent
int iEvent
Definition: GenABIO.cc:224
RefToPtr.h
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
pat::PATTauSlimmer::~PATTauSlimmer
~PATTauSlimmer() override
Definition: PATTauSlimmer.cc:22
edm::Ptr< PFCandidate >
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1130
pat::PATTauSlimmer::dropPFSpecific_
const bool dropPFSpecific_
Definition: PATTauSlimmer.cc:33
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
pat::PATTauSlimmer
Slimmer of PAT Taus.
Definition: PATTauSlimmer.cc:19
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
pat::PATTauSlimmer::dropTauChargedHadronRefs_
const bool dropTauChargedHadronRefs_
Definition: PATTauSlimmer.cc:32
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ParameterSet.h
edm::Event
Definition: Event.h:73