pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestMapPh.cc
1 // -- author: Daniel Pitzl
2 // pulse each pixel, plot PH map
3 
4 #include <stdlib.h> // atof, atoi
5 #include <algorithm> // std::find
6 
7 #include "PixTestMapPh.hh"
8 #include "log.h"
9 #include "constants.h"
10 
11 using namespace std;
12 using namespace pxar;
13 
14 ClassImp(PixTestMapPh)
15 
16 //------------------------------------------------------------------------------
17 PixTestMapPh::PixTestMapPh( PixSetup *a, std::string name )
18 : PixTest(a, name), fParNtrig(-1), fParCals(0)
19 {
20  PixTest::init();
21  init();
22  LOG(logDEBUG) << "PixTestMapPh ctor(PixSetup &a, string, TGTab *)";
23 }
24 
25 //------------------------------------------------------------------------------
26 PixTestMapPh::PixTestMapPh() : PixTest()
27 {
28  LOG(logDEBUG) << "PixTestMapPh ctor()";
29 }
30 
31 //------------------------------------------------------------------------------
32 bool PixTestMapPh::setParameter( string parName, string sval )
33 {
34  bool found(false);
35 
36  for( uint32_t i = 0; i < fParameters.size(); ++i ) {
37 
38  if( fParameters[i].first == parName ) {
39 
40  found = true;
41 
42  if( !parName.compare( "ntrig" ) )
43  fParNtrig = atoi( sval.c_str() );
44 
45  if( !parName.compare( "cals" ) )
46  fParCals = atoi( sval.c_str() );
47 
48  break;
49  }
50  }
51  return found;
52 }
53 
54 //------------------------------------------------------------------------------
55 void PixTestMapPh::init()
56 {
57  LOG(logDEBUG) << "PixTestMapPh::init()";
58 
59  fDirectory = gFile->GetDirectory( fName.c_str() );
60  if( !fDirectory) {
61  fDirectory = gFile->mkdir( fName.c_str() );
62  }
63  fDirectory->cd();
64 }
65 
66 // ----------------------------------------------------------------------
68 {
69  fTestTip = string( "measure pulse height map");
70  fSummaryTip = string("summary plot to be implemented");
71 }
72 
73 //------------------------------------------------------------------------------
74 void PixTestMapPh::bookHist(string name)
75 {
76  LOG(logDEBUG) << "nothing done with " << name;
77 }
78 
79 //------------------------------------------------------------------------------
80 PixTestMapPh::~PixTestMapPh()
81 {
82  LOG(logDEBUG) << "PixTestMapPh dtor";
83  std::list<TH1*>::iterator il;
84  fDirectory->cd();
85  for( il = fHistList.begin(); il != fHistList.end(); ++il ) {
86  LOG(logINFO) << "Write out " << (*il)->GetName();
87  (*il)->SetDirectory(fDirectory);
88  (*il)->Write();
89  }
90 }
91 
92 //------------------------------------------------------------------------------
94 {
95  LOG(logINFO) << "PixTestMapPh::doTest() ntrig = " << fParNtrig;
96 
97  fDirectory->cd();
98  fHistList.clear();
100 
101  if( fApi ) fApi->_dut->testAllPixels(true);
102 
103  // measure:
104 
105  uint16_t flags = 0;
106  if( fParCals ) flags = FLAG_CALS;
107  LOG(logINFO) << "flag " << flags;
108 
109  uint8_t ctl = fApi->_dut->getDAC( 0, "CtrlReg" );
110  if( fParCals ) {
111  fApi->setDAC( "CtrlReg", 4 ); // all ROCs large Vcal
112  LOG(logINFO) << "CtrlReg 4 (large Vcal)";
113  }
114 
115  vector<pixel> vpix; // all pixels, all ROCs
116  if( fApi ) vpix = fApi->getPulseheightMap( flags, fParNtrig );
117 
118  if( fParCals ) {
119  fApi->setDAC( "CtrlReg", ctl ); // restore
120  LOG(logINFO) << "back to CtrlReg " << ctl;
121  }
122 
123  LOG(logINFO) << "vpix.size() " << vpix.size();
124 
125  // book maps per ROC:
126 
127  vector<TH2D*> maps;
128  TH2D *h2(0);
129  vector<TH1D*> hsts;
130  TH1D *h1(0);
131 
132  size_t nRocs = fPixSetup->getConfigParameters()->getNrocs();
133 
134  for( size_t roc = 0; roc < nRocs; ++roc ) {
135 
136  h2 = new TH2D( Form( "MapPh_C%d", int(roc) ),
137  Form( "PH map ROC %d", int(roc) ),
138  52, -0.5, 51.5, 80, -0.5, 79.5 );
139  h2->SetMinimum(0);
140  h2->SetMaximum(256);
141  setTitles( h2, "col", "row" );
142  h2->GetZaxis()->SetTitle( "<PH> [ADC]" );
143  h2->SetStats(0);
144  maps.push_back(h2);
145  fHistList.push_back(h2);
146 
147  h1 = new TH1D( Form( "PhDistribution_C%d", int(roc) ),
148  Form( "Pulse height distribution ROC %d", int(roc) ),
149  256, -0.5, 255.5 );
150  setTitles( h1, "<PH> [ADC]", "pixels" );
151  h1->SetStats(1);
152  hsts.push_back(h1);
153  fHistList.push_back(h1);
154  }
155 
156  // data:
157 
158  for( size_t ipx = 0; ipx < vpix.size(); ++ipx ) {
159  h2 = maps.at(vpix[ipx].roc());
160  if( h2 ) h2->Fill( vpix[ipx].column(), vpix[ipx].row(), vpix[ipx].value());
161  h1 = hsts.at(vpix[ipx].roc());
162  if( h1 ) h1->Fill( vpix[ipx].value());
163  }
164 
165  for( size_t roc = 0; roc < nRocs; ++roc ) {
166  h2 = maps[roc];
167  h2->Draw("colz");
168  PixTest::update();
169  }
170  fDisplayedHist = find( fHistList.begin(), fHistList.end(), h2 );
171 
172  LOG(logINFO) << "PixTestMapPh::doTest() done for " << maps.size() << " ROCs";
173 
174 }
std::vector< pixel > getPulseheightMap(uint16_t flags, uint16_t nTriggers)
Definition: api.cc:1024
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
Definition: api.cc:546
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
void doTest()
function connected to "DoTest" button of PixTab
Definition: PixTestMapPh.cc:93
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
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 setToolTips()
implement this to provide updated tool tips if the user changes test parameters
Definition: PixTestMapPh.cc:67
void update()
signal to PixTab to update the canvas
Definition: PixTest.cc:569
uint8_t getDAC(size_t rocId, std::string dacName)
Definition: dut.cc:314
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
Definition: PixTestMapPh.cc:32
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
void init()
sets all test parameters
Definition: PixTest.cc:62