pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestDacScanRoc.cc
1 // -- author: Daniel Pitzl
2 // ROC readout count vs DAC
3 
4 #include <stdlib.h> // atof, atoi
5 #include <algorithm> // std::find
6 
7 #include <TStopwatch.h>
8 
9 #include "PixTestDacScanRoc.hh"
10 #include "log.h"
11 
12 using namespace std;
13 using namespace pxar;
14 
15 ClassImp(PixTestDacScanRoc)
16 
17 //------------------------------------------------------------------------------
18 PixTestDacScanRoc::PixTestDacScanRoc( PixSetup *a, std::string name )
19 : PixTest(a, name), fParNtrig(-1), fParDAC("nada"),
20  fParLoDAC(-1), fParHiDAC(-1)
21 {
22  PixTest::init();
23  init();
24 }
25 
26 //------------------------------------------------------------------------------
27 PixTestDacScanRoc::PixTestDacScanRoc() : PixTest()
28 {
29 }
30 
31 //------------------------------------------------------------------------------
32 bool PixTestDacScanRoc::setParameter( string parName, string sval )
33 {
34  bool found(false);
35 
36  for( uint32_t i = 0; i < fParameters.size(); ++i ) {
37 
38  if( fParameters[i].first == parName ) {
39 
40  found = true;
41 
42  sval.erase( remove( sval.begin(), sval.end(), ' '), sval.end() );
43 
44  if( !parName.compare("ntrig") ) {
45  fParNtrig = atoi(sval.c_str() );
46  LOG(logDEBUG) << " setting fParNtrig ->" << fParNtrig
47  << "<- from sval = " << sval;
48  }
49 
50  if( !parName.compare("dac") ) {
51  fParDAC = sval;
52  LOG(logDEBUG) << " setting fParDAC ->" << fParDAC
53  << "<- from sval = " << sval;
54  }
55 
56  if( !parName.compare("daclo") ) {
57  fParLoDAC = atoi(sval.c_str() );
58  LOG(logDEBUG) << " setting fParLoDAC ->" << fParLoDAC
59  << "<- from sval = " << sval;
60  }
61 
62  if( !parName.compare("dachi") ) {
63  fParHiDAC = atoi(sval.c_str() );
64  LOG(logDEBUG) << " setting fParHiDAC ->" << fParHiDAC
65  << "<- from sval = " << sval;
66  }
67 
68  break;
69  }
70  }
71  return found;
72 }
73 
74 //------------------------------------------------------------------------------
75 void PixTestDacScanRoc::init()
76 {
77  setToolTips();
78  fDirectory = gFile->GetDirectory( fName.c_str() );
79  if( !fDirectory )
80  fDirectory = gFile->mkdir( fName.c_str() );
81  fDirectory->cd();
82 }
83 
84 //------------------------------------------------------------------------------
86  fTestTip =
87  string( Form( "scan DAC %s, count responding pixels per ROC\n", fParDAC.c_str() ) )
88  ;
89  fSummaryTip = string("summary plot to be implemented")
90  ;
91 }
92 
93 //------------------------------------------------------------------------------
94 void PixTestDacScanRoc::bookHist(string name)
95 {
96  LOG(logDEBUG) << "nothing done with " << name;
97 }
98 
99 //------------------------------------------------------------------------------
100 PixTestDacScanRoc::~PixTestDacScanRoc()
101 {
102 }
103 
104 //------------------------------------------------------------------------------
106 {
107  fDirectory->cd();
108  fHistList.clear();
109  PixTest::update();
110 
111  LOG(logINFO) << "PixTestDacScanRoc::doTest() DAC = " << fParDAC;
112 
113  uint8_t maxDac = fApi->getDACRange( fParDAC ); // 15 or 255
114 
115  if( maxDac == 0 ) {
116  LOG(logINFO) << "ERROR: " << fParDAC << " is not a ROC register";
117  return;
118  }
119 
120  if( fParHiDAC > maxDac ) {
121  LOG(logINFO) << fParDAC << " range only " << maxDac;
122  fParHiDAC = maxDac;
123  }
124 
125  uint32_t nRocs = fPixSetup->getConfigParameters()->getNrocs();
126 
127  uint8_t dacVal[16];
128  for( uint32_t roc = 0; roc < nRocs; ++roc )
129  dacVal[roc] = fApi->_dut->getDAC( roc, fParDAC );
130 
131  LOG(logINFO) << "PixTestDacScanRoc::doTest() ntrig = " << fParNtrig;
132 
133  fApi->_dut->testAllPixels(true);
134 
135  // book:
136 
137  vector<TH1D*> hAlive;
138  vector<TH1D*> hPerfect;
139  TH1D *h1(0);
140 
141  for( uint32_t roc = 0; roc < nRocs; ++roc ) {
142 
143  h1 = new TH1D( Form( "Alive_pixels_vs_%s_C%d",
144  fParDAC.c_str(), roc ),
145  Form( "Alive pixels vs %s C%d",
146  fParDAC.c_str(), roc ),
147  256, -0.5, 255.5 );
148 
149  h1->SetMinimum(0);
150  h1->SetMaximum(4200);
151  setTitles( h1, Form( "%s [DAC]", fParDAC.c_str() ), "alive pixels" );
152  hAlive.push_back(h1);
153  fHistList.push_back(h1);
154 
155  h1 = new TH1D( Form( "Perfect_pixels_vs_%s_C%d",
156  fParDAC.c_str(), roc ),
157  Form( "Perfect pixels vs %s C%d",
158  fParDAC.c_str(), roc ),
159  256, -0.5, 255.5 );
160 
161  h1->SetMinimum(0);
162  h1->SetMaximum(4200);
163  setTitles( h1, Form( "%s [DAC]", fParDAC.c_str() ), "perfect pixels" );
164  hPerfect.push_back(h1);
165  fHistList.push_back(h1);
166 
167  }
168 
169  TStopwatch sw;
170 
171  // loop over DAC values:
172 
173  for( int32_t idac = fParLoDAC; idac < fParHiDAC; ++idac ) { // careful with uint8_t iterators: < 255
174 
175  fApi->setDAC( fParDAC, idac ); // all ROCs
176 
177  // delay:
178 
179  sw.Start(kTRUE); // reset stopwatch
180  double id = 0;
181  do {
182  sw.Start(kFALSE); // continue
183  id = fApi->getTBid()*1E3; // [mA]
184  }
185  while( sw.RealTime() < 0.1 ); // [s]
186 
187  // measure:
188 
189  vector<pixel> vpix = fApi->getEfficiencyMap( 0, fParNtrig ); // all pix, ROCs
190 
191  LOG(logINFO) << fParDAC << setw(4) << idac << " " << id << " mA"
192  << setw(7) << vpix.size();
193 
194  // plot data:
195 
196  for( size_t ipx = 0; ipx < vpix.size(); ++ipx ) {
197 
198  uint8_t roc = vpix[ipx].roc();
199 
200  if( roc < nRocs ) {
201  int32_t readouts = (int32_t)vpix[ipx].value();
202  if( readouts == fParNtrig )
203  hPerfect[roc]->Fill( idac );
204  if( readouts >= fParNtrig/2 )
205  hAlive[roc]->Fill( idac );
206  } // valid
207 
208  } // pix
209 
210  } // dacs
211 
212  // restore:
213 
214  for( uint32_t roc = 0; roc < nRocs; ++roc )
215  fApi->setDAC( fParDAC, dacVal[roc], roc );
216 
217  // draw:
218 
219  for( size_t roc = 0; roc < nRocs; ++roc ) {
220  hPerfect[roc]->Draw();
221  PixTest::update();
222  }
223  fDisplayedHist = find( fHistList.begin(), fHistList.end(), hPerfect[nRocs-1] );
224 
225 }
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
void doTest()
function connected to "DoTest" button of PixTab
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
Definition: api.cc:546
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
double getTBid()
Definition: api.cc:434
uint8_t getDACRange(std::string dacName)
Definition: api.cc:619
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
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
std::vector< pixel > getEfficiencyMap(uint16_t flags, uint16_t nTriggers)
Definition: api.cc:1048
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
void init()
sets all test parameters
Definition: PixTest.cc:62