Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:52

0001 /****************************************************************************
0002  *
0003  *  CondFormats/PPSObjects/plugins/CTPPSBeamParametersESSource.cc
0004  *
0005  *  Description :  - Loads CTPPSBeamParameters from the CTPPSBeamParametersESSource_cfi.py
0006  *                   config file.
0007  *                 - Currently, one single set of beam parameters is provided. Just to be
0008  *                   ready in time for 10_4_0 and allow simple tests.
0009  *                 - To be further developed to provide multiple sets of parameters
0010  *                 - Needed while CTPPSBeamParameters is not available in database
0011  *
0012  *
0013  * Author:
0014  * Wagner Carvalho wcarvalh@cern.ch
0015  *
0016  ****************************************************************************/
0017 
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/Framework/interface/SourceFactory.h"
0020 #include "FWCore/Framework/interface/ModuleFactory.h"
0021 
0022 #include "FWCore/Framework/interface/ESHandle.h"
0023 #include "FWCore/Framework/interface/ESProducer.h"
0024 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0025 #include "FWCore/Framework/interface/ESProducts.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 
0029 #include "CondFormats/PPSObjects/interface/CTPPSBeamParameters.h"
0030 #include "CondFormats/DataRecord/interface/CTPPSBeamParametersRcd.h"
0031 
0032 #include <memory>
0033 
0034 //----------------------------------------------------------------------------------------------------
0035 
0036 using namespace std;
0037 
0038 /**
0039  * \brief Loads CTPPSBeamParameters from a config file.
0040  **/
0041 
0042 class CTPPSBeamParametersESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0043 public:
0044   CTPPSBeamParametersESSource(const edm::ParameterSet&);
0045   ~CTPPSBeamParametersESSource() override = default;
0046 
0047   std::unique_ptr<CTPPSBeamParameters> produce(const CTPPSBeamParametersRcd&);
0048   static void fillDescriptions(edm::ConfigurationDescriptions&);
0049 
0050 private:
0051   bool setBeamPars_;
0052 
0053   /// Set BP to their values from config
0054   void setBeamParameters(const edm::ParameterSet&);
0055   ///  Fill CTPPSBeamParameters object with BP
0056   std::unique_ptr<CTPPSBeamParameters> fillBeamParameters();
0057 
0058   // Beam parameters
0059   double beamMom45_, beamMom56_;
0060   double betaStarX45_, betaStarY45_, betaStarX56_, betaStarY56_;
0061   double beamDivX45_, beamDivY45_, beamDivX56_, beamDivY56_;
0062   double halfXangleX45_, halfXangleY45_;
0063   double halfXangleX56_, halfXangleY56_;
0064   double vtxOffsetX45_, vtxOffsetY45_, vtxOffsetZ45_, vtxOffsetT45_;
0065   double vtxOffsetX56_, vtxOffsetY56_, vtxOffsetZ56_, vtxOffsetT56_;
0066   double vtxStddevX_, vtxStddevY_, vtxStddevZ_, vtxStddevT_;
0067 
0068 protected:
0069   /// sets infinite validity of this data
0070   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0071                       const edm::IOVSyncValue&,
0072                       edm::ValidityInterval&) override;
0073 };
0074 
0075 //----------------------------------------------------------------------------------------------------
0076 
0077 CTPPSBeamParametersESSource::CTPPSBeamParametersESSource(const edm::ParameterSet& iConfig)
0078     : setBeamPars_(iConfig.getParameter<bool>("setBeamPars")),
0079       beamMom45_(0.),
0080       beamMom56_(0.),
0081       betaStarX45_(0.),
0082       betaStarY45_(0.),
0083       betaStarX56_(0.),
0084       betaStarY56_(0.),
0085       beamDivX45_(0.),
0086       beamDivY45_(0.),
0087       beamDivX56_(0.),
0088       beamDivY56_(0.),
0089       halfXangleX45_(0.),
0090       halfXangleY45_(0.),
0091       halfXangleX56_(0.),
0092       halfXangleY56_(0.),
0093       vtxOffsetX45_(0.),
0094       vtxOffsetY45_(0.),
0095       vtxOffsetZ45_(0.),
0096       vtxOffsetT45_(0.),
0097       vtxOffsetX56_(0.),
0098       vtxOffsetY56_(0.),
0099       vtxOffsetZ56_(0.),
0100       vtxOffsetT56_(0.),
0101       vtxStddevX_(0.),
0102       vtxStddevY_(0.),
0103       vtxStddevZ_(0.),
0104       vtxStddevT_(0.) {
0105   if (setBeamPars_)
0106     setBeamParameters(iConfig);
0107 
0108   setWhatProduced(this);
0109   findingRecord<CTPPSBeamParametersRcd>();
0110 }
0111 
0112 //----------------------------------------------------------------------------------------------------
0113 
0114 std::unique_ptr<CTPPSBeamParameters> CTPPSBeamParametersESSource::produce(const CTPPSBeamParametersRcd&) {
0115   // If beam parameters are available from the config file, fill their values into CTPPSBeamParameters object
0116   auto bp = (setBeamPars_) ? fillBeamParameters() : std::make_unique<CTPPSBeamParameters>();
0117 
0118   edm::LogInfo("CTPPSBeamParametersESSource::produce") << "\n" << *bp;
0119 
0120   return bp;
0121 }
0122 
0123 //----------------------------------------------------------------------------------------------------
0124 
0125 void CTPPSBeamParametersESSource::setBeamParameters(const edm::ParameterSet& iConfig) {
0126   beamMom45_ = iConfig.getParameter<double>("beamMom45");
0127   beamMom56_ = iConfig.getParameter<double>("beamMom56");
0128   betaStarX45_ = iConfig.getParameter<double>("betaStarX45");
0129   betaStarX56_ = iConfig.getParameter<double>("betaStarX56");
0130   betaStarY45_ = iConfig.getParameter<double>("betaStarY45");
0131   betaStarY56_ = iConfig.getParameter<double>("betaStarY56");
0132   beamDivX45_ = iConfig.getParameter<double>("beamDivX45");
0133   beamDivX56_ = iConfig.getParameter<double>("beamDivX56");
0134   beamDivY45_ = iConfig.getParameter<double>("beamDivY45");
0135   beamDivY56_ = iConfig.getParameter<double>("beamDivY56");
0136   halfXangleX45_ = iConfig.getParameter<double>("halfXangleX45");
0137   halfXangleX56_ = iConfig.getParameter<double>("halfXangleX56");
0138   halfXangleY45_ = iConfig.getParameter<double>("halfXangleY45");
0139   halfXangleY56_ = iConfig.getParameter<double>("halfXangleY56");
0140   vtxOffsetX45_ = iConfig.getParameter<double>("vtxOffsetX45");
0141   vtxOffsetY45_ = iConfig.getParameter<double>("vtxOffsetY45");
0142   vtxOffsetZ45_ = iConfig.getParameter<double>("vtxOffsetZ45");
0143   vtxOffsetT45_ = iConfig.getParameter<double>("vtxOffsetT45");
0144   vtxOffsetX56_ = iConfig.getParameter<double>("vtxOffsetX56");
0145   vtxOffsetY56_ = iConfig.getParameter<double>("vtxOffsetY56");
0146   vtxOffsetZ56_ = iConfig.getParameter<double>("vtxOffsetZ56");
0147   vtxOffsetT56_ = iConfig.getParameter<double>("vtxOffsetT56");
0148   vtxStddevX_ = iConfig.getParameter<double>("vtxStddevX");
0149   vtxStddevY_ = iConfig.getParameter<double>("vtxStddevY");
0150   vtxStddevZ_ = iConfig.getParameter<double>("vtxStddevZ");
0151   vtxStddevT_ = iConfig.getParameter<double>("vtxStddevT");
0152 }
0153 
0154 //----------------------------------------------------------------------------------------------------
0155 
0156 std::unique_ptr<CTPPSBeamParameters> CTPPSBeamParametersESSource::fillBeamParameters() {
0157   auto p = std::make_unique<CTPPSBeamParameters>();
0158 
0159   p->setBeamMom45(beamMom45_);
0160   p->setBeamMom56(beamMom56_);
0161 
0162   p->setBetaStarX45(betaStarX45_);
0163   p->setBetaStarY45(betaStarY45_);
0164   p->setBetaStarX56(betaStarX56_);
0165   p->setBetaStarY56(betaStarY56_);
0166 
0167   p->setBeamDivergenceX45(beamDivX45_);
0168   p->setBeamDivergenceY45(beamDivY45_);
0169   p->setBeamDivergenceX56(beamDivX56_);
0170   p->setBeamDivergenceY56(beamDivY56_);
0171 
0172   p->setHalfXangleX45(halfXangleX45_);
0173   p->setHalfXangleY45(halfXangleY45_);
0174   p->setHalfXangleX56(halfXangleX56_);
0175   p->setHalfXangleY56(halfXangleY56_);
0176 
0177   p->setVtxOffsetX45(vtxOffsetX45_);
0178   p->setVtxOffsetY45(vtxOffsetY45_);
0179   p->setVtxOffsetZ45(vtxOffsetZ45_);
0180   p->setVtxOffsetT45(vtxOffsetT45_);
0181   p->setVtxOffsetX56(vtxOffsetX56_);
0182   p->setVtxOffsetY56(vtxOffsetY56_);
0183   p->setVtxOffsetZ56(vtxOffsetZ56_);
0184   p->setVtxOffsetT56(vtxOffsetT56_);
0185 
0186   p->setVtxStddevX(vtxStddevX_);
0187   p->setVtxStddevY(vtxStddevY_);
0188   p->setVtxStddevZ(vtxStddevZ_);
0189   p->setVtxStddevT(vtxStddevT_);
0190 
0191   return p;
0192 }
0193 
0194 //----------------------------------------------------------------------------------------------------
0195 
0196 void CTPPSBeamParametersESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& key,
0197                                                  const edm::IOVSyncValue& iosv,
0198                                                  edm::ValidityInterval& oValidity) {
0199   edm::LogInfo("CTPPSBeamParametersESSource")
0200       << ">> CTPPSBeamParametersESSource::setIntervalFor(" << key.name() << ")\n"
0201       << "    run=" << iosv.eventID().run() << ", event=" << iosv.eventID().event();
0202 
0203   edm::ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime());
0204   oValidity = infinity;
0205 }
0206 
0207 //----------------------------------------------------------------------------------------------------
0208 
0209 void CTPPSBeamParametersESSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0210   edm::ParameterSetDescription desc;
0211   desc.add<bool>("setBeamPars", true);
0212   // beam momentum (GeV)
0213   desc.add<double>("beamMom45", 6500.);
0214   desc.add<double>("beamMom56", 6500.);
0215   // beta* (cm)
0216   desc.add<double>("betaStarX45", 30.);
0217   desc.add<double>("betaStarY45", 30.);
0218   desc.add<double>("betaStarX56", 30.);
0219   desc.add<double>("betaStarY56", 30.);
0220   // beam divergence (rad)
0221   desc.add<double>("beamDivX45", 0.1);
0222   desc.add<double>("beamDivY45", 0.1);
0223   desc.add<double>("beamDivX56", 0.1);
0224   desc.add<double>("beamDivY56", 0.1);
0225   // half crossing angle (rad)
0226   desc.add<double>("halfXangleX45", 80.e-6);
0227   desc.add<double>("halfXangleY45", 80.e-6);
0228   desc.add<double>("halfXangleX56", 80.e-6);
0229   desc.add<double>("halfXangleY56", 80.e-6);
0230   // vertex offset (cm)
0231   desc.add<double>("vtxOffsetX45", 1.e-2);
0232   desc.add<double>("vtxOffsetY45", 1.e-2);
0233   desc.add<double>("vtxOffsetZ45", 1.e-2);
0234   desc.add<double>("vtxOffsetT45", 1.e-2);
0235   desc.add<double>("vtxOffsetX56", 1.e-2);
0236   desc.add<double>("vtxOffsetY56", 1.e-2);
0237   desc.add<double>("vtxOffsetZ56", 1.e-2);
0238   desc.add<double>("vtxOffsetT56", 1.e-2);
0239   // vertex sigma (cm)
0240   desc.add<double>("vtxStddevX", 2.e-2);
0241   desc.add<double>("vtxStddevY", 2.e-2);
0242   desc.add<double>("vtxStddevZ", 2.e-2);
0243   desc.add<double>("vtxStddevT", 2.e-2);
0244 
0245   descriptions.add("ctppsBeamParametersESSource", desc);
0246 }
0247 
0248 //----------------------------------------------------------------------------------------------------
0249 
0250 DEFINE_FWK_EVENTSETUP_SOURCE(CTPPSBeamParametersESSource);