pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestMapThr.cc
1 // -- author: Daniel Pitzl
2 // threshold map
3 
4 #include <stdlib.h> // atof, atoi
5 #include <algorithm> // std::find
6 
7 #include "PixTestMapThr.hh"
8 #include "log.h"
9 
10 using namespace std;
11 using namespace pxar;
12 
13 ClassImp(PixTestMapThr)
14 
15 //------------------------------------------------------------------------------
16 PixTestMapThr::PixTestMapThr( PixSetup *a, std::string name )
17 : PixTest(a, name), fParNtrig(-1)
18 {
19  PixTest::init();
20  init();
21  LOG(logDEBUG) << "PixTestMapThr ctor(PixSetup &a, string, TGTab *)";
22 }
23 
24 //------------------------------------------------------------------------------
25 PixTestMapThr::PixTestMapThr() : PixTest()
26 {
27  LOG(logDEBUG) << "PixTestMapThr ctor()";
28 }
29 
30 //------------------------------------------------------------------------------
31 bool PixTestMapThr::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 
44  break;
45  }
46  }
47  return found;
48 }
49 
50 //------------------------------------------------------------------------------
51 void PixTestMapThr::init()
52 {
53  LOG(logDEBUG) << "PixTestMapThr::init()";
54 
55  fDirectory = gFile->GetDirectory( fName.c_str() );
56  if( !fDirectory ) {
57  fDirectory = gFile->mkdir( fName.c_str() );
58  }
59  fDirectory->cd();
60 }
61 
62 // ----------------------------------------------------------------------
64 {
65  fTestTip = string( "measure threshold map");
66  fSummaryTip = string("summary plot to be implemented");
67 }
68 
69 //------------------------------------------------------------------------------
70 void PixTestMapThr::bookHist(string name)
71 {
72  LOG(logDEBUG) << "nothing done with " << name;
73 }
74 
75 //------------------------------------------------------------------------------
76 PixTestMapThr::~PixTestMapThr()
77 {
78  LOG(logDEBUG) << "PixTestMapThr dtor";
79  std::list<TH1*>::iterator il;
80  fDirectory->cd();
81  for( il = fHistList.begin(); il != fHistList.end(); ++il ) {
82  LOG(logINFO) << "Write out " << (*il)->GetName();
83  (*il)->SetDirectory(fDirectory);
84  (*il)->Write();
85  }
86 }
87 
88 //------------------------------------------------------------------------------
90 {
91  LOG(logINFO) << "PixTestMapThr::doTest() ntrig = " << fParNtrig;
92 
93  fDirectory->cd();
94  fHistList.clear();
96 
97  if( !fApi ) {
98  LOG(logERROR) << "PixTestMapThr::doTest: no fApi ?!? quit";
99  return;
100  }
101 
102  fApi->_dut->testAllPixels(true); // all pix, all rocs
103 
104  // measure:
105 
106  uint16_t flags = FLAG_RISING_EDGE;
107  vector<pixel> vpix =
108  fApi->getThresholdMap( "Vcal", flags, fParNtrig ); // all pix, all ROCs
109 
110  LOG(logINFO) << "vpix.size() " << vpix.size();
111 
112  // book maps per ROC:
113 
114  vector<TH2D*> maps;
115  TH2D *h2(0);
116  vector<TH1D*> hsts;
117  TH1D *h1(0);
118 
119  size_t nRocs = fPixSetup->getConfigParameters()->getNrocs();
120 
121  for( size_t roc = 0; roc < nRocs; ++roc ) {
122 
123  h2 = new TH2D( Form( "MapThr_C%d", int(roc) ),
124  Form( "Threshold map ROC %d", int(roc) ),
125  52, -0.5, 51.5, 80, -0.5, 79.5 );
126  h2->SetMinimum(0);
127  h2->SetMaximum(256);
128  setTitles( h2, "col", "row" );
129  h2->GetZaxis()->SetTitle( "Vcal threshold [DAC]" );
130  h2->SetStats(0);
131  maps.push_back(h2);
132  fHistList.push_back(h2);
133 
134  h1 = new TH1D( Form( "ThrDistribution_C%d", int(roc) ),
135  Form( "Threshold distribution ROC %d", int(roc) ),
136  256, -0.5, 255.5 );
137  setTitles( h1, "Vcal threshold [DAC]", "pixels" );
138  h1->SetStats(1);
139  hsts.push_back(h1);
140  fHistList.push_back(h1);
141 
142  }
143 
144  // data:
145 
146  for( size_t ipx = 0; ipx < vpix.size(); ++ipx ) {
147  h2 = maps.at(vpix[ipx].roc());
148  if( h2 ) h2->Fill( vpix[ipx].column(), vpix[ipx].row(), vpix[ipx].value());
149  h1 = hsts.at(vpix[ipx].roc());
150  if( h1 ) h1->Fill( vpix[ipx].value());
151  }
152 
153  for( size_t roc = 0; roc < nRocs; ++roc ) {
154  h2 = maps[roc];
155  h2->Draw("colz");
156  PixTest::update();
157  }
158  fDisplayedHist = find( fHistList.begin(), fHistList.end(), h2 );
159 
160  LOG(logINFO) << "PixTestMapThr::doTest() done for " << maps.size() << " ROCs";
161 
162 }
PixSetup * fPixSetup
all necessary stuff in one place
Definition: PixTest.hh:290
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
std::vector< pixel > getThresholdMap(std::string dacName, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
Definition: api.cc:1080
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
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
void doTest()
function connected to "DoTest" button of PixTab
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
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters