8 #include "PixTestSetTrim.hh"
18 :
PixTest(a, name), fParVcal(-1), fParNtrig(-1)
22 LOG(logDEBUG) <<
"PixTestSetTrim ctor(PixSetup &a, string, TGTab *)";
26 PixTestSetTrim::PixTestSetTrim() :
PixTest()
28 LOG(logDEBUG) <<
"PixTestSetTrim ctor()";
36 for( uint32_t i = 0; i <
fParameters.size(); ++i ) {
42 sval.erase(
remove(sval.begin(), sval.end(),
' '), sval.end());
44 if( !parName.compare(
"targetvcal" ) )
45 fParVcal = atoi( sval.c_str() );
47 if( !parName.compare(
"ntrig" ) )
48 fParNtrig = atoi( sval.c_str() );
58 void PixTestSetTrim::init()
60 LOG(logDEBUG) <<
"PixTestSetTrim::init()";
62 fDirectory = gFile->GetDirectory( fName.c_str() );
72 fTestTip = string(
"set Vtrim and trim bits to get TargetVcal threshold")
74 fSummaryTip = string(
"summary plot to be implemented")
80 void PixTestSetTrim::bookHist(
string name)
82 LOG(logDEBUG) <<
"nothing done with " << name;
86 PixTestSetTrim::~PixTestSetTrim()
88 LOG(logDEBUG) <<
"PixTestSetTrim dtor";
89 std::list<TH1*>::iterator il;
92 LOG(logINFO) <<
"Write out " << (*il)->GetName();
101 void PixTestSetTrim::RocThrMap( uint8_t roc, uint32_t nTrig,
102 bool xtalk,
bool cals )
105 LOG(logERROR) <<
"[PixTestSetTrim::RocThrMap] invalid roc " << roc;
111 for( uint8_t col = 0; col < 52; ++col )
112 for( uint8_t row = 0; row < 80; ++row ) {
113 uint8_t trim = modtrm[roc][col][row];
120 uint16_t flags = FLAG_RISING_EDGE;
121 if( xtalk ) flags |= FLAG_XTALK;
122 if( cals ) flags |= FLAG_CALS;
126 LOG(logINFO) <<
"vpix.size() " << vpix.size();
133 static uint32_t iter = 0;
135 h2 =
new TH2D( Form(
"Threshold_map_ROC_%d_i%i",
int(roc), iter ),
136 Form(
"Threshold map ROC %d i%i",
int(roc), iter ),
137 52, -0.5, 51.5, 80, -0.5, 79.5 );
141 h2->GetZaxis()->SetTitle(
"Vcal threshold [DAC]" );
145 h1 =
new TH1D( Form(
"ThrDistribution_C%d_i%i",
int(roc), iter ),
146 Form(
"Threshold distribution ROC %d i%i",
int(roc), iter ),
148 setTitles( h1,
"Vcal threshold [DAC]",
"pixels" );
154 for(
size_t ipx = 0; ipx < vpix.size(); ++ipx ) {
155 if( vpix[ipx].roc() == roc ) {
156 h2->Fill( vpix[ipx].column(), vpix[ipx].row(), vpix[ipx].value());
157 h1->Fill( vpix[ipx].value());
158 if( vpix[ipx].column() < 52 && vpix[ipx].row() < 80 )
159 modthr[roc][vpix[ipx].column()][vpix[ipx].row()] = (uint8_t)vpix[ipx].value();
177 void PixTestSetTrim::printThrMap( uint8_t roc,
int &nok )
189 cout <<
"Threshold map for ROC " << roc << endl;
190 for(
int row = 79; row >= 0; --row ) {
191 cout << setw(2) << row <<
":";
192 for(
int col = 0; col < 52; ++col ) {
194 int thr = modthr[roc][col][row];
196 if( col == 25 ) cout << endl <<
" ";
203 if( thr > 0 && thr < vmin ) {
208 if( thr > vmax && thr < 255 ) {
217 cout <<
"valid thresholds " << nok << endl;
219 cout <<
"min thr " << vmin <<
" at " << colmin <<
" " << rowmin << endl;
220 cout <<
"max thr " << vmax <<
" at " << colmax <<
" " << rowmax << endl;
221 double mid = (double)sum / (
double) nok;
222 double rms = sqrt( (
double)su2 / (
double)nok - mid*mid );
223 cout <<
"mean thr " << mid
234 void PixTestSetTrim::TrimStep(
int roc,
int target,
int correction,
235 int nTrig,
int xtalk,
int cals )
237 LOG(logINFO) <<
"TrimStep for ROC " << roc
238 <<
" with correction " << correction;
240 for(
int col = 0; col < 52; ++col ) {
241 for(
int row = 0; row < 80; ++row ) {
243 int thr = modthr[roc][col][row];
244 rocthr[col][row] = thr;
246 int trim = modtrm[roc][col][row];
247 roctrm[col][row] = trim;
249 if( thr > target && thr < 255 )
254 if( trim < 0 ) trim = 0;
255 if( trim > 15 ) trim = 15;
257 modtrm[roc][col][row] = trim;
264 RocThrMap( roc, nTrig, xtalk, cals );
266 for(
int col = 0; col < 52; ++col ) {
267 for(
int row = 0; row < 80; ++row ) {
269 int thr = modthr[roc][col][row];
271 int old = rocthr[col][row];
273 if( abs( thr - target ) > abs( old - target ) ) {
274 modtrm[roc][col][row] = roctrm[col][row];
275 modthr[roc][col][row] = old;
286 LOG(logINFO) <<
"PixTestSetTrim::doTest() ntrig = " << fParNtrig;
294 for(
size_t k = 0; k < 16; ++k )
295 for(
size_t i = 0; i < 52; ++i )
296 for(
size_t j = 0; j < 80; ++j ){
297 modthr[k][i][j] = 255;
298 modtrm[k][i][j] = 15;
301 size_t nRocs =
fPixSetup->getConfigParameters()->getNrocs();
304 uint16_t flags = FLAG_RISING_EDGE;
311 LOG(logINFO) <<
"CtrlReg 0 (small Vcal)";
313 for(
size_t roc = 0; roc < nRocs; ++roc ) {
315 LOG(logINFO) <<
"Trimming ROC " << roc;
319 RocThrMap( roc, fParNtrig, xtalk, cals );
327 for(
int row = 79; row >= 0; --row ) {
328 for(
int col = 0; col < 52; ++col ) {
330 int thr = modthr[roc][col][row];
331 if( thr > vmax && thr < 255 ) {
340 LOG(logWARNING) <<
"No valid threshold on ROC " << roc <<
": skipped";
343 LOG(logINFO) <<
"max thr " << vmax
344 <<
" at " << maxcol <<
" " << maxrow;
356 for( ; itrim < 254; itrim += 2 ) {
361 for(
size_t ipx = 0; ipx < vpix9.size(); ++ipx )
362 if( vpix9[ipx].roc() == roc &&
363 vpix9[ipx].column() == maxcol &&
364 vpix9[ipx].row() == maxrow )
365 thr = (
int)vpix9[ipx].value();
368 <<
"Vtrim " << setw(3) << itrim
369 <<
": vpix9.size " << vpix9.size()
370 <<
": " << (int) vpix9[0].roc()
371 <<
" " << (int) vpix9[0].column()
372 <<
" " << (int) vpix9[0].row()
373 <<
", thr " << setw(3) << thr;
381 LOG(logINFO) <<
"set Vtrim to " << itrim;
386 for(
int row = 79; row >= 0; --row )
387 for(
int col = 0; col < 52; ++col ) {
388 modtrm[roc][col][row] = 7;
389 rocthr[col][row] = modtrm[roc][col][row];
390 roctrm[col][row] = 15;
393 LOG(logINFO) <<
"trim: measuring Vcal threshold map with trim 7";
395 RocThrMap( roc, fParNtrig, xtalk, cals );
397 printThrMap( roc, nok );
401 TrimStep( roc, fParVcal, correction,
402 fParNtrig, xtalk, cals );
404 printThrMap( roc, nok );
408 TrimStep( roc, fParVcal, correction,
409 fParNtrig, xtalk, cals );
411 printThrMap( roc, nok );
415 TrimStep( roc, fParVcal, correction,
416 fParNtrig, xtalk, cals );
418 printThrMap( roc, nok );
422 TrimStep( roc, fParVcal, correction,
423 fParNtrig, xtalk, cals );
425 printThrMap( roc, nok );
429 TrimStep( roc, fParVcal, correction,
430 fParNtrig, xtalk, cals );
432 printThrMap( roc, nok );
440 LOG(logINFO) <<
"back to Vcal " << int(cal);
441 LOG(logINFO) <<
"back to CtrlReg " << int(ctl);
443 LOG(logINFO) <<
"PixTestSetTrim::doTest() done for " << nRocs <<
" ROCs";
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
PixSetup * fPixSetup
all necessary stuff in one place
void doTest()
function connected to "DoTest" button of PixTab
void testPixel(uint8_t column, uint8_t row, bool enable)
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
bool updateTrimBits(std::vector< pixelConfig > trimming, uint8_t rocid)
TDirectory * fDirectory
where the root histograms will end up
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
std::vector< pixel > getThresholdMap(std::string dacName, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
void testAllPixels(bool enable)
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
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
void update()
signal to PixTab to update the canvas
uint8_t getDAC(size_t rocId, std::string dacName)
pxar::pxarCore * fApi
pointer to the API
void init()
sets all test parameters