Skip to content

Commit

Permalink
New CondFormat for HG PCL alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeuser committed Jun 3, 2022
1 parent 9c0c506 commit be1d3ea
Show file tree
Hide file tree
Showing 18 changed files with 1,331 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CondCore/PCLConfigPlugins/src/plugin.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "CondCore/ESSources/interface/registration_macros.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h"
#include "CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h"
#include "CondFormats/DataRecord/interface/AlignPCLThresholdsHGRcd.h"

REGISTER_PLUGIN(AlignPCLThresholdsRcd, AlignPCLThresholds);
REGISTER_PLUGIN(AlignPCLThresholdsHGRcd, AlignPCLThresholdsHG);
1 change: 1 addition & 0 deletions CondCore/Utilities/plugins/Module_2XML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PAYLOAD_2XML_MODULE(pluginUtilities_payload2xml) {
m.def("boost_version_label", &cond::boost_version_label, "Get boost version for this release");
PAYLOAD_2XML_CLASS(AlCaRecoTriggerBits);
PAYLOAD_2XML_CLASS(AlignPCLThresholds);
PAYLOAD_2XML_CLASS(AlignPCLThresholdsHG);
PAYLOAD_2XML_CLASS(AlignmentErrors);
PAYLOAD_2XML_CLASS(AlignmentErrorsExtended);
PAYLOAD_2XML_CLASS(AlignmentSurfaceDeformations);
Expand Down
1 change: 1 addition & 0 deletions CondCore/Utilities/src/CondDBFetch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace cond {
FETCH_PAYLOAD_CASE(AlignmentSurfaceDeformations)
FETCH_PAYLOAD_CASE(Alignments)
FETCH_PAYLOAD_CASE(AlignPCLThresholds)
FETCH_PAYLOAD_CASE(AlignPCLThresholdsHG)
FETCH_PAYLOAD_CASE(BeamSpotObjects)
FETCH_PAYLOAD_CASE(BeamSpotOnlineObjects)
FETCH_PAYLOAD_CASE(CSCBadChambers)
Expand Down
1 change: 1 addition & 0 deletions CondCore/Utilities/src/CondDBImport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace cond {
IMPORT_PAYLOAD_CASE(AlignmentSurfaceDeformations)
IMPORT_PAYLOAD_CASE(Alignments)
IMPORT_PAYLOAD_CASE(AlignPCLThresholds)
IMPORT_PAYLOAD_CASE(AlignPCLThresholdsHG)
IMPORT_PAYLOAD_CASE(BeamSpotObjects)
IMPORT_PAYLOAD_CASE(BeamSpotOnlineObjects)
IMPORT_PAYLOAD_CASE(CSCBadChambers)
Expand Down
1 change: 1 addition & 0 deletions CondCore/Utilities/src/CondFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
#include "CondFormats/BTauObjects/interface/TrackProbabilityCalibration.h"
#include "CondFormats/MFObjects/interface/MagFieldConfig.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h"
#include "CondFormats/SiPhase2TrackerObjects/interface/TrackerDetToDTCELinkCablingMap.h"
#include "CondFormats/SiPhase2TrackerObjects/interface/SiPhase2OuterTrackerLorentzAngle.h"
#include "CondFormats/SiPhase2TrackerObjects/interface/DTCELinkId.h"
Expand Down
8 changes: 8 additions & 0 deletions CondFormats/DataRecord/interface/AlignPCLThresholdsHGRcd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef AlignPCLThresholdsRcd_AlignPCLThresholdsHGRcd_h
#define AlignPCLThresholdsRcd_AlignPCLThresholdsHGRcd_h

#include "FWCore/Framework/interface/EventSetupRecordImplementation.h"

class AlignPCLThresholdsHGRcd : public edm::eventsetup::EventSetupRecordImplementation<AlignPCLThresholdsHGRcd> {};

#endif
4 changes: 4 additions & 0 deletions CondFormats/DataRecord/src/AlignPCLThresholdsHGRcd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "CondFormats/DataRecord/interface/AlignPCLThresholdsHGRcd.h"
#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h"

EVENTSETUP_RECORD_REG(AlignPCLThresholdsHGRcd);
2 changes: 1 addition & 1 deletion CondFormats/PCLConfig/interface/AlignPCLThresholds.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AlignPCLThresholds {

void printAll() const;

private:
protected:
threshold_map m_thresholds;
int m_nrecords;

Expand Down
47 changes: 47 additions & 0 deletions CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef CondFormats_PCLConfig_AlignPCLThresholdsHG_h
#define CondFormats_PCLConfig_AlignPCLThresholdsHG_h

#include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"
#include "CondFormats/Serialization/interface/Serializable.h"

#include <map>
#include <string>
#include <vector>

class AlignPCLThresholdsHG : public AlignPCLThresholds {
public:
AlignPCLThresholdsHG() {}

enum FloatParamIndex {
FRACTION_CUT_X = 0,
FRACTION_CUT_Y = 1,
FRACTION_CUT_Z = 2,
FRACTION_CUT_TX = 3,
FRACTION_CUT_TY = 4,
FRACTION_CUT_TZ = 5,
FSIZE = 6
};

void SetFractionCut(const std::string &AlignableId, const coordType &type, const float &cut);

const std::unordered_map<std::string, std::vector<float>> &getFloatMap() const { return floatMap; }
const std::vector<float> &getFloatVec(const std::string &AlignableId) const;

float getFractionCut(const std::string &AlignableId, const coordType &type) const;
std::array<float, 6> getFractionCut(const std::string &AlignableId) const;

int payloadVersion() const;

void printAllHG() const;

~AlignPCLThresholdsHG() override {}

private:
std::unordered_map<std::string, std::vector<float>> floatMap;
std::unordered_map<std::string, std::vector<int>> intMap;
std::unordered_map<std::string, std::vector<std::string>> stringMap;

COND_SERIALIZABLE;
};

#endif
71 changes: 59 additions & 12 deletions CondFormats/PCLConfig/plugins/AlignPCLThresholdsReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h"
#include "CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h"
#include "CondFormats/DataRecord/interface/AlignPCLThresholdsHGRcd.h"
#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"

namespace edmtest {
template <typename T, typename R>
class AlignPCLThresholdsReader : public edm::one::EDAnalyzer<> {
public:
explicit AlignPCLThresholdsReader(edm::ParameterSet const& p);
Expand All @@ -20,46 +24,50 @@ namespace edmtest {
void analyze(const edm::Event& e, const edm::EventSetup& c) override;

// ----------member data ---------------------------
const edm::ESGetToken<AlignPCLThresholds, AlignPCLThresholdsRcd> thresholdToken_;
const edm::ESGetToken<T, R> thresholdToken_;
const bool printdebug_;
const std::string formatedOutput_;
};

AlignPCLThresholdsReader::AlignPCLThresholdsReader(edm::ParameterSet const& p)
template <typename T, typename R>
AlignPCLThresholdsReader<T, R>::AlignPCLThresholdsReader(edm::ParameterSet const& p)
: thresholdToken_(esConsumes()),
printdebug_(p.getUntrackedParameter<bool>("printDebug", true)),
formatedOutput_(p.getUntrackedParameter<std::string>("outputFile", "")) {
edm::LogInfo("AlignPCLThresholdsReader") << "AlignPCLThresholdsReader" << std::endl;
}

AlignPCLThresholdsReader::~AlignPCLThresholdsReader() {
template <typename T, typename R>
AlignPCLThresholdsReader<T, R>::~AlignPCLThresholdsReader() {
edm::LogInfo("AlignPCLThresholdsReader") << "~AlignPCLThresholdsReader " << std::endl;
}

void AlignPCLThresholdsReader::analyze(const edm::Event& e, const edm::EventSetup& context) {
template <typename T, typename R>
void AlignPCLThresholdsReader<T, R>::analyze(const edm::Event& e, const edm::EventSetup& context) {
edm::LogInfo("AlignPCLThresholdsReader") << "### AlignPCLThresholdsReader::analyze ###" << std::endl;
edm::LogInfo("AlignPCLThresholdsReader") << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
edm::LogInfo("AlignPCLThresholdsReader") << " ---EVENT NUMBER " << e.id().event() << std::endl;

edm::eventsetup::EventSetupRecordKey inputKey = edm::eventsetup::EventSetupRecordKey::makeKey<R>();
edm::eventsetup::EventSetupRecordKey recordKey(
edm::eventsetup::EventSetupRecordKey::TypeTag::findType("AlignPCLThresholdsRcd"));
edm::eventsetup::EventSetupRecordKey::TypeTag::findType(inputKey.type().name()));

if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
//record not found
edm::LogInfo("AlignPCLThresholdsReader") << "Record \"AlignPCLThresholdsRcd"
<< "\" does not exist " << std::endl;
edm::LogInfo("AlignPCLThresholdsReader")
<< "Record \"" << inputKey.type().name() << "\" does not exist " << std::endl;
}

//this part gets the handle of the event source and the record (i.e. the Database)
edm::ESHandle<AlignPCLThresholds> thresholdHandle = context.getHandle(thresholdToken_);
edm::ESHandle<T> thresholdHandle = context.getHandle(thresholdToken_);
edm::LogInfo("AlignPCLThresholdsReader") << "got eshandle" << std::endl;

if (!thresholdHandle.isValid()) {
edm::LogError("AlignPCLThresholdsReader") << " Could not get Handle" << std::endl;
return;
}

const AlignPCLThresholds* thresholds = thresholdHandle.product();
const T* thresholds = thresholdHandle.product();
edm::LogInfo("AlignPCLThresholdsReader") << "got AlignPCLThresholds* " << std::endl;
edm::LogInfo("AlignPCLThresholdsReader") << "print pointer address : ";
edm::LogInfo("AlignPCLThresholdsReader") << thresholds << std::endl;
Expand All @@ -69,6 +77,10 @@ namespace edmtest {
// use built-in method in the CondFormat to print the content
if (printdebug_) {
thresholds->printAll();
// print additional thresholds if HG payload is used
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
thresholds->printAllHG();
}
}

FILE* pFile = nullptr;
Expand Down Expand Up @@ -132,16 +144,51 @@ namespace edmtest {
}
}
}

// print additional thresholds for HG payload
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
fprintf(pFile, "AlignPCLThresholdsHG::printAllHG() \n");
fprintf(pFile, " ======================================= \n");
const std::unordered_map<std::string, std::vector<float>>& floatMap = thresholds->getFloatMap();
for (auto it = floatMap.begin(); it != floatMap.end(); ++it) {
fprintf(pFile, " ======================================= \n");

fprintf(pFile, "key : %s \n", (it->first).c_str());
fprintf(pFile,
"- X_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::X));
fprintf(pFile,
"- thetaX_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_X));
fprintf(pFile,
"- Y_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::Y));
fprintf(pFile,
"- thetaY_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_Y));
fprintf(pFile,
"- Z_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::Z));
fprintf(pFile,
"- thetaZ_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_Z));
}
}
}
}

void AlignPCLThresholdsReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
template <typename T, typename R>
void AlignPCLThresholdsReader<T, R>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.setComment("Reads payloads of type AlignPCLThresholds");
desc.addUntracked<bool>("printDebug", true);
desc.addUntracked<std::string>("outputFile", "");
descriptions.add("AlignPCLThresholdsReader", desc);
descriptions.add(defaultModuleLabel<AlignPCLThresholdsReader<T, R>>(), desc);
}

DEFINE_FWK_MODULE(AlignPCLThresholdsReader);
typedef AlignPCLThresholdsReader<AlignPCLThresholds, AlignPCLThresholdsRcd> AlignPCLThresholdsLGReader;
typedef AlignPCLThresholdsReader<AlignPCLThresholdsHG, AlignPCLThresholdsHGRcd> AlignPCLThresholdsHGReader;

DEFINE_FWK_MODULE(AlignPCLThresholdsLGReader);
DEFINE_FWK_MODULE(AlignPCLThresholdsHGReader);
} // namespace edmtest
97 changes: 79 additions & 18 deletions CondFormats/PCLConfig/plugins/AlignPCLThresholdsWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"

Expand All @@ -48,6 +49,10 @@ class AlignPCLThresholdsWriter : public edm::one::EDAnalyzer<> {
void analyze(const edm::Event&, const edm::EventSetup&) override;
DOFs::dof mapOntoEnum(std::string coord);

template <typename T>
void writePayload(T& myThresholds);
void storeHGthresholds(AlignPCLThresholdsHG& myThresholds, const std::vector<std::string>& alignables);

// ----------member data ---------------------------
const std::string m_record;
const unsigned int m_minNrecords;
Expand All @@ -68,10 +73,47 @@ AlignPCLThresholdsWriter::AlignPCLThresholdsWriter(const edm::ParameterSet& iCon

// ------------ method called for each event ------------
void AlignPCLThresholdsWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
// detect if new payload is used
bool newClass = false;
for (auto& thePSet : m_parameters) {
if (thePSet.exists("fractionCut")) {
newClass = true;
break;
}
}

// output object
AlignPCLThresholds myThresholds{};
// use templated method depending on new/old payload
if (newClass) {
AlignPCLThresholdsHG myThresholds{};
writePayload(myThresholds);
} else {
AlignPCLThresholds myThresholds{};
writePayload(myThresholds);
}
}

DOFs::dof AlignPCLThresholdsWriter::mapOntoEnum(std::string coord) {
if (coord == "X") {
return DOFs::X;
} else if (coord == "Y") {
return DOFs::Y;
} else if (coord == "Z") {
return DOFs::Z;
} else if (coord == "thetaX") {
return DOFs::thetaX;
} else if (coord == "thetaY") {
return DOFs::thetaY;
} else if (coord == "thetaZ") {
return DOFs::thetaZ;
} else {
return DOFs::extraDOF;
}
}

// ------------ templated method to write the payload ------------
template <typename T>
void AlignPCLThresholdsWriter::writePayload(T& myThresholds) {
using namespace edm;

edm::LogInfo("AlignPCLThresholdsWriter") << "Size of AlignPCLThresholds object " << myThresholds.size() << std::endl;

Expand Down Expand Up @@ -167,6 +209,11 @@ void AlignPCLThresholdsWriter::analyze(const edm::Event& iEvent, const edm::Even
// use buil-in method in the CondFormat
myThresholds.printAll();

// additional thresholds for AlignPCLThresholdsHG
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
storeHGthresholds(myThresholds, alignables);
}

// Form the data here
edm::Service<cond::service::PoolDBOutputService> poolDbService;
if (poolDbService.isAvailable()) {
Expand All @@ -176,22 +223,34 @@ void AlignPCLThresholdsWriter::analyze(const edm::Event& iEvent, const edm::Even
}
}

DOFs::dof AlignPCLThresholdsWriter::mapOntoEnum(std::string coord) {
if (coord == "X") {
return DOFs::X;
} else if (coord == "Y") {
return DOFs::Y;
} else if (coord == "Z") {
return DOFs::Z;
} else if (coord == "thetaX") {
return DOFs::thetaX;
} else if (coord == "thetaY") {
return DOFs::thetaY;
} else if (coord == "thetaZ") {
return DOFs::thetaZ;
} else {
return DOFs::extraDOF;
// ------------ method to store additional HG thresholds ------------
void AlignPCLThresholdsWriter::storeHGthresholds(AlignPCLThresholdsHG& myThresholds,
const std::vector<std::string>& alignables) {
edm::LogInfo("AlignPCLThresholdsWriter")
<< "Found type AlignPCLThresholdsHG, additional thresholds are written" << std::endl;

for (auto& alignable : alignables) {
for (auto& thePSet : m_parameters) {
const std::string alignableId(thePSet.getParameter<std::string>("alignableId"));
const std::string DOF(thePSet.getParameter<std::string>("DOF"));

// Get coordType from DOF
AlignPCLThresholds::coordType type = static_cast<AlignPCLThresholds::coordType>(mapOntoEnum(DOF));

if (alignableId == alignable) {
if (thePSet.exists("fractionCut")) {
const double fractionCut(thePSet.getParameter<double>("fractionCut"));
myThresholds.SetFractionCut(alignableId, type, fractionCut);
} else {
myThresholds.SetFractionCut(alignableId, type, -1.); // better way to define default fraction cut??
}
}
}
}

// print additional tresholds
edm::LogInfo("AlignPCLThresholdsWriter") << "Additonal content of AlignPCLThresholdsHG " << std::endl;
myThresholds.printAllHG();
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
Expand All @@ -208,6 +267,8 @@ void AlignPCLThresholdsWriter::fillDescriptions(edm::ConfigurationDescriptions&
desc_thresholds.add<double>("sigCut");
desc_thresholds.add<double>("maxMoveCut");
desc_thresholds.add<double>("maxErrorCut");
// optional thresholds from new payload version
desc_thresholds.addOptional<double>("fractionCut");

std::vector<edm::ParameterSet> default_thresholds(1);
desc.addVPSet("thresholds", desc_thresholds, default_thresholds);
Expand Down
Loading

0 comments on commit be1d3ea

Please sign in to comment.