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 PF jets
103  Handle<reco::PFJetCollection> pfJetCollection;
104  if(!iEvent.getByToken(pfJetCollection_, pfJetCollection)){
105  edm::LogError ("HLTScoutingPFProducer") << "invalid collection: pfJetCollection" << "\n";
106  return;
107  }
108  //get PF jet tags
109  Handle<reco::JetTagCollection> pfJetTagCollection;
110  if(doJetTags && !iEvent.getByToken(pfJetTagCollection_, pfJetTagCollection)){
111  edm::LogError ("HLTScoutingPFProducer") << "invalid collection: pfJetTagCollection" << "\n";
112  return;
113  }
114  //get PF candidates
115  Handle<reco::PFCandidateCollection> pfCandidateCollection;
116  if(doCandidates && !iEvent.getByToken(pfCandidateCollection_, pfCandidateCollection)){
117  edm::LogError ("HLTScoutingPFProducer") << "invalid collection: pfCandidateCollection" << "\n";
118  return;
119  }
120  //get vertices
123  edm::LogError ("HLTScoutingPFProducer") << "invalid collection: vertexCollection" << "\n";
124  return;
125  }
126  //get rho
128  if(!iEvent.getByToken(rho_, rho)){
129  edm::LogError ("HLTScoutingPFProducer") << "invalid collection: rho" << "\n";
130  return;
131  }
132  std::auto_ptr<double> outRho(new double(*rho));
133  //get MET
135  if(doMet && !iEvent.getByToken(metCollection_, metCollection)){
136  edm::LogError ("HLTScoutingPFProducer") << "invalid collection: metCollection" << "\n";
137  return;
138  }
139 
140  //produce vertices
141  std::auto_ptr<ScoutingVertexCollection> outVertices(new ScoutingVertexCollection());
142  for(auto &vtx : *vertexCollection){
143  outVertices->emplace_back(
144  vtx.x(), vtx.y(), vtx.z(), vtx.zError()
145  );
146  }
147 
148  //produce PF candidates
149  std::auto_ptr<ScoutingParticleCollection> outPFCandidates(new ScoutingParticleCollection());
150  if(doCandidates){
151  for(auto &cand : *pfCandidateCollection){
152  if(cand.pt() > pfCandidatePtCut){
153  outPFCandidates->emplace_back(
154  cand.pt(), cand.eta(), cand.phi(), cand.mass(), cand.pdgId()
155  );
156  }
157  }
158  }
159 
160  //produce PF jets
161  std::auto_ptr<ScoutingPFJetCollection> outPFJets(new ScoutingPFJetCollection());
162  for(auto &jet : *pfJetCollection){
163  if(jet.pt() < pfJetPtCut || fabs(jet.eta()) > pfJetEtaCut) continue;
164  //find the jet tag corresponding to the jet
165  float tagValue = -20;
166  float minDR2 = 0.01;
167  if(doJetTags){
168  for(auto &tag : *pfJetTagCollection){
169  float dR2 = reco::deltaR2(jet, *(tag.first));
170  if(dR2 < minDR2){
171  minDR2 = dR2;
172  tagValue = tag.second;
173  }
174  }
175  }
176  //get the PF constituents of the jet
177  std::vector<int> candIndices;
178  if(doCandidates){
179  for(auto &cand : jet.getPFConstituents()){
180  if(cand->pt() > pfCandidatePtCut){
181  //search for the candidate in the collection
182  float minDR2 = 0.0001;
183  int matchIndex = -1;
184  int outIndex = 0;
185  for(auto &outCand : *outPFCandidates){
186  float dR2 = pow(cand->eta() - outCand.eta(), 2) + pow(cand->phi() - outCand.phi(), 2);
187  if(dR2 < minDR2){
188  minDR2 = dR2;
189  matchIndex = outIndex;
190  }
191  if(minDR2 == 0){
192  break;
193  }
194  outIndex++;
195  }
196  candIndices.push_back(matchIndex);
197  }
198  }
199  }
200  outPFJets->emplace_back(
201  jet.pt(), jet.eta(), jet.phi(), jet.mass(), jet.jetArea(),
202  jet.chargedHadronEnergy(), jet.neutralHadronEnergy(), jet.photonEnergy(),
203  jet.electronEnergy(), jet.muonEnergy(), jet.HFHadronEnergy(), jet.HFEMEnergy(),
204  jet.chargedHadronMultiplicity(), jet.neutralHadronMultiplicity(), jet.photonMultiplicity(),
205  jet.electronMultiplicity(), jet.muonMultiplicity(),
206  jet.HFHadronMultiplicity(), jet.HFEMMultiplicity(),
207  jet.hoEnergy(), tagValue, 0.0, candIndices
208  );
209  }
210 
211  double metPt = -999;
212  double metPhi = -999;
213  if(doMet){
214  metPt = metCollection->front().pt();
215  metPhi = metCollection->front().phi();
216  }
217  std::auto_ptr<double> outMetPt(new double(metPt));
218  std::auto_ptr<double> outMetPhi(new double(metPhi));
219 
220 
221  //put output
222  iEvent.put(outVertices);
223  iEvent.put(outPFCandidates);
224  iEvent.put(outPFJets);
225  iEvent.put(outRho, "rho");
226  iEvent.put(outMetPt, "pfMetPt");
227  iEvent.put(outMetPhi, "pfMetPhi");
228 }
229 
230 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
233  desc.add<edm::InputTag>("pfJetCollection",edm::InputTag("hltAK4PFJets"));
234  desc.add<edm::InputTag>("pfJetTagCollection",edm::InputTag("hltCombinedSecondaryVertexBJetTagsPF"));
235  desc.add<edm::InputTag>("pfCandidateCollection", edm::InputTag("hltParticleFlow"));
236  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
237  desc.add<edm::InputTag>("metCollection", edm::InputTag("hltPFMETProducer"));
238  desc.add<edm::InputTag>("rho", edm::InputTag("hltFixedGridRhoFastjetAll"));
239  desc.add<double>("pfJetPtCut", 20.0);
240  desc.add<double>("pfJetEtaCut", 3.0);
241  desc.add<double>("pfCandidatePtCut", 0.6);
242  desc.add<bool>("doJetTags", true);
243  desc.add<bool>("doCandidates", true);
244  desc.add<bool>("doMet", true);
245  descriptions.add("hltScoutingPFProducer", desc);
246 }
247 
248 //define this as a plug-in
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Definition: DDAxes.h:10
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:113
std::vector< ScoutingParticle > ScoutingParticleCollection
virtual void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const overridefinal
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
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)
std::vector< PFJet > PFJetCollection
collection of PFJet objects
std::vector< ScoutingPFJet > ScoutingPFJetCollection
Definition: ScoutingPFJet.h:87
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