Skip to content

Commit 8d747a3

Browse files
authored
Merge pull request #48208 from bsunanda/Phase2-hgx364F
Phase2-hgx364F Move HGCGuardRing.h(cc) from SimG4CMS/Calo to Geometry/HGCalCommonData
2 parents b1b3a87 + e8d15a0 commit 8d747a3

File tree

11 files changed

+189
-237
lines changed

11 files changed

+189
-237
lines changed

Geometry/HGCalCommonData/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<use name="DetectorDescription/Core"/>
44
<use name="DetectorDescription/DDCMS"/>
55
<use name="FWCore/ParameterSet"/>
6+
<use name="geant4core"/>
67
<use name="dd4hep"/>
78
<export>
89
<lib name="1"/>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
#ifndef SimG4CMS_HGCGuardRingPartial_h
2-
#define SimG4CMS_HGCGuardRingPartial_h
1+
#ifndef Geometry_HGCalCommonData_HGCGuardRing_h
2+
#define Geometry_HGCalCommonData_HGCGuardRing_h
33

44
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
55
#include "G4ThreeVector.hh"
66

77
#include <vector>
8-
#include <array>
98

10-
class HGCGuardRingPartial {
9+
class HGCGuardRing {
1110
public:
12-
HGCGuardRingPartial(const HGCalDDDConstants& hgc);
11+
HGCGuardRing(const HGCalDDDConstants& hgc);
1312
bool exclude(G4ThreeVector& point, int zside, int frontBack, int layer, int waferU, int waferV);
13+
bool excludePartial(G4ThreeVector& point, int zside, int frontBack, int layer, int waferU, int waferV);
1414
static bool insidePolygon(double x, double y, const std::vector<std::pair<double, double> >& xyv);
1515

1616
private:
1717
static constexpr double sqrt3_ = 1.732050807568877; // std::sqrt(3.0) in double precision
1818
const HGCalDDDConstants& hgcons_;
1919
const HGCalGeometryMode::GeometryMode modeUV_;
2020
const bool v17OrLess_;
21-
const double waferSize_, guardRingOffset_;
21+
const double waferSize_, sensorSizeOffset_, guardRingOffset_;
2222
static constexpr std::array<double, 12> tan_1 = {
2323
{-sqrt3_, sqrt3_, 0.0, -sqrt3_, sqrt3_, 0.0, sqrt3_, -sqrt3_, 0.0, sqrt3_, -sqrt3_, 0.0}};
2424
static constexpr std::array<double, 12> cos_1 = {{0.5, -0.5, -1.0, -0.5, 0.5, 1.0, -0.5, 0.5, 1.0, 0.5, -0.5, -1.0}};
2525
static constexpr std::array<double, 12> cot_1 = {
2626
{sqrt3_, -sqrt3_, 0.0, sqrt3_, -sqrt3_, 0.0, -sqrt3_, sqrt3_, 0.0, -sqrt3_, sqrt3_, 0.0}};
27-
double offset_, c22_, c27_;
27+
double offset_, offsetPartial_, xmax_, ymax_, c22_, c27_;
2828
};
2929

3030
#endif // HGCGuardRing_h
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
2+
#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
3+
#include "Geometry/HGCalCommonData/interface/HGCalWaferType.h"
4+
#include "Geometry/HGCalCommonData/interface/HGCGuardRing.h"
5+
#include <iostream>
6+
7+
//#define EDM_ML_DEBUG
8+
9+
HGCGuardRing::HGCGuardRing(const HGCalDDDConstants& hgc)
10+
: hgcons_(hgc),
11+
modeUV_(hgcons_.geomMode()),
12+
v17OrLess_(hgcons_.v17OrLess()),
13+
waferSize_(hgcons_.waferSize(false)),
14+
sensorSizeOffset_(hgcons_.sensorSizeOffset(false)),
15+
guardRingOffset_(hgcons_.guardRingOffset(false)) {
16+
offset_ = sensorSizeOffset_ + guardRingOffset_;
17+
offsetPartial_ = guardRingOffset_;
18+
xmax_ = 0.5 * waferSize_ - offset_;
19+
ymax_ = xmax_ / sqrt3_;
20+
c22_ = (v17OrLess_) ? HGCalTypes::c22O : HGCalTypes::c22;
21+
c27_ = (v17OrLess_) ? HGCalTypes::c27O : HGCalTypes::c27;
22+
#ifdef EDM_ML_DEBUG
23+
edm::LogVerbatim("HGCSim") << "Creating HGCGuardRing with wafer size " << waferSize_ << ", Offsets "
24+
<< sensorSizeOffset_ << ":" << guardRingOffset_ << ":" << offset_ << ":" << offsetPartial_
25+
<< ", mode " << modeUV_ << ", xmax|ymax " << xmax_ << ":" << ymax_ << " and c22:c77 "
26+
<< c22_ << ":" << c77_;
27+
#endif
28+
}
29+
30+
bool HGCGuardRing::exclude(G4ThreeVector& point, int zside, int frontBack, int layer, int waferU, int waferV) {
31+
bool check(false);
32+
if (hgcons_.waferHexagon8Module()) {
33+
int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV);
34+
int partial = HGCalWaferType::getPartial(index, hgcons_.getParameter()->waferInfoMap_);
35+
#ifdef EDM_ML_DEBUG
36+
edm::LogVerbatim("HGCSim") << "HGCGuardRing::exclude: Layer " << layer << " wafer " << waferU << ":" << waferV
37+
<< " index " << index << " partial " << partial;
38+
#endif
39+
if (partial == HGCalTypes::WaferFull) {
40+
double dx = std::abs(point.x());
41+
double dy = std::abs(point.y());
42+
if (dx > xmax_) {
43+
check = true;
44+
} else if (dy > (2 * ymax_)) {
45+
check = true;
46+
} else {
47+
check = (dx > (sqrt3_ * (2 * ymax_ - dy)));
48+
}
49+
#ifdef EDM_ML_DEBUG
50+
edm::LogVerbatim("HGCSim") << "HGCGuardRing::exclude: Point " << point << " zside " << zside << " layer " << layer
51+
<< " wafer " << waferU << ":" << waferV << " partial type " << partial << ":"
52+
<< HGCalTypes::WaferFull << " x " << dx << ":" << xmax_ << " y " << dy << ":" << ymax_
53+
<< " check " << check;
54+
#endif
55+
} else if (partial > 0) {
56+
int orient = HGCalWaferType::getOrient(index, hgcons_.getParameter()->waferInfoMap_);
57+
#ifdef EDM_ML_DEBUG
58+
edm::LogVerbatim("HGCSim") << "HGCGuardRing::exclude: Orient " << orient << " Mode " << modeUV_;
59+
#endif
60+
if (hgcons_.v16OrLess()) {
61+
std::vector<std::pair<double, double> > wxy =
62+
HGCalWaferMask::waferXY(partial, orient, zside, waferSize_, offset_, 0.0, 0.0, v17OrLess_);
63+
check = !(insidePolygon(point.x(), point.y(), wxy));
64+
#ifdef EDM_ML_DEBUG
65+
std::ostringstream st1;
66+
st1 << "HGCGuardRing::exclude: Point " << point << " Partial/orient/zside/size/offset " << partial << ":"
67+
<< orient << ":" << zside << ":" << waferSize_ << offset_ << " with " << wxy.size() << " points:";
68+
for (unsigned int k = 0; k < wxy.size(); ++k)
69+
st1 << " (" << wxy[k].first << ", " << wxy[k].second << ")";
70+
edm::LogVerbatim("HGCSim") << st1.str();
71+
#endif
72+
} else {
73+
int placement = HGCalCell::cellPlacementIndex(zside, frontBack, orient);
74+
std::vector<std::pair<double, double> > wxy =
75+
HGCalWaferMask::waferXY(partial, placement, waferSize_, offset_, 0.0, 0.0, v17OrLess_);
76+
check = !(insidePolygon(point.x(), point.y(), wxy));
77+
#ifdef EDM_ML_DEBUG
78+
std::ostringstream st1;
79+
st1 << "HGCGuardRing::exclude: Point " << point << " Partial/frontback/orient/zside/placeemnt/size/offset "
80+
<< partial << ":" << frontBack << ":" << orient << ":" << zside << ":" << placement << ":" << waferSize_
81+
<< offset_ << " with " << wxy.size() << " points:";
82+
for (unsigned int k = 0; k < wxy.size(); ++k)
83+
st1 << " (" << wxy[k].first << ", " << wxy[k].second << ")";
84+
edm::LogVerbatim("HGCSim") << st1.str();
85+
#endif
86+
}
87+
} else {
88+
check = true;
89+
}
90+
}
91+
return check;
92+
}
93+
94+
bool HGCGuardRing::excludePartial(G4ThreeVector& point, int zside, int frontBack, int layer, int waferU, int waferV) {
95+
bool check(false);
96+
if (hgcons_.waferHexagon8Cassette()) {
97+
int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV);
98+
int partial = HGCalWaferType::getPartial(index, hgcons_.getParameter()->waferInfoMap_);
99+
int type = HGCalWaferType::getType(index, hgcons_.getParameter()->waferInfoMap_);
100+
#ifdef EDM_ML_DEBUG
101+
edm::LogVerbatim("HGCSim") << "HGCGuardRing::excludePartial: Layer " << layer << " wafer " << waferU << ":"
102+
<< waferV << " index " << index << " partial " << partial << " type " << type;
103+
#endif
104+
if (partial == HGCalTypes::WaferFull) {
105+
return (check);
106+
} else if (partial < 0) {
107+
return true;
108+
} else {
109+
int orient = HGCalWaferType::getOrient(index, hgcons_.getParameter()->waferInfoMap_);
110+
int placement = HGCalCell::cellPlacementIndex(zside, frontBack, orient);
111+
double dx = point.x();
112+
double dy = point.y();
113+
#ifdef EDM_ML_DEBUG
114+
edm::LogVerbatim("HGCSim") << "HGCGuardRing::excludePartial: zside " << zside << " frontBack " << frontBack
115+
<< " orient " << orient << " placement " << placement << " dx " << dx << " dy " << dy;
116+
#endif
117+
if (type > 0) {
118+
for (int ii = HGCalTypes::WaferPartLDOffset;
119+
ii < (HGCalTypes::WaferPartLDOffset + HGCalTypes::WaferPartLDCount);
120+
ii++) {
121+
std::array<double, 4> criterion =
122+
HGCalWaferMask::maskCut(ii, placement, waferSize_, offsetPartial_, v17OrLess_);
123+
check |= std::abs(criterion[0] * dy + criterion[1] * dx + criterion[2]) < criterion[3];
124+
}
125+
} else {
126+
for (int ii = HGCalTypes::WaferPartHDOffset;
127+
ii < (HGCalTypes::WaferPartHDOffset + HGCalTypes::WaferPartHDCount);
128+
ii++) {
129+
std::array<double, 4> criterion =
130+
HGCalWaferMask::maskCut(ii, placement, waferSize_, offsetPartial_, v17OrLess_);
131+
check |= std::abs(criterion[0] * dy + criterion[1] * dx + criterion[2]) < criterion[3];
132+
}
133+
}
134+
}
135+
#ifdef EDM_ML_DEBUG
136+
edm::LogVerbatim("HGCSim") << "HGCGuardRing::excludePartial: Point " << point << " zside " << zside << " layer "
137+
<< layer << " wafer " << waferU << ":" << waferV << " partial type " << partial
138+
<< " type " << type << " check " << check;
139+
#endif
140+
}
141+
return check;
142+
}
143+
144+
bool HGCGuardRing::insidePolygon(double x, double y, const std::vector<std::pair<double, double> >& xyv) {
145+
int counter(0);
146+
double x1(xyv[0].first), y1(xyv[0].second);
147+
for (unsigned i1 = 1; i1 <= xyv.size(); i1++) {
148+
unsigned i2 = (i1 % xyv.size());
149+
double x2(xyv[i2].first), y2(xyv[i2].second);
150+
if (y > std::min(y1, y2)) {
151+
if (y <= std::max(y1, y2)) {
152+
if (x <= std::max(x1, x2)) {
153+
if (y1 != y2) {
154+
double xinter = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
155+
if ((x1 == x2) || (x <= xinter))
156+
++counter;
157+
}
158+
}
159+
}
160+
}
161+
x1 = x2;
162+
y1 = y2;
163+
}
164+
165+
if (counter % 2 == 0)
166+
return false;
167+
else
168+
return true;
169+
}

