pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestDacScanPix.cc
1 // -- author: Daniel Pitzl
2 // Readout count vs DAC for one pixel per ROC
3 
4 #include <stdlib.h> // atof, atoi
5 #include <algorithm> // std::find
6 
7 #include "PixTestDacScanPix.hh"
8 #include "log.h"
9 
10 using namespace std;
11 using namespace pxar;
12 
13 ClassImp(PixTestDacScanPix)
14 
15 //------------------------------------------------------------------------------
16 PixTestDacScanPix::PixTestDacScanPix( PixSetup *a, std::string name )
17 : PixTest(a, name), fParNtrig(-1), fParDAC("nada"),
18  fParLoDAC(-1), fParHiDAC(-1)
19 {
20  PixTest::init();
21  init();
22 }
23 
24 //------------------------------------------------------------------------------
25 PixTestDacScanPix::PixTestDacScanPix() : PixTest()
26 {
27 }
28 
29 //------------------------------------------------------------------------------
30 bool PixTestDacScanPix::setParameter( string parName, string sval )
31 {
32  bool found(false);
33 
34  for( uint32_t i = 0; i < fParameters.size(); ++i ) {
35 
36  if( fParameters[i].first == parName ) {
37 
38  found = true;
39 
40  sval.erase( remove( sval.begin(), sval.end(), ' '), sval.end() );
41 
42  if( !parName.compare("ntrig") ) {
43  fParNtrig = atoi(sval.c_str() );
44  LOG(logDEBUG) << " setting fParNtrig ->" << fParNtrig
45  << "<- from sval = " << sval;
46  }
47 
48  if( !parName.compare("dac") ) {
49  fParDAC = sval;
50  LOG(logDEBUG) << " setting fParDAC ->" << fParDAC
51  << "<- from sval = " << sval;
52  }
53 
54  if( !parName.compare("daclo") ) {
55  fParLoDAC = atoi(sval.c_str() );
56  LOG(logDEBUG) << " setting fParLoDAC ->" << fParLoDAC
57  << "<- from sval = " << sval;
58  }
59 
60  if( !parName.compare("dachi") ) {
61  fParHiDAC = atoi(sval.c_str() );
62  LOG(logDEBUG) << " setting fParHiDAC ->" << fParHiDAC
63  << "<- from sval = " << sval;
64  }
65 
66  string::size_type s1;
67  string str1, str2;
68  int pixc, pixr;
69  if( !parName.compare("pix1") ) {
70  s1 = sval.find(",");
71  if( string::npos != s1) {
72  str1 = sval.substr(0, s1);
73  pixc = atoi(str1.c_str() );
74  str2 = sval.substr(s1+1);
75  pixr = atoi(str2.c_str() );
76  fPIX.push_back( make_pair(pixc, pixr) );
77  }
78  else {
79  fPIX.push_back(make_pair(-1, -1) );
80  }
81  }
82  // FIXME: remove/update from fPIX if the user removes via the GUI!
83  break;
84  }
85  }
86  return found;
87 }
88 
89 //------------------------------------------------------------------------------
90 void PixTestDacScanPix::init()
91 {
92  setToolTips();
93  fDirectory = gFile->GetDirectory( fName.c_str() );
94  if( !fDirectory )
95  fDirectory = gFile->mkdir( fName.c_str() );
96  fDirectory->cd();
97 }
98 
99 //------------------------------------------------------------------------------
101  fTestTip =
102  string( Form( "scan DAC %s, count pixel responses\n", fParDAC.c_str() ) )
103  ;
104  fSummaryTip = string("summary plot to be implemented")
105  ;
106 }
107 
108 //------------------------------------------------------------------------------
109 void PixTestDacScanPix::bookHist(string name)
110 {
111  LOG(logDEBUG) << "nothing done with " << name;
112 }
113 
114 //------------------------------------------------------------------------------
115 PixTestDacScanPix::~PixTestDacScanPix()
116 {
117 }
118 
119 //------------------------------------------------------------------------------
121 {
122  fDirectory->cd();
123  fHistList.clear();
124  PixTest::update();
125 
126  LOG(logINFO) << "PixTestDacScanPix::doTest() DAC = " << fParDAC;
127 
128  uint8_t maxDac = fApi->getDACRange( fParDAC ); // 15 or 255
129 
130  if( maxDac == 0 ) {
131  LOG(logINFO) << "ERROR: " << fParDAC << " is not a ROC register";
132  return;
133  }
134 
135  if( fParHiDAC > maxDac ) {
136  LOG(logINFO) << fParDAC << " range only " << maxDac;
137  fParHiDAC = maxDac;
138  }
139 
140  LOG(logINFO) << "PixTestDacScanPix::doTest() ntrig = " << fParNtrig;
141 
142  fApi->_dut->testAllPixels(false);
143 
144  //coordinates of the last pair = presetly set pixel
145  int32_t col = fPIX[fPIX.size()-1].first;
146  int32_t row = fPIX[fPIX.size()-1].second;
147 
148  if( col > -1)
149  fApi->_dut->testPixel( col, row, true ); // all ROCs
150 
151  // measure:
152 
153  vector< pair< uint8_t, vector<pixel> > >
154  result = fApi->getEfficiencyVsDAC( fParDAC, fParLoDAC, fParHiDAC,
155  0, fParNtrig ); // all ROCs
156 
157  // book:
158 
159  vector<TH1D*> hsts;
160  TH1D *h1(0);
161 
162  uint32_t nRocs = fPixSetup->getConfigParameters()->getNrocs();
163 
164  for( uint32_t roc = 0; roc < nRocs; ++roc ) {
165 
166  h1 = new TH1D( Form( "Readouts_vs_%s_c%d_r%d_C%d",
167  fParDAC.c_str(), col, row, roc ),
168  Form( "Readouts vs %s c%d r%d C%d",
169  fParDAC.c_str(), col, row, roc ),
170  256, -0.5, 255.5 );
171 
172  h1->SetMinimum(0);
173  setTitles( h1, Form( "%s [DAC]", fParDAC.c_str() ), "readouts" );
174  hsts.push_back(h1);
175  fHistList.push_back(h1);
176 
177  }
178 
179  // plot data:
180 
181  for( unsigned int i = 0; i < result.size(); ++i ) {
182 
183  int idac = result[i].first;
184 
185  vector<pixel> vpix = result[i].second;
186 
187  for( size_t ipx = 0; ipx < vpix.size(); ++ipx ) {
188 
189  uint8_t roc = vpix[ipx].roc();
190 
191  if( roc < nRocs &&
192  vpix[ipx].column() == col &&
193  vpix[ipx].row() == row ) {
194  h1 = hsts.at(roc);
195  h1->Fill( idac, vpix[ipx].value()); // already averaged
196  } // valid
197 
198  } // pix
199 
200  } // dacs
201 
202  for( size_t roc = 0; roc < nRocs; ++roc ) {
203  hsts[roc]->Draw();
204  PixTest::update();
205  }
206  fDisplayedHist = find( fHistList.begin(), fHistList.end(), hsts[nRocs-1] );
207 
208 }
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
PixSetup * fPixSetup
all necessary stuff in one place
Definition: PixTest.hh:290
void doTest()
function connected to "DoTest" button of PixTab
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
uint8_t getDACRange(std::string dacName)
Definition: api.cc:619
std::vector< std::pair< int, int > > fPIX
range of enabled pixels for time-consuming tests
Definition: PixTest.hh:311
void testPixel(uint8_t column, uint8_t row, bool enable)
Definition: dut.cc:432
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
Definition: PixTest.hh:302
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
std::vector< std::pair< uint8_t, std::vector< pixel > > > getEfficiencyVsDAC(std::string dacName, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
Definition: api.cc:733
dut * _dut
Definition: api.h:728
void testAllPixels(bool enable)
Definition: dut.cc:503
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
Definition: PixTest.hh:309
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
Definition: PixTest.hh:307
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
Definition: PixTest.cc:649
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