-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28720 from CTPPS/pps_backport_10_6
- Loading branch information
Showing
50 changed files
with
2,581 additions
and
1,560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
CalibPPS/ESProducers/plugins/CTPPSBeamParametersFromLHCInfoESSource.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/**************************************************************************** | ||
* Authors: | ||
* Wagner Carvalho [email protected] | ||
* Jan Kašpar | ||
****************************************************************************/ | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/Framework/interface/SourceFactory.h" | ||
#include "FWCore/Framework/interface/ModuleFactory.h" | ||
|
||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/ESProducer.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
|
||
#include "CondFormats/DataRecord/interface/LHCInfoRcd.h" | ||
#include "CondFormats/DataRecord/interface/CTPPSBeamParametersRcd.h" | ||
|
||
#include "CondFormats/RunInfo/interface/LHCInfo.h" | ||
|
||
#include "CondFormats/CTPPSReadoutObjects/interface/CTPPSBeamParameters.h" | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
class CTPPSBeamParametersFromLHCInfoESSource : public edm::ESProducer { | ||
public: | ||
CTPPSBeamParametersFromLHCInfoESSource(const edm::ParameterSet&); | ||
~CTPPSBeamParametersFromLHCInfoESSource() override = default; | ||
|
||
std::unique_ptr<CTPPSBeamParameters> produce(const CTPPSBeamParametersRcd&); | ||
static void fillDescriptions(edm::ConfigurationDescriptions&); | ||
|
||
private: | ||
edm::ESGetToken<LHCInfo, LHCInfoRcd> lhcInfoToken_; | ||
|
||
CTPPSBeamParameters defaultParameters_; | ||
}; | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
CTPPSBeamParametersFromLHCInfoESSource::CTPPSBeamParametersFromLHCInfoESSource(const edm::ParameterSet& iConfig) { | ||
defaultParameters_.setBeamDivergenceX45(iConfig.getParameter<double>("beamDivX45")); | ||
defaultParameters_.setBeamDivergenceY45(iConfig.getParameter<double>("beamDivX56")); | ||
defaultParameters_.setBeamDivergenceX56(iConfig.getParameter<double>("beamDivY45")); | ||
defaultParameters_.setBeamDivergenceY56(iConfig.getParameter<double>("beamDivY56")); | ||
|
||
defaultParameters_.setVtxOffsetX45(iConfig.getParameter<double>("vtxOffsetX45")); | ||
defaultParameters_.setVtxOffsetY45(iConfig.getParameter<double>("vtxOffsetY45")); | ||
defaultParameters_.setVtxOffsetZ45(iConfig.getParameter<double>("vtxOffsetZ45")); | ||
defaultParameters_.setVtxOffsetX56(iConfig.getParameter<double>("vtxOffsetX56")); | ||
defaultParameters_.setVtxOffsetY56(iConfig.getParameter<double>("vtxOffsetY56")); | ||
defaultParameters_.setVtxOffsetZ56(iConfig.getParameter<double>("vtxOffsetZ56")); | ||
|
||
defaultParameters_.setVtxStddevX(iConfig.getParameter<double>("vtxStddevX")); | ||
defaultParameters_.setVtxStddevY(iConfig.getParameter<double>("vtxStddevY")); | ||
defaultParameters_.setVtxStddevZ(iConfig.getParameter<double>("vtxStddevZ")); | ||
|
||
auto cc = setWhatProduced(this); | ||
lhcInfoToken_ = cc.consumesFrom<LHCInfo, LHCInfoRcd>(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoLabel"))); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
std::unique_ptr<CTPPSBeamParameters> CTPPSBeamParametersFromLHCInfoESSource::produce( | ||
const CTPPSBeamParametersRcd& iRecord) { | ||
LHCInfo const& lhcInfo = iRecord.get(lhcInfoToken_); | ||
|
||
auto bp = std::make_unique<CTPPSBeamParameters>(defaultParameters_); | ||
|
||
const auto beamMom = lhcInfo.energy(); | ||
const auto betaStar = lhcInfo.betaStar() * 1E2; // conversion m --> cm | ||
const auto xangle = lhcInfo.crossingAngle() * 1E-6; // conversion mu rad --> rad | ||
|
||
bp->setBeamMom45(beamMom); | ||
bp->setBeamMom56(beamMom); | ||
|
||
bp->setBetaStarX45(betaStar); | ||
bp->setBetaStarX56(betaStar); | ||
bp->setBetaStarY45(betaStar); | ||
bp->setBetaStarY56(betaStar); | ||
|
||
bp->setHalfXangleX45(xangle); | ||
bp->setHalfXangleX56(xangle); | ||
bp->setHalfXangleY45(xangle); | ||
bp->setHalfXangleY56(xangle); | ||
|
||
return bp; | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
void CTPPSBeamParametersFromLHCInfoESSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
|
||
desc.add<std::string>("lhcInfoLabel", ""); | ||
|
||
// beam divergence (rad) | ||
desc.add<double>("beamDivX45", 0.1); | ||
desc.add<double>("beamDivY45", 0.1); | ||
desc.add<double>("beamDivX56", 0.1); | ||
desc.add<double>("beamDivY56", 0.1); | ||
|
||
// vertex offset (cm) | ||
desc.add<double>("vtxOffsetX45", 1.e-2); | ||
desc.add<double>("vtxOffsetY45", 1.e-2); | ||
desc.add<double>("vtxOffsetZ45", 1.e-2); | ||
desc.add<double>("vtxOffsetX56", 1.e-2); | ||
desc.add<double>("vtxOffsetY56", 1.e-2); | ||
desc.add<double>("vtxOffsetZ56", 1.e-2); | ||
|
||
// vertex sigma (cm) | ||
desc.add<double>("vtxStddevX", 2.e-2); | ||
desc.add<double>("vtxStddevY", 2.e-2); | ||
desc.add<double>("vtxStddevZ", 2.e-2); | ||
|
||
descriptions.add("ctppsBeamParametersFromLHCInfoESSource", desc); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
DEFINE_FWK_EVENTSETUP_MODULE(CTPPSBeamParametersFromLHCInfoESSource); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
CalibPPS/ESProducers/plugins/CTPPSLHCInfoRandomXangleESSource.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// Original Author: Jan Kašpar | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/Framework/interface/SourceFactory.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/Framework/interface/ESProducer.h" | ||
#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h" | ||
#include "FWCore/Framework/interface/ESProducts.h" | ||
#include "FWCore/ServiceRegistry/interface/Service.h" | ||
|
||
#include "CondFormats/RunInfo/interface/LHCInfo.h" | ||
#include "CondFormats/DataRecord/interface/LHCInfoRcd.h" | ||
|
||
#include "CLHEP/Random/RandFlat.h" | ||
#include "CLHEP/Random/JamesRandom.h" | ||
|
||
#include "TFile.h" | ||
#include "TH1D.h" | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
/** | ||
* \brief Provides LHCInfo data necessary for CTPPS reconstruction (and direct simulation). | ||
**/ | ||
class CTPPSLHCInfoRandomXangleESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder { | ||
public: | ||
CTPPSLHCInfoRandomXangleESSource(const edm::ParameterSet &); | ||
edm::ESProducts<std::unique_ptr<LHCInfo>> produce(const LHCInfoRcd &); | ||
static void fillDescriptions(edm::ConfigurationDescriptions &); | ||
|
||
private: | ||
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, | ||
const edm::IOVSyncValue &, | ||
edm::ValidityInterval &) override; | ||
|
||
std::string m_label; | ||
|
||
unsigned int m_generateEveryNEvents; | ||
|
||
double m_beamEnergy; | ||
double m_betaStar; | ||
|
||
std::unique_ptr<CLHEP::HepRandomEngine> m_engine; | ||
|
||
struct BinData { | ||
double min, max, xangle; | ||
}; | ||
|
||
std::vector<BinData> binData; | ||
}; | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
//---------------------------------------------------------------------------------------------------- | ||
|
||
CTPPSLHCInfoRandomXangleESSource::CTPPSLHCInfoRandomXangleESSource(const edm::ParameterSet &conf) | ||
: m_label(conf.getParameter<std::string>("label")), | ||
|
||
m_generateEveryNEvents(conf.getParameter<unsigned int>("generateEveryNEvents")), | ||
|
||
m_beamEnergy(conf.getParameter<double>("beamEnergy")), | ||
m_betaStar(conf.getParameter<double>("betaStar")), | ||
|
||
m_engine(new CLHEP::HepJamesRandom(conf.getParameter<unsigned int>("seed"))) { | ||
const auto &xangleHistogramFile = conf.getParameter<std::string>("xangleHistogramFile"); | ||
const auto &xangleHistogramObject = conf.getParameter<std::string>("xangleHistogramObject"); | ||
|
||
TFile *f_in = TFile::Open(xangleHistogramFile.c_str()); | ||
TH1D *h_xangle = (TH1D *)f_in->Get(xangleHistogramObject.c_str()); | ||
|
||
double s = 0.; | ||
for (int bi = 1; bi <= h_xangle->GetNbinsX(); ++bi) | ||
s += h_xangle->GetBinContent(bi); | ||
|
||
double cw = 0.; | ||
for (int bi = 1; bi <= h_xangle->GetNbinsX(); ++bi) { | ||
double xangle = h_xangle->GetBinCenter(bi); | ||
double w = h_xangle->GetBinContent(bi) / s; | ||
|
||
binData.push_back({cw, cw + w, xangle}); | ||
|
||
cw += w; | ||
} | ||
|
||
delete f_in; | ||
|
||
setWhatProduced(this, m_label); | ||
findingRecord<LHCInfoRcd>(); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
void CTPPSLHCInfoRandomXangleESSource::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { | ||
edm::ParameterSetDescription desc; | ||
|
||
desc.add<std::string>("label", "")->setComment("label of the LHCInfo record"); | ||
|
||
desc.add<unsigned int>("seed", 1)->setComment("random seed"); | ||
|
||
desc.add<unsigned int>("generateEveryNEvents", 1)->setComment("how often to generate new xangle"); | ||
|
||
desc.add<std::string>("xangleHistogramFile", "")->setComment("ROOT file with xangle distribution"); | ||
desc.add<std::string>("xangleHistogramObject", "")->setComment("xangle distribution object in the ROOT file"); | ||
|
||
desc.add<double>("beamEnergy", 0.)->setComment("beam energy"); | ||
desc.add<double>("betaStar", 0.)->setComment("beta*"); | ||
|
||
descriptions.add("ctppsLHCInfoRandomXangleESSource", desc); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
void CTPPSLHCInfoRandomXangleESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key, | ||
const edm::IOVSyncValue &iosv, | ||
edm::ValidityInterval &oValidity) { | ||
edm::EventID beginEvent = iosv.eventID(); | ||
edm::EventID endEvent(beginEvent.run(), beginEvent.luminosityBlock(), beginEvent.event() + m_generateEveryNEvents); | ||
oValidity = edm::ValidityInterval(edm::IOVSyncValue(beginEvent), edm::IOVSyncValue(endEvent)); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
edm::ESProducts<std::unique_ptr<LHCInfo>> CTPPSLHCInfoRandomXangleESSource::produce(const LHCInfoRcd &) { | ||
auto output = std::make_unique<LHCInfo>(); | ||
|
||
const double u = CLHEP::RandFlat::shoot(m_engine.get(), 0., 1.); | ||
|
||
double xangle = 0.; | ||
for (const auto &d : binData) { | ||
if (d.min <= u && u <= d.max) { | ||
xangle = d.xangle; | ||
break; | ||
} | ||
} | ||
|
||
output->setEnergy(m_beamEnergy); | ||
output->setCrossingAngle(xangle); | ||
output->setBetaStar(m_betaStar); | ||
|
||
return edm::es::products(std::move(output)); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
DEFINE_FWK_EVENTSETUP_SOURCE(CTPPSLHCInfoRandomXangleESSource); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,15 @@ | ||
// Authors: | ||
// Wagner De Paula Carvalho | ||
// Jan Kašpar | ||
|
||
#ifndef CTPPSBeamParametersRcd_CTPPSBeamParametersRcd_h | ||
#define CTPPSBeamParametersRcd_CTPPSBeamParametersRcd_h | ||
// -*- C++ -*- | ||
// | ||
// Package: CondFormats/DataRecord | ||
// Class : CTPPSBeamParametersRcd | ||
// | ||
/**\class CTPPSBeamParametersRcd CTPPSBeamParametersRcd.h CondFormats/DataRecord/interface/CTPPSBeamParametersRcd.h | ||
Description: Record for beam parameters for CTPPS | ||
Usage: | ||
<usage> | ||
|
||
*/ | ||
// | ||
// Author: Wagner De Paula Carvalho | ||
// Created: Wed, 21 Nov 2018 16:12:53 GMT | ||
// | ||
#include "FWCore/Framework/interface/DependentRecordImplementation.h" | ||
|
||
#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" | ||
#include "CondFormats/DataRecord/interface/LHCInfoRcd.h" | ||
#include "boost/mpl/vector.hpp" | ||
|
||
class CTPPSBeamParametersRcd : public edm::eventsetup::EventSetupRecordImplementation<CTPPSBeamParametersRcd> {}; | ||
class CTPPSBeamParametersRcd : public edm::eventsetup::DependentRecordImplementation<CTPPSBeamParametersRcd, boost::mpl::vector<LHCInfoRcd>> {}; | ||
|
||
#endif |
File renamed without changes.
Oops, something went wrong.