-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceCalibrationCurveConverter31082018_MS.java
More file actions
205 lines (157 loc) · 8.07 KB
/
Copy pathDeviceCalibrationCurveConverter31082018_MS.java
File metadata and controls
205 lines (157 loc) · 8.07 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
package de.gsi.cs.co.ap.my_test_project.utils;
import cern.accsoft.commons.value.BoundedPolynomial;
import cern.accsoft.commons.value.BoundedPolynomialSequence;
import cern.accsoft.commons.value.Interval;
// import cern.accsoft.commons.value.Polynomial;
// import cern.accsoft.commons.value.operation.BoundedPolynomialOperations;
// import cern.accsoft.commons.value.operation.BoundedPolynomialSequenceOperations;
import cern.accsoft.commons.value.operation.PolynomialOperations;
import cern.lsa.client.OpticService;
import cern.lsa.client.Services;
// import cern.lsa.domain.commons.BoundedFunction;
// import cern.lsa.domain.commons.CalibrationFunction;
import cern.lsa.domain.commons.spi.CalibrationFunctionWrapper;
// import cern.lsa.domain.devices.Device;
import cern.lsa.domain.optics.Calibration;
import cern.lsa.domain.optics.CalibrationFunctionTypes;
// for library loggers
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
// for application loggers
// import de.gsi.cs.co.ap.common.gui.elements.logger.AppLogger;
/**
* @author fschirru
*/
public class DeviceCalibrationCurveConverter {
private static final RegulaFalsiMethod rfm = RegulaFalsiMethod.getInstance();
private static final DeviceCalibrationCurveConverter INSTANCE = new DeviceCalibrationCurveConverter();
public static DeviceCalibrationCurveConverter getInstance() {
return INSTANCE;
}
public double getValueFromCalibrationCurve(final String logicalDeviceName, final double y, final String calType) {
double invertedValue = 0.0;
try {
// final String deviceName = "LOGICAL.GTE1KY1I";
final OpticService opticService = Services.getOpticService();
// System.exit(0);
// final Calibration calibration = opticService.findCalibrationByLogicalHardware(deviceName);
final Calibration calibration = opticService.findCalibrationByLogicalHardware(logicalDeviceName);
// System.out.println(calibration);
// Case of convertion current to bfield
if (calType.equals("current")) {
// System.out.println("*** START NEW DEVICE ***");
// System.out.println("LOGICAL DEVICE: " + logicalDeviceName);
final CalibrationFunctionWrapper currentAsFunctionOfIntegralField = (CalibrationFunctionWrapper) calibration
.getCalibrationFunction(CalibrationFunctionTypes.MAG_INTFIELD2CURRENT);
final BoundedPolynomialSequence boundedPolynomialSequence = (BoundedPolynomialSequence) currentAsFunctionOfIntegralField
.getInterpolable();
// final BoundedPolynomial polynomial = findBoundedPolynomial(boundedPolynomialSequence, y,
// logicalDeviceName);
final BoundedPolynomial polynomial = findBoundedPolynomial(boundedPolynomialSequence, y);
if (polynomial != null) {
invertedValue = rfm.findRoot(polynomial.getInterval().getLowerBound(),
polynomial.getInterval().getUpperBound(), 5E-8, 1000, polynomial, y);
} else {
invertedValue = 0.0;
}
// invertedValue = PolynomialOperations.invert(polynomial, y);
// if (logicalDeviceName.equals("LOGICAL.GHFSMU1")) {
// System.out.println("LOGICAL DEVICE: " + logicalDeviceName);
// System.out.println("Y: " + y);
// System.out.println("CAL TYPE: " + calType);
// System.out.println(currentAsFunctionOfIntegralField);
// System.out.println("Polynomial sequence: " + boundedPolynomialSequence);
// System.out.println("Polynomial filtered sequence: " + polynomial);
// System.out.println("INVERTED VAL: " + invertedValue);
// System.exit(0);
// }
}
if (calType.equals("voltage")) {
/*
*
* final CalibrationFunctionWrapper voltageAsFunctionOfIntegralField = (CalibrationFunctionWrapper)
* calibration
* .getCalibrationFunction(CalibrationFunctionTypes.MAG_INTFIELD2VOLTAGE);
*
* // System.out.println(voltageAsFunctionOfIntegralField.getInterpolable());
* // System.exit(0);
*
* final BoundedPolynomialSequence boundedPolynomialSequence = (BoundedPolynomialSequence)
* voltageAsFunctionOfIntegralField
* .getInterpolable();
*
* final BoundedPolynomial polynomial = findBoundedPolynomial(boundedPolynomialSequence, y);
* invertedValue = PolynomialOperations.invert(polynomial, y);
*
* // System.out.println("Inverted Value " + invertedValue);
*/
}
/*
* if (logicalDeviceName.equals("LOGICAL.GTS2QT12")) {
*
* System.out.println(y);
* System.out.println(invertedValue);
* System.out.println(boundedPolynomialSequence);
* System.out.println(polynomial);
*
* System.exit(0);
*
* }
*/
/*
* if (polynomial == null) {
*
* System.out.println(invertedValue);
* System.exit(0);
* }
*/
} catch (final Exception e) {
System.out.println(e);
invertedValue = -0.5;
// System.exit(0);
}
return invertedValue;
}
// private static BoundedPolynomial findBoundedPolynomial(final BoundedPolynomialSequence boundedPolynomialSequence,
// final double y, final String device) {
private static BoundedPolynomial findBoundedPolynomial(final BoundedPolynomialSequence boundedPolynomialSequence,
final double y) {
final BoundedPolynomial[] boundedPolynomials = boundedPolynomialSequence.getBoundedPolynomials();
for (final BoundedPolynomial boundedPolynomial : boundedPolynomials) {
// System.out.println(boundedPolynomial);
final double lowerBound = boundedPolynomial.getInterval().getLowerBound();
final double upperBound = boundedPolynomial.getInterval().getUpperBound();
final Interval interval = Interval.of(boundedPolynomial.interpolate(lowerBound),
boundedPolynomial.interpolate(upperBound));
// System.out.println(interval);
if (interval.contains(y)) {
// if (device.equals("LOGICAL.GTS2QT11")) {
// System.out.println("*** returning Polynomial ***");
// System.out.println("Lower Bound: " + lowerBound);
// System.out.println("Upper Bound: " + upperBound);
// System.out.println("INTERVAL: " + interval);
// System.out.println("Y:" + y);
// System.out.println("*** returning Polynomial ***");
return boundedPolynomial;
// }
}
}
// System.exit(0);
return null;
}
/*
* s,t: endpoints of an interval where we search
* e: half of upper bound for relative error
* m: maximal number of iterations
*/
private double FalsiMethod(final double s, final double t, final double e, final int m,
final BoundedPolynomial boundedPolynomial, final double Iist) {
final double magneticField = 0.0;
return magneticField;
}
// You can choose a logger (needed imports are given in the import section as comments):
// for libraries:
// private static final Logger LOGGER = LoggerFactory.getLogger(DeviceCalibrationCurveConverter.class);
// for applications:
// private static final AppLogger LOGGER = AppLogger.getLogger();
}