CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  virtual ~PATJetSlimmer() { }
30 
31  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
32  virtual void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override final;
33 
34  private:
35  edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>> pf2pc_;
36  edm::EDGetTokenT<edm::ValueMap<reco::CandidatePtr>> pf2pcAny_;
37  const edm::EDGetTokenT<edm::View<pat::Jet> > jets_;
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  }
66  if( modifyJet_ ) {
67  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
68  jetModifier_.reset(new pat::ObjectModifier<pat::Jet>(mod_config) );
69  jetModifier_->setConsumes(sumes);
70  } else {
71  jetModifier_.reset(nullptr);
72  }
73  produces<std::vector<pat::Jet> >();
74 }
75 
76 void
78  if( modifyJet_ ) jetModifier_->setEventContent(iSetup);
79 }
80 
81 void
83  using namespace edm;
84  using namespace std;
85 
87  iEvent.getByToken(jets_, src);
90  if (mayNeedDaughterMap_) {
91  if (mixedDaughters_) {
92  iEvent.getByToken(pf2pcAny_,pf2pcAny);
93  } else {
94  iEvent.getByToken(pf2pc_,pf2pc);
95  }
96  }
97 
98  auto_ptr<vector<pat::Jet> > out(new vector<pat::Jet>());
99  out->reserve(src->size());
100 
101  if( modifyJet_ ) { jetModifier_->setEvent(iEvent); }
102 
103  for (edm::View<pat::Jet>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
104  out->push_back(*it);
105  pat::Jet & jet = out->back();
106 
107  if( modifyJet_ ) { jetModifier_->modify(jet); }
108 
109  if(dropTagInfos_(*it)){
110  jet.tagInfoLabels_.clear();
111  jet.tagInfos_.clear();
112  jet.tagInfosFwdPtr_.clear();
113  }
114  if (dropJetVars_(*it)) {
115  // jet.setJetArea(0);
116  jet.setNPasses(0);
117  // jet.setPileup(0);
118  }
119  if(dropTrackRefs_(*it))
120  {
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
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  {
144  // jet.addDaughter(refToPtr((*pf2pc)[old[i]]));
145  ptrs[((*pf2pc)[old[i]]).key()]=refToPtr((*pf2pc)[old[i]]);
146  }
147  for(std::map<unsigned int,reco::CandidatePtr>::iterator itp=ptrs.begin();itp!=ptrs.end();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(out);
165 }
166 
168 using namespace pat;
std::unique_ptr< pat::ObjectModifier< pat::Jet > > jetModifier_
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const StringCutObjectSelector< pat::Jet > dropDaughters_
CaloTowerFwdPtrVector caloTowersFwdPtr_
Definition: Jet.h:522
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:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TagInfoFwdPtrCollection tagInfosFwdPtr_
Definition: Jet.h:562
std::vector< pat::PackedCandidate > PackedCandidateCollection
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
const StringCutObjectSelector< pat::Jet > dropTrackRefs_
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) overridefinal
edm::EDGetTokenT< edm::ValueMap< reco::CandidatePtr > > pf2pcAny_
const bool mayNeedDaughterMap_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< PFSpecific > specificPF_
Definition: Jet.h:574
const bool modifyJet_
edm::OwnVector< reco::BaseTagInfo > tagInfos_
Definition: Jet.h:561
int iEvent
Definition: GenABIO.cc:230
std::vector< CaloSpecific > specificCalo_
Definition: Jet.h:572
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void clear()
Definition: OwnVector.h:451
const StringCutObjectSelector< pat::Jet > dropSpecific_
const StringCutObjectSelector< pat::Jet > dropTagInfos_
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::vector< std::string > tagInfoLabels_
Definition: Jet.h:560
std::vector< CandidatePtr > daughters
collection of references to daughters
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
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
string const
Definition: compareJSON.py:14
Analysis-level calorimeter jet class.
Definition: Jet.h:78
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
PATJetSlimmer(const edm::ParameterSet &iConfig)
void clearDaughters()
clear daughter references
const StringCutObjectSelector< pat::Jet > dropJetVars_
virtual void setNPasses(int fPasses)
Set number of passes taken by algorithm.
Definition: Jet.h:113
reco::PFCandidateFwdPtrVector pfCandidatesFwdPtr_
Definition: Jet.h:528
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
const bool mixedDaughters_
const daughters & daughterPtrVector() const
references to daughtes
void addDaughter(const CandidatePtr &)
add a daughter via a reference
Matcher of reconstructed objects to L1 Muons.
virtual ~PATJetSlimmer()