pxar
All Classes Namespaces Functions Variables Typedefs Friends
PixTestAlive.cc
1 #include <stdlib.h> /* atof, atoi */
2 #include <algorithm> // std::find
3 #include <iostream>
4 #include "PixUtil.hh"
5 #include "PixTestAlive.hh"
6 #include "log.h"
7 
8 #include <TStopwatch.h>
9 #include <TH2.h>
10 
11 using namespace std;
12 using namespace pxar;
13 
14 ClassImp(PixTestAlive)
15 
16 // ----------------------------------------------------------------------
17 PixTestAlive::PixTestAlive(PixSetup *a, std::string name) : PixTest(a, name), fParNtrig(0), fParVcal(-1) {
18  PixTest::init();
19  init();
20  LOG(logDEBUG) << "PixTestAlive ctor(PixSetup &a, string, TGTab *)";
21 }
22 
23 
24 //----------------------------------------------------------
25 PixTestAlive::PixTestAlive() : PixTest() {
26  LOG(logDEBUG) << "PixTestAlive ctor()";
27 }
28 
29 // ----------------------------------------------------------------------
30 bool PixTestAlive::setParameter(string parName, string sval) {
31  bool found(false);
32  std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
33  for (unsigned int i = 0; i < fParameters.size(); ++i) {
34  if (fParameters[i].first == parName) {
35  found = true;
36  if (!parName.compare("ntrig")) {
37  fParNtrig = static_cast<uint16_t>(atoi(sval.c_str()));
38  setToolTips();
39  }
40  if (!parName.compare("vcal")) {
41  fParVcal = atoi(sval.c_str());
42  setToolTips();
43  }
44  break;
45  }
46  }
47  return found;
48 }
49 
50 
51 
52 // ----------------------------------------------------------------------
53 void PixTestAlive::runCommand(std::string command) {
54  std::transform(command.begin(), command.end(), command.begin(), ::tolower);
55  LOG(logDEBUG) << "running command: " << command;
56  if (!command.compare("masktest")) {
57  maskTest();
58  return;
59  }
60 
61  if (!command.compare("alivetest")) {
62  aliveTest();
63  return;
64  }
65 
66  if (!command.compare("addressdecodingtest")) {
67  addressDecodingTest();
68  return;
69  }
70  LOG(logDEBUG) << "did not find command ->" << command << "<-";
71 }
72 
73 
74 // ----------------------------------------------------------------------
75 void PixTestAlive::init() {
76  LOG(logDEBUG) << "PixTestAlive::init()";
77 
78  setToolTips();
79  fDirectory = gFile->GetDirectory(fName.c_str());
80  if (!fDirectory) {
81  fDirectory = gFile->mkdir(fName.c_str());
82  }
83  fDirectory->cd();
84 
85 }
86 
87 // ----------------------------------------------------------------------
89  fTestTip = string("send Ntrig \"calibrates\" and count how many hits were measured\n")
90  + string("the result is a hitmap, not an efficiency map\n")
91  + string("NOTE: VCAL is given in high range!")
92  ;
93  fSummaryTip = string("all ROCs are displayed side-by-side. Note the orientation:\n")
94  + string("the canvas bottom corresponds to the narrow module side with the cable")
95  ;
96 }
97 
98 
99 // ----------------------------------------------------------------------
100 void PixTestAlive::bookHist(string name) {
101  fDirectory->cd();
102  LOG(logDEBUG) << "nothing done with " << name;
103 }
104 
105 
106 //----------------------------------------------------------
107 PixTestAlive::~PixTestAlive() {
108  LOG(logDEBUG) << "PixTestAlive dtor";
109 }
110 
111 
112 // ----------------------------------------------------------------------
114 
115  TStopwatch t;
116 
117  fDirectory->cd();
118  PixTest::update();
119  bigBanner(Form("PixTestAlive::doTest()"));
120 
121  aliveTest();
122  TH1 *h1 = (*fDisplayedHist);
123  h1->Draw(getHistOption(h1).c_str());
124  PixTest::update();
125 
126  maskTest();
127  h1 = (*fDisplayedHist);
128  h1->Draw(getHistOption(h1).c_str());
129  PixTest::update();
130 
131  addressDecodingTest();
132  h1 = (*fDisplayedHist);
133  h1->Draw(getHistOption(h1).c_str());
134  PixTest::update();
135 
136  int seconds = t.RealTime();
137  LOG(logINFO) << "PixTestAlive::doTest() done, duration: " << seconds << " seconds";
138 
139 }
140 
141 
142 // ----------------------------------------------------------------------
143 void PixTestAlive::aliveTest() {
144  cacheDacs();
145  fDirectory->cd();
146  PixTest::update();
147  string ctrlregstring = getDacsString("ctrlreg");
148  banner(Form("PixTestAlive::aliveTest() ntrig = %d, vcal = %d (ctrlreg = %s)",
149  static_cast<int>(fParNtrig), static_cast<int>(fParVcal), ctrlregstring.c_str()));
150 
151  fApi->setDAC("vcal", fParVcal);
152 
153  fApi->_dut->testAllPixels(true);
154  fApi->_dut->maskAllPixels(false);
155 
156  fNDaqErrors = 0;
157  vector<TH2D*> test2 = efficiencyMaps("PixelAlive", fParNtrig, FLAG_FORCE_MASKED);
158  vector<int> deadPixel(test2.size(), 0);
159  vector<int> probPixel(test2.size(), 0);
160  for (unsigned int i = 0; i < test2.size(); ++i) {
161  fHistOptions.insert(make_pair(test2[i], "colz"));
162  // -- count dead pixels
163  for (int ix = 0; ix < test2[i]->GetNbinsX(); ++ix) {
164  for (int iy = 0; iy < test2[i]->GetNbinsY(); ++iy) {
165  if (test2[i]->GetBinContent(ix+1, iy+1) < fParNtrig) {
166  ++probPixel[i];
167  if (test2[i]->GetBinContent(ix+1, iy+1) < 1) {
168  ++deadPixel[i];
169  }
170  }
171  }
172  }
173  }
174 
175  copy(test2.begin(), test2.end(), back_inserter(fHistList));
176 
177  TH2D *h = (TH2D*)(fHistList.back());
178 
179  if (h) {
180  h->Draw(getHistOption(h).c_str());
181  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h);
182  PixTest::update();
183  }
184  restoreDacs();
185 
186  // -- summary printout
187  string deadPixelString, probPixelString;
188  for (unsigned int i = 0; i < probPixel.size(); ++i) {
189  probPixelString += Form(" %4d", probPixel[i]);
190  deadPixelString += Form(" %4d", deadPixel[i]);
191  }
192  LOG(logINFO) << "PixTestAlive::aliveTest() done"
193  << (fNDaqErrors>0? Form(" with %d decoding errors", static_cast<int>(fNDaqErrors)):"");
194  LOG(logINFO) << "number of dead pixels (per ROC): " << deadPixelString;
195  LOG(logDEBUG) << "number of red-efficiency pixels: " << probPixelString;
196 
197  // PixTest::hvOff();
198  // PixTest::powerOff();
199 }
200 
201 
202 // ----------------------------------------------------------------------
203 void PixTestAlive::maskTest() {
204 
205  cacheDacs();
206  fDirectory->cd();
207  PixTest::update();
208 
209  string ctrlregstring = getDacsString("ctrlreg");
210  banner(Form("PixTestAlive::maskTest() ntrig = %d, vcal = %d (ctrlreg = %s)",
211  static_cast<int>(fParNtrig), static_cast<int>(fParVcal), ctrlregstring.c_str()));
212 
213  fApi->setDAC("vcal", fParVcal);
214 
215  fApi->_dut->testAllPixels(true);
216  fApi->_dut->maskAllPixels(true);
217 
218  fNDaqErrors = 0;
219  vector<TH2D*> test2 = efficiencyMaps("MaskTest", fParNtrig, FLAG_FORCE_MASKED);
220  vector<int> maskPixel(test2.size(), 0);
221  for (unsigned int i = 0; i < test2.size(); ++i) {
222  fHistOptions.insert(make_pair(test2[i], "colz"));
223  // -- go for binary displays
224  for (int ix = 0; ix < test2[i]->GetNbinsX(); ++ix) {
225  for (int iy = 0; iy < test2[i]->GetNbinsY(); ++iy) {
226  if (test2[i]->GetBinContent(ix+1, iy+1) > 0) {
227  ++maskPixel[i];
228  }
229  if (test2[i]->GetBinContent(ix+1, iy+1) == 0) {
230  test2[i]->SetBinContent(ix+1, iy+1, 1);
231  } else {
232  test2[i]->SetBinContent(ix+1, iy+1, 0);
233  }
234  }
235  }
236  }
237 
238  copy(test2.begin(), test2.end(), back_inserter(fHistList));
239 
240  TH2D *h = (TH2D*)(fHistList.back());
241 
242  h->Draw(getHistOption(h).c_str());
243  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h);
244  restoreDacs();
245  PixTest::update();
246 
247  // -- summary printout
248  string maskPixelString;
249  for (unsigned int i = 0; i < maskPixel.size(); ++i) {
250  maskPixelString += Form(" %4d", maskPixel[i]);
251  }
252  LOG(logINFO) << "PixTestAlive::maskTest() done"
253  << (fNDaqErrors>0? Form(" with %d decoding errors", static_cast<int>(fNDaqErrors)):"");
254  LOG(logINFO) << "number of mask-defect pixels (per ROC): " << maskPixelString;
255 }
256 
257 
258 // ----------------------------------------------------------------------
259 void PixTestAlive::addressDecodingTest() {
260 
261  cacheDacs();
262  fDirectory->cd();
263  PixTest::update();
264  string ctrlregstring = getDacsString("ctrlreg");
265  banner(Form("PixTestAlive::addressDecodingTest() ntrig = %d, vcal = %d (ctrlreg = %s)",
266  static_cast<int>(fParNtrig), static_cast<int>(fParVcal), ctrlregstring.c_str()));
267 
268  fApi->setDAC("vcal", fParVcal);
269 
270  fDirectory->cd();
271 
272  vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
273 
274  fApi->_dut->testAllPixels(true);
275  fApi->_dut->maskAllPixels(false);
276 
277  fNDaqErrors = 0;
278  vector<TH2D*> test2 = efficiencyMaps("AddressDecodingTest", fParNtrig, FLAG_CHECK_ORDER|FLAG_FORCE_MASKED);
279  vector<int> addrPixel(test2.size(), 0);
280  for (unsigned int i = 0; i < test2.size(); ++i) {
281  fHistOptions.insert(make_pair(test2[i], "colz"));
282  // -- binary displays
283  for (int ix = 0; ix < test2[i]->GetNbinsX(); ++ix) {
284  for (int iy = 0; iy < test2[i]->GetNbinsY(); ++iy) {
285  if (test2[i]->GetBinContent(ix+1, iy+1) < 0) {
286  LOG(logDEBUG) << " read col/row = " << ix+1 << "/" << iy+1
287  << " address decoding error";
288  ++addrPixel[i];
289  }
290  if (test2[i]->GetBinContent(ix+1, iy+1) <= 0) {
291  test2[i]->SetBinContent(ix+1, iy+1, 0);
292  } else {
293  test2[i]->SetBinContent(ix+1, iy+1, 1);
294  }
295  }
296  }
297  }
298 
299  copy(test2.begin(), test2.end(), back_inserter(fHistList));
300 
301  TH2D *h = (TH2D*)(fHistList.back());
302 
303  h->Draw(getHistOption(h).c_str());
304  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h);
305  PixTest::update();
306  restoreDacs();
307 
308  // -- summary printout
309  string addrPixelString;
310  for (unsigned int i = 0; i < addrPixel.size(); ++i) {
311  addrPixelString += Form(" %4d", addrPixel[i]);
312  }
313  LOG(logINFO) << "PixTestAlive::addressDecodingTest() done"
314  << (fNDaqErrors>0? Form(" with %d decoding errors", static_cast<int>(fNDaqErrors)):"");
315  LOG(logINFO) << "number of address-decoding pixels (per ROC): " << addrPixelString;
316 }
317 
std::vector< TH2D * > efficiencyMaps(std::string name, uint16_t ntrig=10, uint16_t FLAGS=FLAG_FORCE_MASKED)
returns TH2D's with hit maps
Definition: PixTest.cc:295
void runCommand(std::string)
allow execution of any button in the test
Definition: PixTestAlive.cc:53
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
Definition: PixTest.hh:308
void doTest()
function connected to "DoTest" button of PixTab
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
Definition: api.cc:546
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
Definition: PixTest.hh:302
void maskAllPixels(bool mask, uint8_t rocid)
Definition: dut.cc:481
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
Definition: PixTestAlive.cc:30
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
void restoreDacs(bool verbose=false)
restore all DACs
Definition: PixTest.cc:771
dut * _dut
Definition: api.h:728
std::vector< uint8_t > getEnabledRocIDs()
Definition: dut.cc:214
void testAllPixels(bool enable)
Definition: dut.cc:503
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
Definition: PixTest.hh:309
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::string getDacsString(std::string dacName)
return from all ROCs the DAC dacName as a string
Definition: PixTest.cc:1614
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
Definition: PixTest.hh:307
void update()
signal to PixTab to update the canvas
Definition: PixTest.cc:569
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
void init()
sets all test parameters
Definition: PixTest.cc:62
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
Definition: PixTestAlive.cc:88