Skip to content

Commit

Permalink
Next step toward calibration cell collection for HGCal in the next ve…
Browse files Browse the repository at this point in the history
…rsion of HGCal geometry replacing #43045
  • Loading branch information
Sunanda committed Oct 20, 2023
1 parent 245daa4 commit 386c7fa
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 111 deletions.
147 changes: 98 additions & 49 deletions DataFormats/ForwardDetId/interface/HGCSiliconDetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iosfwd>
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
#include "FWCore/Utilities/interface/Exception.h"

/* \brief description of the bit assigment
[0:4] u-coordinate of the cell (measured from the lower left
Expand All @@ -28,101 +29,149 @@ class HGCSiliconDetId : public DetId {
static const int HGCalCoarseTrigger = 2;

/** Create a null cellid*/
HGCSiliconDetId();
constexpr HGCSiliconDetId() : DetId() {}
/** Create cellid from raw id (0=invalid tower id) */
HGCSiliconDetId(uint32_t rawid);
constexpr HGCSiliconDetId(uint32_t rawid) : DetId(rawid) {}
/** Constructor from subdetector, zplus, layer, module, cell numbers */
HGCSiliconDetId(DetId::Detector det, int zp, int type, int layer, int waferU, int waferV, int cellU, int cellV);
constexpr HGCSiliconDetId(
DetId::Detector det, int zp, int type, int layer, int waferU, int waferV, int cellU, int cellV)
: DetId(det, ForwardEmpty) {
int waferUabs(std::abs(waferU)), waferVabs(std::abs(waferV));
int waferUsign = (waferU >= 0) ? 0 : 1;
int waferVsign = (waferV >= 0) ? 0 : 1;
int zside = (zp < 0) ? 1 : 0;
id_ |= (((cellU & kHGCalCellUMask) << kHGCalCellUOffset) | ((cellV & kHGCalCellVMask) << kHGCalCellVOffset) |
((waferUabs & kHGCalWaferUMask) << kHGCalWaferUOffset) |
((waferUsign & kHGCalWaferUSignMask) << kHGCalWaferUSignOffset) |
((waferVabs & kHGCalWaferVMask) << kHGCalWaferVOffset) |
((waferVsign & kHGCalWaferVSignMask) << kHGCalWaferVSignOffset) |
((layer & kHGCalLayerMask) << kHGCalLayerOffset) | ((zside & kHGCalZsideMask) << kHGCalZsideOffset) |
((type & kHGCalTypeMask) << kHGCalTypeOffset));
}

/** Constructor from a generic cell id */
HGCSiliconDetId(const DetId& id);
constexpr HGCSiliconDetId(const DetId& gen) {
if (!gen.null()) {
if ((gen.det() != HGCalEE) && (gen.det() != HGCalHSi)) {
throw cms::Exception("Invalid DetId")
<< "Cannot initialize HGCSiliconDetId from " << std::hex << gen.rawId() << std::dec;
}
}
id_ = gen.rawId();
}

/** Assignment from a generic cell id */
HGCSiliconDetId& operator=(const DetId& id);
constexpr HGCSiliconDetId& operator=(const DetId& gen) {
if (!gen.null()) {
if ((gen.det() != HGCalEE) && (gen.det() != HGCalHSi)) {
throw cms::Exception("Invalid DetId")
<< "Cannot assign HGCSiliconDetId from " << std::hex << gen.rawId() << std::dec;
}
}
id_ = gen.rawId();
return (*this);
}

