CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTScoutingPFProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HLTrigger/JetMET
4 // Class: HLTScoutingPFProducer
5 //
11 //
12 // Original Author: Dustin James Anderson
13 // Created: Fri, 12 Jun 2015 15:49:20 GMT
14 //
15 //
16 
17 // system include files
18 #include <memory>
19 
20 // user include files
26 
35 
39 
41 
43  public:
46 
47  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48 
49  private:
50  virtual void produce(edm::StreamID sid, edm::Event & iEvent, edm::EventSetup const & setup) const override final;
51 
58 
59  const double pfJetPtCut;
60  const double pfJetEtaCut;
61  const double pfCandidatePtCut;
62 
63  const bool doJetTags;
64  const bool doCandidates;
65  const bool doMet;
66 };
67 
68 //
69 // constructors and destructor
70 //
72  pfJetCollection_(consumes<reco::PFJetCollection>(iConfig.getParameter<edm::InputTag>("pfJetCollection"))),
73  pfJetTagCollection_(consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("pfJetTagCollection"))),
74  pfCandidateCollection_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandidateCollection"))),
75  vertexCollection_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexCollection"))),
76  metCollection_(consumes<reco::METCollection>(iConfig.getParameter<edm::InputTag>("metCollection"))),
77  rho_(consumes<double>(iConfig.getParameter<edm::InputTag>("rho"))),
78  pfJetPtCut(iConfig.getParameter<double>("pfJetPtCut")),
79  pfJetEtaCut(iConfig.getParameter<double>("pfJetEtaCut")),
80  pfCandidatePtCut(iConfig.getParameter<double>("pfCandidatePtCut")),
81  doJetTags(iConfig.getParameter<bool>("doJetTags")),
82  doCandidates(iConfig.getParameter<bool>("doCandidates")),
83  doMet(iConfig.getParameter<bool>("doMet"))
84 {
85  //register products
86  produces<ScoutingPFJetCollection>();
87  produces<ScoutingParticleCollection>();
88  produces<ScoutingVertexCollection>();
89  produces<double>("rho");
90  produces<double>("pfMetPt");
91  produces<double>("pfMetPhi");
92 }
93 
95 { }
96 
97 // ------------ method called to produce the data ------------
99 {
100  using namespace edm;
101 
102  //get vertices
104  std::auto_ptr<ScoutingVertexCollection> outVertices(new ScoutingVertexCollection());
106  for(auto &vtx : *vertexCollection){
107  outVertices->emplace_back(
108  vtx.x(), vtx.y(), vtx.z(), vtx.zError()
109  );
110  }
111  }
112 
113  //get rho
115  std::auto_ptr<double> outRho(new double(-999));
116  if(iEvent.getByToken(rho_, rho)){
117  outRho.reset(new double(*rho));
118  }
119 
120  //get MET
122  std::auto_ptr<double> outMetPt(new double(-999));
123  std::auto_ptr<double> outMetPhi(new double(-999));
125  outMetPt.reset(new double(metCollection->front().pt()));
126  outMetPhi.reset(new double(metCollection->front().phi()));
127  }
128 
129  //get PF candidates
130  Handle<reco::PFCandidateCollection> pfCandidateCollection;
131  std::auto_ptr<ScoutingParticleCollection> outPFCandidates(new ScoutingParticleCollection());
132  if(doCandidates && iEvent.getByToken(pfCandidateCollection_, pfCandidateCollection)){
133  for(auto &cand : *pfCandidateCollection){
134  if(cand.pt() > pfCandidatePtCut){
135  int vertex_index = -1;
136  int index_counter = 0;
137  double dr2 = 0.0001;
138  for (auto &vtx: *outVertices) {
139  double tmp_dr2 = pow(vtx.x() - cand.vx(), 2) + pow(vtx.y() - cand.vy(), 2)
140  + pow(vtx.z() - cand.vz(), 2);
141  if (tmp_dr2 < dr2) {
142  dr2 = tmp_dr2;
143  vertex_index = index_counter;
144  }
145  if (dr2 == 0.0)
146  break;
147  ++index_counter;
148  }
149  outPFCandidates->emplace_back(
150  cand.pt(), cand.eta(), cand.phi(), cand.mass(), cand.pdgId(), vertex_index
151  );
152  }
153  }
154  }
155 
156  //get PF jets
157  Handle<reco::PFJetCollection> pfJetCollection;
158  std::auto_ptr<ScoutingPFJetCollection> outPFJets(new ScoutingPFJetCollection());
159  if(iEvent.getByToken(pfJetCollection_, pfJetCollection)){
160  //get PF jet tags
161  Handle<reco::JetTagCollection> pfJetTagCollection;
162  bool haveJetTags = false;
163  if(doJetTags && iEvent.getByToken(pfJetTagCollection_, pfJetTagCollection)){
164  haveJetTags = true;
165  }
166 
167  for(auto &jet : *pfJetCollection){
168  if(jet.pt() < pfJetPtCut || fabs(jet.eta()) > pfJetEtaCut) continue;
169  //find the jet tag corresponding to the jet
170  float tagValue = -20;
171  float minDR2 = 0.01;
172  if(haveJetTags){
173  for(auto &tag : *pfJetTagCollection){
174  float dR2 = reco::deltaR2(jet, *(tag.first));
175  if(dR2 < minDR2){
176  minDR2 = dR2;
177  tagValue = tag.second;
178  }
179  }
180  }
181  //get the PF constituents of the jet
182  std::vector<int> candIndices;
183  if(doCandidates){
184  for(auto &cand : jet.getPFConstituents()){
185  if(cand->pt() > pfCandidatePtCut){
186  //search for the candidate in the collection
187  float minDR2 = 0.0001;
188  int matchIndex = -1;
189  int outIndex = 0;
190  for(auto &outCand : *outPFCandidates){
191  float dR2 = pow(cand->eta() - outCand.eta(), 2) + pow(cand->phi() - outCand.phi(), 2);
192  if(dR2 < minDR2){
193  minDR2 = dR2;
194  matchIndex = outIndex;
195  }
196  if(minDR2 == 0){
197  break;
198  }
199  outIndex++;
200  }
201  candIndices.push_back(matchIndex);
202  }
203  }
204  }
205  outPFJets->emplace_back(
206  jet.pt(), jet.eta(), jet.phi(), jet.mass(), jet.jetArea(),
207  jet.chargedHadronEnergy(), jet.neutralHadronEnergy(), jet.photonEnergy(),
208  jet.electronEnergy(), jet.muonEnergy(), jet.HFHadronEnergy(), jet.HFEMEnergy(),
209  jet.chargedHadronMultiplicity(), jet.neutralHadronMultiplicity(), jet.photonMultiplicity(),
210  jet.electronMultiplicity(), jet.muonMultiplicity(),
211  jet.HFHadronMultiplicity(), jet.HFEMMultiplicity(),
212  jet.hoEnergy(), tagValue, 0.0, candIndices
213  );
214  }
215  }
216 
217  //put output
218  iEvent.put(outVertices);
219  iEvent.put(outPFCandidates);
220  iEvent.put(outPFJets);
221  iEvent.put(outRho, "rho");
222  iEvent.put(outMetPt, "pfMetPt");
223  iEvent.put(outMetPhi, "pfMetPhi");
224 }
225 
226 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
229  desc.add<edm::InputTag>("pfJetCollection",edm::InputTag("hltAK4PFJets"));
230  desc.add<edm::InputTag>("pfJetTagCollection",edm::InputTag("hltCombinedSecondaryVertexBJetTagsPF"));
231  desc.add<edm::InputTag>("pfCandidateCollection", edm::InputTag("hltParticleFlow"));
232  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
233  desc.add<edm::InputTag>("metCollection", edm::InputTag("hltPFMETProducer"));
234  desc.add<edm::InputTag>("rho", edm::InputTag("hltFixedGridRhoFastjetAll"));
235  desc.add<double>("pfJetPtCut", 20.0);
236  desc.add<double>("pfJetEtaCut", 3.0);
237  desc.add<double>("pfCandidatePtCut", 0.6);
238  desc.add<bool>("doJetTags", true);
239  desc.add<bool>("doCandidates", true);
240  desc.add<bool>("doMet", true);
241  descriptions.add("hltScoutingPFProducer", desc);
242 }
243 
244 //define this as a plug-in
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
JetFloatAssociation::Container JetTagCollection
Definition: JetTag.h:18
tuple vertexCollection
const edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidateCollection_
const edm::EDGetTokenT< reco::METCollection > metCollection_
const edm::EDGetTokenT< reco::VertexCollection > vertexCollection_
int iEvent
Definition: GenABIO.cc:230
std::vector< ScoutingVertex > ScoutingVertexCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
std::vector< ScoutingParticle > ScoutingParticleCollection
virtual void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const overridefinal
const edm::EDGetTokenT< reco::PFJetCollection > pfJetCollection_
Collection of MET.
HLTScoutingPFProducer(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const edm::EDGetTokenT< reco::JetTagCollection > pfJetTagCollection_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
const edm::EDGetTokenT< double > rho_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
std::vector< PFJet > PFJetCollection
collection of PFJet objects
std::vector< ScoutingPFJet > ScoutingPFJetCollection
Definition: ScoutingPFJet.h:87
string metCollection
Definition: MT2Analyzer.py:460
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40