Skip to content

Commit

Permalink
Merge pull request #28720 from CTPPS/pps_backport_10_6
Browse files Browse the repository at this point in the history
PPS: backport of #28492, #28615 and #28621
  • Loading branch information
cmsbuild authored Jan 21, 2020
2 parents 8f7331c + 7f4177b commit 02f73e2
Show file tree
Hide file tree
Showing 50 changed files with 2,581 additions and 1,560 deletions.
1 change: 1 addition & 0 deletions CalibPPS/ESProducers/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<use name="CondFormats/CTPPSReadoutObjects"/>
<use name="DataFormats/CTPPSDetId"/>
<use name="CondFormats/RunInfo"/>
<use name="clhep"/>
</library>
121 changes: 121 additions & 0 deletions CalibPPS/ESProducers/plugins/CTPPSBeamParametersFromLHCInfoESSource.cc
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);
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CTPPSInterpolatedOpticalFunctionsESSource : public edm::ESProducer

private:
std::string lhcInfoLabel_;
std::string opticsLabel_;

float currentCrossingAngle_;
bool currentDataValid_;
Expand All @@ -40,10 +41,11 @@ class CTPPSInterpolatedOpticalFunctionsESSource : public edm::ESProducer

CTPPSInterpolatedOpticalFunctionsESSource::CTPPSInterpolatedOpticalFunctionsESSource(const edm::ParameterSet& iConfig) :
lhcInfoLabel_(iConfig.getParameter<std::string>("lhcInfoLabel")),
opticsLabel_(iConfig.getParameter<std::string>("opticsLabel")),
currentCrossingAngle_(-1.),
currentDataValid_(false)
{
setWhatProduced(this, &CTPPSInterpolatedOpticalFunctionsESSource::produce);
setWhatProduced(this, opticsLabel_);
}

//----------------------------------------------------------------------------------------------------
Expand All @@ -55,6 +57,9 @@ void CTPPSInterpolatedOpticalFunctionsESSource::fillDescriptions(edm::Configurat
desc.add<std::string>("lhcInfoLabel", "")
->setComment("label of the LHCInfo record");

desc.add<std::string>("opticsLabel", "")
->setComment("label of the optics record");

descriptions.add("ctppsInterpolatedOpticalFunctionsESSource", desc);
}

Expand All @@ -64,7 +69,7 @@ std::shared_ptr<LHCInterpolatedOpticalFunctionsSetCollection> CTPPSInterpolatedO
{
// get the input data
edm::ESHandle<LHCOpticalFunctionsSetCollection> hOFColl;
iRecord.getRecord<CTPPSOpticsRcd>().get(hOFColl);
iRecord.getRecord<CTPPSOpticsRcd>().get(opticsLabel_, hOFColl);

edm::ESHandle<LHCInfo> hLHCInfo;
iRecord.getRecord<LHCInfoRcd>().get(lhcInfoLabel_, hLHCInfo);
Expand Down
145 changes: 145 additions & 0 deletions CalibPPS/ESProducers/plugins/CTPPSLHCInfoRandomXangleESSource.cc
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);
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class CTPPSOpticalFunctionsESSource: public edm::ESProducer, public edm::EventSe
private:
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&, const edm::IOVSyncValue&, edm::ValidityInterval&) override;

std::string m_label;

struct FileInfo
{
double m_xangle;
Expand Down Expand Up @@ -56,6 +58,7 @@ class CTPPSOpticalFunctionsESSource: public edm::ESProducer, public edm::EventSe
//----------------------------------------------------------------------------------------------------

CTPPSOpticalFunctionsESSource::CTPPSOpticalFunctionsESSource(const edm::ParameterSet& conf) :
m_label(conf.getParameter<std::string>("label")),
m_currentEntryValid(false),
m_currentEntry(0)
{
Expand Down Expand Up @@ -84,7 +87,7 @@ CTPPSOpticalFunctionsESSource::CTPPSOpticalFunctionsESSource(const edm::Paramete
m_entries.push_back({validityRange, fileInfo, rpInfo});
}

setWhatProduced(this);
setWhatProduced(this, m_label);
findingRecord<CTPPSOpticsRcd>();
}

Expand Down Expand Up @@ -156,6 +159,8 @@ CTPPSOpticalFunctionsESSource::fillDescriptions(edm::ConfigurationDescriptions&
{
edm::ParameterSetDescription desc;

desc.add<std::string>("label", "")->setComment("label of the optics record");

edm::ParameterSetDescription config_desc;

config_desc.add<edm::EventRange>("validityRange", edm::EventRange())->setComment("interval of validity");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "TSpline.h"

class CTPPSInterpolatedOpticalFunctionsESSource;
class CTPPSModifiedOpticalFunctionsESSource;

/// Set of optical functions corresponding to one scoring plane along LHC, including splines for interpolation performance.
class LHCInterpolatedOpticalFunctionsSet : public LHCOpticalFunctionsSet
Expand Down Expand Up @@ -39,6 +40,7 @@ class LHCInterpolatedOpticalFunctionsSet : public LHCOpticalFunctionsSet

protected:
friend CTPPSInterpolatedOpticalFunctionsESSource;
friend CTPPSModifiedOpticalFunctionsESSource;

std::vector<std::shared_ptr<const TSpline3>> m_splines;
};
Expand Down
26 changes: 8 additions & 18 deletions CondFormats/DataRecord/interface/CTPPSBeamParametersRcd.h
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
Loading

0 comments on commit 02f73e2

Please sign in to comment.