pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestHighRate.cc
1 
2 #include <stdlib.h> /* atof, atoi,itoa */
3 #include <algorithm> // std::find
4 #include <iostream>
5 #include <fstream>
6 
7 #include "PixTestHighRate.hh"
8 #include "log.h"
9 #include "TStopwatch.h"
10 
11 #include "PixUtil.hh"
12 
13 
14 #include <TH2.h>
15 #include <TMath.h>
16 
17 using namespace std;
18 using namespace pxar;
19 
20 ClassImp(PixTestHighRate)
21 
22 // ----------------------------------------------------------------------
23 PixTestHighRate::PixTestHighRate(PixSetup *a, std::string name) : PixTest(a, name),
24  fParTriggerFrequency(0), fParRunSeconds(0), fParTriggerDelay(20),
25  fParFillTree(false), fParDelayTBM(false), fParNtrig(5), fParVcal(200),
26  fParMaskFileName("default"), fParSaveMaskedPixels(0) {
27  PixTest::init();
28  init();
29  LOG(logDEBUG) << "PixTestHighRate ctor(PixSetup &a, string, TGTab *)";
30 
31  fTree = 0;
32  fPhCal.setPHParameters(fPixSetup->getConfigParameters()->getGainPedestalParameters());
33  fPhCalOK = fPhCal.initialized();
34 }
35 
36 
37 //----------------------------------------------------------
38 PixTestHighRate::PixTestHighRate() : PixTest() {
39  LOG(logDEBUG) << "PixTestHighRate ctor()";
40  fTree = 0;
41 }
42 
43 
44 // ----------------------------------------------------------------------
45 bool PixTestHighRate::setParameter(string parName, string sval) {
46  bool found(false);
47  string str1, str2;
48  string::size_type s1;
49  int pixc, pixr;
50  std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
51  for (unsigned int i = 0; i < fParameters.size(); ++i) {
52  if (fParameters[i].first == parName) {
53  found = true;
54  if (!parName.compare("savemaskfile")) {
55  PixUtil::replaceAll(sval, "checkbox(", "");
56  PixUtil::replaceAll(sval, ")", "");
57  fParSaveMaskedPixels = !(atoi(sval.c_str())==0);
58  setToolTips();
59  }
60  if (!parName.compare("maskfilename")) {
61  fParMaskFileName = sval;
62  setToolTips();
63  }
64  if (!parName.compare("trgfrequency(khz)")) {
65  fParTriggerFrequency = atoi(sval.c_str());
66  LOG(logDEBUG) << " setting fParTriggerFrequency -> " << fParTriggerFrequency;
67  setToolTips();
68  }
69  if (!parName.compare("runseconds")) {
70  fParRunSeconds = atoi(sval.c_str());
71  setToolTips();
72  }
73  if (!parName.compare("triggerdelay")) {
74  fParTriggerDelay = atoi(sval.c_str());
75  setToolTips();
76  }
77  if (!parName.compare("delaytbm")) {
78  PixUtil::replaceAll(sval, "checkbox(", "");
79  PixUtil::replaceAll(sval, ")", "");
80  fParDelayTBM = !(atoi(sval.c_str())==0);
81  setToolTips();
82  }
83  if (!parName.compare("filltree")) {
84  PixUtil::replaceAll(sval, "checkbox(", "");
85  PixUtil::replaceAll(sval, ")", "");
86  fParFillTree = !(atoi(sval.c_str())==0);
87  setToolTips();
88  }
89  if (!parName.compare("ntrig")) {
90  fParNtrig = static_cast<uint16_t>(atoi(sval.c_str()));
91  setToolTips();
92  }
93  if (!parName.compare("vcal")) {
94  fParVcal = atoi(sval.c_str());
95  setToolTips();
96  }
97  if (!parName.compare("pix") || !parName.compare("pix1") ) {
98  s1 = sval.find(",");
99  if (string::npos != s1) {
100  str1 = sval.substr(0, s1);
101  pixc = atoi(str1.c_str());
102  str2 = sval.substr(s1+1);
103  pixr = atoi(str2.c_str());
105  fPIX.push_back( make_pair(pixc, pixr) );
106  addSelectedPixels(sval);
107  } else {
109  addSelectedPixels("-1,-1");
110  LOG(logDEBUG) << " clear fPIX: " << fPIX.size();
111  }
112  }
113  break;
114  }
115  }
116  return found;
117 }
118 
119 
120 
121 
122 // ----------------------------------------------------------------------
123 void PixTestHighRate::runCommand(std::string command) {
124  std::transform(command.begin(), command.end(), command.begin(), ::tolower);
125  LOG(logDEBUG) << "running command: " << command;
126 
127  if (!command.compare("stop")){
128  doStop();
129  }
130 
131  if (!command.compare("maskhotpixels")) {
132  doRunMaskHotPixels();
133  return;
134  }
135 
136  if (!command.compare("rundaq")) {
137  doRunDaq();
138  return;
139  }
140 
141  if (!command.compare("xpixelalive")) {
142  doXPixelAlive();
143  return;
144  }
145 
146  if (!command.compare("caldelscan")) {
147  doCalDelScan();
148  return;
149  }
150 
151  LOG(logDEBUG) << "did not find command ->" << command << "<-";
152 }
153 
154 // ----------------------------------------------------------------------
155 void PixTestHighRate::init() {
156  LOG(logDEBUG) << "PixTestHighRate::init()";
157  setToolTips();
158  fDirectory = gFile->GetDirectory(fName.c_str());
159  if (!fDirectory) {
160  fDirectory = gFile->mkdir(fName.c_str());
161  }
162  fDirectory->cd();
163 
164 }
165 
166 // ----------------------------------------------------------------------
168  fTestTip = string("Xray vcal calibration test")
169  ;
170  fSummaryTip = string("to be implemented")
171  ;
172  fStopTip = string("Stop 'rundaq' and save data.")
173  ;
174 }
175 
176 
177 // ----------------------------------------------------------------------
178 void PixTestHighRate::bookHist(string name) {
179  fDirectory->cd();
180  if (fParFillTree) bookTree();
181 
182  vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
183  unsigned nrocs = rocIds.size();
184 
185  //-- Sets up the histogram
186  TH2D *h2(0);
187  for (unsigned int iroc = 0; iroc < nrocs; ++iroc){
188  h2 = bookTH2D(Form("hitMap_%s_C%d", name.c_str(), rocIds[iroc]), Form("hitMap_%s_C%d", name.c_str(), rocIds[iroc]),
189  52, 0., 52., 80, 0., 80.);
190  h2->SetMinimum(0.);
191  h2->SetDirectory(fDirectory);
192  fHistOptions.insert(make_pair(h2,"colz"));
193  fHitMap.push_back(h2);
194  }
195 
196  copy(fHitMap.begin(), fHitMap.end(), back_inserter(fHistList));
197 
198 }
199 
200 
201 //----------------------------------------------------------
202 PixTestHighRate::~PixTestHighRate() {
203  LOG(logDEBUG) << "PixTestHighRate dtor";
204  fDirectory->cd();
205  if (fTree && fParFillTree) fTree->Write();
206 }
207 
208 
209 // ----------------------------------------------------------------------
211  bigBanner(Form("PixTestHighRate::doTest()"));
212  doRunMaskHotPixels();
213  doCalDelScan();
214  doXPixelAlive();
215  doRunDaq();
216  LOG(logINFO) << "PixTestHighRate::doTest() done ";
217 }
218 
219 // ----------------------------------------------------------------------
220 void PixTestHighRate::doCalDelScan() {
221 
222  uint16_t FLAGS = FLAG_FORCE_MASKED;
223 
224  int ntrig(10);
225  banner(Form("PixTestHighRate::calDelScan() ntrig = %d, vcal = %d", ntrig, fParVcal));
226  cacheDacs();
227 
228  fDirectory->cd();
229  PixTest::update();
230 
231  fApi->setDAC("vcal", fParVcal);
232 
233  // -- do local short 1D caldel scan
234  // --------------------------------
235  int ip = 0;
236  fApi->_dut->testAllPixels(false);
237  fApi->_dut->maskAllPixels(true);
238  fApi->_dut->testPixel(fPIX[ip].first, fPIX[ip].second, true);
239  fApi->_dut->maskPixel(fPIX[ip].first, fPIX[ip].second, false);
240 
241  bool done = false;
242  vector<pair<uint8_t, vector<pixel> > > results;
243  while (!done) {
244  results.clear();
245  int cnt(0);
246  try{
247  results = fApi->getEfficiencyVsDAC("caldel", 0, 255, FLAGS, 3);
248  done = true;
249  } catch(DataMissingEvent &e){
250  LOG(logCRITICAL) << "problem with readout: "<< e.what() << " missing " << e.numberMissing << " events";
251  ++cnt;
252  if (e.numberMissing > 10) done = true;
253  } catch(pxarException &e) {
254  LOG(logCRITICAL) << "pXar execption: "<< e.what();
255  ++cnt;
256  }
257  done = (cnt>5) || done;
258  }
259  fApi->_dut->testPixel(fPIX[ip].first, fPIX[ip].second, false);
260  fApi->_dut->maskPixel(fPIX[ip].first, fPIX[ip].second, true);
261  fApi->_dut->testAllPixels(true);
262  fApi->_dut->maskAllPixels(false);
263 
264 
265  vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
266  TH1D *h1(0);
267  vector<TH1D*> maps;
268  for (unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
269  h1 = bookTH1D(Form("hrCalDelScan_C%d", rocIds[iroc]), Form("hrCalDelScan_C%d", rocIds[iroc]), 256, 0., 256.);
270  h1->SetMinimum(0.);
271  h1->SetDirectory(fDirectory);
272  fHistList.push_back(h1);
273  maps.push_back(h1);
274  }
275 
276  int idx(-1);
277  for (unsigned int i = 0; i < results.size(); ++i) {
278  int caldel = results[i].first;
279  vector<pixel> pixels = results[i].second;
280  for (unsigned int ipix = 0; ipix < pixels.size(); ++ipix) {
281  idx = getIdxFromId(pixels[ipix].roc());
282  h1 = maps[idx];
283  if (h1) {
284  h1->Fill(caldel, pixels[ipix].value());
285  } else {
286  LOG(logDEBUG) << "no histogram found for ROC " << pixels[ipix].roc() << " with index " << idx;
287  }
288  }
289  }
290 
291  vector<int> calDelLo(rocIds.size(), -1);
292  vector<int> calDelHi(rocIds.size(), -1);
293  int DeltaCalDelMax(-1), reserve(1);
294  for (unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
295  double cdMax = maps[iroc]->GetMaximum();
296  calDelLo[iroc] = static_cast<int>(maps[iroc]->GetBinLowEdge(maps[iroc]->FindFirstBinAbove(0.8*cdMax) + reserve));
297  calDelHi[iroc] = static_cast<int>(maps[iroc]->GetBinLowEdge(maps[iroc]->FindLastBinAbove(0.8*cdMax) - reserve));
298  if (calDelHi[iroc] - calDelLo[iroc] > DeltaCalDelMax) {
299  DeltaCalDelMax = calDelHi[iroc] - calDelLo[iroc];
300  }
301  }
302 
303 
304  // -- now to xEfficiencyMap vs CalDel
305  // ----------------------------------
306  for (unsigned int i = 0; i < fHotPixels.size(); ++i) {
307  vector<pair<int, int> > hot = fHotPixels[i];
308  for (unsigned int ipix = 0; ipix < hot.size(); ++ipix) {
309  LOG(logINFO) << "ROC " << getIdFromIdx(i) << " masking hot pixel " << hot[ipix].first << "/" << hot[ipix].second;
310  fApi->_dut->maskPixel(hot[ipix].first, hot[ipix].second, true, getIdFromIdx(i));
311  }
312  }
313  maskPixels();
314 
315  // -- pattern generator setup without resets
316  resetROC();
317  fPg_setup.clear();
318  vector<pair<string, uint8_t> > pgtmp = fPixSetup->getConfigParameters()->getTbPgSettings();
319  for (unsigned i = 0; i < pgtmp.size(); ++i) {
320  if (string::npos != pgtmp[i].first.find("resetroc")) continue;
321  if (string::npos != pgtmp[i].first.find("resettbm")) continue;
322  fPg_setup.push_back(pgtmp[i]);
323  }
324  if (0) for (unsigned int i = 0; i < fPg_setup.size(); ++i) cout << fPg_setup[i].first << ": " << (int)fPg_setup[i].second << endl;
325 
326  fApi->setPatternGenerator(fPg_setup);
327 
328 
329  vector<pair<int, double> > calDelMax(rocIds.size(), make_pair(-1, -1)); // (CalDel,meanEff)
330  vector<TH1D*> calDelEffHist;
331  for (unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
332  h1 = bookTH1D(Form("HR_CalDelScan_eff_C%d", getIdFromIdx(iroc)),
333  Form("HR_CalDelScan_eff_C%d", getIdFromIdx(iroc)), 256, 0., 256);
334  calDelEffHist.push_back(h1);
335  }
336 
337  int nsteps(20);
338  for (int istep = 0; istep < nsteps; ++istep) {
339  // -- set CalDel per ROC
340  for (unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
341  int caldel = calDelLo[iroc] + istep*(calDelHi[iroc]-calDelLo[iroc])/(nsteps-1);
342  fApi->setDAC("CalDel", caldel, rocIds[iroc]);
343  }
344 
345 
346  pair<vector<TH2D*>,vector<TH2D*> > tests = xEfficiencyMaps(Form("HR_xeff_CalDelScan_step%d", istep),
347  ntrig, FLAG_CHECK_ORDER | FLAG_FORCE_UNMASKED);
348  vector<TH2D*> test2 = tests.first;
349  for (unsigned int iroc = 0; iroc < test2.size(); ++iroc) {
350  fHistOptions.insert(make_pair(test2[iroc], "colz"));
351  h1 = bookTH1D(Form("HR_CalDelScan_step%d_C%d", istep, getIdFromIdx(iroc)),
352  Form("HR_CalDelScan_step%d_C%d", istep, getIdFromIdx(iroc)), 201, 0., 1.005);
353  fHistList.push_back(h1);
354  for (int ix = 0; ix < test2[iroc]->GetNbinsX(); ++ix) {
355  for (int iy = 0; iy < test2[iroc]->GetNbinsY(); ++iy) {
356  h1->Fill(test2[iroc]->GetBinContent(ix+1, iy+1)/ntrig);
357  }
358  }
359  int caldel = fApi->_dut->getDAC(rocIds[iroc], "CalDel");
360  calDelEffHist[iroc]->SetBinContent(caldel, h1->GetMean());
361 
362  if (h1->GetMean() > calDelMax[iroc].second) {
363  calDelMax[iroc].first = caldel;
364  calDelMax[iroc].second = h1->GetMean();
365  }
366  }
367 
368  for (unsigned int i = 0; i < tests.first.size(); ++i) {
369  delete tests.first[i];
370  delete tests.second[i];
371  }
372  tests.first.clear();
373  tests.second.clear();
374  }
375 
376  restoreDacs();
377  for (unsigned int i = 0; i < calDelMax.size(); ++i) {
378  LOG(logDEBUG) << "roc " << Form("%2d", i) << ": caldel = " << calDelMax[i].first << " eff = " << calDelMax[i].second;
379  fApi->setDAC("CalDel", calDelMax[i].first, rocIds[i]);
380  }
381 
382  copy(calDelEffHist.begin(), calDelEffHist.end(), back_inserter(fHistList));
383 
384  calDelEffHist[0]->Draw();
385  fDisplayedHist = find(fHistList.begin(), fHistList.end(), calDelEffHist[0]);
386  PixTest::update();
387 
388 
389 }
390 
391 
392 // ----------------------------------------------------------------------
393 void PixTestHighRate::doXPixelAlive() {
394 
395  banner(Form("PixTestHighRate::xPixelAlive() ntrig = %d, vcal = %d", fParNtrig, fParVcal));
396  cacheDacs();
397 
398 
399  // -- cache triggerdelay
400  vector<pair<string, uint8_t> > oldDelays = fPixSetup->getConfigParameters()->getTbSigDelays();
401  bool foundIt(false);
402  for (unsigned int i = 0; i < oldDelays.size(); ++i) {
403  if (oldDelays[i].first == "triggerdelay") {
404  foundIt = true;
405  }
406  LOG(logDEBUG) << " old set: " << oldDelays[i].first << ": " << (int)oldDelays[i].second;
407  }
408 
409  vector<pair<string, uint8_t> > delays = fPixSetup->getConfigParameters()->getTbSigDelays();
410  if (!foundIt) {
411  delays.push_back(make_pair("triggerdelay", fParTriggerDelay));
412  oldDelays.push_back(make_pair("triggerdelay", 0));
413  } else {
414  for (unsigned int i = 0; i < delays.size(); ++i) {
415  if (delays[i].first == "triggerdelay") {
416  delays[i].second = fParTriggerDelay;
417  }
418  }
419  }
420 
421  for (unsigned int i = 0; i < delays.size(); ++i) {
422  LOG(logDEBUG) << " setting: " << delays[i].first << ": " << (int)delays[i].second;
423  }
424  fApi->setTestboardDelays(delays);
425 
426 
427  fDirectory->cd();
428  PixTest::update();
429 
430  fApi->setDAC("vcal", fParVcal);
431 
432  fApi->_dut->testAllPixels(true);
433  fApi->_dut->maskAllPixels(false);
434  for (unsigned int i = 0; i < fHotPixels.size(); ++i) {
435  vector<pair<int, int> > hot = fHotPixels[i];
436  for (unsigned int ipix = 0; ipix < hot.size(); ++ipix) {
437  LOG(logINFO) << "ROC " << getIdFromIdx(i) << " masking hot pixel " << hot[ipix].first << "/" << hot[ipix].second;
438  fApi->_dut->maskPixel(hot[ipix].first, hot[ipix].second, true, getIdFromIdx(i));
439  }
440  }
441  maskPixels();
442 
443  // -- pattern generator setup without resets
444  resetROC();
445  fPg_setup.clear();
446  vector<pair<string, uint8_t> > pgtmp = fPixSetup->getConfigParameters()->getTbPgSettings();
447  for (unsigned i = 0; i < pgtmp.size(); ++i) {
448  if (string::npos != pgtmp[i].first.find("resetroc")) continue;
449  if (string::npos != pgtmp[i].first.find("resettbm")) continue;
450  fPg_setup.push_back(pgtmp[i]);
451  }
452  if (0) for (unsigned int i = 0; i < fPg_setup.size(); ++i) cout << fPg_setup[i].first << ": " << (int)fPg_setup[i].second << endl;
453 
454  fApi->setPatternGenerator(fPg_setup);
455 
456 
457 
458  pair<vector<TH2D*>,vector<TH2D*> > tests = xEfficiencyMaps("highRate", fParNtrig, FLAG_CHECK_ORDER | FLAG_FORCE_UNMASKED);
459  vector<TH2D*> test2 = tests.first;
460  vector<TH2D*> test3 = tests.second;
461  vector<int> deadPixel(test2.size(), 0);
462  vector<int> probPixel(test2.size(), 0);
463  vector<int> xHits(test3.size(),0);
464  vector<int> fidHits(test2.size(),0);
465  vector<int> allHits(test2.size(),0);
466  vector<int> fidPixels(test2.size(),0);
467  TH1D *h1(0), *h2(0);
468  for (unsigned int i = 0; i < test2.size(); ++i) {
469  fHistOptions.insert(make_pair(test2[i], "colz"));
470  fHistOptions.insert(make_pair(test3[i], "colz"));
471  h1 = bookTH1D(Form("HR_Overall_Efficiency_C%d", getIdFromIdx(i)), Form("HR_Overall_Efficiency_C%d", getIdFromIdx(i)), 201, 0., 1.005);
472  fHistList.push_back(h1);
473  h2 = bookTH1D(Form("HR_Fiducial_Efficiency_C%d", getIdFromIdx(i)), Form("HR_Fiducial_Efficiency_C%d", getIdFromIdx(i)), 201, 0., 1.005);
474  fHistList.push_back(h2);
475 
476  for (int ix = 0; ix < test2[i]->GetNbinsX(); ++ix) {
477  for (int iy = 0; iy < test2[i]->GetNbinsY(); ++iy) {
478  allHits[i] += static_cast<int>(test2[i]->GetBinContent(ix+1, iy+1));
479  h1->Fill(test2[i]->GetBinContent(ix+1, iy+1)/fParNtrig);
480  if ((ix > 0) && (ix < 51) && (iy < 79) && (test2[i]->GetBinContent(ix+1, iy+1) > 0)) {
481  fidHits[i] += static_cast<int>(test2[i]->GetBinContent(ix+1, iy+1));
482  ++fidPixels[i];
483  h2->Fill(test2[i]->GetBinContent(ix+1, iy+1)/fParNtrig);
484  }
485  // -- count dead pixels
486  if (test2[i]->GetBinContent(ix+1, iy+1) < fParNtrig) {
487  ++probPixel[i];
488  if (test2[i]->GetBinContent(ix+1, iy+1) < 1) {
489  ++deadPixel[i];
490  }
491  }
492  // -- Count X-ray hits detected
493  if (test3[i]->GetBinContent(ix+1,iy+1)>0){
494  xHits[i] += static_cast<int> (test3[i]->GetBinContent(ix+1,iy+1));
495  }
496  }
497  }
498  }
499 
500  copy(test2.begin(), test2.end(), back_inserter(fHistList));
501  copy(test3.begin(), test3.end(), back_inserter(fHistList));
502  TH2D *h = (TH2D*)(fHistList.back());
503  h->Draw(getHistOption(h).c_str());
504  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h);
505  PixTest::update();
506 
507  // -- summary printout
508  // int nrocs = fApi->_dut->getNEnabledRocs();
509  double sensorArea = 0.015 * 0.010 * 54 * 81; // in cm^2, accounting for larger edge pixels (J. Hoss 2014/10/21)
510  string deadPixelString, probPixelString, xHitsString, numTrigsString,
511  fidCalHitsString, allCalHitsString,
512  fidCalEfficiencyString, allCalEfficiencyString,
513  xRayRateString;
514  for (unsigned int i = 0; i < probPixel.size(); ++i) {
515  probPixelString += Form(" %4d", probPixel[i]);
516  deadPixelString += Form(" %4d", deadPixel[i]);
517  xHitsString += Form(" %4d", xHits[i]);
518  allCalHitsString += Form(" %4d", allHits[i]);
519  fidCalHitsString += Form(" %4d", fidHits[i]);
520  int numTrigs = fParNtrig * 4160;
521  numTrigsString += Form(" %4d", numTrigs );
522  fidCalEfficiencyString += Form(" %.1f", fidHits[i]/static_cast<double>(fidPixels[i]*fParNtrig)*100);
523  allCalEfficiencyString += Form(" %.1f", allHits[i]/static_cast<double>(numTrigs)*100);
524  xRayRateString += Form(" %.1f", xHits[i]/static_cast<double>(numTrigs)/25./sensorArea*1000.);
525  }
526 
527  LOG(logINFO) << "number of dead pixels (per ROC): " << deadPixelString;
528  LOG(logINFO) << "number of red-efficiency pixels: " << probPixelString;
529  LOG(logINFO) << "number of X-ray hits detected: " << xHitsString;
530  LOG(logINFO) << "number of triggers sent (total per ROC): " << numTrigsString;
531  LOG(logINFO) << "number of Vcal hits detected: " << allCalHitsString;
532  LOG(logINFO) << "Vcal hit fiducial efficiency (%): " << fidCalEfficiencyString;
533  LOG(logINFO) << "Vcal hit overall efficiency (%): " << allCalEfficiencyString;
534  LOG(logINFO) << "X-ray hit rate [MHz/cm2]: " << xRayRateString;
535  LOG(logINFO) << "PixTestHighRate::doXPixelAlive() done";
536  restoreDacs();
537 
538  // -- reset sig delays
539  fApi->setTestboardDelays(oldDelays);
540  for (unsigned int i = 0; i < oldDelays.size(); ++i) {
541  LOG(logDEBUG) << " resetting: " << oldDelays[i].first << ": " << (int)oldDelays[i].second;
542  }
543 
544  finalCleanup();
545 }
546 
547 
548 // ----------------------------------------------------------------------
549 void PixTestHighRate::doRunDaq() {
550 
551  // -- fill into same(!) histogram when re-running the test
552  vector<TH2D*> v = mapsWithString(fHitMap, "daqbbtest");
553  if (0 == v.size()) {
554  bookHist("daqbbtest");
555  v = mapsWithString(fHitMap, "daqbbtest");
556  }
557 
558  banner(Form("PixTestHighRate::runDaq() running for %d seconds", fParRunSeconds));
559 
560  fDirectory->cd();
561  PixTest::update();
562 
563 
564  // -- unmask entire chip and then mask hot pixels
565  fApi->_dut->testAllPixels(false);
566  fApi->_dut->maskAllPixels(false);
567  for (unsigned int i = 0; i < fHotPixels.size(); ++i) {
568  vector<pair<int, int> > hot = fHotPixels[i];
569  for (unsigned int ipix = 0; ipix < hot.size(); ++ipix) {
570  LOG(logINFO) << "ROC " << getIdFromIdx(i) << " masking hot pixel " << hot[ipix].first << "/" << hot[ipix].second;
571  fApi->_dut->maskPixel(hot[ipix].first, hot[ipix].second, true, getIdFromIdx(i));
572  }
573  }
574  maskPixels();
575 
576  // -- cache triggerdelay
577  vector<pair<string, uint8_t> > oldDelays = fPixSetup->getConfigParameters()->getTbSigDelays();
578  bool foundIt(false);
579  for (unsigned int i = 0; i < oldDelays.size(); ++i) {
580  if (oldDelays[i].first == "triggerdelay") {
581  foundIt = true;
582  }
583  LOG(logDEBUG) << " old set: " << oldDelays[i].first << ": " << (int)oldDelays[i].second;
584  }
585 
586  vector<pair<string, uint8_t> > delays = fPixSetup->getConfigParameters()->getTbSigDelays();
587  if (!foundIt) {
588  delays.push_back(make_pair("triggerdelay", fParTriggerDelay));
589  oldDelays.push_back(make_pair("triggerdelay", 0));
590  } else {
591  for (unsigned int i = 0; i < delays.size(); ++i) {
592  if (delays[i].first == "triggerdelay") {
593  delays[i].second = fParTriggerDelay;
594  }
595  }
596  }
597 
598  for (unsigned int i = 0; i < delays.size(); ++i) {
599  LOG(logDEBUG) << " setting: " << delays[i].first << ": " << (int)delays[i].second;
600  }
601  fApi->setTestboardDelays(delays);
602 
603  // -- take data
604  fDirectory->cd();
605  doHitMap(fParRunSeconds, v);
606 
607  // -- display
608  TH2D *h = (TH2D*)(fHistList.back());
609  h->Draw(getHistOption(h).c_str());
610  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h);
611  PixTest::update();
612 
613  // -- analyze
614  string zPixelString("");
615  for (unsigned int i = 0; i < v.size(); ++i) {
616  int cnt(0);
617  LOG(logDEBUG) << "analyzing " << v[i]->GetName();
618  for (int ix = 0; ix < v[i]->GetNbinsX(); ++ix) {
619  for (int iy = 0; iy < v[i]->GetNbinsY(); ++iy) {
620  if (0 == v[i]->GetBinContent(ix+1, iy+1)) ++cnt;
621  }
622  }
623  zPixelString += Form(" %4d ", cnt);
624  }
625 
626  // -- reset sig delays
627  fApi->setTestboardDelays(oldDelays);
628  for (unsigned int i = 0; i < oldDelays.size(); ++i) {
629  LOG(logDEBUG) << " resetting: " << oldDelays[i].first << ": " << (int)oldDelays[i].second;
630  }
631 
632 
633 
634  LOG(logINFO) << "Pixels without X-ray hits (per ROC): " << zPixelString;
635  LOG(logINFO) << "PixTestHighRate::doRunDaq() done";
636 
637 }
638 
639 
640 
641 // ----------------------------------------------------------------------
642 void PixTestHighRate::doHitMap(int nseconds, vector<TH2D*> h) {
643 
644  int totalPeriod = prepareDaq(fParTriggerFrequency, 50);
645  fApi->daqStart();
646 
647  int finalPeriod = fApi->daqTriggerLoop(totalPeriod);
648  LOG(logINFO) << "PixTestHighRate::doHitMap start TriggerLoop with trigger frequency " << fParTriggerFrequency
649  << " kHz, period " << finalPeriod
650  << " and duration " << nseconds << " seconds";
651 
652  TStopwatch t;
653  uint8_t perFull;
654  fDaq_loop = true;
655  int seconds(0);
656  while (fApi->daqStatus(perFull) && fDaq_loop) {
657  gSystem->ProcessEvents();
658  if (perFull > 80) {
659  seconds = t.RealTime();
660  LOG(logINFO) << "run duration " << seconds << " seconds, buffer almost full ("
661  << (int)perFull << "%), pausing triggers.";
663  fillMap(h);
664  LOG(logINFO) << "Resuming triggers.";
665  t.Start(kFALSE);
666  fApi->daqTriggerLoop(finalPeriod);
667  }
668 
669  seconds = t.RealTime();
670  t.Start(kFALSE);
671  if (static_cast<int>(seconds) >= nseconds) {
672  LOG(logINFO) << "data taking finished, elapsed time: " << seconds << " seconds.";
673  fDaq_loop = false;
674  break;
675  }
676  }
677 
679  fApi->daqStop();
680 
681  fillMap(h);
682  finalCleanup();
683 
684 }
685 
686 // ----------------------------------------------------------------------
687 void PixTestHighRate::fillMap(vector<TH2D*> hist) {
688 
689  int pixCnt(0);
690  vector<pxar::Event> daqdat = fApi->daqGetEventBuffer();
691 
692  for(std::vector<pxar::Event>::iterator it = daqdat.begin(); it != daqdat.end(); ++it) {
693  pixCnt += it->pixels.size();
694 
695  for (unsigned int ipix = 0; ipix < it->pixels.size(); ++ipix) {
696  hist[getIdxFromId(it->pixels[ipix].roc())]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row());
697  }
698  }
699  LOG(logDEBUG) << "Processing Data: " << daqdat.size() << " events with " << pixCnt << " pixels";
700 }
701 
702 
703 // ----------------------------------------------------------------------
704 void PixTestHighRate::doRunMaskHotPixels() {
705  PixTest::update();
706  vector<TH2D*> v = mapsWithString(fHitMap, "hotpixels");
707  if (0 == v.size()) {
708  bookHist("hotpixels");
709  v = mapsWithString(fHitMap, "hotpixels");
710  }
711  for (unsigned int i = 0; i < v.size(); ++i) v[i]->Reset();
712  maskHotPixels(v);
713 
714  if (fParSaveMaskedPixels) {
715  if (fParMaskFileName == "default") {
716  fPixSetup->getConfigParameters()->writeMaskFile(fHotPixels);
717  } else {
718  fPixSetup->getConfigParameters()->writeMaskFile(fHotPixels, fParMaskFileName);
719  }
720  }
721 
722  // -- display
723  fDisplayedHist = find(fHistList.begin(), fHistList.end(), v[0]);
724  v[0]->Draw("colz");
725  PixTest::update();
726  return;
727 }
728 
729 // ----------------------------------------------------------------------
730 void PixTestHighRate::doStop(){
731  // Interrupt the test
732  fDaq_loop = false;
733  LOG(logINFO) << "Stop pressed. Ending test.";
734 }
uint16_t prepareDaq(int triggerFreq, uint8_t trgTkDel)
set up DAQ (including call to setTriggerFrequency)
Definition: PixTest.cc:1799
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
in str, replace all occurences of from to to
Definition: PixUtil.cc:24
void resetROC()
send reset to ROC(s)
Definition: PixTest.cc:1771
void doTest()
function connected to "DoTest" button of PixTab
void setPatternGenerator(std::vector< std::pair< std::string, uint8_t > > pg_setup)
Definition: api.cc:78
bool daqStart()
Definition: api.cc:1139
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
Definition: PixTest.hh:308
void daqTriggerLoopHalt()
Definition: api.cc:1257
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
Definition: api.cc:546
std::string fStopTip
information for this test
Definition: PixTest.hh:300
PixSetup * fPixSetup
all necessary stuff in one place
Definition: PixTest.hh:290
std::vector< std::pair< int, int > > fPIX
range of enabled pixels for time-consuming tests
Definition: PixTest.hh:311
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
std::vector< TH1 * > mapsWithString(std::vector< TH1 * >, std::string name)
return a list of TH* that have 'name' as part to their histogram name
void testPixel(uint8_t column, uint8_t row, bool enable)
Definition: dut.cc:432
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
Definition: PixTest.hh:302
int getIdxFromId(int id)
provide the mapping between ROC index and ID
Definition: PixTest.cc:1124
void maskAllPixels(bool mask, uint8_t rocid)
Definition: dut.cc:481
void maskHotPixels(std::vector< TH2D * >)
determine hot pixels with high occupancy
Definition: PixTest.cc:1837
void setTestboardDelays(std::vector< std::pair< std::string, uint8_t > > sig_delays)
Definition: api.cc:68
void clearSelectedPixels()
clear selected pixel list
Definition: PixTest.cc:498
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
uint16_t daqTriggerLoop(uint16_t period=1000)
Definition: api.cc:1239
std::vector< std::pair< uint8_t, std::vector< pixel > > > getEfficiencyVsDAC(std::string dacName, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
Definition: api.cc:733
void restoreDacs(bool verbose=false)
restore all DACs
Definition: PixTest.cc:771
void bookTree()
book a minimal tree with pixel events
Definition: PixTest.cc:99
dut * _dut
Definition: api.h:728
void addSelectedPixels(std::string sval)
add a selected pixel to the internal parameter list
Definition: PixTest.cc:480
std::vector< uint8_t > getEnabledRocIDs()
Definition: dut.cc:214
void finalCleanup()
functions for DAQ
Definition: PixTest.cc:1765
void testAllPixels(bool enable)
Definition: dut.cc:503
bool daqStop()
Definition: api.cc:1324
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
Definition: PixTest.hh:309
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
TH1D * bookTH1D(std::string sname, std::string title, int nbins, double xmin, double xmax)
book a TH1D, adding version information to the name and title
Definition: PixTest.cc:895
virtual std::string getHistOption(TH1 *)
get the hist display options (if stored in fHistOptions)
Definition: PixTest.cc:941
void cacheDacs(bool verbose=false)
cache all DACs
Definition: PixTest.cc:760
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
Definition: PixTest.hh:307
std::pair< std::vector< TH2D * >, std::vector< TH2D * > > xEfficiencyMaps(std::string name, uint16_t ntrig, uint16_t FLAGS=FLAG_CHECK_ORDER|FLAG_FORCE_UNMASKED)
Return pixelAlive map and additional hit map when running with external source.
Definition: PixTest.cc:1667
TH2D * bookTH2D(std::string sname, std::string title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double max)
book a TH2D, adding version information to the name and title
Definition: PixTest.cc:903
void maskPixel(uint8_t column, uint8_t row, bool mask)
Definition: dut.cc:397
void update()
signal to PixTab to update the canvas
Definition: PixTest.cc:569
uint8_t getDAC(size_t rocId, std::string dacName)
Definition: dut.cc:314
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
std::vector< Event > daqGetEventBuffer()
Definition: api.cc:1285
void runCommand(std::string command)
allow execution of any button in the test
void init()
sets all test parameters
Definition: PixTest.cc:62
void maskPixels()
mask all pixels mentioned in the mask file
Definition: PixTest.cc:1741
bool daqStatus()
Definition: api.cc:1191
int getIdFromIdx(int idx)
provide the mapping between ROC ID and index
Definition: PixTest.cc:1114