1 #include "anaFullTest.hh"
11 #include <TUnixSystem.h>
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);
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");
34 anaFullTest::~anaFullTest() {
35 cout <<
"anaFullTest dtor" << endl;
40 void anaFullTest::bookModuleSummary(
string modulename) {
43 ms->moduleName = modulename;
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),
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);
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()),
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;
70 for (
int iroc = 0; iroc < fNrocs; ++iroc) {
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),
75 ms->ndeadpixels.push_back(h);
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),
81 ms->ndeadbumps.push_back(h);
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),
87 ms->deadsep.push_back(h);
91 ms->trimthrpos =
new TH1D(Form(
"%s_trimthrpos", modulename.c_str()),
92 Form(
"%s_trimthrpos", modulename.c_str()),
95 ms->trimthrpos->SetXTitle(
"VCAL [DAC]");
97 ms->trimthrrms =
new TH1D(Form(
"%s_trimthrrms", modulename.c_str()),
98 Form(
"%s_trimthrrms", modulename.c_str()),
100 ms->trimthrrms->SetXTitle(
"VCAL [DAC]");
102 ms->p1pos =
new TH1D(Form(
"%s_p1pos", modulename.c_str()),
103 Form(
"%s_p1pos", modulename.c_str()),
106 ms->p1rms =
new TH1D(Form(
"%s_p1rms", modulename.c_str()),
107 Form(
"%s_p1rms", modulename.c_str()),
110 fModSummaries.insert(make_pair(modulename, ms));
116 void anaFullTest::validateFullTests() {
118 addFullTests(
"D14-0001",
"-003");
120 addFullTests(
"D14-0006",
"-000");
121 addFullTests(
"D14-0008",
"-000");
122 addFullTests(
"D14-0009",
"-000");
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.);
131 map<string, moduleSummary*>::iterator ib = fModSummaries.begin();
133 TH1D *hTrimThrPos = (TH1D*)ib->second->trimthrpos->Clone(
"hTrimThrPos");
134 hTrimThrPos->SetTitle(
"Trim Threshold");
135 hTrimThrPos->Reset();
137 TH1D *hTrimThrRms = (TH1D*)ib->second->trimthrrms->Clone(
"hTrimThrRms");
138 hTrimThrRms->SetTitle(
"Trim Threshold RMS");
139 hTrimThrRms->Reset();
141 TH1D *hp1Pos = (TH1D*)ib->second->p1pos->Clone(
"hp1Pos");
142 hp1Pos->SetTitle(
"p1");
145 TH1D *hp1Rms = (TH1D*)ib->second->p1rms->Clone(
"hp1Rms");
146 hp1Rms->SetTitle(
"p1 RMS");
149 for (map<string, moduleSummary*>::iterator it = fModSummaries.begin(); it != fModSummaries.end(); ++it) {
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]));
161 for (
int ibin = 1; ibin <= it->second->trimthrpos->GetNbinsX(); ++ibin) {
162 hTrimThrPos->SetBinContent(ibin, hTrimThrPos->GetBinContent(ibin)+it->second->trimthrpos->GetBinContent(ibin));
165 for (
int ibin = 1; ibin <= it->second->trimthrrms->GetNbinsX(); ++ibin) {
166 hTrimThrRms->SetBinContent(ibin, hTrimThrRms->GetBinContent(ibin) + it->second->trimthrrms->GetBinContent(ibin));
169 for (
int ibin = 1; ibin <= it->second->p1pos->GetNbinsX(); ++ibin) {
170 hp1Pos->SetBinContent(ibin, hp1Pos->GetBinContent(ibin)+it->second->p1pos->GetBinContent(ibin));
173 for (
int ibin = 1; ibin <= it->second->p1rms->GetNbinsX(); ++ibin) {
174 hp1Rms->SetBinContent(ibin, hp1Rms->GetBinContent(ibin) + it->second->p1rms->GetBinContent(ibin));
184 c0->SaveAs(
"ftval-vana.pdf");
187 c0->SaveAs(
"ftval-caldel.pdf");
190 c0->SaveAs(
"ftval-vthrcomp.pdf");
193 c0->SaveAs(
"ftval-vtrim.pdf");
196 c0->SaveAs(
"ftval-phscale.pdf");
199 c0->SaveAs(
"ftval-phoffset.pdf");
202 c0->SaveAs(
"ftval-trimthrpos.pdf");
205 c0->SaveAs(
"ftval-trimthrrms.pdf");
208 c0->SaveAs(
"ftval-p1pos.pdf");
211 c0->SaveAs(
"ftval-p1rms.pdf");
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;
225 bookModuleSummary(mname);
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);
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);
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]));
270 fModSummaries[mname]->rmsVana->Draw();
272 fModSummaries[mname]->rmsCaldel->Draw();
275 fModSummaries[mname]->rmsVthrcomp->Draw();
278 fModSummaries[mname]->rmsVtrim->Draw();
281 fModSummaries[mname]->rmsPhscale->Draw();
284 fModSummaries[mname]->rmsPhoffset->Draw();
287 fModSummaries[mname]->trimthrpos->Draw();
290 fModSummaries[mname]->trimthrrms->Draw();
293 fModSummaries[mname]->p1pos->Draw();
295 c0->SaveAs(Form(
"%s.pdf", mname.c_str()));
300 void anaFullTest::readLogFile(std::string dir, std::string tag, std::vector<TH1D*> hists) {
306 string::size_type s1;
308 IN.open(Form(
"%s/pxar.log", dir.c_str()));
309 while (IN.getline(buffer, 1000,
'\n')) {
311 s1 = sline.find(tag.c_str());
312 if (string::npos == s1)
continue;
313 sline = sline.substr(s1+tag.length()+1);
317 x = splitIntoRocs(sline);
318 for (
unsigned int i = 0; i < x.size(); ++i) {
320 hists[i]->Fill(x[i]);
327 void anaFullTest::readLogFile(std::string dir, std::string tag, TH1D* hist) {
333 string::size_type s1;
335 IN.open(Form(
"%s/pxar.log", dir.c_str()));
336 while (IN.getline(buffer, 1000,
'\n')) {
338 s1 = sline.find(tag.c_str());
339 if (string::npos == s1)
continue;
340 sline = sline.substr(s1+tag.length()+1);
343 x = splitIntoRocs(sline);
344 for (
unsigned int i = 0; i < x.size(); ++i) {
355 void anaFullTest::readDacFile(
string dir,
string dac, vector<TH1D*> vals) {
360 string::size_type s1;
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;}
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());
384 vector<string> anaFullTest::glob(
string basename) {
390 TSystem *lunix = gSystem;
391 void *pDir = lunix->OpenDirectory(
".");
392 while ((file = lunix->GetDirEntry(pDir))) {
394 if (fname.Contains(basename.c_str())) {
395 lof.push_back(
string(fname));
404 double anaFullTest::diff(TH1D *h) {
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) {
419 std::vector<double> anaFullTest::splitIntoRocs(std::string line) {
420 istringstream istring(line);
421 vector<double> result;
423 cout <<
"splitting: " << line << endl;
424 for (
int iroc = 0; iroc < fNrocs; ++iroc) {
429 for (
unsigned int i = 0; i < result.size(); ++i) {
430 cout << result[i] <<
" ";