pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestDacScanThr.cc
1 // -- author: Daniel Pitzl
2 // Thr vs DAC
3 
4 #include <stdlib.h> // atof, atoi
5 #include <algorithm> // std::find
6 
7 #include "PixTestDacScanThr.hh"
8 #include "log.h"
9 
10 using namespace std;
11 using namespace pxar;
12 
13 ClassImp(PixTestDacScanThr)
14 
15 //------------------------------------------------------------------------------
16 PixTestDacScanThr::PixTestDacScanThr( PixSetup *a, std::string name )
17 : PixTest(a, name), fParNtrig(-1),
18  fParDAC("nada"), fParLoDAC(-1), fParHiDAC(-1),
19  fParCals(0)
20 {
21  PixTest::init();
22  init();
23 
24  for( size_t i = 0; i < fPIX.size(); ++i )
25  LOG(logDEBUG) << " setting fPIX" << i
26  << " ->" << fPIX[i].first
27  << "/" << fPIX[i].second;
28 }
29 
30 //------------------------------------------------------------------------------
31 PixTestDacScanThr::PixTestDacScanThr() : PixTest()
32 {
33  // LOG(logDEBUG) << "PixTestDacScanThr ctor()";
34 }
35 
36 //------------------------------------------------------------------------------
37 bool PixTestDacScanThr::setParameter( string parName, string sval )
38 {
39  bool found(false);
40  string::size_type s1;
41 
42  for( uint32_t i = 0; i < fParameters.size(); ++i ) {
43 
44  if( fParameters[i].first == parName ) {
45 
46  found = true;
47 
48  sval.erase(remove(sval.begin(), sval.end(), ' '), sval.end());
49 
50  if( !parName.compare( "ntrig" ) ) {
51  fParNtrig = atoi( sval.c_str() );
52  LOG(logDEBUG) << " setting fParNtrig ->" << fParNtrig
53  << "<- from sval = " << sval;
54  }
55  if( !parName.compare( "dac" ) ) {
56  fParDAC = sval;
57  LOG(logDEBUG) << " setting fParDAC ->" << fParDAC
58  << "<- from sval = " << sval;
59  }
60  if( !parName.compare( "daclo" ) ) {
61  fParLoDAC = atoi(sval.c_str());
62  LOG(logDEBUG) << " setting fParLoDAC ->" << fParLoDAC
63  << "<- from sval = " << sval;
64  }
65  if( !parName.compare( "dachi" ) ) {
66  fParHiDAC = atoi( sval.c_str() );
67  LOG(logDEBUG) << " setting fParHiDAC ->" << fParHiDAC
68  << "<- from sval = " << sval;
69  }
70  if( !parName.compare( "cals" ) ) {
71  fParCals = atoi( sval.c_str() );
72  LOG(logDEBUG) << " setting fParCals ->" << fParCals
73  << "<- from sval = " << sval;
74  }
75 
76  if( !parName.compare( "pix1" ) ) {
77  s1 = sval.find( "," );
78  if( string::npos != s1 ) {
79  string str1 = sval.substr(0, s1);
80  int pixc = atoi( str1.c_str() );
81  string str2 = sval.substr(s1+1);
82  int pixr = atoi( str2.c_str() );
83  fPIX.push_back( make_pair( pixc, pixr ) );
84  }
85  else {
86  fPIX.push_back( make_pair( -1, -1 ) );
87  }
88  }
89  // FIXME: remove/update from fPIX if the user removes via the GUI!
90  break;
91  }
92  }
93  return found;
94 }
95 
96 //------------------------------------------------------------------------------
97 void PixTestDacScanThr::init()
98 {
99  fDirectory = gFile->GetDirectory(fName.c_str());
100  if( !fDirectory) {
101  fDirectory = gFile->mkdir(fName.c_str());
102  }
103  fDirectory->cd();
104 }
105 
106 // ----------------------------------------------------------------------
108 {
109  fTestTip = string( "measure pixel threshold vs DAC");
110  fSummaryTip = string("summary plot to be implemented");
111 }
112 
113 //------------------------------------------------------------------------------
114 void PixTestDacScanThr::bookHist(string name) // general booking routine
115 {
116  LOG(logDEBUG) << "nothing done with " << name;
117 }
118 
119 //------------------------------------------------------------------------------
120 PixTestDacScanThr::~PixTestDacScanThr()
121 {
122  // LOG(logDEBUG) << "PixTestDacScanThr dtor";
123  std::list<TH1*>::iterator il;
124  fDirectory->cd();
125  for( il = fHistList.begin(); il != fHistList.end(); ++il) {
126  LOG(logINFO) << "Write out " << (*il)->GetName();
127  (*il)->SetDirectory(fDirectory);
128  (*il)->Write();
129  }
130 }
131 
132 //------------------------------------------------------------------------------
134 {
135  fDirectory->cd();
136  fHistList.clear();
137  PixTest::update();
138 
139  LOG(logINFO) << "PixTestDacScanThr::doTest() DAC = " << fParDAC;
140 
141  uint8_t maxDac = fApi->getDACRange( fParDAC ); // 15 or 255
142 
143  if( maxDac == 0 ) {
144  LOG(logINFO) << "ERROR: " << fParDAC << " is not a ROC register";
145  return;
146  }
147 
148  if( fParHiDAC > maxDac ) {
149  LOG(logINFO) << fParDAC << " range only " << maxDac;
150  fParHiDAC = maxDac;
151  }
152 
153  LOG(logINFO) << "PixTestDacScanThr::doTest() ntrig = " << fParNtrig;
154 
155  // activate one pixel per ROC:
156 
157  size_t nRocs = fPixSetup->getConfigParameters()->getNrocs();
158 
159  fApi->_dut->testAllPixels(false);
160 
161  //coordinates of the last pair selected
162  int32_t col = fPIX[fPIX.size()-1].first;
163  int32_t row = fPIX[fPIX.size()-1].second;
164  if( col > -1 )
165  fApi->_dut->testPixel( col, row, true );
166 
167  // DACs:
168 
169  uint8_t dacVal[16];
170  for( uint32_t roc = 0; roc < nRocs; ++roc )
171  dacVal[roc] = fApi->_dut->getDAC( roc, fParDAC );
172  uint8_t cal = fApi->_dut->getDAC( 0, "Vcal" );
173  uint8_t ctl = fApi->_dut->getDAC( 0, "CtrlReg" );
174  if( fParCals ) {
175  fApi->setDAC( "CtrlReg", 4 ); // all ROCs large Vcal
176  LOG(logINFO) << "CtrlReg 4 (large Vcal)";
177  }
178 
179  // measure:
180 
181  uint16_t flags = FLAG_RISING_EDGE; // thr in Vcal units
182  if( fParCals ) flags |= FLAG_CALS;
183  LOG(logINFO) << "flag " << flags;
184 
185  vector < pair < uint8_t, vector<pixel> > > result;
186 
187  for( uint8_t idac = fParLoDAC; idac < fParHiDAC; ++idac ) { // careful with uint8_t iterators: < 255
188 
189  fApi->setDAC( fParDAC, idac ); // all ROCs
190 
191  vector<pixel> vpix = fApi->getThresholdMap( "Vcal", flags, fParNtrig );
192 
193  pair < uint8_t, vector<pixel> > p;
194  p.first = idac;
195  p.second = vpix;
196  result.push_back(p);
197 
198  } // dacs
199 
200  // restore:
201 
202  for( uint32_t roc = 0; roc < nRocs; ++roc )
203  fApi->setDAC( fParDAC, dacVal[roc], roc );
204  fApi->setDAC( "Vcal", cal ); // restore on all ROCs
205  LOG(logINFO) << "back to Vcal " << int(cal);
206 
207  if( fParCals ) {
208  fApi->setDAC( "CtrlReg", ctl ); // restore
209  LOG(logINFO) << "back to CtrlReg " << ctl;
210  }
211 
212  // plot:
213 
214  vector<TH1D*> hsts;
215  TH1D *h1(0);
216 
217  for( size_t roc = 0; roc < nRocs; ++roc ) {
218 
219  h1 = new TH1D( Form( "PH_vs_%s_c%02d_r%02d_C%02d",
220  fParDAC.c_str(), col, row, int(roc) ),
221  Form( "PH vs %s c%02d r%02d C%02d",
222  fParDAC.c_str(), col, row, int(roc) ),
223  256, -0.5, 255.5 );
224  h1->SetStats(0);
225  h1->SetMinimum(0);
226  h1->SetMaximum(256);
227  setTitles( h1, Form( "%s [DAC]", fParDAC.c_str() ), "<PH> [ADC]" );
228  hsts.push_back(h1);
229  fHistList.push_back(h1);
230 
231  } // rocs
232 
233  // data:
234 
235  for( size_t i = 0; i < result.size(); ++i ) {
236 
237  int idac = result[i].first;
238 
239  vector<pixel> vpix = result[i].second;
240 
241  for( size_t ipx = 0; ipx < vpix.size(); ++ipx ) {
242 
243  uint8_t thr = (uint8_t)vpix[ipx].value();
244  if( thr == 255 ) continue; // invalid
245 
246  uint8_t roc = vpix[ipx].roc();
247 
248  if( roc < nRocs &&
249  vpix[ipx].column() == col &&
250  vpix[ipx].row() == row ) {
251  h1 = hsts.at(roc);
252  h1->Fill( idac, thr );
253  } // valid
254 
255  } // pix
256 
257  } // dac values
258 
259  for( size_t roc = 0; roc < nRocs; ++roc ) {
260  hsts[roc]->Draw();
261  PixTest::update();
262  }
263  fDisplayedHist = find( fHistList.begin(), fHistList.end(), hsts[nRocs-1] );
264 
265 }
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
Definition: api.cc:546
PixSetup * fPixSetup
all necessary stuff in one place
Definition: PixTest.hh:290
uint8_t getDACRange(std::string dacName)
Definition: api.cc:619
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
void doTest()
function connected to "DoTest" button of PixTab
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
dut * _dut
Definition: api.h:728
std::vector< pixel > getThresholdMap(std::string dacName, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
Definition: api.cc:1080
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 setToolTips()
implement this to provide updated tool tips if the user changes test parameters
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
uint8_t getDAC(size_t rocId, std::string dacName)
Definition: dut.cc:314
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
void init()
sets all test parameters
Definition: PixTest.cc:62