Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-04 01:25:53

0001 // -*- C++ -*-
0002 ///bookLayer
0003 // Package:    SiPixelPhase1MonitorVertexSoA
0004 // Class:      SiPixelPhase1MonitorVertexSoA
0005 //
0006 /**\class SiPixelPhase1MonitorVertexSoA SiPixelPhase1MonitorVertexSoA.cc 
0007 */
0008 //
0009 // Author: Suvankar Roy Chowdhury
0010 //
0011 #include "FWCore/Framework/interface/Frameworkfwd.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/ServiceRegistry/interface/Service.h"
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019 #include "DataFormats/Common/interface/Handle.h"
0020 // DQM Histograming
0021 #include "DQMServices/Core/interface/MonitorElement.h"
0022 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0023 #include "DQMServices/Core/interface/DQMStore.h"
0024 #include "CUDADataFormats/Vertex/interface/ZVertexHeterogeneous.h"
0025 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0026 
0027 class SiPixelPhase1MonitorVertexSoA : public DQMEDAnalyzer {
0028 public:
0029   using IndToEdm = std::vector<uint16_t>;
0030   explicit SiPixelPhase1MonitorVertexSoA(const edm::ParameterSet&);
0031   ~SiPixelPhase1MonitorVertexSoA() override = default;
0032   void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
0033   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0034   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0035 
0036 private:
0037   edm::EDGetTokenT<ZVertexHeterogeneous> tokenSoAVertex_;
0038   edm::EDGetTokenT<reco::BeamSpot> tokenBeamSpot_;
0039   std::string topFolderName_;
0040   MonitorElement* hnVertex;
0041   MonitorElement* hx;
0042   MonitorElement* hy;
0043   MonitorElement* hz;
0044   MonitorElement* hchi2;
0045   MonitorElement* hchi2oNdof;
0046   MonitorElement* hptv2;
0047   MonitorElement* hntrks;
0048 };
0049 
0050 //
0051 // constructors
0052 //
0053 
0054 SiPixelPhase1MonitorVertexSoA::SiPixelPhase1MonitorVertexSoA(const edm::ParameterSet& iConfig) {
0055   tokenSoAVertex_ = consumes<ZVertexHeterogeneous>(iConfig.getParameter<edm::InputTag>("pixelVertexSrc"));
0056   tokenBeamSpot_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotSrc"));
0057   topFolderName_ = iConfig.getParameter<std::string>("topFolderName");
0058 }
0059 
0060 //
0061 // -- Analyze
0062 //
0063 void SiPixelPhase1MonitorVertexSoA::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0064   const auto& vsoaHandle = iEvent.getHandle(tokenSoAVertex_);
0065   if (!vsoaHandle.isValid()) {
0066     edm::LogWarning("SiPixelPhase1MonitorTrackSoA") << "No Vertex SoA found \n returning!" << std::endl;
0067     return;
0068   }
0069 
0070   auto const& vsoa = *((vsoaHandle.product())->get());
0071   int nVertices = vsoa.nvFinal;
0072   auto bsHandle = iEvent.getHandle(tokenBeamSpot_);
0073   float x0 = 0., y0 = 0., z0 = 0., dxdz = 0., dydz = 0.;
0074   if (!bsHandle.isValid()) {
0075     edm::LogWarning("PixelVertexProducer") << "No beamspot found. returning vertexes with (0,0,Z) ";
0076   } else {
0077     const reco::BeamSpot& bs = *bsHandle;
0078     x0 = bs.x0();
0079     y0 = bs.y0();
0080     z0 = bs.z0();
0081     dxdz = bs.dxdz();
0082     dydz = bs.dydz();
0083   }
0084   for (int iv = 0; iv < nVertices; iv++) {
0085     auto si = vsoa.sortInd[iv];
0086     auto z = vsoa.zv[si];
0087     auto x = x0 + dxdz * z;
0088     auto y = y0 + dydz * z;
0089     z += z0;
0090     hx->Fill(x);
0091     hy->Fill(y);
0092     hz->Fill(z);
0093     auto ndof = vsoa.ndof[si];
0094     hchi2->Fill(vsoa.chi2[si]);
0095     hchi2oNdof->Fill(vsoa.chi2[si] / ndof);
0096     hptv2->Fill(vsoa.ptv2[si]);
0097     hntrks->Fill(ndof + 1);
0098   }
0099   hnVertex->Fill(nVertices);
0100 }
0101 
0102 //
0103 // -- Book Histograms
0104 //
0105 void SiPixelPhase1MonitorVertexSoA::bookHistograms(DQMStore::IBooker& ibooker,
0106                                                    edm::Run const& iRun,
0107                                                    edm::EventSetup const& iSetup) {
0108   //std::string top_folder = ""//
0109   ibooker.cd();
0110   ibooker.setCurrentFolder(topFolderName_);
0111   hnVertex = ibooker.book1D("nVertex", ";# of Vertex;#entries", 101, -0.5, 100.5);
0112   hx = ibooker.book1D("vx", ";Vertex x;#entries", 10, -5., 5.);
0113   hy = ibooker.book1D("vy", ";Vertex y;#entries", 10, -5., 5.);
0114   hz = ibooker.book1D("vz", ";Vertex z;#entries", 30, -30., 30);
0115   hchi2 = ibooker.book1D("chi2", ";Vertex chi-squared;#entries", 40, 0., 20.);
0116   hchi2oNdof = ibooker.book1D("chi2oNdof", ";Vertex chi-squared/Ndof;#entries", 40, 0., 20.);
0117   hptv2 = ibooker.book1D("ptsq", ";Vertex p_T squared;#entries", 200, 0., 200.);
0118   hntrks = ibooker.book1D("ntrk", ";#tracks associated;#entries", 100, -0.5, 99.5);
0119 }
0120 
0121 void SiPixelPhase1MonitorVertexSoA::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0122   // monitorpixelVertexSoA
0123   edm::ParameterSetDescription desc;
0124   desc.add<edm::InputTag>("pixelVertexSrc", edm::InputTag("pixelVerticesSoA"));
0125   desc.add<edm::InputTag>("beamSpotSrc", edm::InputTag("offlineBeamSpot"));
0126   desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelVertexSoA");
0127   descriptions.addWithDefaultLabel(desc);
0128 }
0129 DEFINE_FWK_MODULE(SiPixelPhase1MonitorVertexSoA);