Skip to content

Commit

Permalink
make proton reco use LHCInfoCombined
Browse files Browse the repository at this point in the history
  • Loading branch information
Glitchmin committed Aug 25, 2023
1 parent e0f88d0 commit 438ecaf
Show file tree
Hide file tree
Showing 24 changed files with 343 additions and 68 deletions.
1 change: 1 addition & 0 deletions CalibPPS/ESProducers/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
<use name="Utilities/Xerces"/>

<use name="clhep"/>
<use name="CondTools/RunInfo"/>
</library>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "CondFormats/DataRecord/interface/LHCInfoRcd.h"
#include "CondTools/RunInfo/interface/LHCInfoCombined.h"

#include "CondFormats/DataRecord/interface/CTPPSOpticsRcd.h"
#include "CondFormats/DataRecord/interface/CTPPSInterpolatedOpticsRcd.h"

Expand All @@ -28,19 +29,26 @@ class CTPPSInterpolatedOpticalFunctionsESSource : public edm::ESProducer {
private:
edm::ESGetToken<LHCOpticalFunctionsSetCollection, CTPPSOpticsRcd> opticsToken_;
edm::ESGetToken<LHCInfo, LHCInfoRcd> lhcInfoToken_;
edm::ESGetToken<LHCInfoPerLS, LHCInfoPerLSRcd> lhcInfoPerLSToken_;
edm::ESGetToken<LHCInfoPerFill, LHCInfoPerFillRcd> lhcInfoPerFillToken_;
std::shared_ptr<LHCInterpolatedOpticalFunctionsSetCollection> currentData_;
float currentCrossingAngle_;
bool currentDataValid_;
const bool useNewLHCInfo_;
};

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------

CTPPSInterpolatedOpticalFunctionsESSource::CTPPSInterpolatedOpticalFunctionsESSource(const edm::ParameterSet &iConfig)
: currentCrossingAngle_(-1.), currentDataValid_(false) {
: currentCrossingAngle_(LHCInfoCombined::crossingAngleInvalid),
currentDataValid_(false),
useNewLHCInfo_(iConfig.getParameter<bool>("useNewLHCInfo")) {
auto cc = setWhatProduced(this, iConfig.getParameter<std::string>("opticsLabel"));
opticsToken_ = cc.consumes(edm::ESInputTag("", iConfig.getParameter<std::string>("opticsLabel")));
lhcInfoToken_ = cc.consumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoLabel")));
lhcInfoPerLSToken_ = cc.consumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoPerLSLabel")));
lhcInfoPerFillToken_ = cc.consumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoPerFillLabel")));
}

//----------------------------------------------------------------------------------------------------
Expand All @@ -49,7 +57,10 @@ void CTPPSInterpolatedOpticalFunctionsESSource::fillDescriptions(edm::Configurat
edm::ParameterSetDescription desc;

desc.add<std::string>("lhcInfoLabel", "")->setComment("label of the LHCInfo record");
desc.add<std::string>("lhcInfoPerFillLabel", "")->setComment("label of the LHCInfoPerFill record");
desc.add<std::string>("lhcInfoPerLSLabel", "")->setComment("label of the LHCInfoPerLS record");
desc.add<std::string>("opticsLabel", "")->setComment("label of the optics records");
desc.add<bool>("useNewLHCInfo", false)->setComment("flag whether to use new LHCInfoPer* records or old LHCInfo");

descriptions.add("ctppsInterpolatedOpticalFunctionsESSource", desc);
}
Expand All @@ -61,26 +72,29 @@ std::shared_ptr<LHCInterpolatedOpticalFunctionsSetCollection> CTPPSInterpolatedO
// get the input data
LHCOpticalFunctionsSetCollection const &ofColl = iRecord.get(opticsToken_);

LHCInfo const &lhcInfo = iRecord.get(lhcInfoToken_);
auto lhcInfoCombined = LHCInfoCombined::createLHCInfoCombined<
CTPPSInterpolatedOpticsRcd,
edm::mpl::Vector<CTPPSOpticsRcd, LHCInfoRcd, LHCInfoPerFillRcd, LHCInfoPerLSRcd>>(
iRecord, lhcInfoPerLSToken_, lhcInfoPerFillToken_, lhcInfoToken_, useNewLHCInfo_);

// is there anything to do?
if (currentDataValid_ && lhcInfo.crossingAngle() == currentCrossingAngle_)
if (currentDataValid_ && lhcInfoCombined.crossingAngle() == currentCrossingAngle_)
return currentData_;

// is crossing angle reasonable (LHCInfo is correctly filled in DB)?
if (lhcInfo.crossingAngle() == 0.) {
if (lhcInfoCombined.isCrossingAngleInvalid()) {
edm::LogInfo("CTPPSInterpolatedOpticalFunctionsESSource")
<< "Invalid crossing angle, no optical functions produced.";

currentDataValid_ = false;
currentCrossingAngle_ = -1;
currentCrossingAngle_ = LHCInfoCombined::crossingAngleInvalid;
currentData_ = std::make_shared<LHCInterpolatedOpticalFunctionsSetCollection>();

return currentData_;
}

// set new crossing angle
currentCrossingAngle_ = lhcInfo.crossingAngle();
currentCrossingAngle_ = lhcInfoCombined.crossingAngle();
edm::LogInfo("CTPPSInterpolatedOpticalFunctionsESSource")
<< "Crossing angle has changed to " << currentCrossingAngle_ << ".";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from CalibPPS.ESProducers.ctppsInterpolatedOpticalFunctionsESSource_cfi import *
from Configuration.Eras.Modifier_run3_common_cff import run3_common
run3_common.toModify(ctppsInterpolatedOpticalFunctionsESSource, useNewLHCInfo = True)
13 changes: 0 additions & 13 deletions CalibPPS/ESProducers/python/ctppsLHCInfo_cff.py

This file was deleted.

4 changes: 1 addition & 3 deletions CalibPPS/ESProducers/python/ctppsOpticalFunctions_cff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import FWCore.ParameterSet.Config as cms

from CalibPPS.ESProducers.ctppsLHCInfo_cff import *

# by default, (raw) optical functions are now loaded from CondDB using a GT

Expand All @@ -26,5 +25,4 @@
#ctppsOpticalFunctionsESSource.configuration.append(config_2016_preTS2)

# optics interpolation between crossing angles
from CalibPPS.ESProducers.ctppsInterpolatedOpticalFunctionsESSource_cfi import *
ctppsInterpolatedOpticalFunctionsESSource.lhcInfoLabel = ctppsLHCInfoLabel
from CalibPPS.ESProducers.ctppsInterpolatedOpticalFunctionsESSource_cff import *
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import FWCore.ParameterSet.Config as cms

from CalibPPS.ESProducers.ctppsLHCInfo_cff import *

# (source) optical functions sampled at few xangles
from CalibPPS.ESProducers.ctppsOpticalFunctionsESSource_cfi import *

Expand Down Expand Up @@ -138,5 +136,4 @@
ctppsOpticalFunctionsESSource.configuration.append(optics_2022)

# optics interpolation between crossing angles
from CalibPPS.ESProducers.ctppsInterpolatedOpticalFunctionsESSource_cfi import *
ctppsInterpolatedOpticalFunctionsESSource.lhcInfoLabel = ctppsLHCInfoLabel
from CalibPPS.ESProducers.ctppsInterpolatedOpticalFunctionsESSource_cff import *
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
process = cms.Process( 'TEST',ctpps_2018)

# LHCInfo plotter
process.load("Validation.CTPPS.ctppsLHCInfoPlotter_cfi")
process.load('Validation.CTPPS.ctppsLHCInfoPlotter_cff')
process.ctppsLHCInfoPlotter.outputFile = "alcareco_lhc_info_express.root"

# Load geometry from DB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
process = cms.Process( 'TEST',ctpps_2018)

# LHCInfo plotter
process.load("Validation.CTPPS.ctppsLHCInfoPlotter_cfi")
process.load('Validation.CTPPS.ctppsLHCInfoPlotter_cff')
process.ctppsLHCInfoPlotter.outputFile = "alcareco_lhc_info_prompt.root"

# Load geometry from DB
Expand Down
7 changes: 5 additions & 2 deletions CondFormats/DataRecord/interface/CTPPSInterpolatedOpticsRcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

#include "CondFormats/DataRecord/interface/CTPPSOpticsRcd.h"
#include "CondFormats/DataRecord/interface/LHCInfoRcd.h"
#include "CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h"
#include "CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h"

#include "FWCore/Utilities/interface/mplVector.h"

class CTPPSInterpolatedOpticsRcd
: public edm::eventsetup::DependentRecordImplementation<CTPPSInterpolatedOpticsRcd,
edm::mpl::Vector<CTPPSOpticsRcd, LHCInfoRcd>> {};
: public edm::eventsetup::DependentRecordImplementation<
CTPPSInterpolatedOpticsRcd,
edm::mpl::Vector<CTPPSOpticsRcd, LHCInfoRcd, LHCInfoPerFillRcd, LHCInfoPerLSRcd>> {};

#endif
1 change: 1 addition & 0 deletions CondFormats/RunInfo/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<use name="FWCore/Utilities"/>
<use name="CoralBase"/>
<use name="boost_serialization"/>
<use name="CondFormats/DataRecord"/>
<export>
<lib name="1"/>
</export>
82 changes: 82 additions & 0 deletions CondTools/RunInfo/interface/LHCInfoCombined.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef CondTools_RunInfo_LHCInfoCombined_H
#define CondTools_RunInfo_LHCInfoCombined_H

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/DependentRecordImplementation.h"

#include "CondFormats/RunInfo/interface/LHCInfo.h"
#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h"
#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h"

#include "CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h"
#include "CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h"
#include "CondFormats/DataRecord/interface/LHCInfoRcd.h"

#include <bitset>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

class LHCInfoCombined {
public:
LHCInfoCombined() = default;

LHCInfoCombined(const LHCInfo& lhcInfo);
LHCInfoCombined(const LHCInfoPerLS& infoPerLS, const LHCInfoPerFill& infoPerFill);
LHCInfoCombined(const edm::EventSetup& iSetup,
const edm::ESGetToken<LHCInfoPerLS, LHCInfoPerLSRcd>& tokenInfoPerLS,
const edm::ESGetToken<LHCInfoPerFill, LHCInfoPerFillRcd>& tokenInfoPerFill,
const edm::ESGetToken<LHCInfo, LHCInfoRcd>& tokenInfo,
bool useNewLHCInfo);

//this factory method is necessary because constructor can't be a template
template <class RecordT, class ListT>
static LHCInfoCombined createLHCInfoCombined(
const edm::eventsetup::DependentRecordImplementation<RecordT, ListT>& iRecord,
const edm::ESGetToken<LHCInfoPerLS, LHCInfoPerLSRcd>& tokenInfoPerLS,
const edm::ESGetToken<LHCInfoPerFill, LHCInfoPerFillRcd>& tokenInfoPerFill,
const edm::ESGetToken<LHCInfo, LHCInfoRcd>& tokenInfo,
bool useNewLHCInfo);

void setFromLHCInfo(const LHCInfo& lhcInfo);
void setFromPerLS(const LHCInfoPerLS& infoPerLS);
void setFromPerFill(const LHCInfoPerFill& infoPerFill);

float crossingAngle();
static constexpr float crossingAngleInvalid = -1.;
bool isCrossingAngleInvalid();

float crossingAngleX;
float crossingAngleY;
float betaStarX;
float betaStarY;
float energy;
unsigned short fillNumber;

void print(std::ostream& os) const;
};

std::ostream& operator<<(std::ostream& os, LHCInfoCombined beamInfo);

template <class RecordT, class ListT>
LHCInfoCombined LHCInfoCombined::createLHCInfoCombined(
const edm::eventsetup::DependentRecordImplementation<RecordT, ListT>& iRecord,
const edm::ESGetToken<LHCInfoPerLS, LHCInfoPerLSRcd>& tokenInfoPerLS,
const edm::ESGetToken<LHCInfoPerFill, LHCInfoPerFillRcd>& tokenInfoPerFill,
const edm::ESGetToken<LHCInfo, LHCInfoRcd>& tokenInfo,
bool useNewLHCInfo) {
LHCInfoCombined lhcInfoCombined;
if (useNewLHCInfo) {
LHCInfoPerLS const& lhcInfoPerLS = iRecord.get(tokenInfoPerLS);
LHCInfoPerFill const& lhcInfoPerFill = iRecord.get(tokenInfoPerFill);
lhcInfoCombined.setFromPerLS(lhcInfoPerLS);
lhcInfoCombined.setFromPerFill(lhcInfoPerFill);
} else {
LHCInfo const& lhcInfo = iRecord.get(tokenInfo);
lhcInfoCombined.setFromLHCInfo(lhcInfo);
}
return lhcInfoCombined;
}

#endif // CondTools_RunInfo_LHCInfoCombined_H
74 changes: 74 additions & 0 deletions CondTools/RunInfo/src/LHCInfoCombined.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "CondTools/RunInfo/interface/LHCInfoCombined.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

LHCInfoCombined::LHCInfoCombined(const LHCInfo& lhcInfo) { setFromLHCInfo(lhcInfo); }

LHCInfoCombined::LHCInfoCombined(const LHCInfoPerLS& infoPerLS, const LHCInfoPerFill& infoPerFill) {
setFromPerLS(infoPerLS);
setFromPerFill(infoPerFill);
}

LHCInfoCombined::LHCInfoCombined(const edm::EventSetup& iSetup,
const edm::ESGetToken<LHCInfoPerLS, LHCInfoPerLSRcd>& tokenInfoPerLS,
const edm::ESGetToken<LHCInfoPerFill, LHCInfoPerFillRcd>& tokenInfoPerFill,
const edm::ESGetToken<LHCInfo, LHCInfoRcd>& tokenInfo,
bool useNewLHCInfo) {
if (useNewLHCInfo) {
edm::ESHandle<LHCInfoPerLS> hLHCInfoPerLS = iSetup.getHandle(tokenInfoPerLS);
edm::ESHandle<LHCInfoPerFill> hLHCInfoFill = iSetup.getHandle(tokenInfoPerFill);
setFromPerLS(*hLHCInfoPerLS);
setFromPerFill(*hLHCInfoFill);
} else {
edm::ESHandle<LHCInfo> hLHCInfo = iSetup.getHandle(tokenInfo);
setFromLHCInfo(*hLHCInfo);
}
}

void LHCInfoCombined::setFromLHCInfo(const LHCInfo& lhcInfo) {
crossingAngleX = lhcInfo.crossingAngle();
crossingAngleY = 0;
betaStarX = lhcInfo.betaStar();
betaStarY = lhcInfo.betaStar();
energy = lhcInfo.energy();
fillNumber = lhcInfo.fillNumber();
}
void LHCInfoCombined::setFromPerLS(const LHCInfoPerLS& infoPerLS) {
crossingAngleX = infoPerLS.crossingAngleX();
crossingAngleY = infoPerLS.crossingAngleY();
betaStarX = infoPerLS.betaStarX();
betaStarY = infoPerLS.betaStarY();
}
void LHCInfoCombined::setFromPerFill(const LHCInfoPerFill& infoPerFill) {
energy = infoPerFill.energy();
fillNumber = infoPerFill.fillNumber();
}

float LHCInfoCombined::crossingAngle() {
if (crossingAngleX == 0. && crossingAngleY == 0.) {
return crossingAngleInvalid;
}
if (crossingAngleX != 0. && crossingAngleY != 0.) {
edm::LogWarning("LHCInfoCombined") << "crossingAngleX and crossingAngleY are both different from 0";
return crossingAngleInvalid;
}
return crossingAngleX == 0. ? crossingAngleY : crossingAngleX;
}

//Comparison with the -1 value from LHC when crossing angle is not set
bool LHCInfoCombined::isCrossingAngleInvalid() {
float comparisonTolerance = 1e-6;
return fabs(crossingAngle() - crossingAngleInvalid) <= comparisonTolerance;
}

void LHCInfoCombined::print(std::ostream& os) const {
os << "Crossing angle x (urad): " << crossingAngleX << std::endl
<< "Crossing angle y (urad): " << crossingAngleY << std::endl
<< "Beta star x (m): " << betaStarX << std::endl
<< "Beta star y (m): " << betaStarY << std::endl
<< "Energy (GeV): " << energy << std::endl;
}

std::ostream& operator<<(std::ostream& os, LHCInfoCombined beamInfo) {
beamInfo.print(os);
return os;
}
Loading

0 comments on commit 438ecaf

Please sign in to comment.