SimG4CMS/Calo/interface/HFNoseSD.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#include "SimG4CMS/Calo/interface/CaloSD.h"
1010
#include "SimG4Core/Notification/interface/BeginOfJob.h"
1111
#include "SimG4CMS/Calo/interface/HFNoseNumberingScheme.h"
12-
#include "SimG4CMS/Calo/interface/HGCGuardRing.h"
1312
#include "SimG4CMS/Calo/interface/HGCMouseBite.h"
13+
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
14+
#include "Geometry/HGCalCommonData/interface/HGCGuardRing.h"
1415

1516
#include <string>
1617

17-
class HGCalDDDConstants;
1818
class G4LogicalVolume;
1919
class G4Step;
2020

SimG4CMS/Calo/interface/HGCGuardRing.h

Lines changed: 0 additions & 24 deletions
This file was deleted.

SimG4CMS/Calo/interface/HGCalSD.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
#include "SimG4CMS/Calo/interface/CaloSD.h"
1010
#include "SimG4Core/Notification/interface/BeginOfJob.h"
1111
#include "SimG4CMS/Calo/interface/HGCalNumberingScheme.h"
12-
#include "SimG4CMS/Calo/interface/HGCGuardRing.h"
1312
#include "SimG4CMS/Calo/interface/HGCMouseBite.h"
14-
#include "SimG4CMS/Calo/interface/HGCGuardRingPartial.h"
1513
#include "Geometry/HGCalCommonData/interface/HGCalCellOffset.h"
14+
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
15+
#include "Geometry/HGCalCommonData/interface/HGCGuardRing.h"
1616
#include <string>
1717

