pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestBB2Map.cc
1 // -- author: A.Vargas, D.Pitzl
2 // Bump Bonding tests,
3 // sending test-pulse through the sensor (cals), a scan of vthrcomp for all pixels is performed.
4 // The width of the plateau is used to distinguish between
5 // good/dead/bad bump-bonding
6 
7 
8 #include <sstream> // parsing
9 #include <algorithm> // std::find
10 
11 #include "TStopwatch.h"
12 
13 #include "PixTestBB2Map.hh"
14 #include "PixUtil.hh"
15 #include "log.h"
16 #include "constants.h" // roctypes
17 
18 using namespace std;
19 using namespace pxar;
20 
21 ClassImp(PixTestBB2Map)
22 
23 //------------------------------------------------------------------------------
24 PixTestBB2Map::PixTestBB2Map(PixSetup *a, std::string name): PixTest(a, name), fParNtrig(10), fParVcalS(222), fParPlWidth(35) {
25  PixTest::init();
26  init();
27  LOG(logDEBUG) << "PixTestBB2Map ctor(PixSetup &a, string, TGTab *)";
28 }
29 
30 
31 //------------------------------------------------------------------------------
32 PixTestBB2Map::PixTestBB2Map(): PixTest() {
33  LOG(logDEBUG) << "PixTestBB2Map ctor()";
34 }
35 
36 
37 
38 //------------------------------------------------------------------------------
39 bool PixTestBB2Map::setParameter(string parName, string sval) {
40 
41  std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
42  for (uint32_t i = 0; i < fParameters.size(); ++i) {
43  if (fParameters[i].first == parName) {
44  sval.erase(remove(sval.begin(), sval.end(), ' '), sval.end());
45 
46  stringstream s(sval);
47  if (!parName.compare( "ntrig")) {
48  s >> fParNtrig;
49  setToolTips();
50  return true;
51  }
52  if (!parName.compare( "vcals")) {
53  s >> fParVcalS;
54  setToolTips();
55  return true;
56  }
57  if (!parName.compare( "Plwidth")) {
58  s >> fParPlWidth;
59  setToolTips();
60  return true;
61  }
62  }
63  }
64  return false;
65 }
66 
67 //------------------------------------------------------------------------------
68 void PixTestBB2Map::init() {
69  LOG(logDEBUG) << "PixTestBB2Map::init()";
70 
71  fDirectory = gFile->GetDirectory( fName.c_str() );
72  if( !fDirectory ) {
73  fDirectory = gFile->mkdir( fName.c_str() );
74  }
75  fDirectory->cd();
76 }
77 
78 // ----------------------------------------------------------------------
80  fTestTip = string( "Bump Bonding Test = threshold map for CalS");
81  fSummaryTip = string("module summary");
82 }
83 
84 
85 //------------------------------------------------------------------------------
86 PixTestBB2Map::~PixTestBB2Map() {
87  LOG(logDEBUG) << "PixTestBB2Map dtor";
88 }
89 
90 //------------------------------------------------------------------------------
92 
93  TStopwatch t;
94 
95  cacheDacs();
97  bigBanner(Form("PixTestBB2Map::doTest() Ntrig = %d, VcalS = %d, PlWidth = %d", fParNtrig, fParVcalS, fParPlWidth));
98 
99  fDirectory->cd();
100 
101  fApi->_dut->testAllPixels(true);
102  fApi->_dut->maskAllPixels(false);
103 
104  int flag(FLAG_CALS);
105  fApi->setDAC("ctrlreg", 4); // high range
106  fApi->setDAC("vcal", fParVcalS);
107 
108  //int result(7);
109 
110  // enable roc
111 
112  uint16_t FLAGS0 = flag | FLAG_FORCE_MASKED;
113 
114  vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
115 
116  // loop over roc-s
117 
118  for (unsigned int idx = 0; idx < rocIds.size(); ++idx){
119 
120  unsigned int rocId = getIdFromIdx(idx);
121 
122  vector<pair<uint8_t, vector<pixel> > > results_bbmap;
123  results_bbmap = fApi->getEfficiencyVsDAC("VthrComp", 0, 250, FLAGS0, fParNtrig);
124 
125  // display the quantities:
126  int ic, ir, iroc;
127  double val;
128 
129  // Define the 2D-Histogram
130  // "N_DAC%02i_CR%i_Vcal%03i_ma
131  // Form("%s_%i_%s", "N_DAC12_CR4_Vcal",fParVcalS,"map")
132 
133 
134  TH2D *h22 = new TH2D(Form("h22_C%d", rocId),Form("h22_C%d",rocId), 4160, -0.5, 4160 - 0.5, 250, -0.5, 249.5 );
135  h22->SetTitle(Form("%s_%i_%s", "N_DAC12_CR4_Vcal",fParVcalS,"map"));
136  fHistOptions.insert(make_pair(h22, "colz"));
137  setTitles(h22, "Pixel 80*ic+ir", "VthrComp");
138 
139  for (unsigned int idac = 0; idac < results_bbmap.size(); ++idac) {
140  int dac = results_bbmap[idac].first;
141  for (unsigned int ipix = 0; ipix < results_bbmap[idac].second.size(); ++ipix) {
142  ic = results_bbmap[idac].second[ipix].column();
143  ir = results_bbmap[idac].second[ipix].row();
144  iroc = results_bbmap[idac].second[ipix].roc();
145  if (ic > 51 || ir > 79) {
146  continue;
147  }
148  val = results_bbmap[idac].second[ipix].value();
149  h22->Fill(80 * ic + ir, dac, val);
150  //cout << "dac: " << dac << " ic: " << ic << " ir: " << ir << " iroc: " << iroc << " val: " << val << " "<< 80*ic + ir << endl;
151  }
152  }
153 
154  fHistList.push_back(h22);
155 
156  // Find from the previous scan [h22] the missing bumps
157  // output save in:
158 
159  TH1D *h12 = new TH1D( Form("CalsVthrPlateauWidth_C%d",rocId),
160  "Width of VthrComp plateau for cals;width of VthrComp plateau for cals [DAC];pixels",
161  101, -0.5, 100.5 );
162 
163  TH2D *h24 = new TH2D( Form("BBtestMap_C%d",rocId),
164  "BBtest map;col;row;max responses",
165  52, -0.5, 51.5, 80, -0.5, 79.5 );
166  fHistOptions.insert(make_pair(h24, "colz"));
167  setTitles(h24, "col", "row");
168 
169  int nbinx = h22->GetNbinsX( );
170  int nbiny = h22->GetNbinsY( );
171 
172  int nActive;
173  int nMissing;
174  int nIneff;
175 
176  nActive = 0;
177  nMissing = 0;
178  nIneff = 0;
179 
180  int ibinCenter;
181 
182  // Find Plateau
183 
184  for( int ibin = 1; ibin <= nbinx; ibin++ ) {
185 
186  ibinCenter = h22->GetXaxis( )->GetBinCenter( ibin );
187 
188  // Find first the maximum
189  int imax;
190  imax = 0;
191  for( int j = 1; j <= nbiny; ++j ) {
192  int cnt = h22->GetBinContent( ibin, j );
193  // Find Maximum
194  if( cnt > imax )
195  imax = cnt;
196  }
197 
198  if( imax < fParNtrig / 2 ) {
199  ++nIneff;
200  cout << "Dead pixel at raw col: " << ibinCenter % 80
201  << " " << ibinCenter / 80 << endl;
202  }
203  else {
204 
205  // Search for the Plateau
206 
207  int iEnd = 0;
208  int iBegin = 0;
209 
210  // use the maximum response to localize the Plateau
211  for( int jbin = 0; jbin <= nbiny; jbin++ ) {
212  int cnt = h22->GetBinContent( ibin, jbin );
213  // Find Plateau
214  if( cnt >= imax / 2 ) {
215  iEnd = jbin; // end of plateau
216  if( iBegin == 0 )
217  iBegin = jbin; // begin of plateau
218  }
219  }
220 
221  // cout << "Bin: " << ibin << " Plateau Begins and End in " << iBegin << " - " << iEnd << endl;
222  // narrow plateau is from noise
223 
224  h12->Fill( iEnd - iBegin );
225  // plateau Size
226  if( iEnd - iBegin < fParPlWidth ) {
227 
228  nMissing++;
229  cout << "[Missing Bump at raw col:] " << ibinCenter% 80 << " " << ibinCenter / 80 << endl;
230  // with weight 2 to draw it as red
231  h24->Fill( ibinCenter / 80, ibinCenter % 80, 2 );
232  }
233  else {
234  //h24->Fill( ibinCenter / 80, ibinCenter % 80, imax );
235  // draw this pixel green
236  h24->Fill( ibinCenter / 80, ibinCenter % 80, 1 );
237  nActive++;
238  } // plateau width
239  } // active imax
240  } // x-bins
241 
242  // define the color
243  h24->SetMaximum(2);
244  h24->SetMinimum(0);
245 
246  fHistList.push_back(h12);
247  fHistList.push_back(h24);
248 
249  h22->Draw(getHistOption(h22).c_str());
250 
251  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h22);
252  } // end of loop over rocs
253 
254  restoreDacs();
255  PixTest::update();
256 
257  int seconds = t.RealTime();
258  LOG(logINFO) << "PixTestBB2Map::doTest() done"
259  << (fNDaqErrors>0? Form(" with %d decoding errors: ", static_cast<int>(fNDaqErrors)):"")
260  << ", duration: " << seconds << " seconds";
261 
262 
263 }
264 
265 
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
Definition: PixTest.hh:308
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
Definition: api.cc:546
void doTest()
function connected to "DoTest" button of PixTab
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
void maskAllPixels(bool mask, uint8_t rocid)
Definition: dut.cc:481
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
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
void restoreDacs(bool verbose=false)
restore all DACs
Definition: PixTest.cc:771
dut * _dut
Definition: api.h:728
std::vector< uint8_t > getEnabledRocIDs()
Definition: dut.cc:214
void testAllPixels(bool enable)
Definition: dut.cc:503
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
Definition: PixTest.hh:309
virtual std::string getHistOption(TH1 *)
get the hist display options (if stored in fHistOptions)
Definition: PixTest.cc:941
void cacheDacs(bool verbose=false)
cache all DACs
Definition: PixTest.cc:760
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
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
void init()
sets all test parameters
Definition: PixTest.cc:62
int getIdFromIdx(int idx)
provide the mapping between ROC ID and index
Definition: PixTest.cc:1114