Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase2-TB69 Provide the geometry for HGCal Test Beam application #40713

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions Geometry/HGCalGeometry/interface/HGCalTBGeometry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#ifndef GeometryHGCalGeometryHGCalTBGeometry_h
#define GeometryHGCalGeometryHGCalTBGeometry_h

/*
* Geometry for High Granularity Calorimeter TestBeam
* This geometry is essentially driven by topology,
* which is thus encapsulated in this class.
* This makes this geometry not suitable to be loaded
* by regular CaloGeometryLoader<T>
*/

#include "DataFormats/Common/interface/AtomicPtrCache.h"
#include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
#include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
#include "DataFormats/GeometryVector/interface/GlobalVector.h"
#include "DetectorDescription/Core/interface/DDFilteredView.h"
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "Geometry/CaloGeometry/interface/FlatHexagon.h"
#include "Geometry/CaloGeometry/interface/FlatTrd.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/CaloTopology/interface/HGCalTBTopology.h"
#include "Geometry/Records/interface/HGCalGeometryRecord.h"
#include "MagneticField/Engine/interface/MagneticField.h"
#include <vector>

class HGCalTBGeometry final : public CaloSubdetectorGeometry {
public:
typedef std::vector<FlatHexagon> CellVec;
typedef std::vector<FlatTrd> CellVec2;
typedef CaloCellGeometry::CCGFloat CCGFloat;
typedef CaloCellGeometry::Pt3D Pt3D;
typedef CaloCellGeometry::Pt3DVec Pt3DVec;

typedef std::set<DetId> DetIdSet;
typedef std::vector<GlobalPoint> CornersVec;

typedef HGCalGeometryRecord AlignedRecord; // NOTE: not aligned yet
typedef PHGCalRcd PGeometryRecord;

static constexpr unsigned int k_NumberOfParametersPerTrd = 12; // FlatTrd
static constexpr unsigned int k_NumberOfParametersPerHex = 3; // FlatHexagon
static constexpr unsigned int k_NumberOfParametersPerShape = 3; // FlatHexagon
static constexpr unsigned int k_NumberOfShapes = 100;
static constexpr unsigned int k_NumberOfShapesTrd = 1000;

static std::string dbString() { return "PHGCalTBRcd"; }

HGCalTBGeometry(const HGCalTBTopology& topology);

~HGCalTBGeometry() override;

void localCorners(Pt3DVec& lc, const CCGFloat* pv, unsigned int i, Pt3D& ref);

void newCell(const GlobalPoint& f1,
const GlobalPoint& f2,
const GlobalPoint& f3,
const CCGFloat* parm,
const DetId& detId) override;

/// Get the cell geometry of a given detector id. Should return false if not found.
std::shared_ptr<const CaloCellGeometry> getGeometry(const DetId& id) const override;

bool present(const DetId& id) const override;

void getSummary(CaloSubdetectorGeometry::TrVec& trVector,
CaloSubdetectorGeometry::IVec& iVector,
CaloSubdetectorGeometry::DimVec& dimVector,
CaloSubdetectorGeometry::IVec& dinsVector) const override;

GlobalPoint getPosition(const DetId& id, bool debug = false) const;
GlobalPoint getWaferPosition(const DetId& id) const;

/// Returns area of a cell
double getArea(const DetId& detid) const;

/// Returns the corner points of this cell's volume.
CornersVec getCorners(const DetId& id) const;
CornersVec get8Corners(const DetId& id) const;
CornersVec getNewCorners(const DetId& id, bool debug = false) const;

// Get neighbor in z along a direction
DetId neighborZ(const DetId& idin, const GlobalVector& p) const;
DetId neighborZ(const DetId& idin, const MagneticField* bField, int charge, const GlobalVector& momentum) const;

// avoid sorting set in base class
const std::vector<DetId>& getValidDetIds(DetId::Detector det = DetId::Detector(0), int subdet = 0) const override {
return m_validIds;
}
const std::vector<DetId>& getValidGeomDetIds(void) const { return m_validGeomIds; }

// Get closest cell, etc...
DetId getClosestCell(const GlobalPoint& r) const override;

/** \brief Get a list of all cells within a dR of the given cell

The default implementation makes a loop over all cell geometries.
Cleverer implementations are suggested to use rough conversions between
eta/phi and ieta/iphi and test on the boundaries.
*/
DetIdSet getCells(const GlobalPoint& r, double dR) const override;

virtual void fillNamedParams(DDFilteredView fv);
void initializeParms() override;

static std::string producerTag() { return "HGCalTB"; }
std::string cellElement() const;

const HGCalTBTopology& topology() const { return m_topology; }
void sortDetIds();

protected:
unsigned int indexFor(const DetId& id) const override;
using CaloSubdetectorGeometry::sizeForDenseIndex;
unsigned int sizeForDenseIndex() const;

// Modify the RawPtr class
const CaloCellGeometry* getGeometryRawPtr(uint32_t index) const override;

std::shared_ptr<const CaloCellGeometry> cellGeomPtr(uint32_t index) const override;

void addValidID(const DetId& id);
unsigned int getClosestCellIndex(const GlobalPoint& r) const;

private:
template <class T>
unsigned int getClosestCellIndex(const GlobalPoint& r, const std::vector<T>& vec) const;
std::shared_ptr<const CaloCellGeometry> cellGeomPtr(uint32_t index, const GlobalPoint& p) const;
DetId getGeometryDetId(DetId detId) const;

static constexpr double k_half = 0.5;
static constexpr double k_fac1 = 0.5;
static constexpr double k_fac2 = 1.0 / 3.0;

const HGCalTBTopology& m_topology;
CellVec m_cellVec;
std::vector<DetId> m_validGeomIds;
DetId::Detector m_det;
ForwardSubdetector m_subdet;
const double twoBysqrt3_;
};

