CMS 3D CMS Logo

CTPPSLHCInfoRandomXangleESSource.cc
Go to the documentation of this file.
1 // Original Author: Jan Kašpar
2 
11 
14 
15 #include "CLHEP/Random/RandFlat.h"
16 #include "CLHEP/Random/JamesRandom.h"
17 
18 #include "TFile.h"
19 #include "TH1D.h"
20 
21 //----------------------------------------------------------------------------------------------------
22 
27 public:
31 
32 private:
34  const edm::IOVSyncValue &,
35  edm::ValidityInterval &) override;
36 
38 
39  unsigned int m_generateEveryNEvents;
40 
41  double m_beamEnergy;
42  double m_betaStar;
43 
44  std::unique_ptr<CLHEP::HepRandomEngine> m_engine;
45 
46  struct BinData {
47  double min, max, xangle;
48  };
49 
50  std::vector<BinData> binData;
51 };
52 
53 //----------------------------------------------------------------------------------------------------
54 //----------------------------------------------------------------------------------------------------
55 
57  : m_label(conf.getParameter<std::string>("label")),
58 
59  m_generateEveryNEvents(conf.getParameter<unsigned int>("generateEveryNEvents")),
60 
61  m_beamEnergy(conf.getParameter<double>("beamEnergy")),
62  m_betaStar(conf.getParameter<double>("betaStar")),
63 
64  m_engine(new CLHEP::HepJamesRandom(conf.getParameter<unsigned int>("seed"))) {
65  const auto &xangleHistogramFile = conf.getParameter<std::string>("xangleHistogramFile");
66  const auto &xangleHistogramObject = conf.getParameter<std::string>("xangleHistogramObject");
67 
68  TFile *f_in = TFile::Open(xangleHistogramFile.c_str());
69  TH1D *h_xangle = (TH1D *)f_in->Get(xangleHistogramObject.c_str());
70 
71  double s = 0.;
72  for (int bi = 1; bi <= h_xangle->GetNbinsX(); ++bi)
73  s += h_xangle->GetBinContent(bi);
74 
75  double cw = 0.;
76  for (int bi = 1; bi <= h_xangle->GetNbinsX(); ++bi) {
77  double xangle = h_xangle->GetBinCenter(bi);
78  double w = h_xangle->GetBinContent(bi) / s;
79 
80  binData.push_back({cw, cw + w, xangle});
81 
82  cw += w;
83  }
84 
85  delete f_in;
86 
87  setWhatProduced(this, m_label);
88  findingRecord<LHCInfoRcd>();
89 }
90 
91 //----------------------------------------------------------------------------------------------------
92 
95 
96  desc.add<std::string>("label", "")->setComment("label of the LHCInfo record");
97 
98  desc.add<unsigned int>("seed", 1)->setComment("random seed");
99 
100  desc.add<unsigned int>("generateEveryNEvents", 1)->setComment("how often to generate new xangle");
101 
102  desc.add<std::string>("xangleHistogramFile", "")->setComment("ROOT file with xangle distribution");
103  desc.add<std::string>("xangleHistogramObject", "")->setComment("xangle distribution object in the ROOT file");
104 
105  desc.add<double>("beamEnergy", 0.)->setComment("beam energy");
106  desc.add<double>("betaStar", 0.)->setComment("beta*");
107 
108  descriptions.add("ctppsLHCInfoRandomXangleESSource", desc);
109 }
110 
111 //----------------------------------------------------------------------------------------------------
112 
114  const edm::IOVSyncValue &iosv,
115  edm::ValidityInterval &oValidity) {
116  edm::EventID beginEvent = iosv.eventID();
117  edm::EventID endEvent(beginEvent.run(), beginEvent.luminosityBlock(), beginEvent.event() + m_generateEveryNEvents);
118  oValidity = edm::ValidityInterval(edm::IOVSyncValue(beginEvent), edm::IOVSyncValue(endEvent));
119 }
120 
121 //----------------------------------------------------------------------------------------------------
122 
124  auto output = std::make_unique<LHCInfo>();
125 
126  const double u = CLHEP::RandFlat::shoot(m_engine.get(), 0., 1.);
127 
128  double xangle = 0.;
129  for (const auto &d : binData) {
130  if (d.min <= u && u <= d.max) {
131  xangle = d.xangle;
132  break;
133  }
134  }
135 
136  output->setEnergy(m_beamEnergy);
137  output->setCrossingAngle(xangle);
138  output->setBetaStar(m_betaStar);
139 
141 }
142 
143 //----------------------------------------------------------------------------------------------------
144 
CTPPSLHCInfoRandomXangleESSource::BinData
Definition: CTPPSLHCInfoRandomXangleESSource.cc:46
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
ESHandle.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::ValidityInterval
Definition: ValidityInterval.h:28
LHCInfo.h
ESProducer.h
edm::ESProducts
Definition: ESProducts.h:105
edm::EventID::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
edm::es::products
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
CTPPSLHCInfoRandomXangleESSource
Provides LHCInfo data necessary for CTPPS reconstruction (and direct simulation).
Definition: CTPPSLHCInfoRandomXangleESSource.cc:26
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CTPPSLHCInfoRandomXangleESSource::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: CTPPSLHCInfoRandomXangleESSource.cc:93
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
Service.h
w
const double w
Definition: UKUtility.cc:23
CTPPSLHCInfoRandomXangleESSource::BinData::min
double min
Definition: CTPPSLHCInfoRandomXangleESSource.cc:47
LHCInfoRcd
Definition: LHCInfoRcd.h:24
CTPPSLHCInfoRandomXangleESSource::BinData::xangle
double xangle
Definition: CTPPSLHCInfoRandomXangleESSource.cc:47
CTPPSLHCInfoRandomXangleESSource::m_betaStar
double m_betaStar
Definition: CTPPSLHCInfoRandomXangleESSource.cc:42
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
DEFINE_FWK_EVENTSETUP_SOURCE
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
EventSetupRecordIntervalFinder.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
CLHEP
Definition: CocoaGlobals.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
OpticalFunctionsConfig_cfi.xangle
xangle
Definition: OpticalFunctionsConfig_cfi.py:17
ESProducts.h
SourceFactory.h
edm::IOVSyncValue::eventID
const EventID & eventID() const
Definition: IOVSyncValue.h:40
edm::ParameterSet
Definition: ParameterSet.h:36
CTPPSLHCInfoRandomXangleESSource::m_label
std::string m_label
Definition: CTPPSLHCInfoRandomXangleESSource.cc:37
edm::EventID::event
EventNumber_t event() const
Definition: EventID.h:40
createfilelist.int
int
Definition: createfilelist.py:10
CTPPSLHCInfoRandomXangleESSource::m_engine
std::unique_ptr< CLHEP::HepRandomEngine > m_engine
Definition: CTPPSLHCInfoRandomXangleESSource.cc:44
CTPPSLHCInfoRandomXangleESSource::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: CTPPSLHCInfoRandomXangleESSource.cc:113
CTPPSLHCInfoRandomXangleESSource::produce
edm::ESProducts< std::unique_ptr< LHCInfo > > produce(const LHCInfoRcd &)
Definition: CTPPSLHCInfoRandomXangleESSource.cc:123
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
cond::ValidityInterval
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
CTPPSLHCInfoRandomXangleESSource::CTPPSLHCInfoRandomXangleESSource
CTPPSLHCInfoRandomXangleESSource(const edm::ParameterSet &)
Definition: CTPPSLHCInfoRandomXangleESSource.cc:56
CTPPSLHCInfoRandomXangleESSource::binData
std::vector< BinData > binData
Definition: CTPPSLHCInfoRandomXangleESSource.cc:50
CTPPSLHCInfoRandomXangleESSource::m_beamEnergy
double m_beamEnergy
Definition: CTPPSLHCInfoRandomXangleESSource.cc:41
edm::ESProducer
Definition: ESProducer.h:101
ztail.d
d
Definition: ztail.py:151
ParameterSet.h
LHCInfoRcd.h
edm::ParameterDescriptionNode::setComment
void setComment(std::string const &value)
Definition: ParameterDescriptionNode.cc:106
edm::EventID
Definition: EventID.h:31
crabWrapper.key
key
Definition: crabWrapper.py:19
CTPPSLHCInfoRandomXangleESSource::BinData::max
double max
Definition: CTPPSLHCInfoRandomXangleESSource.cc:47
CTPPSLHCInfoRandomXangleESSource::m_generateEveryNEvents
unsigned int m_generateEveryNEvents
Definition: CTPPSLHCInfoRandomXangleESSource.cc:39