#include "TText.h" #include "TH1F.h" #include "TProfile.h" #include "TMath.h" #include "TF1.h" #include "TLegend.h" #include "TCanvas.h" // #include "TROOT.h" //#include "TStyle.h" #include "TTree.h" #include "TFile.h" #include "TGraphErrors.h" #include "TStyle.h" #include #include #include #include #include #include // using namespace std; // for debug running: const int debug = 1; //DS test const bool regeneratePlots = true; //DS test const int kNMaxDays = 200; const int kFitDateStart = 1; // constants; reading data const int kNFields = 17; const int kMaxLineLength = 200; //const int kNSkip = 57; // skip first dates with only partial info, and until we were done with reprocessing; TPC prod start const int kNSkip = 153; // MuCh prod start on Dec 28, 2018 const int kNCat = 10; // Cat 0 to 9; 0:Empty 1:Untested 2:OK 3:Unknown 4:Bad 1 5:Bad 2 6:Bad 3 7:C1 8:C2 9:C3 const char *kCatStr[] = { "Empty", "Untested", "OK", "Unknown", "Bad1", "Bad2", "Bad3", "C1", "C2", "C3" }; // we use kOK = 2, kBad2 = 5, kC1 = 7, kC2 = 8 const int kLineColor[5] = { 1, 2, 6, 4, 1 }; const int kCatUse[kNCat] = { 0, 0, 1, 0, 0, 1, 0, 1, 1, 0 }; const int kNCount = 5; // TotalChips TotalTests Trays Tester1 Tester2 const char *kCountStr[] = { "TotalChips", "TotalTests", "Trays", "Tester1", "Tester2" }; const int kCountUse[kNCount] = { 1, 0, 0, 0, 0}; const int kNonQR = 1260; // offset for 10 non-QR trays in system, before we started with QR chips const int kNonQRCat[kNCat] = { 0, 1, 989, 1, 0, 130, 0, 111, 29, 0}; const int kNonQRCount[kNCount] = { 1260, 0, 10, 630, 629}; // just put in info for the non-QR trays const int kNonQRTested = kNonQR - kNonQRCat[1]; int analyse_file(const char *infile) { gStyle->SetOptStat(0); gStyle->SetOptFit(0111); gStyle->SetStatX(0.5); ifstream in; in.open(infile); cout << " reading file " << infile << endl; // for each line int idate = 0; char cdate[11]; int itime = 0; char ctime[9]; int ic = 0; int iCat[kNCat] = {0}; int iCount[kNCount] = {0}; int firstCat[kNCat] = {0}; int firstCount[kNCount] = {0}; char hname[100]; char hdesc[100]; TH1F* hCat[kNCat]; TH1F* hCount[kNCount]; TH1F* hTestedChips; TH1F* hCatGrowth[kNCat]; TH1F* hCountGrowth[kNCount]; TH1F* hTestedChipsGrowth; TH1F* hCatQR[kNCat]; TH1F* hCountQR[kNCount]; TH1F* hTestedChipsQR; for (ic=0; ic2) { cout << "nlines " << nlines << " nf " << nf << endl; } if (nlines > kNSkip) { idate = nlines - kNSkip; if (idate == 1) { sprintf(firstDate, "%s", cdate); } if (debug>2) { cout << "Fill hist nlines " << nlines << endl; } for (ic=0; icSetBinContent(idate, iCat[ic]); hCatGrowth[ic]->SetBinContent(idate, iCat[ic] - firstCat[ic]); hCatQR[ic]->SetBinContent(idate, iCat[ic] - kNonQRCat[ic]); } for (ic=0; icSetBinContent(idate, iCount[ic]); hCountGrowth[ic]->SetBinContent(idate, iCount[ic] - firstCount[ic]); hCountQR[ic]->SetBinContent(idate, iCount[ic] - kNonQRCount[ic]); } hTestedChips->SetBinContent(idate, iCount[0] - iCat[1]); hTestedChipsGrowth->SetBinContent(idate, iCount[0] - iCat[1] - firstCount[0] + firstCat[1]); hTestedChipsQR->SetBinContent(idate, iCount[0] - iCat[1] - kNonQRTested ); } else { // not skipped for (ic=0; ic 0) { hCount[ic]->SetMarkerStyle(20); hCount[ic]->GetXaxis()->SetRangeUser(0, maxDate); hCount[ic]->GetXaxis()->SetTitle( Form("Days since %s", firstDate) ); hCount[ic]->GetYaxis()->SetTitle("Yield"); cAll->cd(); hCount[ic]->SetLineColor(kLineColor[nAll]); if (nAll == 0) { hCount[ic]->SetTitle("Test Statistics - All Chips"); hCount[ic]->Draw(); } else { hCount[ic]->Draw("SAME"); } sprintf(leginfo, "%s : %d", kCountStr[ic], iCount[ic]); legend->AddEntry(hCount[ic], leginfo, "l"); // Growth hCountGrowth[ic]->SetMarkerStyle(20); hCountGrowth[ic]->GetXaxis()->SetRangeUser(0, maxDate ); hCountGrowth[ic]->GetXaxis()->SetTitle( Form("Days since %s", firstDate) ); hCountGrowth[ic]->GetYaxis()->SetTitle("Yield"); cAllGrowth->cd(); hCountGrowth[ic]->SetLineColor(kLineColor[nAll]); if (nAll == 0) { hCountGrowth[ic]->SetTitle("Test Statistics - Growth : Chips"); hCountGrowth[ic]->Draw(); } else { hCountGrowth[ic]->Draw("SAME"); } sprintf(leginfo, "%s : %d", kCountStr[ic], iCount[ic] - firstCount[ic]); legendGrowth->AddEntry(hCountGrowth[ic], leginfo, "l"); // QR hCountQR[ic]->SetMarkerStyle(20); hCountQR[ic]->GetXaxis()->SetRangeUser(0, maxDate ); hCountQR[ic]->GetXaxis()->SetTitle( Form("Days since %s", firstDate) ); hCountQR[ic]->GetYaxis()->SetTitle("Yield"); cAllQR->cd(); hCountQR[ic]->SetLineColor(kLineColor[nAll]); if (nAll == 0) { hCountQR[ic]->SetTitle("Test Statistics - QR Chips"); hCountQR[ic]->Draw(); } else { hCountQR[ic]->Draw("SAME"); } sprintf(leginfo, "%s : %d", kCountStr[ic], iCount[ic] - kNonQRCount[ic]); legendQR->AddEntry(hCountQR[ic], leginfo, "l"); nAll++; } } // ic cAll->cd(); hTestedChips->Draw("SAME"); hTestedChips->SetLineColor(3); sprintf(leginfo, "Tested : %d", iCount[0] - iCat[1]); legend->AddEntry(hTestedChips, leginfo, "l"); cAllGrowth->cd(); hTestedChipsGrowth->Draw("SAME"); hTestedChipsGrowth->SetLineColor(3); sprintf(leginfo, "Tested : %d", iCount[0] - iCat[1] - firstCount[0] + firstCat[1]); legendGrowth->AddEntry(hTestedChipsGrowth, leginfo, "l"); cAllQR->cd(); hTestedChipsQR->Draw("SAME"); hTestedChipsQR->SetLineColor(3); sprintf(leginfo, "Tested : %d", iCount[0] - iCat[1] - kNonQRTested); legendQR->AddEntry(hTestedChipsQR, leginfo, "l"); for (ic=0; ic 0) { hCat[ic]->SetMarkerStyle(20); hCat[ic]->GetXaxis()->SetRangeUser(0, maxDate ); hCat[ic]->GetXaxis()->SetTitle( Form("Days since %s", firstDate) ); hCat[ic]->GetYaxis()->SetTitle("Yield"); cAll->cd(); hCat[ic]->SetLineColor(kLineColor[nAll]); if (nAll == 0) { hCat[ic]->SetTitle("Test Statistics - All Chips"); hCat[ic]->Draw(); } else { hCat[ic]->Draw("SAME"); } sprintf(leginfo, "%s : %d", kCatStr[ic], iCat[ic]); legend->AddEntry(hCat[ic], leginfo, "l"); // Growth hCatGrowth[ic]->SetMarkerStyle(20); hCatGrowth[ic]->GetXaxis()->SetRangeUser(0, maxDate ); hCatGrowth[ic]->GetXaxis()->SetTitle( Form("Days since %s", firstDate) ); hCatGrowth[ic]->GetYaxis()->SetTitle("Yield"); cAllGrowth->cd(); hCatGrowth[ic]->SetLineColor(kLineColor[nAll]); if (nAll == 0) { hCatGrowth[ic]->SetTitle("Test Statistics - Growth : Chips"); hCatGrowth[ic]->Draw(); } else { hCatGrowth[ic]->Draw("SAME"); } sprintf(leginfo, "%s : %d", kCatStr[ic], iCat[ic] - firstCat[ic]); legendGrowth->AddEntry(hCatGrowth[ic], leginfo, "l"); // QR hCatQR[ic]->SetMarkerStyle(20); hCatQR[ic]->GetXaxis()->SetRangeUser(0, maxDate ); hCatQR[ic]->GetXaxis()->SetTitle( Form("Days since %s", firstDate) ); hCatQR[ic]->GetYaxis()->SetTitle("Yield"); cAllQR->cd(); hCatQR[ic]->SetLineColor(kLineColor[nAll]); if (nAll == 0) { hCatQR[ic]->SetTitle("Test Statistics - QR Chips"); hCatQR[ic]->Draw(); } else { hCatQR[ic]->Draw("SAME"); } sprintf(leginfo, "%s : %d", kCatStr[ic], iCat[ic] - kNonQRCat[ic]); legendQR->AddEntry(hCatQR[ic], leginfo, "l"); nAll++; } } // ic TText *t = new TText(); t->SetTextSize(0.07); t->SetTextColor(2); TDatime now; sprintf(leginfo, "%d", now.GetDate() - 1); cAll->cd(); legend->Draw(); t->DrawTextNDC(0.12, 0.5, leginfo); cAll->Modified(); cAll->SaveAs("png/all.png"); cAll->SaveAs("pdf/all.pdf"); cAllGrowth->cd(); legendGrowth->Draw(); t->DrawTextNDC(0.12, 0.5, leginfo); cAllGrowth->Modified(); cAllGrowth->SaveAs("png/allGrowth.png"); cAllGrowth->SaveAs("pdf/allGrowth.pdf"); cAllQR->cd(); legendQR->Draw(); t->DrawTextNDC(0.12, 0.5, leginfo); cAllQR->Modified(); cAllQR->SaveAs("png/allQR.png"); cAllQR->SaveAs("pdf/allQR.pdf"); // try some fits also cAllGrowth->cd(); hTestedChipsGrowth->GetXaxis()->SetRangeUser(kFitDateStart, maxDate ); hTestedChipsGrowth->Fit("pol1"); hTestedChipsGrowth->Draw(); cAllGrowth->Modified(); cAllGrowth->SaveAs("png/TestedChipsGrowthFit.png"); hCatGrowth[2]->GetXaxis()->SetRangeUser(kFitDateStart, maxDate ); hCatGrowth[2]->Fit("pol1"); hCatGrowth[2]->Draw(); cAllGrowth->Modified(); cAllGrowth->SaveAs("png/OKChipsGrowthFit.png"); } // plots return 0; } int main (int argc, char *argv[]) { if (argc<2) { printf("not enough arguments: argc = %d\nSyntax should be:\n./history.exe statfilename\n",argc); printf("Example:\n./history.exe teststat.log\n"); return -1; } char* infile = argv[1]; int iret = analyse_file(infile); return iret; }