Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-04 00:01:58

0001 // -*- C++ -*-
0002 //
0003 // Package:    BeamProfile2DBWriter
0004 // Class:      BeamProfile2DBWriter
0005 //
0006 /**\class BeamProfile2DBWriter BeamProfile2DBWriter.cc CondTools/BeamSpot/plugins/BeamProfile2DBWriter.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Jean-Roch Vlimant,40 3-A28,+41227671209,
0015 //         Created:  Fri Jan  6 14:49:42 CET 2012
0016 //
0017 // Updated; Francesco Brivio, June 11, 2023
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0025 #include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/Frameworkfwd.h"
0028 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/ServiceRegistry/interface/Service.h"
0032 
0033 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0034 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0035 
0036 //
0037 // class declaration
0038 //
0039 class BeamProfile2DBWriter : public edm::global::EDAnalyzer<> {
0040 public:
0041   explicit BeamProfile2DBWriter(const edm::ParameterSet&);
0042   ~BeamProfile2DBWriter() override = default;
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046 private:
0047   void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override;
0048   void endJob() override;
0049 
0050   // ----------member data ---------------------------
0051   const std::string recordName_;
0052   SimBeamSpotObjects beamSpot_;
0053 };
0054 
0055 //
0056 // constructors and destructor
0057 //
0058 BeamProfile2DBWriter::BeamProfile2DBWriter(const edm::ParameterSet& iConfig)
0059     : recordName_(iConfig.getParameter<std::string>("recordName")) {
0060   beamSpot_.setX(iConfig.getParameter<double>("X0"));
0061   beamSpot_.setY(iConfig.getParameter<double>("Y0"));
0062   beamSpot_.setZ(iConfig.getParameter<double>("Z0"));
0063   beamSpot_.setMeanX(iConfig.getParameter<double>("MeanX"));
0064   beamSpot_.setMeanY(iConfig.getParameter<double>("MeanY"));
0065   beamSpot_.setMeanZ(iConfig.getParameter<double>("MeanZ"));
0066   beamSpot_.setSigmaX(iConfig.getParameter<double>("SigmaX"));
0067   beamSpot_.setSigmaY(iConfig.getParameter<double>("SigmaY"));
0068   beamSpot_.setSigmaZ(iConfig.getParameter<double>("SigmaZ"));
0069   beamSpot_.setAlpha(iConfig.getParameter<double>("Alpha"));
0070   beamSpot_.setPhi(iConfig.getParameter<double>("Phi"));
0071   beamSpot_.setBetaStar(iConfig.getParameter<double>("BetaStar"));
0072   beamSpot_.setEmittance(iConfig.getParameter<double>("Emittance"));
0073   beamSpot_.setTimeOffset(iConfig.getParameter<double>("TimeOffset"));
0074 }
0075 
0076 //
0077 // member functions
0078 //
0079 
0080 // ------------ method called for each event  ------------
0081 void BeamProfile2DBWriter::analyze(edm::StreamID, const edm::Event& iEvent, const edm::EventSetup& iSetup) const {}
0082 
0083 // ------------ method called once each job just after ending the event loop  ------------
0084 void BeamProfile2DBWriter::endJob() {
0085   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0086   poolDbService->createOneIOV<SimBeamSpotObjects>(beamSpot_, poolDbService->beginOfTime(), recordName_);
0087 }
0088 
0089 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0090 void BeamProfile2DBWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0091   //The following says we do not know what parameters are allowed so do no validation
0092   // Please change this to state exactly what you do use, even if it is no parameters
0093   edm::ParameterSetDescription desc;
0094   desc.add<std::string>("recordName", "SimBeamSpotObjectsRcd")
0095       ->setComment("name of the record to use for the PoolDBOutputService");
0096   desc.add<double>("X0", 0.0)->setComment("in cm");
0097   desc.add<double>("Y0", 0.0)->setComment("in cm");
0098   desc.add<double>("Z0", 0.0)->setComment("in cm");
0099   desc.add<double>("MeanX", 0.0)->setComment("in cm");
0100   desc.add<double>("MeanY", 0.0)->setComment("in cm");
0101   desc.add<double>("MeanZ", 0.0)->setComment("in cm");
0102   desc.add<double>("SigmaX", -1.0)->setComment("in cm");
0103   desc.add<double>("SigmaY", -1.0)->setComment("in cm");
0104   desc.add<double>("SigmaZ", 0.0)->setComment("in cm");
0105   desc.add<double>("BetaStar", 0.0)->setComment("in cm");
0106   desc.add<double>("Emittance", 0.0)->setComment("in cm");
0107   desc.add<double>("Alpha", 0.0)->setComment("in radians");
0108   desc.add<double>("Phi", 0.0)->setComment("in radians");
0109   desc.add<double>("TimeOffset", 0.0)->setComment("in ns");
0110   descriptions.addWithDefaultLabel(desc);
0111 }
0112 
0113 //define this as a plug-in
0114 DEFINE_FWK_MODULE(BeamProfile2DBWriter);