Skip to content

Commit

Permalink
Code check
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunanda committed Oct 19, 2023
1 parent bde61e4 commit f9186b5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
36 changes: 22 additions & 14 deletions DataFormats/ForwardDetId/interface/HGCSiliconDetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@ class HGCSiliconDetId : public DetId {
/** Create cellid from raw id (0=invalid tower id) */
constexpr HGCSiliconDetId(uint32_t rawid) : DetId(rawid) {}
/** Constructor from subdetector, zplus, layer, module, cell numbers */
constexpr HGCSiliconDetId(DetId::Detector det, int zp, int type, int layer, int waferU, int waferV, int cellU, int cellV): DetId(det, ForwardEmpty) {
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));
((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 */
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;
throw cms::Exception("Invalid DetId")
<< "Cannot initialize HGCSiliconDetId from " << std::hex << gen.rawId() << std::dec;
}
}
id_ = gen.rawId();
Expand All @@ -62,16 +64,18 @@ class HGCSiliconDetId : public DetId {
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;
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 */
constexpr HGCSiliconDetId geometryCell() const { return HGCSiliconDetId(det(), zside(), 0, layer(), waferU(), waferV(), 0, 0); }
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);
}
Expand Down Expand Up @@ -105,8 +109,12 @@ class HGCSiliconDetId : public DetId {
/// get the wafer #'s in u,v or in x,y
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 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()); }
Expand Down
4 changes: 2 additions & 2 deletions SimG4CMS/Calo/interface/HGCalSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ 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);
bool calibCell(const uint32_t &id, double &frac);

std::string myName_;
const HGCalDDDConstants *hgcons_;
edm::ParameterSet const& ps_;
edm::ParameterSet const &ps_;
std::unique_ptr<HGCalNumberingScheme> numberingScheme_;
std::unique_ptr<HGCGuardRing> guardRing_;
std::unique_ptr<HGCGuardRingPartial> guardRingPartial_;
Expand Down
8 changes: 4 additions & 4 deletions SimG4CMS/Calo/src/CaloSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ void CaloSD::newCollection(const std::string& name, edm::ParameterSet const& p)
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<CaloMeanResponse>(p);
break;
meanResponse[1] = std::make_unique<CaloMeanResponse>(p);
break;
}
}
}
Expand Down Expand Up @@ -367,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
Expand All @@ -384,7 +384,7 @@ void CaloSD::Initialize(G4HCofThisEvent* HCE, int k) {
if (k == 0) {
detName_[0] = GetName();
collName_[0] = collectionName[0];
}
}
totalHits[k] = 0;

#ifdef EDM_ML_DEBUG
Expand Down
8 changes: 5 additions & 3 deletions SimG4CMS/Calo/src/HGCalSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ void HGCalSD::update(const BeginOfJob* job) {
throw cms::Exception("Unknown", "HGCalSD") << "Cannot find HGCalDDDConstants for " << nameX_ << "\n";
}
if (calibCells_) {
newCollection(("Calibration"+myName_), ps_);
cellOffset_ = std::make_unique<HGCalCellOffset>(waferSize_, hgcons_->getUVMax(0), hgcons_->getUVMax(1), guardRingOffset_, mouseBiteCut_);
newCollection(("Calibration" + myName_), ps_);
cellOffset_ = std::make_unique<HGCalCellOffset>(
waferSize_, hgcons_->getUVMax(0), hgcons_->getUVMax(1), guardRingOffset_, mouseBiteCut_);
}
}

Expand Down Expand Up @@ -363,7 +364,8 @@ bool HGCalSD::calibCell(const uint32_t& id, double& frac) {
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 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);
Expand Down

0 comments on commit f9186b5

Please sign in to comment.