18-
class HGCalDDDConstants;
1918
class G4LogicalVolume;
2019
class G4Step;
2120

@@ -48,7 +47,6 @@ class HGCalSD : public CaloSD, public Observer<const BeginOfJob *> {
4847
edm::ParameterSet const &ps_;
4948
std::unique_ptr<HGCalNumberingScheme> numberingScheme_;
5049
std::unique_ptr<HGCGuardRing> guardRing_;
51-
std::unique_ptr<HGCGuardRingPartial> guardRingPartial_;
5250
std::unique_ptr<HGCMouseBite> mouseBite_;
5351
std::unique_ptr<HGCalCellOffset> cellOffset_;
5452
DetId::Detector mydet_;

SimG4CMS/Calo/plugins/HGCalMouseBiteTester.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@
4343
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
4444
#include "Geometry/HGCalCommonData/interface/HGCalCellUV.h"
4545
#include "Geometry/HGCalCommonData/interface/HGCalCell.h"
46+
#include "Geometry/HGCalCommonData/interface/HGCGuardRing.h"
4647
#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
4748
#include "Geometry/HGCalCommonData/interface/HGCalWaferType.h"
4849
#include "SimG4CMS/Calo/interface/HGCMouseBite.h"
49-
#include "SimG4CMS/Calo/interface/HGCGuardRing.h"
50-
#include "SimG4CMS/Calo/interface/HGCGuardRingPartial.h"
5150
#include "G4ThreeVector.hh"
5251

5352
class HGCalMouseBiteTester : public edm::one::EDAnalyzer<> {
@@ -114,7 +113,6 @@ void HGCalMouseBiteTester::analyze(const edm::Event& iEvent, const edm::EventSet
114113
double mouseBiteCut_ = hgcons_.mouseBite(false);
115114
bool v17OrLess = hgcons_.v17OrLess();
116115
HGCGuardRing guardRing_(hgcons_);
117-
HGCGuardRingPartial guardRingPartial_(hgcons_);
118116
HGCMouseBite mouseBite_(hgcons_, angle_, (waferSize_ * tan(30.0 * CLHEP::deg) - mouseBiteCut_), true);
119117
const int nFine(12), nCoarse(8);
120118
double r2 = 0.5 * waferSize_;
@@ -127,7 +125,7 @@ void HGCalMouseBiteTester::analyze(const edm::Event& iEvent, const edm::EventSet
127125
double x0 = (zside > 0) ? xy.first : -xy.first;
128126
double y0 = xy.second;
129127
std::ofstream guard_ring("Guard_ring.csv");
130-
std::ofstream guard_ring_partial("Guard_ring_partial.csv");
128+
// std::ofstream guard_ring_partial("Guard_ring_partial.csv");
131129
std::ofstream mouse_bite("Mouse_bite.csv");
132130
std::ofstream selected("Selected.csv");
133131
edm::LogVerbatim("HGCalGeom") << "\nHGCalMouseBiteTester:: nCells " << nCells << " FrontBack " << frontBack
@@ -177,8 +175,9 @@ void HGCalMouseBiteTester::analyze(const edm::Event& iEvent, const edm::EventSet
177175
guard_ring << xi << "," << yi << std::endl;
178176
}
179177

180-
if (guardRingPartial_.exclude(point, zside, frontBack, layer_, waferU_, waferV_)) {
181-
guard_ring_partial << xi << "," << yi << std::endl;
178+
if (guardRing_.excludePartial(point, zside, frontBack, layer_, waferU_, waferV_)) {
179+
guard_ring << xi << "," << yi << std::endl;
180+
// guard_ring_partial << xi << "," << yi << std::endl;
182181
} else if (mouseBite_.exclude(point, zside, layer_, waferU_, waferV_)) {
183182
mouse_bite << xi << "," << yi << std::endl;
184183
} else {
@@ -188,7 +187,6 @@ void HGCalMouseBiteTester::analyze(const edm::Event& iEvent, const edm::EventSet
188187
}
189188
}
190189
guard_ring.close();
191-
guard_ring_partial.close();
192190
mouse_bite.close();
193191
selected.close();
194192
outputFile.close();

SimG4CMS/Calo/plugins/HGCalTestGuardRing.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
#include "SimDataFormats/CaloHit/interface/PCaloHit.h"
1919
#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
2020
#include "SimG4CMS/Calo/interface/CaloSimUtils.h"
21-
#include "SimG4CMS/Calo/interface/HGCGuardRing.h"
2221

2322
#include "Geometry/CaloTopology/interface/HGCalTopology.h"
2423
#include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
2524
#include "Geometry/HGCalCommonData/interface/HGCalCell.h"
2625
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
2726
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
2827
#include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
28+
#include "Geometry/HGCalCommonData/interface/HGCGuardRing.h"
2929
#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
3030
#include "Geometry/Records/interface/IdealGeometryRecord.h"
3131

0 commit comments

Comments
 (0)