pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestThreshMap.cc
1 #include <stdlib.h> /* atof, atoi */
2 #include <algorithm> // std::find
3 #include <iostream>
4 #include "PixTestThreshMap.hh"
5 #include "log.h"
6 
7 #include <TH2.h>
8 
9 using namespace std;
10 using namespace pxar;
11 
12 ClassImp(PixTestThreshMap)
13 
14 // ----------------------------------------------------------------------
15 PixTestThreshMap::PixTestThreshMap(PixSetup *a, std::string name) : PixTest(a, name) {
16  PixTest::init();
17  init();
18  LOG(logDEBUG) << "PixTestThreshMap ctor(PixSetup &a, string, TGTab *)";
19 }
20 
21 
22 //----------------------------------------------------------
23 PixTestThreshMap::PixTestThreshMap() : PixTest() {
24  LOG(logDEBUG) << "PixTestThreshMap ctor()";
25 }
26 
27 // ----------------------------------------------------------------------
28 bool PixTestThreshMap::setParameter(string parName, string sval) {
29  bool found(false);
30  string stripParName;
31  std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
32  for (unsigned int i = 0; i < fParameters.size(); ++i) {
33  if (fParameters[i].first == parName) {
34  found = true;
35 
36  LOG(logDEBUG) << " ==> parName: " << parName;
37  LOG(logDEBUG) << " ==> sval: " << sval;
38  if (!parName.compare("dac")) {
39  fParDac = sval.c_str();
40  setToolTips();
41  }
42  if (!parName.compare("ntrig")) {
43  fParNtrig = static_cast<uint16_t>(atoi(sval.c_str()));
44  setToolTips();
45  }
46  if (!parName.compare("thresholdpercent")) {
47  fParThresholdLevel = static_cast<uint8_t>(atoi(sval.c_str()));
48  setToolTips();
49  }
50  if (!parName.compare("daclo")) {
51  fParLoDAC = static_cast<uint16_t>(atoi(sval.c_str()));
52  setToolTips();
53  }
54  if (!parName.compare("dachi")) {
55  fParHiDAC = static_cast<uint16_t>(atoi(sval.c_str()));
56  setToolTips();
57  }
58  if (!parName.compare("stepsize")) {
59  fParStepSize = static_cast<uint16_t>(atoi(sval.c_str()));
60  setToolTips();
61  }
62  if (!parName.compare("risingedge")) {
63  fParRisingEdge = atoi(sval.c_str()) != 0;
64  setToolTips();
65  }
66  if (!parName.compare("cals")) {
67  fParCalS = atoi(sval.c_str()) != 0;
68  setToolTips();
69  }
70  break;
71  }
72  }
73  return found;
74 }
75 
76 
77 // ----------------------------------------------------------------------
78 void PixTestThreshMap::init() {
79  LOG(logINFO) << "PixTestThreshMap::init()";
80 
81  setToolTips();
82  fDirectory = gFile->GetDirectory(fName.c_str());
83  if (!fDirectory) {
84  fDirectory = gFile->mkdir(fName.c_str());
85  }
86  fDirectory->cd();
87 
88 }
89 
90 // ----------------------------------------------------------------------
92  fTestTip = string("send Ntrig \"calibrates\" and count how many hits were measured\n")
93  + string("the result is a hitmap, not an efficiency map")
94  ;
95  fSummaryTip = string("all ROCs are displayed side-by-side. Note the orientation:\n")
96  + string("the canvas bottom corresponds to the narrow module side with the cable")
97  ;
98 }
99 
100 
101 // ----------------------------------------------------------------------
102 void PixTestThreshMap::bookHist(string name) {
103  fDirectory->cd();
104  LOG(logDEBUG) << "nothing done with " << name;
105 }
106 
107 
108 //----------------------------------------------------------
109 PixTestThreshMap::~PixTestThreshMap() {
110  LOG(logDEBUG) << "PixTestThreshMap dtor";
111 }
112 
113 
114 // ----------------------------------------------------------------------
116  PixTest::update();
117  fDirectory->cd();
118  LOG(logINFO) << "PixTestThreshMap::doTest() ntrig = " << int(fParNtrig);
119  PixTest::update();
120 
121  fDirectory->cd();
122  vector<TH2D*> maps;
123  vector<TH1D*> hResults;
124  TH2D *h2(0);
125  string name("Thresh");
126 
127  vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
128 
129  for (unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
130  id2idx.insert(make_pair(rocIds[iroc], iroc));
131  std::string rising = (fParRisingEdge ? "Rising" : "Falling");
132  std::string cals = (fParCalS ? "_CalS" : "");
133  h2 = bookTH2D(Form("%s_C%d", name.c_str(), iroc), Form("%s%d_%s_%s%s_C%d", name.c_str(), fParThresholdLevel, fParDac.c_str(), rising.c_str(), cals.c_str(), rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
134  h2->SetMinimum(0.);
135  h2->SetDirectory(fDirectory);
136  setTitles(h2, "col", "row");
137  maps.push_back(h2);
138  }
139 
140  fApi->_dut->testAllPixels(true);
141  fApi->_dut->maskAllPixels(false);
142 
143  LOG(logINFO) << "Recording Threshold Map...";
144  uint16_t flags = 0;
145  if(fParRisingEdge) flags |= FLAG_RISING_EDGE;
146  if(fParCalS) flags |= FLAG_CALS;
147  std::vector<pixel> results = fApi->getThresholdMap(fParDac, fParStepSize, fParLoDAC,fParHiDAC,fParThresholdLevel,flags, fParNtrig);
148 
149  LOG(logINFO) << "Pixels returned: " << results.size();
150 
151  for(std::vector<pixel>::size_type idx = 0; idx < results.size() ; idx++) {
152  maps[id2idx[results[idx].roc()]]->SetBinContent(results[idx].column()+1,results[idx].row()+1,results[idx].value());
153  }
154 
155  for (unsigned int i = 0; i < maps.size(); ++i) {
156  fHistOptions.insert(make_pair(maps[i], "colz"));
157  }
158 
159  copy(maps.begin(), maps.end(), back_inserter(fHistList));
160 
161  TH2D *h = (TH2D*)(fHistList.back());
162  h->Draw(getHistOption(h).c_str());
163  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h);
164 
165  PixTest::update();
166  LOG(logINFO) << "PixTestThreshMap::doTest() done";
167 }
168 
169 
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
Definition: PixTest.hh:308
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
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 setToolTips()
implement this to provide updated tool tips if the user changes test parameters
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
void doTest()
function connected to "DoTest" button of PixTab
virtual std::string getHistOption(TH1 *)
get the hist display options (if stored in fHistOptions)
Definition: PixTest.cc:941
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
TH2D * bookTH2D(std::string sname, std::string title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double max)
book a TH2D, adding version information to the name and title
Definition: PixTest.cc:903
void update()
signal to PixTab to update the canvas
Definition: PixTest.cc:569
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
void init()
sets all test parameters
Definition: PixTest.cc:62