pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestCurrentVsDac.cc
1 
2 // scan a DAC, measure currents
3 
4 #include <stdlib.h> /* atof, atoi */
5 #include <algorithm> // std::find
6 #include <iostream>
7 
8 #include <TH1.h>
9 
10 #include "PixTestCurrentVsDac.hh"
11 #include "log.h"
12 
13 using namespace std;
14 using namespace pxar;
15 
16 ClassImp(PixTestCurrentVsDac)
17 
18 // ----------------------------------------------------------------------
19 PixTestCurrentVsDac::PixTestCurrentVsDac( PixSetup *a, std::string name )
20 : PixTest(a, name), fParDAC("nada")
21 {
22  PixTest::init();
23  init();
24 }
25 
26 //----------------------------------------------------------
27 PixTestCurrentVsDac::PixTestCurrentVsDac() : PixTest()
28 {
29  //LOG(logDEBUG) << "PixTestCurrentVsDac ctor()";
30 }
31 
32 // ----------------------------------------------------------------------
33 bool PixTestCurrentVsDac::setParameter( string parName, string sval )
34 {
35  bool found(false);
36 
37  std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
38  for (unsigned int i = 0; i < fParameters.size(); ++i) {
39  if (fParameters[i].first == parName) {
40  found = true;
41  sval.erase(remove(sval.begin(), sval.end(), ' '), sval.end());
42  if( !parName.compare( "dac" ) ) {
43  fParDAC = sval;
44  setToolTips();
45  }
46 
47  break;
48  }
49  }
50 
51  return found;
52 }
53 
54 // ----------------------------------------------------------------------
55 void PixTestCurrentVsDac::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 // ----------------------------------------------------------------------
64 void PixTestCurrentVsDac::bookHist(string name) // general booking routine
65 {
66  fDirectory->cd();
67 
68  TH1D *h1(0);
69  fHistList.clear();
70  for( uint32_t i = 0; i < fPixSetup->getConfigParameters()->getNrocs(); ++i ) {
71 
72  h1 = new TH1D( Form( "Ia_vs_%s_C%d", name.c_str(), i),
73  Form( "Ia vs %s C%d", name.c_str(), i),
74  256, 0, 256 );
75  h1->SetMinimum(0);
76  h1->SetStats(0);
77  setTitles( h1, Form( "%s [DAC]", name.c_str() ), "analog current [mA]" );
78  fHistList.push_back(h1);
79 
80  h1 = new TH1D( Form( "Id_vs_%s_C%d", name.c_str(), i),
81  Form( "Id vs %s C%d", name.c_str(), i),
82  256, 0, 256 );
83  h1->SetMinimum(0);
84  h1->SetStats(0);
85  setTitles( h1, Form( "%s [DAC]", name.c_str() ), "digital current [mA]" );
86  fHistList.push_back(h1);
87  }
88 }
89 
90 //----------------------------------------------------------
91 PixTestCurrentVsDac::~PixTestCurrentVsDac()
92 {
93  LOG(logDEBUG) << "PixTestCurrentVsDac dtor";
94  std::list<TH1*>::iterator il;
95  fDirectory->cd();
96  for( il = fHistList.begin(); il != fHistList.end(); ++il) {
97  LOG(logDEBUG) << "Write out " << (*il)->GetName();
98  (*il)->SetDirectory(fDirectory);
99  (*il)->Write();
100  }
101 }
102 
103 // ----------------------------------------------------------------------
105  fDirectory->cd();
106  PixTest::update();
107 
108  LOG(logINFO) << "PixTestCurrentVsDac::doTest() DAC = " << fParDAC;
109 
110  fApi->_dut->testAllPixels(false);
111 
112  bookHist( fParDAC );
113 
114  TH1D *hia(0);
115  TH1D *hid(0);
116 
117  for( uint32_t roc = 0; roc < fPixSetup->getConfigParameters()->getNrocs(); ++roc ) {
118 
119  hia = (TH1D*)fDirectory->Get( Form( "Ia_vs_%s_C%d", fParDAC.c_str(), roc ) );
120  hid = (TH1D*)fDirectory->Get( Form( "Id_vs_%s_C%d", fParDAC.c_str(), roc ) );
121 
122  if( hia && hid ) {
123 
124  // remember DAC
125 
126  uint8_t dacval = fApi->_dut->getDAC( roc, fParDAC );
127 
128  // loop over DAC
129  int dacmax = fApi->getDACRange(fParDAC);
130  for( int idac = 0; idac <= dacmax; ++idac ) {
131 
132  fApi->setDAC( fParDAC, idac, roc );
133  // delay
134  hia->SetBinContent( idac+1, fApi->getTBia()*1E3 );
135  hid->SetBinContent( idac+1, fApi->getTBid()*1E3 );
136  }
137 
138  fApi->setDAC( fParDAC, dacval, roc ); // restore
139  }
140  else {
141  LOG(logINFO) << "XX did not find "
142  << Form( "Ia_vs_%s_C%d", fParDAC.c_str(), roc );
143  }
144  fDisplayedHist = find( fHistList.begin(), fHistList.end(), hid );
145  if( hid ) hid->Draw();
146  PixTest::update();
147 
148  } // rocs
149 
150 }
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
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
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
virtual void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
Definition: PixTest.cc:85
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
void doTest()
function connected to "DoTest" button of PixTab