4 #include "PixTestDacDacScan.hh"
17 PixTest(a, name), fParNtrig(-1), fParPHmap(0), fParDAC1("nada"), fParDAC2("nada"),
18 fParLoDAC1(-1), fParHiDAC1(-1), fParLoDAC2(-1), fParHiDAC2(-1) {
21 LOG(logDEBUG) <<
"PixTestDacDacScan ctor(PixSetup &a, string, TGTab *)";
26 PixTestDacDacScan::PixTestDacDacScan() :
PixTest() {
27 LOG(logDEBUG) <<
"PixTestDacDacScan ctor()";
36 std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
37 for (
unsigned int i = 0; i <
fParameters.size(); ++i) {
40 sval.erase(
remove(sval.begin(), sval.end(),
' '), sval.end());
41 if (!parName.compare(
"ntrig")) {
42 fParNtrig = atoi(sval.c_str());
45 if (!parName.compare(
"phmap")) {
48 fParPHmap = atoi(sval.c_str());
51 if (!parName.compare(
"dac1")) {
55 if (!parName.compare(
"dac2")) {
59 if (!parName.compare(
"dac1lo")) {
60 fParLoDAC1 = atoi(sval.c_str());
63 if (!parName.compare(
"dac1hi")) {
64 fParHiDAC1 = atoi(sval.c_str());
67 if (!parName.compare(
"dac2lo")) {
68 fParLoDAC2 = atoi(sval.c_str());
71 if (!parName.compare(
"dac2hi")) {
72 fParHiDAC2 = atoi(sval.c_str());
75 if (!parName.compare(
"pix")) {
77 if (string::npos != s1) {
78 str1 = sval.substr(0, s1);
79 pixc = atoi(str1.c_str());
80 str2 = sval.substr(s1+1);
81 pixr = atoi(str2.c_str());
83 fPIX.push_back(make_pair(pixc, pixr));
87 fPIX.push_back(make_pair(-1, -1));
101 void PixTestDacDacScan::init() {
102 LOG(logDEBUG) <<
"PixTestDacDacScan::init()";
105 fDirectory = gFile->GetDirectory(fName.c_str());
116 fTestTip = string(Form(
"scan the two DACs %s vs %s and ", fParDAC1.c_str(), fParDAC2.c_str()))
117 + string(
"determine the number of hits for each setting")
118 + string(
"\nNOTE: There is currently a limitation that the total number of scanned points is less than 2^14!")
120 fSummaryTip = string(
"summary plot to be implemented")
126 void PixTestDacDacScan::bookHist(
string ) {
134 PixTestDacDacScan::~PixTestDacDacScan() {
135 LOG(logDEBUG) <<
"PixTestDacDacScan dtor";
142 uint16_t FLAGS = FLAG_FORCE_MASKED;
146 string zname = fParDAC1 + string(
":") + fParDAC2;
148 string::size_type s1 = zname.find(
":");
149 string dac1 = zname.substr(0, s1);
150 string dac2 = zname.substr(s1+1);
151 LOG(logINFO) <<
"PixTestDacDacScan: " << dac1 <<
"[" << fParLoDAC1 <<
", " << fParHiDAC1 <<
"]"
152 <<
" vs. " << dac2 <<
"[" << fParLoDAC2 <<
", " << fParHiDAC2 <<
"]"
153 << (fParPHmap?
" average PH":
" readouts")
154 <<
", ntrig = " << fParNtrig
155 <<
", npixels = " <<
fPIX.size();
158 map<string, TH2D*> maps;
160 string name(fParPHmap?
"ph":
"nhits");
163 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
164 for (
unsigned int ip = 0; ip <
fPIX.size(); ++ip) {
165 h2 =
bookTH2D(Form(
"%s_%s_%s_c%d_r%d_C%d", name.c_str(), dac1.c_str(), dac2.c_str(),
fPIX[ip].first,
fPIX[ip].second, rocIds[iroc]),
166 Form(
"%s_%s_%s_c%d_r%d_C%d", name.c_str(), dac1.c_str(), dac2.c_str(),
fPIX[ip].first,
fPIX[ip].second, rocIds[iroc]),
167 nx, 0., static_cast<double>(nx), ny, 0.,
static_cast<double>(ny));
168 if (0 == fParPHmap) h2->SetMinimum(0.);
169 setTitles(h2, dac1.c_str(), dac2.c_str());
172 maps.insert(make_pair(Form(
"%s_%s_%s_c%d_r%d_C%d",
173 name.c_str(), dac1.c_str(), dac2.c_str(),
fPIX[ip].first,
fPIX[ip].second, rocIds[iroc]), h2));
180 vector<pair<uint8_t, pair<uint8_t, vector<pixel> > > > rresults, results;
183 for (
unsigned int i = 0; i <
fPIX.size(); ++i) {
184 if (
fPIX[i].first > -1) {
191 if (0 == fParPHmap) {
193 fParDAC2, fParLoDAC2, fParHiDAC2, FLAGS, fParNtrig);
198 fParDAC2, fParLoDAC2, fParHiDAC2, FLAGS, fParNtrig);
203 LOG(logCRITICAL) <<
"problem with readout: "<< e.what() <<
" missing " << e.numberMissing <<
" events";
204 fNDaqErrors = 666666;
206 if (e.numberMissing > 10) done =
true;
208 LOG(logCRITICAL) <<
"pXar execption: "<< e.what();
209 fNDaqErrors = 666667;
212 done = (cnt>5) || done;
215 if (fNDaqErrors > 0) problems = fNDaqErrors;
216 copy(rresults.begin(), rresults.end(), back_inserter(results));
224 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
225 for (
unsigned int i = 0; i < results.size(); ++i) {
226 pair<uint8_t, pair<uint8_t, vector<pixel> > > v = results[i];
228 pair<uint8_t, vector<pixel> > w = v.second;
230 vector<pixel> wpix = w.second;
232 for (
unsigned ipix = 0; ipix < wpix.size(); ++ipix) {
233 if (wpix[ipix].roc() == rocIds[iroc]) {
234 h = maps[Form(
"%s_%s_%s_c%d_r%d_C%d",
235 name.c_str(), fParDAC1.c_str(), fParDAC2.c_str(), wpix[ipix].column(), wpix[ipix].row(), rocIds[iroc])];
237 h->Fill(idac1, idac2, wpix[ipix].value());
239 LOG(logDEBUG) <<
"XX did not find "
240 << Form(
"%s_%s_%s_c%d_r%d_C%d",
241 name.c_str(), fParDAC1.c_str(), fParDAC2.c_str(), wpix[ipix].column(), wpix[ipix].row(), rocIds[iroc]);
251 LOG(logINFO) <<
"dac dac scan done" << (problems > 0? Form(
" problems observed: %d", problems):
" no problems seen");
261 LOG(logDEBUG) <<
"PixTestDacScan::moduleMap histname: " << histname;
262 TH1* h0 = (*fDisplayedHist);
263 if (!h0->InheritsFrom(TH2::Class())) {
267 TH2D *h1 = (TH2D*)h0;
268 string h1name = h1->GetName();
269 string::size_type s1 = h1name.rfind(
"_c");
270 string barename = h1name.substr(0, s1);
271 LOG(logDEBUG) <<
"h1->GetName() = " << h1name <<
" -> " << barename;
277 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
279 h1 =
bookTH2D(Form(
"%s_C%d", barename.c_str(), rocIds[iroc]), Form(
"%s_C%d", barename.c_str(), rocIds[iroc]),
280 h0->GetNbinsX(), h0->GetXaxis()->GetBinLowEdge(1), h0->GetXaxis()->GetBinLowEdge(h0->GetNbinsX()+1),
281 h0->GetNbinsY(), h0->GetYaxis()->GetBinLowEdge(1), h0->GetYaxis()->GetBinLowEdge(h0->GetNbinsY()+1));
283 if (0 == iroc) cycle = -1 +
histCycle(Form(
"%s_C%d", barename.c_str(), rocIds[iroc]));
285 list<TH1*>::iterator hbeg =
fHistList.begin();
286 list<TH1*>::iterator hend =
fHistList.end();
287 cout <<
"Search for: " << Form(
"%s", barename.c_str()) << endl;
288 for (list<TH1*>::iterator il = hbeg; il != hend; ++il) {
289 h =
dynamic_cast<TH2D*
>(*il);
290 hname = h->GetName();
291 cout <<
" looking at " << hname << endl;
292 if (string::npos != hname.find(Form(
"%s", barename.c_str()))) {
293 if (string::npos != hname.rfind(Form(
"_C%d", rocIds[iroc]))) {
294 if (string::npos != hname.rfind(Form(
"_V%d", cycle))) {
295 for (
int ix = 1; ix < h->GetNbinsX(); ++ix) {
296 for (
int iy = 1; iy < h->GetNbinsX(); ++iy) {
297 h1->Fill(h->GetBinCenter(ix), h->GetBinCenter(iy), h->GetBinContent(ix, iy));
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
in str, replace all occurences of from to to
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
int histCycle(std::string hname)
determine histogram cycle
statistics getStatistics()
uint8_t getDACRange(std::string dacName)
std::vector< std::pair< int, int > > fPIX
range of enabled pixels for time-consuming tests
void testPixel(uint8_t column, uint8_t row, bool enable)
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
void maskAllPixels(bool mask, uint8_t rocid)
void clearSelectedPixels()
clear selected pixel list
TDirectory * fDirectory
where the root histograms will end up
void addSelectedPixels(std::string sval)
add a selected pixel to the internal parameter list
TH1 * moduleMap(std::string histname)
combine all available ROC maps into a module map
std::vector< std::pair< uint8_t, std::pair< uint8_t, std::vector< pixel > > > > getPulseheightVsDACDAC(std::string dac1name, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers)
std::vector< uint8_t > getEnabledRocIDs()
void testAllPixels(bool enable)
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
virtual std::string getHistOption(TH1 *)
get the hist display options (if stored in fHistOptions)
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
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
std::vector< std::pair< uint8_t, std::pair< uint8_t, std::vector< pixel > > > > getEfficiencyVsDACDAC(std::string dac1name, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers)
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
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
void maskPixel(uint8_t column, uint8_t row, bool mask)
void update()
signal to PixTab to update the canvas
void doTest()
function connected to "DoTest" button of PixTab
pxar::pxarCore * fApi
pointer to the API
void init()
sets all test parameters
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters