pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTest.hh
1 #ifndef PIXTEST_H
2 #define PIXTEST_H
3 
7 #include "pxardllexport.h"
8 
9 #ifdef __CINT__
10 #undef __GNUC__
11 typedef char __signed;
12 typedef char int8_t;
13 #endif
14 
15 #include <string>
16 #include <map>
17 #include <list>
18 
19 #include <TQObject.h>
20 #include <TH1.h>
21 #include <TH2.h>
22 #include <TProfile2D.h>
23 #include <TTree.h>
24 #include <TDirectory.h>
25 #include <TFile.h>
26 #include <TSystem.h>
27 #include <TTimeStamp.h>
28 
29 #include "api.h"
30 #include "log.h"
31 
32 #include "PixInitFunc.hh"
33 #include "PixSetup.hh"
34 #include "PixTestParameters.hh"
35 #include "shist256.hh"
36 
37 typedef struct {
38  uint16_t dac;
39  uint16_t header;
40  uint16_t trailer;
41  uint16_t numDecoderErrors;
42  uint16_t npix;
43  uint8_t proc[20000];
44  uint8_t pcol[20000];
45  uint8_t prow[20000];
46  double pval[20000];
47  double pq[20000];
48 } TreeEvent;
49 
50 
65 class DLLEXPORT PixTest: public TQObject {
66 public:
68  PixTest(PixSetup *a, std::string name);
69  PixTest();
70  virtual ~PixTest();
72  void init();
74  void bookHist(std::string name);
76  void bookTree();
78  virtual void doAnalysis();
80  virtual void doTest();
82  virtual void fullTest();
84  virtual void runCommand(std::string command);
86  void saveDacs();
88  void saveTrimBits();
90  void saveTbParameters();
92  std::vector<std::vector<std::pair<int, int> > > deadPixels(int ntrig, bool scanCalDel = false);
94  void maskPixels();
96  bool testProblem() {return fProblem;}
97 
99  virtual void setToolTips();
101  virtual std::string getStopTip() {return fStopTip;}
103  virtual std::string getSummaryTip() {return fSummaryTip;}
105  virtual std::string getTestTip() {return fTestTip;}
107  virtual std::string getHistOption(TH1*);
108 
110  int pixelThreshold(std::string dac, int ntrig, int dacmin, int dacmax);
112  void dacScan(std::string dac, int ntrig, int dacmin, int dacmax, std::vector<shist256*> maps, int ihit, int flag = 0);
114  void preScan(std::string dac, std::vector<shist256*> maps, int &dacmin, int &dacmax);
116  void scurveAna(std::string dac, std::string name, std::vector<shist256*> maps, std::vector<TH1*> &resultMaps, int result);
118  void getPhError(std::string dac, int dacmin, int dacmax, int FLAGS, int ntrig);
120  std::vector<TH2D*> phMaps(std::string name, uint16_t ntrig = 10, uint16_t FLAGS = FLAG_FORCE_MASKED);
122  std::vector<TH2D*> efficiencyMaps(std::string name, uint16_t ntrig = 10, uint16_t FLAGS = FLAG_FORCE_MASKED);
134  std::vector<TH1*> scurveMaps(std::string dac, std::string name, int ntrig = 10, int daclo = 0, int dachi = 255, int dacsperstep = -1,
135  int result = 15, int ihit = 1, int flag = FLAG_FORCE_MASKED);
137  std::vector<TH1*> thrMaps(std::string dac, std::string name, uint8_t dacmin, uint8_t dachi, int ntrig, uint16_t flag = 0);
138  std::vector<TH1*> thrMaps(std::string dac, std::string name, int ntrig, uint16_t flag = 0);
139 
140 
145  std::vector<std::pair<int,int> > checkHotPixels(TH2D* h);
146 
148  std::pair<std::vector<TH2D*>,std::vector<TH2D*> > xEfficiencyMaps(std::string name, uint16_t ntrig,
149  uint16_t FLAGS = FLAG_CHECK_ORDER | FLAG_FORCE_UNMASKED);
150 
152  void maskHotPixels(std::vector<TH2D*>);
154  void resetROC();
156  void resetTBM();
158  uint16_t prepareDaq(int triggerFreq, uint8_t trgTkDel);
160  uint16_t setTriggerFrequency(int triggerFreq, uint8_t TrgTkDel);
162  void finalCleanup();
163  void pgToDefault();
164 
166  TH1D* bookTH1D(std::string sname, std::string title, int nbins, double xmin, double xmax);
168  TH2D* bookTH2D(std::string sname, std::string title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double max);
170  TProfile2D* bookTProfile2D(std::string sname, std::string title,
171  int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double max,
172  std::string option = "");
174  void fillDacHist(std::vector<std::pair<uint8_t, std::vector<pxar::pixel> > > &results, TH1D *h,
175  int icol = -1, int irow = -1, int iroc = -1);
176 
178  virtual void sparseRoc(int npix = 8);
179 
181  TH1D* distribution(TH2D *, int nbins, double xmin, double xmax);
183  bool threshold(TH1 *);
185  int simpleThreshold(TH1 *);
187  std::vector<int> getMaximumVthrComp(int ntrig, double frac = 0.8, int reserve = 10);
189  std::vector<int> getMinimumVthrComp(std::vector<TH1*>, int reserve = 10, double nsigma = 3.);
191  double getMinimumThreshold(std::vector<TH1*>);
193  double getMaximumThreshold(std::vector<TH1*>);
195  std::vector<TH1*> mapsWithString(std::vector<TH1*>, std::string name);
196  std::vector<TH2D*> mapsWithString(std::vector<TH2D*>, std::string name);
197 
199  void print(std::string, pxar::TLogLevel log = pxar::logINFO);
200  void banner(std::string, pxar::TLogLevel log = pxar::logINFO);
201  void bigBanner(std::string, pxar::TLogLevel log = pxar::logINFO);
202 
204  void cacheDacs(bool verbose = false);
206  void restoreDacs(bool verbose = false);
207 
209  std::vector<uint8_t> getDacs(std::string dacName);
211  void setDacs(std::string dacName, std::vector<uint8_t> dacVector);
213  std::string getDacsString(std::string dacName);
214 
216  virtual TH1* moduleMap(std::string histname);
217 
219  void clearHistList();
220 
222  std::string getName() {return fName; }
224  void resetDirectory();
226  TDirectory* getDirectory() {return fDirectory;}
227 
229  std::vector<std::pair<std::string, std::string> > getParameters() {return fParameters;}
231  bool getParameter(std::string parName, int &);
233  bool getParameter(std::string parName, float &);
235  std::string getParameter(std::string parName);
237  virtual bool setParameter(std::string parName, std::string sval);
239  virtual void setDAC(std::string parName, uint8_t val) {fApi->setDAC(parName, val);}
241  virtual void setDAC(std::string parName, uint8_t val, uint8_t rocid) {fApi->setDAC(parName, val, rocid);}
243  void dumpParameters();
245  void setTitles(TH1 *h, const char *sx, const char *sy,
246  float size = 0.05, float xoff = 1.1, float yoff = 1.1, float lsize = 0.05, int font = 42);
247 
249  void setId2Idx(std::map<int, int> a);
251  int getIdFromIdx(int idx);
253  int getIdxFromId(int id);
255  bool selectedRoc(int id);
257  void clearSelectedPixels();
259  void addSelectedPixels(std::string sval);
261  bool setTestParameter(std::string parname, std::string value);
262 
264  static std::string stripPos(std::string);
265 
267  void testDone(); // *SIGNAL*
269  void update(); // *SIGNAL*
271  void hvOff(); // *SIGNAL*
273  void hvOn(); // *SIGNAL*
275  void powerOff(); // *SIGNAL*
277  void powerOn(); // *SIGNAL*
279  TH1* nextHist();
281  TH1* previousHist();
282 
283 
284 protected:
285 
286  int histCycle(std::string hname);
287  void fillMap(TH2D *hmod, TH2D *hroc, int iroc);
288 
293 
294  double fThreshold, fThresholdE, fSigma, fSigmaE;
295  double fThresholdN;
296  int fNtrig;
297  std::vector<double> fPhErrP0, fPhErrP1;
298  uint32_t fNDaqErrors;
299 
300  std::string fName, fTestTip, fSummaryTip, fStopTip;
301 
302  std::vector<std::pair<std::string, std::string> > fParameters;
303 
304  std::vector<std::vector<std::pair<std::string,uint8_t> > > fDacCache;
305 
306  TDirectory *fDirectory;
307  std::list<TH1*> fHistList;
308  std::map<TH1*, std::string> fHistOptions;
309  std::list<TH1*>::iterator fDisplayedHist;
310 
311  std::vector<std::pair<int, int> > fPIX;
312  std::map<int, int> fId2Idx;
313  TTree *fTree;
314  TreeEvent fTreeEvent;
315  TTimeStamp *fTimeStamp;
316 
317  bool fProblem;
318 
319 
320  // -- data members for DAQ purposes
321  std::vector<std::pair<std::string, uint8_t> > fPg_setup;
322  std::vector<std::vector<std::pair<int, int> > > fHotPixels;
323 
324  ClassDef(PixTest, 1); // testing PixTest
325 
326 };
327 
328 #endif
std::vector< std::pair< std::string, std::string > > getParameters()
returns a vector of test parameter names and string values
Definition: PixTest.hh:229
double fThresholdN
variable for passing back the threshold where noise leads to loss of efficiency
Definition: PixTest.hh:295
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
Definition: PixTest.hh:308
std::string fStopTip
information for this test
Definition: PixTest.hh:300
PixSetup * fPixSetup
all necessary stuff in one place
Definition: PixTest.hh:290
bool testProblem()
query whether test 'failed'
Definition: PixTest.hh:96
std::vector< std::pair< int, int > > fPIX
range of enabled pixels for time-consuming tests
Definition: PixTest.hh:311
std::vector< std::vector< std::pair< std::string, uint8_t > > > fDacCache
vector for all ROCs
Definition: PixTest.hh:304
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
Definition: PixTest.hh:302
std::string getName()
returns the test name
Definition: PixTest.hh:222
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
virtual std::string getTestTip()
get the string describing the test (called from PixTab::updateToolTips)
Definition: PixTest.hh:105
double fSigmaE
variables for passing back s-curve results
Definition: PixTest.hh:294
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
Definition: PixTest.hh:309
virtual std::string getSummaryTip()
hint to what happens if the user hits the "summary" button
Definition: PixTest.hh:103
virtual void setDAC(std::string parName, uint8_t val)
allow setting DACs in scripts for entire DUT
Definition: PixTest.hh:239
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
Definition: PixTest.hh:307
PixInitFunc * fPIF
function instantiation and automatic initialization
Definition: PixTest.hh:292
TDirectory * getDirectory()
return fDirectory
Definition: PixTest.hh:226
virtual void setDAC(std::string parName, uint8_t val, uint8_t rocid)
allow setting DACs in scripts for spcific ROCs
Definition: PixTest.hh:241
PixTestParameters * fTestParameters
the repository of all test parameters
Definition: PixTest.hh:291
virtual std::string getStopTip()
hint to what happens if the user hits the "stop" button
Definition: PixTest.hh:101
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
std::map< int, int > fId2Idx
map the ROC ID onto the (results vector) index of the ROC
Definition: PixTest.hh:312