Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-11 04:34:00

0001 // -*- C++ -*-
0002 //
0003 // Package:    BeamProfile2DB
0004 // Class:      BeamProfile2DB
0005 //
0006 /**\class BeamProfile2DB BeamProfile2DB.cc IOMC/BeamProfile2DB/src/BeamProfile2DB.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 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 #include "FWCore/ServiceRegistry/interface/Service.h"
0033 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0034 #include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h"
0035 
0036 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0037 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0038 
0039 //
0040 // class declaration
0041 //
0042 
0043 class BeamProfile2DB : public edm::global::EDAnalyzer<> {
0044 public:
0045   explicit BeamProfile2DB(const edm::ParameterSet&);
0046   ~BeamProfile2DB() override;
0047 
0048   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0049 
0050 private:
0051   void beginJob() override;
0052   void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override;
0053   void endJob() override;
0054 
0055   // ----------member data ---------------------------
0056   SimBeamSpotObjects beamSpot_;
0057 };
0058 
0059 namespace {
0060   SimBeamSpotObjects read(const edm::ParameterSet& p) {
0061     SimBeamSpotObjects ret;
0062     ret.fX0 = p.getParameter<double>("X0") * cm;
0063     ret.fY0 = p.getParameter<double>("Y0") * cm;
0064     ret.fZ0 = p.getParameter<double>("Z0") * cm;
0065     ret.fSigmaZ = p.getParameter<double>("SigmaZ") * cm;
0066     ret.fAlpha = p.getParameter<double>("Alpha") * radian;
0067     ret.fPhi = p.getParameter<double>("Phi") * radian;
0068     ret.fbetastar = p.getParameter<double>("BetaStar") * cm;
0069     ret.femittance = p.getParameter<double>("Emittance") * cm;              // this is not the normalized emittance
0070     ret.fTimeOffset = p.getParameter<double>("TimeOffset") * ns * c_light;  // HepMC time units are mm
0071     return ret;
0072   }
0073 
0074 }  // namespace
0075 //
0076 // constants, enums and typedefs
0077 //
0078 
0079 //
0080 // static data member definitions
0081 //
0082 
0083 //
0084 // constructors and destructor
0085 //
0086 BeamProfile2DB::BeamProfile2DB(const edm::ParameterSet& iConfig) : beamSpot_(read(iConfig)) {}
0087 
0088 BeamProfile2DB::~BeamProfile2DB() {
0089   // do anything here that needs to be done at desctruction time
0090   // (e.g. close files, deallocate resources etc.)
0091 }
0092 
0093 //
0094 // member functions
0095 //
0096 
0097 // ------------ method called for each event  ------------
0098 void BeamProfile2DB::analyze(edm::StreamID, const edm::Event& iEvent, const edm::EventSetup& iSetup) const {}
0099 
0100 // ------------ method called once each job just before starting event loop  ------------
0101 void BeamProfile2DB::beginJob() {}
0102 
0103 // ------------ method called once each job just after ending the event loop  ------------
0104 void BeamProfile2DB::endJob() {
0105   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0106   poolDbService->createOneIOV<SimBeamSpotObjects>(beamSpot_, poolDbService->beginOfTime(), "SimBeamSpotObjectsRcd");
0107 }
0108 
0109 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0110 void BeamProfile2DB::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0111   //The following says we do not know what parameters are allowed so do no validation
0112   // Please change this to state exactly what you do use, even if it is no parameters
0113   edm::ParameterSetDescription desc;
0114   desc.add<double>("X0")->setComment("in cm");
0115   desc.add<double>("Y0")->setComment("in cm");
0116   desc.add<double>("Z0")->setComment("in cm");
0117   desc.add<double>("SigmaZ")->setComment("in cm");
0118   desc.add<double>("BetaStar")->setComment("in cm");
0119   desc.add<double>("Emittance")->setComment("in cm");
0120   desc.add<double>("Alpha")->setComment("in radians");
0121   desc.add<double>("Phi")->setComment("in radians");
0122   desc.add<double>("TimeOffset")->setComment("in ns");
0123   descriptions.addDefault(desc);
0124 }
0125 
0126 //define this as a plug-in
0127 DEFINE_FWK_MODULE(BeamProfile2DB);