/** Converter for a geometry cell id */
HGCSiliconDetId geometryCell() const { return HGCSiliconDetId(det(), zside(), 0, layer(), waferU(), waferV(), 0, 0); }
HGCSiliconDetId moduleId() const {
constexpr HGCSiliconDetId geometryCell() const {
return HGCSiliconDetId(det(), zside(), 0, layer(), waferU(), waferV(), 0, 0);
}
constexpr HGCSiliconDetId moduleId() const {
return HGCSiliconDetId(det(), zside(), type(), layer(), waferU(), waferV(), 0, 0);
}

/// get the subdetector
DetId::Detector subdet() const { return det(); }
constexpr DetId::Detector subdet() const { return det(); }

/// get the type
int type() const { return (id_ >> kHGCalTypeOffset) & kHGCalTypeMask; }
constexpr int type() const { return (id_ >> kHGCalTypeOffset) & kHGCalTypeMask; }

/// get the z-side of the cell (1/-1)
int zside() const { return (((id_ >> kHGCalZsideOffset) & kHGCalZsideMask) ? -1 : 1); }
constexpr int zside() const { return (((id_ >> kHGCalZsideOffset) & kHGCalZsideMask) ? -1 : 1); }

/// get the layer #
int layer() const { return (id_ >> kHGCalLayerOffset) & kHGCalLayerMask; }
constexpr int layer() const { return (id_ >> kHGCalLayerOffset) & kHGCalLayerMask; }

/// get the cell #'s in u,v or in x,y
int cellU() const { return (id_ >> kHGCalCellUOffset) & kHGCalCellUMask; }
int cellV() const { return (id_ >> kHGCalCellVOffset) & kHGCalCellVMask; }
std::pair<int, int> cellUV() const { return std::pair<int, int>(cellU(), cellV()); }
int cellX() const {
constexpr int cellU() const { return (id_ >> kHGCalCellUOffset) & kHGCalCellUMask; }
constexpr int cellV() const { return (id_ >> kHGCalCellVOffset) & kHGCalCellVMask; }
constexpr std::pair<int, int> cellUV() const { return std::pair<int, int>(cellU(), cellV()); }
constexpr int cellX() const {
int N = (type() == HGCalFine) ? HGCalFineN : HGCalCoarseN;
return (3 * (cellV() - N) + 2);
}
int cellY() const {
constexpr int cellY() const {
int N = (type() == HGCalFine) ? HGCalFineN : HGCalCoarseN;
return (2 * cellU() - (N + cellV()));
}
std::pair<int, int> cellXY() const { return std::pair<int, int>(cellX(), cellY()); }
constexpr std::pair<int, int> cellXY() const { return std::pair<int, int>(cellX(), cellY()); }

/// get the wafer #'s in u,v or in x,y
int waferUAbs() const { return (id_ >> kHGCalWaferUOffset) & kHGCalWaferUMask; }
int waferVAbs() const { return (id_ >> kHGCalWaferVOffset) & kHGCalWaferVMask; }
int waferU() const { return (((id_ >> kHGCalWaferUSignOffset) & kHGCalWaferUSignMask) ? -waferUAbs() : waferUAbs()); }
int waferV() const { return (((id_ >> kHGCalWaferVSignOffset) & kHGCalWaferVSignMask) ? -waferVAbs() : waferVAbs()); }
std::pair<int, int> waferUV() const { return std::pair<int, int>(waferU(), waferV()); }
int waferX() const { return (-2 * waferU() + waferV()); }
int waferY() const { return (2 * waferV()); }
std::pair<int, int> waferXY() const { return std::pair<int, int>(waferX(), waferY()); }
constexpr int waferUAbs() const { return (id_ >> kHGCalWaferUOffset) & kHGCalWaferUMask; }
constexpr int waferVAbs() const { return (id_ >> kHGCalWaferVOffset) & kHGCalWaferVMask; }
constexpr int waferU() const {
return (((id_ >> kHGCalWaferUSignOffset) & kHGCalWaferUSignMask) ? -waferUAbs() : waferUAbs());
}
constexpr int waferV() const {
return (((id_ >> kHGCalWaferVSignOffset) & kHGCalWaferVSignMask) ? -waferVAbs() : waferVAbs());
}
constexpr std::pair<int, int> waferUV() const { return std::pair<int, int>(waferU(), waferV()); }
constexpr int waferX() const { return (-2 * waferU() + waferV()); }
constexpr int waferY() const { return (2 * waferV()); }
constexpr std::pair<int, int> waferXY() const { return std::pair<int, int>(waferX(), waferY()); }
constexpr void unpack(int& ty, int& zs, int& ly, int& wU, int& wV, int& cU, int& cV) const {
ty = type();
zs = zside();
ly = layer();
wU = waferU();
wV = waferV();
cU = cellU();
cV = cellV();
}

// get trigger cell u,v
int triggerCellU() const {
constexpr int triggerCellU() const {
int N = (type() == HGCalFine) ? HGCalFineN : HGCalCoarseN;
int NT = (type() == HGCalFine) ? HGCalFineTrigger : HGCalCoarseTrigger;
return (cellU() >= N && cellV() >= N)
? cellU() / NT
: ((cellU() < N && cellU() <= cellV()) ? cellU() / NT : (1 + (cellU() - (cellV() % NT + 1)) / NT));
}
int triggerCellV() const {
constexpr int triggerCellV() const {
int N = (type() == HGCalFine) ? HGCalFineN : HGCalCoarseN;
int NT = (type() == HGCalFine) ? HGCalFineTrigger : HGCalCoarseTrigger;
return (cellU() >= N && cellV() >= N)
? cellV() / NT
: ((cellU() < N && cellU() <= cellV()) ? ((cellV() - cellU()) / NT + cellU() / NT) : cellV() / NT);
}
std::pair<int, int> triggerCellUV() const { return std::pair<int, int>(triggerCellU(), triggerCellV()); }
constexpr std::pair<int, int> triggerCellUV() const { return std::pair<int, int>(triggerCellU(), triggerCellV()); }

/// consistency check : no bits left => no overhead
bool isEE() const { return (det() == HGCalEE); }
bool isHE() const { return (det() == HGCalHSi); }
bool isForward() const { return true; }
constexpr bool isEE() const { return (det() == HGCalEE); }
constexpr bool isHE() const { return (det() == HGCalHSi); }
constexpr bool isForward() const { return true; }

static const HGCSiliconDetId Undefined;

public:
static const int kHGCalCellUOffset = 0;
static const int kHGCalCellUMask = 0x1F;
static const int kHGCalCellVOffset = 5;
static const int kHGCalCellVMask = 0x1F;
static const int kHGCalWaferUOffset = 10;
static const int kHGCalWaferUMask = 0xF;
static const int kHGCalWaferUSignOffset = 14;
static const int kHGCalWaferUSignMask = 0x1;
static const int kHGCalWaferVOffset = 15;
static const int kHGCalWaferVMask = 0xF;
static const int kHGCalWaferVSignOffset = 19;
static const int kHGCalWaferVSignMask = 0x1;
static const int kHGCalLayerOffset = 20;
static const int kHGCalLayerMask = 0x1F;
static const int kHGCalZsideOffset = 25;
static const int kHGCalZsideMask = 0x1;
static const int kHGCalTypeOffset = 26;
static const int kHGCalTypeMask = 0x3;
static constexpr uint32_t kHGCalCellUOffset = 0;
static constexpr uint32_t kHGCalCellUMask = 0x1F;
static constexpr uint32_t kHGCalCellVOffset = 5;
static constexpr uint32_t kHGCalCellVMask = 0x1F;
static constexpr uint32_t kHGCalWaferUOffset = 10;
static constexpr uint32_t kHGCalWaferUMask = 0xF;
static constexpr uint32_t kHGCalWaferUSignOffset = 14;
static constexpr uint32_t kHGCalWaferUSignMask = 0x1;
static constexpr uint32_t kHGCalWaferVOffset = 15;
static constexpr uint32_t kHGCalWaferVMask = 0xF;
static constexpr uint32_t kHGCalWaferVSignOffset = 19;
static constexpr uint32_t kHGCalWaferVSignMask = 0x1;
static constexpr uint32_t kHGCalLayerOffset = 20;
static constexpr uint32_t kHGCalLayerMask = 0x1F;
static constexpr uint32_t kHGCalZsideOffset = 25;
static constexpr uint32_t kHGCalZsideMask = 0x1;
static constexpr uint32_t kHGCalTypeOffset = 26;
static constexpr uint32_t kHGCalTypeMask = 0x3;
};

std::ostream& operator<<(std::ostream&, const HGCSiliconDetId& id);
Expand Down
44 changes: 1 addition & 43 deletions DataFormats/ForwardDetId/src/HGCSiliconDetId.cc
Original file line number Diff line number Diff line change
@@ -1,50 +1,8 @@
#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
#include "FWCore/Utilities/interface/Exception.h"
#include <ostream>
#include <iostream>

const HGCSiliconDetId HGCSiliconDetId::Undefined(HGCalEE, 0, 0, 0, 0, 0, 0, 0);

HGCSiliconDetId::HGCSiliconDetId() : DetId() {}

HGCSiliconDetId::HGCSiliconDetId(uint32_t rawid) : DetId(rawid) {}

HGCSiliconDetId::HGCSiliconDetId(
DetId::Detector det, int zp, int type, int layer, int waferU, int waferV, int cellU, int cellV)
: DetId(det, ForwardEmpty) {
int waferUabs(std::abs(waferU)), waferVabs(std::abs(waferV));
int waferUsign = (waferU >= 0) ? 0 : 1;
int waferVsign = (waferV >= 0) ? 0 : 1;
int zside = (zp < 0) ? 1 : 0;
id_ |= (((cellU & kHGCalCellUMask) << kHGCalCellUOffset) | ((cellV & kHGCalCellVMask) << kHGCalCellVOffset) |
((waferUabs & kHGCalWaferUMask) << kHGCalWaferUOffset) |
((waferUsign & kHGCalWaferUSignMask) << kHGCalWaferUSignOffset) |
((waferVabs & kHGCalWaferVMask) << kHGCalWaferVOffset) |
((waferVsign & kHGCalWaferVSignMask) << kHGCalWaferVSignOffset) |
((layer & kHGCalLayerMask) << kHGCalLayerOffset) | ((zside & kHGCalZsideMask) << kHGCalZsideOffset) |
((type & kHGCalTypeMask) << kHGCalTypeOffset));
}

HGCSiliconDetId::HGCSiliconDetId(const DetId& gen) {
if (!gen.null()) {
if ((gen.det() != HGCalEE) && (gen.det() != HGCalHSi)) {
throw cms::Exception("Invalid DetId")
<< "Cannot initialize HGCSiliconDetId from " << std::hex << gen.rawId() << std::dec;
}
}
id_ = gen.rawId();
}

HGCSiliconDetId& HGCSiliconDetId::operator=(const DetId& gen) {
if (!gen.null()) {
if ((gen.det() != HGCalEE) && (gen.det() != HGCalHSi)) {
throw cms::Exception("Invalid DetId")
<< "Cannot assign HGCSiliconDetId from " << std::hex << gen.rawId() << std::dec;
}
}
id_ = gen.rawId();
return (*this);
}
const HGCSiliconDetId HGCSiliconDetId::Undefined(DetId::HGCalEE, 0, 0, 0, 0, 0, 0, 0);

std::ostream& operator<<(std::ostream& s, const HGCSiliconDetId& id) {
return s << " HGCSiliconDetId::EE:HE= " << id.isEE() << ":" << id.isHE() << " type= " << id.type()
Expand Down
3 changes: 3 additions & 0 deletions Geometry/HGCalCommonData/interface/HGCalTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class HGCalTypes {
// Get the front-back index from the layer orientation index
static constexpr int32_t layerFrontBack(int32_t layerOrient) { return ((layerOrient == WaferCenterB) ? 1 : -1); }
static constexpr int32_t waferFrontBack(int32_t index) { return ((index == 0) ? -1 : 1); }
// LD vs HD and Fullvs Partial wafer
static constexpr bool waferHD(int32_t type) { return ((type == WaferFineThin) || (type == WaferFineThick)); }
static constexpr bool waferFull(int32_t type) { return (type == WaferFull); }

private:
static constexpr int32_t facu_ = 1;
Expand Down
4 changes: 4 additions & 0 deletions SimG4CMS/Calo/interface/CaloSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CaloSD : public SensitiveCaloDetector,
bool ignoreTkID = false);
~CaloSD() override;

void newCollection(const std::string& name, edm::ParameterSet const& p);
G4bool ProcessHits(G4Step* step, G4TouchableHistory*) override;
bool ProcessHits(G4GFlashSpot* aSpot, G4TouchableHistory*) override;

Expand Down Expand Up @@ -143,6 +144,8 @@ class CaloSD : public SensitiveCaloDetector,
CaloHitID currentID[2], previousID[2];

double energyCut, tmaxHit, eminHit;
std::vector<std::string> hcn_;
std::vector<int> useResMap_;

CaloG4Hit* currentHit[2];

Expand Down Expand Up @@ -185,6 +188,7 @@ class CaloSD : public SensitiveCaloDetector,
bool doFineCalo_;
double eMinFine_;
int nHC_;
std::string detName_[2], collName_[2];

std::map<CaloHitID, CaloG4Hit*> hitMap[2];
std::map<int, TrackWithHistory*> tkMap;
Expand Down
7 changes: 6 additions & 1 deletion SimG4CMS/Calo/interface/HGCalSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "SimG4CMS/Calo/interface/HGCGuardRing.h"
#include "SimG4CMS/Calo/interface/HGCMouseBite.h"
#include "SimG4CMS/Calo/interface/HGCGuardRingPartial.h"
#include "Geometry/HGCalCommonData/interface/HGCalCellOffset.h"
#include <string>

class HGCalDDDConstants;
Expand Down Expand Up @@ -39,17 +40,21 @@ class HGCalSD : public CaloSD, public Observer<const BeginOfJob *> {
private:
uint32_t setDetUnitId(int, int, int, int, G4ThreeVector &);
bool isItinFidVolume(const G4ThreeVector &);
bool calibCell(const uint32_t &id, double &frac);

std::string myName_;
const HGCalDDDConstants *hgcons_;
edm::ParameterSet const &ps_;
std::unique_ptr<HGCalNumberingScheme> numberingScheme_;
std::unique_ptr<HGCGuardRing> guardRing_;
std::unique_ptr<HGCGuardRingPartial> guardRingPartial_;
std::unique_ptr<HGCMouseBite> mouseBite_;
std::unique_ptr<HGCalCellOffset> cellOffset_;
DetId::Detector mydet_;
std::string nameX_;
HGCalGeometryMode::GeometryMode geom_mode_;
double eminHit_, slopeMin_, distanceFromEdge_;
double mouseBiteCut_, weight_;
double waferSize_, mouseBiteCut_, guardRingOffset_, weight_;
int levelT1_, levelT2_, cornerMinMask_;
bool storeAllG4Hits_;
bool fiducialCut_, rejectMB_, waferRot_, checkID_;
Expand Down
Loading

0 comments on commit 386c7fa

Please sign in to comment.