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:
40  std::unique_ptr<pat::ObjectModifier<pat::Jet> > jetModifier_;
41  };
42 
43 } // namespace
44 
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" && iConfig.getParameter<std::string>("rekeyDaughters") != "0"),
56  mixedDaughters_(iConfig.getParameter<bool>("mixedDaughters"))
57 {
58  if (mayNeedDaughterMap_) {
59  if (mixedDaughters_) {
60  pf2pcAny_ = consumes<edm::ValueMap<reco::CandidatePtr> >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
61  } else {
62  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
63  }
64  }
65  if( modifyJet_ ) {
66  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
67  jetModifier_ = std::make_unique<pat::ObjectModifier<pat::Jet>>(mod_config, consumesCollector());
68  }
69  produces<std::vector<pat::Jet> >();
70 }
71 
72 void
74  if( modifyJet_ ) jetModifier_->setEventContent(iSetup);
75 }
76 
77 void
79  using namespace edm;
80  using namespace std;
81 
83  iEvent.getByToken(jets_, src);
86  if (mayNeedDaughterMap_) {
87  if (mixedDaughters_) {
88  iEvent.getByToken(pf2pcAny_,pf2pcAny);
89  } else {
90  iEvent.getByToken(pf2pc_,pf2pc);
91  }
92  }
93 
94  auto out = std::make_unique<std::vector<pat::Jet>>();
95  out->reserve(src->size());
96 
97  if( modifyJet_ ) { jetModifier_->setEvent(iEvent); }
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_ ) { jetModifier_->modify(jet); }
104 
105  if(dropTagInfos_(*it)){
106  jet.tagInfoLabels_.clear();
107  jet.tagInfos_.clear();
108  jet.tagInfosFwdPtr_.clear();
109  }
110  if (dropJetVars_(*it)) {
111  // jet.setJetArea(0);
112  jet.setNPasses(0);
113  // jet.setPileup(0);
114  }
115  if(dropTrackRefs_(*it))
116  {
118  }
119  if (dropDaughters_(*it)) {
120  jet.clearDaughters();
121  jet.pfCandidatesFwdPtr_.clear();
122  jet.caloTowersFwdPtr_.clear();
123  } else if (rekeyDaughters_(*it)) { //rekey
124  //copy old
126  jet.clearDaughters();
127  if (mixedDaughters_) {
128  std::vector<reco::CandidatePtr> ptrs;
129  for(const reco::CandidatePtr &oldptr : old) {
130  ptrs.push_back( (*pf2pcAny)[oldptr] );
131  }
132  std::sort(ptrs.begin(), ptrs.end());
133  for(const reco::CandidatePtr &newptr : ptrs) {
134  jet.addDaughter(newptr);
135  }
136  } else {
137  std::map<unsigned int,reco::CandidatePtr> ptrs;
138  for(unsigned int i=0;i<old.size();i++)
139  {
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();itp++) //iterate on sorted items
144  {
145  jet.addDaughter(itp->second);
146  }
147  }
148  }
149  if (dropSpecific_(*it)) {
150  // FIXME add method in pat::Jet
151  jet.specificCalo_.clear();
152  jet.specificPF_.clear();
153  }
154  // if (dropJetCorrFactors_(*it)) {
155  // // FIXME add method in pat::Jet
156  // jet.jetEnergyCorrections_.clear();
157  // }
158  }
159 
160  iEvent.put(std::move(out));
161 }
162 
164 using namespace pat;
std::unique_ptr< pat::ObjectModifier< pat::Jet > > jetModifier_
T getParameter(std::string const &) const
const StringCutObjectSelector< pat::Jet > dropDaughters_
~PATJetSlimmer() override
CaloTowerFwdPtrVector caloTowersFwdPtr_
Definition: Jet.h:554
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
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:517
TagInfoFwdPtrCollection tagInfosFwdPtr_
Definition: Jet.h:595
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
std::vector< PFSpecific > specificPF_
Definition: Jet.h:607
const bool modifyJet_
edm::OwnVector< reco::BaseTagInfo > tagInfos_
Definition: Jet.h:594
int iEvent
Definition: GenABIO.cc:224
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< CaloSpecific > specificCalo_
Definition: Jet.h:605
Definition: Jet.py:1
void clearDaughters() override
clear daughter references
Definition: Jet.h:459
void clear()
Definition: OwnVector.h:445
const StringCutObjectSelector< pat::Jet > dropSpecific_
const StringCutObjectSelector< pat::Jet > dropTagInfos_
std::vector< std::string > tagInfoLabels_
Definition: Jet.h:593
std::vector< CandidatePtr > daughters
collection of references to daughters
const StringCutObjectSelector< pat::Jet > rekeyDaughters_
void setAssociatedTracks(const reco::TrackRefVector &tracks)
method to set the vector of refs to the tracks associated to this jet
Analysis-level calorimeter jet class.
Definition: Jet.h:80
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
PATJetSlimmer(const edm::ParameterSet &iConfig)
const StringCutObjectSelector< pat::Jet > dropJetVars_
virtual void setNPasses(int fPasses)
Set number of passes taken by algorithm.
Definition: Jet.h:113
HLT enums.
reco::PFCandidateFwdPtrVector pfCandidatesFwdPtr_
Definition: Jet.h:560
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
const bool mixedDaughters_
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void addDaughter(const CandidatePtr &)
add a daughter via a reference
const reco::CompositePtrCandidate::daughters & daughterPtrVector() const override
references to daughtes
def move(src, dest)
Definition: eostools.py:511
Matcher of reconstructed objects to L1 Muons.