Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:35

0001 /****************************************************************************
0002  * Authors:
0003  *   Wagner Carvalho wcarvalh@cern.ch
0004  *   Jan Kašpar
0005  ****************************************************************************/
0006 
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Framework/interface/SourceFactory.h"
0009 #include "FWCore/Framework/interface/ModuleFactory.h"
0010 
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/ESProducer.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 
0016 #include "CondTools/RunInfo/interface/LHCInfoCombined.h"
0017 #include "CondFormats/DataRecord/interface/CTPPSBeamParametersRcd.h"
0018 
0019 #include "CondFormats/RunInfo/interface/LHCInfo.h"
0020 
0021 #include "CondFormats/PPSObjects/interface/CTPPSBeamParameters.h"
0022 
0023 //----------------------------------------------------------------------------------------------------
0024 
0025 class CTPPSBeamParametersFromLHCInfoESSource : public edm::ESProducer {
0026 public:
0027   CTPPSBeamParametersFromLHCInfoESSource(const edm::ParameterSet&);
0028   ~CTPPSBeamParametersFromLHCInfoESSource() override = default;
0029 
0030   std::unique_ptr<CTPPSBeamParameters> produce(const CTPPSBeamParametersRcd&);
0031   static void fillDescriptions(edm::ConfigurationDescriptions&);
0032 
0033 private:
0034   edm::ESGetToken<LHCInfo, LHCInfoRcd> lhcInfoToken_;
0035   edm::ESGetToken<LHCInfoPerLS, LHCInfoPerLSRcd> lhcInfoPerLSToken_;
0036   edm::ESGetToken<LHCInfoPerFill, LHCInfoPerFillRcd> lhcInfoPerFillToken_;
0037   const bool useNewLHCInfo_;
0038 
0039   CTPPSBeamParameters defaultParameters_;
0040 };
0041 
0042 //----------------------------------------------------------------------------------------------------
0043 
0044 CTPPSBeamParametersFromLHCInfoESSource::CTPPSBeamParametersFromLHCInfoESSource(const edm::ParameterSet& iConfig)
0045     : useNewLHCInfo_(iConfig.getParameter<bool>("useNewLHCInfo")) {
0046   auto cc = setWhatProduced(this);
0047   lhcInfoToken_ = cc.consumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoLabel")));
0048   lhcInfoPerLSToken_ = cc.consumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoPerLSLabel")));
0049   lhcInfoPerFillToken_ = cc.consumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoPerFillLabel")));
0050 
0051   defaultParameters_.setBeamDivergenceX45(iConfig.getParameter<double>("beamDivX45"));
0052   defaultParameters_.setBeamDivergenceY45(iConfig.getParameter<double>("beamDivX56"));
0053   defaultParameters_.setBeamDivergenceX56(iConfig.getParameter<double>("beamDivY45"));
0054   defaultParameters_.setBeamDivergenceY56(iConfig.getParameter<double>("beamDivY56"));
0055 
0056   defaultParameters_.setVtxOffsetX45(iConfig.getParameter<double>("vtxOffsetX45"));
0057   defaultParameters_.setVtxOffsetY45(iConfig.getParameter<double>("vtxOffsetY45"));
0058   defaultParameters_.setVtxOffsetZ45(iConfig.getParameter<double>("vtxOffsetZ45"));
0059   defaultParameters_.setVtxOffsetX56(iConfig.getParameter<double>("vtxOffsetX56"));
0060   defaultParameters_.setVtxOffsetY56(iConfig.getParameter<double>("vtxOffsetY56"));
0061   defaultParameters_.setVtxOffsetZ56(iConfig.getParameter<double>("vtxOffsetZ56"));
0062 
0063   defaultParameters_.setVtxStddevX(iConfig.getParameter<double>("vtxStddevX"));
0064   defaultParameters_.setVtxStddevY(iConfig.getParameter<double>("vtxStddevY"));
0065   defaultParameters_.setVtxStddevZ(iConfig.getParameter<double>("vtxStddevZ"));
0066 }
0067 
0068 //----------------------------------------------------------------------------------------------------
0069 
0070 std::unique_ptr<CTPPSBeamParameters> CTPPSBeamParametersFromLHCInfoESSource::produce(
0071     const CTPPSBeamParametersRcd& iRecord) {
0072   auto lhcInfoCombined =
0073       LHCInfoCombined::createLHCInfoCombined<CTPPSBeamParametersRcd,
0074                                              edm::mpl::Vector<LHCInfoRcd, LHCInfoPerFillRcd, LHCInfoPerLSRcd>>(
0075           iRecord, lhcInfoPerLSToken_, lhcInfoPerFillToken_, lhcInfoToken_, useNewLHCInfo_);
0076 
0077   auto bp = std::make_unique<CTPPSBeamParameters>(defaultParameters_);
0078 
0079   const auto beamMom = lhcInfoCombined.energy;
0080   const auto betaStar = lhcInfoCombined.betaStarX * 1E2;       // conversion m --> cm
0081   const auto xangle = lhcInfoCombined.crossingAngle() * 1E-6;  // conversion mu rad --> rad
0082 
0083   bp->setBeamMom45(beamMom);
0084   bp->setBeamMom56(beamMom);
0085 
0086   bp->setBetaStarX45(betaStar);
0087   bp->setBetaStarX56(betaStar);
0088   bp->setBetaStarY45(betaStar);
0089   bp->setBetaStarY56(betaStar);
0090 
0091   bp->setHalfXangleX45(xangle);
0092   bp->setHalfXangleX56(xangle);
0093   bp->setHalfXangleY45(xangle);
0094   bp->setHalfXangleY56(xangle);
0095 
0096   return bp;
0097 }
0098 
0099 //----------------------------------------------------------------------------------------------------
0100 
0101 void CTPPSBeamParametersFromLHCInfoESSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0102   edm::ParameterSetDescription desc;
0103 
0104   desc.add<std::string>("lhcInfoLabel", "");
0105   desc.add<std::string>("lhcInfoPerLSLabel", "");
0106   desc.add<std::string>("lhcInfoPerFillLabel", "");
0107   desc.add<bool>("useNewLHCInfo", false);
0108 
0109   // beam divergence (rad)
0110   desc.add<double>("beamDivX45", 0.1);
0111   desc.add<double>("beamDivY45", 0.1);
0112   desc.add<double>("beamDivX56", 0.1);
0113   desc.add<double>("beamDivY56", 0.1);
0114 
0115   // vertex offset (cm)
0116   desc.add<double>("vtxOffsetX45", 1.e-2);
0117   desc.add<double>("vtxOffsetY45", 1.e-2);
0118   desc.add<double>("vtxOffsetZ45", 1.e-2);
0119   desc.add<double>("vtxOffsetX56", 1.e-2);
0120   desc.add<double>("vtxOffsetY56", 1.e-2);
0121   desc.add<double>("vtxOffsetZ56", 1.e-2);
0122 
0123   // vertex sigma (cm)
0124   desc.add<double>("vtxStddevX", 2.e-2);
0125   desc.add<double>("vtxStddevY", 2.e-2);
0126   desc.add<double>("vtxStddevZ", 2.e-2);
0127 
0128   descriptions.add("ctppsBeamParametersFromLHCInfoESSourceDefault", desc);
0129 }
0130 
0131 //----------------------------------------------------------------------------------------------------
0132 
0133 DEFINE_FWK_EVENTSETUP_MODULE(CTPPSBeamParametersFromLHCInfoESSource);