9 #include "PixTestSetup.hh"
11 #include "constants.h"
26 PixTestSetup::PixTestSetup() :
PixTest() {}
30 ParOutOfRange =
false;
31 std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
32 for (
unsigned int i = 0; i <
fParameters.size(); ++i) {
36 if (!parName.compare(
"clkmax")) {
37 fClkMax = atoi(sval.c_str());
38 if(fClkMax < 0 || fClkMax > 25) {
39 LOG(logWARNING) <<
"PixTestSetup::setParameter() ClkMax out of range (0-25)";
40 found=
false; ParOutOfRange =
true;
43 if (!parName.compare(
"desermax")) {
44 fDeserMax = atoi(sval.c_str());
45 if(fDeserMax < 0 || fDeserMax > 7) {
46 LOG(logWARNING) <<
"PixTestSetup::setParameter() DeserMax out of range (0-7)";
47 found=
false; ParOutOfRange =
true;
56 void PixTestSetup::init()
58 LOG(logDEBUG) <<
"PixTestSetup::init()";
60 fDirectory = gFile->GetDirectory(fName.c_str());
68 fTestTip = string(Form(
"scan testboard parameter settings and check for valid readout\n")
69 +
string(
"TO BE IMPLEMENTED!!"));
70 fSummaryTip = string(
"summary plot to be implemented");
73 void PixTestSetup::bookHist(
string name)
76 LOG(logDEBUG) <<
"nothing done with " << name;
79 PixTestSetup::~PixTestSetup()
81 LOG(logDEBUG) <<
"PixTestSetup dtor";
82 std::list<TH1*>::iterator il;
86 LOG(logINFO) <<
"Write out " << (*il)->GetName();
96 if (ParOutOfRange)
return;
104 LOG(logINFO) <<
"PixTestSetup::doTest() ntrig = " << Ntrig;
109 std::vector<std::pair<std::string, uint8_t> > pg_setup;
110 pg_setup.push_back(make_pair(
"resetroc", 25));
111 pg_setup.push_back(make_pair(
"token", 0));
112 uint16_t period = 28;
114 LOG(logINFO) <<
"PixTestSetup:: pg set to RES|TOK";
117 TH2D *histo =
new TH2D(Form(
"DeserphaseClkScan"), Form(
"DeserphaseClkScan"), fDeserMax+1, 0., fDeserMax+1, fClkMax+1, 0., fClkMax+1);
118 histo->GetXaxis()->SetTitle(
"deser160phase");
119 histo->GetYaxis()->SetTitle(
"clk");
122 std::vector<rawEvent> daqRawEv;
124 int good_clk = -1, good_deser = -1;
126 std::stringstream tablehead;
127 for (ideser = 0; ideser <= fDeserMax; ideser++) tablehead << std::setw(8) << ideser;
128 LOG(logINFO) << tablehead.str();
134 for (iclk = 0; iclk <= fClkMax; iclk++) {
135 std::stringstream oneline;
136 oneline << std::setw(2) << iclk <<
": ";
138 for (ideser = 0; ideser <= fDeserMax; ideser++) {
147 unsigned int head_good = 0;
148 unsigned int head_bad = 0;
151 for (std::vector<rawEvent>::iterator evt = daqRawEv.begin(); evt != daqRawEv.end(); ++evt) {
153 int head =
static_cast<int>(evt->data.at(0) & 0xffc);
154 if (head == 0x7f8) { head_good++; }
160 oneline << std::hex <<
"<7f8>" << std::dec;
161 histo->Fill(ideser, iclk, head_good);
162 good_clk = iclk; good_deser = ideser;
165 if (head_good < 10) oneline <<
"[" << head_good <<
"]";
166 else oneline <<
"[*]";
168 else if(head_bad > 0) {
169 oneline << std::hex <<
" " << std::setw(3) << std::setfill(
'0') << (daqRawEv.at(0).data.at(0) & 0xffc) << std::setfill(
' ') <<
" " << std::dec;
171 else oneline <<
" [.] ";
173 LOG(logINFO) << oneline.str();
180 int finalclk, finaldeser;
182 Int_t bin = histo->GetMaximumBin();
183 Int_t binx, biny, binz;
184 histo->GetBinXYZ(bin, binx, biny, binz);
187 LOG(logDEBUG) <<
"PixTestSetup:: choosing the good clk phase.";
188 Double_t val1 = histo->GetBinContent(bin);
191 for (
int ibiny = (biny+1); ibiny <= fClkMax; ibiny ++) {
192 val2 = histo->GetBinContent(binx, ibiny);
193 if (val2 < val1)
break;
196 biny = biny + ((int)(cnt / 2));
198 Double_t x1 = histo->GetXaxis()->GetBinLowEdge(binx);
199 Double_t x2 = histo->GetXaxis()->GetBinUpEdge(binx);
200 Double_t y1 = histo->GetYaxis()->GetBinLowEdge(biny);
201 Double_t y2 = histo->GetYaxis()->GetBinUpEdge(biny);
202 TBox b(x1, y1, x2, y2);
205 b.SetLineColor(kBlack);
208 if (good_clk != -1 && good_deser != -1) {
214 finaldeser = binx - 1;
215 LOG(logINFO) <<
"Found good delays at " <<
"CLK = "<< finalclk <<
", DESER160 = " << finaldeser;
219 finalclk = finaldeser = 4;
220 LOG(logINFO) <<
"DTB Delay Setup could not find any good delays.";
221 LOG(logINFO) <<
"Falling back to default values.";
229 sig_delays = getMagicDelays(finalclk,finaldeser);
230 for(std::vector<std::pair<std::string,uint8_t> >::iterator sig = sig_delays.begin(); sig != sig_delays.end(); ++sig) {
231 fPixSetup->getConfigParameters()->setTbParameter(sig->first, sig->second);
243 LOG(logINFO) <<
"PixTestSetup::doTest() done for.";
246 std::vector<std::pair<std::string,uint8_t> > PixTestSetup::getMagicDelays(uint8_t clk, uint8_t deser160) {
247 std::vector<std::pair<std::string,uint8_t> > sigdelays;
248 sigdelays.push_back(std::make_pair(
"clk", clk));
249 sigdelays.push_back(std::make_pair(
"ctr", clk));
250 sigdelays.push_back(std::make_pair(
"sda", clk + 15));
251 sigdelays.push_back(std::make_pair(
"tin", clk + 5));
252 sigdelays.push_back(std::make_pair(
"deser160phase", deser160));
257 void PixTestSetup::saveTbParameters() {
258 LOG(logINFO) <<
"PixTestSetup:: Write Tb parameters to file.";
259 fPixSetup->getConfigParameters()->writeTbParameterFile();
264 std::transform(command.begin(), command.end(), command.begin(), ::tolower);
265 LOG(logDEBUG) <<
"running command: " << command;
266 if (!command.compare(
"savetbparameters")) {
270 LOG(logDEBUG) <<
"did not find command ->" << command <<
"<-";
void setPatternGenerator(std::vector< std::pair< std::string, uint8_t > > pg_setup)
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
PixSetup * fPixSetup
all necessary stuff in one place
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
void setTestboardDelays(std::vector< std::pair< std::string, uint8_t > > sig_delays)
TDirectory * fDirectory
where the root histograms will end up
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
void cacheDacs(bool verbose=false)
cache all DACs
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
void doTest()
function connected to "DoTest" button of PixTab
void runCommand(std::string)
allow execution of any button in the test
void update()
signal to PixTab to update the canvas
pxar::pxarCore * fApi
pointer to the API
uint16_t daqTrigger(uint32_t nTrig=1, uint16_t period=0)
void init()
sets all test parameters
std::vector< rawEvent > daqGetRawEventBuffer()