CMS 3D CMS Logo

HLTJetCollectionsForBoostedLeptonPlusJets.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
4 #include "TVector3.h"
5 
20 
21 template <typename jetType>
23  const edm::ParameterSet& iConfig)
24  : hltLeptonTag(iConfig.getParameter<edm::InputTag>("HltLeptonTag")),
25  sourceJetTag(iConfig.getParameter<edm::InputTag>("SourceJetTag")),
26  minDeltaR_(iConfig.getParameter<double>("minDeltaR")) {
27  using namespace edm;
28  using namespace std;
29 
30  typedef vector<RefVector<vector<jetType>, jetType, refhelper::FindUsingAdvance<vector<jetType>, jetType>>>
31  JetCollectionVector;
32  typedef vector<jetType> JetCollection;
33 
34  m_theLeptonToken = consumes<trigger::TriggerFilterObjectWithRefs>(hltLeptonTag);
35  m_theJetToken = consumes<std::vector<jetType>>(sourceJetTag);
36  produces<JetCollectionVector>();
37  produces<JetCollection>();
38 }
39 
40 template <typename jetType>
42  // do anything here that needs to be done at desctruction time
43  // (e.g. close files, deallocate resources etc.)
44 }
45 
46 template <typename jetType>
49  desc.add<edm::InputTag>("HltLeptonTag", edm::InputTag("triggerFilterObjectWithRefs"));
50  //(2)
51  desc.add<edm::InputTag>("SourceJetTag", edm::InputTag("jetCollection"));
52  //(2)
53  desc.add<double>("minDeltaR", 0.5);
55 }
56 
57 //
58 // member functions
59 //
60 
61 // ------------ method called to produce the data ------------
62 // template <typename T>
63 template <typename jetType>
65  using namespace edm;
66  using namespace std;
67  //(3)
68  using namespace reco;
69  //(3)
70  typedef vector<RefVector<vector<jetType>, jetType, refhelper::FindUsingAdvance<vector<jetType>, jetType>>>
71  JetCollectionVector;
72  typedef vector<jetType> JetCollection;
75 
77  iEvent.getByToken(m_theLeptonToken, PrevFilterOutput);
78 
79  //its easier on the if statement flow if I try everything at once, shouldnt add to timing
80  // Electrons can be stored as objects of types TriggerCluster, TriggerElectron, or TriggerPhoton
81  vector<reco::RecoChargedCandidateRef> muonCands;
82  PrevFilterOutput->getObjects(trigger::TriggerMuon, muonCands);
83 
84  vector<Ref<reco::ElectronCollection>> eleCands;
85  PrevFilterOutput->getObjects(trigger::TriggerElectron, eleCands);
86 
87  trigger::VRphoton photonCands;
88  PrevFilterOutput->getObjects(trigger::TriggerPhoton, photonCands);
89 
90  vector<Ref<reco::RecoEcalCandidateCollection>> clusCands;
91  PrevFilterOutput->getObjects(trigger::TriggerCluster, clusCands);
92 
93  Handle<JetCollection> theJetCollectionHandle;
94  iEvent.getByToken(m_theJetToken, theJetCollectionHandle);
95 
96  typename JetCollection::const_iterator jet;
97 
98  unique_ptr<JetCollection> allSelections(new JetCollection);
99  unique_ptr<JetCollectionVector> product(new JetCollectionVector);
100 
101  std::vector<size_t> usedCands;
102 
103  if (!muonCands.empty()) { // muons
104  for (jet = theJetCollectionHandle->begin(); jet != theJetCollectionHandle->end(); jet++) {
105  //const jetType* referenceJet = &*jet;
106  jetType cleanedJet = *jet; //copy original jet
107  for (size_t candNr = 0; candNr < muonCands.size(); candNr++) {
108  if (std::find(usedCands.begin(), usedCands.end(), candNr) != usedCands.end())
109  continue;
110  if (deltaR((*muonCands[candNr]), cleanedJet) <= minDeltaR_) {
111  std::vector<edm::Ptr<reco::PFCandidate>> pfConstituents = cleanedJet.getPFConstituents();
112  for (std::vector<edm::Ptr<reco::PFCandidate>>::const_iterator i_candidate = pfConstituents.begin();
113  i_candidate != pfConstituents.end();
114  ++i_candidate) {
115  if (deltaR((*muonCands[candNr]), (**i_candidate)) < 0.001) {
116  cleanedJet.setP4(cleanedJet.p4() - muonCands[candNr]->p4());
117  usedCands.push_back(candNr);
118  break;
119  } //if constituent matched
120  } //for constituents
121  } //if dR<min
122  } //for cands
123  allSelections->push_back(cleanedJet);
124  } //for jets
125  } //if cands
126 
127  if (!eleCands.empty()) { // electrons
128  for (jet = theJetCollectionHandle->begin(); jet != theJetCollectionHandle->end(); jet++) {
129  //const jetType* referenceJet = &*jet;
130  jetType cleanedJet = *jet; //copy original jet
131  for (size_t candNr = 0; candNr < eleCands.size(); candNr++) {
132  if (std::find(usedCands.begin(), usedCands.end(), candNr) != usedCands.end())
133  continue;
134  if (deltaR((*eleCands[candNr]), cleanedJet) <= minDeltaR_) {
135  std::vector<edm::Ptr<reco::PFCandidate>> pfConstituents = cleanedJet.getPFConstituents();
136  for (std::vector<edm::Ptr<reco::PFCandidate>>::const_iterator i_candidate = pfConstituents.begin();
137  i_candidate != pfConstituents.end();
138  ++i_candidate) {
139  if (deltaR((*eleCands[candNr]), (**i_candidate)) < 0.001) {
140  cleanedJet.setP4(cleanedJet.p4() - eleCands[candNr]->p4());
141  usedCands.push_back(candNr);
142  break;
143  } //if constituent matched
144  } //for constituents
145  } //if dR<min
146  } //for cands
147  allSelections->push_back(cleanedJet);
148  } //for jets
149  } //if cands
150 
151  if (!photonCands.empty()) { // photons
152  for (jet = theJetCollectionHandle->begin(); jet != theJetCollectionHandle->end(); jet++) {
153  //const jetType* referenceJet = &*jet;
154  jetType cleanedJet = *jet; //copy original jet
155  for (size_t candNr = 0; candNr < photonCands.size(); candNr++) {
156  if (std::find(usedCands.begin(), usedCands.end(), candNr) != usedCands.end())
157  continue;
158  if (deltaR((*photonCands[candNr]), cleanedJet) <= minDeltaR_) {
159  std::vector<edm::Ptr<reco::PFCandidate>> pfConstituents = cleanedJet.getPFConstituents();
160  for (std::vector<edm::Ptr<reco::PFCandidate>>::const_iterator i_candidate = pfConstituents.begin();
161  i_candidate != pfConstituents.end();
162  ++i_candidate) {
163  if (deltaR((*photonCands[candNr]), (**i_candidate)) < 0.001) {
164  cleanedJet.setP4(cleanedJet.p4() - photonCands[candNr]->p4());
165  usedCands.push_back(candNr);
166  break;
167  } //if constituent matched
168  } //for constituents
169  } //if dR<min
170  } //for cands
171  allSelections->push_back(cleanedJet);
172  } //for jets
173  } //if cands
174 
175  if (!clusCands.empty()) { // trigger clusters
176  for (jet = theJetCollectionHandle->begin(); jet != theJetCollectionHandle->end(); jet++) {
177  //const jetType* referenceJet = &*jet;
178  jetType cleanedJet = *jet; //copy original jet
179  for (size_t candNr = 0; candNr < clusCands.size(); candNr++) {
180  if (std::find(usedCands.begin(), usedCands.end(), candNr) != usedCands.end())
181  continue;
182  if (deltaR((*clusCands[candNr]), cleanedJet) <= minDeltaR_) {
183  std::vector<edm::Ptr<reco::PFCandidate>> pfConstituents = cleanedJet.getPFConstituents();
184  for (std::vector<edm::Ptr<reco::PFCandidate>>::const_iterator i_candidate = pfConstituents.begin();
185  i_candidate != pfConstituents.end();
186  ++i_candidate) {
187  if (deltaR((*clusCands[candNr]), (**i_candidate)) < 0.001) {
188  cleanedJet.setP4(cleanedJet.p4() - clusCands[candNr]->p4());
189  usedCands.push_back(candNr);
190  break;
191  } //if constituent matched
192  } //for constituents
193  } //if dR<min
194  } //for cands
195  allSelections->push_back(cleanedJet);
196  } //for jets
197  } //if cands
198 
200  // reorder cleaned jets
201  std::sort(allSelections->begin(), allSelections->end(), compJets);
202  edm::OrphanHandle<JetCollection> cleanedJetHandle = iEvent.put(std::move(allSelections));
203 
204  JetCollection const& jets = *cleanedJetHandle;
205 
206  JetRefVector cleanedJetRefs;
207 
208  for (unsigned iJet = 0; iJet < jets.size(); ++iJet) {
209  cleanedJetRefs.push_back(JetRef(cleanedJetHandle, iJet));
210  }
211 
212  product->emplace_back(cleanedJetRefs);
213  iEvent.put(std::move(product));
214 
215  return;
216 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
std::vector< Jet > JetCollection
Definition: Jet.h:53
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::Ref< JetBxCollection > JetRef
Definition: Jet.h:12
edm::EDGetTokenT< std::vector< jetType > > m_theJetToken
std::string defaultModuleLabel()
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > m_theLeptonToken
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::RefVector< JetBxCollection > JetRefVector
Definition: Jet.h:13
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
std::vector< reco::RecoEcalCandidateRef > VRphoton
def move(src, dest)
Definition: eostools.py:511
void produce(edm::Event &, const edm::EventSetup &) override