24 #include "TGraphErrors.h"
30 #include <TLegendEntry.h>
32 #include "KM3NeTDBClient.h"
50 using namespace KM3NeT;
51 using namespace KM3NeT::DB;
55 bool validRun =
false;
57 while ((validRun ==
false) && (tryCounter < 10)) {
61 if (streamName ==
"vendorhv") {
62 Selector detIdSel(
"detid", detectorId.c_str());
63 vSel.push_back(detIdSel);
65 if (streamName ==
"pmt_hv_settings") {
66 Selector detIdSel(
"detid", detectorId.c_str());
67 vSel.push_back(detIdSel);
69 if (streamName ==
"pmt_hv_run_settings") {
70 std::stringstream runIdSStr;
72 std::string runIdStr = runIdSStr.str();
73 Selector runIdSel(
"run", runIdStr.c_str());
74 vSel.push_back(runIdSel);
77 auto client = Client::Create(Server::Default, cookie.c_str());
78 username = client->User();
79 if (runId == -1) std::cout <<
"opening connection as user " << username <<
" for default HV values" << std::endl;
80 else std::cout <<
"opening connection as user " << username <<
" for run " << runId << std::endl;
81 auto &rs = client->StreamDS(streamName.c_str(), vSel);
91 for (
unsigned int i = 0; i < rs.FieldCount(); ++i) {
92 std::istringstream valueSStr(rs.GetString(i));
95 std::string fieldName = rs.FieldName(i);
96 if (fieldName ==
"DUID") {
97 for (
unsigned int i = 0; i < lineIds.size(); ++i) {
98 if (lineIds[i] == value) {
102 }
else if (fieldName ==
"FLOORID") {
104 }
else if (fieldName ==
"CABLEPOS") {
106 }
else if (fieldName ==
"PMTSERIAL") {
108 }
else if (fieldName ==
"PMTUPI") {
109 std::string fullUpi = valueSStr.str().substr(22, 5);
110 std::istringstream fullUpiSStr(fullUpi);
112 std::string fullUpiExt = valueSStr.str().substr(20, 2);
113 std::istringstream fullUpiExtSStr(fullUpiExt);
114 fullUpiExtSStr >> upiExt;
115 }
else if (fieldName ==
"CG_NAME") {
116 if (valueSStr.str() == hvDefault) validHv =
true;
117 }
else if (fieldName ==
"HV_VALUE") {
119 if (streamName ==
"pmt_hv_run_settings") validHv =
true;
120 }
else if (fieldName ==
"PMT_SUPPLY_VOLTAGE") {
123 }
else if (fieldName ==
"DETID") {
124 if (valueSStr.str() != detectorId) test =
false;
125 }
else if (fieldName ==
"PMTEXT") {
131 if (validHv ==
true) vvvHv[lineId][domId][pmtId] = hv;
132 vvvupi[lineId][domId][pmtId] = upi;
133 if (streamName ==
"pmt_hv_settings") vvvupiExt[lineId][domId][pmtId] = upiExt;
140 catch (DBException x) {
141 std::cout << x.what() << std::endl;
149 double SolveAnalytic(
const double deg0,
const double deg1,
const double deg2,
const double tot) {
150 const double delta = deg1*deg1 - 4*deg2*(deg0 - tot);
151 if ((delta < 0) || (deg2 == 0))
return deg1? (tot - deg0)/deg1 : 0;
152 const double x1 = (-deg1 + sqrt(delta))/(2*deg2);
153 const double x2 = (-deg1 - sqrt(delta))/(2*deg2);
154 if (deg2 > 0)
return (x1 < x2)? x1 : x2;
155 else return (x1 < x2)? x2 : x1;
163 if (curFunction ==
"pol1") {
164 curSol.first =
SolveAnalytic(vParameter[1], vParameter[2], 0, tot);
165 curSol.second = vParameter[2]*curSol.first + vParameter[1];
166 }
else if (curFunction ==
"pol2") {
167 curSol.first =
SolveAnalytic(vParameter[1], vParameter[2], vParameter[3], tot);
168 curSol.second = vParameter[3]*pow(curSol.first, 2) + vParameter[2]*curSol.first + vParameter[1];
169 }
else if (curFunction ==
"[0] + sqrt([1] - [2]*x)") {
170 curSol.first = (vParameter[2] - pow(tot - vParameter[1], 2))/vParameter[3];
171 curSol.second = vParameter[1] + sqrt(vParameter[2] - vParameter[3]*curSol.first);
181 void FillGraph(TGraphErrors*& graph, TH1D*& hChi2, TH1D*& histo,
const double hv,
int& localCounter) {
182 const int firstBin = 15;
183 const int lastBin = histo->GetXaxis()->GetLast() - 60;
184 histo->GetXaxis()->SetRange(firstBin, lastBin);
185 if (!histo->GetEntries())
return;
186 if (!histo->Integral())
return;
187 const int maxBin = histo->GetMaximumBin();
188 double bestRedChi2 = 1e6;
190 for (
int binInf = maxBin - 6; binInf < maxBin; ++binInf) {
191 for (
int binSup = maxBin + 1; binSup <= maxBin + 6; ++binSup) {
192 if (binSup - binInf < 4)
continue;
193 TF1* gausFit =
new TF1(
"gausFit",
"gaus", binInf, binSup);
194 const double curInteg = histo->Integral(binInf, binSup);
195 if (curInteg == 0)
continue;
196 histo->Fit(gausFit,
"RQ");
197 if (!gausFit->GetNDF()) {
201 const double fitMean = gausFit->GetParameter(1);
202 const double fitSigma = gausFit->GetParameter(2);
203 const double reducedChi2 = gausFit->GetChisquare()/gausFit->GetNDF();
204 if ((std::fabs(reducedChi2 - 1) < std::fabs(bestRedChi2 - 1)) && (reducedChi2 > 0.5) && (fitSigma < 10)) {
205 bestRedChi2 = reducedChi2;
211 hChi2->Fill(bestRedChi2);
212 histo->GetXaxis()->SetRange(0, lastBin);
214 graph->SetPoint(localCounter, hv, bestMean);
222 for (
unsigned int line = 0; line < vvvHvRange.size(); ++line) {
223 for (
unsigned int dom = 0; dom < vvvHvRange[line].size(); ++dom) {
224 for (
unsigned int pmt = 0; pmt < vvvHvRange[line][dom].size(); ++pmt) {
225 double minHvDiff = 1e8;
226 double maxHvDiff = 0;
227 for (
unsigned int run = 0; run < vvvRunHv.size(); ++run) {
228 if ((vvvRunHv[run][line][dom][pmt] - vvvHv[line][dom][pmt]) < minHvDiff)
229 minHvDiff = vvvRunHv[run][line][dom][pmt] - vvvHv[line][dom][pmt];
230 if (((vvvRunHv[run][line][dom][pmt] - vvvHv[line][dom][pmt]) > maxHvDiff) &&(vvvRunHv[run][line][dom][pmt]))
231 maxHvDiff = vvvRunHv[run][line][dom][pmt] - vvvHv[line][dom][pmt];
233 vvvHvRange[line][dom][pmt] = std::make_pair(minHvDiff, maxHvDiff);
242 TF1* fLocal =
new TF1(curFunction.c_str(), curFunction.c_str(), range.first, range.second);
243 if (curFunction ==
"[0] + sqrt([1] - [2]*x)")
244 fLocal->SetParameter(1, range.second + 25.0);
245 localGraph->Fit(fLocal, curOptions.c_str());
246 const int ndf = fLocal->GetNDF();
247 const double chi2 = fLocal->GetChisquare();
248 double reducedChi2 = 0;
250 reducedChi2 = chi2/ndf;
252 vParameter.push_back(reducedChi2);
253 for (
int p = 0; p < fLocal->GetNpar(); ++p) {
254 vParameter.push_back(fLocal->GetParameter(p));
258 int main(
int argc,
char **argv)
262 using namespace KM3NETDAQ;
264 gStyle->SetLegendBorderSize(0);
265 struct timeval startTimeTv;
266 gettimeofday(&startTimeTv, NULL);
267 time_t startTime = (time_t)startTimeTv.tv_sec;
268 tm* startGmTime = gmtime(&startTime);
269 const string startUTCTime = asctime(startGmTime);
271 JMultipleFileScanner<JDAQTimesliceTypes_t> vInputFiles;
273 std::string detectorFile;
274 std::string outXMLFile;
277 std::string mycookies;
278 std::string testType;
279 std::string location;
282 std::string hvDefault;
292 zap[
'T'] =
make_field(testType) =
"HV-TUNING-V2";
293 zap[
'w'] =
make_field(location) =
"A00070004";
299 catch(
const exception& error) {
300 FATAL(error.what() << endl);
305 load(detectorFile, detector);
307 catch(
const JException& error) {
310 const JModuleRouter moduleRouter(detector);
313 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
314 const int curId = module->getString();
315 if (lineIds.size() == 0) {
316 lineIds.push_back(curId);
319 for (
unsigned int l = 0; l < lineIds.size(); ++l) {
320 if (curId == lineIds[l]) {
324 if (newLine ==
true) {
325 lineIds.push_back(curId);
329 const unsigned int lineNb = lineIds.size();
331 const int AllDomNb = detector.size();
332 const int runNb = vInputFiles.size();
334 const int domNb = AllDomNb/lineNb;
335 const double diffHVMax = 250;
344 string cookiesContent;
345 ifstream incookies(mycookies.c_str(), ofstream::in);
346 getline(incookies, cookiesContent);
358 stringstream detectorIdSStr;
359 int detectorId = detector.getID();
360 detectorIdSStr << detectorId;
361 string detectorIdStr = detectorIdSStr.str();
363 string streamName =
"pmt_hv_settings";
365 AccessDB(vvvupi, vvvupiExt, vvvHv, cookiesContent, username, streamName, detectorIdStr, -1, hvDefault, lineIds);
371 vhToTReducedChi2.resize(runNb);
372 for (
int run = 0; run < runNb; ++run) {
373 ostringstream plotname;
374 plotname <<
"hToTReducedChi2-run" << run + 1;
375 vhToTReducedChi2[run] =
new TH1D(plotname.str().c_str(), plotname.str().c_str(), 101, -0.05, 10.05);
376 for (
unsigned int line = 0; line < lineNb; ++line) {
377 for (
int dom = 0; dom < domNb; ++dom) {
378 for (
int pmt = 0; pmt < pmtNb; ++pmt) {
381 plotname <<
"hToT-run" << run + 1 <<
"-line" << line + 1 <<
"-dom" << dom + 1 <<
"-pmt" << pmt;
382 vhToT[run][line][dom][pmt] =
new TH1D(plotname.str().c_str(), plotname.str().c_str(), 301, -0.5, 300.5);
392 JROOTClassSelector selector(
"JDAQTimesliceL1");
395 for ( ; in.
hasNext() && counter != vInputFiles.getLimit(); ++counter) {
398 if (newRun != oldRun) {
399 streamName =
"pmt_hv_run_settings";
401 AccessDB(vvvupi, vvvupiExt, vvvRunHv[runCounter], cookiesContent, username, streamName, detectorIdStr, newRun, hvDefault, lineIds);
403 runList.push_back(newRun);
406 for (JDAQTimeslice::const_iterator super_frame = timeslice->begin(); super_frame != timeslice->end(); ++super_frame) {
407 const int domId = super_frame->getModuleID();
408 const JModule module = moduleRouter.getModule(domId);
409 const int lineIndex = module.getString() - 1;
410 const int domIndex = module.getFloor() - 1;
412 const double hitToT = hit->getToT();
413 const int pmtIndex = hit->getPMT();
414 const int pmtId = module.getPMT(pmtIndex).getID();
415 if (pmtId != vvvupi[lineIndex][domIndex][pmtIndex]) {
416 DEBUG(
"mismatch between pmt id of detector file " << pmtId <<
" and the xml file "
417 << vvvupi[lineIndex][domIndex][pmtIndex] << endl);
420 vhToT[runCounter - 1][lineIndex][domIndex][pmtIndex]->Fill(hitToT);
427 for (
unsigned int line = 0; line < lineNb; ++line) {
428 for (
int dom = 0; dom < domNb; ++dom) {
430 for (
int pmt = 0; pmt < pmtNb; ++pmt) {
431 vgToTvsHV[line][dom][pmt] =
new TGraphErrors();
432 int localCounter = 0;
433 for (
int run = 0; run < runNb; ++run) {
434 if (vvvRunHv[run][line][dom][pmt] == 0)
continue;
435 FillGraph(vgToTvsHV[line][dom][pmt], vhToTReducedChi2[run], vhToT[run][line][dom][pmt], vvvRunHv[run][line][dom][pmt] - vvvHv[line][dom][pmt], localCounter);
437 if ((localCounter < runNb) && (localCounter > 0))
438 DEBUG(
"only " << localCounter <<
" runs out of " << runNb <<
" have ToT data for line " << line + 1 <<
" - dom " << dom + 1 <<
" - pmt " << pmt << endl);
439 if (localCounter == 0) ++fullDom;
442 DEBUG(fullDom <<
" pmt do not have data in dom " << dom + 1 <<
" of line " << line + 1 << endl);
447 fstream outCalibXml(outXMLFile.c_str(), ofstream::out);
448 struct timeval endTimeTv;
449 gettimeofday(&endTimeTv, NULL);
450 time_t endTime = (time_t)endTimeTv.tv_sec;
451 tm* endGmTime = gmtime(&endTime);
452 const string endUTCTime = asctime(endGmTime);
454 ostringstream endTimeStr;
455 endTimeStr << 1900 + endGmTime->tm_year <<
"-" << std::setw(2) << std::setfill(
'0')
456 << endGmTime->tm_mon + 1 <<
"-" << std::setw(2) << std::setfill(
'0')
457 << endGmTime->tm_mday <<
"T" << std::setw(2) << std::setfill(
'0')
458 << endGmTime->tm_hour <<
":" << std::setw(2) << std::setfill(
'0')
459 << endGmTime->tm_min <<
":" << std::setw(2) << std::setfill(
'0')
460 << endGmTime->tm_sec <<
"." << std::setw(6) << std::setfill(
'0')
461 << endTimeTv.tv_usec <<
"+01:00";
462 ostringstream startTimeStr;
463 startTimeStr << 1900 + startGmTime->tm_year <<
"-" << std::setw(2) << std::setfill(
'0')
464 << startGmTime->tm_mon + 1 <<
"-" << std::setw(2) << std::setfill(
'0')
465 << startGmTime->tm_mday <<
"T" << std::setw(2) << std::setfill(
'0')
466 << startGmTime->tm_hour <<
":" << std::setw(2) << std::setfill(
'0')
467 << startGmTime->tm_min <<
":" << std::setw(2) << std::setfill(
'0')
468 << startGmTime->tm_sec <<
"." << std::setw(6) << std::setfill(
'0')
469 << startTimeTv.tv_usec <<
"+01:00";
470 outCalibXml <<
"<ProductTestSession>\r\n";
472 outCalibXml <<
"\t<User>" << username <<
"</User>\r\n";
473 outCalibXml <<
"\t<Location>" << location <<
"</Location>\r\n";
474 outCalibXml <<
"\t<StartTime>" << startTimeStr.str() <<
"</StartTime>\r\n";
475 outCalibXml <<
"\t<EndTime>" << endTimeStr.str() <<
"</EndTime>\r\n";
476 outCalibXml <<
"\t<TestType>" << testType <<
"</TestType>\r\n";
477 outCalibXml <<
"\t<Tests>\r\n";
478 TCanvas* cToTvsHV =
new TCanvas(
"cToTvsHV",
"cToTvsHV", 800, 600);
479 TH1D* hToTvsHVReducedChi2 =
new TH1D(
"hToTvsHVReducedChi2",
"hToTvsHVReducedChi2", 101, -0.05, 10.05);
480 TH1D* hToTExpected =
new TH1D(
"hToTExpected",
"hToTExpected", 100001, -0.0005, 100.0005);
481 bool firstEvent =
true;
487 int counterLinear = 0;
488 int counter2Order = 0;
489 int counter2OrderPos = 0;
490 int counter2OrderNeg = 0;
492 double aveLinearSlope = 0;
493 for (
unsigned int line = 0; line < lineNb; ++line) {
494 for (
int dom = 0; dom < domNb; ++dom) {
495 for (
int pmt = 0; pmt < pmtNb; ++pmt) {
496 stringstream filename;
499 filename <<
"ToTvsHV-line" << line + 1 <<
"-dom" << dom + 1 <<
"-pmt" << pmt;
500 vgToTvsHV[line][dom][pmt]->SetName(filename.str().c_str());
501 const int pointNb = vgToTvsHV[line][dom][pmt]->GetN();
504 vgToTvsHV[line][dom][pmt]->SetLineColor(line*18 + dom*31 + pmt);
505 vgToTvsHV[line][dom][pmt]->SetMarkerColor(line*18 + dom*31 + pmt);
506 vgToTvsHV[line][dom][pmt]->SetMarkerStyle(2);
507 vgToTvsHV[line][dom][pmt]->SetMarkerSize(1);
508 if (firstEvent ==
true) {
510 vgToTvsHV[line][dom][pmt]->SetTitle(
"");
511 vgToTvsHV[line][dom][pmt]->GetXaxis()->SetTitle(
"HV_{offset} [V]");
512 vgToTvsHV[line][dom][pmt]->GetXaxis()->CenterTitle();
513 vgToTvsHV[line][dom][pmt]->GetXaxis()->SetTitleOffset(1.2);
514 vgToTvsHV[line][dom][pmt]->GetXaxis()->SetRangeUser(-200, +200);
515 vgToTvsHV[line][dom][pmt]->GetYaxis()->SetTitle(
"ToT values [ns]");
516 vgToTvsHV[line][dom][pmt]->GetYaxis()->CenterTitle();
517 vgToTvsHV[line][dom][pmt]->GetYaxis()->SetTitleOffset(1.2);
518 vgToTvsHV[line][dom][pmt]->GetYaxis()->SetRangeUser(0, 80);
519 vgToTvsHV[line][dom][pmt]->Draw(
"APL");
521 vgToTvsHV[line][dom][pmt]->GetXaxis()->SetRangeUser(-200, +200);
522 vgToTvsHV[line][dom][pmt]->Draw(
"samePL");
526 string functionFormula =
"";
529 const string pol2Name =
"pol2";
532 const string pol1Name =
"pol1";
535 const string sqrtName =
"[0] + sqrt([1] - [2]*x)";
538 const double testChi2 = min({fabs(vParameterPol1[0] - 1), fabs(vParameterPol2[0] - 1), fabs(vParameterSqrt[0] - 1)});
539 if (testChi2 == fabs(vParameterPol1[0] - 1)) {
540 vParameter = vParameterPol1;
541 functionFormula = pol1Name;
542 aveLinearSlope += vParameterPol1[2];
544 }
else if (testChi2 == fabs(vParameterPol2[0] - 1)) {
545 vParameter = vParameterPol2;
546 functionFormula = pol2Name;
548 if (vParameterPol2[3] > 0) ++counter2OrderPos;
549 else ++counter2OrderNeg;
550 }
else if (testChi2 == fabs(vParameterSqrt[0] - 1)) {
551 vParameter = vParameterSqrt;
552 functionFormula = sqrtName;
555 DEBUG(
"problem in the function definition, check the code at about line 500");
557 vgToTvsHV[line][dom][pmt]->Fit(functionFormula.c_str(),
"RQ");
558 hToTvsHVReducedChi2->Fill(vParameter[0]);
559 if (vParameter[0] > redChi2Max)
DEBUG(
"ToTvsHV fit may be bad for pmt " << pmt <<
" of dom " << dom + 1 <<
" of line " << line + 1 <<
", the reduced chi square is " << vParameter[0] << endl);
560 hvAndToTOpt =
Solve(vParameter, functionFormula, tot);
561 if ((hvAndToTOpt.first == -1) && (hvAndToTOpt.second == -1))
562 DEBUG(
"function used for fitting " << functionFormula <<
" is not handled by the code. Change the code or use a predefined function such as pol1 or pol2" << endl);
563 if ((fabs(vParameter[2]) > slopeMax) && ((functionFormula ==
"pol1") || (functionFormula ==
"pol2")))
564 DEBUG(
"ToTvsHV fit may be bad for pmt " << pmt <<
" of dom " << dom + 1 <<
" of line " << line + 1 <<
", the slope at 0 is " << vParameter[2] << endl);
565 hToTExpected->Fill(hvAndToTOpt.second);
567 if (fabs(hvAndToTOpt.first) > diffHVMax) hvAndToTOpt.first = 0;
568 vvvHvOpt[line][dom][pmt] = hvAndToTOpt.first;
569 outCalibXml <<
"\t\t<ProductTest>\r\n";
570 outCalibXml <<
"\t\t\t<UPI>3.4.2.3/HAMA-R12199/" << vvvupiExt[line][dom][pmt] <<
"." << vvvupi[line][dom][pmt] <<
"</UPI>\r\n";
571 outCalibXml <<
"\t\t\t<TestResult>OK</TestResult>\r\n";
572 outCalibXml <<
"\t\t\t<TestParameters>\r\n";
573 outCalibXml <<
"\t\t\t\t<ProductTestParameter>\r\n";
574 outCalibXml <<
"\t\t\t\t\t<Name>PMT_Supply_Voltage</Name>\r\n";
575 outCalibXml <<
"\t\t\t\t\t<Values>\r\n";
576 outCalibXml <<
"\t\t\t\t\t\t<string>" << hvAndToTOpt.first + vvvHv[line][dom][pmt] <<
"</string>\r\n";
577 outCalibXml <<
"\t\t\t\t\t</Values>\r\n";
578 outCalibXml <<
"\t\t\t\t</ProductTestParameter>\r\n";
579 outCalibXml <<
"\t\t\t\t<ProductTestParameter>\r\n";
580 outCalibXml <<
"\t\t\t\t\t<Name>RUN_NUMBER</Name>\r\n";
581 outCalibXml <<
"\t\t\t\t\t<Values>\r\n";
582 for (
int run = 0; run < runNb; ++run) {
583 outCalibXml <<
"\t\t\t\t\t\t<string>" << runList[run] <<
"</string>\r\n";
585 outCalibXml <<
"\t\t\t\t\t</Values>\r\n";
586 outCalibXml <<
"\t\t\t\t</ProductTestParameter>\r\n";
587 outCalibXml <<
"\t\t\t\t<ProductTestParameter>\r\n";
588 outCalibXml <<
"\t\t\t\t\t<Name>PMT_Time_over_Threshold</Name>\r\n";
589 outCalibXml <<
"\t\t\t\t\t<Values>\r\n";
590 outCalibXml <<
"\t\t\t\t\t\t<string>" << tot*1e-9 <<
"</string>\r\n";
591 outCalibXml <<
"\t\t\t\t\t</Values>\r\n";
592 outCalibXml <<
"\t\t\t\t</ProductTestParameter>\r\n";
593 outCalibXml <<
"\t\t\t</TestParameters>\r\n";
594 outCalibXml <<
"\t\t</ProductTest>\r\n";
598 cout <<
"linear:" << counterLinear <<
" - 2nd order (pos, neg):" << counter2Order
599 <<
"(" << counter2OrderPos <<
"," << counter2OrderNeg <<
")"
600 <<
" - sqrt:" << counterSqrt <<
" - linear slope average: "
601 << aveLinearSlope/counterLinear << endl;
602 outCalibXml <<
"\t</Tests>\r\n";
603 outCalibXml <<
"</ProductTestSession>\r\n";
605 cToTvsHV->SaveAs(
"figs/cToTvsHV.png");
606 cToTvsHV->SaveAs(
"figs/cToTvsHV.root");
608 ostringstream osstxt;
611 osstxt <<
"HVTuning-det" << detectorId <<
".txt";
613 ofstream outHv(osstxt.str().c_str(), ofstream::out);
614 for (
unsigned int line = 0; line < lineNb; ++line) {
615 for (
int dom = 0; dom < domNb; ++dom) {
616 for (
int pmt = 0; pmt < pmtNb; ++pmt) {
617 outHv << line + 1 <<
' ' << dom + 1 <<
' ' << pmt <<
' ' << vvvupiExt[line][dom][pmt] <<
' ' << vvvupi[line][dom][pmt] <<
' ' << vvvHv[line][dom][pmt] <<
' ' << vvvHvOpt[line][dom][pmt] + vvvHv[line][dom][pmt] << endl;
623 TCanvas* cToTs[lineNb][domNb];
624 for (
unsigned int line = 0; line < lineNb; ++line) {
625 for (
int dom = 0; dom < domNb; ++dom) {
629 iss <<
"cToTs-line" << line + 1 <<
"-dom" << dom + 1;
630 cToTs[line][dom] =
new TCanvas(iss.str().c_str(), iss.str().c_str(), 800, 600);
631 cToTs[line][dom]->Divide(8,4);
632 for (
int pmt = 0; pmt < pmtNb; ++pmt) {
633 cToTs[line][dom]->cd(pmt + 1);
635 for (
int run = 0; run < runNb; ++run) {
636 vhToT[run][line][dom][pmt]->SetLineColor(run + 1);
637 if (vhToT[run][line][dom][pmt]->GetMaximum() > localMax) localMax = vhToT[run][line][dom][pmt]->GetMaximum();
639 vhToT[run][line][dom][pmt]->SetTitle(
"");
640 vhToT[run][line][dom][pmt]->SetStats(0);
641 vhToT[run][line][dom][pmt]->GetXaxis()->SetTitle(
"ToT values [ns]");
642 vhToT[run][line][dom][pmt]->GetXaxis()->CenterTitle();
643 vhToT[run][line][dom][pmt]->GetXaxis()->SetTitleOffset(1.2);
644 vhToT[run][line][dom][pmt]->GetXaxis()->SetRange(0, 100);
645 vhToT[run][line][dom][pmt]->Draw();
647 vhToT[run][line][dom][pmt]->Draw(
"same");
651 vhToT[0][line][dom][pmt]->GetYaxis()->SetRangeUser(0.1, 2*localMax);
655 iss <<
"figs/cToTs-line" << line + 1 <<
"-dom" << dom + 1 <<
".png";
656 cToTs[line][dom]->SaveAs(iss.str().c_str());
659 iss <<
"figs/cToTs-line" << line + 1 <<
"-dom" << dom + 1 <<
".root";
660 cToTs[line][dom]->SaveAs(iss.str().c_str());
664 TCanvas* cToTReducedChi2 =
new TCanvas(
"cToTReducedChi2",
"cToTReducedChi2", 800, 600);
665 for (
int run = 0; run < runNb; ++run) {
667 vhToTReducedChi2[run]->SetTitle(
"");
668 vhToTReducedChi2[run]->SetStats(0);
669 vhToTReducedChi2[run]->GetXaxis()->SetTitle(
"reduced #chi^{2}");
670 vhToTReducedChi2[run]->GetXaxis()->CenterTitle();
671 vhToTReducedChi2[run]->GetXaxis()->SetTitleOffset(1.2);
672 vhToTReducedChi2[run]->Draw();
674 vhToTReducedChi2[run]->Draw(
"same");
676 vhToTReducedChi2[run]->SetLineColor(run + 1);
678 cToTReducedChi2->SetLogy();
679 cToTReducedChi2->SaveAs(
"figs/cToT-ReducedChi2.png");
680 cToTReducedChi2->SaveAs(
"figs/cToT-ReducedChi2.root");
682 TCanvas* cToTvsHVReducedChi2 =
new TCanvas(
"cToTvsHVReducedChi2",
"cToTvsHVReducedChi2", 800, 600);
683 hToTvsHVReducedChi2->SetTitle(
"");
684 hToTvsHVReducedChi2->SetStats(0);
685 hToTvsHVReducedChi2->GetXaxis()->SetTitle(
"reduced #chi^{2}");
686 hToTvsHVReducedChi2->GetXaxis()->CenterTitle();
687 hToTvsHVReducedChi2->GetXaxis()->SetTitleOffset(1.2);
688 hToTvsHVReducedChi2->Draw();
689 cToTvsHVReducedChi2->SetLogy();
690 cToTvsHVReducedChi2->SaveAs(
"figs/cToTvsHV-ReducedChi2.png");
691 cToTvsHVReducedChi2->SaveAs(
"figs/cToTvsHV-ReducedChi2.root");
693 TCanvas* cToTExpected =
new TCanvas(
"cToTExpected",
"cToTExpected", 800, 600);
694 hToTExpected->SetTitle(
"");
695 hToTExpected->SetStats(0);
696 hToTExpected->GetXaxis()->SetTitle(
"Expected ToT value [ns]");
697 hToTExpected->GetXaxis()->CenterTitle();
698 hToTExpected->GetXaxis()->SetTitleOffset(1.2);
699 hToTExpected->Draw();
701 cToTExpected->SaveAs(
"figs/cToTExpected.png");
702 cToTExpected->SaveAs(
"figs/cToTExpected.root");
704 const int lineId1 = 0;
705 const int domId1 = 2;
706 const int pmtId1 = 5;
707 const int lineId2 = 0;
708 const int domId2 = 5;
709 const int pmtId2 = 7;
710 ostringstream issTemp;
711 issTemp <<
"cToTsdom" << domId1 + 1 <<
"pmt" << pmtId1;
712 TCanvas* cToTsdomxpmtx =
new TCanvas(issTemp.str().c_str(), issTemp.str().c_str(), 800, 600);
714 TLegend* leg1 =
new TLegend(0.70,0.55,0.90,0.90);
715 leg1->SetFillStyle(0);
716 double localMaxTemp = 0;
717 if ((lineId1 > lineNb - 1) || (domId1 > domNb - 1) || (pmtId1 > pmtNb - 1))
719 if (pmtTest ==
false) {
720 DEBUG(
"wrong PMT1 identification for sample plot");
722 ostringstream plotname0;
723 for (
int run = 0; run < runNb; ++run) {
724 vhToT[run][lineId1][domId1][pmtId1]->SetLineColor(run + 1);
725 if (vhToT[run][lineId1][domId1][pmtId1]->GetMaximum() > localMaxTemp) localMaxTemp = vhToT[run][lineId1][domId1][pmtId1]->GetMaximum();
727 vhToT[run][lineId1][domId1][pmtId1]->SetTitle(
"");
728 vhToT[run][lineId1][domId1][pmtId1]->SetStats(0);
729 vhToT[run][lineId1][domId1][pmtId1]->GetXaxis()->SetTitle(
"ToT values [ns]");
730 vhToT[run][lineId1][domId1][pmtId1]->GetXaxis()->CenterTitle();
731 vhToT[run][lineId1][domId1][pmtId1]->GetXaxis()->SetTitleOffset(1.2);
732 vhToT[run][lineId1][domId1][pmtId1]->GetXaxis()->SetRange(0, 100);
733 vhToT[run][lineId1][domId1][pmtId1]->Draw();
735 vhToT[run][lineId1][domId1][pmtId1]->Draw(
"same");
739 plotname0 <<
"HV: " << setprecision(2) << fixed
740 << vvvRunHv[run][lineId1][domId1][pmtId1] <<
"V";
741 leg1->AddEntry(vhToT[run][lineId1][domId1][pmtId1], plotname0.str().c_str(),
"l");
744 vhToT[0][lineId1][domId1][pmtId1]->GetYaxis()->SetRangeUser(0.1, 2*localMaxTemp);
748 issTemp <<
"figs/cToTs-line" << lineId1 + 1 <<
"-dom" << domId1 + 1 <<
"-pmt" << pmtId1 <<
".png";
749 cToTsdomxpmtx->SaveAs(issTemp.str().c_str());
752 issTemp <<
"figs/cToTs-line" << lineId1 + 1 <<
"-dom" << domId1 + 1 <<
"-pmt" << pmtId1 <<
".root";
753 cToTsdomxpmtx->SaveAs(issTemp.str().c_str());
758 issTemp <<
"cToTsdom" << domId2 + 1 <<
"pmt" << pmtId2;
759 TCanvas* cToTsdomxpmty =
new TCanvas(issTemp.str().c_str(), issTemp.str().c_str(), 800, 600);
761 TLegend* leg2 =
new TLegend(0.70,0.55,0.90,0.90);
762 if ((lineId2 > lineNb - 1) || (domId2 > domNb - 1) || (pmtId2 > pmtNb - 1))
764 if (pmtTest ==
false) {
765 DEBUG(
"wrong PMT2 identification for sample plot");
767 ostringstream plotname0;
768 for (
int run = 0; run < runNb; ++run) {
769 vhToT[run][lineId2][domId2][pmtId2]->SetLineColor(run + 1);
770 if (vhToT[run][lineId2][domId2][pmtId2]->GetMaximum() > localMaxTemp) localMaxTemp = vhToT[run][lineId2][domId2][pmtId2]->GetMaximum();
772 vhToT[run][lineId2][domId2][pmtId2]->SetTitle(
"");
773 vhToT[run][lineId2][domId2][pmtId2]->SetStats(0);
774 vhToT[run][lineId2][domId2][pmtId2]->GetXaxis()->SetTitle(
"ToT values [ns]");
775 vhToT[run][lineId2][domId2][pmtId2]->GetXaxis()->CenterTitle();
776 vhToT[run][lineId2][domId2][pmtId2]->GetXaxis()->SetTitleOffset(1.2);
777 vhToT[run][lineId2][domId2][pmtId2]->GetXaxis()->SetRange(0, 100);
778 vhToT[run][lineId2][domId2][pmtId2]->Draw();
780 vhToT[run][lineId2][domId2][pmtId2]->Draw(
"same");
784 plotname0 <<
"HV: " << setprecision(2) << fixed
785 << vvvRunHv[run][lineId2][domId2][pmtId2] <<
"V";
786 leg2->AddEntry(vhToT[run][lineId2][domId2][pmtId2], plotname0.str().c_str(),
"l");
789 vhToT[0][lineId2][domId2][pmtId2]->GetYaxis()->SetRangeUser(0.1, 2*localMaxTemp);
793 issTemp <<
"figs/cToTs-line" << lineId2 + 1 <<
"-dom" << domId2 + 1 <<
"-pmt" << pmtId2 <<
".png";
794 cToTsdomxpmty->SaveAs(issTemp.str().c_str());
797 issTemp <<
"figs/cToTs-line" << lineId2 + 1 <<
"-dom" << domId2 + 1 <<
"-pmt" << pmtId2 <<
".root";
798 cToTsdomxpmty->SaveAs(issTemp.str().c_str());
801 DEBUG(
"analysis duration: " << difftime(endTime, startTime) << endl);
void AccessDB(std::vector< std::vector< std::vector< int > > > &vvvupi, std::vector< std::vector< std::vector< int > > > &vvvupiExt, std::vector< std::vector< std::vector< double > > > &vvvHv, std::string &cookie, std::string &username, std::string &streamName, std::string &detectorId, const int runId, const std::string &hvDefault, std::vector< int > &lineIds)
Utility class to parse command line options.
void FillParameterFitFunction(std::vector< double > &vParameter, TGraphErrors *&localGraph, const std::string &curFunction, const std::string &curOptions, const std::pair< double, double > range)
void FindHVRange(std::vector< std::vector< std::vector< std::pair< double, double > > > > &vvvHvRange, std::vector< std::vector< std::vector< std::vector< double > > > > &vvvRunHv, std::vector< std::vector< std::vector< double > > > &vvvHv)
Long64_t counter_type
Type definition for counter.
Auxiliary class for multiplexing object iterators.
double SolveAnalytic(const double deg0, const double deg1, const double deg2, const double tot)
int getRunNumber() const
Get run number.
Data structure for detector geometry and calibration.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
virtual const pointer_type & next()
Get next element.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
General purpose messaging.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Direct access to module in detector data structure.
std::pair< double, double > Solve(std::vector< double > &vParameter, const std::string &curFunction, const double tot)
void FillGraph(TGraphErrors *&graph, TH1D *&hChi2, TH1D *&histo, const double hv, int &localCounter)
Utility class to parse command line options.
ROOT TTree parameter settings.
virtual bool hasNext()
Check availability of next element.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
#define DEBUG(A)
Message macros.
int main(int argc, char *argv[])