pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestSetCalDel.cc
1 // -- author: Daniel Pitzl
2 // set good CalDel for each ROC
3 
4 #include <stdlib.h> // atof, atoi
5 #include <algorithm> // std::find
6 #include <iostream> // cout
7 #include <iomanip> // setw
8 
9 #include <TH1.h>
10 
11 #include "PixTestSetCalDel.hh"
12 #include "log.h"
13 
14 
15 using namespace std;
16 using namespace pxar;
17 
18 ClassImp(PixTestSetCalDel)
19 
20 //------------------------------------------------------------------------------
21 PixTestSetCalDel::PixTestSetCalDel( PixSetup *a, std::string name) :
22 PixTest(a, name), fParNtrig(-1)
23 {
24  PixTest::init();
25  init();
26  // LOG(logINFO) << "PixTestSetCalDel ctor(PixSetup &a, string, TGTab *)";
27  for( unsigned int i = 0; i < fPIX.size(); ++i) {
28  LOG(logDEBUG) << " PixTestSetCalDel setting fPIX" << i
29  << " ->" << fPIX[i].first
30  << "/" << fPIX[i].second;
31  }
32 }
33 
34 //------------------------------------------------------------------------------
35 PixTestSetCalDel::PixTestSetCalDel() : PixTest() {
36  // LOG(logINFO) << "PixTestSetCalDel ctor()";
37 }
38 
39 //------------------------------------------------------------------------------
40 bool PixTestSetCalDel::setParameter(string parName, string sval) {
41  bool found(false);
42  string str1, str2;
43  string::size_type s1;
44  int pixc, pixr;
45  for (unsigned int i = 0; i < fParameters.size(); ++i) {
46  if (fParameters[i].first == parName) {
47  found = true;
48  sval.erase( remove( sval.begin(), sval.end(), ' '), sval.end() );
49  if( !parName.compare("ntrig") ) {
50  fParNtrig = atoi( sval.c_str() );
51  LOG(logDEBUG) << " PixTestSetCalDel setting fParNtrig ->" << fParNtrig
52  << "<- from sval = " << sval;
53  }
54  if( !parName.compare("pix1") ) {
55  s1 = sval.find(",");
56  if( string::npos != s1) {
57  str1 = sval.substr(0, s1);
58  pixc = atoi(str1.c_str());
59  str2 = sval.substr(s1+1);
60  pixr = atoi(str2.c_str());
61  fPIX.push_back( make_pair(pixc, pixr) );
62  }
63  else {
64  fPIX.push_back( make_pair(-1, -1) );
65  }
66  }
67  // FIXME: remove/update from fPIX if the user removes via the GUI!
68  break;
69  }
70  }
71  return found;
72 }
73 
74 //------------------------------------------------------------------------------
75 void PixTestSetCalDel::init()
76 {
77  setToolTips();
78  fDirectory = gFile->GetDirectory( fName.c_str() );
79  if( !fDirectory ) {
80  fDirectory = gFile->mkdir( fName.c_str() );
81  }
82  fDirectory->cd();
83 }
84 
85 //------------------------------------------------------------------------------
87 {
88  fTestTip = string( "scan and set CalDel using one pixel");
89  fSummaryTip = string("summary plot to be implemented");
90 }
91 
92 //------------------------------------------------------------------------------
93 void PixTestSetCalDel::bookHist(string name) {
94  fDirectory->cd();
95 
96  TH1D *h1(0);
97  fHistList.clear();
98 
99  for( unsigned int i = 0; i < fPixSetup->getConfigParameters()->getNrocs(); ++i ) {
100 
101  for( unsigned int ip = 0; ip < fPIX.size(); ++ip ) {
102  h1 = new TH1D(Form("NhitsVs%s_c%d_r%d_C%d", name.c_str(), fPIX[ip].first, fPIX[ip].second, i),
103  Form("NhitsVs%s_c%d_r%d_C%d", name.c_str(), fPIX[ip].first, fPIX[ip].second, i),
104  256, -0.5, 255.5 );
105  h1->SetMinimum(0.);
106  setTitles( h1, Form( "%s [DAC]", name.c_str() ), "readouts" );
107  fHistList.push_back(h1);
108  }
109  }
110 }
111 
112 //------------------------------------------------------------------------------
113 PixTestSetCalDel::~PixTestSetCalDel() {
114  LOG(logDEBUG) << "PixTestSetCalDel dtor";
115 }
116 
117 //------------------------------------------------------------------------------
119  fDirectory->cd();
120  PixTest::update();
121  LOG(logINFO) << "PixTestSetCalDel::doTest() ntrig = " << fParNtrig;
122  //FIXME clearHist();
123  // -- FIXME: Should/could separate better test from display?
124 
125  fApi->_dut->testAllPixels(false);
126  for( unsigned int i = 0; i < fPIX.size(); ++i) {
127  if( fPIX[i].first > -1) fApi->_dut->testPixel(fPIX[i].first, fPIX[i].second, true);
128  }
129 
130  bookHist("caldel");
131 
132  string DacName = "caldel";
133 
134  vector <pair <uint8_t, vector<pixel> > > results =
135  fApi->getEfficiencyVsDAC( DacName, 0, 255, 0, fParNtrig ); // dac, pixels
136 
137  LOG(logDEBUG) << " dacscandata.size(): " << results.size();
138 
139  TH1D *h(0);
140 
141  int i0[16] = {0};
142  int i9[16] = {0};
143  int nm[16] = {0};
144 
145  for( unsigned int i = 0; i < results.size(); ++i ) { // dac values
146 
147  pair<uint8_t, vector<pixel> > v = results[i];
148  int caldel = v.first;
149 
150  vector<pixel> vpix = v.second; // pixels from all rocs
151 
152  for( unsigned int ipx = 0; ipx < vpix.size(); ++ipx ) {
153 
154  int roc = vpix.at(ipx).roc();
155 
156  int nn = (int)vpix.at(ipx).value();
157 
158  if( nn > nm[roc] ) {
159  nm[roc] = nn;
160  i0[roc] = caldel; // begin of plateau
161  }
162  if( nn == nm[roc] )
163  i9[roc] = caldel; // end of plateau
164 
165  h = (TH1D*)fDirectory->Get( Form( "NhitsVs%s_c%d_r%d_C%d",
166  DacName.c_str(), vpix.at(ipx).column(), vpix.at(ipx).row(), roc ) );
167 
168  if( h ) {
169  h->Fill( caldel, nn );
170  }
171  else {
172  LOG(logDEBUG) << "XX did not find "
173  << Form( "NhitsVs%s_c%d_r%d_C%d",
174  DacName.c_str(), vpix.at(ipx).column(), vpix.at(ipx).row(), roc );
175  }
176  } // pixels and rocs
177  } // caldel vals
178 
179  for( list<TH1*>::iterator il = fHistList.begin(); il != fHistList.end(); ++il ) {
180  (*il)->Draw();
181  PixTest::update();
182  }
183  fDisplayedHist = fHistList.end();
184 
185  //h = (TH1D*)(*fHistList.begin() );
186  //h->Draw();
187 
188  for( unsigned int roc = 0; roc < fPixSetup->getConfigParameters()->getNrocs(); ++roc ) {
189 
190  LOG(logINFO) << "ROC " << setw(2) << roc
191  << ": eff plateau from " << setw(3) << i0[roc]
192  << " to " << setw(3) << i9[roc];
193  if( i9[roc] > 0 ) {
194  int i2 = i0[roc] + (i9[roc]-i0[roc])/4;
195  fApi->setDAC( DacName, i2, roc );
196  LOG(logINFO) << "ROC " << setw(2) << roc
197  << ": set CalDel to " << i2;
198  }
199  } // rocs
200 }
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
std::vector< std::pair< int, int > > fPIX
range of enabled pixels for time-consuming tests
Definition: PixTest.hh:311
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 setToolTips()
implement this to provide updated tool tips if the user changes test parameters
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
void doTest()
function connected to "DoTest" button of PixTab
std::vector< std::pair< uint8_t, std::vector< pixel > > > getEfficiencyVsDAC(std::string dacName, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
Definition: api.cc:733
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
void update()
signal to PixTab to update the canvas
Definition: PixTest.cc:569
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
void init()
sets all test parameters
Definition: PixTest.cc:62