//20210621 //MiuMorita // // //eye_share_0.C : convert txt to root file of raw graph //eye_share_1.C : make eyediagram //eye_share_2.C : read data word //eye_share_3.C : analyze sync bit #ifndef EYE_CAL_0_C #define EYE_CAL_0_C #include "eye_share_1.C" //#include "eye_share_2.C" //#include "eye_share_3.C" #include using namespace std; TGraph* TexttoGraph(const char *fname){ ifstream fin(fname); vector x; vector y; string sbuf; while(!fin.eof()){ getline(fin,sbuf); TString stxt(sbuf); stxt.ReplaceAll(",", " "); istringstream iss(stxt.Data()); double tmpx, tmpy; iss >> tmpx >> tmpy; x.push_back(tmpx); y.push_back(tmpy); } TGraph *g = new TGraph(x.size(), &x[0], &y[0]); fin.close(); return g; } int CheckTopBottom(TGraph *g){ double x, y; int PP = 0; int MM = 0; for( int i = 0; i < g -> GetN(); i++ ){ g -> GetPoint(i, x, y); //y = g -> GetPointY(i); //GetPointY is used only version 6 if( y < 0 )MM++; else PP++; } if ( MM < PP )return 1; else return -1; } TGraph* SwapTopBottom(TGraph *g){ TGraph *g_ = new TGraph(); double x, y; for( int i = 0; i < g -> GetN(); i++ ){ g -> GetPoint(i, x, y); g_ -> SetPoint(i, x, -y); } return g_; } double VMaximum(TGraph *g){ double x, y; double max; g -> GetPoint(0, x, max); //double max = g -> GetPointY(0); for( int i = 1; i < g -> GetN(); i++ ){ g -> GetPoint(i, x, y); //y = g -> GetPointY(i); if( max < y )max = y; } return max; } double VMinimum(TGraph *g){ double x, y; double min; g -> GetPoint(0, x, min); for(int i = 1; i < g -> GetN(); i++){ g -> GetPoint(i, x, y); //y = g -> GetPointY(i); if(y < min)min = y; } return min; } TFile* ReCreateTxttoRoot(const char *fname){ TString foname(fname); foname.ReplaceAll(".txt", ".root"); TFile *foroot = TFile::Open(foname.Data(), "recreate"); cout << "recreate new root file : " << foname << endl; return foroot; } TFile* ReCreateRoot(const char *fname, string *pre){ TString foname(fname); foname.Prepend(Form("%s", pre)); TFile *foroot = TFile::Open(foname.Data(), "recreate"); cout << "recreate new root file : " << foname << endl; return foroot; } TGraph* GetGraphPart(TGraph *g, double min = NULL, double max = NULL){ double x, y; TGraph *g_part = new TGraph(); if( min != NULL) for( int i = 0; i < g -> GetN(); i++ ){ g -> GetPoint(i, x, y); if( max != NULL && min < x && x < max ){ //if( min < x && x < max ){ g_part -> SetPoint(i, x, y); } if( max != NULL && max < x )continue; //if( max < x )continue; } return g_part; } string axis_t = "time[s]"; string axis_V = "voltage[V]"; double tt, vv; void eye_share_0(const char *fname = "number.txt"){ gStyle -> SetOptStat(0); //0. read txt file and make waveform graph TGraph *g_raw = TexttoGraph(fname); int CTB = CheckTopBottom(g_raw); if(CTB == 1)TGraph *g_uni = SwapTopBottom(g_raw); else TGraph *g_uni = g_raw -> Clone(); double hmin = VMinimum(g_uni); double hmax = VMaximum(g_uni); double tmin, tmax; g_uni -> GetPoint(0, tmin, vv); //tmin = g_uni -> GetPointX(0); // g_uni -> GetPoint(g_uni -> GetN() - 1, tmax, vv); //tmax = g_uni -> GetPointX(g_uni -> GetN()); double pmax = tmin + 110e-9; TGraph *g_sync0 = GetGraphPart(g_uni, tmin, pmax); TString title1 = gSystem -> BaseName(fname); title1.ReplaceAll(".txt", ""); AxisTitle(g_raw , &title1, &axis_t, &axis_V); AxisTitle(g_uni , &title1, &axis_t, &axis_V); AxisTitle(g_sync0, &title1, &axis_t, &axis_V); //1. draw and graph and print png files TCanvas *c_raw = new TCanvas("c_raw", "c_raw", 1400, 450); c_raw -> cd(); g_raw -> Draw("AP"); TCanvas *c_uni = new TCanvas("c_uni", "c_uni", 1400, 450); c_uni -> cd(); g_uni -> Draw("AP"); TCanvas *c_sync0 = new TCanvas("c_sync0", "c_sync0", 1400, 450); c_sync0 -> cd(); g_sync0 -> Draw("AP"); //c_raw -> Print(Form("C:\\Users\\10miu\\Documents\\INTT\\picture\\eyediagram\\20210526-29\\eye0\\g_raw_%s.png" , title1.Data())); //c_uni -> Print(Form("C:\\Users\\10miu\\Documents\\INTT\\picture\\eyediagram\\20210526-29\\eye0\\g_uni_%s.png" , title1.Data())); //c_sync0 -> Print(Form("C:\\Users\\10miu\\Documents\\INTT\\picture\\eyediagram\\20210526-29\\eye0\\g_sync0_%s.png", title1.Data())); //2. make root.file //TFile *foroot = ReCreateTxttoRoot(fname); //g_raw -> SetName("g_raw" ); //g_uni -> SetName("g_uni" ); //g_sync0 -> SetName("g_sync0"); //g_raw -> Write(); //g_uni -> Write(); //g_sync0 -> Write(); //foroot -> Close(); } #endif