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