pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestDacScanCurrent.cc
1 // -- author: Daniel Pitzl
2 // scan a DAC, measure currents
3 
4 #include <stdlib.h> // atof, atoi
5 #include <algorithm> // std::find
6 
7 #include <TStopwatch.h>
8 
9 #include "PixTestDacScanCurrent.hh"
10 #include "log.h"
11 
12 using namespace std;
13 using namespace pxar;
14 
15 ClassImp(PixTestDacScanCurrent)
16 
17 //------------------------------------------------------------------------------
19 : PixTest(a, name), fParDAC("nada")
20 {
21  PixTest::init();
22  init();
23 }
24 
25 //------------------------------------------------------------------------------
26 PixTestDacScanCurrent::PixTestDacScanCurrent() : PixTest()
27 {
28 }
29 
30 //------------------------------------------------------------------------------
31 bool PixTestDacScanCurrent::setParameter( string parName, string sval )
32 {
33  bool found(false);
34 
35  for( uint32_t i = 0; i < fParameters.size(); ++i ) {
36 
37  if( fParameters[i].first == parName ) {
38 
39  found = true;
40 
41  sval.erase( remove( sval.begin(), sval.end(), ' ' ), sval.end() );
42 
43  if( !parName.compare( "dac" ) ) {
44  fParDAC = sval;
45  LOG(logDEBUG) << "PixTestDacScanCurrent setting fParDAC ->" << fParDAC
46  << "<- from sval = " << sval;
47  }
48  break;
49  }
50  }
51  return found;
52 }
53 
54 //------------------------------------------------------------------------------
55 void PixTestDacScanCurrent::init()
56 {
57  fDirectory = gFile->GetDirectory( fName.c_str() );
58  if( !fDirectory )
59  fDirectory = gFile->mkdir( fName.c_str() );
60  fDirectory->cd();
61 }
62 
63 // ----------------------------------------------------------------------
65 {
66  fTestTip = string( "measure ROC currents vs DAC");
67  fSummaryTip = string("summary plot to be implemented");
68 }
69 
70 //------------------------------------------------------------------------------
71 void PixTestDacScanCurrent::bookHist(string name) // general booking routine
72 {
73  fDirectory->cd();
74 
75  // Improvement: change binning for 4-bit DACs...
76 
77  TH1D *h1(0);
78  fHistList.clear();
79  for( uint32_t i = 0; i < fPixSetup->getConfigParameters()->getNrocs(); ++i ) {
80 
81  h1 = new TH1D( Form( "Ia_vs_%s_C%d", name.c_str(), i),
82  Form( "Ia vs %s C%d", name.c_str(), i),
83  256, 0, 256 );
84  h1->SetMinimum(0);
85  h1->SetStats(0);
86  setTitles( h1, Form( "%s [DAC]", name.c_str() ), "analog current [mA]" );
87  fHistList.push_back(h1);
88 
89  h1 = new TH1D( Form( "Id_vs_%s_C%d", name.c_str(), i),
90  Form( "Id vs %s C%d", name.c_str(), i),
91  256, 0, 256 );
92  h1->SetMinimum(0);
93  h1->SetStats(0);
94  setTitles( h1, Form( "%s [DAC]", name.c_str() ), "digital current [mA]" );
95  fHistList.push_back(h1);
96  }
97 }
98 
99 //------------------------------------------------------------------------------
100 PixTestDacScanCurrent::~PixTestDacScanCurrent()
101 {
102  LOG(logDEBUG) << "PixTestDacScanCurrent dtor";
103  std::list<TH1*>::iterator il;
104  fDirectory->cd();
105  for( il = fHistList.begin(); il != fHistList.end(); ++il) {
106  LOG(logDEBUG) << "Write out " << (*il)->GetName();
107  (*il)->SetDirectory(fDirectory);
108  (*il)->Write();
109  }
110 }
111 
112 //------------------------------------------------------------------------------
114 {
115  fDirectory->cd();
116  PixTest::update();
117 
118  LOG(logINFO) << "PixTestDacScanCurrent::doTest() DAC = " << fParDAC;
119 
120  uint8_t maxDac = fApi->getDACRange( fParDAC ); // 15 or 255
121 
122  if( maxDac == 0 ) {
123  LOG(logINFO) << "ERROR: " << fParDAC << " is not a ROC register";
124  return;
125  }
126 
127  fApi->_dut->testAllPixels(false);
128 
129  bookHist( fParDAC );
130 
131  TH1D *hia(0);
132  TH1D *hid(0);
133  TStopwatch sw;
134 
135  size_t nRocs = fPixSetup->getConfigParameters()->getNrocs();
136 
137  for( uint32_t roc = 0; roc < nRocs; ++roc ) {
138 
139  hia = (TH1D*)fDirectory->Get( Form( "Ia_vs_%s_C%d", fParDAC.c_str(), roc ) );
140  hid = (TH1D*)fDirectory->Get( Form( "Id_vs_%s_C%d", fParDAC.c_str(), roc ) );
141 
142  if( hia && hid ) {
143 
144  // remember DAC
145 
146  uint8_t dacval = fApi->_dut->getDAC( roc, fParDAC );
147 
148  fApi->setDAC( fParDAC, 0, roc ); // start at zero
149 
150  // delay:
151 
152  sw.Start(kTRUE); // reset stopwatch
153  do {
154  sw.Start(kFALSE); // continue
155  fApi->getTBia();
156  }
157  while( sw.RealTime() < 0.1 ); // [s]
158 
159  // loop over DAC:
160 
161  for( uint32_t idac = 0; idac <= maxDac; ++idac ) {
162 
163  fApi->setDAC( fParDAC, idac, roc );
164  // delay?
165  hia->SetBinContent( idac+1, fApi->getTBia()*1E3 );
166  hid->SetBinContent( idac+1, fApi->getTBid()*1E3 );
167 
168  }
169 
170  fApi->setDAC( fParDAC, dacval, roc ); // restore
171  }
172  else {
173  LOG(logINFO) << "XX did not find "
174  << Form( "Ia_vs_%s_C%d", fParDAC.c_str(), roc );
175  }
176  fDisplayedHist = find( fHistList.begin(), fHistList.end(), hid );
177  if( hid ) hid->Draw();
178  PixTest::update();
179 
180  } // rocs
181 
182 }
void doTest()
function connected to "DoTest" button of PixTab
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
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
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
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
double getTBia()
Definition: api.cc:424
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
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter