-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSector.java
More file actions
317 lines (286 loc) · 10.7 KB
/
Sector.java
File metadata and controls
317 lines (286 loc) · 10.7 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// part of Taclet
// author: Ulrike Hager
import java.util.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
public class Sector {
private ArrayList<double[]> dataPoints;
private double slope, angle, origin, lastRadius, firstRadius, length, firstZ, lastZ, totalEnergy, secondRadius, secondZ, penultimateRadius, penultimateZ,deltaE;
private int number;
private double radiusOffset;
public Sector(int i){
dataPoints = new ArrayList<double[]>();
lastRadius = length = 0;
firstZ=secondZ=1000000;
lastZ=penultimateZ=-1000000;
totalEnergy=0;
number = i;
}
public Sector(int i, ArrayList<double[]> dataPoints){
this.dataPoints = dataPoints;
lastRadius = length = 0;
firstZ=secondZ=1000000;
lastZ=penultimateZ=-1000000;
totalEnergy=0;
number = i;
updateSector();
}
public ArrayList<double[]> getData(){
return dataPoints;
}
public void setData(ArrayList<double[]> someData){
dataPoints = someData;
}
public void addData(ArrayList<double[]> someData){
int initialPads = dataPoints.size();
for (int j=0 ; j<someData.size() ; j++){
boolean added =false;
for (int i=0 ; i<initialPads ; i++){
if (dataPoints.get(i)[0]-someData.get(j)[0]<2){
if (someData.get(j)[2]>dataPoints.get(i)[2]) dataPoints.set(i,someData.get(j));
added = true;
break;
}
}
if (!added) dataPoints.add(someData.get(j));
}
}
public void addPoint(double zPos, double radius, double energy){
double[] temp = {zPos, radius, energy};
dataPoints.add(temp);
}
public double getTotalEnergy(){
return totalEnergy;
}
public int getNumber(){
return number;
}
public double getAngle(){ // use after getOrigin to set the slope
return angle;
}
public void zeroData(){
lastRadius = length = 0;
firstZ=1000000;
lastZ=-1000000;
totalEnergy=0;
}
public void zeroTrack(){
dataPoints.clear();
dataPoints = new ArrayList<double[]>();
}
public double getLastZ(){
return lastZ;
}
public double getFirstZ(){
return firstZ;
}
public double getLastRadius(){
return lastRadius;
}
public void updateSector(){
totalEnergy=0;
deltaE = Double.NaN;
radiusOffset = 0;
double driftOrigin = 12.0;
double firstE,secondE,penultimateE,lastE,thirdE,thirdLastE;
firstE = secondE = thirdE = thirdLastE = penultimateE = lastE = 0;
if (dataPoints.size() < 2){
origin = Double.NaN; length=Double.NaN; slope=Double.NaN; angle = Double.NaN; lastZ = Double.NaN; lastRadius = Double.NaN;
return;
}
if (dataPoints.size() == 2){
if ((dataPoints.get(0)[2]<0.000001) || (dataPoints.get(1)[2]<0.000001)){
origin = Double.NaN; length=Double.NaN; slope=Double.NaN; angle = Double.NaN; lastZ = Double.NaN; lastRadius = Double.NaN;
return;
}
if (dataPoints.get(0)[1]<dataPoints.get(1)[1]){
firstZ=dataPoints.get(0)[0];
secondZ=dataPoints.get(1)[0];
firstRadius=dataPoints.get(0)[1];
secondRadius=dataPoints.get(1)[1];
}
else{
firstZ=dataPoints.get(1)[0];
secondZ=dataPoints.get(0)[0];
firstRadius=dataPoints.get(1)[1];
secondRadius=dataPoints.get(0)[1];
}
lastZ=secondZ;
lastRadius = secondRadius;
totalEnergy = dataPoints.get(0)[2] + dataPoints.get(1)[2];
slope = (2*(firstZ*firstRadius+secondZ*secondRadius)-((firstZ+secondZ)*(firstRadius+secondRadius)))/(2*(firstZ*firstZ+secondZ*secondZ)-(firstZ+secondZ)*(firstZ+secondZ));
angle = (Math.atan(slope))*(180.0/Math.PI);
origin = firstZ - firstRadius/slope;
length = (lastZ-origin) / (Math.cos(angle*Math.PI/180)); // 4mm per pad
if (angle < 0) angle += 180;
if ((origin<-121) || (origin>122)){ origin = Double.NaN; length=Double.NaN; slope=Double.NaN; angle=Double.NaN;}
return;
}
if (dataPoints.size() > 2){ //dataPoints.size() > 2
double sumZ, sumZZ, sumR, sumRR, sumZR, nPad;
sumZ = sumZZ = sumR = sumZR = nPad = 0;
double thirdZ=firstZ;
double thirdRadius=firstRadius;
double thirdLastZ=lastZ;
double thirdLastRadius=lastRadius;
for (int i=0 ; i<dataPoints.size() ; i++){ //sort through dataPoints
if ((dataPoints.get(i)[1]>60) || (dataPoints.get(i)[2]<0.000001)) continue;
totalEnergy += dataPoints.get(i)[2];
if (dataPoints.get(i)[0]<firstZ) {
thirdZ = secondZ;
thirdRadius = secondRadius;
thirdE=secondE;
secondZ = firstZ;
secondE = firstE;
secondRadius = firstRadius;
firstZ=dataPoints.get(i)[0];
firstRadius=dataPoints.get(i)[1];
firstE=dataPoints.get(i)[2];
}
else if (dataPoints.get(i)[0]<secondZ){
thirdZ = secondZ;
thirdE=secondE;
thirdRadius = secondRadius;
secondZ=dataPoints.get(i)[0];
secondRadius=dataPoints.get(i)[1];
secondE=dataPoints.get(i)[2];
}
else if (dataPoints.get(i)[0] < thirdZ){
thirdZ=dataPoints.get(i)[0];
thirdE=dataPoints.get(i)[2];
thirdRadius=dataPoints.get(i)[1];
}
if (dataPoints.get(i)[0]>lastZ) {
thirdLastZ = penultimateZ;
thirdLastRadius = penultimateRadius;
thirdLastE = penultimateE;
penultimateZ = lastZ;
penultimateRadius = lastRadius;
penultimateE = lastE;
lastZ=dataPoints.get(i)[0];
lastRadius=dataPoints.get(i)[1];
lastE=dataPoints.get(i)[2];
}
else if (dataPoints.get(i)[0] > penultimateZ) {
thirdLastZ = penultimateZ;
thirdLastRadius = penultimateRadius;
thirdLastE = penultimateE;
penultimateZ=dataPoints.get(i)[0];
penultimateRadius=dataPoints.get(i)[1];
penultimateE=dataPoints.get(i)[2];
}
else if (dataPoints.get(i)[0] > thirdLastZ){
thirdLastZ=dataPoints.get(i)[0];
thirdLastE=dataPoints.get(i)[2];
thirdLastRadius=dataPoints.get(i)[1];
}
nPad++;
sumZ += dataPoints.get(i)[0];
sumZZ += dataPoints.get(i)[0]*dataPoints.get(i)[0];
sumR += dataPoints.get(i)[1];
sumZR += dataPoints.get(i)[0]*dataPoints.get(i)[1];
}
double totSlope = (nPad*sumZR - sumZ*sumR)/(nPad*sumZZ - sumZ*sumZ);
if ((lastRadius<firstRadius) && ((lastRadius <= secondRadius) || (firstE > secondE/2.5))){
double temp = firstZ; firstZ=lastZ; lastZ=temp;
temp = firstRadius; firstRadius=lastRadius; lastRadius=temp;
temp = firstE; firstE=lastE; lastE=temp;
secondZ = penultimateZ; secondRadius = penultimateRadius; secondE = penultimateE;
thirdZ = thirdLastZ; thirdRadius = thirdLastRadius; thirdE=thirdLastE;
}
if (dataPoints.size()>3) deltaE = secondE + thirdE;
double firstSlope = (2*(firstZ*firstRadius+secondZ*secondRadius)-((firstZ+secondZ)*(firstRadius+secondRadius)))/(2*(firstZ*firstZ+secondZ*secondZ)-(firstZ+secondZ)*(firstZ+secondZ));
double secondSlope = (2*(thirdZ*thirdRadius+secondZ*secondRadius)-((thirdZ+secondZ)*(thirdRadius+secondRadius)))/(2*(thirdZ*thirdZ+secondZ*secondZ)-(thirdZ+secondZ)*(thirdZ+secondZ));
double totAngle = (Math.atan(totSlope))*(180.0/Math.PI);
double secondAngle = (Math.atan(secondSlope))*(180.0/Math.PI);
slope = firstSlope;
angle = (Math.atan(slope))*(180.0/Math.PI);
origin = firstZ - firstRadius/slope;
// System.out.println("points 1&2 slope: " + slope + " angle: " + angle + " origin: " + origin);
// System.out.println("points 2&3 slope: " + secondSlope + " angle: " + secondAngle + " origin: " + (secondZ - secondRadius/secondSlope));
// System.out.println("total slope: " + totSlope + " angle: " + totAngle + " origin: " + (firstZ - firstRadius/totSlope) + "\n");
if ((origin<-120) || (origin>120)) {radiusOffset = 1.5; origin = firstZ - 1/slope *(firstRadius - radiusOffset);}
if ((origin<-120) || (origin>120)) {radiusOffset = 3; origin = firstZ - 1/slope *(firstRadius - radiusOffset);}
// if ((Math.signum(totSlope) != Math.signum(slope)) || (Math.abs(totAngle-angle) - Math.abs(secondAngle-totAngle) > 10 ) || (origin<-121) || (origin>122)){
// if ((Math.abs(totAngle-angle) - Math.abs(secondAngle-totAngle) > 10 ) || (origin<-121) || (origin>122)){
if (((Math.abs(secondAngle-angle) > 30) && (Math.abs(secondAngle-totAngle) < 20) && (Math.abs(secondSlope) > 0.00000001)) || (origin<-120) || (origin>120) || (firstE < secondE/2.5) || ((Math.signum(slope) != Math.signum(totSlope)) && (Math.abs(secondSlope) > 0.00000001) )){
firstZ = secondZ; firstRadius = secondRadius;
slope = secondSlope; angle = secondAngle;
radiusOffset = 0;
origin = firstZ - firstRadius/slope;
if ((origin<-120) || (origin>120)) {radiusOffset = 1.5; origin = firstZ - 1/slope *(firstRadius - radiusOffset);}
if ((origin<-120) || (origin>120)) {radiusOffset = 3; origin = firstZ - 1/slope *(firstRadius - radiusOffset);}
}
if (nPad == 2) {
angle = totAngle;
slope = totSlope;
radiusOffset = 0;
origin = firstZ - firstRadius/slope;
if ((origin<-120) || (origin>120)) {radiusOffset = 1.5; origin = firstZ - 1/slope *(firstRadius - radiusOffset);}
if ((origin<-120) || (origin>120)) {radiusOffset = 3; origin = firstZ - 1/slope *(firstRadius - radiusOffset);}
}
length = (lastZ-origin-radiusOffset/slope) / (Math.cos(angle*Math.PI/180)); // 4mm per pad
if (angle < 0) angle += 180;
if ((origin<-120) || (origin>120)){ origin = Double.NaN; length=Double.NaN; slope=Double.NaN; angle=Double.NaN;}
}
}
public double getOrigin(){
return origin;
}
public double getTotalLength(){
return length;
}
public double getDeltaE(){
return deltaE;
}
public void paintTrack(Graphics g, int Scale, boolean logScale){
Graphics2D g2D = (Graphics2D) g;
double xc,yc,rc;
switch(number){
case 0:
case 1:
case 6:
case 7:
for (int j=0 ; j<dataPoints.size() ; j++){
if (logScale) rc = Math.pow(10,dataPoints.get(j)[2]) * Scale;
else rc = dataPoints.get(j)[2] * Scale;
xc =(double)(((double)dataPoints.get(j)[0]+120.0)*10.0/4.0+20.0- rc/2.0);
yc = (450.0 - (((double)dataPoints.get(j)[1]) *3.0))-(rc/2.0);
g2D.fill(new Ellipse2D.Double(xc,yc,rc,rc));
}
break;
case 2:
case 3:
case 4:
case 5:
for (int j=0 ; j<dataPoints.size() ; j++){
if (logScale) rc = Math.pow(10,dataPoints.get(j)[2]) * Scale;
else rc = dataPoints.get(j)[2] * Scale;
xc =(double)((dataPoints.get(j)[0]+120.0)*10.0/4.0+20.0-rc/2.0);
yc =((dataPoints.get(j)[1]) *3.0)+450.0-(rc/2.0);
g2D.fill(new Ellipse2D.Double(xc,yc,rc,rc));
}
break;
}
}
public void paintLine(Graphics g, int Scale){
Graphics2D g2D = (Graphics2D) g;
if ((!Double.isNaN(origin)) && (!Double.isNaN(slope))){
switch(number){
case 0:
case 1:
case 6:
case 7:
g2D.draw(new Line2D.Double(((origin+120.0)*10.0/4.0)+20.0,450.0-(radiusOffset*3),((lastZ+120.0)*10.0/4.0)+20.0,(((origin-lastZ)*slope-radiusOffset)*3.0)+450.0));
break;
case 2:
case 3:
case 4:
case 5:
g2D.draw(new Line2D.Double(((origin+120.0)*10.0/4.0)+20.0,450.0+(radiusOffset*3),((lastZ+120.0)*10.0/4.0)+20.0,(((lastZ-origin)*slope+radiusOffset)*3.0)+450.0));
break;
}
}
}
}