Skip to content

Commit

Permalink
cmd.cpp: work on tunePHmod
Browse files Browse the repository at this point in the history
  • Loading branch information
pitzl committed Feb 12, 2015
1 parent 171f836 commit d7cea46
Showing 1 changed file with 19 additions and 45 deletions.
64 changes: 19 additions & 45 deletions cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11010,6 +11010,8 @@ bool tunePHmod( int col, int row, int roc )

// add: loop over ROCs

tb.roc_I2cAddr( roc );

DacScanPix( roc, col, row, dac, 1, nTrig, nReadouts, PHavg, PHrms );

if( nReadouts.size( ) < 256 ) {
Expand Down Expand Up @@ -11132,14 +11134,7 @@ bool tunePHmod( int col, int row, int roc )
tb.Flush( );

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// check for all pixels

vector < int16_t > nResponses; // size 0
vector < double >QHmax;
vector < double >QHrms;
nResponses.reserve( 4160 ); // size 0, capacity 4160
QHmax.reserve( 4160 );
QHrms.reserve( 4160 );
// check for all pixels:

tb.SetDAC( Vcal, 255 );
tb.Flush( );
Expand All @@ -11153,46 +11148,40 @@ bool tunePHmod( int col, int row, int roc )

ModPixelAlive( nTrig ); // fills modcnt and modamp

size_t j = 0;
double phmax = 0;

for( int col = 0; col < 52; ++col ) {

for( int row = 0; row < 80; ++row ) {

double ph = modamp[roc][col][row] / nTrig;
//cout<< " ph " << ph << endl;
if( ph > phmax ) {
phmax = ph;
colmax = col;
rowmax = row;
if( modcnt[roc][col][row] < nTrig / 2 ) {
cout << "weak pixel " << col << " " << row << endl;
}

++j;
if( j == nReadouts.size( ) )
break;
else {
double ph = 1.0*modamp[roc][col][row] / modcnt[roc][col][row];
if( ph > phmax ) {
phmax = ph;
colmax = col;
rowmax = row;
}
}

} // row

if( j == nReadouts.size( ) )
break;

} // col

cout << "max PH " << phmax << " at " << colmax << " " << rowmax << endl;

if( phmax > 252 && gain < 255 ) {

gain += 1; // reduce gain
tb.roc_I2cAddr( roc );
tb.SetDAC( gaindac, gain );
tb.Flush( );

cout << "gain dac " << dacName[gaindac] << " set to " << gain << endl;

again = 1;
nResponses.clear( );
QHmax.clear( );
QHrms.clear( );

}
else
Expand All @@ -11202,11 +11191,6 @@ bool tunePHmod( int col, int row, int roc )

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// check all pixels for underflow at minVcal:
/*
vector < double >QHmin;
QHmin.reserve( 4160 );
nResponses.clear( );
QHrms.clear( );

tb.SetDAC( Vcal, minVcal );
tb.Flush( );
Expand All @@ -11218,53 +11202,43 @@ bool tunePHmod( int col, int row, int roc )

do { // no underflows

GetRocData( nTrig, nResponses, QHmin, QHrms );
ModPixelAlive( nTrig ); // fills modcnt and modamp

size_t j = 0;
double phmin = 255;

for( int col = 0; col < 52; ++col ) {

for( int row = 0; row < 80; ++row ) {

if( nResponses.at( j ) < nTrig / 2 ) {
if( modcnt[roc][col][row] < nTrig / 2 ) {
cout << "pixel " << col << " " << row << " below threshold at Vcal "
<< minVcal << endl;
}
else {
double ph = QHmin.at( j );
double ph = 1.0*modamp[roc][col][row] / modcnt[roc][col][row];
if( ph < phmin ) {
phmin = ph;
colmin = col;
rowmin = row;
}
}

++j;
if( j == nReadouts.size( ) )
break;
} // row

if( j == nReadouts.size( ) )
break;
} // col

cout << "min PH " << phmin << " at " << colmin << " " << rowmin << endl;

if( phmin < 3 && gain > 0 ) {

gain += 1; // reduce gain
tb.roc_I2cAddr( roc );
tb.SetDAC( gaindac, gain );
tb.Flush( );

cout << "gain dac " << dacName[gaindac] << " set to " << gain << endl;

again = 1;
nResponses.clear( );
QHmin.clear( );
QHrms.clear( );

}
else
Expand All @@ -11275,7 +11249,7 @@ bool tunePHmod( int col, int row, int roc )
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// we have min and max.
// adjust gain and offset such that max-min = 200, mid = 132
/*
again = 0;
do {
Expand Down

0 comments on commit d7cea46

Please sign in to comment.