CMS 3D CMS Logo

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:
45  ~HLTScoutingPFProducer() override;
46 
47  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48 
49  private:
50  void produce(edm::StreamID sid, edm::Event & iEvent, edm::EventSetup const & setup) const 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::PFMETCollection>(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<double>("rho");
89  produces<double>("pfMetPt");
90  produces<double>("pfMetPhi");
91 }
92 
94 
95 // ------------ method called to produce the data ------------
97 {
98  using namespace edm;
99 
100  //get vertices
102  std::unique_ptr<ScoutingVertexCollection> outVertices(new ScoutingVertexCollection());
103  if(iEvent.getByToken(vertexCollection_, vertexCollection)){
104  for(auto &vtx : *vertexCollection){
105  outVertices->emplace_back(
106  vtx.x(), vtx.y(), vtx.z(), vtx.zError(), vtx.xError(), vtx.yError(), vtx.tracksSize(), vtx.chi2(), vtx.ndof(), vtx.isValid()
107  );
108  }
109  }
110 
111  //get rho
113  std::unique_ptr<double> outRho(new double(-999));
114  if(iEvent.getByToken(rho_, rho)){
115  outRho.reset(new double(*rho));
116  }
117 
118  //get MET
120  std::unique_ptr<double> outMetPt(new double(-999));
121  std::unique_ptr<double> outMetPhi(new double(-999));
122  if(doMet && iEvent.getByToken(metCollection_, metCollection)){
123  outMetPt.reset(new double(metCollection->front().pt()));
124  outMetPhi.reset(new double(metCollection->front().phi()));
125  }
126 
127  //get PF candidates
128  Handle<reco::PFCandidateCollection> pfCandidateCollection;
129  std::unique_ptr<ScoutingParticleCollection> outPFCandidates(new ScoutingParticleCollection());
130  if(doCandidates && iEvent.getByToken(pfCandidateCollection_, pfCandidateCollection)){
131  for(auto &cand : *pfCandidateCollection){
132  if(cand.pt() > pfCandidatePtCut){
133  int vertex_index = -1;
134  int index_counter = 0;
135  double dr2 = 0.0001;
136  for (auto &vtx: *outVertices) {
137  double tmp_dr2 = pow(vtx.x() - cand.vx(), 2) + pow(vtx.y() - cand.vy(), 2)
138  + pow(vtx.z() - cand.vz(), 2);
139  if (tmp_dr2 < dr2) {
140  dr2 = tmp_dr2;
141  vertex_index = index_counter;
142  }
143  if (dr2 == 0.0)
144  break;
145  ++index_counter;
146  }
147  outPFCandidates->emplace_back(
148  cand.pt(), cand.eta(), cand.phi(), cand.mass(), cand.pdgId(), vertex_index
149  );
150  }
151  }
152  }
153 
154  //get PF jets
155  Handle<reco::PFJetCollection> pfJetCollection;
156  std::unique_ptr<ScoutingPFJetCollection> outPFJets(new ScoutingPFJetCollection());
157  if(iEvent.getByToken(pfJetCollection_, pfJetCollection)){
158  //get PF jet tags
159  Handle<reco::JetTagCollection> pfJetTagCollection;
160  bool haveJetTags = false;
161  if(doJetTags && iEvent.getByToken(pfJetTagCollection_, pfJetTagCollection)){
162  haveJetTags = true;
163  }
164 
165  for(auto &jet : *pfJetCollection){
166  if(jet.pt() < pfJetPtCut || fabs(jet.eta()) > pfJetEtaCut) continue;
167  //find the jet tag corresponding to the jet
168  float tagValue = -20;
169  float minDR2 = 0.01;
170  if(haveJetTags){
171  for(auto &tag : *pfJetTagCollection){
172  float dR2 = reco::deltaR2(jet, *(tag.first));
173  if(dR2 < minDR2){
174  minDR2 = dR2;
175  tagValue = tag.second;
176  }
177  }
178  }
179  //get the PF constituents of the jet
180  std::vector<int> candIndices;
181  if(doCandidates){
182  for(auto &cand : jet.getPFConstituents()){
183  if(cand->pt() > pfCandidatePtCut){
184  //search for the candidate in the collection
185  float minDR2 = 0.0001;
186  int matchIndex = -1;
187  int outIndex = 0;
188  for(auto &outCand : *outPFCandidates){
189  float dR2 = pow(cand->eta() - outCand.eta(), 2) + pow(cand->phi() - outCand.phi(), 2);
190  if(dR2 < minDR2){
191  minDR2 = dR2;
192  matchIndex = outIndex;
193  }
194  if(minDR2 == 0){
195  break;
196  }
197  outIndex++;
198  }
199  candIndices.push_back(matchIndex);
200  }
201  }
202  }
203  outPFJets->emplace_back(
204  jet.pt(), jet.eta(), jet.phi(), jet.mass(), jet.jetArea(),
205  jet.chargedHadronEnergy(), jet.neutralHadronEnergy(), jet.photonEnergy(),
206  jet.electronEnergy(), jet.muonEnergy(), jet.HFHadronEnergy(), jet.HFEMEnergy(),
207  jet.chargedHadronMultiplicity(), jet.neutralHadronMultiplicity(), jet.photonMultiplicity(),
208  jet.electronMultiplicity(), jet.muonMultiplicity(),
209  jet.HFHadronMultiplicity(), jet.HFEMMultiplicity(),
210  jet.hoEnergy(), tagValue, 0.0, candIndices
211  );
212  }
213  }
214 
215  //put output
216  iEvent.put(std::move(outPFCandidates));
217  iEvent.put(std::move(outPFJets));
218  iEvent.put(std::move(outRho), "rho");
219  iEvent.put(std::move(outMetPt), "pfMetPt");
220  iEvent.put(std::move(outMetPhi), "pfMetPhi");
221 }
222 
223 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
226  desc.add<edm::InputTag>("pfJetCollection",edm::InputTag("hltAK4PFJets"));
227  desc.add<edm::InputTag>("pfJetTagCollection",edm::InputTag("hltCombinedSecondaryVertexBJetTagsPF"));
228  desc.add<edm::InputTag>("pfCandidateCollection", edm::InputTag("hltParticleFlow"));
229  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
230  desc.add<edm::InputTag>("metCollection", edm::InputTag("hltPFMETProducer"));
231  desc.add<edm::InputTag>("rho", edm::InputTag("hltFixedGridRhoFastjetAll"));
232  desc.add<double>("pfJetPtCut", 20.0);
233  desc.add<double>("pfJetEtaCut", 3.0);
234  desc.add<double>("pfCandidatePtCut", 0.6);
235  desc.add<bool>("doJetTags", true);
236  desc.add<bool>("doCandidates", true);
237  desc.add<bool>("doMet", true);
238  descriptions.add("hltScoutingPFProducer", desc);
239 }
240 
241 // declare this class as a framework plugin
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
const edm::EDGetTokenT< reco::PFMETCollection > metCollection_
~HLTScoutingPFProducer() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
JetFloatAssociation::Container JetTagCollection
Definition: JetTag.h:18
const edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidateCollection_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< reco::VertexCollection > vertexCollection_
void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const final
int iEvent
Definition: GenABIO.cc:230
std::vector< ScoutingVertex > ScoutingVertexCollection
std::vector< ScoutingParticle > ScoutingParticleCollection
const edm::EDGetTokenT< reco::PFJetCollection > pfJetCollection_
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
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
const edm::EDGetTokenT< double > rho_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< PFJet > PFJetCollection
collection of PFJet objects
fixed size matrix
HLT enums.
std::vector< ScoutingPFJet > ScoutingPFJetCollection
Definition: ScoutingPFJet.h:87
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
def move(src, dest)
Definition: eostools.py:510
Collection of PF MET.