//20210625 //MiuMorita // //eye_share_1 : make eye diagram #ifndef EYE_CAL_1_C #define EYE_CAL_1_C #include "header.h" #include "eye_share_0.C" //#include "eye_share_2.C" //#include "eye_share_3.C" using namespace std; vector GetRiseCtrPoint(TGraph *g, double yctr){ double x, y; double x1, x2 = 0.; double y1, y2 = yctr; double x_buf = 0.; vector xctr; int GATE = 0; for( int i = 0; i < g -> GetN(); i++ ){ g -> GetPoint(i, x, y); if( y < yctr ){ x1 = x; y1 = y; GATE = 1; } if( y > yctr ){ x2 = x; y2 = y; GATE = 2; } if( y1 < yctr && yctr < y2 && GATE == 2 ){ x_buf = ( x1 * y2 - x2 * y1 ) / ( y2 - y1 ); xctr.push_back(x_buf); x1 = 0.; x2 = 0.; y1 = yctr; y2 = yctr; GATE = 0; } } return xctr; } TGraph* MakeEyeDiagram(TGraph *g, double d, double a, int l){ double x, y; int k = 0; TGraph *g_ = new TGraph(); for( int i = 0; i < g -> GetN(); i++ ){ g -> GetPoint( i, x, y ); for ( int j = 0; j < l; j++ ){ if( d + a * ( j - 2 ) < x && x < d + a * ( j + 1 )){ g_ -> SetPoint( k, x - ( d + a * ( j - 1 )), y ); k++; } } } return g_; } TH2D* GraphtoHist(TGraph *g, TH2D *h){ double x, y; for( int i = 0; i < g -> GetN(); i++){ g -> GetPoint( i, x, y ); h -> Fill( x, y ); } return h; } TGraph* SumGraph(TGraph *g, TGraph *g_, int k){ double x, y; for( int i = 0; i < g -> GetN(); i++){ g -> GetPoint( i, x, y ); g_ -> SetPoint( k, x, y ); k++; } return g_; } TLine* MakeMask(TLine *l, int i, double centx){ if( i == 0 )l = new TLine( centx - 1.01e-9, 0. , centx - 0.37e-9, 0.1); if( i == 1 )l = new TLine( centx - 0.37e-9, 0.1, centx + 0.37e-9, 0.1); if( i == 2 )l = new TLine( centx + 0.37e-9, 0.1, centx + 1.01e-9, 0. ); if( i == 3 )l = new TLine( centx + 1.01e-9, 0. , centx + 0.37e-9, -0.1); if( i == 4 )l = new TLine( centx + 0.37e-9, -0.1, centx - 0.37e-9, -0.1); if( i == 5 )l = new TLine( centx - 0.37e-9, -0.1, centx - 1.01e-9, 0. ); l -> SetLineColor(kRed); l -> SetLineWidth(2); return l; } void eye_share_1(const char *fname = "number.root", const Int_t cur = 2){ //0. read file.root TFile *file0 = TFile::Open(fname); gStyle -> SetOptStat(0); TGraph *g_uni = (TGraph*)file0 -> Get("g_uni"); TGraph *g_sync0 = (TGraph*)file0 -> Get("g_sync0"); //1. make eyediagram double hmin = VMinimum(g_uni); double hmax = VMaximum(g_uni); double hctr = hmin + cur * 0.1; double smin = VMinimum(g_sync0); double smax = VMaximum(g_sync0); double sctr = ( smin + smax ) / 2; vector ris_edge = GetRiseCtrPoint(g_uni, sctr); vector intvl; double sum_intvl = 0.; int BIT20 = 0; intvl.push_back(ris_edge[0]); for( int i = 0; i < ris_edge.size() - 1 ; i++){ tt = ris_edge[i + 1] - ris_edge[i]; if( 100e-9 < tt ){ intvl.push_back(ris_edge[i + 1]); sum_intvl += tt; BIT20++; } } double ave_intvl = sum_intvl / double( BIT20 ); double bit1 = ave_intvl / 20.; double sync_bit[20] = 0.; double min_intvl = ave_intvl - bit1 / 2.; double max_intvl = ave_intvl + bit1 / 2.; int BIT = 0; sync_bit[0] = intvl[0]; for( int i = 0; i < intvl.size() - 1; i++ ){ tt = intvl[i + 1] - intvl[i]; if( min_intvl < tt && tt < max_intvl ){ sync_bit[BIT] = intvl[i + 1]; BIT++; } if( min_intvl * 2 < tt && tt < max_intvl * 2 ){ sync_bit[BIT] = ( intvl[i + 1] + intvl[i] ) / 2; BIT++; sync_bit[BIT] = intvl[i + 1]; BIT++; } if( min_intvl * 3 < tt && tt < max_intvl * 3 ){ sync_bit[BIT] = ( intvl[i + 1] * 2 + intvl[i] ) / 3; BIT++; sync_bit[BIT] = ( intvl[i + 1] + intvl[i] * 2 ) / 3; BIT++; sync_bit[BIT] = intvl[i + 1]; BIT++; } } TGraph *g_eye_all = new TGraph(); TGraph *g_eye_sync = new TGraph(); TGraph *gc_eye_all = new TGraph(); TGraph *gc_eye_sync = new TGraph(); TGraph *gp_eye_all[20]; TGraph *gp_eye_sync[20]; TGraph *gpc_eye_all[20]; TGraph *gpc_eye_sync[20]; double const_bit = sync_bit[0]; for( int i = 0; i < BIT; i++){ const_bit += ave_intvl; gp_eye_all[i] = MakeEyeDiagram(g_uni, sync_bit[i], bit1, 20); gp_eye_sync[i] = MakeEyeDiagram(g_uni, sync_bit[i], bit1, 3); gpc_eye_all[i] = MakeEyeDiagram(g_uni, const_bit, bit1, 20); gpc_eye_sync[i] = MakeEyeDiagram(g_uni, const_bit, bit1, 3); } TString t_e_a("all"); TString t_e_s("sync"); TString tc_e_a("all -constant-"); TString tc_e_s("sync -constant-"); int tbin = 300; int vbin = 60 * ( 2 * cur + 1 ); double vmin = -0.1 * cur - 0.05; double vmax = 0.1 * cur + 0.05; TH2D *h_eye_all = new TH2D("h_eye_all" , "h_eye_all" , tbin, -2e-9, 7e-9, vbin, vmin, vmax); TH2D *h_eye_sync = new TH2D("h_eye_sync", "h_eye_sync", tbin, -2e-9, 7e-9, vbin, vmin, vmax); TH2D *hc_eye_all = new TH2D("hc_eye_all" , "hc_eye_all" , tbin, -2e-9, 7e-9, vbin, vmin, vmax); TH2D *hc_eye_sync = new TH2D("hc_eye_sync", "hc_eye_sync", tbin, -2e-9, 7e-9, vbin, vmin, vmax); int GALL = 0; int GSYNC = 0; int GCALL = 0; int GCSYNC = 0; for( int i = 0; i < BIT; i++){ g_eye_all = SumGraph(gp_eye_all[i] , g_eye_all , GALL); g_eye_sync = SumGraph(gp_eye_sync[i] , g_eye_sync , GSYNC); gc_eye_all = SumGraph(gpc_eye_all[i] , gc_eye_all , GCALL); gc_eye_sync = SumGraph(gpc_eye_sync[i], gc_eye_sync, GCSYNC); GALL = g_eye_all -> GetN(); GSYNC = g_eye_sync -> GetN(); GCALL = gc_eye_all -> GetN(); GCSYNC = gc_eye_sync -> GetN(); } AxisTitle(g_eye_all , &t_e_a , &axis_t, &axis_V); AxisTitle(g_eye_sync , &t_e_s , &axis_t, &axis_V); AxisTitle(gc_eye_all , &tc_e_a, &axis_t, &axis_V); AxisTitle(gc_eye_sync, &tc_e_s, &axis_t, &axis_V); AxisTitle(h_eye_all , &t_e_a , &axis_t, &axis_V); AxisTitle(h_eye_sync , &t_e_s , &axis_t, &axis_V); AxisTitle(hc_eye_all , &tc_e_a, &axis_t, &axis_V); AxisTitle(hc_eye_sync, &tc_e_s, &axis_t, &axis_V); h_eye_all = GraphtoHist( g_eye_all , h_eye_all ); h_eye_sync = GraphtoHist( g_eye_sync, h_eye_sync ); hc_eye_all = GraphtoHist( gc_eye_all , hc_eye_all ); hc_eye_sync = GraphtoHist( gc_eye_sync, hc_eye_sync ); //2. draw graph and histogram, and print file.png TCanvas *c_all = new TCanvas("c_all" , "c_all" , 600, 450); c_all -> cd(); h_eye_all -> Draw("col"); TCanvas *c_sync = new TCanvas("c_sync" , "c_sync" , 600, 450); c_sync -> cd(); h_eye_sync -> Draw("col"); TCanvas *cc_all = new TCanvas("cc_all" , "cc_all" , 600, 450); cc_all -> cd(); hc_eye_all -> Draw("col"); TCanvas *cc_sync = new TCanvas("cc_sync", "cc_sync", 600, 450); cc_sync -> cd(); hc_eye_sync -> Draw("col"); double centx = bit1 / 2.; //2.5 draw mask //for( int i = 0; i < 6; i++ ){ // lm[i] = MakeMask(lm[i], i, centx); //} //3. make file.root for eyediagram TString title1 = gSystem -> BaseName(fname); title1.ReplaceAll(".root", ""); //c_all -> Print(Form("C:\\Users\\10miu\\Documents\\INTT\\picture\\eyediagram\\20210526-29\\eye0\\h_eye_all_%s.png" , title1.Data())); //c_sync -> Print(Form("C:\\Users\\10miu\\Documents\\INTT\\picture\\eyediagram\\20210526-29\\eye0\\h_eye_sync_%s.png" , title1.Data())); //cc_all -> Print(Form("C:\\Users\\10miu\\Documents\\INTT\\picture\\eyediagram\\20210526-29\\eye0\\hc_eye_all_%s.png" , title1.Data())); //cc_sync -> Print(Form("C:\\Users\\10miu\\Documents\\INTT\\picture\\eyediagram\\20210526-29\\eye0\\hc_eye_sync_%s.png", title1.Data())); string seye = "eye_"; //TFile *foroot = ReCreateRoot(fname, &seye); //g_eye_all -> SetName("g_eye_all" ); //g_eye_sync -> SetName("g_eye_sync" ); //gc_eye_all -> SetName("gc_eye_all" ); //gc_eye_sync -> SetName("gc_eye_sync"); //g_eye_all -> Write(); //g_eye_sync -> Write(); //gc_eye_all -> Write(); //gc_eye_sync -> Write(); //h_eye_all -> Write(); //h_eye_sync -> Write(); //hc_eye_all -> Write(); //hc_eye_sync -> Write(); //foroot -> Close(); } #endif