コード例 #1
0
void draw_analysis_mht_plots3( const char* infile = "outputfiles/analysis-output3-default.root", bool with_numbers = true, const char* save_file_base = "plot-dtt-analysis3" ) {

    gDirectory -> Delete( "h*" ) ;

    gStyle -> SetOptStat(0) ;

    loadHist( infile ) ;

    int wx(50), wy(50) ;





    //--- Canvas by Nb, 3x3 Njet vs HT grid

    for ( int nbi=0; nbi<=3; nbi++ ) {

        char cname[100] ;
        char ctitle[100] ;
        sprintf( cname, "can_draw_dtt_analysis1_nb%d", nbi ) ;
        sprintf( ctitle, "MHT distributions, Nb%d", nbi ) ;
        TCanvas* can = new TCanvas( cname, ctitle, 900, 900 ) ;
        can -> Divide( 3, 3 ) ;

        can -> SetWindowPosition( wx, wy ) ;
        wx += 50 ;
        wy += 20 ;

        int ci(1) ;

        for ( int hti=1; hti<4; hti++ ) {
            for ( int nji=1; nji<4; nji++ ) {

                can -> cd( ci++ ) ;

                char hname[100] ;

                sprintf( hname, "h_lostlep_mht_cdtt_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                TH1F* hpll_cdtt = (TH1F*) gDirectory -> FindObject( hname ) ;
                if ( hpll_cdtt == 0x0 ) {
                    printf("\n\n *** Missing hist %s\n\n", hname ) ;
                    return ;
                }

                sprintf( hname, "h_lostlep_mht_mc_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                TH1F* hpll_mc = (TH1F*) gDirectory -> FindObject( hname ) ;
                if ( hpll_mc == 0x0 ) {
                    printf("\n\n *** Missing hist %s\n\n", hname ) ;
                    return ;
                }

                do_plots( hpll_cdtt, hpll_mc ) ;
                if ( with_numbers) do_numbers( hpll_cdtt, hpll_mc ) ;

            } // nji
        } // hti


        char savefile[10000] ;
        sprintf( savefile, "outputfiles/%s-mht-nb%d.pdf", save_file_base, nbi ) ;
        can -> SaveAs( savefile ) ;

    } // nbi.




    //--- Canvas for sum over Nb, 3x3 Njet vs HT grid


    {   // sum over Nb

        char cname[100] ;
        char ctitle[100] ;
        sprintf( cname, "can_draw_dtt_analysis1_nball" ) ;
        sprintf( ctitle, "MHT distributions, all Nb" ) ;
        TCanvas* can = new TCanvas( cname, ctitle, 900, 900 ) ;
        can -> Divide( 3, 3 ) ;

        can -> SetWindowPosition( wx, wy ) ;
        wx += 50 ;
        wy += 20 ;

        int ci(1) ;

        for ( int hti=1; hti<4; hti++ ) {
            for ( int nji=1; nji<4; nji++ ) {

                can -> cd( ci++ ) ;

                char hname[1000] ;
                char htitle[1000] ;

                sprintf( hname, "h_lostlep_mht_cdtt_nb1_nj1_ht1_80bin" ) ;
                TH1F* hp_toclone = (TH1F*) gDirectory -> FindObject( hname ) ;
                if ( hp_toclone == 0x0 ) {
                    printf("\n\n *** Missing hist %s\n\n", hname ) ;
                    return ;
                }

                sprintf( hname, "h_mht_cdtt_nj%d_ht%d", nji, hti ) ;
                sprintf( htitle, "MHT, from cdtt, Njet%d, HT%d", nji, hti ) ;
                TH1F* hp_cdtt = (TH1F*) hp_toclone -> Clone( hname ) ;
                hp_cdtt -> Reset() ;
                hp_cdtt -> SetTitle( htitle ) ;

                sprintf( hname, "h_mht_mc_nj%d_ht%d", nji, hti ) ;
                sprintf( htitle, "MHT, from MC, Njet%d, HT%d", nji, hti ) ;
                TH1F* hp_mc = (TH1F*) hp_toclone -> Clone( hname ) ;
                hp_mc -> Reset() ;
                hp_mc -> SetTitle( htitle ) ;

                for ( int nbi=0; nbi<=3; nbi++ ) {
                    char hname[100] ;

                    sprintf( hname, "h_lostlep_mht_cdtt_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_cdtt = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_cdtt == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    sprintf( hname, "h_lostlep_mht_mc_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_mc = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_mc == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    hp_cdtt -> Add( hpll_cdtt ) ;
                    hp_mc   -> Add( hpll_mc ) ;

                } // nbi.

                do_plots( hp_cdtt, hp_mc ) ;
                if ( with_numbers) do_numbers( hp_cdtt, hp_mc ) ;

            } // nji
        } // hti


        char savefile[10000] ;
        sprintf( savefile, "outputfiles/%s-mht-nball.pdf", save_file_base ) ;
        can -> SaveAs( savefile ) ;

    } // sum over Nb






    //--- Canvas for HT bins --------------------------------------------------------------------

    {   // HT bins canvas

        char cname[100] ;
        char ctitle[100] ;
        sprintf( cname, "can_draw_dtt_analysis1_ht_bins" ) ;
        sprintf( ctitle, "MHT distributions, HT bins" ) ;
        TCanvas* can = new TCanvas( cname, ctitle, 400, 1100 ) ;
        can -> Divide( 1, 3 ) ;

        can -> SetWindowPosition( wx, wy ) ;
        wx += 50 ;
        wy += 20 ;

        int ci(1) ;

        for ( int hti=1; hti<4; hti++ ) {

            can -> cd( ci++ ) ;

            char hname[1000] ;
            char htitle[1000] ;

            sprintf( hname, "h_lostlep_mht_cdtt_nb1_nj1_ht%d_80bin", hti ) ;
            TH1F* hp_toclone = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp_toclone == 0x0 ) {
                printf("\n\n *** Missing hist %s\n\n", hname ) ;
                return ;
            }

            sprintf( hname, "h_mht_cdtt_ht%d", hti ) ;
            sprintf( htitle, "MHT, from cdtt, HT%d", hti ) ;
            TH1F* hp_cdtt = (TH1F*) hp_toclone -> Clone( hname ) ;
            hp_cdtt -> Reset() ;
            hp_cdtt -> SetTitle( htitle ) ;

            sprintf( hname, "h_mht_mc_ht%d", hti ) ;
            sprintf( htitle, "MHT, from MC, HT%d", hti ) ;
            TH1F* hp_mc = (TH1F*) hp_toclone -> Clone( hname ) ;
            hp_mc -> Reset() ;
            hp_mc -> SetTitle( htitle ) ;

            for ( int nji=1; nji<4; nji++ ) {
                for ( int nbi=0; nbi<4; nbi++ ) {

                    sprintf( hname, "h_lostlep_mht_cdtt_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_cdtt = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_cdtt == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    sprintf( hname, "h_lostlep_mht_mc_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_mc = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_mc == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    hp_cdtt -> Add( hpll_cdtt ) ;
                    hp_mc   -> Add( hpll_mc ) ;

                } // nbi
            } // nji

            do_plots( hp_cdtt, hp_mc ) ;
            if ( with_numbers) do_numbers( hp_cdtt, hp_mc ) ;

        } // hti

        char savefile[10000] ;
        sprintf( savefile, "outputfiles/%s-mht-ht.pdf", save_file_base ) ;
        can -> SaveAs( savefile ) ;

    } // HT bins canvas



    //--- Canvas for Njet bins --------------------------------------------------------------------

    {   // Njet bins canvas

        char cname[100] ;
        char ctitle[100] ;
        sprintf( cname, "can_draw_dtt_analysis1_njet_bins" ) ;
        sprintf( ctitle, "MHT distributions, Njet bins" ) ;
        TCanvas* can = new TCanvas( cname, ctitle, 400, 1100 ) ;
        can -> Divide( 1, 3 ) ;

        can -> SetWindowPosition( wx, wy ) ;
        wx += 50 ;
        wy += 20 ;

        int ci(1) ;

        for ( int nji=1; nji<4; nji++ ) {

            can -> cd( ci++ ) ;

            char hname[1000] ;
            char htitle[1000] ;

            sprintf( hname, "h_lostlep_mht_cdtt_nb1_nj1_ht1_80bin" ) ;
            TH1F* hp_toclone = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp_toclone == 0x0 ) {
                printf("\n\n *** Missing hist %s\n\n", hname ) ;
                return ;
            }

            sprintf( hname, "h_mht_cdtt_njet%d", nji ) ;
            sprintf( htitle, "MHT, from cdtt, Njet%d", nji ) ;
            TH1F* hp_cdtt = (TH1F*) hp_toclone -> Clone( hname ) ;
            hp_cdtt -> Reset() ;
            hp_cdtt -> SetTitle( htitle ) ;

            sprintf( hname, "h_mht_mc_njet%d", nji ) ;
            sprintf( htitle, "MHT, from MC, Njet%d", nji ) ;
            TH1F* hp_mc = (TH1F*) hp_toclone -> Clone( hname ) ;
            hp_mc -> Reset() ;
            hp_mc -> SetTitle( htitle ) ;

            for ( int hti=1; hti<4; hti++ ) {
                for ( int nbi=0; nbi<4; nbi++ ) {

                    sprintf( hname, "h_lostlep_mht_cdtt_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_cdtt = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_cdtt == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    sprintf( hname, "h_lostlep_mht_mc_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_mc = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_mc == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    hp_cdtt -> Add( hpll_cdtt ) ;
                    hp_mc   -> Add( hpll_mc ) ;

                } // nbi
            } // hti

            do_plots( hp_cdtt, hp_mc ) ;
            if ( with_numbers) do_numbers( hp_cdtt, hp_mc ) ;

        } // hti

        char savefile[10000] ;
        sprintf( savefile, "outputfiles/%s-mht-njet.pdf", save_file_base ) ;
        can -> SaveAs( savefile ) ;

    } // Njet bins canvas


    //--- Canvas for Nb bins --------------------------------------------------------------------

    {   // Nb bins canvas

        char cname[100] ;
        char ctitle[100] ;
        sprintf( cname, "can_draw_dtt_analysis1_nb_bins" ) ;
        sprintf( ctitle, "MHT distributions, Nb bins" ) ;
        TCanvas* can = new TCanvas( cname, ctitle, 400, 1100 ) ;
        can -> Divide( 1, 4 ) ;

        can -> SetWindowPosition( wx, wy ) ;
        wx += 50 ;
        wy += 20 ;

        int ci(1) ;

        for ( int nbi=0; nbi<4; nbi++ ) {

            can -> cd( ci++ ) ;

            char hname[1000] ;
            char htitle[1000] ;

            sprintf( hname, "h_lostlep_mht_cdtt_nb1_nj1_ht1_80bin" ) ;
            TH1F* hp_toclone = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp_toclone == 0x0 ) {
                printf("\n\n *** Missing hist %s\n\n", hname ) ;
                return ;
            }

            sprintf( hname, "h_mht_cdtt_nb%d", nbi ) ;
            sprintf( htitle, "MHT, from cdtt, Nb%d", nbi ) ;
            TH1F* hp_cdtt = (TH1F*) hp_toclone -> Clone( hname ) ;
            hp_cdtt -> Reset() ;
            hp_cdtt -> SetTitle( htitle ) ;

            sprintf( hname, "h_mht_mc_nb%d", nbi ) ;
            sprintf( htitle, "MHT, from MC, Nb%d", nbi ) ;
            TH1F* hp_mc = (TH1F*) hp_toclone -> Clone( hname ) ;
            hp_mc -> Reset() ;
            hp_mc -> SetTitle( htitle ) ;

            for ( int hti=1; hti<4; hti++ ) {
                for ( int nji=1; nji<4; nji++ ) {

                    sprintf( hname, "h_lostlep_mht_cdtt_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_cdtt = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_cdtt == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    sprintf( hname, "h_lostlep_mht_mc_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_mc = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_mc == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    hp_cdtt -> Add( hpll_cdtt ) ;
                    hp_mc   -> Add( hpll_mc ) ;

                } // nji
            } // hti

            do_plots( hp_cdtt, hp_mc ) ;
            if ( with_numbers) do_numbers( hp_cdtt, hp_mc ) ;

        } // hti

        char savefile[10000] ;
        sprintf( savefile, "outputfiles/%s-mht-nb.pdf", save_file_base ) ;
        can -> SaveAs( savefile ) ;

    } // Nb bins canvas





    //--- Canvas for sum over all --------------------------------------------------------------------

    {   // sum over all

        char cname[100] ;
        char ctitle[100] ;
        sprintf( cname, "can_draw_dtt_analysis1_all" ) ;
        sprintf( ctitle, "MHT distributions, all" ) ;
        TCanvas* can = new TCanvas( cname, ctitle, 700, 600 ) ;

        can -> SetWindowPosition( wx, wy ) ;
        wx += 50 ;
        wy += 20 ;

        char hname[1000] ;
        char htitle[1000] ;

        sprintf( hname, "h_lostlep_mht_cdtt_nb1_nj1_ht1_80bin" ) ;
        TH1F* hp_toclone = (TH1F*) gDirectory -> FindObject( hname ) ;
        if ( hp_toclone == 0x0 ) {
            printf("\n\n *** Missing hist %s\n\n", hname ) ;
            return ;
        }

        sprintf( hname, "h_mht_cdtt_all" ) ;
        sprintf( htitle, "MHT, from cdtt, all" ) ;
        TH1F* hp_cdtt = (TH1F*) hp_toclone -> Clone( hname ) ;
        hp_cdtt -> Reset() ;
        hp_cdtt -> SetTitle( htitle ) ;

        sprintf( hname, "h_mht_mc_all" ) ;
        sprintf( htitle, "MHT, from MC, all" ) ;
        TH1F* hp_mc = (TH1F*) hp_toclone -> Clone( hname ) ;
        hp_mc -> Reset() ;
        hp_mc -> SetTitle( htitle ) ;

        for ( int nbi=0; nbi<4; nbi++ ) {

            for ( int hti=1; hti<4; hti++ ) {
                for ( int nji=1; nji<4; nji++ ) {

                    sprintf( hname, "h_lostlep_mht_cdtt_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_cdtt = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_cdtt == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    sprintf( hname, "h_lostlep_mht_mc_nb%d_nj%d_ht%d_80bin", nbi, nji, hti ) ;
                    TH1F* hpll_mc = (TH1F*) gDirectory -> FindObject( hname ) ;
                    if ( hpll_mc == 0x0 ) {
                        printf("\n\n *** Missing hist %s\n\n", hname ) ;
                        return ;
                    }

                    hp_cdtt -> Add( hpll_cdtt ) ;
                    hp_mc   -> Add( hpll_mc ) ;

                } // nji
            } // hti

        } // nbi

        do_plots( hp_cdtt, hp_mc ) ;
        if ( with_numbers) do_numbers( hp_cdtt, hp_mc ) ;

        char savefile[10000] ;
        sprintf( savefile, "outputfiles/%s-mht-all.pdf", save_file_base ) ;
        can -> SaveAs( savefile ) ;

    } // sum over all


    //--- Canvas for superbins for MHT2, HT12 --------------------------------------------------------------------

    {

        char cname[100] ;
        char ctitle[100] ;
        sprintf( cname, "can_draw_dtt_analysis1_superbins_mht2_ht12" ) ;
        sprintf( ctitle, "MHT distributions for mht2 superbins, HT12 " ) ;
        TCanvas* can = new TCanvas( cname, ctitle, 1400, 700 ) ;
        can -> Divide(4,2) ;

        can -> SetWindowPosition( wx, wy ) ;
        wx += 50 ;
        wy += 20 ;

        char hname[1000] ;
        char htitle[1000] ;

        int ci(1) ;

        for ( int sbi=0; sbi<3; sbi++ ) {

            can -> cd(ci++ ) ;

            sprintf( hname, "h_lostlep_mht_cdtt_mht2_superbin%02d", sbi ) ;
            TH1F* hp_cdtt = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp_cdtt == 0x0 ) {
                printf("\n\n *** Missing hist %s\n\n", hname ) ;
                return ;
            }

            sprintf( hname, "h_lostlep_mht_mc_mht2_superbin%02d", sbi ) ;
            TH1F* hp_mc = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp_mc == 0x0 ) {
                printf("\n\n *** Missing hist %s\n\n", hname ) ;
                return ;
            }

            do_plots( hp_cdtt, hp_mc ) ;
            if ( with_numbers) do_numbers( hp_cdtt, hp_mc ) ;

        } // sbi


        char savefile[10000] ;
        sprintf( savefile, "outputfiles/%s-superbins-mht2-ht12.pdf", save_file_base ) ;
        can -> SaveAs( savefile ) ;

    } // superbins for mht2, ht12


    //--- Canvas for superbins for MHT2, HT3 --------------------------------------------------------------------

    {

        char cname[100] ;
        char ctitle[100] ;
        sprintf( cname, "can_draw_dtt_analysis1_superbins_mht2_ht3" ) ;
        sprintf( ctitle, "MHT distributions for mht2 superbins, HT3 " ) ;
        TCanvas* can = new TCanvas( cname, ctitle, 1400, 700 ) ;
        can -> Divide(4,2) ;

        can -> SetWindowPosition( wx, wy ) ;
        wx += 50 ;
        wy += 20 ;

        char hname[1000] ;
        char htitle[1000] ;

        int ci(1) ;

        for ( int sbi=3; sbi<6; sbi++ ) {

            can -> cd(ci++ ) ;

            sprintf( hname, "h_lostlep_mht_cdtt_mht2_superbin%02d", sbi ) ;
            TH1F* hp_cdtt = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp_cdtt == 0x0 ) {
                printf("\n\n *** Missing hist %s\n\n", hname ) ;
                return ;
            }

            sprintf( hname, "h_lostlep_mht_mc_mht2_superbin%02d", sbi ) ;
            TH1F* hp_mc = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp_mc == 0x0 ) {
                printf("\n\n *** Missing hist %s\n\n", hname ) ;
                return ;
            }

            do_plots( hp_cdtt, hp_mc ) ;
            if ( with_numbers) do_numbers( hp_cdtt, hp_mc ) ;

        } // sbi


        char savefile[10000] ;
        sprintf( savefile, "outputfiles/%s-superbins-mht2-ht3.pdf", save_file_base ) ;
        can -> SaveAs( savefile ) ;

    } // superbins for mht2, ht3



    //--- Canvas for superbins for MHT3 --------------------------------------------------------------------

    {

        char cname[100] ;
        char ctitle[100] ;
        sprintf( cname, "can_draw_dtt_analysis1_superbins_mht3" ) ;
        sprintf( ctitle, "MHT distributions for mht3 superbins" ) ;
        TCanvas* can = new TCanvas( cname, ctitle, 600, 900 ) ;
        can -> Divide(1,2) ;

        can -> SetWindowPosition( wx, wy ) ;
        wx += 50 ;
        wy += 20 ;

        char hname[1000] ;
        char htitle[1000] ;

        int ci(1) ;

        for ( int sbi=0; sbi<1; sbi++ ) {

            can -> cd(ci++ ) ;

            sprintf( hname, "h_lostlep_mht_cdtt_mht3_superbin%02d", sbi ) ;
            TH1F* hp_cdtt = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp_cdtt == 0x0 ) {
                printf("\n\n *** Missing hist %s\n\n", hname ) ;
                return ;
            }

            sprintf( hname, "h_lostlep_mht_mc_mht3_superbin%02d", sbi ) ;
            TH1F* hp_mc = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp_mc == 0x0 ) {
                printf("\n\n *** Missing hist %s\n\n", hname ) ;
                return ;
            }

            do_plots( hp_cdtt, hp_mc ) ;
            if ( with_numbers) do_numbers( hp_cdtt, hp_mc ) ;

        } // sbi


        char savefile[10000] ;
        sprintf( savefile, "outputfiles/%s-superbins-mht3.pdf", save_file_base ) ;
        can -> SaveAs( savefile ) ;

    } // superbins for mht3


} // draw_analysis_mht_plots3
コード例 #2
0
ファイル: pss_usrp.c プロジェクト: sdnnfv/srsLTE
int main(int argc, char **argv) {
  cf_t *buffer; 
  int frame_cnt, n; 
  void *uhd;
  srslte_pss_synch_t pss; 
  srslte_cfo_t cfocorr, cfocorr64; 
  srslte_sss_synch_t sss; 
  int32_t flen; 
  int peak_idx, last_peak;
  float peak_value; 
  float mean_peak; 
  uint32_t nof_det, nof_nodet, nof_nopeak, nof_nopeakdet;
  cf_t ce[SRSLTE_PSS_LEN]; 
  
  parse_args(argc, argv);

  if (N_id_2_sync == -1) {
    N_id_2_sync = cell_id%3;
  }
  uint32_t N_id_2 = cell_id%3;
  uint32_t N_id_1 = cell_id/3;

#ifndef DISABLE_GRAPHICS
  if (!disable_plots)
    init_plots();
#endif

  float srate = 15000.0*fft_size; 
  
  flen = srate*5/1000;

  printf("Opening UHD device...\n");
  if (cuhd_open(uhd_args, &uhd)) {
    fprintf(stderr, "Error opening uhd\n");
    exit(-1);
  }
  
  if (srate < 10e6) {
    cuhd_set_master_clock_rate(uhd, 4*srate);        
  } else {
    cuhd_set_master_clock_rate(uhd, srate);        
  }

  printf("Set RX rate: %.2f MHz\n", cuhd_set_rx_srate(uhd, srate) / 1000000);
  printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain));
  printf("Set RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000);
  cuhd_rx_wait_lo_locked(uhd);
  
  buffer = malloc(sizeof(cf_t) * flen * 2);
  if (!buffer) {
    perror("malloc");
    exit(-1);
  }
    
  if (srslte_pss_synch_init_fft(&pss, flen, fft_size)) {
    fprintf(stderr, "Error initiating PSS\n");
    exit(-1);
  }

  if (srslte_pss_synch_set_N_id_2(&pss, N_id_2_sync)) {
    fprintf(stderr, "Error setting N_id_2=%d\n",N_id_2_sync);
    exit(-1);
  }
  
  srslte_cfo_init(&cfocorr, flen); 
  srslte_cfo_init(&cfocorr64, flen); 
 
  if (srslte_sss_synch_init(&sss, fft_size)) {
    fprintf(stderr, "Error initializing SSS object\n");
    return SRSLTE_ERROR;
  }

  srslte_sss_synch_set_N_id_2(&sss, N_id_2);

  printf("N_id_2: %d\n", N_id_2);  

  cuhd_start_rx_stream(uhd);
  
  printf("Frame length %d samples\n", flen);
  printf("PSS detection threshold: %.2f\n", threshold);
  
  nof_det = nof_nodet = nof_nopeak = nof_nopeakdet = 0;
  frame_cnt = 0;
  last_peak = 0; 
  mean_peak = 0;
  int peak_offset = 0;
  float cfo; 
  float mean_cfo = 0; 
  uint32_t m0, m1; 
  uint32_t sss_error1 = 0, sss_error2 = 0, sss_error3 = 0; 
  uint32_t cp_is_norm = 0; 
  
  srslte_sync_t ssync; 
  bzero(&ssync, sizeof(srslte_sync_t));
  ssync.fft_size = fft_size;
  
  while(frame_cnt < nof_frames || nof_frames == -1) {
    n = cuhd_recv(uhd, buffer, flen - peak_offset, 1);
    if (n < 0) {
      fprintf(stderr, "Error receiving samples\n");
      exit(-1);
    }
    
    peak_idx = srslte_pss_synch_find_pss(&pss, buffer, &peak_value);
    if (peak_idx < 0) {
      fprintf(stderr, "Error finding PSS peak\n");
      exit(-1);
    }
        
    mean_peak = SRSLTE_VEC_CMA(peak_value, mean_peak, frame_cnt);
    
    if (peak_value >= threshold) {
      nof_det++;
        
      if (peak_idx >= fft_size) {

        // Estimate CFO 
        cfo = srslte_pss_synch_cfo_compute(&pss, &buffer[peak_idx-fft_size]);
        mean_cfo = SRSLTE_VEC_CMA(cfo, mean_cfo, frame_cnt);        

        // Correct CFO
        srslte_cfo_correct(&cfocorr, buffer, buffer, -mean_cfo / fft_size);               

        // Estimate channel
        if (srslte_pss_synch_chest(&pss, &buffer[peak_idx-fft_size], ce)) {
          fprintf(stderr, "Error computing channel estimation\n");
          exit(-1);
        }
        
        // Find SSS 
        int sss_idx = peak_idx-2*fft_size-(SRSLTE_CP_ISNORM(cp)?SRSLTE_CP_LEN(fft_size, SRSLTE_CP_NORM_LEN):SRSLTE_CP_LEN(fft_size, SRSLTE_CP_EXT_LEN));             
        if (sss_idx >= 0 && sss_idx < flen-fft_size) {
          srslte_sss_synch_m0m1_partial(&sss, &buffer[sss_idx], 3, NULL, &m0, &m0_value, &m1, &m1_value);
          if (srslte_sss_synch_N_id_1(&sss, m0, m1) != N_id_1) {
            sss_error2++;            
          }
          INFO("Partial N_id_1: %d\n", srslte_sss_synch_N_id_1(&sss, m0, m1));
          srslte_sss_synch_m0m1_diff(&sss, &buffer[sss_idx], &m0, &m0_value, &m1, &m1_value);
          if (srslte_sss_synch_N_id_1(&sss, m0, m1) != N_id_1) {
            sss_error3++;            
          }
          INFO("Diff N_id_1: %d\n", srslte_sss_synch_N_id_1(&sss, m0, m1));
          srslte_sss_synch_m0m1_partial(&sss, &buffer[sss_idx], 1, NULL, &m0, &m0_value, &m1, &m1_value);
          if (srslte_sss_synch_N_id_1(&sss, m0, m1) != N_id_1) {
            sss_error1++;     
          }
          INFO("Full N_id_1: %d\n", srslte_sss_synch_N_id_1(&sss, m0, m1));
        }
        
        // Estimate CP 
        if (peak_idx > 2*(fft_size + SRSLTE_CP_LEN_EXT(fft_size))) {
          srslte_cp_t cp = srslte_sync_detect_cp(&ssync, buffer, peak_idx);
          if (SRSLTE_CP_ISNORM(cp)) {
            cp_is_norm++; 
          }          
        }
        
      } else {
        INFO("No space for CFO computation. Frame starts at \n",peak_idx);
      }
      
      if(srslte_sss_synch_subframe(m0,m1) == 0)
      {
#ifndef DISABLE_GRAPHICS
          if (!disable_plots)
            do_plots_sss(sss.corr_output_m0, sss.corr_output_m1);
#endif
      }
      
    } else {
      nof_nodet++;
    }

    if (frame_cnt > 100) {
      if (abs(last_peak-peak_idx) > 4) {
        if (peak_value >= threshold) {
          nof_nopeakdet++;
        } 
        nof_nopeak++;                  
      } 
    }
    
    frame_cnt++;
   
    printf("[%5d]: Pos: %5d, PSR: %4.1f (~%4.1f) Pdet: %4.2f, "
           "FA: %4.2f, CFO: %+4.1f KHz SSSmiss: %4.2f/%4.2f/%4.2f CPNorm: %.0f%%\r", 
           frame_cnt, 
           peak_idx, 
           peak_value, mean_peak,
           (float) nof_det/frame_cnt, 
           (float) nof_nopeakdet/frame_cnt, mean_cfo*15, 
           (float) sss_error1/nof_det,(float) sss_error2/nof_det,(float) sss_error3/nof_det,
           (float) cp_is_norm/nof_det * 100);
    
    if (SRSLTE_VERBOSE_ISINFO()) {
      printf("\n");
    }
  
#ifndef DISABLE_GRAPHICS
    if (!disable_plots)
      do_plots(pss.conv_output_avg, pss.conv_output_avg[peak_idx], pss.fft_size+pss.frame_size-1, ce);
#endif

    last_peak = peak_idx;

  }
  
  srslte_pss_synch_free(&pss);
  free(buffer);
  cuhd_close(uhd);

  printf("Ok\n");
  exit(0);
}
コード例 #3
0
ファイル: pdsch_ue.c プロジェクト: marojevic/libLTE
int main(int argc, char **argv) {
  int ret; 
  cf_t *sf_buffer; 
  iodev_t iodev; 
  prog_args_t prog_args; 
  lte_cell_t cell; 
  ue_dl_t ue_dl; 
  bool ue_dl_initiated = false; 
  int64_t sf_cnt;
  uint32_t sf_idx;
  pbch_mib_t mib; 
  bool printed_sib = false; 
  uint32_t rlen; 
  
  parse_args(&prog_args, argc, argv);
  
  if (iodev_init(&iodev, &prog_args.io_config)) {
    fprintf(stderr, "Error initiating input device\n");
    exit(-1);
  }
  
#ifndef DISABLE_GRAPHICS
  if (!prog_args.disable_plots) {
    init_plots();    
  }
#endif
  
  /* Setup SIGINT handler */
  printf("\n --- Press Ctrl+C to exit --- \n");
  signal(SIGINT, sigintHandler);

  /* Initialize frame and subframe counters */
  sf_cnt = 0;
  sf_idx = 0; 
  
  /* Main loop */
  while (!go_exit && (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1)) {

    ret = iodev_receive(&iodev, &sf_buffer);
    if (ret < 0) {
      fprintf(stderr, "Error reading from input device (%d)\n", ret);
      break;
    }
    
    /* iodev_receive returns 1 if successfully read 1 aligned subframe */
    if (ret == 1) {
      if (!ue_dl_initiated) {
        if (iodev_isUSRP(&iodev)) {
          cell = ue_sync_get_cell(&iodev.sframe);
          mib = ue_sync_get_mib(&iodev.sframe);
        } else {
          cell.id = prog_args.cell_id_file;
          cell.cp = CPNORM; 
          cell.nof_ports = 1; // TODO: Use prog_args 
          cell.nof_prb = prog_args.nof_prb_file; 
          mib.phich_resources = R_1; 
          mib.phich_length = PHICH_NORM;
        }        
        if (ue_dl_init(&ue_dl, cell, mib.phich_resources, mib.phich_length, 1234)) { 
          fprintf(stderr, "Error initiating UE downlink processing module\n");
          exit(-1);
        }
        pdsch_set_rnti(&ue_dl.pdsch, prog_args.rnti);
        ue_dl_initiated = true; 
      } else {
        if (iodev_isUSRP(&iodev)) {
          sf_idx = ue_sync_get_sfidx(&iodev.sframe);
        } 
        rlen = ue_dl_receive(&ue_dl, sf_buffer, data, sf_idx, ue_sync_get_mib(&iodev.sframe).sfn, prog_args.rnti);
        if (rlen < 0) {
          fprintf(stderr, "\nError running receiver\n");fflush(stdout);
          exit(-1);
        }
        if (prog_args.rnti == SIRNTI && !printed_sib && rlen > 0) {
          printf("\n\nDecoded SIB1 Message: ");
          vec_fprint_hex(stdout, data, rlen);
          printf("\n");fflush(stdout);
          printed_sib = true; 
        }
        if (!(sf_cnt % 10)) {         
          printf("Cell ID: %3d, RSSI: %+.2f dBm, CFO: %+.4f KHz, SFO: %+.4f Khz, TimeOffset: %4d, Errors: %4d/%4d, BLER: %.1e\r",
              cell.id, 20*log10f(agc_get_rssi(&iodev.sframe.agc)), iodev.sframe.cur_cfo * 15, iodev.sframe.mean_time_offset / 5, iodev.sframe.peak_idx,
              (int) ue_dl.pkt_errors, (int) ue_dl.pkts_total, (float) ue_dl.pkt_errors / ue_dl.pkts_total);
          fflush(stdout);       
          if (VERBOSE_ISINFO()) {
            printf("\n");
          }
        }  
        #ifndef DISABLE_GRAPHICS
        if (!prog_args.disable_plots && sf_idx == 5) {
          do_plots(&ue_dl, sf_idx);          
        }
        #endif
      }
      if (iodev_isfile(&iodev)) {
        sf_idx++;       
        if (sf_idx == NSUBFRAMES_X_FRAME) {
          sf_idx = 0;
        }        
      }
    }
    if (prog_args.nof_subframes > 0) {
      sf_cnt++;      
    }    
    if (iodev_isfile(&iodev)) {
      usleep(5000);
    }
  }

  if (ue_dl_initiated) {
    ue_dl_free(&ue_dl);    
  }
  iodev_free(&iodev);

  printf("\nBye\n");
  exit(0);
}
コード例 #4
0
   void draw_analysis_ratio_plots3( const char* infile = "outputfiles/cdtt_input.root", const char* save_file_base = "plot-dtt-analysis3" ) {

      gDirectory -> Delete( "h*" ) ;

      gStyle -> SetOptStat(0) ;

      loadHist( infile ) ;

      int wx(50), wy(50) ;


      char cname[100] ;
      char ctitle[100] ;

      TCanvas* can ;
      int ci ;

      char savefile[10000] ;




    //--- 3x3 Njet vs HT grid

      sprintf( cname, "can_draw_analysis_ratio_plots" ) ;
      sprintf( ctitle, "lost/found ratio vs W pT" ) ;
      can = new TCanvas( cname, ctitle, 900, 900 ) ;
      can -> Divide( 3, 3 ) ;

      can -> SetWindowPosition( wx, wy ) ; wx += 50 ; wy += 20 ;

      ci = 1 ;

      for ( int hti=1; hti<4; hti++ ) {
         for ( int nji=1; nji<4; nji++ ) {

            can -> cd( ci++ ) ;

            char hname[100] ;

            sprintf( hname, "h_wpt_lostfound_ratio_nj%d_ht%d", nji, hti ) ;
            TH1F* hp = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp == 0x0 ) { printf("\n\n *** Missing hist %s\n\n", hname ) ; return ; }
            hp -> SetMarkerStyle(20) ;
            hp -> SetMarkerSize(0.5) ;

            do_plots( hp ) ;

         } // wpti
      } // hti


      sprintf( savefile, "outputfiles/%s-lostfound-ratio.pdf", save_file_base ) ;
      can -> SaveAs( savefile ) ;





    //--- 3 Njet plots

      sprintf( cname, "can_draw_analysis_ratio_plots_njet" ) ;
      sprintf( ctitle, "lost/found ratio vs W pT, Njet bins" ) ;
      can = new TCanvas( cname, ctitle, 1300, 600 ) ;
      can -> Divide( 3, 1 ) ;

      can -> SetWindowPosition( wx, wy ) ; wx += 50 ; wy += 20 ;

      ci = 1 ;

      for ( int nji=1; nji<4; nji++ ) {

         can -> cd( ci++ ) ;

         for ( int hti=1; hti<4; hti++ ) {

            char hname[100] ;

            sprintf( hname, "h_wpt_lostfound_ratio_nj%d_ht%d", nji, hti ) ;
            TH1F* hp = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp == 0x0 ) { printf("\n\n *** Missing hist %s\n\n", hname ) ; return ; }

            if ( hti==1 ) {
               do_plots( hp ) ;
               hp -> SetMarkerStyle(20) ;
               hp -> SetMarkerSize(0.5) ;
               hp -> Draw("same") ;
            } else {
               if ( hti==2) { hp -> SetLineColor(2) ; hp -> SetMarkerColor(2) ; hp -> SetMarkerStyle(21) ; hp -> SetMarkerSize(0.5) ; }
               if ( hti==3) { hp -> SetLineColor(4) ; hp -> SetMarkerColor(4) ; hp -> SetMarkerStyle(22) ; hp -> SetMarkerSize(0.5) ; }
               hp->Draw("same") ;
            }


         } // hti
      } // nji


      sprintf( savefile, "outputfiles/%s-lostfound-ratio-njet-bins.pdf", save_file_base ) ;
      can -> SaveAs( savefile ) ;




    //--- 3 HT plots

      sprintf( cname, "can_draw_analysis_ratio_plots_ht" ) ;
      sprintf( ctitle, "lost/found ratio vs W pT, HT bins" ) ;
      can = new TCanvas( cname, ctitle, 1300, 600 ) ;
      can -> Divide( 3, 1 ) ;

      can -> SetWindowPosition( wx, wy ) ; wx += 50 ; wy += 20 ;

      ci = 1 ;

      for ( int hti=1; hti<4; hti++ ) {

         can -> cd( ci++ ) ;

         for ( int nji=1; nji<4; nji++ ) {

            char hname[100] ;

            sprintf( hname, "h_wpt_lostfound_ratio_nj%d_ht%d", nji, hti ) ;
            TH1F* hp = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hp == 0x0 ) { printf("\n\n *** Missing hist %s\n\n", hname ) ; return ; }

            if ( nji==1 ) {
               hp -> SetMarkerStyle(20) ;
               hp -> SetMarkerSize(0.5) ;
               hp -> SetMarkerColor(1) ;
               hp -> SetLineColor(1) ;
               do_plots( hp ) ;
               hp -> Draw("same") ;
            } else {
               if ( nji==2) { hp -> SetLineColor(2) ; hp -> SetMarkerColor(2) ; hp -> SetMarkerStyle(21) ; hp -> SetMarkerSize(0.5) ; }
               if ( nji==3) { hp -> SetLineColor(4) ; hp -> SetMarkerColor(4) ; hp -> SetMarkerStyle(22) ; hp -> SetMarkerSize(0.5) ; }
               hp->Draw("same") ;
            }


         } // nji
      } // hti


      sprintf( savefile, "outputfiles/%s-lostfound-ratio-ht-bins.pdf", save_file_base ) ;
      can -> SaveAs( savefile ) ;








   } // draw_analysis_ratio_plots3