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;
33 
34  private:
41  std::unique_ptr<pat::ObjectModifier<pat::Jet>> jetModifier_;
42  };
43 
44 } // namespace pat
45 
47  : jets_(consumes<edm::View<pat::Jet>>(iConfig.getParameter<edm::InputTag>("src"))),
48  dropJetVars_(iConfig.getParameter<std::string>("dropJetVars")),
49  dropDaughters_(iConfig.getParameter<std::string>("dropDaughters")),
50  rekeyDaughters_(iConfig.getParameter<std::string>("rekeyDaughters")),
51  dropTrackRefs_(iConfig.getParameter<std::string>("dropTrackRefs")),
52  dropSpecific_(iConfig.getParameter<std::string>("dropSpecific")),
53  dropTagInfos_(iConfig.getParameter<std::string>("dropTagInfos")),
54  modifyJet_(iConfig.getParameter<bool>("modifyJets")),
55  mayNeedDaughterMap_(iConfig.getParameter<std::string>("dropDaughters") != "1" &&
56  iConfig.getParameter<std::string>("rekeyDaughters") != "0"),
57  mixedDaughters_(iConfig.getParameter<bool>("mixedDaughters")) {
58  if (mayNeedDaughterMap_) {
59  if (mixedDaughters_) {
60  pf2pcAny_ =
61  consumes<edm::ValueMap<reco::CandidatePtr>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
62  } else {
63  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(
64  iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
65  }
66  }
67  if (modifyJet_) {
68  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
69  jetModifier_ = std::make_unique<pat::ObjectModifier<pat::Jet>>(mod_config, consumesCollector());
70  }
71  produces<std::vector<pat::Jet>>();
72 }
73 
75  if (modifyJet_)
76  jetModifier_->setEventContent(iSetup);
77 }
78 
80  using namespace edm;
81  using namespace std;
82 
84  iEvent.getByToken(jets_, src);
87  if (mayNeedDaughterMap_) {
88  if (mixedDaughters_) {
89  iEvent.getByToken(pf2pcAny_, pf2pcAny);
90  } else {
91  iEvent.getByToken(pf2pc_, pf2pc);
92  }
93  }
94 
95  auto out = std::make_unique<std::vector<pat::Jet>>();
96  out->reserve(src->size());
97 
98  if (modifyJet_) {
99  jetModifier_->setEvent(iEvent);
100  }
101 
102  for (edm::View<pat::Jet>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
103  out->push_back(*it);
104  pat::Jet& jet = out->back();
105 
106  if (modifyJet_) {
107  jetModifier_->modify(jet);
108  }
109 
110  if (dropTagInfos_(*it)) {
111  jet.tagInfoLabels_.clear();
112  jet.tagInfos_.clear();
113  jet.tagInfosFwdPtr_.clear();
114  }
115  if (dropJetVars_(*it)) {
116  // jet.setJetArea(0);
117  jet.setNPasses(0);
118  // jet.setPileup(0);
119  }
120  if (dropTrackRefs_(*it)) {
121  jet.setAssociatedTracks(reco::TrackRefVector());
122  }
123  if (dropDaughters_(*it)) {
124  jet.clearDaughters();
125  jet.pfCandidatesFwdPtr_.clear();
126  jet.caloTowersFwdPtr_.clear();
127  } else if (rekeyDaughters_(*it)) { //rekey
128  //copy old
129  reco::CompositePtrCandidate::daughters old = jet.daughterPtrVector();
130  jet.clearDaughters();
131  if (mixedDaughters_) {
132  std::vector<reco::CandidatePtr> ptrs;
133  for (const reco::CandidatePtr& oldptr : old) {
134  ptrs.push_back((*pf2pcAny)[oldptr]);
135  }
136  std::sort(ptrs.begin(), ptrs.end());
137  for (const reco::CandidatePtr& newptr : ptrs) {
138  jet.addDaughter(newptr);
139  }
140  } else {
141  std::map<unsigned int, reco::CandidatePtr> ptrs;
142  for (unsigned int i = 0; i < old.size(); i++) {
143  // jet.addDaughter(refToPtr((*pf2pc)[old[i]]));
144  ptrs[((*pf2pc)[old[i]]).key()] = refToPtr((*pf2pc)[old[i]]);
145  }
146  for (std::map<unsigned int, reco::CandidatePtr>::iterator itp = ptrs.begin(); itp != ptrs.end();
147  itp++) //iterate on sorted items
148  {
149  jet.addDaughter(itp->second);
150  }
151  }
152  }
153  if (dropSpecific_(*it)) {
154  // FIXME add method in pat::Jet
155  jet.specificCalo_.clear();
156  jet.specificPF_.clear();
157  }
158  // if (dropJetCorrFactors_(*it)) {
159  // // FIXME add method in pat::Jet
160  // jet.jetEnergyCorrections_.clear();
161  // }
162  }
163 
164  iEvent.put(std::move(out));
165 }
166 
168 using namespace pat;
pat::PATJetSlimmer
Matcher of reconstructed objects to L1 Muons.
Definition: PATJetSlimmer.cc:26
ObjectModifier.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
StringCutObjectSelector.h
sistrip::View
View
Definition: ConstantsForView.h:26
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
pat::PATJetSlimmer::mayNeedDaughterMap_
const bool mayNeedDaughterMap_
Definition: PATJetSlimmer.cc:40
edm::EDGetTokenT
Definition: EDGetToken.h:33
pat::PATJetSlimmer::jets_
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
Definition: PATJetSlimmer.cc:37
edm
HLT enums.
Definition: AlignableModifier.h:19
EDProducer.h
edm::RefVector< TrackCollection >
edm::Handle
Definition: AssociativeIterator.h:50
pat::PATJetSlimmer::pf2pcAny_
edm::EDGetTokenT< edm::ValueMap< reco::CandidatePtr > > pf2pcAny_
Definition: PATJetSlimmer.cc:36
CandidateFwd.h
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
pat::Jet
Analysis-level calorimeter jet class.
Definition: Jet.h:77
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Jet
Definition: Jet.py:1
pat::PATJetSlimmer::dropSpecific_
const StringCutObjectSelector< pat::Jet > dropSpecific_
Definition: PATJetSlimmer.cc:38
pat::PATJetSlimmer::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
Definition: PATJetSlimmer.cc:74
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
pat::PATJetSlimmer::~PATJetSlimmer
~PATJetSlimmer() override
Definition: PATJetSlimmer.cc:29
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
pat::PATJetSlimmer::pf2pc_
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
Definition: PATJetSlimmer.cc:35
Event.h
PackedCandidate.h
iEvent
int iEvent
Definition: GenABIO.cc:224
RefToPtr.h
edm::stream::EDProducer
Definition: EDProducer.h:38
pat::PATJetSlimmer::dropJetVars_
const StringCutObjectSelector< pat::Jet > dropJetVars_
Definition: PATJetSlimmer.cc:38
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
Jet.h
reco::CompositePtrCandidate::daughters
std::vector< CandidatePtr > daughters
collection of references to daughters
Definition: CompositePtrCandidate.h:20
edm::Ptr< Candidate >
pat::PATJetSlimmer::dropTagInfos_
const StringCutObjectSelector< pat::Jet > dropTagInfos_
Definition: PATJetSlimmer.cc:38
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
pat::PATJetSlimmer::mixedDaughters_
const bool mixedDaughters_
Definition: PATJetSlimmer.cc:40
Frameworkfwd.h
metsig::jet
Definition: SignAlgoResolutions.h:47
pat::PATJetSlimmer::PATJetSlimmer
PATJetSlimmer(const edm::ParameterSet &iConfig)
Definition: PATJetSlimmer.cc:46
pat::PATJetSlimmer::modifyJet_
const bool modifyJet_
Definition: PATJetSlimmer.cc:40
StringCutObjectSelector< pat::Jet >
pat::PATJetSlimmer::jetModifier_
std::unique_ptr< pat::ObjectModifier< pat::Jet > > jetModifier_
Definition: PATJetSlimmer.cc:41
pat::PATJetSlimmer::dropDaughters_
const StringCutObjectSelector< pat::Jet > dropDaughters_
Definition: PATJetSlimmer.cc:38
pat::PATJetSlimmer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATJetSlimmer.cc:79
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
crabWrapper.key
key
Definition: crabWrapper.py:19
pat::PATJetSlimmer::dropTrackRefs_
const StringCutObjectSelector< pat::Jet > dropTrackRefs_
Definition: PATJetSlimmer.cc:38
edm::InputTag
Definition: InputTag.h:15
pat::PATJetSlimmer::rekeyDaughters_
const StringCutObjectSelector< pat::Jet > rekeyDaughters_
Definition: PATJetSlimmer.cc:38