Skip to content

Commit ba243e5

Browse files
author
Sunanda
committed
Move HGCGuardRing.h(cc) from SimG4CMS/Calo to Geometry/HGCalCommonData
1 parent ebb1b53 commit ba243e5

File tree

11 files changed

+174
-237
lines changed

11 files changed

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

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)