4 #include <TStopwatch.h>
6 #include "PixTestReadback.hh"
22 LOG(logDEBUG) <<
"PixTestReadback ctor(PixSetup &a, string, TGTab *)";
25 vector<vector<pair<string, double> > > iniCal;
26 vector<pair<string, double> > prova1;
27 fRbCal = fPixSetup->getConfigParameters()->getReadbackCal();
30 vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
31 for(
unsigned int iroc=0; iroc < rocIds.size(); iroc++){
32 fPar0VdCal.push_back(1.);
33 fPar1VdCal.push_back(1.);
34 fPar0VaCal.push_back(1.);
35 fPar1VaCal.push_back(1.);
36 fPar0RbIaCal.push_back(1.);
37 fPar1RbIaCal.push_back(1.);
38 fPar0TbIaCal.push_back(1.);
39 fPar1TbIaCal.push_back(1.);
40 fPar2TbIaCal.push_back(1.);
44 for(
unsigned int iroc=0; iroc < rocIds.size(); iroc++){
45 for(std::vector<std::pair<std::string, double> >::iterator ical = fRbCal[iroc].begin(); ical != fRbCal[iroc].end(); ical++){
46 if(!(ical->first.compare(
"par0vd"))){
47 fPar0VdCal[iroc] = ical->second;
49 else if(!(ical->first.compare(
"par1vd"))){
50 fPar1VdCal[iroc] = ical->second;
52 else if(!(ical->first.compare(
"par0va"))){
53 fPar0VaCal[iroc] = ical->second;
55 else if(!(ical->first.compare(
"par1va"))){
56 fPar1VaCal[iroc] = ical->second;
58 else if(!(ical->first.compare(
"par0rbia"))){
59 fPar0RbIaCal[iroc] = ical->second;
61 else if(!(ical->first.compare(
"par1rbia"))){
62 fPar1RbIaCal[iroc] = ical->second;
64 else if(!(ical->first.compare(
"par0tbia"))){
65 fPar0TbIaCal[iroc] = ical->second;
67 else if(!(ical->first.compare(
"par1tbia"))){
68 fPar1TbIaCal[iroc] = ical->second;
70 else if(!(ical->first.compare(
"par2tbia"))){
71 fPar2TbIaCal[iroc] = ical->second;
76 fPhCal.setPHParameters(fPixSetup->getConfigParameters()->getGainPedestalParameters());
77 fPhCalOK = fPhCal.initialized();
82 PixTestReadback::PixTestReadback() :
PixTest() {
83 LOG(logDEBUG) <<
"PixTestReadback ctor()";
88 PixTestReadback::~PixTestReadback() {
89 LOG(logDEBUG) <<
"PixTestReadback dtor, saving tree ... ";
91 if (fTree && fParFillTree) fTree->Write();
95 void PixTestReadback::init() {
96 LOG(logDEBUG) <<
"PixTestReadback::init()";
99 fDirectory = gFile->GetDirectory(fName.c_str());
108 fTestTip = string(
"Run DAQ - data from each run will be added to the same histogram.") ;
109 fSummaryTip = string(
"to be implemented") ;
110 fStopTip = string(
"Stop DAQ and save data.");
114 void PixTestReadback::bookHist(
string name) {
116 LOG(logDEBUG) <<
"nothing done with " << name;
120 void PixTestReadback::stop(){
123 LOG(logINFO) <<
"Stop pressed. Ending test.";
128 std::transform(command.begin(), command.end(), command.begin(), ::tolower);
129 LOG(logDEBUG) <<
"running command: " << command;
130 if(!command.compare(
"stop")){
134 if(!command.compare(
"calibratevd")){
138 if(!command.compare(
"calibrateva")){
142 if(!command.compare(
"calibrateia")){
146 if(!command.compare(
"readbackvbg")){
151 if(!command.compare(
"getcalibratedvbg")){
155 if(!command.compare(
"getcalibratedia")){
159 if(!command.compare(
"setvana")){
164 LOG(logINFO) <<
"Command " << command <<
" not implemented.";
171 fParOutOfRange =
false;
172 std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
173 for (
unsigned int i = 0; i <
fParameters.size(); ++i) {
176 if (!parName.compare(
"readback")) {
177 fParReadback = atoi(sval.c_str());
180 if (!parName.compare(
"usecalvd")) {
183 fCalwVd = atoi(sval.c_str());
184 LOG(logDEBUG)<<
"fCalwVd set to "<<fCalwVd;
187 if (!parName.compare(
"usecalva")) {
190 fCalwVa = atoi(sval.c_str());
193 if (!parName.compare(
"clockstretch")) {
194 fParStretch = atoi(sval.c_str());
197 if (!parName.compare(
"filltree")) {
198 fParFillTree = !(atoi(sval.c_str()) == 0);
201 if (!parName.compare(
"trgfrequency(khz)")){
202 fParTriggerFrequency = atoi(sval.c_str());
203 if (fParTriggerFrequency == 0) {
204 LOG(logWARNING) <<
"PixTestReadback::setParameter() trgfrequency must be different from zero";
205 found =
false; fParOutOfRange =
true;
214 bool PixTestReadback::setTrgFrequency(uint8_t TrgTkDel){
216 uint8_t trgtkdel= TrgTkDel;
217 double period_ns = 1 / (double)fParTriggerFrequency * 1000000;
218 fParPeriod = (uint16_t)period_ns / 25;
219 uint16_t ClkDelays = fParPeriod - trgtkdel;
223 fPg_setup.push_back(make_pair(
"resetroc", 15));
227 while (ClkDelays>255){
228 fPg_setup.push_back(make_pair(
"delay", 255));
229 ClkDelays = ClkDelays - 255;
232 fPg_setup.push_back(make_pair(
"delay", ClkDelays));
235 fPg_setup.push_back(make_pair(
"trg", trgtkdel));
236 fPg_setup.push_back(make_pair(
"tok", 0));
238 fParPeriod = fParPeriod + 4 + nDel;
244 void PixTestReadback::pgToDefault() {
246 LOG(logDEBUG) <<
"PixTestPattern::PG_Setup clean";
248 fPg_setup =
fPixSetup->getConfigParameters()->getTbPgSettings();
250 LOG(logINFO) <<
"PixTestPattern:: pg_setup set to default.";
254 void PixTestReadback::setHistos(){
256 fHits.clear(); fPhmap.clear(); fPh.clear(); fQmap.clear(); fQ.clear();
262 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
263 h2 =
bookTH2D(Form(
"hits_C%d", rocIds[iroc]), Form(
"hits_C%d", rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
270 p2 =
bookTProfile2D(Form(
"phMap_C%d", rocIds[iroc]), Form(
"phMap_C%d", rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
275 fPhmap.push_back(p2);
277 h1 =
bookTH1D(Form(
"ph_C%d", rocIds[iroc]), Form(
"ph_C%d", rocIds[iroc]), 256, 0., 256.);
283 p2 =
bookTProfile2D(Form(
"qMap_C%d", rocIds[iroc]), Form(
"qMap_C%d", rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
290 h1 =
bookTH1D(Form(
"q_C%d", rocIds[iroc]), Form(
"q_C%d", rocIds[iroc]), 200, 0., 1000.);
293 setTitles(h1,
"Q [Vcal]",
"Entries/bin");
300 void PixTestReadback::ProcessData(uint16_t numevents){
302 LOG(logDEBUG) <<
"Getting Event Buffer";
303 std::vector<pxar::Event> daqdat;
306 for (
unsigned int i = 0; i < numevents; i++) {
309 if (evt.pixels.size() > 0)
310 daqdat.push_back(evt);
316 LOG(logDEBUG) <<
"Processing Data: " << daqdat.size() <<
" events.";
322 for (std::vector<pxar::Event>::iterator it = daqdat.begin(); it != daqdat.end(); ++it) {
323 pixCnt += it->pixels.size();
326 fTreeEvent.header = it->header;
328 fTreeEvent.trailer = it->trailer;
329 fTreeEvent.npix = it->pixels.size();
332 for (
unsigned int ipix = 0; ipix < it->pixels.size(); ++ipix) {
335 LOG(logWARNING) <<
"PixTestReadback::ProcessData() wrong 'idx' value --> return";
338 fHits[idx]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row());
339 fPhmap[idx]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row(), it->pixels[ipix].value());
340 fPh[idx]->Fill(it->pixels[ipix].value());
343 q =
static_cast<uint16_t
>(fPhCal.vcal(it->pixels[ipix].roc(), it->pixels[ipix].column(),
344 it->pixels[ipix].row(), it->pixels[ipix].value()));
350 fQmap[idx]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row(), q);
352 fTreeEvent.proc[ipix] = it->pixels[ipix].roc();
353 fTreeEvent.pcol[ipix] = it->pixels[ipix].column();
354 fTreeEvent.prow[ipix] = it->pixels[ipix].row();
355 fTreeEvent.pval[ipix] = it->pixels[ipix].value();
356 fTreeEvent.pq[ipix] = q;
359 if (fParFillTree) fTree->Fill();
363 TH2D* h2 = (TH2D*)(fHits.back());
368 LOG(logINFO) << Form(
"events read: %6ld, pixels seen: %3d, hist entries: %4d",
369 daqdat.size(), pixCnt,
static_cast<int>(fHits[0]->GetEntries()));
373 void PixTestReadback::FinalCleaning() {
383 LOG(logINFO) <<
"PixTestReadback::doTest() start.";
388 vector<double> VBG = getCalibratedVbg();
394 LOG(logINFO) <<
"PixTestReadback::doTest() done";
399 void PixTestReadback::CalibrateIa(){
404 vector<uint8_t> readback;
408 vector<TH1D*> hs_rbIa, hs_tbIa;
410 map<uint8_t, vector<uint8_t > > rbIa;
411 while(readback.size()<1){
412 readback=daqReadback(
"vana", (uint8_t)80, fParReadback);
414 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
415 name = Form(
"rbIa_C%d", iroc);
417 hrb =
bookTH1D(name, title, 256, 0., 256);
418 hs_rbIa.push_back(hrb);
419 name = Form(
"tbIa_C%d", iroc);
421 hrb =
bookTH1D(name, title, 256, 0., 256);
422 hs_tbIa.push_back(hrb);
432 avIoff = ioff16*(readback.size()-1)/(readback.size());
434 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
436 for(
int ivana=0; ivana<52; ivana++){
437 vana = (uint8_t)ivana*5;
438 do{readback=daqReadback(
"vana", vana, iroc, fParReadback);
439 }
while(readback.size()<1);
440 rbIa.insert(make_pair(vana, readback));
443 hs_rbIa[iroc]->Fill(vana, readback[iroc]);
444 hs_tbIa[iroc]->Fill(vana, tbIa-avIoff);
448 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
449 hs_rbIa[iroc]->GetXaxis()->SetTitle(
"Vana [DAC]");
450 hs_rbIa[iroc]->GetYaxis()->SetTitle(
"Ia_rb [ADC]");
451 hs_tbIa[iroc]->GetXaxis()->SetTitle(
"Vana [DAC]");
452 hs_tbIa[iroc]->GetYaxis()->SetTitle(
"Ia_TB [mA]");
454 gStyle->SetOptFit(1111);
456 vector<double> rb_vanaMax(readback.size(), 0.);
457 vector<double> tb_vanaMax(readback.size(), 0.);
460 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
461 rb_vanaMax[iroc] = hs_rbIa[iroc]->GetBinCenter(hs_rbIa[iroc]->FindFirstBinAbove(254));
463 LOG(logDEBUG)<<
"Vana max for fit:"<<endl<<
"rb: "<<rb_vanaMax[iroc]<<endl<<
"tb :"<<tb_vanaMax[iroc];
469 vector<TF1*> v_frb, v_ftb;
470 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
471 name = Form(
"lin_rb_C%d", iroc);
472 frb =
new TF1(name.c_str(),
"[0] + x*[1]", 0, rb_vanaMax[iroc]);
473 v_frb.push_back(frb);
474 name = Form(
"pol2_ftb_C%d", iroc);
475 ftb =
new TF1(name.c_str(),
"[0] + x*[1] + x*x*[2] ", 0, 255);
476 v_ftb.push_back(ftb);
479 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
480 hs_rbIa[iroc]->Fit(v_frb[iroc],
"W",
"", 0., rb_vanaMax[iroc]);
481 hs_tbIa[iroc]->Fit(v_ftb[iroc]);
485 fPar0RbIaCal[iroc]=v_frb[iroc]->GetParameter(0);
486 fPar1RbIaCal[iroc]=v_frb[iroc]->GetParameter(1);
487 fPar0TbIaCal[iroc]=v_ftb[iroc]->GetParameter(0);
488 fPar1TbIaCal[iroc]=v_ftb[iroc]->GetParameter(1);
489 fPar2TbIaCal[iroc]=v_ftb[iroc]->GetParameter(2);
493 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
494 for(std::vector<std::pair<std::string, double> >::iterator ical = fRbCal[iroc].begin(); ical != fRbCal[iroc].end(); ical++){
495 if(!(ical->first.compare(
"par0rbia"))){
496 ical->second = fPar0RbIaCal[iroc];
498 else if(!(ical->first.compare(
"par1rbia"))){
499 ical->second = fPar1RbIaCal[iroc];
501 else if(!(ical->first.compare(
"par0tbia"))){
502 ical->second = fPar0TbIaCal[iroc];
504 else if(!(ical->first.compare(
"par1tbia"))){
505 ical->second = fPar1TbIaCal[iroc];
507 else if(!(ical->first.compare(
"par2tbia"))){
508 ical->second = fPar2TbIaCal[iroc];
513 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
514 for(std::vector<std::pair<std::string, double> >::iterator ical = fRbCal[iroc].begin(); ical != fRbCal[iroc].end(); ical++){
515 LOG(logDEBUG)<<
"debug: "<<ical->first<<
" "<<ical->second;
520 vector<TH1D*> hs_rbIaCal;
521 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
522 name = Form(
"rbIaCal_C%d", iroc);
524 h_rbIaCal =
bookTH1D(name,title, 256, 0., 256.);
525 hs_rbIaCal.push_back(h_rbIaCal);
528 for(
int ivana=0; ivana<52; ivana++){
529 vana = (uint8_t)ivana*5;
530 for(
unsigned int iroc=0; iroc < rbIa[vana].size(); iroc++){
531 LOG(logDEBUG)<<
"step ivana = "<<ivana;
533 hs_rbIaCal[iroc]->Fill(vana, (rbIa[vana][iroc]*rbIa[vana][iroc]*fPar2TbIaCal[iroc]/fPar1RbIaCal[iroc]/fPar1RbIaCal[iroc] + rbIa[vana][iroc]/fPar1RbIaCal[iroc]/fPar1RbIaCal[iroc]*(fPar1RbIaCal[iroc]*fPar1TbIaCal[iroc]-2*fPar0RbIaCal[iroc]*fPar2TbIaCal[iroc]) + (fPar0RbIaCal[iroc]*fPar0RbIaCal[iroc]*fPar2TbIaCal[iroc] - fPar0RbIaCal[iroc]*fPar1TbIaCal[iroc])/fPar1RbIaCal[iroc] + fPar0TbIaCal[iroc]));
537 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
538 hs_rbIaCal[iroc]->GetXaxis()->SetTitle(
"Vana [DAC]");
539 hs_rbIaCal[iroc]->GetYaxis()->SetTitle(
"Ia_rb_cal [mA]");
540 hs_rbIaCal[iroc]->SetLineColor(kBlue);
545 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
546 fPixSetup->getConfigParameters()->writeReadbackFile(iroc, fRbCal[iroc]);
552 std::vector<double> PixTestReadback::getCalibratedIa(){
556 vector<uint8_t> readback;
558 while(readback.size()<1){
559 readback=daqReadbackIa();
561 vector<double> calIa(readback.size(), 0.);
562 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
564 calIa[iroc] = (((double)readback[iroc])*((double)readback[iroc])*fPar2TbIaCal[iroc]/fPar1RbIaCal[iroc]/fPar1RbIaCal[iroc] + ((double)readback[iroc])/fPar1RbIaCal[iroc]/fPar1RbIaCal[iroc]*(fPar1RbIaCal[iroc]*fPar1TbIaCal[iroc]-2*fPar0RbIaCal[iroc]*fPar2TbIaCal[iroc]) + (fPar0RbIaCal[iroc]*fPar0RbIaCal[iroc]*fPar2TbIaCal[iroc] - fPar0RbIaCal[iroc]*fPar1TbIaCal[iroc])/fPar1RbIaCal[iroc] + fPar0TbIaCal[iroc]);
565 LOG(logDEBUG)<<
"Calibrated analog current is "<<calIa[iroc];
570 double PixTestReadback::getCalibratedIa(
unsigned int iroc){
574 vector<uint8_t> readback;
576 while(readback.size()<1){
577 readback=daqReadbackIa();
580 calIa = (((double)readback[iroc])*((double)readback[iroc])*fPar2TbIaCal[iroc]/fPar1RbIaCal[iroc]/fPar1RbIaCal[iroc] + ((double)readback[iroc])/fPar1RbIaCal[iroc]/fPar1RbIaCal[iroc]*(fPar1RbIaCal[iroc]*fPar1TbIaCal[iroc]-2*fPar0RbIaCal[iroc]*fPar2TbIaCal[iroc]) + (fPar0RbIaCal[iroc]*fPar0RbIaCal[iroc]*fPar2TbIaCal[iroc] - fPar0RbIaCal[iroc]*fPar1TbIaCal[iroc])/fPar1RbIaCal[iroc] + fPar0TbIaCal[iroc]);
581 LOG(logDEBUG)<<
"Calibrated analog current is "<<calIa;
586 void PixTestReadback::CalibrateVana(){
638 void PixTestReadback::CalibrateVd(){
644 vector<uint8_t> readback;
648 vector<TH1D*> hs_rbVd, hs_dacVd;
649 vector<double > rbVd;
653 while(readback.size()<1){
654 readback=daqReadback(
"vd", 2.1, fParReadback);
657 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
658 name = Form(
"rbVd_C%d", iroc);
660 hrb =
bookTH1D(name, title, 500, 0., 5.);
661 hs_rbVd.push_back(hrb);
662 name = Form(
"dacVd_C%d", iroc);
664 hrb =
bookTH1D(name, title, 500, 0., 5.);
665 hs_dacVd.push_back(hrb);
669 for(
int iVd=0; iVd<18; iVd++){
670 LOG(logDEBUG)<<
"/****:::::: CALIBRATE VD :::::****/";
672 LOG(logDEBUG)<<
"Digital voltage will be set to: "<<Vd;
674 readback=daqReadback(
"vd", Vd, fParReadback);
675 }
while(readback.size()<1);
676 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
677 LOG(logDEBUG)<<
"Voltage "<<Vd<<
", readback "<<(int)readback[iroc];
679 hs_rbVd[iroc]->Fill(Vd, readback[iroc]);
684 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
685 hs_rbVd[iroc]->GetXaxis()->SetTitle(
"Vd [V]");
686 hs_rbVd[iroc]->GetYaxis()->SetTitle(
"Vd_rb [ADC]");
687 hs_dacVd[iroc]->GetXaxis()->SetTitle(
"Vd set [V]");
688 hs_dacVd[iroc]->GetYaxis()->SetTitle(
"Vd TB [V]");
691 gStyle->SetOptFit(1111);
695 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
696 name = Form(
"lin_vd_C%d", iroc);
697 frb =
new TF1(name.c_str(),
"[0] + x*[1]");
698 v_frb.push_back(frb);
701 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
702 hs_rbVd[iroc]->Fit(v_frb[iroc],
"W",
"");
704 fPar0VdCal[iroc]=v_frb[iroc]->GetParameter(0);
705 fPar1VdCal[iroc]=v_frb[iroc]->GetParameter(1);
712 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
713 for(std::vector<std::pair<std::string, double> >::iterator ical = fRbCal[iroc].begin(); ical != fRbCal[iroc].end(); ical++){
714 if(!(ical->first.compare(
"par0vd"))){
715 ical->second = fPar0VdCal[iroc];
717 else if(!(ical->first.compare(
"par1vd"))){
718 ical->second = fPar1VdCal[iroc];
723 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
724 fPixSetup->getConfigParameters()->writeReadbackFile(iroc, fRbCal[iroc]);
731 void PixTestReadback::readbackVbg(){
736 vector<uint8_t> readback;
738 while(readback.size()<1){
739 readback = daqReadback(
"vd", 2.5, fParReadback);
741 vector<double> avReadback(readback.size(), 0.);
748 for(
int i=0; i<10; i++){
749 LOG(logDEBUG)<<
"/****:::::: READBACK VBG :::::****/";
751 LOG(logDEBUG)<<
"Digital voltage will be set to: "<<Vd;
753 do{ readback = daqReadback(
"vd", Vd, fParReadback);
754 }
while(readback.size()<1);
755 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
756 if(0==readback[iroc]){
761 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
763 avReadback[iroc]+=(double)readback[iroc];
766 LOG(logDEBUG)<<
"Voltage "<<Vd<<
", average readback "<<(double)readback[iroc]/(i+1);
769 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
770 fRbVbg[iroc] = avReadback[iroc]/n_meas;
776 vector<double> PixTestReadback::getCalibratedVbg(){
777 vector<double> calVbg(fRbVbg.size(), 0.);
780 LOG(logINFO)<<
"Vbg will be calibrated using Vd calibration";
781 for(
unsigned int iroc=0; iroc < calVbg.size(); iroc++){
782 calVbg[iroc]=0.5*(fRbVbg[iroc]-fPar0VdCal[iroc])/fPar1VdCal[iroc];
786 LOG(logINFO)<<
"Vbg will be calibrated using Va calibration";
787 for(
unsigned int iroc=0; iroc < calVbg.size(); iroc++){
788 calVbg[iroc]=0.5*(fRbVbg[iroc]-fPar0VaCal[iroc])/fPar1VaCal[iroc];
792 LOG(logDEBUG)<<
"No calibration option specified. Please select one and retry.";
795 for(
unsigned int iroc=0; iroc < calVbg.size(); iroc++){
796 LOG(logINFO)<<
"/*/*/*/*::: ROC "<<iroc<<
": calibrated Vbg = "<<calVbg[iroc]<<
" :::*/*/*/*/";
801 void PixTestReadback::CalibrateVa(){
807 vector<uint8_t> readback;
811 vector<TH1D*> hs_rbVa, hs_dacVa;
812 vector<double > rbVa;
816 while(readback.size()<1){
817 readback=daqReadback(
"va", 1.5, fParReadback);
820 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
821 name = Form(
"rbVa_C%d", iroc);
823 hrb =
bookTH1D(name, title, 500, 0., 5.);
824 hs_rbVa.push_back(hrb);
825 name = Form(
"dacVa_C%d", iroc);
827 hrb =
bookTH1D(name, title, 500, 0., 5.);
828 hs_dacVa.push_back(hrb);
832 for(
int iVa=0; iVa<18; iVa++){
833 LOG(logDEBUG)<<
"/****:::::: CALIBRATE VA FUNCTION :::::****/";
835 LOG(logDEBUG)<<
"Analog voltage will be set to: "<<Va;
836 do{readback=daqReadback(
"va", Va, fParReadback);
837 }
while(readback.size()<1);
838 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
839 hs_rbVa[iroc]->Fill(Va, readback[iroc]);
844 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
845 hs_rbVa[iroc]->GetXaxis()->SetTitle(
"Va [V]");
846 hs_rbVa[iroc]->GetYaxis()->SetTitle(
"Va_rb [ADC]");
847 hs_dacVa[iroc]->GetXaxis()->SetTitle(
"Va set [V]");
848 hs_dacVa[iroc]->GetYaxis()->SetTitle(
"Va TB [V]");
851 gStyle->SetOptFit(1111);
853 vector<double> rb_VaMax(readback.size(), 0.);
854 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
855 rb_VaMax[iroc] = hs_rbVa[iroc]->GetBinCenter(hs_rbVa[iroc]->FindFirstBinAbove(254));
857 LOG(logDEBUG)<<
"Va max for fit on ROC "<<iroc<<
" : "<<rb_VaMax[iroc];
862 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
863 name = Form(
"lin_va_C%d", iroc);
864 frb =
new TF1(name.c_str(),
"[0] + x*[1]", 0, rb_VaMax[iroc]);
865 v_frb.push_back(frb);
868 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
869 hs_rbVa[iroc]->Fit(v_frb[iroc],
"W",
"", 0., rb_VaMax[iroc]);
873 fPar0VaCal[iroc]=v_frb[iroc]->GetParameter(0);
874 fPar1VaCal[iroc]=v_frb[iroc]->GetParameter(1);
880 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
881 for(std::vector<std::pair<std::string, double> >::iterator ical = fRbCal[iroc].begin(); ical != fRbCal[iroc].end(); ical++){
882 if(!(ical->first.compare(
"par0va"))){
883 ical->second = fPar0VaCal[iroc];
885 else if(!(ical->first.compare(
"par1va"))){
886 ical->second = fPar1VaCal[iroc];
891 for(
unsigned int iroc=0; iroc < readback.size(); iroc++){
892 fPixSetup->getConfigParameters()->writeReadbackFile(iroc, fRbCal[iroc]);
898 vector<uint8_t> PixTestReadback::daqReadback(
string dac,
double vana, int8_t parReadback){
904 if (!dac.compare(
"vana")){
905 LOG(logDEBUG)<<
"Wrong daqReadback function called!!!";
907 else if (!dac.compare(
"vd")){
908 vector<pair<string,double > > powerset =
fPixSetup->getConfigParameters()->getTbPowerSettings();
909 for(std::vector<std::pair<std::string,double> >::iterator pow_it=powerset.begin(); pow_it!=powerset.end(); pow_it++){
910 if( pow_it->first.compare(
"vd") == 0){
911 pow_it->second = vana;
916 else if (!dac.compare(
"va")){
917 vector<pair<string,double > > powerset =
fPixSetup->getConfigParameters()->getTbPowerSettings();
918 for(std::vector<std::pair<std::string,double> >::iterator pow_it=powerset.begin(); pow_it!=powerset.end(); pow_it++){
919 if( pow_it->first.compare(
"va") == 0){
920 pow_it->second = vana;
930 std::vector<std::vector<uint16_t> > rb;
932 std::vector<uint8_t> rb_val;
934 for(uint8_t i=0; i<rb.size(); i++){
935 rb_val.push_back( rb[i][ rb[i].size()-1 ]&0xff );
947 std::vector<uint8_t> PixTestReadback::daqReadback(
string dac, uint8_t vana, int8_t parReadback){
953 if (!dac.compare(
"vana")){
957 LOG(logDEBUG)<<
"Wrong daqReadback function called!!!";
964 std::vector<std::vector<uint16_t> > rb;
966 std::vector<uint8_t> rb_val;
968 for(uint8_t i=0; i<rb.size(); i++){
969 rb_val.push_back( rb[i][ rb[i].size()-1 ]&0xff );
980 std::vector<uint8_t> PixTestReadback::daqReadback(
string dac, uint8_t vana,
unsigned int roc, int8_t parReadback){
986 if (!dac.compare(
"vana")){
990 LOG(logDEBUG)<<
"Wrong daqReadback function called!!!";
997 std::vector<std::vector<uint16_t> > rb;
999 std::vector<uint8_t> rb_val;
1001 for(uint8_t i=0; i<rb.size(); i++){
1002 rb_val.push_back( rb[i][ rb[i].size()-1 ]&0xff );
1015 std::vector<uint8_t> PixTestReadback::daqReadbackIa(){
1034 LOG(logINFO) <<
"PixTestReadback::Number of masked pixels:";
1035 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc) {
1036 LOG(logINFO) <<
"PixTestReadback:: ROC " <<
static_cast<int>(iroc) <<
": " <<
fApi->
_dut->
getNMaskedPixels(static_cast<int>(iroc));
1045 fPg_setup.push_back(make_pair(
"resetroc", 0));
1046 uint16_t period = 28;
1055 LOG(logINFO) <<
"PixTestReadback::RES sent once ";
1060 LOG(logINFO) <<
"PixTestReadback::PG_Setup clean";
1063 LOG(logINFO) <<
"PG set to have trigger frequency = " << fParTriggerFrequency <<
" kHz";
1064 if (!setTrgFrequency(20)){
1080 gSystem->ProcessEvents();
1085 std::vector<std::vector<uint16_t> > rb;
1087 std::vector<uint8_t> rb_val;
1089 for(uint8_t i=0; i<rb.size(); i++){
1090 rb_val.push_back( rb[i][ rb[i].size()-1 ]&0xff );
1102 void PixTestReadback::setVana() {
1109 banner(Form(
"PixTestPretest::setVana() target Ia = %d mA/ROC", fTargetIa));
1113 vector<uint8_t> vanaStart;
1114 vector<double> rocIana;
1118 for (
int iroc = 0; iroc < nRocs; ++iroc) {
1120 rocIana.push_back(0.);
1142 const double extra = 0.1;
1143 const double eps = 0.25;
1144 const double slope = 6;
1146 for (
int roc = 0; roc < nRocs; ++roc) {
1148 LOG(logDEBUG) <<
"skipping ROC idx = " << roc <<
" (not selected) for Vana tuning";
1151 int vana = vanaStart[roc];
1154 double ia = getCalibratedIa(roc);
1158 ia = getCalibratedIa(roc);
1159 }
while (sw.RealTime() < 0.1);
1161 double diff = fTargetIa + extra - (ia - i015);
1164 LOG(logDEBUG) <<
"ROC " << roc <<
" iter " << iter
1166 <<
" Ia " << ia-i015 <<
" mA";
1168 while (TMath::Abs(diff) > eps && iter < 11 && vana > 0 && vana < 255) {
1170 int stp =
static_cast<int>(TMath::Abs(slope*diff));
1171 if (stp == 0) stp = 1;
1172 if (diff < 0) stp = -stp;
1190 ia = getCalibratedIa(roc);
1192 while( sw.RealTime() < 0.1 );
1194 diff = fTargetIa + extra - (ia - i015);
1196 LOG(logDEBUG) <<
"ROC " << setw(2) << roc
1197 <<
" iter " << setw(2) << iter
1198 <<
" Vana " << setw(3) << vana
1199 <<
" Ia " << ia-i015 <<
" mA";
1202 rocIana[roc] = ia-i015;
1203 vanaStart[roc] = vana;
1208 TH1D *hsum =
bookTH1D(
"VanaSettings",
"Vana per ROC", nRocs, 0., nRocs);
1211 hsum->SetMinimum(0);
1212 hsum->SetMaximum(256);
1215 TH1D *hcurr =
bookTH1D(
"Iana",
"Iana per ROC", nRocs, 0., nRocs);
1218 hcurr->SetMinimum(0);
1219 hcurr->SetMaximum(30.0);
1224 for (
int roc = 0; roc < nRocs; ++roc) {
1227 LOG(logDEBUG) <<
"ROC " << setw(2) << roc <<
" Vana " << setw(3) << int(vanaStart[roc]);
1230 hsum->Fill(roc, vanaStart[roc] );
1231 hcurr->Fill(roc, rocIana[roc]);
1234 vector<double> v_ia16 = getCalibratedIa();
1239 v_ia16 = getCalibratedIa();
1241 while( sw.RealTime() < 0.1 );
1244 for(
unsigned int iroc = 0; iroc<v_ia16.size(); iroc++){
1245 ia16 += v_ia16[iroc];
1252 LOG(logINFO) <<
"PixTestPretest::setVana() done, Module Ia " << ia16 <<
" mA = " << ia16/nRocs <<
" mA/ROC";
1257 void PixTestReadback::doDAQ(){
1259 if (fParOutOfRange)
return;
1269 LOG(logINFO) <<
"PixTestReadback::Number of masked pixels:";
1270 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc) {
1271 LOG(logINFO) <<
"PixTestReadback:: ROC " <<
static_cast<int>(iroc) <<
": " <<
fApi->
_dut->
getNMaskedPixels(static_cast<int>(iroc));
1280 fPg_setup.push_back(make_pair(
"resetroc", 0));
1281 uint16_t period = 28;
1290 LOG(logINFO) <<
"PixTestReadback::RES sent once ";
1295 LOG(logINFO) <<
"PixTestReadback::PG_Setup clean";
1298 LOG(logINFO) <<
"PG set to have trigger frequency = " << fParTriggerFrequency <<
" kHz";
1299 if (!setTrgFrequency(20)){
1315 gSystem->ProcessEvents();
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
in str, replace all occurences of from to to
size_t getNMaskedPixels(uint8_t rocid)
void setPatternGenerator(std::vector< std::pair< std::string, uint8_t > > pg_setup)
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
std::string fStopTip
information for this test
PixSetup * fPixSetup
all necessary stuff in one place
std::vector< std::vector< uint16_t > > daqGetReadback()
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
int getIdxFromId(int id)
provide the mapping between ROC index and ID
TDirectory * fDirectory
where the root histograms will end up
void restoreDacs(bool verbose=false)
restore all DACs
void bookTree()
book a minimal tree with pixel events
void setTestboardPower(std::vector< std::pair< std::string, double > > power_settings)
std::vector< uint8_t > getEnabledRocIDs()
void testAllPixels(bool enable)
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
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::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
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
bool selectedRoc(int id)
is ROC ID selected?
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
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
void update()
signal to PixTab to update the canvas
uint8_t getDAC(size_t rocId, std::string dacName)
void setClockStretch(uint8_t src, uint16_t delay, uint16_t width)
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
pxar::pxarCore * fApi
pointer to the API
std::vector< Event > daqGetEventBuffer()
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
uint16_t daqTrigger(uint32_t nTrig=1, uint16_t period=0)
void init()
sets all test parameters
void runCommand(std::string command)
allow execution of any button in the test
void doTest()
function connected to "DoTest" button of PixTab