pxar
All Classes Namespaces Functions Variables Typedefs Friends
anaFullTest.cc
1 #include "anaFullTest.hh"
2 
3 #include <fstream>
4 #include <sstream>
5 #include <cstdlib>
6 
7 #include <TROOT.h>
8 #include <TSystem.h>
9 #if defined(WIN32)
10 #else
11 #include <TUnixSystem.h>
12 #endif
13 
14 using namespace std;
15 
16 // ----------------------------------------------------------------------
17 anaFullTest::anaFullTest(): fNrocs(16), fTrimVcal(40) {
18  cout << "anaFullTest ctor" << endl;
19  c0 = (TCanvas*)gROOT->FindObject("c0");
20  if (!c0) c0 = new TCanvas("c0","--c0--",0,0,656,700);
21 
22  fDiffMetric = 0;
23 
24  fDacs.clear();
25  fDacs.push_back("vana");
26  fDacs.push_back("caldel");
27  fDacs.push_back("vthrcomp");
28  fDacs.push_back("vtrim");
29  fDacs.push_back("phscale");
30  fDacs.push_back("phoffset");
31 }
32 
33 // ----------------------------------------------------------------------
34 anaFullTest::~anaFullTest() {
35  cout << "anaFullTest dtor" << endl;
36 
37 }
38 
39 // ----------------------------------------------------------------------
40 void anaFullTest::bookModuleSummary(string modulename) {
41 
42  moduleSummary *ms = new moduleSummary;
43  ms->moduleName = modulename;
44 
45  for (unsigned int idac = 0; idac < fDacs.size(); ++idac) {
46  for (int iroc = 0; iroc < fNrocs; ++iroc) {
47  TH1D *h = new TH1D(Form("%s_%s_C%d", modulename.c_str(), fDacs[idac].c_str(), iroc),
48  Form("%s_%s_C%d", modulename.c_str(), fDacs[idac].c_str(), iroc),
49  256, 0., 256.);
50  if (fDacs[idac] == "vana") ms->vana.push_back(h);
51  if (fDacs[idac] == "caldel") ms->caldel.push_back(h);
52  if (fDacs[idac] == "vthrcomp") ms->vthrcomp.push_back(h);
53  if (fDacs[idac] == "vtrim") ms->vtrim.push_back(h);
54  if (fDacs[idac] == "phscale") ms->phscale.push_back(h);
55  if (fDacs[idac] == "phoffset") ms->phoffset.push_back(h);
56  }
57  TH1D *h = new TH1D(Form("%s_%s_rms", modulename.c_str(), fDacs[idac].c_str()),
58  Form("%s_%s_rms", modulename.c_str(), fDacs[idac].c_str()),
59  50, 0., 5.);
60 
61  if (fDacs[idac] == "vana") ms->rmsVana = h;
62  if (fDacs[idac] == "caldel") ms->rmsCaldel = h;
63  if (fDacs[idac] == "vthrcomp") ms->rmsVthrcomp = h;
64  if (fDacs[idac] == "vtrim") ms->rmsVtrim = h;
65  if (fDacs[idac] == "phscale") ms->rmsPhscale = h;
66  if (fDacs[idac] == "phoffset") ms->rmsPhoffset = h;
67  }
68 
69  string what("");
70  for (int iroc = 0; iroc < fNrocs; ++iroc) {
71  what = "ndeadpixels";
72  TH1D *h = new TH1D(Form("%s_%s_C%d", modulename.c_str(), what.c_str(), iroc),
73  Form("%s_%s_C%d", modulename.c_str(), what.c_str(), iroc),
74  100, 0., 100.);
75  ms->ndeadpixels.push_back(h);
76 
77  what = "ndeadbumps";
78  h = new TH1D(Form("%s_%s_C%d", modulename.c_str(), what.c_str(), iroc),
79  Form("%s_%s_C%d", modulename.c_str(), what.c_str(), iroc),
80  100, 0., 100.);
81  ms->ndeadbumps.push_back(h);
82 
83  what = "deadsep";
84  h = new TH1D(Form("%s_%s_C%d", modulename.c_str(), what.c_str(), iroc),
85  Form("%s_%s_C%d", modulename.c_str(), what.c_str(), iroc),
86  150, 0., 150.);
87  ms->deadsep.push_back(h);
88 
89  }
90 
91  ms->trimthrpos = new TH1D(Form("%s_trimthrpos", modulename.c_str()),
92  Form("%s_trimthrpos", modulename.c_str()),
93  80, 39., 41.);
94 
95  ms->trimthrpos->SetXTitle("VCAL [DAC]");
96 
97  ms->trimthrrms = new TH1D(Form("%s_trimthrrms", modulename.c_str()),
98  Form("%s_trimthrrms", modulename.c_str()),
99  50, 0., 2.);
100  ms->trimthrrms->SetXTitle("VCAL [DAC]");
101 
102  ms->p1pos = new TH1D(Form("%s_p1pos", modulename.c_str()),
103  Form("%s_p1pos", modulename.c_str()),
104  50, 0.5, 1.0);
105 
106  ms->p1rms = new TH1D(Form("%s_p1rms", modulename.c_str()),
107  Form("%s_p1rms", modulename.c_str()),
108  50, 0., 0.2);
109 
110  fModSummaries.insert(make_pair(modulename, ms));
111 
112 }
113 
114 
115 // ----------------------------------------------------------------------
116 void anaFullTest::validateFullTests() {
117  // -- PSI module
118  addFullTests("D14-0001", "-003");
119  // -- ETH modules
120  addFullTests("D14-0006", "-000");
121  addFullTests("D14-0008", "-000");
122  addFullTests("D14-0009", "-000");
123 
124  TH1D *hVana = new TH1D("hVana", Form("Vana %s", fDiffMetric == 0?"difference":"RMS"), 50, 0., 5.);
125  TH1D *hCaldel = new TH1D("hCaldel", Form("CalDel %s", fDiffMetric == 0?"difference":"RMS"), 50, 0., 5.);
126  TH1D *hVthrcomp = new TH1D("hVthrcomp", Form("VthrComp %s", fDiffMetric == 0?"difference":"RMS"), 50, 0., 5.);
127  TH1D *hVtrim = new TH1D("hVtrim", Form("Vtrim %s", fDiffMetric == 0?"difference":"RMS"), 50, 0., 10.);
128  TH1D *hPhs = new TH1D("hPhs", Form("phscale %s", fDiffMetric == 0?"difference":"RMS"), 50, 0., 5.);
129  TH1D *hPho = new TH1D("hPho", Form("phoffset %s", fDiffMetric == 0?"difference":"RMS"), 50, 0., 5.);
130 
131  map<string, moduleSummary*>::iterator ib = fModSummaries.begin();
132 
133  TH1D *hTrimThrPos = (TH1D*)ib->second->trimthrpos->Clone("hTrimThrPos");
134  hTrimThrPos->SetTitle("Trim Threshold");
135  hTrimThrPos->Reset();
136 
137  TH1D *hTrimThrRms = (TH1D*)ib->second->trimthrrms->Clone("hTrimThrRms");
138  hTrimThrRms->SetTitle("Trim Threshold RMS");
139  hTrimThrRms->Reset();
140 
141  TH1D *hp1Pos = (TH1D*)ib->second->p1pos->Clone("hp1Pos");
142  hp1Pos->SetTitle("p1");
143  hp1Pos->Reset();
144 
145  TH1D *hp1Rms = (TH1D*)ib->second->p1rms->Clone("hp1Rms");
146  hp1Rms->SetTitle("p1 RMS");
147  hp1Rms->Reset();
148 
149  for (map<string, moduleSummary*>::iterator it = fModSummaries.begin(); it != fModSummaries.end(); ++it) {
150 
151  cout << "summarizing " << it->second->moduleName << endl;
152  for (int iroc = 0; iroc < fNrocs; ++iroc) {
153  hVana->Fill(diff(it->second->vana[iroc]));
154  hCaldel->Fill(diff(it->second->caldel[iroc]));
155  hVthrcomp->Fill(diff(it->second->vthrcomp[iroc]));
156  hVtrim->Fill(diff(it->second->vtrim[iroc]));
157  hPhs->Fill(diff(it->second->phscale[iroc]));
158  hPho->Fill(diff(it->second->phoffset[iroc]));
159  }
160 
161  for (int ibin = 1; ibin <= it->second->trimthrpos->GetNbinsX(); ++ibin) {
162  hTrimThrPos->SetBinContent(ibin, hTrimThrPos->GetBinContent(ibin)+it->second->trimthrpos->GetBinContent(ibin));
163  }
164 
165  for (int ibin = 1; ibin <= it->second->trimthrrms->GetNbinsX(); ++ibin) {
166  hTrimThrRms->SetBinContent(ibin, hTrimThrRms->GetBinContent(ibin) + it->second->trimthrrms->GetBinContent(ibin));
167  }
168 
169  for (int ibin = 1; ibin <= it->second->p1pos->GetNbinsX(); ++ibin) {
170  hp1Pos->SetBinContent(ibin, hp1Pos->GetBinContent(ibin)+it->second->p1pos->GetBinContent(ibin));
171  }
172 
173  for (int ibin = 1; ibin <= it->second->p1rms->GetNbinsX(); ++ibin) {
174  hp1Rms->SetBinContent(ibin, hp1Rms->GetBinContent(ibin) + it->second->p1rms->GetBinContent(ibin));
175  }
176 
177  }
178 
179 
180  c0->Clear();
181  c0->cd(1);
182 
183  hVana->Draw();
184  c0->SaveAs("ftval-vana.pdf");
185 
186  hCaldel->Draw();
187  c0->SaveAs("ftval-caldel.pdf");
188 
189  hVthrcomp->Draw();
190  c0->SaveAs("ftval-vthrcomp.pdf");
191 
192  hVtrim->Draw();
193  c0->SaveAs("ftval-vtrim.pdf");
194 
195  hPhs->Draw();
196  c0->SaveAs("ftval-phscale.pdf");
197 
198  hPho->Draw();
199  c0->SaveAs("ftval-phoffset.pdf");
200 
201  hTrimThrPos->Draw();
202  c0->SaveAs("ftval-trimthrpos.pdf");
203 
204  hTrimThrRms->Draw();
205  c0->SaveAs("ftval-trimthrrms.pdf");
206 
207  hp1Pos->Draw();
208  c0->SaveAs("ftval-p1pos.pdf");
209 
210  hp1Rms->Draw();
211  c0->SaveAs("ftval-p1rms.pdf");
212 
213 
214 }
215 
216 
217 // ----------------------------------------------------------------------
218 void anaFullTest::addFullTests(string mname, string mpattern) {
219  vector<string> dirs = glob(mname+mpattern);
220  cout << dirs.size() << endl;
221  for (unsigned int idirs = 0; idirs < dirs.size(); ++idirs) {
222  cout << dirs[idirs] << endl;
223  }
224 
225  bookModuleSummary(mname);
226 
227  for (unsigned int idirs = 0; idirs < dirs.size(); ++idirs) {
228  readDacFile(dirs[idirs], "vana", fModSummaries[mname]->vana);
229  readDacFile(dirs[idirs], "caldel", fModSummaries[mname]->caldel);
230  readDacFile(dirs[idirs], "vthrcomp", fModSummaries[mname]->vthrcomp);
231  readDacFile(dirs[idirs], "vtrim", fModSummaries[mname]->vtrim);
232  readDacFile(dirs[idirs], "phscale", fModSummaries[mname]->phscale);
233  readDacFile(dirs[idirs], "phoffset", fModSummaries[mname]->phoffset);
234 
235 
236 // readLogFile(dirs[idirs], "number of dead pixels (per ROC):", fModSummaries[mname]->ndeadpixels);
237 // readLogFile(dirs[idirs], "number of dead bumps (per ROC):", fModSummaries[mname]->ndeadbumps);
238 // readLogFile(dirs[idirs], "separation cut (per ROC):", fModSummaries[mname]->deadsep);
239  readLogFile(dirs[idirs], "vcal mean:", fModSummaries[mname]->trimthrpos);
240  readLogFile(dirs[idirs], "vcal RMS:", fModSummaries[mname]->trimthrrms);
241  readLogFile(dirs[idirs], "p1 mean:", fModSummaries[mname]->p1pos);
242  readLogFile(dirs[idirs], "p1 RMS:", fModSummaries[mname]->p1rms);
243 
244  /*
245  vcal mean:
246  vcal RMS:
247  bits mean:
248  bits RMS:
249 
250  VthrComp mean:
251  VthrComp RMS:
252  Vcal mean:
253  Vcal RMS:
254  */
255  }
256 
257  for (int iroc = 0; iroc < fNrocs; ++iroc) {
258  fModSummaries[mname]->rmsVana->Fill(diff(fModSummaries[mname]->vana[iroc]));
259  fModSummaries[mname]->rmsCaldel->Fill(diff(fModSummaries[mname]->caldel[iroc]));
260  fModSummaries[mname]->rmsVthrcomp->Fill(diff(fModSummaries[mname]->vthrcomp[iroc]));
261  fModSummaries[mname]->rmsVtrim->Fill(diff(fModSummaries[mname]->vtrim[iroc]));
262  fModSummaries[mname]->rmsPhscale->Fill(diff(fModSummaries[mname]->phscale[iroc]));
263  fModSummaries[mname]->rmsPhoffset->Fill(diff(fModSummaries[mname]->phoffset[iroc]));
264  }
265 
266  c0->Clear();
267  c0->Divide(3,3);
268 
269  c0->cd(1);
270  fModSummaries[mname]->rmsVana->Draw();
271  c0->cd(2);
272  fModSummaries[mname]->rmsCaldel->Draw();
273 
274  c0->cd(3);
275  fModSummaries[mname]->rmsVthrcomp->Draw();
276 
277  c0->cd(4);
278  fModSummaries[mname]->rmsVtrim->Draw();
279 
280  c0->cd(5);
281  fModSummaries[mname]->rmsPhscale->Draw();
282 
283  c0->cd(6);
284  fModSummaries[mname]->rmsPhoffset->Draw();
285 
286  c0->cd(7);
287  fModSummaries[mname]->trimthrpos->Draw();
288 
289  c0->cd(8);
290  fModSummaries[mname]->trimthrrms->Draw();
291 
292  c0->cd(9);
293  fModSummaries[mname]->p1pos->Draw();
294 
295  c0->SaveAs(Form("%s.pdf", mname.c_str()));
296 
297 }
298 
299 // ----------------------------------------------------------------------
300 void anaFullTest::readLogFile(std::string dir, std::string tag, std::vector<TH1D*> hists) {
301 
302  ifstream IN;
303 
304  char buffer[1000];
305  string sline;
306  string::size_type s1;
307  vector<double> x;
308  IN.open(Form("%s/pxar.log", dir.c_str()));
309  while (IN.getline(buffer, 1000, '\n')) {
310  sline = buffer;
311  s1 = sline.find(tag.c_str());
312  if (string::npos == s1) continue;
313  sline = sline.substr(s1+tag.length()+1);
314  break;
315  }
316 
317  x = splitIntoRocs(sline);
318  for (unsigned int i = 0; i < x.size(); ++i) {
319  // cout << "Filling into " << hist->GetName() << " x = " << x[i] << endl;
320  hists[i]->Fill(x[i]);
321  }
322 
323  IN.close();
324 }
325 
326 // ----------------------------------------------------------------------
327 void anaFullTest::readLogFile(std::string dir, std::string tag, TH1D* hist) {
328 
329  ifstream IN;
330 
331  char buffer[1000];
332  string sline;
333  string::size_type s1;
334  vector<double> x;
335  IN.open(Form("%s/pxar.log", dir.c_str()));
336  while (IN.getline(buffer, 1000, '\n')) {
337  sline = buffer;
338  s1 = sline.find(tag.c_str());
339  if (string::npos == s1) continue;
340  sline = sline.substr(s1+tag.length()+1);
341  break;
342  }
343  x = splitIntoRocs(sline);
344  for (unsigned int i = 0; i < x.size(); ++i) {
345  // cout << "Filling into " << hist->GetName() << " x = " << x[i] << endl;
346  hist->Fill(x[i]);
347  }
348 
349  IN.close();
350 }
351 
352 
353 
354 // ----------------------------------------------------------------------
355 void anaFullTest::readDacFile(string dir, string dac, vector<TH1D*> vals) {
356  ifstream IN;
357 
358  char buffer[1000];
359  string sline;
360  string::size_type s1;
361  int val(0);
362  for (int i = 0; i < fNrocs; ++i) {
363  IN.open(Form("%s/dacParameters%d_C%d.dat", dir.c_str(), fTrimVcal, i));
364  while (IN.getline(buffer, 1000, '\n')) {
365  if (buffer[0] == '#') {continue;}
366  if (buffer[0] == '/') {continue;}
367  if (buffer[0] == '\n') {continue;}
368  sline = buffer;
369  s1 = sline.find(dac.c_str());
370  if (string::npos != s1) {
371  sline = sline.substr(s1+dac.length()+1);
372  val = atoi(sline.c_str());
373  vals[i]->Fill(val);
374  }
375  }
376  IN.close();
377  }
378 
379 }
380 
381 
382 
383 // ----------------------------------------------------------------------
384 vector<string> anaFullTest::glob(string basename) {
385  vector<string> lof;
386 #if defined(WIN32)
387 #else
388  TString fname;
389  const char *file;
390  TSystem *lunix = gSystem; //new TUnixSystem();
391  void *pDir = lunix->OpenDirectory(".");
392  while ((file = lunix->GetDirEntry(pDir))) {
393  fname = file;
394  if (fname.Contains(basename.c_str())) {
395  lof.push_back(string(fname));
396  }
397  }
398 #endif
399  return lof;
400 }
401 
402 
403 // ----------------------------------------------------------------------
404 double anaFullTest::diff(TH1D *h) {
405 
406  if (0 == fDiffMetric) {
407  int minbin = h->FindFirstBinAbove(0.1);
408  int maxbin = h->FindLastBinAbove(0.1);
409  return (maxbin-minbin);
410  } else if (1 == fDiffMetric) {
411  return h->GetRMS();
412  }
413 
414  return -1.;
415 }
416 
417 
418 // ----------------------------------------------------------------------
419 std::vector<double> anaFullTest::splitIntoRocs(std::string line) {
420  istringstream istring(line);
421  vector<double> result;
422  double x(0.);
423  cout << "splitting: " << line << endl;
424  for (int iroc = 0; iroc < fNrocs; ++iroc) {
425  istring >> x;
426  result.push_back(x);
427  }
428 
429  for (unsigned int i = 0; i < result.size(); ++i) {
430  cout << result[i] << " ";
431  }
432  cout << endl;
433 
434  return result;
435 }