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 
45 
47 public:
48  explicit HLTScoutingPFProducer(const edm::ParameterSet &);
49  ~HLTScoutingPFProducer() override;
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
52 
53 private:
54  void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const final;
55 
62 
63  const double pfJetPtCut_;
64  const double pfJetEtaCut_;
65  const double pfCandidatePtCut_;
66  const double pfCandidateEtaCut_;
67  const int mantissaPrecision_;
68 
69  const bool doJetTags_;
70  const bool doCandidates_;
71  const bool doMet_;
72  const bool doTrackVars_;
73  const bool relativeTrackVars_;
74  const bool doCandIndsForJets_;
75 };
76 
77 //
78 // constructors and destructor
79 //
81  : pfJetCollection_(consumes(iConfig.getParameter<edm::InputTag>("pfJetCollection"))),
82  pfJetTagCollection_(consumes(iConfig.getParameter<edm::InputTag>("pfJetTagCollection"))),
83  pfCandidateCollection_(consumes(iConfig.getParameter<edm::InputTag>("pfCandidateCollection"))),
84  vertexCollection_(consumes(iConfig.getParameter<edm::InputTag>("vertexCollection"))),
85  metCollection_(consumes(iConfig.getParameter<edm::InputTag>("metCollection"))),
86  rho_(consumes(iConfig.getParameter<edm::InputTag>("rho"))),
87  pfJetPtCut_(iConfig.getParameter<double>("pfJetPtCut")),
88  pfJetEtaCut_(iConfig.getParameter<double>("pfJetEtaCut")),
89  pfCandidatePtCut_(iConfig.getParameter<double>("pfCandidatePtCut")),
90  pfCandidateEtaCut_(iConfig.getParameter<double>("pfCandidateEtaCut")),
91  mantissaPrecision_(iConfig.getParameter<int>("mantissaPrecision")),
92  doJetTags_(iConfig.getParameter<bool>("doJetTags")),
93  doCandidates_(iConfig.getParameter<bool>("doCandidates")),
94  doMet_(iConfig.getParameter<bool>("doMet")),
95  doTrackVars_(iConfig.getParameter<bool>("doTrackVars")),
96  relativeTrackVars_(iConfig.getParameter<bool>("relativeTrackVars")),
97  doCandIndsForJets_(iConfig.getParameter<bool>("doCandIndsForJets")) {
98  //register products
99  produces<Run3ScoutingPFJetCollection>();
100  produces<Run3ScoutingParticleCollection>();
101  produces<double>("rho");
102  produces<double>("pfMetPt");
103  produces<double>("pfMetPhi");
104 }
105 
107 
108 // ------------ method called to produce the data ------------
110  using namespace edm;
111 
112  //get vertices
114  auto outVertices = std::make_unique<Run3ScoutingVertexCollection>();
115  if (iEvent.getByToken(vertexCollection_, vertexCollection)) {
116  for (auto const &vtx : *vertexCollection) {
123  vtx.tracksSize(),
125  vtx.ndof(),
126  vtx.isValid());
127  }
128  }
129 
130  //get rho
132  auto outRho = std::make_unique<double>(-999);
133  if (iEvent.getByToken(rho_, rho)) {
134  *outRho = *rho;
135  }
136 
137  //get MET
139  auto outMetPt = std::make_unique<double>(-999);
140  auto outMetPhi = std::make_unique<double>(-999);
141  if (doMet_ && iEvent.getByToken(metCollection_, metCollection)) {
142  outMetPt = std::make_unique<double>(metCollection->front().pt());
143  outMetPhi = std::make_unique<double>(metCollection->front().phi());
144  }
145 
146  //get PF candidates
148  auto outPFCandidates = std::make_unique<Run3ScoutingParticleCollection>();
150  for (auto const &cand : *pfCandidateCollection) {
151  if (cand.pt() > pfCandidatePtCut_ && std::abs(cand.eta()) < pfCandidateEtaCut_) {
152  int vertex_index = -1;
153  int index_counter = 0;
154  double dr2 = 0.0001;
155  for (auto const &vtx : *outVertices) {
156  double tmp_dr2 = pow(vtx.x() - cand.vx(), 2) + pow(vtx.y() - cand.vy(), 2) + pow(vtx.z() - cand.vz(), 2);
157  if (tmp_dr2 < dr2) {
158  dr2 = tmp_dr2;
159  vertex_index = index_counter;
160  }
161  if (dr2 == 0.0)
162  break;
163  ++index_counter;
164  }
165  float normchi2{0}, dz{0}, dxy{0}, dzError{0}, dxyError{0}, trk_pt{0}, trk_eta{0}, trk_phi{0};
166  uint8_t lostInnerHits{0}, quality{0};
167  if (doTrackVars_) {
168  const auto *trk = cand.bestTrack();
169  if (trk != nullptr) {
173  if (relativeTrackVars_) {
177  } else {
181  }
182  if (not vertexCollection->empty()) {
183  const reco::Vertex &pv = (*vertexCollection)[0];
184 
185  dz = trk->dz(pv.position());
188 
189  dxy = trk->dxy(pv.position());
192  }
193  } else {
195  }
196  }
200  cand.pdgId(),
201  vertex_index,
202  normchi2,
203  dz,
204  dxy,
205  dzError,
206  dxyError,
207  lostInnerHits,
208  quality,
209  trk_pt,
210  trk_eta,
211  trk_phi,
213  }
214  }
215  }
216 
217  //get PF jets
219  auto outPFJets = std::make_unique<Run3ScoutingPFJetCollection>();
220  if (iEvent.getByToken(pfJetCollection_, pfJetCollection)) {
221  //get PF jet tags
223  bool haveJetTags = false;
225  haveJetTags = true;
226  }
227 
228  for (auto const &jet : *pfJetCollection) {
229  if (jet.pt() < pfJetPtCut_ || std::abs(jet.eta()) > pfJetEtaCut_)
230  continue;
231  //find the jet tag corresponding to the jet
232  float tagValue = -20;
233  float minDR2 = 0.01;
234  if (haveJetTags) {
235  for (auto const &tag : *pfJetTagCollection) {
236  float dR2 = reco::deltaR2(jet, *(tag.first));
237  if (dR2 < minDR2) {
238  minDR2 = dR2;
239  tagValue = tag.second;
240  }
241  }
242  }
243  //get the PF constituents of the jet
244  std::vector<int> candIndices;
246  for (auto const &cand : jet.getPFConstituents()) {
247  if (not(cand.isNonnull() and cand.isAvailable())) {
248  throw cms::Exception("HLTScoutingPFProducer")
249  << "invalid reference to reco::PFCandidate from reco::PFJet::getPFConstituents()";
250  }
251  if (cand->pt() > pfCandidatePtCut_ && std::abs(cand->eta()) < pfCandidateEtaCut_) {
252  //search for the candidate in the collection
253  float minDR2 = 0.0001;
254  int matchIndex = -1;
255  int outIndex = 0;
256  for (auto &outCand : *outPFCandidates) {
257  auto const dR2 = reco::deltaR2(*cand, outCand);
258  if (dR2 < minDR2) {
259  minDR2 = dR2;
260  matchIndex = outIndex;
261  }
262  if (minDR2 == 0) {
263  break;
264  }
265  outIndex++;
266  }
267  candIndices.push_back(matchIndex);
268  }
269  }
270  }
271  outPFJets->emplace_back(
284  jet.chargedHadronMultiplicity(),
285  jet.neutralHadronMultiplicity(),
286  jet.photonMultiplicity(),
287  jet.electronMultiplicity(),
288  jet.muonMultiplicity(),
289  jet.HFHadronMultiplicity(),
290  jet.HFEMMultiplicity(),
294  candIndices);
295  }
296  }
297 
298  //put output
299  iEvent.put(std::move(outPFCandidates));
300  iEvent.put(std::move(outPFJets));
301  iEvent.put(std::move(outRho), "rho");
302  iEvent.put(std::move(outMetPt), "pfMetPt");
303  iEvent.put(std::move(outMetPhi), "pfMetPhi");
304 }
305 
306 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
309  desc.add<edm::InputTag>("pfJetCollection", edm::InputTag("hltAK4PFJets"));
310  desc.add<edm::InputTag>("pfJetTagCollection", edm::InputTag("hltDeepCombinedSecondaryVertexBJetTagsPF"));
311  desc.add<edm::InputTag>("pfCandidateCollection", edm::InputTag("hltParticleFlow"));
312  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
313  desc.add<edm::InputTag>("metCollection", edm::InputTag("hltPFMETProducer"));
314  desc.add<edm::InputTag>("rho", edm::InputTag("hltFixedGridRhoFastjetAll"));
315  desc.add<double>("pfJetPtCut", 20.0);
316  desc.add<double>("pfJetEtaCut", 3.0);
317  desc.add<double>("pfCandidatePtCut", 0.6);
318  desc.add<double>("pfCandidateEtaCut", 5.0);
319  desc.add<int>("mantissaPrecision", 10)->setComment("default float16, change to 23 for float32");
320  desc.add<bool>("doJetTags", true);
321  desc.add<bool>("doCandidates", true);
322  desc.add<bool>("doMet", true);
323  desc.add<bool>("doTrackVars", true);
324  desc.add<bool>("relativeTrackVars", true);
325  desc.add<bool>("doCandIndsForJets", false);
326  descriptions.addWithDefaultLabel(desc);
327 }
328 
329 // declare this class as a framework plugin
float quality_from_pfcand(const reco::PFCandidate &pfcand)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< reco::PFMETCollection > metCollection_
~HLTScoutingPFProducer() override
constexpr int pow(int x)
Definition: conifer.h:24
const edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidateCollection_
const edm::EDGetTokenT< reco::VertexCollection > vertexCollection_
string quality
int iEvent
Definition: GenABIO.cc:224
void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const final
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< reco::PFJetCollection > pfJetCollection_
HLTScoutingPFProducer(const edm::ParameterSet &)
const edm::EDGetTokenT< reco::JetTagCollection > pfJetTagCollection_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
const edm::EDGetTokenT< double > rho_
float lost_inner_hits_from_pfcand(const reco::PFCandidate &pfcand)
static float reduceMantissaToNbitsRounding(const float &f)
Definition: libminifloat.h:79
HLT enums.
def move(src, dest)
Definition: eostools.py:511