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) {
117  outVertices->emplace_back(
124  vtx.tracksSize(),
126  vtx.ndof(),
127  vtx.isValid(),
131  }
132  }
133 
134  //get rho
136  auto outRho = std::make_unique<double>(-999);
137  if (iEvent.getByToken(rho_, rho)) {
138  *outRho = *rho;
139  }
140 
141  //get MET
143  auto outMetPt = std::make_unique<double>(-999);
144  auto outMetPhi = std::make_unique<double>(-999);
145  if (doMet_ && iEvent.getByToken(metCollection_, metCollection)) {
146  outMetPt = std::make_unique<double>(metCollection->front().pt());
147  outMetPhi = std::make_unique<double>(metCollection->front().phi());
148  }
149 
150  //get PF candidates
152  auto outPFCandidates = std::make_unique<Run3ScoutingParticleCollection>();
154  for (auto const &cand : *pfCandidateCollection) {
155  if (cand.pt() > pfCandidatePtCut_ && std::abs(cand.eta()) < pfCandidateEtaCut_) {
156  int vertex_index = -1;
157  int index_counter = 0;
158  double dr2 = 0.0001;
159  for (auto const &vtx : *outVertices) {
160  double tmp_dr2 = pow(vtx.x() - cand.vx(), 2) + pow(vtx.y() - cand.vy(), 2) + pow(vtx.z() - cand.vz(), 2);
161  if (tmp_dr2 < dr2) {
162  dr2 = tmp_dr2;
163  vertex_index = index_counter;
164  }
165  if (dr2 == 0.0)
166  break;
167  ++index_counter;
168  }
169  float normchi2{0}, dz{0}, dxy{0}, dzError{0}, dxyError{0}, trk_pt{0}, trk_eta{0}, trk_phi{0};
170  uint8_t lostInnerHits{0}, quality{0};
171  if (doTrackVars_) {
172  const auto *trk = cand.bestTrack();
173  if (trk != nullptr) {
177  if (relativeTrackVars_) {
181  } else {
185  }
186  if (not vertexCollection->empty()) {
187  const reco::Vertex &pv = (*vertexCollection)[0];
188 
189  dz = trk->dz(pv.position());
192 
193  dxy = trk->dxy(pv.position());
196  }
197  } else {
199  }
200  }
204  cand.pdgId(),
205  vertex_index,
206  normchi2,
207  dz,
208  dxy,
209  dzError,
210  dxyError,
211  lostInnerHits,
212  quality,
213  trk_pt,
214  trk_eta,
215  trk_phi,
217  }
218  }
219  }
220 
221  //get PF jets
223  auto outPFJets = std::make_unique<Run3ScoutingPFJetCollection>();
224  if (iEvent.getByToken(pfJetCollection_, pfJetCollection)) {
225  //get PF jet tags
227  bool haveJetTags = false;
229  haveJetTags = true;
230  }
231 
232  for (auto const &jet : *pfJetCollection) {
233  if (jet.pt() < pfJetPtCut_ || std::abs(jet.eta()) > pfJetEtaCut_)
234  continue;
235  //find the jet tag corresponding to the jet
236  float tagValue = -20;
237  float minDR2 = 0.01;
238  if (haveJetTags) {
239  for (auto const &tag : *pfJetTagCollection) {
240  float dR2 = reco::deltaR2(jet, *(tag.first));
241  if (dR2 < minDR2) {
242  minDR2 = dR2;
243  tagValue = tag.second;
244  }
245  }
246  }
247  //get the PF constituents of the jet
248  std::vector<int> candIndices;
250  for (auto const &cand : jet.getPFConstituents()) {
251  if (not(cand.isNonnull() and cand.isAvailable())) {
252  throw cms::Exception("HLTScoutingPFProducer")
253  << "invalid reference to reco::PFCandidate from reco::PFJet::getPFConstituents()";
254  }
255  if (cand->pt() > pfCandidatePtCut_ && std::abs(cand->eta()) < pfCandidateEtaCut_) {
256  //search for the candidate in the collection
257  float minDR2 = 0.0001;
258  int matchIndex = -1;
259  int outIndex = 0;
260  for (auto &outCand : *outPFCandidates) {
261  auto const dR2 = reco::deltaR2(*cand, outCand);
262  if (dR2 < minDR2) {
263  minDR2 = dR2;
264  matchIndex = outIndex;
265  }
266  if (minDR2 == 0) {
267  break;
268  }
269  outIndex++;
270  }
271  candIndices.push_back(matchIndex);
272  }
273  }
274  }
275  outPFJets->emplace_back(
288  jet.chargedHadronMultiplicity(),
289  jet.neutralHadronMultiplicity(),
290  jet.photonMultiplicity(),
291  jet.electronMultiplicity(),
292  jet.muonMultiplicity(),
293  jet.HFHadronMultiplicity(),
294  jet.HFEMMultiplicity(),
298  candIndices);
299  }
300  }
301 
302  //put output
303  iEvent.put(std::move(outPFCandidates));
304  iEvent.put(std::move(outPFJets));
305  iEvent.put(std::move(outRho), "rho");
306  iEvent.put(std::move(outMetPt), "pfMetPt");
307  iEvent.put(std::move(outMetPhi), "pfMetPhi");
308 }
309 
310 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
313  desc.add<edm::InputTag>("pfJetCollection", edm::InputTag("hltAK4PFJets"));
314  desc.add<edm::InputTag>("pfJetTagCollection", edm::InputTag("hltDeepCombinedSecondaryVertexBJetTagsPF"));
315  desc.add<edm::InputTag>("pfCandidateCollection", edm::InputTag("hltParticleFlow"));
316  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
317  desc.add<edm::InputTag>("metCollection", edm::InputTag("hltPFMETProducer"));
318  desc.add<edm::InputTag>("rho", edm::InputTag("hltFixedGridRhoFastjetAll"));
319  desc.add<double>("pfJetPtCut", 20.0);
320  desc.add<double>("pfJetEtaCut", 3.0);
321  desc.add<double>("pfCandidatePtCut", 0.6);
322  desc.add<double>("pfCandidateEtaCut", 5.0);
323  desc.add<int>("mantissaPrecision", 10)->setComment("default float16, change to 23 for float32");
324  desc.add<bool>("doJetTags", true);
325  desc.add<bool>("doCandidates", true);
326  desc.add<bool>("doMet", true);
327  desc.add<bool>("doTrackVars", true);
328  desc.add<bool>("relativeTrackVars", true);
329  desc.add<bool>("doCandIndsForJets", false);
330  descriptions.addWithDefaultLabel(desc);
331 }
332 
333 // 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
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
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
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.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511