diff --git a/DataFormats/ForwardDetId/interface/HGCSiliconDetId.h b/DataFormats/ForwardDetId/interface/HGCSiliconDetId.h index 9c6014e5a7545..0ce56bd2b2b72 100644 --- a/DataFormats/ForwardDetId/interface/HGCSiliconDetId.h +++ b/DataFormats/ForwardDetId/interface/HGCSiliconDetId.h @@ -4,6 +4,7 @@ #include #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 @@ -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 cellUV() const { return std::pair(cellU(), cellV()); } - int cellX() const { + constexpr int cellU() const { return (id_ >> kHGCalCellUOffset) & kHGCalCellUMask; } + constexpr int cellV() const { return (id_ >> kHGCalCellVOffset) & kHGCalCellVMask; } + constexpr std::pair cellUV() const { return std::pair(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 cellXY() const { return std::pair(cellX(), cellY()); } + constexpr std::pair cellXY() const { return std::pair(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 waferUV() const { return std::pair(waferU(), waferV()); } - int waferX() const { return (-2 * waferU() + waferV()); } - int waferY() const { return (2 * waferV()); } - std::pair waferXY() const { return std::pair(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 waferUV() const { return std::pair(waferU(), waferV()); } + constexpr int waferX() const { return (-2 * waferU() + waferV()); } + constexpr int waferY() const { return (2 * waferV()); } + constexpr std::pair waferXY() const { return std::pair(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 triggerCellUV() const { return std::pair(triggerCellU(), triggerCellV()); } + constexpr std::pair triggerCellUV() const { return std::pair(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); diff --git a/DataFormats/ForwardDetId/src/HGCSiliconDetId.cc b/DataFormats/ForwardDetId/src/HGCSiliconDetId.cc index 2715b392b69a2..13302f3808c7b 100644 --- a/DataFormats/ForwardDetId/src/HGCSiliconDetId.cc +++ b/DataFormats/ForwardDetId/src/HGCSiliconDetId.cc @@ -1,50 +1,8 @@ #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h" -#include "FWCore/Utilities/interface/Exception.h" #include #include -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() diff --git a/Geometry/HGCalCommonData/interface/HGCalTypes.h b/Geometry/HGCalCommonData/interface/HGCalTypes.h index f483249fc42f0..0f5a3c786d026 100644 --- a/Geometry/HGCalCommonData/interface/HGCalTypes.h +++ b/Geometry/HGCalCommonData/interface/HGCalTypes.h @@ -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; diff --git a/SimG4CMS/Calo/interface/CaloSD.h b/SimG4CMS/Calo/interface/CaloSD.h index a70ca6f3f5fa2..44e54c92a777b 100644 --- a/SimG4CMS/Calo/interface/CaloSD.h +++ b/SimG4CMS/Calo/interface/CaloSD.h @@ -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; @@ -143,6 +144,8 @@ class CaloSD : public SensitiveCaloDetector, CaloHitID currentID[2], previousID[2]; double energyCut, tmaxHit, eminHit; + std::vector hcn_; + std::vector useResMap_; CaloG4Hit* currentHit[2]; @@ -185,6 +188,7 @@ class CaloSD : public SensitiveCaloDetector, bool doFineCalo_; double eMinFine_; int nHC_; + std::string detName_[2], collName_[2]; std::map hitMap[2]; std::map tkMap; diff --git a/SimG4CMS/Calo/interface/HGCalSD.h b/SimG4CMS/Calo/interface/HGCalSD.h index a3ea6a839f37f..a1b933a07ab9a 100644 --- a/SimG4CMS/Calo/interface/HGCalSD.h +++ b/SimG4CMS/Calo/interface/HGCalSD.h @@ -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 class HGCalDDDConstants; @@ -39,17 +40,21 @@ class HGCalSD : public CaloSD, public Observer { 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 numberingScheme_; std::unique_ptr guardRing_; std::unique_ptr guardRingPartial_; std::unique_ptr mouseBite_; + std::unique_ptr 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_; diff --git a/SimG4CMS/Calo/src/CaloSD.cc b/SimG4CMS/Calo/src/CaloSD.cc index 7c6056c3881f5..fd0de85fabc50 100644 --- a/SimG4CMS/Calo/src/CaloSD.cc +++ b/SimG4CMS/Calo/src/CaloSD.cc @@ -28,7 +28,7 @@ #include #include -//#define EDM_ML_DEBUG +#define EDM_ML_DEBUG CaloSD::CaloSD(const std::string& name, const SensitiveDetectorCatalog& clg, @@ -57,8 +57,8 @@ CaloSD::CaloSD(const std::string& name, tmaxHit = m_CaloSD.getParameter("TmaxHit") * CLHEP::ns; std::vector eminHits = m_CaloSD.getParameter>("EminHits"); std::vector tmaxHits = m_CaloSD.getParameter>("TmaxHits"); - std::vector hcn = m_CaloSD.getParameter>("HCNames"); - std::vector useResMap = m_CaloSD.getParameter>("UseResponseTables"); + hcn_ = m_CaloSD.getParameter>("HCNames"); + useResMap_ = m_CaloSD.getParameter>("UseResponseTables"); std::vector eminHitX = m_CaloSD.getParameter>("EminHitsDepth"); suppressHeavy = m_CaloSD.getParameter("SuppressHeavy"); kmaxIon = m_CaloSD.getParameter("IonThreshold") * CLHEP::MeV; @@ -82,20 +82,21 @@ CaloSD::CaloSD(const std::string& name, SetVerboseLevel(verbn); for (int k = 0; k < 2; ++k) meanResponse[k].reset(nullptr); - for (unsigned int k = 0; k < hcn.size(); ++k) { - if (name == hcn[k]) { + for (unsigned int k = 0; k < hcn_.size(); ++k) { + if (name == hcn_[k]) { if (k < eminHits.size()) eminHit = eminHits[k] * CLHEP::MeV; if (k < eminHitX.size()) eminHitD = eminHitX[k] * CLHEP::MeV; if (k < tmaxHits.size()) tmaxHit = tmaxHits[k] * CLHEP::ns; - if (k < useResMap.size() && useResMap[k] > 0) { + if (k < useResMap_.size() && useResMap_[k] > 0) { meanResponse[0] = std::make_unique(p); break; } } } + detName_[0] = name; slave[0] = std::make_unique(name); slave[1].reset(nullptr); @@ -169,6 +170,23 @@ CaloSD::CaloSD(const std::string& name, CaloSD::~CaloSD() {} +void CaloSD::newCollection(const std::string& name, edm::ParameterSet const& p) { + nHC_ = 2; + detName_[1] = collName_[1] = name; + for (unsigned int k = 0; k < hcn_.size(); ++k) { + if (name == hcn_[k]) { + if (k < useResMap_.size() && useResMap_[k] > 0) { + meanResponse[1] = std::make_unique(p); + break; + } + } + } + slave[1] = std::make_unique(name); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("CaloSim") << "CaloSD:: Initialise a second collection for " << name; +#endif +} + G4bool CaloSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) { NaNTrap(aStep); ignoreReject = false; @@ -349,7 +367,7 @@ bool CaloSD::isItFineCalo(const G4VTouchable* touch) { G4LogicalVolume* lv = touch->GetVolume(ii)->GetLogicalVolume(); ok = (lv == detector.lv); #ifdef EDM_ML_DEBUG - std::string name1 = (lv == 0) ? "Unknown" : lv->GetName(); + std::string name1 = (lv == nullptr) ? "Unknown" : lv->GetName(); edm::LogVerbatim("CaloSim") << "CaloSD: volume " << name1 << ":" << detector.name << " at Level " << detector.level << " Flag " << ok; #endif @@ -363,18 +381,22 @@ bool CaloSD::isItFineCalo(const G4VTouchable* touch) { void CaloSD::Initialize(G4HCofThisEvent* HCE) { Initialize(HCE, 0); } void CaloSD::Initialize(G4HCofThisEvent* HCE, int k) { + if (k == 0) { + detName_[0] = GetName(); + collName_[0] = collectionName[0]; + } totalHits[k] = 0; #ifdef EDM_ML_DEBUG - edm::LogVerbatim("CaloSim") << "CaloSD : Initialize called for " << GetName(); + edm::LogVerbatim("CaloSim") << "CaloSD : Initialize called for " << detName_[k]; #endif //This initialization is performed at the beginning of an event //------------------------------------------------------------ - theHC[k] = new CaloG4HitCollection(GetName(), collectionName[0]); + theHC[k] = new CaloG4HitCollection(detName_[k], collName_[k]); if (hcID[k] < 0) { - hcID[k] = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); + hcID[k] = G4SDManager::GetSDMpointer()->GetCollectionID(collName_[k]); } //theHC ownership is transfered here to HCE HCE->AddHitsCollection(hcID[k], theHC[k]); diff --git a/SimG4CMS/Calo/src/HGCalSD.cc b/SimG4CMS/Calo/src/HGCalSD.cc index adef64b0fa431..c8ededa2311ed 100644 --- a/SimG4CMS/Calo/src/HGCalSD.cc +++ b/SimG4CMS/Calo/src/HGCalSD.cc @@ -19,6 +19,7 @@ #include "G4VProcess.hh" #include "G4Trap.hh" +#include #include #include #include @@ -40,7 +41,9 @@ HGCalSD::HGCalSD(const std::string& name, manager, static_cast(p.getParameter("HGCSD").getParameter("TimeSliceUnit")), p.getParameter("HGCSD").getParameter("IgnoreTrackID")), + myName_(name), hgcons_(hgc), + ps_(p), slopeMin_(0), levelT1_(99), levelT2_(99), @@ -52,6 +55,7 @@ HGCalSD::HGCalSD(const std::string& name, guardRing_.reset(nullptr); guardRingPartial_.reset(nullptr); mouseBite_.reset(nullptr); + cellOffset_.reset(nullptr); edm::ParameterSet m_HGC = p.getParameter("HGCSD"); eminHit_ = m_HGC.getParameter("EminHit") * CLHEP::MeV; @@ -72,13 +76,12 @@ HGCalSD::HGCalSD(const std::string& name, } //this is defined in the hgcsens.xml - G4String myName = name; mydet_ = DetId::Forward; nameX_ = "HGCal"; - if (myName.find("HitsEE") != std::string::npos) { + if (myName_.find("HitsEE") != std::string::npos) { mydet_ = DetId::HGCalEE; nameX_ = "HGCalEESensitive"; - } else if (myName.find("HitsHEfront") != std::string::npos) { + } else if (myName_.find("HitsHEfront") != std::string::npos) { mydet_ = DetId::HGCalHSi; nameX_ = "HGCalHESiliconSensitive"; } @@ -256,20 +259,20 @@ void HGCalSD::update(const BeginOfJob* job) { } useSimWt_ = hgcons_->getParameter()->useSimWt_; int useOffset = hgcons_->getParameter()->useOffset_; - double waferSize = hgcons_->waferSize(false); + waferSize_ = hgcons_->waferSize(false); double mouseBite = hgcons_->mouseBite(false); - double guardRingOffset = hgcons_->guardRingOffset(false); + guardRingOffset_ = hgcons_->guardRingOffset(false); double sensorSizeOffset = hgcons_->sensorSizeOffset(false); if (useOffset > 0) { rejectMB_ = true; fiducialCut_ = true; } - double mouseBiteNew = (fiducialCut_) ? (mouseBite + guardRingOffset + sensorSizeOffset / cos30deg_) : mouseBite; - mouseBiteCut_ = waferSize * tan30deg_ - mouseBiteNew; + double mouseBiteNew = (fiducialCut_) ? (mouseBite + guardRingOffset_ + sensorSizeOffset / cos30deg_) : mouseBite; + mouseBiteCut_ = waferSize_ * tan30deg_ - mouseBiteNew; #ifdef EDM_ML_DEBUG edm::LogVerbatim("HGCSim") << "HGCalSD::Initialized with mode " << geom_mode_ << " Slope cut " << slopeMin_ << " top Level " << levelT1_ << ":" << levelT2_ << " useSimWt " << useSimWt_ << " wafer " - << waferSize << ":" << mouseBite << ":" << guardRingOffset << ":" << sensorSizeOffset + << waferSize_ << ":" << mouseBite << ":" << guardRingOffset_ << ":" << sensorSizeOffset << ":" << mouseBiteNew << ":" << mouseBiteCut_ << " useOffset " << useOffset << " dd4hep " << dd4hep_; #endif @@ -314,6 +317,11 @@ void HGCalSD::update(const BeginOfJob* job) { } else { throw cms::Exception("Unknown", "HGCalSD") << "Cannot find HGCalDDDConstants for " << nameX_ << "\n"; } + if (calibCells_) { + newCollection(("Calibration" + myName_), ps_); + cellOffset_ = std::make_unique( + waferSize_, hgcons_->getUVMax(0), hgcons_->getUVMax(1), guardRingOffset_, mouseBiteCut_); + } } void HGCalSD::initRun() {} @@ -334,3 +342,34 @@ uint32_t HGCalSD::setDetUnitId(int layer, int module, int cell, int iz, G4ThreeV ignoreRejection(); return id; } + +bool HGCalSD::calibCell(const uint32_t& id, double& frac) { + bool flag(false); + frac = 1; + int type, zside, layer, waferU, waferV, cellU, cellV; + HGCSiliconDetId(id).unpack(type, zside, layer, waferU, waferV, cellU, cellV); + HGCalParameters::waferInfo info = hgcons_->waferInfo(layer, waferU, waferV); + bool hd = HGCalTypes::waferHD(info.type); + bool full = HGCalTypes::waferFull(info.part); + int indx = 100 * cellU + cellV; + if (hd) { + if (full) + flag = (std::find(calibCellFullHD_.begin(), calibCellFullHD_.end(), indx) != calibCellFullHD_.end()); + else + flag = (std::find(calibCellPartHD_.begin(), calibCellPartHD_.end(), indx) != calibCellPartHD_.end()); + } else { + if (full) + flag = (std::find(calibCellFullLD_.begin(), calibCellFullLD_.end(), indx) != calibCellFullLD_.end()); + else + flag = (std::find(calibCellPartLD_.begin(), calibCellPartLD_.end(), indx) != calibCellPartLD_.end()); + } + if (flag) { + int32_t place = + HGCalCell::cellPlacementIndex(zside, HGCalTypes::layerFrontBack(hgcons_->layerType(layer)), info.orient); + int32_t type = hd ? 0 : 1; + double num = hd ? (M_PI * calibCellRHD_ * calibCellRHD_) : (M_PI * calibCellRLD_ * calibCellRLD_); + double bot = cellOffset_->cellAreaUV(cellU, cellV, place, type); + frac = (bot > 0 && bot < num) ? (num / bot) : 1.0; + } + return flag; +}