Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-06 00:35:21

0001 #ifndef BeamMonitor_H
0002 #define BeamMonitor_H
0003 
0004 /** \class BeamMonitor
0005  * *
0006  *  \author  Geng-yuan Jeng/UC Riverside
0007  *           Francisco Yumiceva/FNAL
0008  *
0009  */
0010 // C++
0011 #include <string>
0012 #include <memory>
0013 // CMS
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0018 #include "DataFormats/VertexReco/interface/Vertex.h"
0019 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0020 #include "DataFormats/TrackReco/interface/Track.h"
0021 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0022 #include "DataFormats/Common/interface/TriggerResults.h"
0023 #include "DQMServices/Core/interface/DQMStore.h"
0024 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0025 #include "RecoVertex/BeamSpotProducer/interface/BSTrkParameters.h"
0026 #include "RecoVertex/BeamSpotProducer/interface/BeamFitter.h"
0027 #include "CondCore/DBOutputService/interface/OnlineDBOutputService.h"
0028 #include "DataFormats/TCDS/interface/BSTRecord.h"
0029 #include "DataFormats/TCDS/interface/TCDSRecord.h"
0030 #include <fstream>
0031 
0032 //
0033 // class declaration
0034 //
0035 
0036 class BeamMonitor : public DQMOneEDAnalyzer<edm::one::WatchLuminosityBlocks> {
0037 public:
0038   BeamMonitor(const edm::ParameterSet&);
0039 
0040 protected:
0041   // BeginRun
0042   void dqmBeginRun(edm::Run const&, edm::EventSetup const&) override;
0043 
0044   void bookHistograms(DQMStore::IBooker& i, const edm::Run& r, const edm::EventSetup& c) override;
0045 
0046   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0047 
0048   void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& context) override;
0049 
0050   void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c) override;
0051   // EndRun
0052   void dqmEndRun(const edm::Run& r, const edm::EventSetup& c) override;
0053 
0054 private:
0055   void FitAndFill(const edm::LuminosityBlock& lumiSeg, int&, int&, int&);
0056   void RestartFitting();
0057   void scrollTH1(TH1*, std::time_t);
0058   bool testScroll(std::time_t&, std::time_t&);
0059   void formatFitTime(char*, const std::time_t&);
0060   std::string getGMTstring(const std::time_t&);
0061 
0062   const int dxBin_;
0063   const double dxMin_;
0064   const double dxMax_;
0065 
0066   const int vxBin_;
0067   const double vxMin_;
0068   const double vxMax_;
0069 
0070   const int phiBin_;
0071   const double phiMin_;
0072   const double phiMax_;
0073 
0074   const int dzBin_;
0075   const double dzMin_;
0076   const double dzMax_;
0077   std::string monitorName_;
0078   std::string recordName_;                  // output BeamSpotOnline Record name
0079   edm::EDGetTokenT<reco::BeamSpot> bsSrc_;  // beam spot
0080   edm::EDGetTokenT<reco::TrackCollection> tracksLabel_;
0081   edm::EDGetTokenT<reco::VertexCollection> pvSrc_;                      // primary vertex
0082   edm::EDGetTokenT<edm::TriggerResults> hltSrc_;                        //hlt collection
0083   edm::Service<cond::service::OnlineDBOutputService> onlineDbService_;  // DB service
0084   int DBloggerReturn_;                                                  // DB logger return value
0085 
0086   int fitNLumi_;
0087   int fitPVNLumi_;
0088   int resetFitNLumi_;
0089   int resetPVNLumi_;
0090   int intervalInSec_;
0091   bool debug_;
0092   bool onlineMode_;
0093   std::vector<std::string> jetTrigger_;
0094 
0095   std::unique_ptr<BeamFitter> theBeamFitter;
0096 
0097   int countEvt_;   //counter
0098   int countLumi_;  //counter
0099   int beginLumiOfBSFit_;
0100   int endLumiOfBSFit_;
0101   int beginLumiOfPVFit_;
0102   int endLumiOfPVFit_;
0103   int lastlumi_;  // previous LS processed
0104   int nextlumi_;  // next LS of Fit
0105   std::time_t refBStime[2];
0106   std::time_t refPVtime[2];
0107   unsigned int nthBSTrk_;
0108   int nFitElements_;
0109   int nFits_;
0110   double deltaSigCut_;
0111   unsigned int min_Ntrks_;
0112   double maxZ_;
0113   unsigned int minNrVertices_;
0114   double minVtxNdf_;
0115   double minVtxWgt_;
0116 
0117   bool resetHistos_;
0118   bool StartAverage_;
0119   int firstAverageFit_;
0120   int countGapLumi_;
0121 
0122   bool processed_;
0123   bool useLockRecords_;
0124 
0125   int nAnalyzedLS_;
0126   int nLS_for_upload_;
0127 
0128   edm::EDGetTokenT<TCDSRecord> tcdsToken_;
0129   bool logToDb_;
0130   bool loggerActive_;
0131 
0132   // ----------member data ---------------------------
0133 
0134   //   std::vector<BSTrkParameters> fBSvector;
0135   reco::BeamSpot refBS;
0136   reco::BeamSpot preBS;
0137 
0138   // MonitorElements:
0139   MonitorElement* h_nTrk_lumi;
0140   MonitorElement* h_nVtx_lumi;
0141   MonitorElement* h_nVtx_lumi_all;
0142   MonitorElement* h_d0_phi0;
0143   MonitorElement* h_trk_z0;
0144   MonitorElement* h_vx_vy;
0145   MonitorElement* h_vx_dz;
0146   MonitorElement* h_vy_dz;
0147   MonitorElement* h_trkPt;
0148   MonitorElement* h_trkVz;
0149   MonitorElement* fitResults;
0150   MonitorElement* h_x0;
0151   MonitorElement* h_y0;
0152   MonitorElement* h_z0;
0153   MonitorElement* h_sigmaX0;
0154   MonitorElement* h_sigmaY0;
0155   MonitorElement* h_sigmaZ0;
0156   MonitorElement* h_nVtx;
0157   MonitorElement* h_nVtx_st;
0158   MonitorElement* h_PVx[2];
0159   MonitorElement* h_PVy[2];
0160   MonitorElement* h_PVz[2];
0161   MonitorElement* h_PVxz;
0162   MonitorElement* h_PVyz;
0163   MonitorElement* pvResults;
0164   std::vector<MonitorElement*> hs;
0165 
0166   // The histo of the primary vertex for  DQM gui
0167   std::map<int, std::vector<float> > mapPVx, mapPVy, mapPVz;
0168   std::map<int, std::vector<int> > mapNPV;
0169   //keep track of beginLuminosity block and time
0170   std::map<int, int> mapBeginBSLS, mapBeginPVLS;
0171   std::map<int, std::time_t> mapBeginBSTime, mapBeginPVTime;
0172   //these maps are needed to keep track of size of theBSvector and pvStore
0173   std::map<int, std::size_t> mapLSBSTrkSize;
0174   std::map<int, size_t> mapLSPVStoreSize;
0175   //to correct the cutFlot Table
0176   std::map<int, TH1F> mapLSCF;
0177 
0178   // Summary:
0179   Float_t reportSummary_;
0180   Float_t summarySum_;
0181   Float_t summaryContent_[3];
0182   MonitorElement* reportSummary;
0183   MonitorElement* reportSummaryContents[3];
0184   MonitorElement* reportSummaryMap;
0185   MonitorElement* cutFlowTable;
0186   // variables for beam fit
0187 
0188   //
0189   std::time_t tmpTime;
0190   std::time_t startTime;
0191   std::time_t refTime;
0192   edm::TimeValue_t ftimestamp;
0193   // Current run
0194   int frun;
0195   int lastNZbin;  // last non zero bin of time histos
0196 };
0197 
0198 #endif
0199 
0200 // Local Variables:
0201 // show-trailing-whitespace: t
0202 // truncate-lines: t
0203 // End: