#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; // 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 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[4] = { 1, 2, 6, 4 }; const int kCatUse[kNCat] = { 0, 0, 1, 0, 0, 1, 0, 1, 1, 0 }; const int kCountUse[kNCat] = { 1, 0, 1, 0, 0}; const int kNCount = 5; // TotalChips TotalTests Trays Tester1 Tester2 const char *kCountStr[] = { "TotalChips", "TotalTests", "Trays", "Tester1", "Tester2" }; const int kNonQR = 1260; // offset for 10 non-QR trays in system, before we started with QR chips const int kNonQRCat[kNCat] = { 0, 516, 591, 105, 0, 48, 0, 0, 0, 0}; const int kNonQRCount[kNCount] = { 1260, 0, 10, 0, 0}; // just put in info for the non-QR trays const int kNonQRTested = 744; 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}; char hname[100]; char hdesc[100]; TH1F* hCat[kNCat]; TH1F* hCount[kNCount]; TH1F* hCatQR[kNCat]; TH1F* hCountQR[kNCount]; TH1F* hTestedChips; 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]); hCatQR[ic]->SetBinContent(idate, iCat[ic] - kNonQRCat[ic]); } for (ic=0; icSetBinContent(idate, iCount[ic]); hCountQR[ic]->SetBinContent(idate, iCount[ic] - kNonQRCount[ic]); } hTestedChips->SetBinContent(idate, iCount[0] - iCat[1]); hTestedChipsQR->SetBinContent(idate, iCount[0] - iCat[1] - kNonQRTested ); } } // in int maxDate = nlines - kNSkip; if (regeneratePlots) { // make plots // fit channel info, and store fit parameters (with errors) and chi2 values char name[50], description[100]; TCanvas* cAll = new TCanvas("cAll", "Test statistics #", 900, 600); TCanvas* cAllQR = new TCanvas("cAllQR", "Test statistics #", 900, 600); TLegend* legend = new TLegend(0.1,0.6,0.4,0.9); TLegend* legendQR = new TLegend(0.1,0.6,0.4,0.9); char leginfo[100]; int nAll = 0; 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"); // 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/allCat.png"); cAll->SaveAs("pdf/allCat.pdf"); cAllQR->cd(); legendQR->Draw(); t->DrawTextNDC(0.12, 0.5, leginfo); cAllQR->Modified(); cAllQR->SaveAs("png/allCatQR.png"); cAllQR->SaveAs("pdf/allCatQR.pdf"); // Count plots TLegend* legendCount = new TLegend(0.1,0.6,0.4,0.9); TLegend* legendCountQR = new TLegend(0.1,0.6,0.4,0.9); nAll = 0; 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]); legendCount->AddEntry(hCount[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]); legendCountQR->AddEntry(hCountQR[ic], leginfo, "l"); nAll++; } } // ic sprintf(leginfo, "%d", now.GetDate() - 1); cAll->cd(); legendCount->Draw(); t->DrawTextNDC(0.12, 0.5, leginfo); cAll->Modified(); cAll->SaveAs("png/allCount.png"); cAll->SaveAs("pdf/allCount.pdf"); cAllQR->cd(); legendCountQR->Draw(); t->DrawTextNDC(0.12, 0.5, leginfo); cAllQR->Modified(); cAllQR->SaveAs("png/allCountQR.png"); cAllQR->SaveAs("pdf/allCountQR.pdf"); } // 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; }