Changeset 17020
- Timestamp:
- 08/19/13 16:29:10 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r16996 r17020 444 444 deque<float> fTngWeatherDustHist; 445 445 Time fTngWeatherDustTime; 446 447 vector<float> fFeedbackCalibration;448 449 float fFeedbackTempOffset;450 float fFeedbackUserOffset;451 446 452 447 vector<float> fBiasControlVoltageVec; … … 1073 1068 } 1074 1069 1075 int HandleFeedbackCalibration(const EventImp &d) 1076 { 1077 if (!CheckDataSize(d, "Feedback:Calibration", 3*4*416)) 1078 { 1079 fFeedbackCalibration.clear(); 1070 int HandleFeedbackCalibratedCurrents(const EventImp &d) 1071 { 1072 if (!CheckDataSize(d, "Feedback:CalibratedCurrents", (416+1+1+1+1+1+416+1+1)*sizeof(float)+sizeof(uint32_t))) 1080 1073 return GetCurrentState(); 1081 }1082 1074 1083 1075 const float *ptr = d.Ptr<float>(); 1084 fFeedbackCalibration.assign(ptr+2*416, ptr+3*416); 1076 1077 double power_tot = 0; 1078 double power_apd = 0; 1079 1080 // Calibrate the data (subtract offset) 1081 for (int i=0; i<320; i++) 1082 { 1083 // Group index (0 or 1) of the of the pixel (4 or 5 pixel patch) 1084 const int N = fPixelMap.hv(i).count(); 1085 1086 // Serial resistor of the individual G-APDs 1087 double R5 = 3900/N; 1088 1089 // This is also valid for the patches with wrong resistors, 1090 // because Iapd is a factor f larger but R a factor f smaller 1091 double Iapd = ptr[i] * 1e-6; // [A] 1092 double Iout = Iapd*N; // [A] 1093 1094 double UdrpCam = 1000 *Iout; // Voltage seen by everything in Camera 1095 double UdrpApd = (R5+2000)*Iout; // Voltage seen by G-APD 1096 1097 const double pwrCam = Iapd * (fBiasControlVoltageVec[i]-UdrpCam); 1098 const double pwrApd = Iapd * (fBiasControlVoltageVec[i]-UdrpApd); 1099 1100 // Total power participated in the camera at the G-APD 1101 // and the serial resistors (total voltage minus voltage 1102 // drop at resistors in bias crate) 1103 power_tot += pwrCam; 1104 1105 // Power consumption per G-APD 1106 power_apd += pwrApd; 1107 } 1108 1109 // Divide by number of summed channels, convert to mW 1110 power_apd /= 320e-3; // [mW] 1111 1112 if (power_tot<1e-3) 1113 power_tot = 0; 1114 if (power_apd<1e-3) 1115 power_apd = 0; 1116 1117 fBiasControlPowerTot = power_tot; 1118 1119 // -------------------------------------------------------- 1120 1121 // Get the maximum of each patch 1122 vector<float> val(320, 0); 1123 for (int i=0; i<320; i++) 1124 { 1125 const int idx = (fPixelMap.hv(i).hw()/9)*2+fPixelMap.hv(i).group(); 1126 val[idx] = ptr[i]; 1127 } 1128 1129 // Write the 160 patch values to a file 1130 WriteCam(d, "cam-biascontrol-current", val, 100); 1131 1132 // -------------------------------------------------------- 1133 1134 const Statistics stat(vector<float>(ptr, ptr+320)); 1135 1136 // Exclude the three crazy channels 1137 fBiasControlCurrentMed = stat.med; 1138 fBiasControlCurrentMax = stat.max; 1139 1140 // Store a history of the last 60 entries 1141 fBiasControlCurrentHist.push_back(fBiasControlCurrentMed); 1142 if (fBiasControlCurrentHist.size()>360) 1143 fBiasControlCurrentHist.pop_front(); 1144 1145 // write the history to a file 1146 WriteHist(d, "hist-biascontrol-current", fBiasControlCurrentHist, 100); 1147 1148 // -------------------------------------------------------- 1149 1150 string col1 = HTML::kGreen; 1151 string col2 = HTML::kGreen; 1152 string col3 = HTML::kGreen; 1153 string col4 = HTML::kGreen; 1154 1155 if (stat.min>90) 1156 col1 = HTML::kYellow; 1157 if (stat.min>110) 1158 col1 = HTML::kRed; 1159 1160 if (stat.med>90) 1161 col2 = HTML::kYellow; 1162 if (stat.med>110) 1163 col2 = HTML::kRed; 1164 1165 if (stat.avg>90) 1166 col3 = HTML::kYellow; 1167 if (stat.avg>110) 1168 col3 = HTML::kRed; 1169 1170 if (stat.max>90) 1171 col4 = HTML::kYellow; 1172 if (stat.max>110) 1173 col4 = HTML::kRed; 1174 1175 ostringstream out; 1176 out << setprecision(3); 1177 out << d.GetJavaDate() << '\n'; 1178 out << HTML::kGreen << '\t' << "yes" << '\n'; 1179 out << col1 << '\t' << stat.min << '\n'; 1180 out << col2 << '\t' << stat.med << '\n'; 1181 out << col3 << '\t' << stat.avg << '\n'; 1182 out << col4 << '\t' << stat.max << '\n'; 1183 out << HTML::kWhite << '\t' << power_tot << "W [" << power_apd << "mW]\n"; 1184 ofstream(fPath+"/current.data") << out.str(); 1185 1186 // -------------------------------------------------------- 1187 1188 const float Unom = ptr[2*416+6]; 1189 const float Utmp = ptr[2*416+7]; 1190 1191 vector<float> Uov(ptr+416+6, ptr+416+6+320); 1192 1193 WriteCam(d, "cam-feedback-overvoltage", Uov, 0.2, 1.0); 1194 1195 const Statistics stat2(Uov); 1196 1197 out.str(""); 1198 out << d.GetJavaDate() << '\n'; 1199 out << setprecision(3); 1200 out << HTML::kWhite << '\t' << Utmp << '\n'; 1201 out << HTML::kWhite << '\t' << Unom << '\n'; 1202 out << HTML::kWhite << '\t' << stat2.min << '\n'; 1203 out << HTML::kWhite << '\t' << stat2.med << '\n'; 1204 out << HTML::kWhite << '\t' << stat2.avg << '\n'; 1205 out << HTML::kWhite << '\t' << stat2.max << '\n'; 1206 ofstream(fPath+"/feedback.data") << out.str(); 1085 1207 1086 1208 return GetCurrentState(); 1087 1209 } 1088 1210 1089 int Handle FeedbackDeviation(const EventImp &d)1090 { 1091 if ( !CheckDataSize(d, "Feedback:Deviation", (2*416+2)*4))1211 int HandleBiasCurrent(const EventImp &d) 1212 { 1213 if (fDimFeedback.state()>=Feedback::State::kCalibrated) 1092 1214 return GetCurrentState(); 1093 1215 1094 const float *ptr = d.Ptr<float>(); 1095 vector<float> dev(ptr+416, ptr+416+320); 1096 1097 fFeedbackTempOffset = ptr[2*416]; 1098 fFeedbackUserOffset = ptr[2*416+1]; 1099 1216 if (!CheckDataSize(d, "BiasControl:Current", 832)) 1217 return GetCurrentState(); 1218 1219 // Convert dac counts to uA 1220 vector<float> v(320); 1100 1221 for (int i=0; i<320; i++) 1101 dev[i] -= fFeedbackTempOffset+fFeedbackUserOffset; 1222 v[i] = d.Ptr<uint16_t>()[i] * 5000./4096; 1223 1224 fBiasControlPowerTot = 0; 1225 1226 // Get the maximum of each patch 1227 vector<float> val(320, 0); 1228 for (int i=0; i<320; i++) 1229 { 1230 const PixelMapEntry &hv = fPixelMap.hv(i); 1231 if (!hv) 1232 continue; 1233 1234 const int idx = (hv.hw()/9)*2+hv.group(); 1235 val[idx] = v[i]; 1236 } 1102 1237 1103 1238 // Write the 160 patch values to a file 1104 WriteCam(d, "cam-feedback-deviation", dev, 1); 1105 1106 const Statistics stat(dev, 3); 1239 WriteCam(d, "cam-biascontrol-current", val, 1000); 1240 1241 const Statistics stat(v, 0, 3); 1242 1243 // Exclude the three crazy channels 1244 fBiasControlCurrentMed = stat.med; 1245 fBiasControlCurrentMax = stat.max; 1246 1247 // Store a history of the last 60 entries 1248 fBiasControlCurrentHist.push_back(fBiasControlCurrentMed); 1249 if (fBiasControlCurrentHist.size()>360) 1250 fBiasControlCurrentHist.pop_front(); 1251 1252 // write the history to a file 1253 WriteHist(d, "hist-biascontrol-current", fBiasControlCurrentHist, 1000); 1107 1254 1108 1255 ostringstream out; 1256 out << setprecision(3); 1109 1257 out << d.GetJavaDate() << '\n'; 1110 out << HTML::kWhite << '\t' << fFeedbackUserOffset << '\n'; 1111 out << setprecision(3); 1112 out << HTML::kWhite << '\t' << fFeedbackTempOffset << '\n'; 1258 out << HTML::kWhite<< '\t' << "no" << '\n'; 1113 1259 out << HTML::kWhite << '\t' << stat.min << '\n'; 1114 1260 out << HTML::kWhite << '\t' << stat.med << '\n'; 1115 1261 out << HTML::kWhite << '\t' << stat.avg << '\n'; 1116 1262 out << HTML::kWhite << '\t' << stat.max << '\n'; 1117 ofstream(fPath+"/feedback.data") << out.str(); 1263 out << HTML::kWhite << '\t' << "---\n"; 1264 ofstream(fPath+"/current.data") << out.str(); 1118 1265 1119 1266 return GetCurrentState(); … … 1141 1288 } 1142 1289 1143 if (fDimBiasControl.state()==BIAS::State::kVoltageOn )1290 if (fDimBiasControl.state()==BIAS::State::kVoltageOn || fDimBiasControl.state()==BIAS::State::kRamping) 1144 1291 WriteCam(d, "cam-biascontrol-voltage", val, 10, 65); 1145 1292 else … … 1154 1301 out << HTML::kWhite << '\t' << stat.max << '\n'; 1155 1302 ofstream(fPath+"/voltage.data") << out.str(); 1156 1157 return GetCurrentState();1158 }1159 1160 int HandleBiasCurrent(const EventImp &d)1161 {1162 if (!CheckDataSize(d, "BiasControl:Current", 832))1163 return GetCurrentState();1164 1165 // Convert dac counts to uA1166 vector<float> v(320);1167 for (int i=0; i<320; i++)1168 v[i] = d.Ptr<uint16_t>()[i] * 5000./4096;1169 1170 const bool cal = !fFeedbackCalibration.empty() && !fBiasControlVoltageVec.empty();1171 1172 double power_tot = 0;1173 double power_apd = 0;1174 1175 // 3900 Ohm/n + 1000 Ohm + 1100 Ohm (with n=4 or n=5)1176 const double R[2] = { 3075, 2870 };1177 1178 // Calibrate the data (subtract offset)1179 if (cal)1180 for (int i=0; i<320; i++)1181 {1182 // Measued current minus leakage current (bias crate calibration)1183 v[i] -= fBiasControlVoltageVec[i]/fFeedbackCalibration[i]*1e6;1184 1185 // Total power participated in the camera at the G-APD1186 // and the serial resistors (total voltage minus voltage1187 // drop at resistors in bias crate)1188 power_tot += v[i]*(fBiasControlVoltageVec[i] - 1100e-6*v[i])*1e-6;1189 1190 // Group index (0 or 1) of the of the pixel (4 or 5 pixel patch)1191 const int g = fPixelMap.hv(i).group();1192 1193 // Current per G-APD1194 v[i] /= g ? 5 : 4;1195 1196 // Power consumption per G-APD1197 if (i!=66 && i!=191 && i!=193)1198 power_apd += v[i]*(fBiasControlVoltageVec[i]-R[g]*v[i]*1e-6)*1e-6;1199 }1200 1201 // Divide by number of summed channels, convert to mW1202 power_apd /= 317e-3; // [mW]1203 1204 if (power_tot<1e-3)1205 power_tot = 0;1206 if (power_apd<1e-3)1207 power_apd = 0;1208 1209 fBiasControlPowerTot = power_tot;1210 1211 // Get the maximum of each patch1212 vector<float> val(320, 0);1213 for (int i=0; i<320; i++)1214 {1215 const int idx = (fPixelMap.hv(i).hw()/9)*2+fPixelMap.hv(i).group();1216 val[idx] = v[i];1217 }1218 1219 // Write the 160 patch values to a file1220 WriteCam(d, "cam-biascontrol-current", val, 100);1221 1222 const Statistics stat(v, 0, 3);1223 1224 // Exclude the three crazy channels1225 fBiasControlCurrentMed = stat.med;1226 fBiasControlCurrentMax = stat.max;1227 1228 // Store a history of the last 60 entries1229 fBiasControlCurrentHist.push_back(fBiasControlCurrentMed);1230 if (fBiasControlCurrentHist.size()>360)1231 fBiasControlCurrentHist.pop_front();1232 1233 // write the history to a file1234 WriteHist(d, "hist-biascontrol-current", fBiasControlCurrentHist, 100);1235 1236 const string col0 = cal ? HTML::kGreen : HTML::kWhite;1237 1238 string col1 = col0;1239 string col2 = col0;1240 string col3 = col0;1241 string col4 = col0;1242 1243 if (cal && stat.min>65)1244 col1 = kYellow;1245 if (cal && stat.min>80)1246 col1 = kRed;1247 1248 if (cal && stat.med>65)1249 col2 = kYellow;1250 if (cal && stat.med>80)1251 col2 = kRed;1252 1253 if (cal && stat.avg>65)1254 col3 = kYellow;1255 if (cal && stat.avg>80)1256 col3 = kRed;1257 1258 if (cal && stat.max>65)1259 col4 = kYellow;1260 if (cal && stat.max>80)1261 col4 = kRed;1262 1263 ostringstream out;1264 out << setprecision(2);1265 out << d.GetJavaDate() << '\n';1266 out << col0 << '\t' << (cal?"yes":"no") << '\n';1267 out << col1 << '\t' << stat.min << '\n';1268 out << col2 << '\t' << stat.med << '\n';1269 out << col3 << '\t' << stat.avg << '\n';1270 out << col4 << '\t' << stat.max << '\n';1271 out << HTML::kWhite << '\t' << power_tot << "W [" << power_apd << "mW]\n";1272 ofstream(fPath+"/current.data") << out.str();1273 1303 1274 1304 return GetCurrentState(); … … 1978 2008 } 1979 2009 1980 pair<vector<float>, pair<Time, float>> GetLightCondition( Nova::EquPosn *src,double jd)2010 pair<vector<float>, pair<Time, float>> GetLightCondition(double jd) 1981 2011 { 1982 2012 jd = floor(jd); … … 2174 2204 ccol++; 2175 2205 2176 /*const*/ pair<vector<float>, pair<Time, float>> lc = GetLightCondition( &pos,now.JD());2206 /*const*/ pair<vector<float>, pair<Time, float>> lc = GetLightCondition(now.JD()); 2177 2207 if (!lc.first.empty()) 2178 2208 { … … 2295 2325 fDimBiasControl.state()==BIAS::State::kVoltageOn; 2296 2326 2327 const bool calibrated = 2328 fDimFeedback.state()>=Feedback::State::kCalibrated; 2329 2297 2330 const bool haderr = !fErrorList.empty(); 2298 2331 … … 2324 2357 2325 2358 2326 newerr |= SetError(bias_on && !fFeedbackCalibration.empty()&& fBiasControlCurrentMed>90,2359 newerr |= SetError(bias_on && calibrated && fBiasControlCurrentMed>90, 2327 2360 "Median current exceeds 90µA/pix"); 2328 newerr |= SetError(bias_on && !fFeedbackCalibration.empty()&& fBiasControlCurrentMax>110,2361 newerr |= SetError(bias_on && calibrated && fBiasControlCurrentMax>110, 2329 2362 "Maximum current exceeds 110µA/pix"); 2330 2363 … … 2351 2384 "Warning timecheck not running"); 2352 2385 2353 newerr |= SetError(fDimFeedback.state()!=Feedback::State::kCalibrating && 2354 fDimBiasControl.state()==BIAS::State::kVoltageOn && 2355 fBiasControlVoltageMed>3 && 2356 fFeedbackCalibration.empty(), 2386 newerr |= SetError(fDimBiasControl.state()==BIAS::State::kVoltageOn && 2387 fDimFeedback.state()<Feedback::State::kCalibrating && 2388 fBiasControlVoltageMed>3, 2357 2389 "Bias voltage switched on, but bias crate not calibrated"); 2358 2390 … … 2697 2729 col = HTML::kRed; 2698 2730 2699 const bool cal = !fFeedbackCalibration.empty();2731 const bool cal = fDimFeedback.state()>=Feedback::State::kCalibrated; 2700 2732 2701 2733 // Feedback is currently calibrating => Blue … … 2756 2788 out << GetStateHtml(fDimFtmControl, FTM::State::kConnected); 2757 2789 out << GetStateHtml(fDimBiasControl, BIAS::State::kConnected); 2758 out << GetStateHtml(fDimFeedback, Feedback::State::kConnected FSC);2790 out << GetStateHtml(fDimFeedback, Feedback::State::kConnected); 2759 2791 out << GetStateHtml(fDimRateControl, RateControl::State::kConnected); 2760 2792 out << GetStateHtml(fDimFscControl, FSC::State::kConnected); … … 2890 2922 (bind(&StateMachineSmartFACT::HandleTngWeatherDust, this, placeholders::_1)); 2891 2923 2892 Subscribe("FEEDBACK/DEVIATION") 2893 (bind(&StateMachineSmartFACT::HandleFeedbackDeviation, this, placeholders::_1)); 2894 Subscribe("FEEDBACK/CALIBRATION") 2895 (bind(&StateMachineSmartFACT::HandleFeedbackCalibration, this, placeholders::_1)); 2924 Subscribe("FEEDBACK/CALIBRATED_CURRENTS") 2925 (bind(&StateMachineSmartFACT::HandleFeedbackCalibratedCurrents, this, placeholders::_1)); 2896 2926 2897 2927 Subscribe("BIAS_CONTROL/VOLTAGE")
Note:
See TracChangeset
for help on using the changeset viewer.