EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EtmPolygonGroup.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EtmPolygonGroup.cc
1 
2 #include <TPolyLine.h>
3 
4 #include <EicToyModel.h>
5 #include <EtmPolygonGroup.h>
6 
7 // ---------------------------------------------------------------------------------------
8 // ---------------------------------------------------------------------------------------
9 
10 void EtmPolygonGroup::AddPolygon(unsigned dim, const double xx[], const double yy[])
11 {
12  std::vector<TVector2> edges;
13 
14  for(unsigned iq=0; iq<dim; iq++)
15  edges.push_back(TVector2(xx[iq], yy[iq]));
16 
17  mPolygons.push_back(edges);
18 } // EtmPolygonGroup::AddPolygon()
19 
20 // ---------------------------------------------------------------------------------------
21 
22 void EtmPolygonGroup::AddRectangle(const TVector2 &bl, const TVector2 &tr,
23  unsigned xsplit, unsigned ysplit)
24 {
25  if (!xsplit) xsplit = 1; if (!ysplit) ysplit = 1;
26 
27  double x0 = bl.X(), y0 = bl.Y();
28  double xstep = (tr.X() - bl.X())/xsplit, ystep = (tr.Y() - bl.Y())/ysplit;
29 
30  // FIXME: not the most economic way to do this; but it works;
31  for(unsigned ix=0; ix<xsplit; ix++) {
32  double xOffset = x0 + xstep*ix;
33 
34  for(unsigned iy=0; iy<ysplit; iy++) {
35  double yOffset = y0 + ystep*iy;
36 
37  std::vector<TVector2> buffer;
38 
39  buffer.push_back(TVector2(xOffset, yOffset));
40  buffer.push_back(TVector2(xOffset + xstep, yOffset));
41  buffer.push_back(TVector2(xOffset + xstep, yOffset + ystep));
42  buffer.push_back(TVector2(xOffset, yOffset + ystep));
43 
44  AddPolygon(buffer);
45  } //for iy
46  } //for ix
47 } // EtmPolygonGroup::AddRectangle()
48 
49 // ---------------------------------------------------------------------------------------
50 
51 void EtmPolygonGroup::AddRectangle(double x0, double y0, double xsize, double ysize,
52  unsigned xsplit, unsigned ysplit)
53 {
54  AddRectangle(TVector2(x0 - xsize/2, y0 - ysize/2), TVector2(x0 + xsize/2, y0 + ysize/2),
55  xsplit, ysplit);
56 } // EtmPolygonGroup::AddRectangle()
57 
58 // ---------------------------------------------------------------------------------------
59 
61 {
62  // NB: '&' here is essential!; well, is this call needed at all (see mPolygons.clear())?;
63  for(auto &polygon: mPolygons)
64  polygon.clear();
65 
66  mPolygons.clear();
67 } // EtmPolygonGroup::ClearPolygons()
68 
69 // ---------------------------------------------------------------------------------------
70 
71 void EtmPolygonGroup::DrawPolygon(unsigned dim, const double xx[], const double yy[], bool line) const
72 {
73  auto eic = EicToyModel::Instance();
74 
75  double xxc[dim+1], yyc[dim+1];
76 
77  for(unsigned iq=0; iq<dim; iq++) {
78  auto xyc = eic->cnv(TVector2(xx[iq], yy[iq]));
79  xxc[iq] = xyc.X(); yyc[iq] = xyc.Y();
80  } //for iq
81  xxc[dim] = xxc[0]; yyc[dim] = yyc[0];
82 
83  TPolyLine *poly = new TPolyLine(dim+1, xxc, yyc);
84 
85  poly->SetLineColor(mLineColor);
86  poly->SetFillColorAlpha(IsHighlighted() ? mFillColor : kWhite, GetColorAlpha());
87  poly->SetLineWidth(mLineWidth);
88  poly->SetLineStyle(mLineStyle);
89  poly->Draw("F");
90  if (line) poly->Draw();
91  // FIXME: this is indeed a hack;
92  if (eic->mUseDetectorHighlighting) {
93  TPolyLine *qpoly = new TPolyLine(dim+1, xxc, yyc);
94 
95  qpoly->SetLineColor(kWhite);
96  qpoly->SetLineWidth(3);
97  qpoly->SetLineStyle(mLineStyle);
98  qpoly->Draw("");
99  if (line) qpoly->Draw();
100  } //if
101 } // EtmPolygonGroup::DrawPolygon()
102 
103 // ---------------------------------------------------------------------------------------
104 
105 void EtmPolygonGroup::DrawPolygon(const std::vector<TVector2> &polygon, bool line,
106  const TVector2 *shift, unsigned tb) const
107 {
108  // Not the most efficient way, but TPolyLine requires separate xx[] and yy[] arrays anyway;
109  unsigned dim = polygon.size();
110  double xx[dim], yy[dim];
111 
112  for(unsigned iq=0; iq<dim; iq++) {
113  TVector2 vtx = polygon[iq] + (shift ? *shift : TVector2());
114 
115  xx[iq] = vtx.X();//polygon[iq].X();
116  yy[iq] = vtx.Y()*(tb ? -1.0 : 1.0);//polygon[iq].Y();
117  } //for iq
118 
119  DrawPolygon(dim, xx, yy, line);
120 } // EtmPolygonGroup::DrawPolygon()
121 
122 // ---------------------------------------------------------------------------------------
123 
124 void EtmPolygonGroup::DrawMe(const TVector2 *shift, unsigned tb) const
125 {
126  for(auto polygon: mPolygons)
127  DrawPolygon(polygon, true, shift, tb);
128 } // EtmPolygonGroup::DrawMe()
129 
130 // ---------------------------------------------------------------------------------------
131 // ---------------------------------------------------------------------------------------
132