CMS 3D CMS Logo

PATJetSlimmer.cc
Go to the documentation of this file.
1 //
2 // $Id: PATJetSlimmer.cc,v 1.1 2011/03/24 18:45:45 mwlebour Exp $
3 //
4 
20 
23 
24 namespace pat {
25 
27  public:
28  explicit PATJetSlimmer(const edm::ParameterSet& iConfig);
29  ~PATJetSlimmer() override {}
30 
31  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
32 
33  private:
40  std::unique_ptr<pat::ObjectModifier<pat::Jet>> jetModifier_;
41  };
42 
43 } // namespace pat
44 
46  : jets_(consumes<edm::View<pat::Jet>>(iConfig.getParameter<edm::InputTag>("src"))),
47  dropJetVars_(iConfig.getParameter<std::string>("dropJetVars")),
48  dropDaughters_(iConfig.getParameter<std::string>("dropDaughters")),
49  rekeyDaughters_(iConfig.getParameter<std::string>("rekeyDaughters")),
50  dropTrackRefs_(iConfig.getParameter<std::string>("dropTrackRefs")),
51  dropSpecific_(iConfig.getParameter<std::string>("dropSpecific")),
52  dropTagInfos_(iConfig.getParameter<std::string>("dropTagInfos")),
53  modifyJet_(iConfig.getParameter<bool>("modifyJets")),
54  mayNeedDaughterMap_(iConfig.getParameter<std::string>("dropDaughters") != "1" &&
55  iConfig.getParameter<std::string>("rekeyDaughters") != "0"),
56  mixedDaughters_(iConfig.getParameter<bool>("mixedDaughters")) {
57  if (mayNeedDaughterMap_) {
58  if (mixedDaughters_) {
59  pf2pcAny_ =
60  consumes<edm::ValueMap<reco::CandidatePtr>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
61  } else {
62  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(
63  iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
64  }
65  }
66  if (modifyJet_) {
67  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
68  jetModifier_ = std::make_unique<pat::ObjectModifier<pat::Jet>>(mod_config, consumesCollector());
69  }
70  produces<std::vector<pat::Jet>>();
71 }
72 
74  using namespace edm;
75  using namespace std;
76 
77  if (modifyJet_)
78  jetModifier_->setEventContent(iSetup);
79 
81  iEvent.getByToken(jets_, src);
84  if (mayNeedDaughterMap_) {
85  if (mixedDaughters_) {
86  iEvent.getByToken(pf2pcAny_, pf2pcAny);
87  } else {
88  iEvent.getByToken(pf2pc_, pf2pc);
89  }
90  }
91 
92  auto out = std::make_unique<std::vector<pat::Jet>>();
93  out->reserve(src->size());
94 
95  if (modifyJet_) {
96  jetModifier_->setEvent(iEvent);
97  }
98 
99  for (edm::View<pat::Jet>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
100  out->push_back(*it);
101  pat::Jet& jet = out->back();
102 
103  if (modifyJet_) {
104  jetModifier_->modify(jet);
105  }
106 
107  if (dropTagInfos_(*it)) {
108  jet.tagInfoLabels_.clear();
109  jet.tagInfos_.clear();
110  jet.tagInfosFwdPtr_.clear();
111  }
112  if (dropJetVars_(*it)) {
113  // jet.setJetArea(0);
114  jet.setNPasses(0);
115  // jet.setPileup(0);
116  }
117  if (dropTrackRefs_(*it)) {
118  jet.setAssociatedTracks(reco::TrackRefVector());
119  }
120  if (dropDaughters_(*it)) {
121  jet.clearDaughters();
122  jet.pfCandidatesFwdPtr_.clear();
123  jet.caloTowersFwdPtr_.clear();
124  } else if (rekeyDaughters_(*it)) { //rekey
125  //copy old
126  reco::CompositePtrCandidate::daughters old = jet.daughterPtrVector();
127  jet.clearDaughters();
128  if (mixedDaughters_) {
129  std::vector<reco::CandidatePtr> ptrs;
130  for (const reco::CandidatePtr& oldptr : old) {
131  ptrs.push_back((*pf2pcAny)[oldptr]);
132  }
133  std::sort(ptrs.begin(), ptrs.end());
134  for (const reco::CandidatePtr& newptr : ptrs) {
135  jet.addDaughter(newptr);
136  }
137  } else {
138  std::map<unsigned int, reco::CandidatePtr> ptrs;
139  for (unsigned int i = 0; i < old.size(); i++) {
140  // jet.addDaughter(refToPtr((*pf2pc)[old[i]]));
141  ptrs[((*pf2pc)[old[i]]).key()] = refToPtr((*pf2pc)[old[i]]);
142  }
143  for (std::map<unsigned int, reco::CandidatePtr>::iterator itp = ptrs.begin(); itp != ptrs.end();
144  itp++) //iterate on sorted items
145  {
146  jet.addDaughter(itp->second);
147  }
148  }
149  }
150  if (dropSpecific_(*it)) {
151  // FIXME add method in pat::Jet
152  jet.specificCalo_.clear();
153  jet.specificPF_.clear();
154  }
155  // if (dropJetCorrFactors_(*it)) {
156  // // FIXME add method in pat::Jet
157  // jet.jetEnergyCorrections_.clear();
158  // }
159  }
160 
161  iEvent.put(std::move(out));
162 }
163 
165 using namespace pat;
std::unique_ptr< pat::ObjectModifier< pat::Jet > > jetModifier_
const StringCutObjectSelector< pat::Jet > dropDaughters_
~PATJetSlimmer() override
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
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
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
const StringCutObjectSelector< pat::Jet > dropTrackRefs_
edm::EDGetTokenT< edm::ValueMap< reco::CandidatePtr > > pf2pcAny_
const bool mayNeedDaughterMap_
Definition: HeavyIon.h:7
const bool modifyJet_
int iEvent
Definition: GenABIO.cc:224
Definition: Jet.py:1
const StringCutObjectSelector< pat::Jet > dropSpecific_
const StringCutObjectSelector< pat::Jet > dropTagInfos_
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< CandidatePtr > daughters
collection of references to daughters
const StringCutObjectSelector< pat::Jet > rekeyDaughters_
Analysis-level calorimeter jet class.
Definition: Jet.h:77
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
PATJetSlimmer(const edm::ParameterSet &iConfig)
const StringCutObjectSelector< pat::Jet > dropJetVars_
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
const bool mixedDaughters_
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
def move(src, dest)
Definition: eostools.py:511
Matcher of reconstructed objects to L1 Muons.