Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // Original Author:  Jan Kašpar
0002 
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/Framework/interface/SourceFactory.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Framework/interface/ESProducer.h"
0008 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0009 #include "FWCore/Framework/interface/ESProducts.h"
0010 
0011 #include "CondFormats/RunInfo/interface/LHCInfo.h"
0012 #include "CondFormats/DataRecord/interface/LHCInfoRcd.h"
0013 
0014 //----------------------------------------------------------------------------------------------------
0015 
0016 /**
0017  * \brief Provides LHCInfo data necessary for CTPPS reconstruction (and direct simulation).
0018  **/
0019 class CTPPSLHCInfoESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0020 public:
0021   CTPPSLHCInfoESSource(const edm::ParameterSet &);
0022   edm::ESProducts<std::unique_ptr<LHCInfo>> produce(const LHCInfoRcd &);
0023   static void fillDescriptions(edm::ConfigurationDescriptions &);
0024 
0025 private:
0026   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0027                       const edm::IOVSyncValue &,
0028                       edm::ValidityInterval &) override;
0029 
0030   std::string m_label;
0031 
0032   edm::EventRange m_validityRange;
0033   double m_beamEnergy;
0034   double m_betaStar;
0035   double m_xangle;
0036 
0037   bool m_insideValidityRange;
0038 };
0039 
0040 //----------------------------------------------------------------------------------------------------
0041 //----------------------------------------------------------------------------------------------------
0042 
0043 CTPPSLHCInfoESSource::CTPPSLHCInfoESSource(const edm::ParameterSet &conf)
0044     : m_label(conf.getParameter<std::string>("label")),
0045       m_validityRange(conf.getParameter<edm::EventRange>("validityRange")),
0046       m_beamEnergy(conf.getParameter<double>("beamEnergy")),
0047       m_betaStar(conf.getParameter<double>("betaStar")),
0048       m_xangle(conf.getParameter<double>("xangle")),
0049       m_insideValidityRange(false) {
0050   setWhatProduced(this, m_label);
0051   findingRecord<LHCInfoRcd>();
0052 }
0053 
0054 //----------------------------------------------------------------------------------------------------
0055 
0056 void CTPPSLHCInfoESSource::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0057   edm::ParameterSetDescription desc;
0058 
0059   desc.add<std::string>("label", "")->setComment("label of the LHCInfo record");
0060 
0061   desc.add<edm::EventRange>("validityRange", edm::EventRange())->setComment("interval of validity");
0062 
0063   desc.add<double>("beamEnergy", 0.)->setComment("beam energy");
0064   desc.add<double>("betaStar", 0.)->setComment("beta*");
0065   desc.add<double>("xangle", 0.)->setComment("crossing angle");
0066 
0067   descriptions.add("ctppsLHCInfoESSource", desc);
0068 }
0069 
0070 //----------------------------------------------------------------------------------------------------
0071 
0072 void CTPPSLHCInfoESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key,
0073                                           const edm::IOVSyncValue &iosv,
0074                                           edm::ValidityInterval &oValidity) {
0075   if (edm::contains(m_validityRange, iosv.eventID())) {
0076     m_insideValidityRange = true;
0077     oValidity = edm::ValidityInterval(edm::IOVSyncValue(m_validityRange.startEventID()),
0078                                       edm::IOVSyncValue(m_validityRange.endEventID()));
0079   } else {
0080     m_insideValidityRange = false;
0081 
0082     if (iosv.eventID() < m_validityRange.startEventID()) {
0083       edm::RunNumber_t run = m_validityRange.startEventID().run();
0084       edm::LuminosityBlockNumber_t lb = m_validityRange.startEventID().luminosityBlock();
0085       edm::EventID endEvent =
0086           (lb > 1) ? edm::EventID(run, lb - 1, 0) : edm::EventID(run - 1, edm::EventID::maxLuminosityBlockNumber(), 0);
0087 
0088       oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue(endEvent));
0089     } else {
0090       edm::RunNumber_t run = m_validityRange.startEventID().run();
0091       edm::LuminosityBlockNumber_t lb = m_validityRange.startEventID().luminosityBlock();
0092       edm::EventID beginEvent = (lb < edm::EventID::maxLuminosityBlockNumber() - 1) ? edm::EventID(run, lb + 1, 0)
0093                                                                                     : edm::EventID(run + 1, 0, 0);
0094 
0095       oValidity = edm::ValidityInterval(edm::IOVSyncValue(beginEvent), edm::IOVSyncValue::endOfTime());
0096     }
0097   }
0098 }
0099 
0100 //----------------------------------------------------------------------------------------------------
0101 
0102 edm::ESProducts<std::unique_ptr<LHCInfo>> CTPPSLHCInfoESSource::produce(const LHCInfoRcd &) {
0103   auto output = std::make_unique<LHCInfo>();
0104 
0105   if (m_insideValidityRange) {
0106     output->setEnergy(m_beamEnergy);
0107     output->setBetaStar(m_betaStar);
0108     output->setCrossingAngle(m_xangle);
0109   } else {
0110     output->setEnergy(0.);
0111     output->setBetaStar(0.);
0112     output->setCrossingAngle(0.);
0113   }
0114 
0115   return edm::es::products(std::move(output));
0116 }
0117 
0118 //----------------------------------------------------------------------------------------------------
0119 
0120 DEFINE_FWK_EVENTSETUP_SOURCE(CTPPSLHCInfoESSource);