CMS 3D CMS Logo

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 
12 #include <vector>
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 
46 
48  src_(consumes<edm::View<reco::GenJet> >(iConfig.getParameter<edm::InputTag>("src"))),
49  gp2pgp_(consumes<edm::Association<std::vector<pat::PackedGenParticle> > >(iConfig.getParameter<edm::InputTag>("packedGenParticles"))),
50  cut_(iConfig.getParameter<std::string>("cut")),
51  clearDaughters_(iConfig.getParameter<bool>("clearDaughters")),
52  dropSpecific_(iConfig.getParameter<bool>("dropSpecific"))
53 {
54  produces<std::vector<reco::GenJet> >();
55  produces< edm::Association<std::vector<reco::GenJet> > >("slimmedGenJetAssociation");
56 }
57 
58 void
60  using namespace edm;
61  using namespace std;
62 
64  iEvent.getByToken(src_, src);
65 
66  auto out = std::make_unique<vector<reco::GenJet> >();
67  out->reserve(src->size());
68 
70  iEvent.getByToken(gp2pgp_,gp2pgp);
71 
72  auto genJetSlimmedGenJetAssociation = make_unique< edm::Association<std::vector<reco::GenJet> > > ();
73 
74  auto mapping = std::make_unique<std::vector<int> >();
75  mapping->reserve(src->size());
76 
77  for (View<reco::GenJet>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
78  if (!cut_(*it)) {
79  mapping->push_back(-1);
80  continue;
81  }
82 
83  out->push_back(*it);
84  reco::GenJet & jet = out->back();
85 
86  mapping->push_back(it-src->begin());
87 
88 
89  if (clearDaughters_) {
90  jet.clearDaughters();
91  }
92  else // rekey
93  {
94  //copy old
96  jet.clearDaughters();
97  std::map<unsigned int,reco::CandidatePtr> ptrs;
98  for(unsigned int i=0;i<old.size();i++)
99  {
100 // if(! ((*gp2pgp)[old[i]]).isNonnull()) {
101 // 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;
102 // }
103  ptrs[((*gp2pgp)[old[i]]).key()]=refToPtr((*gp2pgp)[old[i]]);
104  }
105  for(std::map<unsigned int,reco::CandidatePtr>::iterator itp=ptrs.begin();itp!=ptrs.end();itp++) //iterate on sorted items
106  {
107  jet.addDaughter(itp->second);
108  }
109 
110 
111  }
112  if (dropSpecific_) {
114  }
115 
116  }
117 
119 
120  auto asso = std::make_unique<edm::Association<std::vector<reco::GenJet> > >(orphanHandle);
121  edm::Association< std::vector<reco::GenJet> >::Filler slimmedAssoFiller(*asso);
122  slimmedAssoFiller.insert(src, mapping->begin(), mapping->end());
123  slimmedAssoFiller.fill();
124 
125 
126  iEvent.put(std::move(asso),"slimmedGenJetAssociation");
127 }
128 
130 using namespace pat;
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
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:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
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.
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
std::vector< CandidatePtr > daughters
collection of references to daughters
const edm::EDGetTokenT< edm::View< reco::GenJet > > src_
void clearDaughters()
clear daughter references
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
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
def move(src, dest)
Definition: eostools.py:510
PATGenJetSlimmer(const edm::ParameterSet &iConfig)