forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring geometry testing infrastructure (cms-sw#114)
- Loading branch information
Showing
14 changed files
with
1,495 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifndef __L1Trigger_L1THGCal_HGCalTriggerGeoTesterBase_h__ | ||
#define __L1Trigger_L1THGCal_HGCalTriggerGeoTesterBase_h__ | ||
|
||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/ConsumesCollector.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "TTree.h" | ||
#include <unordered_map> | ||
#include <string> | ||
|
||
namespace HepPDT { | ||
class ParticleDataTable; | ||
} | ||
class MagneticField; | ||
class HGCalTriggerGeometryBase; | ||
|
||
struct HGCalTriggerGeoTesterEventSetup { | ||
edm::ESHandle<HGCalTriggerGeometryBase> geometry; | ||
}; | ||
|
||
class HGCalTriggerGeoTesterErrors { | ||
public: | ||
enum ErrorCode { | ||
CellValidity = 0, | ||
MissingCellInTC, | ||
InvalidCellInTC, | ||
MissingTCInModule, | ||
InvalidTCInModule, | ||
ConnectedModuleWithoutLpgbt, | ||
ModuleSplitInStage1, | ||
MissingModuleInStage1FPGA, | ||
InvalidModuleInStage1FPGA, | ||
MissingStage1InStage2FPGA, | ||
InvalidStage1InStage2FPGA | ||
}; | ||
static const std::unordered_map<ErrorCode, std::string> messages; | ||
|
||
void fill(ErrorCode error, unsigned detid) { | ||
auto itr_err = error_detids_.insert({error, {}}).first; | ||
itr_err->second.insert(detid); | ||
auto itr_id = detid_errors_.insert({detid, {}}).first; | ||
itr_id->second.insert(error); | ||
} | ||
const std::unordered_map<ErrorCode, std::set<unsigned>>& errors() const { return error_detids_; } | ||
const std::unordered_map<unsigned, std::set<ErrorCode>>& detids() const { return detid_errors_; } | ||
|
||
private: | ||
std::unordered_map<ErrorCode, std::set<unsigned>> error_detids_; | ||
std::unordered_map<unsigned, std::set<ErrorCode>> detid_errors_; | ||
}; | ||
|
||
class HGCalTriggerGeoTesterBase { | ||
public: | ||
HGCalTriggerGeoTesterBase(const edm::ParameterSet& conf) : name_(conf.getParameter<std::string>("TesterName")){}; | ||
virtual ~HGCalTriggerGeoTesterBase(){}; | ||
const std::string& name() const { return name_; } | ||
virtual void initialize(TTree*, const edm::ParameterSet&) = 0; | ||
virtual void check(const HGCalTriggerGeoTesterEventSetup&) = 0; | ||
virtual void fill(const HGCalTriggerGeoTesterEventSetup&) = 0; | ||
const HGCalTriggerGeoTesterErrors& errors() { return errors_; } | ||
|
||
protected: | ||
virtual void clear() = 0; | ||
const std::string name_; | ||
HGCalTriggerGeoTesterErrors errors_; | ||
TTree* tree_; | ||
}; | ||
|
||
#include "FWCore/PluginManager/interface/PluginFactory.h" | ||
typedef edmplugin::PluginFactory<HGCalTriggerGeoTesterBase*(const edm::ParameterSet&)> HGCalTriggerGeoTesterFactory; | ||
|
||
#endif |
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
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,16 @@ | ||
#include "L1Trigger/L1THGCal/interface/HGCalTriggerGeoTesterBase.h" | ||
|
||
const std::unordered_map<HGCalTriggerGeoTesterErrors::ErrorCode, std::string> HGCalTriggerGeoTesterErrors::messages = { | ||
{HGCalTriggerGeoTesterErrors::CellValidity, "Found invalid cell(s)"}, | ||
{HGCalTriggerGeoTesterErrors::MissingCellInTC, "Found missing cell(s) in trigger cell"}, | ||
{HGCalTriggerGeoTesterErrors::InvalidCellInTC, "Found invalid cell(s) in trigger cell"}, | ||
{HGCalTriggerGeoTesterErrors::MissingTCInModule, "Found missing trigger cell(s) in module"}, | ||
{HGCalTriggerGeoTesterErrors::InvalidTCInModule, "Found invalid trigger cell(s) in module"}, | ||
{HGCalTriggerGeoTesterErrors::ConnectedModuleWithoutLpgbt, "Found module without lpGBT but flagged as connected"}, | ||
{HGCalTriggerGeoTesterErrors::ModuleSplitInStage1, "Found module with lpGBTs connected to several Stage 1 FPGAs"}, | ||
{HGCalTriggerGeoTesterErrors::MissingModuleInStage1FPGA, "Found missing module(s) in Stage 1 FPGA"}, | ||
{HGCalTriggerGeoTesterErrors::InvalidModuleInStage1FPGA, "Found invalid module(s) in Stage 1 FPGA"}, | ||
{HGCalTriggerGeoTesterErrors::MissingStage1InStage2FPGA, "Found missing stage1(s) in Stage 2 FPGA"}, | ||
{HGCalTriggerGeoTesterErrors::InvalidStage1InStage2FPGA, "Found invalid stage1(s) in Stage 2 FPGA"}}; | ||
|
||
EDM_REGISTER_PLUGINFACTORY(HGCalTriggerGeoTesterFactory, "HGCalTriggerGeoTesterFactory"); |
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,7 +1,15 @@ | ||
<use name="Geometry/HGCalGeometry"/> | ||
<use name="L1Trigger/L1THGCal"/> | ||
<use name="Geometry/Records"/> | ||
<use name="CommonTools/UtilAlgos"/> | ||
<library name="testL1TriggerL1THGCal" file="HGCalTriggerGeomTesterV9Imp2.cc,HGCalTriggerGeomTesterV9Imp3.cc,HGCalBackendStage1ParameterExtractor.cc"> | ||
<use name="Geometry/HGCalGeometry"/> | ||
<use name="L1Trigger/L1THGCal"/> | ||
<use name="Geometry/Records"/> | ||
<use name="CommonTools/UtilAlgos"/> | ||
<flags EDM_PLUGIN="1"/> | ||
</library> | ||
|
||
<library name="testL1TriggerL1THGCal_geometry" file="geometry/*.cc"> | ||
<use name="Geometry/HGCalGeometry"/> | ||
<use name="L1Trigger/L1THGCal"/> | ||
<use name="Geometry/Records"/> | ||
<use name="CommonTools/UtilAlgos"/> | ||
<flags EDM_PLUGIN="1"/> | ||
</library> |
152 changes: 152 additions & 0 deletions
152
L1Trigger/L1THGCal/test/geometry/HGCalTriggerGeoTesterBackendStage1.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,152 @@ | ||
|
||
#include "Geometry/Records/interface/CaloGeometryRecord.h" | ||
#include "DataFormats/ForwardDetId/interface/HGCalTriggerModuleDetId.h" | ||
#include "DataFormats/ForwardDetId/interface/HGCalTriggerBackendDetId.h" | ||
#include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h" | ||
#include "L1Trigger/L1THGCal/interface/HGCalTriggerGeoTesterBase.h" | ||
#include "L1Trigger/L1THGCal/interface/HGCalTriggerTools.h" | ||
|
||
class HGCalTriggerGeoTesterBackendStage1 : public HGCalTriggerGeoTesterBase { | ||
public: | ||
HGCalTriggerGeoTesterBackendStage1(const edm::ParameterSet& conf); | ||
~HGCalTriggerGeoTesterBackendStage1() override{}; | ||
void initialize(TTree*, const edm::ParameterSet&) final; | ||
void check(const HGCalTriggerGeoTesterEventSetup& es) final; | ||
void fill(const HGCalTriggerGeoTesterEventSetup& es) final; | ||
|
||
private: | ||
void clear() final; | ||
|
||
HGCalTriggerTools triggerTools_; | ||
|
||
unsigned id_ = 0; | ||
unsigned errorbits_ = 0; | ||
int label_ = 0; | ||
int zside_ = 0; | ||
int sector_ = 0; | ||
int type_ = 0; | ||
int lpgbts_n_ = 0; | ||
int modules_n_ = 0; | ||
std::vector<uint32_t> lpgbts_; | ||
std::vector<uint32_t> modules_; | ||
}; | ||
|
||
DEFINE_EDM_PLUGIN(HGCalTriggerGeoTesterFactory, | ||
HGCalTriggerGeoTesterBackendStage1, | ||
"HGCalTriggerGeoTesterBackendStage1"); | ||
|
||
HGCalTriggerGeoTesterBackendStage1::HGCalTriggerGeoTesterBackendStage1(const edm::ParameterSet& conf) | ||
: HGCalTriggerGeoTesterBase(conf) {} | ||
|
||
void HGCalTriggerGeoTesterBackendStage1::initialize(TTree* tree, const edm::ParameterSet& conf) { | ||
tree_ = tree; | ||
|
||
tree_->Branch("id", &id_, "id/i"); | ||
tree_->Branch("errorbits", &errorbits_, "errorbits/i"); | ||
tree_->Branch("zside", &zside_, "zside/I"); | ||
tree_->Branch("sector", §or_, "sector/I"); | ||
tree_->Branch("label", &label_, "label/I"); | ||
tree_->Branch("type", &type_, "type/i"); | ||
tree_->Branch("lpgbts_n", &lpgbts_n_, "lpgbts_n/I"); | ||
tree_->Branch("lpgbts", &lpgbts_); | ||
tree_->Branch("modules_n", &modules_n_, "modules_n/I"); | ||
tree_->Branch("modules", &modules_); | ||
} | ||
|
||
void HGCalTriggerGeoTesterBackendStage1::fill(const HGCalTriggerGeoTesterEventSetup& es) { | ||
clear(); | ||
edm::LogPrint("TreeFilling") << "Filling Backend Stage 1 tree"; | ||
// Create list of Stage 1 boards from valid cells | ||
std::unordered_set<uint32_t> modules; | ||
for (const auto& id : es.geometry->eeGeometry()->getValidDetIds()) { | ||
modules.insert(es.geometry->getModuleFromCell(id)); | ||
} | ||
for (const auto& id : es.geometry->hsiGeometry()->getValidDetIds()) { | ||
modules.insert(es.geometry->getModuleFromCell(id)); | ||
} | ||
for (const auto& id : es.geometry->hscGeometry()->getValidDetIds()) { | ||
modules.insert(es.geometry->getModuleFromCell(id)); | ||
} | ||
std::unordered_set<uint32_t> stage1s; | ||
for (const auto& module : modules) { | ||
if (es.geometry->disconnectedModule(module)) | ||
continue; | ||
stage1s.insert(es.geometry->getStage1FpgaFromModule(module)); | ||
} | ||
for (const auto& id : stage1s) { | ||
HGCalTriggerBackendDetId detid(id); | ||
const auto error_itr = errors_.detids().find(id); | ||
if (error_itr != errors_.detids().end()) { | ||
for (const auto& error : error_itr->second) { | ||
errorbits_ |= (0x1 << error); | ||
} | ||
} | ||
id_ = id; | ||
zside_ = detid.zside(); | ||
type_ = detid.type(); | ||
sector_ = detid.sector(); | ||
label_ = detid.label(); | ||
auto lpgbts = es.geometry->getLpgbtsFromStage1Fpga(id); | ||
lpgbts_n_ = lpgbts.size(); | ||
lpgbts_.resize(lpgbts.size()); | ||
std::copy(lpgbts.begin(), lpgbts.end(), lpgbts_.begin()); | ||
auto modules = es.geometry->getModulesFromStage1Fpga(id); | ||
modules_n_ = modules.size(); | ||
modules_.resize(modules.size()); | ||
std::copy(modules.begin(), modules.end(), modules_.begin()); | ||
|
||
tree_->Fill(); | ||
clear(); | ||
} | ||
} | ||
|
||
void HGCalTriggerGeoTesterBackendStage1::check(const HGCalTriggerGeoTesterEventSetup& es) { | ||
edm::LogPrint("GeoTesterBackendStage1") << "Checking Stage 1"; | ||
// Create list of modules from valid cells | ||
std::unordered_set<uint32_t> modules; | ||
for (const auto& id : es.geometry->eeGeometry()->getValidDetIds()) { | ||
modules.insert(es.geometry->getModuleFromCell(id)); | ||
} | ||
for (const auto& id : es.geometry->hsiGeometry()->getValidDetIds()) { | ||
modules.insert(es.geometry->getModuleFromCell(id)); | ||
} | ||
for (const auto& id : es.geometry->hscGeometry()->getValidDetIds()) { | ||
modules.insert(es.geometry->getModuleFromCell(id)); | ||
} | ||
std::unordered_map<uint32_t, std::unordered_set<uint32_t>> stage1_to_modules; | ||
for (const auto& id : modules) { | ||
if (es.geometry->disconnectedModule(id)) | ||
continue; | ||
auto stage1 = es.geometry->getStage1FpgaFromModule(id); | ||
auto itr_insert = stage1_to_modules.emplace(stage1, std::unordered_set<uint32_t>()); | ||
itr_insert.first->second.emplace(id); | ||
} | ||
|
||
// Check consistency of trigger cells included in modules | ||
for (const auto& [stage1id, modules] : stage1_to_modules) { | ||
HGCalTriggerGeometryBase::geom_set modules_from_stage1 = es.geometry->getModulesFromStage1Fpga(stage1id); | ||
for (auto module : modules) { | ||
if (modules_from_stage1.find(module) == modules_from_stage1.end()) { | ||
errors_.fill(HGCalTriggerGeoTesterErrors::MissingModuleInStage1FPGA, stage1id); | ||
} | ||
} | ||
for (auto module : modules_from_stage1) { | ||
if (modules.find(module) == modules.end()) { | ||
errors_.fill(HGCalTriggerGeoTesterErrors::InvalidModuleInStage1FPGA, stage1id); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void HGCalTriggerGeoTesterBackendStage1::clear() { | ||
id_ = 0; | ||
errorbits_ = 0; | ||
label_ = 0; | ||
zside_ = 0; | ||
sector_ = 0; | ||
type_ = 0; | ||
lpgbts_n_ = 0; | ||
lpgbts_.clear(); | ||
modules_n_ = 0; | ||
modules_.clear(); | ||
} |
Oops, something went wrong.