CMS 3D CMS Logo

HGCGuardRing.cc
Go to the documentation of this file.
5 #include <iostream>
6 
7 //#define EDM_ML_DEBUG
8 
10  : hgcons_(hgc),
11  modeUV_(hgcons_.geomMode()),
12  waferSize_(hgcons_.waferSize(false)),
13  sensorSizeOffset_(hgcons_.getParameter()->sensorSizeOffset_),
14  guardRingOffset_(hgcons_.getParameter()->guardRingOffset_) {
16  xmax_ = 0.5 * (waferSize_ - offset_);
17  ymax_ = xmax_ / sqrt3_;
18 #ifdef EDM_ML_DEBUG
19  edm::LogVerbatim("HGCSim") << "Creating HGCGuardRing with wafer size " << waferSize_ << ", Offsets "
20  << sensorSizeOffset_ << ":" << guardRingOffset_ << ":" << offset_ << ", and mode "
21  << modeUV_ << " xmax|ymax " << xmax_ << ":" << ymax_;
22 #endif
23 }
24 
25 bool HGCGuardRing::exclude(G4ThreeVector& point, int zside, int frontBack, int layer, int waferU, int waferV) {
26  bool check(false);
30  if (partial == HGCalTypes::WaferFull) {
31  double dx = std::abs(point.x());
32  double dy = std::abs(point.y());
33  if (dx > xmax_) {
34  check = true;
35  } else if (dy > (2 * ymax_)) {
36  check = true;
37  } else {
38  check = (dx > (sqrt3_ * (2 * ymax_ - dy)));
39  }
40 #ifdef EDM_ML_DEBUG
41  edm::LogVerbatim("HGCSim") << "HGCGuardRing:: Point " << point << " zside " << zside << " layer " << layer
42  << " wafer " << waferU << ":" << waferV << " partial type " << partial << ":"
43  << HGCalTypes::WaferFull << " x " << dx << ":" << xmax_ << " y " << dy << ":" << ymax_
44  << " check " << check;
45 #endif
46  } else {
49  std::vector<std::pair<double, double> > wxy =
50  HGCalWaferMask::waferXY(partial, orient, zside, waferSize_, offset_, 0.0, 0.0);
51  check = !(insidePolygon(point.x(), point.y(), wxy));
52 #ifdef EDM_ML_DEBUG
53  std::ostringstream st1;
54  st1 << "HGCGuardRing:: Point " << point << " Partial/orient/zside/size/offset " << partial << ":" << orient
55  << ":" << zside << ":" << waferSize_ << offset_ << " with " << wxy.size() << " points:";
56  for (unsigned int k = 0; k < wxy.size(); ++k)
57  st1 << " (" << wxy[k].first << ", " << wxy[k].second << ")";
58  edm::LogVerbatim("HGCSim") << st1.str();
59 #endif
60  } else {
61  int placement = HGCalCell::cellPlacementIndex(zside, frontBack, orient);
62  std::vector<std::pair<double, double> > wxy =
63  HGCalWaferMask::waferXY(partial, placement, waferSize_, offset_, 0.0, 0.0);
64  check = !(insidePolygon(point.x(), point.y(), wxy));
65 #ifdef EDM_ML_DEBUG
66  std::ostringstream st1;
67  st1 << "HGCGuardRing:: Point " << point << " Partial/frontback/orient/zside/placeemnt/size/offset " << partial
68  << ":" << frontBack << ":" << orient << ":" << zside << ":" << placement << ":" << waferSize_ << offset_
69  << " with " << wxy.size() << " points:";
70  for (unsigned int k = 0; k < wxy.size(); ++k)
71  st1 << " (" << wxy[k].first << ", " << wxy[k].second << ")";
72  edm::LogVerbatim("HGCSim") << st1.str();
73 #endif
74  }
75  }
76  }
77  return check;
78 }
79 
80 bool HGCGuardRing::insidePolygon(double x, double y, const std::vector<std::pair<double, double> >& xyv) {
81  int counter(0);
82  double x1(xyv[0].first), y1(xyv[0].second);
83  for (unsigned i1 = 1; i1 <= xyv.size(); i1++) {
84  unsigned i2 = (i1 % xyv.size());
85  double x2(xyv[i2].first), y2(xyv[i2].second);
86  if (y > std::min(y1, y2)) {
87  if (y <= std::max(y1, y2)) {
88  if (x <= std::max(x1, x2)) {
89  if (y1 != y2) {
90  double xinter = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
91  if ((x1 == x2) || (x <= xinter))
92  ++counter;
93  }
94  }
95  }
96  }
97  x1 = x2;
98  y1 = y2;
99  }
100 
101  if (counter % 2 == 0)
102  return false;
103  else
104  return true;
105 }
Log< level::Info, true > LogVerbatim
static int32_t cellPlacementIndex(int32_t iz, int32_t frontBack, int32_t orient)
Definition: HGCalCell.cc:237
const double sensorSizeOffset_
Definition: HGCGuardRing.h:19
double ymax_
Definition: HGCGuardRing.h:20
const HGCalParameters * getParameter() const
int32_t waferU(const int32_t index)
static int getPartial(int index, const HGCalParameters::waferInfo_map &wafers)
int zside(DetId const &)
static std::vector< std::pair< double, double > > waferXY(int part, int orient, int zside, double waferSize, double offset, double xpos, double ypos)
static int getOrient(int index, const HGCalParameters::waferInfo_map &wafers)
U second(std::pair< T, U > const &p)
const double waferSize_
Definition: HGCGuardRing.h:19
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
const double guardRingOffset_
Definition: HGCGuardRing.h:19
bool exclude(G4ThreeVector &point, int zside, int frontBack, int layer, int waferU, int waferV)
Definition: HGCGuardRing.cc:25
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double xmax_
Definition: HGCGuardRing.h:20
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
const HGCalDDDConstants & hgcons_
Definition: HGCGuardRing.h:17
static bool insidePolygon(double x, double y, const std::vector< std::pair< double, double > > &xyv)
Definition: HGCGuardRing.cc:80
HGCGuardRing(const HGCalDDDConstants &hgc)
Definition: HGCGuardRing.cc:9
double offset_
Definition: HGCGuardRing.h:20
static std::atomic< unsigned int > counter
const HGCalGeometryMode::GeometryMode modeUV_
Definition: HGCGuardRing.h:18
int32_t waferV(const int32_t index)
float x
static constexpr double sqrt3_
Definition: HGCGuardRing.h:16
waferInfo_map waferInfoMap_
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5