11 #include "TVirtualFitter.h"
18 #include "rsstools.hh"
31 fTestParameters = a->getPixTestParameters();
32 fTimeStamp =
new TTimeStamp();
38 fParameters = a->getPixTestParameters()->getTestParameters(name);
45 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
46 for (
unsigned i = 0; i < rocIds.size(); ++i) {
47 id2idx.insert(make_pair(rocIds[i], i));
66 cout <<
"test: " << getName() << endl;
69 for (
unsigned int i = 0; i < fParameters.size(); ++i) {
70 if (verbose) cout <<
"fParameters[" << i <<
"].first = " << fParameters[i].first
71 <<
" fParameters[" << i <<
"].second = " << fParameters[i].second
73 setParameter(fParameters[i].first, fParameters[i].second);
79 string::size_type m1 = name.find(
"::");
80 name = name.substr(m1+2);
86 fTestTip =
"generic tool tip for a test";
87 fSummaryTip =
"generic tool tip for a the summary plot";
94 LOG(logDEBUG) <<
"Nothing done with " << name;
101 fTreeEvent.header = 0;
102 fTreeEvent.trailer = 0;
103 fTreeEvent.numDecoderErrors = 0;
105 for (
int ipix = 0; ipix < 20000; ++ipix) {
106 fTreeEvent.proc[ipix] = 0;
107 fTreeEvent.pcol[ipix] = 0;
108 fTreeEvent.prow[ipix] = 0;
109 fTreeEvent.pval[ipix] = 0.;
110 fTreeEvent.pq[ipix] = 0.;
114 fTree =
new TTree(
"events",
"events");
115 fTree->SetDirectory(fDirectory);
116 fTree->Branch(
"header", &fTreeEvent.header,
"header/s");
117 fTree->Branch(
"trailer", &fTreeEvent.trailer,
"trailer/s");
118 fTree->Branch(
"npix", &fTreeEvent.npix,
"npix/s");
119 fTree->Branch(
"proc", fTreeEvent.proc,
"proc[npix]/b");
120 fTree->Branch(
"pcol", fTreeEvent.pcol,
"pcol[npix]/b");
121 fTree->Branch(
"prow", fTreeEvent.prow,
"prow[npix]/b");
122 fTree->Branch(
"pval", fTreeEvent.pval,
"pval[npix]/D");
123 fTree->Branch(
"pq", fTreeEvent.pq,
"pq[npix]/D");
130 std::transform(command.begin(), command.end(), command.begin(), ::tolower);
131 LOG(logDEBUG) <<
"Nothing done with " << command;
137 fDirectory = gFile->GetDirectory(fName.c_str());
144 uint16_t FLAGS = FLAG_FORCE_MASKED;
145 TH1D *h =
new TH1D(
"h1",
"h1", 256, 0., 256.);
147 vector<pair<uint8_t, vector<pixel> > > results;
151 LOG(logDEBUG) <<
" attempt #" << cnt;
153 results = fApi->getEfficiencyVsDAC(dac, dacmin, dacmax, FLAGS, ntrig);
154 fNDaqErrors = fApi->getStatistics().errors_pixel();
159 done = (cnt>2) || done;
163 for (
unsigned int idac = 0; idac < results.size(); ++idac) {
164 int dacval = results[idac].first;
165 for (
unsigned int ipix = 0; ipix < results[idac].second.size(); ++ipix) {
166 val = results[idac].second[ipix].value();
167 h->Fill(dacval, val);
170 int thr = simpleThreshold(h);
177 vector<TH1*>
PixTest::scurveMaps(
string dac,
string name,
int ntrig,
int dacmin,
int dacmax,
int dacsperstep,
178 int result,
int ihit,
int flag) {
180 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
182 if (2 == ihit) type = string(
"pulseheight");
183 print(Form(
"dac: %s name: %s ntrig: %d dacrange: %d .. %d %s flags = %d (plus default)",
184 dac.c_str(), name.c_str(), ntrig, dacmin, dacmax, type.c_str(), flag));
186 vector<shist256*> maps;
187 vector<TH1*> resultMaps;
195 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc) {
196 for (
unsigned int ic = 0; ic < 52; ++ic) {
197 for (
unsigned int ir = 0; ir < 80; ++ir) {
199 ph = pshistBlock + idx;
205 if (dacsperstep > 0) {
206 int stepsize(dacsperstep);
207 int dacminAdj = dacmin;
208 int dacmaxAdj = dacmin + stepsize - 1;
209 bool finalRun(
false);
210 while (dacmaxAdj <= dacmax) {
211 LOG(logINFO) <<
" dacScan step from " << dacminAdj <<
" .. " << dacmaxAdj;
212 dacScan(dac, ntrig, dacminAdj, dacmaxAdj, maps, ihit, flag);
214 dacminAdj = dacminAdj + stepsize;
215 dacmaxAdj = dacminAdj + stepsize - 1;
216 if (dacmaxAdj >= dacmax) {
222 dacScan(dac, ntrig, dacmin, dacmax, maps, ihit, flag);
226 if (fNDaqErrors > 666000)
return resultMaps;
228 scurveAna(dac, name, maps, resultMaps, result);
231 LOG(logDEBUG) <<
"PixTest::scurveMaps end: getCurrentRSS() = " << rss.
getCurrentRSS();
241 vector<pixel> results;
246 LOG(logDEBUG) <<
" attempt #" << cnt;
248 results = fApi->getPulseheightMap(FLAGS, ntrig);
249 fNDaqErrors = fApi->getStatistics().errors_pixel();
252 fNDaqErrors = 666667;
255 done = (cnt>2) || done;
257 LOG(logDEBUG) <<
" eff result size = " << results.size();
263 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
264 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
265 LOG(logDEBUG) <<
"Create hist " << Form(
"%s_C%d", name.c_str(), rocIds[iroc]);
266 h2 = bookTH2D(Form(
"%s_C%d", name.c_str(), rocIds[iroc]), Form(
"%s_C%d", name.c_str(), rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
268 h2->SetDirectory(fDirectory);
269 fHistOptions.insert(make_pair(h2,
"colz"));
270 setTitles(h2,
"col",
"row");
275 for (
unsigned int i = 0; i < results.size(); ++i) {
276 idx = getIdxFromId(results[i].roc());
277 if (rocIds.end() != find(rocIds.begin(), rocIds.end(), results[i].roc())) {
279 if (h2->GetBinContent(results[i].column()+1, results[i].row()+1) > 0) {
280 LOG(logDEBUG) <<
"ROC/col/row = " << int(results[i].roc()) <<
"/" << int(results[i].column()) <<
"/" << int(results[i].row())
281 <<
" with = " << h2->GetBinContent(results[i].column()+1, results[i].row()+1)
282 <<
" now adding " <<
static_cast<float>(results[i].value());
284 h2->Fill(results[i].column(), results[i].row(), static_cast<float>(results[i].value()));
286 LOG(logDEBUG) <<
"histogram for ROC " << (int)results[i].roc() <<
" not found";
297 vector<pixel> results;
302 LOG(logDEBUG) <<
" attempt #" << cnt;
304 results = fApi->getEfficiencyMap(FLAGS, ntrig);
305 fNDaqErrors = fApi->getStatistics().errors_pixel();
308 fNDaqErrors = 666667;
311 done = (cnt>5) || done;
313 LOG(logDEBUG) <<
" eff result size = " << results.size();
319 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
320 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
321 LOG(logDEBUG) <<
"Create hist " << Form(
"%s_C%d", name.c_str(), rocIds[iroc]);
322 h2 = bookTH2D(Form(
"%s_C%d", name.c_str(), rocIds[iroc]), Form(
"%s_C%d", name.c_str(), rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
324 h2->SetDirectory(fDirectory);
325 fHistOptions.insert(make_pair(h2,
"colz"));
326 setTitles(h2,
"col",
"row");
331 for (
unsigned int i = 0; i < results.size(); ++i) {
332 idx = getIdxFromId(results[i].roc());
334 if (rocIds.end() != find(rocIds.begin(), rocIds.end(), results[i].roc())) {
336 if (h2->GetBinContent(results[i].column()+1, results[i].row()+1) > 0) {
337 LOG(logDEBUG) <<
"ROC/col/row = " << int(results[i].roc()) <<
"/" << int(results[i].column()) <<
"/" << int(results[i].row())
338 <<
" with = " << h2->GetBinContent(results[i].column()+1, results[i].row()+1)
339 <<
" now adding " <<
static_cast<float>(results[i].value());
341 h2->Fill(results[i].column(), results[i].row(), static_cast<float>(results[i].value()));
343 LOG(logDEBUG) <<
"histogram for ROC " << (int)results[i].roc() <<
" not found";
353 vector<TH1*>
PixTest::thrMaps(
string dac,
string name,
int ntrig, uint16_t flag) {
354 return thrMaps(dac, name, 1, 0, ntrig, flag);
360 vector<TH1*>
PixTest::thrMaps(
string dac,
string name, uint8_t daclo, uint8_t dachi,
int ntrig, uint16_t flag) {
362 vector<TH1*> resultMaps;
365 LOG(logWARNING) <<
"thrMaps called with dacLo = " << daclo <<
" > dacHi = " << dachi;
369 uint16_t FLAGS = flag | FLAG_RISING_EDGE;
373 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
374 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
375 h1 = bookTH2D(Form(
"thr_%s_%s_C%d", name.c_str(), dac.c_str(), iroc),
376 Form(
"thr_%s_%s_C%d", name.c_str(), dac.c_str(), iroc),
377 52, 0., 52., 80, 0., 80.);
378 resultMaps.push_back(h1);
379 fHistOptions.insert(make_pair(h1,
"colz"));
382 int ic, ir, iroc, val;
383 LOG(logDEBUG) <<
"start threshold map for dac = " << dac;
385 std::vector<pixel> results;
390 LOG(logDEBUG) <<
" attempt #" << cnt;
392 results = fApi->getThresholdMap(dac, 1, daclo, dachi, FLAGS, ntrig);
393 fNDaqErrors = fApi->getStatistics().errors_pixel();
396 fNDaqErrors = 666667;
399 done = (cnt>2) || done;
402 LOG(logDEBUG) <<
"finished threshold map for dac = " << dac <<
" results size = " << results.size();
403 for (
unsigned int ipix = 0; ipix < results.size(); ++ipix) {
404 ic = results[ipix].column();
405 ir = results[ipix].row();
406 iroc = getIdxFromId(results[ipix].roc());
407 val = results[ipix].value();
408 if (rocIds.end() != find(rocIds.begin(), rocIds.end(), results[ipix].roc())) {
409 ((TH2D*)resultMaps[iroc])->Fill(ic, ir, val);
411 LOG(logDEBUG) <<
"histogram for ROC " <<
static_cast<int>(results[ipix].roc()) <<
" not found";
415 for (
unsigned int i = 0; i < rocIds.size(); ++i){
416 TH2D *h2 = (TH2D*)resultMaps[i];
417 TH1* d1 = distribution(h2, 256, 0., 256.);
418 resultMaps.push_back(d1);
421 copy(resultMaps.begin(), resultMaps.end(), back_inserter(fHistList));
422 fDisplayedHist = find(fHistList.begin(), fHistList.end(), h1);
423 if (h1) h1->Draw(getHistOption(h1).c_str());
434 LOG(logDEBUG) <<
" PixTest::setParameter wrong function" << parName <<
" " << value;
441 for (
unsigned int i = 0; i < fParameters.size(); ++i) {
442 if (0 == fParameters[i].first.compare(parName)) {
443 return fParameters[i].second;
446 return string(Form(
"parameter %s not found", parName.c_str()));
453 for (
unsigned int i = 0; i < fParameters.size(); ++i) {
454 if (0 == fParameters[i].first.compare(parName)) {
456 ival = atoi(fParameters[i].first.c_str());
468 for (
unsigned int i = 0; i < fParameters.size(); ++i) {
469 if (0 == fParameters[i].first.compare(parName)) {
471 fval =
static_cast<float>(atof(fParameters[i].first.c_str()));
481 bool reset(
false), alreadyIn(
false);
482 for (
unsigned int i = 0; i < fParameters.size(); ++i) {
483 if (!fParameters[i].first.compare(
"pix") && !fParameters[i].second.compare(
"reset")) {
484 fParameters[i].second = sval;
488 if (!fParameters[i].first.compare(
"pix") && !fParameters[i].second.compare(sval)) {
493 if (!reset && !alreadyIn) fParameters.push_back(make_pair(
"pix", sval));
500 std::vector<std::pair<std::string, std::string> > pnew;
501 for (
unsigned int i = 0; i < fParameters.size(); ++i) {
502 if (0 == fParameters[i].first.compare(
"pix")) {
503 pnew.push_back(make_pair(
"pix",
"reset"));
505 pnew.push_back(make_pair(fParameters[i].first, fParameters[i].second));
516 for (
unsigned int i = 0; i < fParameters.size(); ++i) {
517 if (!fParameters[i].first.compare(parname)) {
518 fParameters[i].second = value;
519 LOG(logDEBUG) <<
" setting " << fParameters[i].first <<
" to new value " << fParameters[i].second;
530 LOG(logINFO) <<
"Parameters for test " << getName() <<
", number of parameters = " << fParameters.size();
532 for (
unsigned int i = 0; i < fParameters.size(); ++i) {
533 LOG(logINFO) << fParameters[i].first <<
": " << fParameters[i].second;
539 PixTest::~PixTest() {
541 std::list<TH1*>::iterator il;
543 for (il = fHistList.begin(); il != fHistList.end(); ++il) {
545 (*il)->SetDirectory(fDirectory);
549 TH1D *h = (TH1D*)gDirectory->Get(
"ha");
551 h->SetDirectory(fDirectory);
555 h = (TH1D*)gDirectory->Get(
"hd");
557 h->SetDirectory(fDirectory);
572 fPixSetup->getPixMonitor()->update();
620 if (fHistList.size() == 0)
return 0;
621 std::list<TH1*>::iterator itmp = fDisplayedHist;
623 if (itmp == fHistList.end()) {
625 fDisplayedHist = fHistList.begin();
626 return (*fDisplayedHist);
629 return (*fDisplayedHist);
635 if (fHistList.size() == 0)
return 0;
636 if (fDisplayedHist == fHistList.begin()) {
638 fDisplayedHist = fHistList.end();
640 return (*fDisplayedHist);
643 return (*fDisplayedHist);
650 float xoff,
float yoff,
float lsize,
int font) {
652 LOG(logDEBUG) <<
" Histogram not defined";
654 h->SetXTitle(sx); h->SetYTitle(sy);
655 if (fPixSetup->useRootLogon()) {
656 h->SetTitleOffset(gStyle->GetTitleOffset(
"X"),
"x"); h->SetTitleOffset(gStyle->GetTitleOffset(
"Y"),
"y");
657 h->SetTitleSize(gStyle->GetTitleSize(
"X"),
"x"); h->SetTitleSize(gStyle->GetTitleSize(
"Y"),
"y");
658 h->SetLabelSize(gStyle->GetLabelSize(
"X"),
"x"); h->SetLabelSize(gStyle->GetLabelSize(
"Y"),
"y");
659 h->SetLabelFont(gStyle->GetLabelFont()); h->SetLabelFont(gStyle->GetLabelFont(),
"y");
660 h->GetXaxis()->SetTitleFont(gStyle->GetTitleFont(
"X")); h->GetYaxis()->SetTitleFont(gStyle->GetTitleFont(
"Y"));
661 h->SetNdivisions(gStyle->GetNdivisions(
"X"),
"X");
663 h->SetTitleOffset(xoff,
"x"); h->SetTitleOffset(yoff,
"y");
664 h->SetTitleSize(size,
"x"); h->SetTitleSize(size,
"y");
665 h->SetLabelSize(lsize,
"x"); h->SetLabelSize(lsize,
"y");
666 h->SetLabelFont(font,
"x"); h->SetLabelFont(font,
"y");
667 h->GetXaxis()->SetTitleFont(font); h->GetYaxis()->SetTitleFont(font);
668 h->SetNdivisions(508,
"X");
675 for (list<TH1*>::iterator il = fHistList.begin(); il != fHistList.end(); ++il) {
686 double plaVal = h->GetMaximum();
687 double thrVal = 0.5*plaVal;
688 for (
int ibin = 1; ibin < h->GetNbinsX(); ++ibin) {
689 if (h->GetBinContent(ibin) >= thrVal) {
690 if (h->GetBinContent(ibin+1) < thrVal)
continue;
691 return static_cast<int>(h->GetBinCenter(ibin));
701 TF1 *f = fPIF->errScurve(h);
706 fThresholdN = h->FindLastBinAbove(0.5*h->GetMaximum());
708 if (fPIF->doNotFit()) {
709 fThreshold = f->GetParameter(0);
715 h->Fit(f,
"qr",
"", lo, hi);
716 fThreshold = f->GetParameter(0);
717 fThresholdE = f->GetParError(0);
718 fSigma = 1./(TMath::Sqrt(2.)/f->GetParameter(1));
719 fSigmaE = fSigma * f->GetParError(1) / f->GetParameter(1);
725 if (fThreshold < h->GetBinLowEdge(1)) {
734 if (fThreshold > h->GetBinLowEdge(h->GetNbinsX())) {
735 fThreshold = h->GetBinLowEdge(h->GetNbinsX());
739 fThresholdN = fThreshold;
749 TH1D *h1 =
new TH1D(Form(
"dist_%s", h2->GetName()), Form(
"dist_%s", h2->GetName()), nbins, xmin, xmax);
750 for (
int ix = 0; ix < h2->GetNbinsX(); ++ix) {
751 for (
int iy = 0; iy < h2->GetNbinsY(); ++iy) {
752 h1->Fill(h2->GetBinContent(ix+1, iy+1));
762 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
763 for (
unsigned i = 0; i < rocIds.size(); ++i) {
764 fDacCache.push_back(fApi->_dut->getDACs(rocIds[i]));
765 if (verbose) fApi->_dut->printDACs(i);
773 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
774 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc) {
775 vector<pair<string, uint8_t> > rocDacs = fDacCache[iroc];
776 for (
unsigned int idac = 0; idac < rocDacs.size(); ++idac) {
777 fApi->setDAC(rocDacs[idac].first, rocDacs[idac].second, rocIds[iroc]);
779 if (verbose) fApi->_dut->printDACs(rocIds[iroc]);
788 LOG(logDEBUG) <<
"moduleMap histname: " << histname;
789 TH1* h0 = (*fDisplayedHist);
790 if (!h0->InheritsFrom(TH2::Class())) {
793 TH2D *h1 = (TH2D*)h0;
794 string h1name = h1->GetName();
795 string::size_type s1 = h1name.rfind(
"_C");
796 string barename = h1name.substr(0, s1);
797 string h2name = barename + string(
"_mod");
798 LOG(logDEBUG) <<
"h1->GetName() = " << h1name <<
" -> " << h2name;
799 TH2D *h2 = bookTH2D(h2name.c_str(), h2name.c_str(), 2*80, 0., 2*80., 8*52, 0., 8*52);
800 fHistOptions.insert(make_pair(h2,
"colz"));
802 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
803 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
804 if (0 == iroc) cycle = -1 + histCycle(Form(
"%s_C%d", barename.c_str(), rocIds[iroc]));
805 TH2D *hroc = (TH2D*)fDirectory->Get(Form(
"%s_C%d_V%d", barename.c_str(), rocIds[iroc], cycle));
806 if (hroc) fillMap(h2, hroc, rocIds[iroc]);
809 fHistList.push_back(h2);
810 fDisplayedHist = find(fHistList.begin(), fHistList.end(), h2);
812 if (h2) h2->Draw(getHistOption(h2).c_str());
819 int mxOffset(iroc<8?159:0), mxDirection(iroc<8?-1:+1);
820 int myOffset(iroc<8?52*(iroc%8):52*(16-iroc)-1), myDirection(iroc<8?1:-1);
823 for (
int rx = 0; rx < hroc->GetNbinsX(); ++rx) {
824 for (
int ry = 0; ry < hroc->GetNbinsY(); ++ry) {
825 mx = mxOffset + mxDirection*ry;
826 my = myOffset + myDirection*rx;
830 hmod->Fill(mx, my, hroc->GetBinContent(rx+1, ry+1));
845 for (
int i = 0; i < npix; ++i) {
846 fApi->_dut->testPixel(5*i, 5*i,
true);
847 fApi->_dut->maskPixel(5*i, 5*i,
false);
850 }
else if (npix < 101) {
851 for (
int i = 0; i < 50; ++i) {
852 fApi->_dut->testPixel(i, 5 + i/2,
true);
853 fApi->_dut->maskPixel(i, 5 + i/2,
false);
855 fApi->_dut->testPixel(i, 15 + i/2,
true);
856 fApi->_dut->maskPixel(i, 15 + i/2,
false);
858 if (cnt == npix)
return;
860 }
else if (npix < 1001) {
861 for (
int i = 0; i < 50; ++i) {
862 for (
int j = 0; j < 10; ++j) {
863 fApi->_dut->testPixel(i, i + 2*j,
true);
864 fApi->_dut->maskPixel(i, i + 2*j,
false);
865 fApi->_dut->testPixel(i, i + 5*j,
true);
866 fApi->_dut->maskPixel(i, i + 5*j,
false);
868 if (cnt == npix)
return;
872 fApi->_dut->testAllPixels(
true);
873 fApi->_dut->maskAllPixels(
false);
880 vector<uint8_t> v = fApi->_dut->getEnabledRocIDs();
881 if (v.end() == find(v.begin(), v.end(), iroc)) {
895 TH1D*
PixTest::bookTH1D(std::string sname, std::string title,
int nbins,
double xmin,
double xmax) {
896 int cnt = histCycle(sname);
898 return new TH1D(Form(
"%s_V%d", sname.c_str(), cnt), Form(
"%s (V%d)", title.c_str(), cnt), nbins, xmin, xmax);
903 TH2D*
PixTest::bookTH2D(std::string sname, std::string title,
int nbinsx,
double xmin,
double xmax,
904 int nbinsy,
double ymin,
double ymax) {
905 int cnt = histCycle(sname);
907 return new TH2D(Form(
"%s_V%d", sname.c_str(), cnt), Form(
"%s (V%d)", title.c_str(), cnt), nbinsx, xmin, xmax, nbinsy, ymin, ymax);
912 int nbinsy,
double ymin,
double ymax,
string option) {
913 int cnt = histCycle(sname);
915 return new TProfile2D(Form(
"%s_V%d", sname.c_str(), cnt), Form(
"%s (V%d)", title.c_str(), cnt),
916 nbinsx, xmin, xmax, nbinsy, ymin, ymax, option.c_str());
924 if (fPixSetup->doRootFileUpdate()) fDirectory->ReadAll();
925 h = (TH1*)fDirectory->FindObject(Form(
"%s_V%d", hname.c_str(), cnt));
932 h = (TH1*)fDirectory->FindObject(Form(
"%s_V%d", hname.c_str(), cnt));
942 map<TH1*, string>::iterator end = fHistOptions.end();
943 for (map<TH1*, string>::iterator pos = fHistOptions.begin();
945 if (h == pos->first)
return pos->second;
958 uint16_t FLAGS = FLAG_FORCE_MASKED;
960 vector<pair<uint8_t, vector<pixel> > > scans;
964 LOG(logDEBUG) <<
" attempt #" << cnt;
966 scans = fApi->getEfficiencyVsDAC(
"vthrcomp", 0, 255, FLAGS, ntrig);
967 fNDaqErrors = fApi->getStatistics().errors_pixel();
970 fNDaqErrors = 666667;
973 done = (cnt>2) || done;
977 LOG(logDEBUG) <<
" getMaximumVthrComp.size(): " << scans.size();
979 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
980 vector<TH1*> scanHists;
983 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
984 h1 = bookTH1D(Form(
"maxVthrComp_C%d", rocIds[iroc]), Form(
"maxVthrComp_C%d", rocIds[iroc]), 255, 0., 255.);
985 scanHists.push_back(h1);
986 npixels.push_back(fApi->_dut->getNEnabledPixels(rocIds[iroc]));
990 for (
unsigned int i = 0; i < scans.size(); ++i) {
991 pair<uint8_t, vector<pixel> > v = scans[i];
994 vector<pixel> vpix = v.second;
995 for (
unsigned int ipix = 0; ipix < vpix.size(); ++ipix) {
996 idx = getIdxFromId(vpix[ipix].roc());
997 if (scanHists[idx]) {
998 scanHists[idx]->Fill(idac, vpix[ipix].value());
1000 LOG(logDEBUG) <<
"histogram for ROC " << vpix[ipix].roc() <<
" not found" << endl;
1005 for (
unsigned int i = 0; i < scanHists.size(); ++i) {
1006 scanHists[i]->Draw();
1008 bool onPlateau(
false);
1010 int plateau = ntrig*npixels[i];
1011 for (idac = 1; idac < 255; ++idac) {
1012 if (scanHists[i]->GetBinContent(idac) > frac*plateau
1013 && scanHists[i]->GetBinContent(idac+1) > frac*plateau
1014 && scanHists[i]->GetBinContent(idac+2) > frac*plateau
1015 && scanHists[i]->GetBinContent(idac+3) > frac*plateau
1025 fHistList.push_back(scanHists[i]);
1026 results.push_back(idac);
1034 vector<int> results;
1037 TH2D *h2(0), *hn(0);
1039 for (
unsigned int i = 0; i < maps.size(); ++i) {
1040 double minThr(999.), thr(0.), minThrN(999.), result(-1.);
1041 h2 = (TH2D*)maps[i];
1042 hname = h2->GetName();
1043 if (string::npos == hname.find(
"thr_"))
continue;
1044 hn = (TH2D*)maps[i+2];
1046 if (strcmp(hname.c_str(), hn->GetName())) {
1047 LOG(logDEBUG) <<
"XXX problem in the ordering of the scurveMaps results ThrN map has name " << hn->GetName();
1050 TH1* d1 = distribution(h2, 256, 0., 256.);
1051 TH1* dn = distribution(hn, 256, 0., 256.);
1052 double minThrLimit = TMath::Max(1., d1->GetMean() - nsigma*d1->GetRMS());
1053 double minThrNLimit = TMath::Max(1., dn->GetMean() - nsigma*dn->GetRMS());
1056 for (
int ic = 0; ic < 52; ++ic) {
1057 for (
int ir = 0; ir < 80; ++ir) {
1058 thr = h2->GetBinContent(ic+1, ir+1);
1059 if (thr < minThr && thr > minThrLimit) {
1063 thr = hn->GetBinContent(ic+1, ir+1);
1064 if (thr < minThrN && thr > minThrNLimit) {
1069 if (minThrN - reserve < minThr) {
1070 result = minThrN - 10;
1071 LOG(logDEBUG) <<
"minThr = " << minThr <<
" minThrN = " << minThrN <<
" -> result = " << result;
1074 LOG(logDEBUG) <<
"minThr = " << minThr <<
" minThrLimit = " << minThrLimit <<
" minThrNLimit = " << minThrNLimit
1075 <<
" -> result = " << result <<
" -> " <<
static_cast<int>(result);
1077 results.push_back(static_cast<int>(result));
1085 double val(0.), result(999.);
1087 for (
unsigned int i = 0; i < maps.size(); ++i) {
1088 h2 = (TH2D*)maps[i];
1089 for (
int ic = 0; ic < h2->GetNbinsX(); ++ic) {
1090 for (
int ir = 0; ir < h2->GetNbinsY(); ++ir) {
1091 val = h2->GetBinContent(ic+1, ir+1);
1092 if (val > 0 && val < result) result = val;
1096 if (result < 0.) result = 0.;
1102 double result(-999.);
1104 for (
unsigned int i = 0; i < maps.size(); ++i) {
1105 h2 = (TH2D*)maps[i];
1106 double maxi = h2->GetMaximum();
1107 if (maxi > result) result = maxi;
1109 if (result > 255.) result = 255.;
1115 map<int, int>::iterator end = fId2Idx.end();
1116 for (map<int, int>::iterator il = fId2Idx.begin(); il != end; ++il) {
1117 if (il->second == idx)
return il->first;
1125 if (fId2Idx.count(
id) > 0) {
1135 vector<TH1*> results;
1137 for (
unsigned i = 0; i < maps.size(); ++i) {
1138 hname = maps[i]->GetName();
1139 if (string::npos != hname.find(name)) results.push_back(maps[i]);
1146 vector<TH2D*> results;
1148 for (
unsigned i = 0; i < maps.size(); ++i) {
1149 hname = maps[i]->GetName();
1150 if (string::npos != hname.find(name)) results.push_back(maps[i]);
1156 void PixTest::fillDacHist(vector<pair<uint8_t, vector<pixel> > > &results, TH1D *h,
int icol,
int irow,
int iroc) {
1158 int ri(-1), ic(-1), ir(-1);
1159 for (
unsigned int idac = 0; idac < results.size(); ++idac) {
1160 int dac = results[idac].first;
1161 for (
unsigned int ipix = 0; ipix < results[idac].second.size(); ++ipix) {
1162 ri = results[idac].second[ipix].roc();
1163 ic = results[idac].second[ipix].column();
1164 ir = results[idac].second[ipix].row();
1165 if (iroc > -1 && ri != iroc)
continue;
1166 if (icol > -1 && ic != icol)
continue;
1167 if (irow > -1 && ir != irow)
continue;
1168 if (ic > 51 || ir > 79)
continue;
1170 h->Fill(dac, results[idac].second[ipix].value());
1177 void PixTest::bigBanner(
string what, TLogLevel log) {
1178 LOG(log) <<
"######################################################################";
1180 LOG(log) <<
"######################################################################";
1184 void PixTest::banner(
string what, TLogLevel log) {
1185 LOG(log) <<
" ----------------------------------------------------------------------";
1186 LOG(log) <<
" " << what;
1187 LOG(log) <<
" ----------------------------------------------------------------------";
1192 LOG(log) <<
"---> " << what;
1199 uint16_t FLAGS = FLAG_FORCE_MASKED;
1201 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
1204 int ntrig(3), cnt(0);
1205 vector<pair<uint8_t, vector<pixel> > > results;
1208 LOG(logDEBUG) <<
" attempt #" << cnt;
1210 results = fApi->getEfficiencyVsDAC(dac, 1, 200, FLAGS, ntrig);
1211 fNDaqErrors = fApi->getStatistics().errors_pixel();
1214 fNDaqErrors = 666667;
1217 done = (cnt>2) || done;
1220 if (666667 == fNDaqErrors) {
1221 LOG(logDEBUG) <<
"fNDaqErrors = " << fNDaqErrors;
1225 int idx(0), roc(0), ic(0), ir(0);
1227 for (
unsigned int idac = 0; idac < results.size(); ++idac) {
1228 int dac = results[idac].first;
1229 for (
unsigned int ipix = 0; ipix < results[idac].second.size(); ++ipix) {
1230 ic = results[idac].second[ipix].column();
1231 ir = results[idac].second[ipix].row();
1232 roc = results[idac].second[ipix].roc();
1233 if (ic > 51 || ir > 79) {
1234 LOG(logDEBUG) <<
"bad pixel address encountered: ROC/col/row = " << roc <<
"/" << ic <<
"/" << ir;
1237 val = results[idac].second[ipix].value();
1239 if (idx > -1) maps[idx]->fill(dac, val);
1246 TH1D *hT =
new TH1D(
"hT",
"hT", 256, 0., 256.); hT->Sumw2();
1247 TH1D *h1 =
new TH1D(
"h1",
"h1", 256, 0., 256.); h1->Sumw2();
1248 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc) {
1249 LOG(logDEBUG) <<
"analyzing ROC " <<
static_cast<int>(rocIds[iroc]);
1250 for (
unsigned int i = iroc*4160; i < (iroc+1)*4160; ++i) {
1251 if (maps[i]->getSumOfWeights() < 1)
continue;
1254 for (
int ib = 1; ib <= 256; ++ib) {
1255 h1->SetBinContent(ib, maps[i]->
get(ib));
1256 h1->SetBinError(ib, ntrig*PixUtil::dBinomial(static_cast<int>(maps[i]->
get(ib)), ntrig));
1260 if (fThreshold > 0) {
1261 hT->Fill(fThreshold);
1281 for (
int i = 1; i < 256; ++i) {
1282 if (hT->Integral(i, i+5) > 5) {
1288 for (
int i = lo; i < 255; ++i) {
1289 if (0 == hT->Integral(i, i+5)) {
1303 fHistList.push_back(hT);
1304 fDisplayedHist = find(fHistList.begin(), fHistList.end(), hT);
1312 void PixTest::dacScan(
string dac,
int ntrig,
int dacmin,
int dacmax, std::vector<shist256*> maps,
int ihit,
int flag) {
1313 uint16_t FLAGS = flag | FLAG_FORCE_MASKED;
1317 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
1323 vector<pair<uint8_t, vector<pixel> > > results;
1326 LOG(logDEBUG) <<
"determine PH error: " << dacmin <<
" .. " << dacmax;
1327 getPhError(dac, dacmin, dacmax, FLAGS, fNtrig);
1331 LOG(logDEBUG) <<
" attempt #" << cnt;
1334 results = fApi->getEfficiencyVsDAC(dac, dacmin, dacmax, FLAGS, fNtrig);
1335 fNDaqErrors = fApi->getStatistics().errors_pixel();
1337 results = fApi->getPulseheightVsDAC(dac, dacmin, dacmax, FLAGS, fNtrig);
1338 fNDaqErrors = fApi->getStatistics().errors_pixel();
1342 fNDaqErrors = 666667;
1345 done = (cnt>2) || done;
1349 for (
unsigned int idac = 0; idac < results.size(); ++idac) {
1350 int dac = results[idac].first;
1351 for (
unsigned int ipix = 0; ipix < results[idac].second.size(); ++ipix) {
1352 ic = results[idac].second[ipix].column();
1353 ir = results[idac].second[ipix].row();
1354 iroc = results[idac].second[ipix].roc();
1355 if (ic > 51 || ir > 79) {
1356 LOG(logDEBUG) <<
"bad pixel address encountered: ROC/col/row = " << iroc <<
"/" << ic <<
"/" << ir;
1359 val = results[idac].second[ipix].value();
1361 if (idx > -1) maps[idx]->fill(dac, val);
1369 void PixTest::scurveAna(
string dac,
string name, vector<shist256*> maps, vector<TH1*> &resultMaps,
int result) {
1371 TH1* h2(0), *h3(0), *h4(0);
1372 string fname(
"SCurveData");
1373 ofstream OutputFile;
1375 string empty(
"32 93 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ");
1376 bool dumpFile(
false);
1377 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
1378 int roc(0), ic(0), ir(0);
1379 TH1D *h1 =
new TH1D(
"h1",
"h1", 256, 0., 256.); h1->Sumw2();
1381 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc) {
1382 LOG(logDEBUG) <<
"analyzing ROC " <<
static_cast<int>(rocIds[iroc]);
1383 h2 = bookTH2D(Form(
"thr_%s_%s_C%d", name.c_str(), dac.c_str(), rocIds[iroc]),
1384 Form(
"thr_%s_%s_C%d", name.c_str(), dac.c_str(), rocIds[iroc]),
1385 52, 0., 52., 80, 0., 80.);
1386 fHistOptions.insert(make_pair(h2,
"colz"));
1388 h3 = bookTH2D(Form(
"sig_%s_%s_C%d", name.c_str(), dac.c_str(), rocIds[iroc]),
1389 Form(
"sig_%s_%s_C%d", name.c_str(), dac.c_str(), rocIds[iroc]),
1390 52, 0., 52., 80, 0., 80.);
1391 fHistOptions.insert(make_pair(h3,
"colz"));
1393 h4 = bookTH2D(Form(
"thn_%s_%s_C%d", name.c_str(), dac.c_str(), rocIds[iroc]),
1394 Form(
"thn_%s_%s_C%d", name.c_str(), dac.c_str(), rocIds[iroc]),
1395 52, 0., 52., 80, 0., 80.);
1396 fHistOptions.insert(make_pair(h4,
"colz"));
1399 std::transform(lname.begin(), lname.end(), lname.begin(), ::tolower);
1400 if (!name.compare(
"scurveVcal") || !lname.compare(
"scurvevcal")) {
1402 OutputFile.open(Form(
"%s/%s_C%d.dat", fPixSetup->getConfigParameters()->getDirectory().c_str(), fname.c_str(), iroc));
1403 OutputFile <<
"Mode 1 " <<
"Ntrig " << fNtrig << endl;
1407 for (
unsigned int i = iroc*4160; i < (iroc+1)*4160; ++i) {
1409 if (maps[i]->getSumOfWeights() < 1) {
1410 if (dumpFile) OutputFile << empty << endl;
1416 for (
int ib = 1; ib <= 256; ++ib) {
1417 h1->SetBinContent(ib, maps[i]->
get(ib));
1418 h1->SetBinError(ib, fNtrig*PixUtil::dBinomial(static_cast<int>(maps[i]->
get(ib)), fNtrig));
1421 bool ok = threshold(h1);
1422 if (((result & 0x10) && !ok) || (result & 0x20)) {
1423 TH1D *h1c = (TH1D*)h1->Clone(Form(
"scurve_%s_c%d_r%d_C%d", dac.c_str(), ic, ir, rocIds[iroc]));
1425 h1c->SetTitle(Form(
"problematic %s scurve (c%d_r%d_C%d), thr = %4.3f", dac.c_str(), ic, ir, rocIds[iroc], fThreshold));
1427 h1c->SetTitle(Form(
"%s scurve (c%d_r%d_C%d), thr = %4.3f", dac.c_str(), ic, ir, rocIds[iroc], fThreshold));
1429 fHistList.push_back(h1c);
1431 h2->SetBinContent(ic+1, ir+1, fThreshold);
1432 h2->SetBinError(ic+1, ir+1, fThresholdE);
1434 h3->SetBinContent(ic+1, ir+1, fSigma);
1435 h3->SetBinError(ic+1, ir+1, fSigmaE);
1437 h4->SetBinContent(ic+1, ir+1, fThresholdN);
1442 int ibin = h1->FindBin(fThreshold);
1443 int bmin = ibin - 15;
1444 line = Form(
"%2d %3d", NSAMPLES, bmin);
1445 for (
int ix = bmin; ix < bmin + NSAMPLES; ++ix) {
1446 line += string(Form(
" %3d", static_cast<int>(h1->GetBinContent(ix+1))));
1448 OutputFile << line << endl;
1451 if (dumpFile) OutputFile.close();
1454 resultMaps.push_back(h2);
1455 fHistList.push_back(h2);
1458 resultMaps.push_back(h3);
1459 fHistList.push_back(h3);
1462 resultMaps.push_back(h4);
1463 fHistList.push_back(h4);
1468 TH1* d1 = distribution((TH2D*)h2, 256, 0., 256.);
1469 resultMaps.push_back(d1);
1470 fHistList.push_back(d1);
1473 TH1* d2 = distribution((TH2D*)h3, 100, 0., 6.);
1474 resultMaps.push_back(d2);
1475 fHistList.push_back(d2);
1478 TH1* d3 = distribution((TH2D*)h4, 256, 0., 256.);
1479 resultMaps.push_back(d3);
1480 fHistList.push_back(d3);
1486 fDisplayedHist = find(fHistList.begin(), fHistList.end(), h2);
1490 if (h2) h2->Draw(
"colz");
1499 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
1500 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
1501 fPhErrP0.push_back(0.05);
1502 fPhErrP1.push_back(0.0);
1512 fPixSetup->writeDacParameterFiles();
1517 fPixSetup->writeTrimFiles();
1523 LOG(logDEBUG) <<
"save Tb parameters";
1524 fPixSetup->getConfigParameters()->writeTbParameterFile();
1529 vector<vector<pair<int, int> > > deadPixels;
1530 vector<pair<int, int> > deadPixelsRoc;
1533 vector<uint8_t> vVcal = getDacs(
"vcal");
1534 vector<uint8_t> vVthrComp = getDacs(
"vthrcomp");
1535 vector<uint8_t> vCreg = getDacs(
"ctrlreg");
1536 vector<uint8_t> vCalDel = getDacs(
"caldel");
1538 fApi->setDAC(
"vcal", 200);
1539 fApi->setDAC(
"ctrlreg", 4);
1540 fApi->setDAC(
"vthrcomp", 50);
1542 fApi->_dut->testAllPixels(
true);
1543 fApi->_dut->maskAllPixels(
false);
1544 vector<TH2D*> testEff;
1548 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
1549 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
1550 TH2D *h2 = bookTH2D(Form(
"dp0_C%d", rocIds[iroc]), Form(
"dp0_C%d", rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
1551 testEff.push_back(h2);
1556 for (
int icaldel = 10; icaldel < 250; icaldel += 30) {
1557 fApi->setDAC(
"caldel", icaldel);
1558 tEff = efficiencyMaps(Form(
"dp_caldel%d", icaldel), ntrig);
1559 for (
int i = 0; i < static_cast<int>(tEff.size()); ++i) {
1560 if (tEff[i]->Integral() > testEff[i]->Integral()) {
1563 testEff[i] = tEff[i];
1572 testEff = efficiencyMaps(
"deadPixels", ntrig);
1575 std::pair<int, int> badPix;
1578 for (
unsigned int i = 0; i < testEff.size(); ++i) {
1579 deadPixelsRoc.clear();
1580 for(
int r=0; r<80; r++){
1581 for(
int c=0; c<52; c++){
1582 eff = testEff[i]->GetBinContent( testEff[i]->FindFixBin((
double)c + 0.5, (
double)r+0.5) );
1584 LOG(logDEBUG) << Form(
"ROC %2d", i) <<
" col/row = " << c <<
"/" << r <<
" with eff " << eff <<
"/" << ntrig <<
"; blacklisting";
1587 deadPixelsRoc.push_back(badPix);
1591 deadPixels.push_back(deadPixelsRoc);
1594 setDacs(
"vcal", vVcal);
1595 setDacs(
"ctrlreg", vCreg);
1596 setDacs(
"caldel", vCalDel);
1597 setDacs(
"vthrcomp", vVthrComp);
1605 vector<uint8_t> result;
1606 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
1607 for (
unsigned int i = 0; i < rocIds.size(); ++i) {
1608 result.push_back(fApi->_dut->getDAC(rocIds[i], dacName));
1615 vector<uint8_t> v = getDacs(dacName);
1617 unsigned int vsize = v.size();
1618 for (
unsigned int i = 0; i < vsize; ++i) {
1619 s << static_cast<int>(v[i]);
1620 if (i < vsize-1) s <<
" ";
1628 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
1629 for (
unsigned int i = 0; i < rocIds.size(); ++i) {
1630 fApi->setDAC(dacName, v[i], rocIds[i]);
1637 vector<pair<int,int> > hotPixels(0);
1639 for (
int ix = 0; ix < h->GetNbinsX(); ++ix) {
1640 for (
int iy = 0; iy < h->GetNbinsY(); ++iy) {
1641 mean += h->GetBinContent(ix+1, iy+1);
1644 mean /= h->GetNbinsX()*h->GetNbinsY();
1648 double hitThr = (mean < 10.?10.:3.*mean);
1649 LOG(logDEBUG) <<
"average number of unexpected hits per pixel: "
1651 <<
" hit threshold: " << hitThr;
1652 for (
int ix = 0; ix < h->GetNbinsX(); ++ix) {
1653 for (
int iy = 0; iy < h->GetNbinsY(); ++iy) {
1654 bc = h->GetBinContent(ix+1, iy+1);
1655 if (bc > hitThr && bc > fos*mean) {
1656 hotPixels.push_back(make_pair(ix,iy));
1657 LOG(logDEBUG) <<
"Found a hot pixel with " << bc <<
" hits "
1658 <<
" and masking Pixel (" << ix <<
',' << iy <<
')';
1669 vector<pixel> results;
1670 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
1674 LOG(logDEBUG) <<
" attempt #" << cnt;
1676 results = fApi->getEfficiencyMap(FLAGS, ntrig);
1677 fNDaqErrors = fApi->getStatistics().errors_pixel();
1680 fNDaqErrors = 666667;
1683 done = (cnt>2) || done;
1688 vector<TH2D*> xMaps;
1690 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
1691 h2 = bookTH2D(Form(
"%s_calmap_C%d", name.c_str(), rocIds[iroc]),
1692 Form(
"%s_calmap_C%d", name.c_str(), rocIds[iroc]),
1693 52, 0., 52., 80, 0., 80.);
1694 fHistOptions.insert(make_pair(h2,
"colz"));
1695 h3 = bookTH2D(Form(
"%s_xraymap_C%d", name.c_str(), rocIds[iroc]),
1696 Form(
"%s_xraymap_C%d", name.c_str(), rocIds[iroc]),
1697 52, 0., 52., 80, 0., 80.);
1698 fHistOptions.insert(make_pair(h3,
"colz"));
1702 h2->SetDirectory(fDirectory);
1703 h3->SetDirectory(fDirectory);
1705 setTitles(h2,
"col",
"row");
1706 setTitles(h3,
"col",
"row");
1709 xMaps.push_back(h3);
1713 for (
unsigned int i = 0; i < results.size(); ++i) {
1714 idx = getIdxFromId(results[i].roc());
1715 if (rocIds.end() != find(rocIds.begin(), rocIds.end(), idx)) {
1718 if (FLAGS | FLAG_CHECK_ORDER) {
1719 if (results[i].value() > 0) {
1720 h2->Fill(results[i].column(), results[i].row(), static_cast<float>(results[i].value()));
1724 h3->Fill(results[i].column(), results[i].row(), 1);
1728 h2->Fill(results[i].column(), results[i].row(), static_cast<float>(results[i].value()));
1732 LOG(logDEBUG) <<
"histogram for ROC " << (int)results[i].roc() <<
" not found";
1735 LOG(logDEBUG) <<
"Size of results from : PixTestHighRate::xEfficiencyMaps: " << results.size();
1736 return make_pair(maps, xMaps);
1742 string mfile = fPixSetup->getConfigParameters()->getDirectory() +
"/" + fPixSetup->getConfigParameters()->getMaskFileName();
1743 vector<vector<pair<int, int> > > vmask = fPixSetup->getConfigParameters()->readMaskFile(mfile);
1745 for (
unsigned int i = 0; i < vmask.size(); ++i) {
1746 vector<pair<int, int> > mask = vmask[i];
1747 for (
unsigned int ipix = 0; ipix < mask.size(); ++ipix) {
1748 LOG(logINFO) <<
"ROC " << getIdFromIdx(i) <<
" masking pixel " << mask[ipix].first <<
"/" << mask[ipix].second;
1749 fApi->_dut->maskPixel(mask[ipix].first, mask[ipix].second,
true, getIdFromIdx(i));
1757 void PixTest::pgToDefault() {
1759 fPg_setup = fPixSetup->getConfigParameters()->getTbPgSettings();
1760 fApi->setPatternGenerator(fPg_setup);
1761 LOG(logINFO) <<
"PixTest:: pg_setup set to default.";
1774 fPg_setup.push_back(make_pair(
"resetroc", 0));
1775 uint16_t period = 28;
1776 fApi->setPatternGenerator(fPg_setup);
1778 fApi->daqTrigger(1, period);
1779 LOG(logINFO) <<
"IGNORE THE WARNING ABOVE (resetROC sent)!";
1788 fPg_setup.push_back(make_pair(
"resettbm", 0));
1789 uint16_t period = 28;
1790 fApi->setPatternGenerator(fPg_setup);
1792 fApi->daqTrigger(1, period);
1793 LOG(logINFO) <<
"IGNORE THE WARNING ABOVE (resetTBM sent)!";
1801 uint16_t totalPeriod = setTriggerFrequency(triggerFreq, trgTkDel);
1802 fApi->setPatternGenerator(fPg_setup);
1810 uint16_t totalPeriod = 0;
1812 double period_ns = 1 / (double)triggerFreq * 1000000;
1813 double clkDelays = period_ns / 25 - trgTkDel;
1814 uint16_t ClkDelays = (uint16_t)clkDelays;
1819 uint16_t i = ClkDelays;
1821 fPg_setup.push_back(make_pair(
"delay", 255));
1825 fPg_setup.push_back(make_pair(
"delay", i));
1828 fPg_setup.push_back(make_pair(
"trg", trgTkDel));
1829 fPg_setup.push_back(make_pair(
"tok", 0));
1830 if (0)
for (
unsigned int i = 0; i < fPg_setup.size(); ++i) cout << fPg_setup[i].first <<
": " << (
int)fPg_setup[i].second << endl;
1832 totalPeriod = ((uint16_t)period_ns / 25) + 4 + nDel;
1842 banner(Form(
"PixTest::maskHotPixels() running for %d seconds with %d kHz trigger rate", NSECONDS, TRGFREQ));
1846 fApi->_dut->testAllPixels(
false);
1847 fApi->_dut->maskAllPixels(
false);
1849 int totalPeriod = prepareDaq(TRGFREQ, (uint8_t)500);
1853 bool daq_loop =
true;
1857 int finalPeriod = fApi->daqTriggerLoop(totalPeriod);
1858 LOG(logINFO) <<
"PixTestHighRate::maskHotPixels start TriggerLoop with period " << finalPeriod
1859 <<
" and duration " << NSECONDS <<
" seconds and trigger rate " << TRGFREQ <<
" kHz";
1861 while (fApi->daqStatus(perFull) && daq_loop) {
1863 LOG(logINFO) <<
"Buffer almost full, pausing triggers.";
1864 fApi->daqTriggerLoopHalt();
1867 vector<pxar::Event> daqdat = fApi->daqGetEventBuffer();
1868 for(std::vector<pxar::Event>::iterator it = daqdat.begin(); it != daqdat.end(); ++it) {
1869 for (
unsigned int ipix = 0; ipix < it->pixels.size(); ++ipix) {
1870 v[getIdxFromId(it->pixels[ipix].roc())]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row());
1874 LOG(logINFO) <<
"Resuming triggers.";
1875 fApi->daqTriggerLoop(finalPeriod);
1878 if (static_cast<int>(t.get()/1000) >= NSECONDS) {
1879 LOG(logINFO) <<
"Done with hot pixel readout";
1885 fApi->daqTriggerLoopHalt();
1889 vector<pxar::Event> daqdat = fApi->daqGetEventBuffer();
1890 for(std::vector<pxar::Event>::iterator it = daqdat.begin(); it != daqdat.end(); ++it) {
1891 for (
unsigned int ipix = 0; ipix < it->pixels.size(); ++ipix) {
1892 v[getIdxFromId(it->pixels[ipix].roc())]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row());
1900 double THR = 1.e-4*NSECONDS*TRGFREQ*1000;
1901 LOG(logDEBUG) <<
"hot pixel determination with THR = " << THR;
1904 for (
unsigned int i = 0; i < v.size(); ++i) {
1906 vector<pair<int, int> > hot;
1907 for (
int ix = 0; ix < h->GetNbinsX(); ++ix) {
1908 for (
int iy = 0; iy < h->GetNbinsY(); ++iy) {
1909 if (h->GetBinContent(ix+1, iy+1) > THR) {
1911 LOG(logDEBUG) <<
"ROC " << i <<
" with hot pixel " << ix <<
"/" << iy <<
", hits = " << h->GetBinContent(ix+1, iy+1);
1912 hot.push_back(make_pair(ix, iy));
1916 fHotPixels.push_back(hot);
1919 LOG(logDEBUG) <<
"no hot pixel found!";
1921 LOG(logINFO) <<
"PixTest::maskHotPixels() done";
uint16_t prepareDaq(int triggerFreq, uint8_t trgTkDel)
set up DAQ (including call to setTriggerFrequency)
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
in str, replace all occurences of from to to
void getPhError(std::string dac, int dacmin, int dacmax, int FLAGS, int ntrig)
determine PH error interpolation
void fillMap(TH2D *hmod, TH2D *hroc, int iroc)
provides the coordinate transformation to module map
std::vector< TH2D * > efficiencyMaps(std::string name, uint16_t ntrig=10, uint16_t FLAGS=FLAG_FORCE_MASKED)
returns TH2D's with hit maps
void resetROC()
send reset to ROC(s)
virtual void runCommand(std::string command)
allow execution of any button in the test
static std::string stripPos(std::string)
decrepit, do not use
static int rcr2idx(int iroc, int icol, int irow)
convert ROC/COL/ROW into idx
virtual void doTest()
function connected to "DoTest" button of PixTab
void preScan(std::string dac, std::vector< shist256 * > maps, int &dacmin, int &dacmax)
kind of another work-around (splitting the range, adjusting ntrig, etc)
std::vector< std::vector< std::pair< int, int > > > deadPixels(int ntrig, bool scanCalDel=false)
create vector (per ROC) of vector of dead pixels
void setDacs(std::string dacName, std::vector< uint8_t > dacVector)
set on all ROCs the DAC dacName
TH1 * nextHist()
allow forward iteration through list of histograms
int histCycle(std::string hname)
determine histogram cycle
void powerOff()
turn DTB power off
virtual void fullTest()
function called when FullTest is running; most often this is simply calling doTest() ...
void dumpParameters()
print all parameters and values
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 resetTBM()
send reset to TBM(s)
int getIdxFromId(int id)
provide the mapping between ROC index and ID
int simpleThreshold(TH1 *)
find first bin above 50% level. Fills fThreshold, fThresholdE, fSigma, fSigmaE
virtual void sparseRoc(int npix=8)
select some pattern of pixels if not enabling the complete ROC. Enables the complete ROC if npix > 99...
std::vector< std::pair< int, int > > checkHotPixels(TH2D *h)
std::vector< int > getMinimumVthrComp(std::vector< TH1 * >, int reserve=10, double nsigma=3.)
minimum allowable VthrComp; reserve indicate the separation from the minimum VthrComp where noise set...
void maskHotPixels(std::vector< TH2D * >)
determine hot pixels with high occupancy
void bookHist(std::string name)
use if you want, or define the histograms in the specific member functions
void dacScan(std::string dac, int ntrig, int dacmin, int dacmax, std::vector< shist256 * > maps, int ihit, int flag=0)
scan a dac range. Will call preScan to protect against r/o problems.
void clearSelectedPixels()
clear selected pixel list
void fillDacHist(std::vector< std::pair< uint8_t, std::vector< pxar::pixel > > > &results, TH1D *h, int icol=-1, int irow=-1, int iroc=-1)
fill the results of a api::getEfficiencyVsDAC into a TH1D; if icol/irow/iroc are > -1, then fill only 'correct' pixels
std::vector< int > getMaximumVthrComp(int ntrig, double frac=0.8, int reserve=10)
maximum allowable VthrComp
void restoreDacs(bool verbose=false)
restore all DACs
void testDone()
signal to PixTab that the test is done (and to update the canvas)
void bookTree()
book a minimal tree with pixel events
void scurveAna(std::string dac, std::string name, std::vector< shist256 * > maps, std::vector< TH1 * > &resultMaps, int result)
do the scurve analysis
void addSelectedPixels(std::string sval)
add a selected pixel to the internal parameter list
virtual void doAnalysis()
to be filled per test
bool getParameter(std::string parName, int &)
return by reference the INT value of a parameter
virtual TH1 * moduleMap(std::string histname)
combine all available ROC maps into a module map
TH1D * distribution(TH2D *, int nbins, double xmin, double xmax)
creates a 1D distribution of a map
bool setTestParameter(std::string parname, std::string value)
change the local parameter
TH1 * previousHist()
allow backward iteration through list of histograms
void finalCleanup()
functions for DAQ
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
virtual std::string getHistOption(TH1 *)
get the hist display options (if stored in fHistOptions)
void cacheDacs(bool verbose=false)
cache all DACs
std::string getDacsString(std::string dacName)
return from all ROCs the DAC dacName as a string
void setTitles(TH1 *h, const char *sx, const char *sy, float size=0.05, float xoff=1.1, float yoff=1.1, float lsize=0.05, int font=42)
utility to set histogram titles
static void idx2rcr(int idx, int &iroc, int &icol, int &irow)
and back again
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.
std::vector< uint8_t > getDacs(std::string dacName)
return from all ROCs the DAC dacName
void print(std::string, pxar::TLogLevel log=pxar::logINFO)
produce eye-catching printouts
bool selectedRoc(int id)
is ROC ID selected?
double getMinimumThreshold(std::vector< TH1 * >)
return minimum threshold in a set of maps
void saveDacs()
save DACs to file
virtual void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
void clearHistList()
delete histogams from HistList
void saveTbParameters()
save TB parameters to file
void saveTrimBits()
save trim bits to file
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
uint16_t setTriggerFrequency(int triggerFreq, uint8_t TrgTkDel)
set trigger frequence [kHz] and trigger token delay
void update()
signal to PixTab to update the canvas
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
int pixelThreshold(std::string dac, int ntrig, int dacmin, int dacmax)
work-around to cope with suboptimal pxar/core
void powerOn()
turn DTB power on
PixTest(PixSetup *a, std::string name)
constructor requires PixSet to get test parameters and config parameters
void setId2Idx(std::map< int, int > a)
set the mapping between ROC ID and index
TProfile2D * bookTProfile2D(std::string sname, std::string title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double max, std::string option="")
book a TProfile2D, adding version information to the name and title
bool threshold(TH1 *)
fit an s-curve to a distribution. Fills fThreshold, fThresholdE, fSigma, fSigmaE
std::vector< TH1 * > scurveMaps(std::string dac, std::string name, int ntrig=10, int daclo=0, int dachi=255, int dacsperstep=-1, int result=15, int ihit=1, int flag=FLAG_FORCE_MASKED)
void init()
sets all test parameters
void maskPixels()
mask all pixels mentioned in the mask file
std::vector< TH2D * > phMaps(std::string name, uint16_t ntrig=10, uint16_t FLAGS=FLAG_FORCE_MASKED)
returns TH2D's with pulseheight maps
double getMaximumThreshold(std::vector< TH1 * >)
return maximum threshold in a set of maps
int getIdFromIdx(int idx)
provide the mapping between ROC ID and index
std::vector< TH1 * > thrMaps(std::string dac, std::string name, uint8_t dacmin, uint8_t dachi, int ntrig, uint16_t flag=0)
returns TH2D's for the threshold, the user flag argument is intended for selecting calS and will be O...