#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; const int debug = 0; //const int debug = 3; //DS test const bool regeneratePlots = true; //const bool regeneratePlots = false; const int kNCurr = 5; const int kNFiles = 5; // # of calibration points const double kPrecisionVin = 0.01; const double kPrecisionVout = 1; const int kMaxLineLength = 100; int analyse_file(const char *station, const char *outfile) { gStyle->SetOptStat(0); gStyle->SetOptFit(0111); gStyle->SetStatX(0.5); vector hTitle; hTitle.push_back("FE1_CURR"); hTitle.push_back("FE2_CURR"); hTitle.push_back("AD_CURR"); hTitle.push_back("DR_CURR"); hTitle.push_back("DG_CURR"); TGraphErrors *g1[kNCurr]; int nOK[kNCurr] = {0}; for (int ic=0; ic> Vin >> infile; if (! inLog.good()) break; cout << " Vin " << Vin << " infile " << infile << endl; nfiles++; int nlines = 0; // over whole file ifstream inADC; inADC.open(infile); while ( inADC.good() ) { inADC.getline(line, kMaxLineLength); if (! inADC.good()) break; // split line into the expected pieces int nf = 0; char * pch; pch = strtok (line," "); char title[100]; float Vout; while ( (pch != NULL) ) { printf ("nf %d pch %s\n",nf, pch); if (nf==2) sprintf(title, "%s", pch); if (nf==4) Vout = 1000 * atof(pch); // 1000 to convert from V to mV pch = strtok (NULL, " "); nf++; } cout << " nlines " << nlines << " nf " << nf << " title " << title << " Vout " << Vout << endl; int currline = nlines - 6; if ( (currline >= 0) && (currline < kNCurr) ) { g1[currline]->SetPoint(nOK[currline], Vin, Vout); g1[currline]->SetPointError(nOK[currline], kPrecisionVin, kPrecisionVout); nOK[currline]++; } nlines++; } // inADC } // infiles for (int ic=0; icSetMarkerStyle(20); g1[ic]->SetTitle("Max - Baseline"); // fit info, and store fit parameters (with errors) and chi2 values char name[50], description[100]; TCanvas* c1 = new TCanvas("c1", "Amplitude vs Vin", 900, 600); if (nOK[ic] < 2) continue; // don't try to fit an empty plot TF1 *func1 = new TF1("func1","[0] + [1]*x", 1, 21); func1->SetParameter(0, 0); func1->SetParameter(1, 0.05); c1->cd(); g1[ic]->Fit("func1","RQ"); fprintf(fout, "%9s %7.2f +/- %3.2f %5.2f +/- %3.2f\n", hTitle[ic].c_str(), "", func1->GetParameter(0), func1->GetParError(0), func1->GetParameter(1), func1->GetParError(1) ); if (regeneratePlots) { g1[ic]->Draw("A*"); sprintf(description, "Vout vs Vin for %s %s", station, hTitle[ic].c_str()); g1[ic]->GetXaxis()->SetTitle("Vin (mV)"); g1[ic]->GetYaxis()->SetTitle("Vout (mV)"); g1[ic]->SetTitle(description); c1->Modified(); sprintf(name, "%s/%s_%s.png", outdir, station, hTitle[ic].c_str()); c1->SaveAs(name); } // clean up if (func1) delete func1; if (g1[ic]) delete g1[ic]; } // ic fclose(fout); return 0; } int main (int argc, char *argv[]) { if (argc<2) { printf("not enough arguments: argc = %d\nSyntax should be:\n./calib.exe station\n",argc); printf("Example:\n./calib.exe sta2\n",argc); return -1; } int iSta = atoi(argv[1]); char* outfile = Form("calib_%s.log", argv[1]); int iret = analyse_file(argv[1], outfile); return iret; }