CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATGenJetSlimmer.cc
Go to the documentation of this file.
1 //
2 // $Id: PATGenJetSlimmer.cc,v 1.1 2011/03/24 18:45:45 mwlebour Exp $
3 //
4 
22 
23 namespace pat {
24 
26  public:
27  explicit PATGenJetSlimmer(const edm::ParameterSet & iConfig);
28  virtual ~PATGenJetSlimmer() { }
29 
30  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
31 
32  private:
35 
37 
39  const bool clearDaughters_;
41  const bool dropSpecific_;
42  };
43 
44 } // namespace
45 
47  src_(consumes<edm::View<reco::GenJet> >(iConfig.getParameter<edm::InputTag>("src"))),
48  gp2pgp_(consumes<edm::Association<std::vector<pat::PackedGenParticle> > >(iConfig.getParameter<edm::InputTag>("packedGenParticles"))),
49  cut_(iConfig.getParameter<std::string>("cut")),
50  clearDaughters_(iConfig.getParameter<bool>("clearDaughters")),
51  dropSpecific_(iConfig.getParameter<bool>("dropSpecific"))
52 {
53  produces<std::vector<reco::GenJet> >();
54 }
55 
56 void
58  using namespace edm;
59  using namespace std;
60 
62  iEvent.getByToken(src_, src);
63 
64  auto_ptr<vector<reco::GenJet> > out(new vector<reco::GenJet>());
65  out->reserve(src->size());
66 
68  iEvent.getByToken(gp2pgp_,gp2pgp);
69 
70 
71  for (View<reco::GenJet>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
72  if (!cut_(*it)) continue;
73 
74  out->push_back(*it);
75  reco::GenJet & jet = out->back();
76 
77  if (clearDaughters_) {
78  jet.clearDaughters();
79  }
80  else // rekey
81  {
82  //copy old
84  jet.clearDaughters();
85  std::map<unsigned int,reco::CandidatePtr> ptrs;
86  for(unsigned int i=0;i<old.size();i++)
87  {
88 // if(! ((*gp2pgp)[old[i]]).isNonnull()) {
89 // std::cout << "Missing ref for key" << old[i].key() << " pdgid " << old[i]->pdgId() << " st "<< old[i]->status() << " pt " << old[i]->pt() << " eta " << old[i]->eta() << std::endl;
90 // }
91  ptrs[((*gp2pgp)[old[i]]).key()]=refToPtr((*gp2pgp)[old[i]]);
92  }
93  for(std::map<unsigned int,reco::CandidatePtr>::iterator itp=ptrs.begin();itp!=ptrs.end();itp++) //iterate on sorted items
94  {
95  jet.addDaughter(itp->second);
96  }
97 
98 
99  }
100  if (dropSpecific_) {
102  }
103  }
104 
105  iEvent.put(out);
106 }
107 
109 using namespace pat;
int i
Definition: DBlmapReader.cc:9
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:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int iEvent
Definition: GenABIO.cc:230
const bool clearDaughters_
reset daughters to an empty vector
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
Matcher of reconstructed objects to L1 Muons.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
const StringCutObjectSelector< reco::GenJet > cut_
const edm::EDGetTokenT< edm::Association< std::vector< pat::PackedGenParticle > > > gp2pgp_
const bool dropSpecific_
drop the specific
Jets made from MC generator particles.
Definition: GenJet.h:24
tuple out
Definition: dbtoconf.py:99
std::vector< CandidatePtr > daughters
collection of references to daughters
const edm::EDGetTokenT< edm::View< reco::GenJet > > src_
void clearDaughters()
clear daughter references
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
void setSpecific(const Specific &spec)
set the specific (note: responsibility of keeping it consistent with the jet daughers belongs to the ...
Definition: GenJet.h:80
const daughters & daughterPtrVector() const
references to daughtes
void addDaughter(const CandidatePtr &)
add a daughter via a reference
PATGenJetSlimmer(const edm::ParameterSet &iConfig)