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 
26  private:
28  const bool linkToPackedPF_;
30  const bool linkToLostTracks_;
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 pat
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>>(
45  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
46  linkToLostTracks_(iConfig.getParameter<bool>("linkToLostTracks")),
47  trk2lost_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(
48  iConfig.getParameter<edm::InputTag>("lostTracks"))),
49  dropPiZeroRefs_(iConfig.exists("dropPiZeroRefs") ? iConfig.getParameter<bool>("dropPiZeroRefs") : true),
50  dropTauChargedHadronRefs_(
51  iConfig.exists("dropTauChargedHadronRefs") ? iConfig.getParameter<bool>("dropTauChargedHadronRefs") : true),
52  dropPFSpecific_(iConfig.exists("dropPFSpecific") ? iConfig.getParameter<bool>("dropPFSpecific") : true),
53  modifyTau_(iConfig.getParameter<bool>("modifyTaus")) {
54  if (modifyTau_) {
55  const edm::ParameterSet &mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
56  tauModifier_ = std::make_unique<pat::ObjectModifier<pat::Tau>>(mod_config, consumesCollector());
57  }
58  produces<std::vector<pat::Tau>>();
59 }
60 
62  using namespace edm;
63  using namespace std;
64 
65  if (modifyTau_)
66  tauModifier_->setEventContent(iSetup);
67 
69  iEvent.getByToken(src_, src);
70 
72  if (linkToPackedPF_)
73  iEvent.getByToken(pf2pc_, pf2pc);
74 
76  if (linkToLostTracks_)
77  iEvent.getByToken(trk2lost_, trk2lost);
78 
79  auto out = std::make_unique<std::vector<pat::Tau>>();
80  out->reserve(src->size());
81 
82  if (modifyTau_) {
83  tauModifier_->setEvent(iEvent);
84  }
85 
86  for (View<pat::Tau>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
87  out->push_back(*it);
88  pat::Tau &tau = out->back();
89 
90  if (modifyTau_) {
91  tauModifier_->modify(tau);
92  }
93 
94  // clearing the pat isolation which is not used by taus
95  tau.isolations_.clear();
96  tau.isoDeposits_.clear();
97 
98  if (linkToPackedPF_) {
99  reco::CandidatePtrVector signalChHPtrs, signalNHPtrs, signalGammaPtrs, isolationChHPtrs, isolationNHPtrs,
100  isolationGammaPtrs;
101 
102  for (const reco::PFCandidatePtr &p : tau.signalPFChargedHadrCands()) {
103  signalChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
104  }
105  tau.setSignalChargedHadrCands(signalChHPtrs);
106 
107  for (const reco::PFCandidatePtr &p : tau.signalPFNeutrHadrCands()) {
108  signalNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
109  }
110  tau.setSignalNeutralHadrCands(signalNHPtrs);
111 
112  for (const reco::PFCandidatePtr &p : tau.signalPFGammaCands()) {
113  signalGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
114  }
115  tau.setSignalGammaCands(signalGammaPtrs);
116 
117  for (const reco::PFCandidatePtr &p : tau.isolationPFChargedHadrCands()) {
118  isolationChHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
119  }
120  tau.setIsolationChargedHadrCands(isolationChHPtrs);
121 
122  for (const reco::PFCandidatePtr &p : tau.isolationPFNeutrHadrCands()) {
123  isolationNHPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
124  }
125  tau.setIsolationNeutralHadrCands(isolationNHPtrs);
126 
127  for (const reco::PFCandidatePtr &p : tau.isolationPFGammaCands()) {
128  isolationGammaPtrs.push_back(edm::refToPtr((*pf2pc)[p]));
129  }
130  tau.setIsolationGammaCands(isolationGammaPtrs);
131  }
132  if (linkToLostTracks_ && !tau.signalTracks().empty()) {
133  std::vector<reco::CandidatePtr> signalLostTracks;
134  for (const auto &trkRef : tau.signalTracks()) {
135  const auto &lostCandRef = (*trk2lost)[edm::refToPtr(trkRef)];
136  if (lostCandRef.isNonnull())
137  signalLostTracks.push_back(edm::refToPtr(lostCandRef));
138  }
139  tau.setSignalLostTracks(signalLostTracks);
140  }
141 
142  if (dropPiZeroRefs_) {
143  tau.pfSpecific_[0].signalPiZeroCandidates_.clear();
144  tau.pfSpecific_[0].isolationPiZeroCandidates_.clear();
145  }
146  if (dropTauChargedHadronRefs_) {
147  tau.pfSpecific_[0].signalTauChargedHadronCandidates_.clear();
148  tau.pfSpecific_[0].isolationTauChargedHadronCandidates_.clear();
149  }
150  if (dropPFSpecific_) {
151  tau.pfSpecific_.clear();
152  }
153  }
154 
155  iEvent.put(std::move(out));
156 }
157 
159 using namespace pat;
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
const bool linkToLostTracks_
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
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:152
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
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > trk2lost_
PATTauSlimmer(const edm::ParameterSet &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Analysis-level tau class.
Definition: Tau.h:53
Definition: Tau.py:1
const bool modifyTau_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
const bool dropTauChargedHadronRefs_
const bool linkToPackedPF_
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< pat::ObjectModifier< pat::Tau > > tauModifier_