-
Notifications
You must be signed in to change notification settings - Fork 12
/
WirePlane2D.cxx
235 lines (193 loc) · 6.15 KB
/
WirePlane2D.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include "WirePlane2D.h"
#include "TMath.h"
#include <cstring>
#include <cstdio>
#include <iostream>
#include <sstream>
#define DEBUG_LEVEL 0
using namespace std;
WirePlane2D::WirePlane2D(string PlaneName, double Height, double Width, double WireAngle,
int nWires, int wirecolor, CStransform *trans, double offset, int index)
{
cst = trans;
color = wirecolor;
double th= WireAngle*3.14159/180.0;
int ind= index;
/// Width (left to right) = 56.0 cm
/// Height = 113 cm
/// Ratio H/w = 2.017857
double x = cst->transXtoCX(0.0) - cst->transLtoCL(Width)/2;
double y = cst->transYtoCY(0.0) - cst->transLtoCL(Height)/2;
double a = cst->transLtoCL(Width);
double b = cst->transLtoCL(Height);
double os= cst->transLtoCL(offset);
// n = actual number of wires
// Num = number of wires that we draw
if ((nWires/5.0 - int(nWires/5.0))>0) WireNum = (int) (nWires/5.0) + 1; // must be rounded up
else WireNum = (int) (nWires/5.0);
//Draw the Wires
double d;
double x1,y1,x2,y2,fac;
if(th==0.0) {
for(int n=0; n<WireNum; n++) {
fac=((double)n/(double)WireNum);
x1=x;
y1=y+b*(1-fac)-os;
x2=x+a;
y2=y+b*(1-fac)-os;
wires.push_back(new TLine(x1,y1,x2,y2));
wires[n]->SetLineColor(kGray);
wires[n]->Draw();
}
}
else if(WireAngle==90.0) {
for(int n=0; n<WireNum; n++) {
fac=((double)n/(double)WireNum);
x1=x+a*fac+os;
y1=y;
x2=x+a*fac+os;
y2=y+b;
wires.push_back(new TLine(x1,y1,x2,y2));
wires[n]->SetLineColor(kGray);
wires[n]->Draw();
}
}
else if(fabs(th)<atan(b/a)) {
if(WireAngle>0.0 && WireAngle<90.0) {
d=b+a*tan(th);
for(int n=0; n<WireNum; n++) {
fac=((double)n/(double)WireNum);
if((a*tan(th)-d*fac)>0) {
x1=x;
y1=y+b-d*fac;
x2=x+d*fac/tan(th);
y2=y+b;
} else if((b-d*fac)<0) {
x1=x+(d*fac-b)/tan(th);
y1=y;
x2=x+a;
y2=y+b-d*fac+a*tan(th);
} else {
x1=x;
y1=y+b-d*fac;
x2=x+a;
y2=y+b-d*fac+a*tan(th);
}
wires.push_back(new TLine(x1,y1,x2,y2));
wires[n]->SetLineColor(kGray);
wires[n]->Draw();
}
}
else if(WireAngle<0.0 && WireAngle>-90.0) {
th=-th;
d=b+a*tan(th);
for(int n=0; n<WireNum; n++) {
fac=((double)n/(double)WireNum);
if((d*fac-a*tan(th))<0) {
x1=x+a-d*fac/tan(th);
y1=y+b;
x2=x+a;
y2=y+d*(1-fac)-a*tan(th);
} else if((d*(1-fac)-a*tan(th))<0) {
x2=x+d*(1-fac)/tan(th);
y2=y;
x1=x;
y1=y+d*(1-fac);
} else {
x1=x;
y1=y+d*(1-fac);
x2=x+a;
y2=y+d*(1-fac)-a*tan(th);
}
wires.push_back(new TLine(x1,y1,x2,y2));
wires[n]->SetLineColor(kGray);
wires[n]->Draw();
}
}
}
//when fabs(th)>arctan(b/a)
else {
if(WireAngle>0.0) {
d=a+b/tan(th);
for(int n=0; n<WireNum; n++) {
fac=((double)n/(double)WireNum);
if((d*fac)<(b/tan(th))) {
x1=x;
y1=y+b-d*fac*tan(th);
x2=x+d*fac;
y2=y+b;
} else if((a-d*fac)<0) {
x1=x+d*fac-b/tan(th);
y1=y;
x2=x+a;
y2=y+b-(d*fac-a)*tan(th);
} else {
x1=x+d*fac-b/tan(th);
y1=y;
x2=x+d*fac;
y2=y+b;
}
wires.push_back(new TLine(x1,y1,x2,y2));
wires[n]->SetLineColor(kGray);
wires[n]->Draw();
}
}
else if(WireAngle<0.0) {
th=-th;
d=a+b/tan(th);
for(int n=0; n<WireNum; n++) {
fac=((double)n/(double)WireNum);
if((d*fac-b/tan(th))<0) {
x1=x;
y1=y+(d*fac)*tan(th);
x2=x+d*fac;
y2=y;
} else if((d*fac-a)>0) {
x2=x+a;
y2=y+(d*fac-a)*tan(th);
x1=x+d*fac-b/tan(th);
y1=y+b;
} else {
x1=x+d*fac;
y1=y;
x2=x+d*fac-b/tan(th);
y2=y+b;
}
wires.push_back(new TLine(x1,y1,x2,y2));
wires[n]->SetLineColor(kGray);
wires[n]->Draw();
}//for loop
}//else if(WireAngle<0.0)
}
//else cerr<< "WirePlane2D construct error.\n";
//Type name and draw circle represent the WirePlane;
circ = new TEllipse(x+a+0.02,y+b*(1-(double)ind/6), b*0.03, b*0.03);
circ->SetFillColor(kGray);
circ->Draw();
TLatex *title = new TLatex(x+a+0.035,y+b*(1-(double)ind/6), PlaneName.c_str());
title->SetTextSize(0.02);
title->Draw();
}
WirePlane2D::~WirePlane2D()
{
}
void WirePlane2D::WireHit(int Num)
{
int quotient = (int) Num/5; /// 1 wire drawn for every 5 "real" wires
if (quotient<WireNum) {
#if DEBUG_LEVEL >= 3
cout<<"****u1WireHit: "<<quotient<<endl;
#endif
wires[quotient]->SetLineColor(color);
wires[quotient]->SetLineWidth(3);
circ->SetFillColor(color);
}
}
void WirePlane2D::clear ()
{
for(int n=0; n< WireNum; n++) {
wires[n]->SetLineColor(kGray);
wires[n]->SetLineWidth(1);
}
circ->SetFillColor(kGray);
}