pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestShowIana.cc
1 // -- author: Wolfram Erdmann
2 // get analog current vs vana from testboard and roc readback
3 
4 #include <algorithm> // std::find
5 #include "PixTestShowIana.hh"
6 #include "log.h"
7 #include "constants.h"
8 
9 using namespace std;
10 using namespace pxar;
11 
12 ClassImp(PixTestShowIana)
13 
14 //------------------------------------------------------------------------------
15 PixTestShowIana::PixTestShowIana( PixSetup *a, std::string name )
16 : PixTest(a, name)
17 {
18  PixTest::init();
19  init();
20 }
21 
22 //------------------------------------------------------------------------------
23 PixTestShowIana::PixTestShowIana() : PixTest()
24 {
25 }
26 
27 //------------------------------------------------------------------------------
28 bool PixTestShowIana::setParameter( string parName, string sval )
29 {
30  if (parName == sval) return true; // silence the compiler warnings
31  return true;
32 }
33 
34 //------------------------------------------------------------------------------
35 void PixTestShowIana::init()
36 {
37  LOG(logINFO) << "PixTestShowIana::init()";
38  fDirectory = gFile->GetDirectory( fName.c_str() );
39  if( !fDirectory )
40  fDirectory = gFile->mkdir( fName.c_str() );
41  fDirectory->cd();
42 }
43 
44 // ----------------------------------------------------------------------
46 {
47  fTestTip = string( "show analog current vs Vana\n measured by testboard and roc readback");
48  fSummaryTip = string("summary plot to be implemented");
49 }
50 
51 //------------------------------------------------------------------------------
52 void PixTestShowIana::bookHist(string name)
53 {
54  LOG(logDEBUG) << "nothing done with " << name;
55 }
56 
57 //------------------------------------------------------------------------------
58 PixTestShowIana::~PixTestShowIana()
59 {
60  LOG(logDEBUG) << "PixTestShowIana dtor";
61  std::list<TH1*>::iterator il;
62  fDirectory->cd();
63  for( il = fHistList.begin(); il != fHistList.end(); ++il ) {
64  LOG(logINFO) << "Write out " << (*il)->GetName();
65  (*il)->SetDirectory(fDirectory);
66  (*il)->Write();
67  }
68 
69 }
70 
71 
72 //------------------------------------------------------------------------------
73 uint8_t PixTestShowIana::readRocADC(uint8_t adc)
74 {
75  fApi->setDAC("readback", adc);
76 
77  //read 32 events
78  fApi->daqTrigger(32);
79  vector<pxar::Event> events = fApi->daqGetEventBuffer();
80 
81  if ( events.size()<32 ){
82  cout << "only got " << events.size() << endl;
83  return 0;
84  }
85 
86  // and extract the readback data from the header bits
87  uint8_t value=0;
88  int n=-1; // ignore everything before the start marker
89 
90  //for( auto e : events){ // -std=c++0x/c++11 would be nice
91  for(vector<pxar::Event>::iterator ie=events.begin(); ie!=events.end(); ie++){
92  pxar::Event & e= *ie;
93 
94  if ( ( n>=0 ) && (n<16) ){
95  value = (value << 1 ) + (e.header & 1);
96  n++;
97  }
98  else if ( ((e.header & 2) >>1) == 1 ){
99  n=0;
100  }
101  }
102 
103  //int roc_readback = ( value & 0xF000 ) >> 12;
104  //int cmd_readback = ( value & 0x0F00 ) >> 8;
105  uint8_t data = value & 0x00FF;
106 
107  return data;
108 }
109 
110 
111 //------------------------------------------------------------------------------
113 {
114  LOG(logINFO) << "PixTestShowIana::doTest() " ;
115 
116  fDirectory->cd();
117  fHistList.clear();
118  PixTest::update();
119 
120  TH1D* h1 = new TH1D(
121  Form( "iatb_vs_vana_roc_%02d",0),
122  Form( "iatb vs vana roc %2d",0),
123  256, 0,256) ;
124  h1->SetMinimum(0);
125  TH1D* h2 = new TH1D(
126  Form( "iaroc_vs vana_roc_%02d",0),
127  Form( "iaroc vs vana roc %2d",0),
128  256, 0,256) ;
129  h2->SetMinimum(0);
130 
131 
132  uint8_t savedvana = fApi->_dut->getDAC( 0, "Vana" );
133  fApi->_dut->maskAllPixels(true);
134 
135  //size_t nRocs = fPixSetup->getConfigParameters()->getNrocs();
136  vector<uint8_t> dac2save;
137 
138  fApi->daqStart();
139 
140  for(int dacvalue=0; dacvalue<=256; dacvalue++){
141  fApi->setDAC("Vana", dacvalue);
142  double ia1 = fApi->getTBia()*1e3;
143  double ia=0;
144  int n=0;
145  for(;n<10; n++){
146  ia = fApi->getTBia()*1e3;
147  if ( TMath::Abs(ia-ia1) < 1 ) break;
148  ia1=ia;
149  }
150 
151 
152  int ia2 = readRocADC( 12 );
153  h1->SetBinContent( dacvalue, ia);
154  h2->SetBinContent( dacvalue, ia2);
155  }
156 
157  fApi->daqStop();
158 
159  // plot:
160 
161  fHistList.push_back(h1);
162  fHistList.push_back(h2);
163 
164  h1->Draw();
165  h2->Draw();
166  PixTest::update();
167  fDisplayedHist = find( fHistList.begin(), fHistList.end(), h1 );
168 
169  // restore the previous state
170  fApi->setDAC( "Vana", savedvana );
171 }
172 
bool daqStart()
Definition: api.cc:1139
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
Definition: api.cc:546
void maskAllPixels(bool mask, uint8_t rocid)
Definition: dut.cc:481
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
dut * _dut
Definition: api.h:728
void doTest()
function connected to "DoTest" button of PixTab
bool daqStop()
Definition: api.cc:1324
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
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
std::vector< Event > daqGetEventBuffer()
Definition: api.cc:1285
uint16_t daqTrigger(uint32_t nTrig=1, uint16_t period=0)
Definition: api.cc:1222
void init()
sets all test parameters
Definition: PixTest.cc:62