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 }
defaultModuleLabel.h
HLTJetCollectionsForBoostedLeptonPlusJets::hltLeptonTag
edm::InputTag hltLeptonTag
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.h:51
Handle.h
trigger::TriggerElectron
Definition: TriggerTypeDefs.h:78
HLTJetCollectionsForBoostedLeptonPlusJets::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.cc:64
trigger::VRphoton
std::vector< reco::RecoEcalCandidateRef > VRphoton
Definition: TriggerRefsCollections.h:67
PFCandidate.h
l1t::JetRefVector
edm::RefVector< JetBxCollection > JetRefVector
Definition: Jet.h:13
edm
HLT enums.
Definition: AlignableModifier.h:19
HLTJetCollectionsForBoostedLeptonPlusJets.h
PFJet.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HLTJetCollectionsForBoostedLeptonPlusJets::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.cc:47
PtComparator.h
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
edm::RefVector
Definition: EDProductfwd.h:27
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HLTJetCollectionsForBoostedLeptonPlusJets::m_theLeptonToken
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > m_theLeptonToken
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.h:49
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle< trigger::TriggerFilterObjectWithRefs >
RecoCandidate.h
trigger::TriggerRefsCollections::getObjects
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
Definition: TriggerRefsCollections.h:590
edm::Ref
Definition: AssociativeIterator.h:58
MakerMacros.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
HLTJetCollectionsForBoostedLeptonPlusJets::m_theJetToken
edm::EDGetTokenT< std::vector< jetType > > m_theJetToken
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.h:50
NumericSafeGreaterByPt
Definition: PtComparator.h:46
pat::JetCollection
std::vector< Jet > JetCollection
Definition: Jet.h:53
trigger::TriggerMuon
Definition: TriggerTypeDefs.h:79
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLTJetCollectionsForBoostedLeptonPlusJets::HLTJetCollectionsForBoostedLeptonPlusJets
HLTJetCollectionsForBoostedLeptonPlusJets(const edm::ParameterSet &)
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.cc:22
edm::ParameterSet
Definition: ParameterSet.h:47
defaultModuleLabel
std::string defaultModuleLabel()
Definition: defaultModuleLabel.h:16
deltaR.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
trigger::TriggerCluster
Definition: TriggerTypeDefs.h:88
l1t::JetRef
edm::Ref< JetBxCollection > JetRef
Definition: Jet.h:12
edm::Ptr
Definition: AssociationVector.h:31
HLTJetCollectionsForBoostedLeptonPlusJets
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.h:40
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
Electron.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::OrphanHandle
Definition: EDProductfwd.h:39
RecoEcalCandidate.h
RecoChargedCandidate.h
metsig::jet
Definition: SignAlgoResolutions.h:47
SuperCluster.h
HLT_FULL_cff.jetType
jetType
Definition: HLT_FULL_cff.py:8630
HLTJetCollectionsForBoostedLeptonPlusJets::~HLTJetCollectionsForBoostedLeptonPlusJets
~HLTJetCollectionsForBoostedLeptonPlusJets() override
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.cc:41
trigger::TriggerPhoton
HLT.
Definition: TriggerTypeDefs.h:77
HLTJetCollectionsForBoostedLeptonPlusJets::sourceJetTag
edm::InputTag sourceJetTag
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.h:52
edm::Event
Definition: Event.h:73
RecoChargedCandidateFwd.h
HLTJetCollectionsForBoostedLeptonPlusJets::minDeltaR_
double minDeltaR_
Definition: HLTJetCollectionsForBoostedLeptonPlusJets.h:54
edm::InputTag
Definition: InputTag.h:15
edm::refhelper::FindUsingAdvance
Definition: RefTraits.h:14