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 "TH2D.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 
43  std::unique_ptr<CLHEP::HepRandomEngine> m_engine;
44 
45  struct BinData {
46  double min, max;
47  double xangle, betaStar;
48  };
49 
50  std::vector<BinData> xangleBetaStarBins;
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 
63  m_engine(new CLHEP::HepJamesRandom(conf.getParameter<unsigned int>("seed"))) {
64  // get input beta* vs. xangle histogram
65  const auto &xangleBetaStarHistogramFile = conf.getParameter<std::string>("xangleBetaStarHistogramFile");
66  const auto &xangleBetaStarHistogramObject = conf.getParameter<std::string>("xangleBetaStarHistogramObject");
67 
69  std::unique_ptr<TFile> f_in(TFile::Open(fip.fullPath().c_str()));
70  if (!f_in)
71  throw cms::Exception("PPS") << "Cannot open input file '" << xangleBetaStarHistogramFile << "'.";
72 
73  TH2D *h_xangle_beta_star = (TH2D *)f_in->Get(xangleBetaStarHistogramObject.c_str());
74  if (!h_xangle_beta_star)
75  throw cms::Exception("PPS") << "Cannot load input object '" << xangleBetaStarHistogramObject << "'.";
76 
77  // parse histogram
78  double sum = 0.;
79  for (int x = 1; x <= h_xangle_beta_star->GetNbinsX(); ++x) {
80  for (int y = 1; y <= h_xangle_beta_star->GetNbinsY(); ++y)
81  sum += h_xangle_beta_star->GetBinContent(x, y);
82  }
83 
84  double cw = 0;
85  for (int x = 1; x <= h_xangle_beta_star->GetNbinsX(); ++x) {
86  for (int y = 1; y <= h_xangle_beta_star->GetNbinsY(); ++y) {
87  const double c = h_xangle_beta_star->GetBinContent(x, y);
88  const double xangle = h_xangle_beta_star->GetXaxis()->GetBinCenter(x);
89  const double betaStar = h_xangle_beta_star->GetYaxis()->GetBinCenter(y);
90 
91  if (c > 0.) {
92  const double rc = c / sum;
93  xangleBetaStarBins.push_back({cw, cw + rc, xangle, betaStar});
94  cw += rc;
95  }
96  }
97  }
98 
99  setWhatProduced(this, m_label);
100  findingRecord<LHCInfoRcd>();
101 }
102 
103 //----------------------------------------------------------------------------------------------------
104 
107 
108  desc.add<std::string>("label", "")->setComment("label of the LHCInfo record");
109 
110  desc.add<unsigned int>("seed", 1)->setComment("random seed");
111 
112  desc.add<unsigned int>("generateEveryNEvents", 1)->setComment("how often to generate new xangle");
113 
114  desc.add<std::string>("xangleBetaStarHistogramFile", "")->setComment("ROOT file with xangle distribution");
115  desc.add<std::string>("xangleBetaStarHistogramObject", "")->setComment("xangle distribution object in the ROOT file");
116 
117  desc.add<double>("beamEnergy", 0.)->setComment("beam energy");
118 
119  descriptions.add("ctppsLHCInfoRandomXangleESSource", desc);
120 }
121 
122 //----------------------------------------------------------------------------------------------------
123 
125  const edm::IOVSyncValue &iosv,
126  edm::ValidityInterval &oValidity) {
127  edm::EventID beginEvent = iosv.eventID();
128  edm::EventID endEvent(beginEvent.run(), beginEvent.luminosityBlock(), beginEvent.event() + m_generateEveryNEvents);
129  oValidity = edm::ValidityInterval(edm::IOVSyncValue(beginEvent), edm::IOVSyncValue(endEvent));
130 }
131 
132 //----------------------------------------------------------------------------------------------------
133 
135  auto output = std::make_unique<LHCInfo>();
136 
137  double xangle = 0., betaStar = 0.;
138  const double u = CLHEP::RandFlat::shoot(m_engine.get(), 0., 1.);
139  for (const auto &d : xangleBetaStarBins) {
140  if (d.min <= u && u <= d.max) {
141  xangle = d.xangle;
142  betaStar = d.betaStar;
143  break;
144  }
145  }
146 
147  output->setEnergy(m_beamEnergy);
148  output->setCrossingAngle(xangle);
149  output->setBetaStar(betaStar);
150 
152 }
153 
154 //----------------------------------------------------------------------------------------------------
155 
CTPPSLHCInfoRandomXangleESSource::BinData
Definition: CTPPSLHCInfoRandomXangleESSource.cc:45
DDAxes::y
ESHandle.h
BeamSpotFakeParameters_cfi.betaStar
betaStar
Definition: BeamSpotFakeParameters_cfi.py:19
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
CTPPSLHCInfoRandomXangleESSource::xangleBetaStarBins
std::vector< BinData > xangleBetaStarBins
Definition: CTPPSLHCInfoRandomXangleESSource.cc:50
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::ValidityInterval
Definition: ValidityInterval.h:28
LHCInfo.h
ESProducer.h
edm::ESProducts
Definition: ESProducts.h:105
DDAxes::x
edm::EventID::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
base_cff.xangleBetaStarHistogramFile
xangleBetaStarHistogramFile
Definition: base_cff.py:18
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
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
CTPPSLHCInfoRandomXangleESSource::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: CTPPSLHCInfoRandomXangleESSource.cc:105
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
Service.h
CTPPSLHCInfoRandomXangleESSource::BinData::min
double min
Definition: CTPPSLHCInfoRandomXangleESSource.cc:46
LHCInfoRcd
Definition: LHCInfoRcd.h:24
CTPPSLHCInfoRandomXangleESSource::BinData::xangle
double xangle
Definition: CTPPSLHCInfoRandomXangleESSource.cc:47
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:47
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:43
CTPPSLHCInfoRandomXangleESSource::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: CTPPSLHCInfoRandomXangleESSource.cc:124
CTPPSLHCInfoRandomXangleESSource::produce
edm::ESProducts< std::unique_ptr< LHCInfo > > produce(const LHCInfoRcd &)
Definition: CTPPSLHCInfoRandomXangleESSource.cc:134
cond::ValidityInterval
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
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
Exception
Definition: hltDiff.cc:245
CTPPSLHCInfoRandomXangleESSource::BinData::betaStar
double betaStar
Definition: CTPPSLHCInfoRandomXangleESSource.cc:47
CTPPSLHCInfoRandomXangleESSource::m_beamEnergy
double m_beamEnergy
Definition: CTPPSLHCInfoRandomXangleESSource.cc:41
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESProducer
Definition: ESProducer.h:104
ztail.d
d
Definition: ztail.py:151
ParameterSet.h
LHCInfoRcd.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::EventID
Definition: EventID.h:31
crabWrapper.key
key
Definition: crabWrapper.py:19
CTPPSLHCInfoRandomXangleESSource::BinData::max
double max
Definition: CTPPSLHCInfoRandomXangleESSource.cc:46
CTPPSLHCInfoRandomXangleESSource::m_generateEveryNEvents
unsigned int m_generateEveryNEvents
Definition: CTPPSLHCInfoRandomXangleESSource.cc:39
base_cff.xangleBetaStarHistogramObject
xangleBetaStarHistogramObject
Definition: base_cff.py:19