FACT++  1.0
int StateMachineSmartFACT::HandleFeedbackCalibratedCurrents ( const EventImp d)
inlineprivate

Definition at line 1181 of file smartfact.cc.

References StateMachineSmartFACT::Statistics::avg, PixelMapEntry::count(), EventImp::GetJavaDate(), PixelMapEntry::group(), PixelMap::hv(), PixelMapEntry::hw(), i, HTML::kGreen, HTML::kRed, HTML::kWhite, HTML::kYellow, StateMachineSmartFACT::Statistics::max, StateMachineSmartFACT::Statistics::med, StateMachineSmartFACT::Statistics::min, and EventImp::Ptr().

Referenced by StateMachineSmartFACT().

1182  {
1183  if (!CheckDataSize(d, "Feedback:CalibratedCurrents", (416+1+1+1+1+1+416+1+1)*sizeof(float)+sizeof(uint32_t)))
1184  return GetCurrentState();
1185 
1186  const float *ptr = d.Ptr<float>();
1187 
1188  double power_tot = 0;
1189  double power_apd = 0;
1190 
1191  if (fBiasControlVoltageVec.size()>0)
1192  {
1193  // Calibrate the data (subtract offset)
1194  for (int i=0; i<320; i++)
1195  {
1196  // Exclude crazy pixels
1197  if (i==66 || i==191 || i==193)
1198  continue;
1199 
1200  // Group index (0 or 1) of the of the pixel (4 or 5 pixel patch)
1201  const int N = fPixelMap.hv(i).count();
1202 
1203  // Serial resistor of the individual G-APDs
1204  double R5 = 3900/N;
1205 
1206  // This is also valid for the patches with wrong resistors,
1207  // because Iapd is a factor f larger but R a factor f smaller
1208  double Iapd = ptr[i] * 1e-6; // [A]
1209  double Iout = Iapd*N; // [A]
1210 
1211  double UdrpCam = 1000 *Iout; // Voltage seen by everything in Camera
1212  double UdrpApd = (R5+2000)*Iout; // Voltage seen by G-APD
1213 
1214  const double pwrCam = Iout * (fBiasControlVoltageVec[i]-UdrpCam);
1215  const double pwrApd = Iout * (fBiasControlVoltageVec[i]-UdrpApd);
1216 
1217  // Total power participated in the camera at the G-APD
1218  // and the serial resistors (total voltage minus voltage
1219  // drop at resistors in bias crate)
1220  power_tot += pwrCam;
1221 
1222  // Power consumption per G-APD
1223  power_apd += pwrApd;
1224  }
1225  }
1226 
1227  // Divide by number of summed channels, convert to mW
1228  power_apd /= (320-3)*1e-3; // [mW]
1229 
1230  if (power_tot<1e-3)
1231  power_tot = 0;
1232  if (power_apd<1e-3)
1233  power_apd = 0;
1234 
1235  fBiasControlPowerTot = power_tot;
1236 
1237  // --------------------------------------------------------
1238 
1239  // Get the maximum of each patch
1240  vector<float> val(320, 0);
1241  for (int i=0; i<320; i++)
1242  {
1243  const int idx = (fPixelMap.hv(i).hw()/9)*2+fPixelMap.hv(i).group();
1244  val[idx] = ptr[i];
1245  }
1246 
1247  // Write the 160 patch values to a file
1248  WriteCam(d, "cam-biascontrol-current", val, 100);
1249 
1250  // --------------------------------------------------------
1251 
1252  // After being displayed, exclude the patches with
1253  // the crazy pixels from the statsitics
1254 
1255  vector<float> cpy(ptr, ptr+320);
1256  cpy[66] = 0;
1257  cpy[191] = 0;
1258  cpy[193] = 0;
1259  const Statistics stat(cpy);
1260 
1261  // Exclude the three crazy channels
1262  fBiasControlCurrentMed = stat.med;
1263  fBiasControlCurrentMax = stat.max;
1264 
1265  // Store a history of the last 60 entries
1267  if (fBiasControlCurrentHist.size()>360)
1268  fBiasControlCurrentHist.pop_front();
1269 
1270  // write the history to a file
1271  WriteHist(d, "hist-biascontrol-current", fBiasControlCurrentHist, 125);
1272 
1273  // --------------------------------------------------------
1274 
1275  string col1 = HTML::kGreen;
1276  string col2 = HTML::kGreen;
1277  string col3 = HTML::kGreen;
1278  string col4 = HTML::kGreen;
1279 
1280  if (stat.min>90)
1281  col1 = HTML::kYellow;
1282  if (stat.min>110)
1283  col1 = HTML::kRed;
1284 
1285  if (stat.med>90)
1286  col2 = HTML::kYellow;
1287  if (stat.med>110)
1288  col2 = HTML::kRed;
1289 
1290  if (stat.avg>90)
1291  col3 = HTML::kYellow;
1292  if (stat.avg>110)
1293  col3 = HTML::kRed;
1294 
1295  if (stat.max>90)
1296  col4 = HTML::kYellow;
1297  if (stat.max>110)
1298  col4 = HTML::kRed;
1299 
1300  ostringstream out;
1301  out << setprecision(3);
1302  out << d.GetJavaDate() << '\n';
1303  out << HTML::kGreen << '\t' << "yes" << '\n';
1304  out << col1 << '\t' << stat.min << '\n';
1305  out << col2 << '\t' << stat.med << '\n';
1306  out << col3 << '\t' << stat.avg << '\n';
1307  out << col4 << '\t' << stat.max << '\n';
1308  out << HTML::kWhite << '\t' << power_tot << "W [" << power_apd << "mW]\n";
1309  ofstream(fPath+"/current.data") << out.str();
1310 
1311  // --------------------------------------------------------
1312 
1313  const float Unom = ptr[2*416+6];
1314  const float Utmp = ptr[2*416+7];
1315 
1316  vector<float> Uov(ptr+416+6, ptr+416+6+320);
1317 
1318  WriteCam(d, "cam-feedback-overvoltage", Uov, 0.2, -0.1);
1319 
1320  const Statistics stat2(Uov);
1321 
1322  out.str("");
1323  out << d.GetJavaDate() << '\n';
1324  out << setprecision(3);
1325  out << HTML::kWhite << '\t' << Utmp << '\n';
1326  out << HTML::kWhite << '\t' << Unom << '\n';
1327  out << HTML::kWhite << '\t' << stat2.min << '\n';
1328  out << HTML::kWhite << '\t' << stat2.med << '\n';
1329  out << HTML::kWhite << '\t' << stat2.avg << '\n';
1330  out << HTML::kWhite << '\t' << stat2.max << '\n';
1331  ofstream(fPath+"/feedback.data") << out.str();
1332 
1333  return GetCurrentState();
1334  }
int GetCurrentState() const
return the current state of the machine
static const string kYellow
Definition: smartfact.cc:75
bool CheckDataSize(const EventImp &d, const char *name, size_t size, bool min=false)
Definition: smartfact.cc:669
int i
Definition: db_dim_client.c:21
int group() const
Definition: PixelMap.h:40
deque< float > fBiasControlCurrentHist
Definition: smartfact.cc:552
void WriteHist(const EventImp &d, const string &fname, const T &t, double scale, double offset=0)
Definition: smartfact.cc:752
int count() const
Definition: PixelMap.h:41
vector< float > fBiasControlVoltageVec
Definition: smartfact.cc:545
static const string kWhite
Definition: smartfact.cc:74
uint64_t GetJavaDate() const
Definition: EventImp.cc:303
static const string kGreen
Definition: smartfact.cc:77
int hw() const
Definition: PixelMap.h:39
static const string kRed
Definition: smartfact.cc:76
void WriteCam(const EventImp &d, const string &fname, const T &t, double scale, double offset=0)
Definition: smartfact.cc:758
const T * Ptr(size_t offset=0) const
Definition: EventImp.h:74
const PixelMapEntry & hv(int board, int channel) const
Definition: PixelMap.h:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function: