Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-22 05:03:06

0001 #ifndef DQM_BeamMonitor_AlcaBeamMonitor_h
0002 #define DQM_BeamMonitor_AlcaBeamMonitor_h
0003 
0004 /** \class AlcaBeamMonitor
0005  * *
0006  *  \author  Lorenzo Uplegger/FNAL
0007  *   modified by Simone Gennai INFN/Bicocca
0008  */
0009 // C++
0010 #include <map>
0011 #include <array>
0012 #include <vector>
0013 #include <string>
0014 #include <utility>
0015 
0016 // CMS
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/Utilities/interface/ESGetToken.h"
0021 #include "DQMServices/Core/interface/DQMStore.h"
0022 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0023 #include "DataFormats/Provenance/interface/LuminosityBlockID.h"
0024 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0025 #include "DataFormats/VertexReco/interface/Vertex.h"
0026 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0027 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
0028 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
0029 
0030 class BeamFitter;
0031 class PVFitter;
0032 
0033 namespace alcabeammonitor {
0034 
0035   struct pvPosAndErr {
0036     // Array of pairs: (value, error) for x, y, z
0037     std::array<std::pair<double, double>, 3> data;
0038 
0039     // Constructor initializes the array with values and errors from a reco::Vertex
0040     pvPosAndErr(const reco::Vertex& vertex)
0041         : data{{{vertex.x(), vertex.xError()}, {vertex.y(), vertex.yError()}, {vertex.z(), vertex.zError()}}} {}
0042 
0043     // Accessor functions that return pairs (value, error) directly
0044     std::pair<double, double> xWithError() const { return data[0]; }
0045     std::pair<double, double> yWithError() const { return data[1]; }
0046     std::pair<double, double> zWithError() const { return data[2]; }
0047   };
0048 
0049   struct BeamSpotInfo {
0050     std::vector<std::vector<pvPosAndErr>> vertices_;
0051     typedef std::map<std::string, reco::BeamSpot> BeamSpotContainer;
0052     BeamSpotContainer beamSpotMap_;
0053   };
0054 }  // namespace alcabeammonitor
0055 
0056 class AlcaBeamMonitor : public DQMOneEDAnalyzer<edm::LuminosityBlockCache<alcabeammonitor::BeamSpotInfo>> {
0057 public:
0058   AlcaBeamMonitor(const edm::ParameterSet&);
0059   static void fillDescriptions(edm::ConfigurationDescriptions&);
0060 
0061 protected:
0062   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0063   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0064   std::shared_ptr<alcabeammonitor::BeamSpotInfo> globalBeginLuminosityBlock(
0065       const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) const override;
0066   void globalEndLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) override;
0067   void dqmEndRun(edm::Run const&, edm::EventSetup const&) override;
0068 
0069 private:
0070   //Typedefs
0071   //                BF,BS...
0072   typedef std::map<std::string, reco::BeamSpot> BeamSpotContainer;
0073   //                x,y,z,sigmax(y,z)... [run,lumi]          Histo name
0074   typedef std::map<std::string, std::map<std::string, std::map<std::string, MonitorElement*>>> HistosContainer;
0075   //                x,y,z,sigmax(y,z)... [run,lumi]          Histo name
0076   typedef std::map<std::string, std::map<std::string, std::map<std::string, int>>> PositionContainer;
0077 
0078   //Parameters
0079   std::string monitorName_;
0080   const edm::EDGetTokenT<reco::VertexCollection> primaryVertexLabel_;
0081   const edm::EDGetTokenT<reco::TrackCollection> trackLabel_;
0082   const edm::EDGetTokenT<reco::BeamSpot> scalerLabel_;
0083   const edm::ESGetToken<BeamSpotObjects, BeamSpotObjectsRcd> beamSpotToken_;
0084   bool perLSsaving_;  //to avoid nanoDQMIO crashing, driven by  DQMServices/Core/python/DQMStore_cfi.py
0085 
0086   //Service variables
0087   int numberOfValuesToSave_;
0088   std::unique_ptr<BeamFitter> theBeamFitter_;
0089   std::unique_ptr<PVFitter> thePVFitter_;
0090   std::vector<int> processedLumis_;
0091 
0092   // MonitorElements:
0093   MonitorElement* hD0Phi0_;
0094   MonitorElement* hDxyBS_;
0095   //mutable MonitorElement* theValuesContainer_;
0096 
0097   //Containers
0098   HistosContainer histosMap_;
0099   PositionContainer positionsMap_;
0100   std::vector<std::string> varNamesV_;                            //x,y,z,sigmax(y,z)
0101   std::multimap<std::string, std::string> histoByCategoryNames_;  //run, lumi
0102 };
0103 
0104 #endif