pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestMap.cc
1 // -- author: Daniel Pitzl
2 // pulse each pixel, count responses, plot map, (aka Alive)
3 
4 #include <stdlib.h> // atof, atoi
5 #include <algorithm> // std::find
6 
7 #include "PixTestMap.hh"
8 #include "log.h"
9 
10 using namespace std;
11 using namespace pxar;
12 
13 ClassImp(PixTestMap)
14 
15 //------------------------------------------------------------------------------
16 PixTestMap::PixTestMap( PixSetup *a, std::string name ) :
17 PixTest(a, name), fParNtrig(-1), fParVcal(-1)
18 {
19  PixTest::init();
20  init();
21  LOG(logDEBUG) << "PixTestMap ctor(PixSetup &a, string, TGTab *)";
22 }
23 
24 //------------------------------------------------------------------------------
25 PixTestMap::PixTestMap() : PixTest()
26 {
27  LOG(logDEBUG) << "PixTestMap ctor()";
28 }
29 
30 //------------------------------------------------------------------------------
31 bool PixTestMap::setParameter( string parName, string sval )
32 {
33  bool found(false);
34 
35  for( uint32_t i = 0; i < fParameters.size(); ++i ) {
36 
37  if( fParameters[i].first == parName ) {
38 
39  found = true;
40 
41  if( !parName.compare("ntrig") ) {
42  fParNtrig = atoi(sval.c_str() );
43  setToolTips();
44  }
45 
46  if( !parName.compare("vcal") ) {
47  fParVcal = atoi(sval.c_str() );
48  setToolTips();
49  }
50  break;
51  }
52  }
53  return found;
54 }
55 
56 //------------------------------------------------------------------------------
57 void PixTestMap::init()
58 {
59  LOG(logDEBUG) << "PixTestMap::init()";
60 
61  setToolTips();
62  fDirectory = gFile->GetDirectory(fName.c_str() );
63  if( !fDirectory) {
64  fDirectory = gFile->mkdir(fName.c_str() );
65  }
66  fDirectory->cd();
67 }
68 
69 //------------------------------------------------------------------------------
71 {
72  fTestTip =
73  string("send Ntrig pulses to each pixel and count readouts\n")
74  + string("the result is a hitmap, not an efficiency map")
75  ;
76  fSummaryTip =
77  string("all ROCs are displayed side-by-side. Note the orientation:\n")
78  + string("the canvas bottom corresponds to the narrow module side with the cable")
79  ;
80 }
81 
82 //------------------------------------------------------------------------------
83 void PixTestMap::bookHist(string name)
84 {
85  fDirectory->cd();
86  LOG(logDEBUG) << "nothing done with " << name;
87 }
88 
89 //------------------------------------------------------------------------------
90 PixTestMap::~PixTestMap()
91 {
92  LOG(logDEBUG) << "PixTestMap dtor";
93 }
94 
95 //------------------------------------------------------------------------------
97 {
98  fDirectory->cd();
99  LOG(logINFO) << "PixTestMap::doTest() ntrig = " << fParNtrig;
100  PixTest::update();
101 
102  if( fApi) fApi->_dut->testAllPixels(true);
103 
104  vector<TH2D*> test2 = efficiencyMaps( "PixelMap", fParNtrig ); // PixTest.cc
105 
106  copy( test2.begin(), test2.end(), back_inserter(fHistList) );
107 
108  // ROC summary:
109 
110  TH1D *halive = new TH1D( "MapCount",
111  "Map pixels per ROC;ROC;alive pixels",
112  16, -0.5, 15.5 );
113  halive->SetStats(0); // no stats
114  halive->SetMinimum(0);
115  halive->SetMaximum(4200);
116  fHistList.push_back(halive);
117 
118  TH1D *hperfect = new TH1D( "PerfectCount",
119  "Perfect pixels per ROC;ROC;perfect pixels",
120  16, -0.5, 15.5 );
121  hperfect->SetStats(0); // no stats
122  hperfect->SetMinimum(0);
123  hperfect->SetMaximum(4200);
124  fHistList.push_back(hperfect);
125 
126  TH1D *hdead = new TH1D( "DeadCount",
127  "Dead pixels per ROC;ROC;dead pixels",
128  16, -0.5, 15.5 );
129  hdead->SetStats(0); // no stats
130  hdead->SetMinimum(0);
131  hdead->SetMaximum(4200);
132  fHistList.push_back(hdead);
133 
134  TH2D * h2;
135 
136  for( size_t roc = 0; roc < test2.size(); ++roc ) {
137 
138  h2 = test2.at(roc);
139  h2->Draw("colz");
140  PixTest::update();
141 
142  int dead = 0;
143  int alive = 0;
144  int perfect = 0;
145 
146  for( int ix = 0; ix < h2->GetNbinsX(); ++ix ) {
147  for( int iy = 0; iy < h2->GetNbinsY(); ++iy ) {
148  int nn = int( h2->GetBinContent( ix+1, iy+1 ) + 0.1 );
149  if( nn == 0 ) dead++;
150  if( nn >= fParNtrig/2 ) alive++;
151  if( nn == fParNtrig ) perfect++;
152  }
153  }
154 
155  LOG(logINFO) << "ROC " << setw(2) << roc
156  << " dead " << setw(4) << dead
157  << ", alive " << setw(4) << alive
158  << ", perfect " << setw(4) << perfect;
159 
160  hdead->Fill( roc, dead );
161  halive->Fill( roc, alive );
162  hperfect->Fill( roc, perfect );
163 
164  } // rocs
165 
166  hdead->Draw();
167  halive->Draw();
168  hperfect->Draw();
169 
170  h2 = (TH2D*)(*fHistList.begin() );
171  h2->Draw("colz");
172  fDisplayedHist = find( fHistList.begin(), fHistList.end(), h2 );
173  PixTest::update();
174 
175  LOG(logINFO) << "PixTestMap::doTest() done";
176 }
std::vector< TH2D * > efficiencyMaps(std::string name, uint16_t ntrig=10, uint16_t FLAGS=FLAG_FORCE_MASKED)
returns TH2D's with hit maps
Definition: PixTest.cc:295
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
Definition: PixTestMap.cc:70
void doTest()
function connected to "DoTest" button of PixTab
Definition: PixTestMap.cc:96
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
Definition: PixTest.hh:302
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
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
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
Definition: PixTestMap.cc:31
void update()
signal to PixTab to update the canvas
Definition: PixTest.cc:569
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
void init()
sets all test parameters
Definition: PixTest.cc:62