CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauJetRegionProducer.cc
Go to the documentation of this file.
1 /*
2  * RecoTauJetRegionProducer
3  *
4  * Given a set of PFJets, make new jets with the same p4 but collect all the
5  * PFCandidates from a cone of a given size into the constituents.
6  *
7  * Author: Evan K. Friis, UC Davis
8  *
9  */
10 
11 #include <boost/bind.hpp>
12 
15 
18 
25 
27  public:
29  explicit RecoTauJetRegionProducer(const edm::ParameterSet& pset);
31  void produce(edm::Event& evt, const edm::EventSetup& es);
32  private:
33  float deltaR2_;
36 };
37 
39  const edm::ParameterSet& pset) {
40  deltaR2_ = pset.getParameter<double>("deltaR"); deltaR2_*=deltaR2_;
41  inputJets_ = pset.getParameter<edm::InputTag>("src");
42  pfSrc_ = pset.getParameter<edm::InputTag>("pfSrc");
43  produces<reco::PFJetCollection>("jets");
44  produces<PFJetMatchMap>();
45 }
46 
48  const edm::EventSetup& es) {
49 
51  evt.getByLabel(pfSrc_, pfCandsHandle);
52 
53  // Build Ptrs for all the PFCandidates
54  typedef edm::Ptr<reco::PFCandidate> PFCandPtr;
55  std::vector<PFCandPtr> pfCands;
56  pfCands.reserve(pfCandsHandle->size());
57  for (size_t icand = 0; icand < pfCandsHandle->size(); ++icand) {
58  pfCands.push_back(PFCandPtr(pfCandsHandle, icand));
59  }
60 
61  // Get the jets
63  evt.getByLabel(inputJets_, jetView);
64  // Convert to a vector of PFJetRefs
66  reco::tau::castView<reco::PFJetRefVector>(jetView);
67  size_t nJets = jets.size();
68 
69  // Get the original product, so we can match against it - otherwise the
70  // indices don't match up.
71  edm::ProductID originalId = jets.id();
73  size_t nOriginalJets = 0;
74  // We have to make sure that we have some selected jets, otherwise we don't
75  // actually have a valid product ID to the original jets.
76  if (nJets) {
77  try {
78  evt.get(originalId, originalJets);
79  } catch(const cms::Exception &e) {
80  edm::LogError("MissingOriginalCollection")
81  << "Can't get the original jets that made: " << inputJets_
82  << " that have product ID: " << originalId
83  << " from the event!!";
84  throw e;
85  }
86  nOriginalJets = originalJets->size();
87  }
88 
89  std::auto_ptr<reco::PFJetCollection> newJets(new reco::PFJetCollection);
90 
91  // Keep track of the indices of the current jet and the old (original) jet
92  // -1 indicats no match.
93  std::vector<int> matchInfo(nOriginalJets, -1);
94  newJets->reserve(nJets);
95  for (size_t ijet = 0; ijet < nJets; ++ijet) {
96  // Get a ref to jet
97  reco::PFJetRef jetRef = jets[ijet];
98  // Make an initial copy.
99  newJets->emplace_back(*jetRef);
100  reco::PFJet & newJet = newJets->back();
101  // Clear out all the constituents
102  newJet.clearDaughters();
103  // Loop over all the PFCands
104  for ( auto cand : pfCands )
105  if ( reco::deltaR2(*jetRef,*cand)<deltaR2_ ) newJet.addDaughter(cand);
106  // Match the index of the jet we just made to the index into the original
107  // collection.
108  matchInfo[jetRef.key()] = ijet;
109  }
110 
111  // Put our new jets into the event
113  evt.put(newJets, "jets");
114 
115  // Create a matching between original jets -> extra collection
116  std::auto_ptr<PFJetMatchMap> matching(new PFJetMatchMap(newJetsInEvent));
117  if (nJets) {
118  PFJetMatchMap::Filler filler(*matching);
119  filler.insert(originalJets, matchInfo.begin(), matchInfo.end());
120  filler.fill();
121  }
122  evt.put(matching);
123 }
124 
T getParameter(std::string const &) const
RecoTauJetRegionProducer(const edm::ParameterSet &pset)
edm::Association< reco::PFJetCollection > PFJetMatchMap
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void produce(edm::Event &evt, const edm::EventSetup &es)
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
Jets made from PFObjects.
Definition: PFJet.h:22
ProductID id() const
Accessor for product ID.
Definition: RefVector.h:104
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
vector< PseudoJet > jets
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:267
double deltaR2(double eta1, double phi1, double eta2, double phi2)
Definition: deltaR.h:13
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
key_type key() const
Accessor for product key.
Definition: Ref.h:266
void clearDaughters()
clear daughter references
std::vector< PFJet > PFJetCollection
collection of PFJet objects
void addDaughter(const CandidatePtr &)
add a daughter via a reference
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89