Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-28 01:32:27

0001 // -*- C++ -*-
0002 //
0003 // Package:    HLTrigger/JetMET
0004 // Class:      HLTScoutingPrimaryVertexProducer
0005 //
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/global/EDProducer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "DataFormats/VertexReco/interface/Vertex.h"
0013 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0014 #include "DataFormats/Scouting/interface/Run3ScoutingVertex.h"
0015 #include "DataFormats/Math/interface/libminifloat.h"
0016 
0017 #include <memory>
0018 #include <utility>
0019 
0020 class HLTScoutingPrimaryVertexProducer : public edm::global::EDProducer<> {
0021 public:
0022   explicit HLTScoutingPrimaryVertexProducer(const edm::ParameterSet&);
0023 
0024   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0025 
0026 private:
0027   void produce(edm::StreamID sid, edm::Event& iEvent, edm::EventSetup const& setup) const final;
0028 
0029   edm::EDGetTokenT<reco::VertexCollection> const vertexCollToken_;
0030   int const mantissaPrecision_;
0031 };
0032 
0033 HLTScoutingPrimaryVertexProducer::HLTScoutingPrimaryVertexProducer(const edm::ParameterSet& iConfig)
0034     : vertexCollToken_(consumes(iConfig.getParameter<edm::InputTag>("vertexCollection"))),
0035       mantissaPrecision_(iConfig.getParameter<int>("mantissaPrecision")) {
0036   produces<Run3ScoutingVertexCollection>("primaryVtx");
0037 }
0038 
0039 void HLTScoutingPrimaryVertexProducer::produce(edm::StreamID sid,
0040                                                edm::Event& iEvent,
0041                                                edm::EventSetup const& setup) const {
0042   auto outVertices = std::make_unique<Run3ScoutingVertexCollection>();
0043 
0044   auto const vertexCollHandle = iEvent.getHandle(vertexCollToken_);
0045 
0046   if (vertexCollHandle.isValid()) {
0047     outVertices->reserve(vertexCollHandle->size());
0048     for (auto const& vtx : *vertexCollHandle) {
0049       outVertices->emplace_back(MiniFloatConverter::reduceMantissaToNbitsRounding(vtx.x(), mantissaPrecision_),
0050                                 MiniFloatConverter::reduceMantissaToNbitsRounding(vtx.y(), mantissaPrecision_),
0051                                 MiniFloatConverter::reduceMantissaToNbitsRounding(vtx.z(), mantissaPrecision_),
0052                                 MiniFloatConverter::reduceMantissaToNbitsRounding(vtx.zError(), mantissaPrecision_),
0053                                 MiniFloatConverter::reduceMantissaToNbitsRounding(vtx.xError(), mantissaPrecision_),
0054                                 MiniFloatConverter::reduceMantissaToNbitsRounding(vtx.yError(), mantissaPrecision_),
0055                                 vtx.tracksSize(),
0056                                 MiniFloatConverter::reduceMantissaToNbitsRounding(vtx.chi2(), mantissaPrecision_),
0057                                 vtx.ndof(),
0058                                 vtx.isValid());
0059     }
0060   }
0061 
0062   iEvent.put(std::move(outVertices), "primaryVtx");
0063 }
0064 
0065 void HLTScoutingPrimaryVertexProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0066   edm::ParameterSetDescription desc;
0067   desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"))
0068       ->setComment("InputTag of input collection of primary vertices");
0069   desc.add<int>("mantissaPrecision", 10)->setComment("default float16, change to 23 for float32");
0070   descriptions.addWithDefaultLabel(desc);
0071 }
0072 
0073 DEFINE_FWK_MODULE(HLTScoutingPrimaryVertexProducer);