#endif
27 changes: 27 additions & 0 deletions Geometry/HGCalGeometry/interface/HGCalTBGeometryLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef GeometryHGCalGeometryHGCalTBGeometryLoader_h
#define GeometryHGCalGeometryHGCalTBGeometryLoader_h
#include "Geometry/HGCalGeometry/interface/HGCalTBGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
#include "Geometry/CaloGeometry/interface/FlatHexagon.h"

class HGCalTBTopology;
class HGCalTBGeometry;

class HGCalTBGeometryLoader {
public:
typedef CaloCellGeometry::CCGFloat CCGFloat;
typedef std::vector<float> ParmVec;

HGCalTBGeometryLoader();
~HGCalTBGeometryLoader() = default;

HGCalTBGeometry* build(const HGCalTBTopology&);

private:
void buildGeom(const ParmVec&, const HepGeom::Transform3D&, const DetId&, HGCalTBGeometry*);

const double twoBysqrt3_;
int parametersPerShape_;
};

#endif
77 changes: 77 additions & 0 deletions Geometry/HGCalGeometry/plugins/HGCalTBGeometryESProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// -*- C++ -*-
//
// Package: HGCalGeometry
// Class: HGCalTBGeometryESProducer
//
/**\class HGCalTBGeometryESProducer HGCalTBGeometryESProducer.h

Description: <one line class summary>

Implementation:
<Notes on implementation>
*/
//
// Original Author: Sunanda Banerjee
//
//

// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "Geometry/CaloTopology/interface/HGCalTBTopology.h"
#include "Geometry/HGCalGeometry/interface/HGCalTBGeometry.h"
#include "Geometry/HGCalGeometry/interface/HGCalTBGeometryLoader.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"

//#define EDM_ML_DEBUG

//
// class decleration
//

class HGCalTBGeometryESProducer : public edm::ESProducer {
public:
HGCalTBGeometryESProducer(const edm::ParameterSet& iP);
~HGCalTBGeometryESProducer() override;

using ReturnType = std::unique_ptr<HGCalTBGeometry>;

ReturnType produce(const IdealGeometryRecord&);

private:
// ----------member data ---------------------------
edm::ESGetToken<HGCalTBTopology, IdealGeometryRecord> topologyToken_;
std::string name_;
};

HGCalTBGeometryESProducer::HGCalTBGeometryESProducer(const edm::ParameterSet& iConfig) {
name_ = iConfig.getUntrackedParameter<std::string>("Name");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Constructing HGCalTBGeometry for " << name_;
#endif
auto cc = setWhatProduced(this, name_);
topologyToken_ = cc.consumes<HGCalTBTopology>(edm::ESInputTag{"", name_});
}

HGCalTBGeometryESProducer::~HGCalTBGeometryESProducer() {}

//
// member functions
//

// ------------ method called to produce the data ------------
HGCalTBGeometryESProducer::ReturnType HGCalTBGeometryESProducer::produce(const IdealGeometryRecord& iRecord) {
const auto& topo = iRecord.get(topologyToken_);
edm::LogVerbatim("HGCalGeom") << "Create HGCalTBGeometry (*topo) for " << name_;

HGCalTBGeometryLoader builder;
return ReturnType(builder.build(topo));
}

DEFINE_FWK_EVENTSETUP_MODULE(HGCalTBGeometryESProducer);
13 changes: 13 additions & 0 deletions Geometry/HGCalGeometry/python/HGCalTBGeometryESProducer_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import FWCore.ParameterSet.Config as cms

#
# This cfi should be included to build the HGCal TB Geometry
#

HGCalTBEEGeometryESProducer = cms.ESProducer("HGCalTBGeometryESProducer",
Name = cms.untracked.string("HGCalEESensitive") )


HGCalTBHESilGeometryESProducer = cms.ESProducer("HGCalTBGeometryESProducer",
Name = cms.untracked.string("HGCalHESiliconSensitive") )

2 changes: 1 addition & 1 deletion Geometry/HGCalGeometry/src/HGCalGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ const CaloCellGeometry* HGCalGeometry::getGeometryRawPtr(uint32_t index) const {
const CaloCellGeometry* cell(&m_cellVec2[index]);
return (nullptr == cell->param() ? nullptr : cell);
} else {
if (m_cellVec2.size() < index)
if (m_cellVec.size() < index)
return nullptr;
const CaloCellGeometry* cell(&m_cellVec[index]);
return (nullptr == cell->param() ? nullptr : cell);
Expand Down
Loading