CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
45 public:
46  explicit HLTScoutingPFProducer(const edm::ParameterSet &);
47  ~HLTScoutingPFProducer() override;
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
50 
51 private:
52  void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const final;
53 
60 
61  const double pfJetPtCut;
62  const double pfJetEtaCut;
63  const double pfCandidatePtCut;
64  const double pfCandidateEtaCut;
65  const int mantissaPrecision;
66 
67  const bool doJetTags;
68  const bool doCandidates;
69  const bool doMet;
70 };
71 
72 //
73 // constructors and destructor
74 //
76  : pfJetCollection_(consumes<reco::PFJetCollection>(iConfig.getParameter<edm::InputTag>("pfJetCollection"))),
77  pfJetTagCollection_(consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("pfJetTagCollection"))),
78  pfCandidateCollection_(
79  consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandidateCollection"))),
80  vertexCollection_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexCollection"))),
81  metCollection_(consumes<reco::PFMETCollection>(iConfig.getParameter<edm::InputTag>("metCollection"))),
82  rho_(consumes<double>(iConfig.getParameter<edm::InputTag>("rho"))),
83  pfJetPtCut(iConfig.getParameter<double>("pfJetPtCut")),
84  pfJetEtaCut(iConfig.getParameter<double>("pfJetEtaCut")),
85  pfCandidatePtCut(iConfig.getParameter<double>("pfCandidatePtCut")),
86  pfCandidateEtaCut(iConfig.getParameter<double>("pfCandidateEtaCut")),
87  mantissaPrecision(iConfig.getParameter<int>("mantissaPrecision")),
88  doJetTags(iConfig.getParameter<bool>("doJetTags")),
89  doCandidates(iConfig.getParameter<bool>("doCandidates")),
90  doMet(iConfig.getParameter<bool>("doMet")) {
91  //register products
92  produces<Run3ScoutingPFJetCollection>();
93  produces<Run3ScoutingParticleCollection>();
94  produces<double>("rho");
95  produces<double>("pfMetPt");
96  produces<double>("pfMetPhi");
97 }
98 
100 
101 // ------------ method called to produce the data ------------
103  using namespace edm;
104 
105  //get vertices
107  std::unique_ptr<Run3ScoutingVertexCollection> outVertices(new Run3ScoutingVertexCollection());
109  for (auto &vtx : *vertexCollection) {
110  outVertices->emplace_back(vtx.x(),
111  vtx.y(),
112  vtx.z(),
113  vtx.zError(),
114  vtx.xError(),
115  vtx.yError(),
116  vtx.tracksSize(),
117  vtx.chi2(),
118  vtx.ndof(),
119  vtx.isValid());
120  }
121  }
122 
123  //get rho
125  std::unique_ptr<double> outRho(new double(-999));
126  if (iEvent.getByToken(rho_, rho)) {
127  outRho = std::make_unique<double>(*rho);
128  }
129 
130  //get MET
132  std::unique_ptr<double> outMetPt(new double(-999));
133  std::unique_ptr<double> outMetPhi(new double(-999));
134  if (doMet && iEvent.getByToken(metCollection_, metCollection)) {
135  outMetPt = std::make_unique<double>(metCollection->front().pt());
136  outMetPhi = std::make_unique<double>(metCollection->front().phi());
137  }
138 
139  //get PF candidates
141  std::unique_ptr<Run3ScoutingParticleCollection> outPFCandidates(new Run3ScoutingParticleCollection());
143  for (auto &cand : *pfCandidateCollection) {
144  if (cand.pt() > pfCandidatePtCut && std::abs(cand.eta()) < pfCandidateEtaCut) {
145  int vertex_index = -1;
146  int index_counter = 0;
147  double dr2 = 0.0001;
148  for (auto &vtx : *outVertices) {
149  double tmp_dr2 = pow(vtx.x() - cand.vx(), 2) + pow(vtx.y() - cand.vy(), 2) + pow(vtx.z() - cand.vz(), 2);
150  if (tmp_dr2 < dr2) {
151  dr2 = tmp_dr2;
152  vertex_index = index_counter;
153  }
154  if (dr2 == 0.0)
155  break;
156  ++index_counter;
157  }
158 
159  outPFCandidates->emplace_back(MiniFloatConverter::reduceMantissaToNbitsRounding(cand.pt(), mantissaPrecision),
163  cand.pdgId(),
164  vertex_index);
165  }
166  }
167  }
168 
169  //get PF jets
171  std::unique_ptr<Run3ScoutingPFJetCollection> outPFJets(new Run3ScoutingPFJetCollection());
173  //get PF jet tags
175  bool haveJetTags = false;
176  if (doJetTags && iEvent.getByToken(pfJetTagCollection_, pfJetTagCollection)) {
177  haveJetTags = true;
178  }
179 
180  for (auto &jet : *pfJetCollection) {
181  if (jet.pt() < pfJetPtCut || std::abs(jet.eta()) > pfJetEtaCut)
182  continue;
183  //find the jet tag corresponding to the jet
184  float tagValue = -20;
185  float minDR2 = 0.01;
186  if (haveJetTags) {
187  for (auto &tag : *pfJetTagCollection) {
188  float dR2 = reco::deltaR2(jet, *(tag.first));
189  if (dR2 < minDR2) {
190  minDR2 = dR2;
191  tagValue = tag.second;
192  }
193  }
194  }
195  //get the PF constituents of the jet
196  std::vector<int> candIndices;
197  if (doCandidates) {
198  for (auto &cand : jet.getPFConstituents()) {
199  if (not(cand.isNonnull() and cand.isAvailable())) {
200  throw cms::Exception("HLTScoutingPFProducer")
201  << "invalid reference to reco::PFCandidate from reco::PFJet::getPFConstituents()";
202  }
203  if (cand->pt() > pfCandidatePtCut && std::abs(cand->eta()) < pfCandidateEtaCut) {
204  //search for the candidate in the collection
205  float minDR2 = 0.0001;
206  int matchIndex = -1;
207  int outIndex = 0;
208  for (auto &outCand : *outPFCandidates) {
209  float dR2 = pow(cand->eta() - outCand.eta(), 2) + pow(cand->phi() - outCand.phi(), 2);
210  if (dR2 < minDR2) {
211  minDR2 = dR2;
212  matchIndex = outIndex;
213  }
214  if (minDR2 == 0) {
215  break;
216  }
217  outIndex++;
218  }
219  candIndices.push_back(matchIndex);
220  }
221  }
222  }
223  outPFJets->emplace_back(jet.pt(),
224  jet.eta(),
225  jet.phi(),
226  jet.mass(),
227  jet.jetArea(),
228  jet.chargedHadronEnergy(),
229  jet.neutralHadronEnergy(),
230  jet.photonEnergy(),
231  jet.electronEnergy(),
232  jet.muonEnergy(),
233  jet.HFHadronEnergy(),
234  jet.HFEMEnergy(),
235  jet.chargedHadronMultiplicity(),
236  jet.neutralHadronMultiplicity(),
237  jet.photonMultiplicity(),
238  jet.electronMultiplicity(),
239  jet.muonMultiplicity(),
240  jet.HFHadronMultiplicity(),
241  jet.HFEMMultiplicity(),
242  jet.hoEnergy(),
243  tagValue,
244  0.0,
245  candIndices);
246  }
247  }
248 
249  //put output
250  iEvent.put(std::move(outPFCandidates));
251  iEvent.put(std::move(outPFJets));
252  iEvent.put(std::move(outRho), "rho");
253  iEvent.put(std::move(outMetPt), "pfMetPt");
254  iEvent.put(std::move(outMetPhi), "pfMetPhi");
255 }
256 
257 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
260  desc.add<edm::InputTag>("pfJetCollection", edm::InputTag("hltAK4PFJets"));
261  desc.add<edm::InputTag>("pfJetTagCollection", edm::InputTag("hltDeepCombinedSecondaryVertexBJetTagsPF"));
262  desc.add<edm::InputTag>("pfCandidateCollection", edm::InputTag("hltParticleFlow"));
263  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
264  desc.add<edm::InputTag>("metCollection", edm::InputTag("hltPFMETProducer"));
265  desc.add<edm::InputTag>("rho", edm::InputTag("hltFixedGridRhoFastjetAll"));
266  desc.add<double>("pfJetPtCut", 20.0);
267  desc.add<double>("pfJetEtaCut", 3.0);
268  desc.add<double>("pfCandidatePtCut", 0.6);
269  desc.add<double>("pfCandidateEtaCut", 5.0);
270  desc.add<int>("mantissaPrecision", 10)->setComment("default float16, change to 23 for float32");
271  desc.add<bool>("doJetTags", true);
272  desc.add<bool>("doCandidates", true);
273  desc.add<bool>("doMet", true);
274  descriptions.add("hltScoutingPFProducer", desc);
275 }
276 
277 // declare this class as a framework plugin
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
tuple mantissaPrecision
std::vector< Run3ScoutingVertex > Run3ScoutingVertexCollection
const edm::EDGetTokenT< reco::PFMETCollection > metCollection_
~HLTScoutingPFProducer() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
std::vector< Run3ScoutingPFJet > Run3ScoutingPFJetCollection
JetFloatAssociation::Container JetTagCollection
Definition: JetTag.h:17
tuple pfJetTagCollection
std::vector< Vertex > VertexCollection
Definition: Vertex.h:12
tuple vertexCollection
const edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidateCollection_
tuple pfCandidateCollection
const edm::EDGetTokenT< reco::VertexCollection > vertexCollection_
int iEvent
Definition: GenABIO.cc:224
void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const final
std::vector< Run3ScoutingParticle > Run3ScoutingParticleCollection
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
tuple pfCandidatePtCut
const edm::EDGetTokenT< double > rho_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
tuple pfCandidateEtaCut
static float reduceMantissaToNbitsRounding(const float &f)
Definition: libminifloat.h:79
std::vector< PFJet > PFJetCollection
collection of PFJet objects
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
Collection of PF MET.