Пример #1
0
void wfd_raw_fill_reset(const int run_nr = 0) 
{
  int i;
  char name[256];

  const int n_crates = WFD_NUMBER_OF_CRATES;
  
  TH2D *h2[n_crates];

  //=========================================================
  //             *** initialize style ***
  //=========================================================

  init();
  gStyle->SetOptStat(11);

  //=========================================================
  //                  *** open canvas ***
  //=========================================================
  
  TCanvas *c1 = new TCanvas("c1","c1",0,0,800,1000);
  c1->Draw();
  c1->cd();

  c1->Divide(2,3,0.001,0.001,10);

  //=========================================================
  //          *** receive and plot histograms ***
  //=========================================================
  
  for (i=0; i<n_crates; i++) {

    sprintf(name,"WFDrawFillHasResetBlock%s",wfd_crate_name[i]);
    h2[i] = (TH2D*) get_hist(name, run_nr);

    if ( !h2[i] ) continue;

    int ipad = i+1;   
    c1->cd(ipad);

    h2[i]->Draw("ColZ");
    c1->GetPad(ipad)->Update();
    h2[i]->SetXTitle("fill counter");
    h2[i]->SetYTitle("(slot-1)*4 + chan.");
    h2[i]->GetXaxis()->SetRangeUser(0.0,2000.0);

    TPaletteAxis *palette = (TPaletteAxis*)h2[i]->GetListOfFunctions()->FindObject("palette");
    if ( palette ) {
      palette->SetX2NDC( palette->GetX1NDC()+0.01 );
      palette->Draw();
    }

  }
  
  c1->SaveAs("../png/wfd_raw_fill_reset.png");


}
Пример #2
0
int		my_history()
{
  t_hist	*hist;
  char		*s;

  hist = get_hist(NULL);
  if (hist == NULL)
    return (1);
  while (hist->prev != NULL)
     hist = hist->prev;
  if (hist->next != NULL)
    hist = hist->next;
  else
    return (0);
  while (hist != NULL)
    {
      my_putstr((s = take_cmd(hist->edit, 0, 0)));
      free(s);
      my_putchar('\n');
      hist = hist->next;
    }
  return (1);
}
   void make_hadtau_input_files1( const char* input_root_file  = "non-qcd-inputs-topup2/ARElog60_12.9ifb_HadTauEstimation_data_formatted_New.root",
                                  const char* output_text_file = "outputfiles/combine-input-hadtau.txt",
                                  const char* nbsum_text_file  = "outputfiles/nbsum-input-hadtau.txt"
                               ) {

      setup_bins();

      gDirectory -> Delete( "h*" ) ;

      TFile* tf_input = new TFile( input_root_file, "read" ) ;
      if ( tf_input == 0x0 ) { printf("\n\n *** Bad input file: %s\n\n", input_root_file ) ; return ; }
      if ( !(tf_input -> IsOpen() ) ) { printf("\n\n *** Bad input file: %s\n\n", input_root_file ) ; return ; }

      printf("\n") ;
      tf_input -> ls() ;
      printf("\n") ;

      FILE* ofp_combine ;
      if ( (ofp_combine = fopen( output_text_file, "w" ))==NULL ) {
         printf( "\n\n *** Problem opening combine output file: %s\n\n", output_text_file ) ;
         return ;
      }

      FILE* ofp_nbsum ;
      if ( (ofp_nbsum = fopen( nbsum_text_file, "w" ))==NULL ) {
         printf( "\n\n *** Problem opening nbsum output file: %s\n\n", nbsum_text_file ) ;
         return ;
      }

      FILE* ofp_nbsum_stat_syst ;
      TString systfile_nbsum( nbsum_text_file ) ;
      systfile_nbsum.ReplaceAll("input","stat-syst") ;
      if ( (ofp_nbsum_stat_syst = fopen( systfile_nbsum.Data(), "w" ))==NULL ) {
         printf( "\n\n *** Problem opening nbsum stat-syst output file: %s\n\n", systfile_nbsum.Data() ) ;
         return ;
      }

      FILE* ofp_combine_stat_syst ;
      TString systfile_combine( output_text_file ) ;
      systfile_combine.ReplaceAll("input","stat-syst") ;
      if ( (ofp_combine_stat_syst = fopen( systfile_combine.Data(), "w" ))==NULL ) {
         printf( "\n\n *** Problem opening combine stat-syst output file: %s\n\n", systfile_combine.Data() ) ;
         return ;
      }


      ///////TH1F* h_ldp = (TH1F*) tf -> Get( "QCDBin_LowDphi_nominal_fullstatuncertainty" ) ;
      TH1* h_pred_lowdphi = get_hist( tf_input, "QCDBin_LowDphi_nominal_fullstatuncertainty" ) ;

      /////////TH1F* h_hdp = (TH1F*) tf -> Get( "QCDBin_HiDphi_nominal_fullstatuncertainty" ) ;
      TH1* h_pred_highdphi = get_hist( tf_input, "QCDBin_HiDphi_nominal_fullstatuncertainty" ) ;





      TH1* h_systerr_lowdphi[100] ;
      TH1* h_systerr_highdphi[100] ;
      char systerr_name[100][100] ;
      int n_systerr(0) ;

      {
         int si(0) ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_closureUncertainty" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_closureUncertainty" ) ;
         sprintf( systerr_name[si], "Closure" ) ;
         si++ ;

     //----------

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_BMistagUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_BMistagUp" ) ;
         sprintf( systerr_name[si], "Btag" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MuRecoSysUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MuRecoSysUp" ) ;
         sprintf( systerr_name[si], "MuRecoSys" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MuIsoSysUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MuIsoSysUp" ) ;
         sprintf( systerr_name[si], "MuIsoSys" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MuRecoIsoUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MuRecoIsoUp" ) ;
         sprintf( systerr_name[si], "MuRecoIso" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_JECSysUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_JECSysUp" ) ;
         sprintf( systerr_name[si], "JEC" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MTSysUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MTSysUp" ) ;
         sprintf( systerr_name[si], "MT" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MtEffStat" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MtEffStat" ) ;
         sprintf( systerr_name[si], "MtEffStat" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_IsoTrkVetoEffUncertaintySys" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_IsoTrkVetoEffUncertaintySys" ) ;
         sprintf( systerr_name[si], "IsoTrkVetoSys" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_AccStat" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_AccStat" ) ;
         sprintf( systerr_name[si], "AccStat" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_AccSysPDFUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_AccSysPDFUp" ) ;
         sprintf( systerr_name[si], "AccSysPDF" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_AccSysScaleUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_AccSysScaleUp" ) ;
         sprintf( systerr_name[si], "AccSysScale" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MuFromTauStat" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MuFromTauStat" ) ;
         sprintf( systerr_name[si], "MuFromTauStat" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_DileptonUncertainty" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_DileptonUncertainty" ) ;
         sprintf( systerr_name[si], "Dilepton" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_TrigEffUncertainty" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_TrigEffUncertainty" ) ;
         sprintf( systerr_name[si], "TrigEff" ) ;
         si++ ;

         n_systerr = si ;
      }




      int bi_hist(0) ;
      int bi_control(0) ;
      int bi_search(0) ;
      for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {
         for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {
            for ( int bi_htmht=1; bi_htmht<=nb_htmht; bi_htmht++ ) {

               if ( bin_edges_nj[bi_nj-1] < 2.5 ) continue;// because lost lepton input file lacks NJets = 2 bin
               bi_hist ++ ;

               double ldp_val = h_pred_lowdphi -> GetBinContent( bi_hist ) ;
               double ldp_hist_err = h_pred_lowdphi -> GetBinError( bi_hist ) ;
               double ldp_err = 1. ;
               if ( ldp_val > 0 ) ldp_err = ldp_hist_err ;

               double hdp_val = h_pred_highdphi -> GetBinContent( bi_hist ) ;
               double hdp_hist_err = h_pred_highdphi -> GetBinError( bi_hist ) ;
               double hdp_err = 1. ;
               if ( hdp_val > 0 ) hdp_err = hdp_hist_err ;


               double total_syst2_lowdphi_events(0.) ;
               double total_syst2_highdphi_events(0.) ;
               for ( int si=0; si<n_systerr; si++ ) {
                  double syst_lowdphi = fabs( h_systerr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ) ;
                  double syst_highdphi = fabs( h_systerr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ) ;
                  if ( syst_lowdphi > 0 && syst_highdphi > 0 ) {
                     total_syst2_lowdphi_events  += pow( syst_lowdphi  * ldp_val, 2. ) ;
                     total_syst2_highdphi_events += pow( syst_highdphi * hdp_val, 2. ) ;
                  }
               } // si

               double ldp_syst = sqrt( total_syst2_lowdphi_events ) ;
               double hdp_syst = sqrt( total_syst2_highdphi_events ) ;

               TString hist_bin_label( h_pred_lowdphi -> GetXaxis() -> GetBinLabel( bi_hist ) ) ;

               int bi_ht = 0, bi_mht = 0;

               if ( bi_htmht == 1 ) { bi_ht = 1; bi_mht = 1; }
               if ( bi_htmht == 2 ) { bi_ht = 2; bi_mht = 1; }
               if ( bi_htmht == 3 ) { bi_ht = 3; bi_mht = 1; }

               if ( bi_htmht == 4 ) { bi_ht = 1; bi_mht = 2; }
               if ( bi_htmht == 5 ) { bi_ht = 2; bi_mht = 2; }
               if ( bi_htmht == 6 ) { bi_ht = 3; bi_mht = 2; }

               if ( bi_htmht == 7 ) { bi_ht = 1; bi_mht = 3; }
               if ( bi_htmht == 8 ) { bi_ht = 2; bi_mht = 3; }
               if ( bi_htmht == 9 ) { bi_ht = 3; bi_mht = 3; }

               if ( bi_htmht ==10 ) { bi_ht = 2; bi_mht = 4; }
               if ( bi_htmht ==11 ) { bi_ht = 3; bi_mht = 4; }

               if ( bi_htmht ==12 ) { bi_ht = 2; bi_mht = 5; }
               if ( bi_htmht ==13 ) { bi_ht = 3; bi_mht = 5; }

               if ( bi_mht == 1 ) {
                  bi_control ++ ;
               } else {
                  bi_search ++ ;
               }

               char mhtchar[10] ;
               if ( bi_mht == 1 ) {
                  sprintf( mhtchar, "C" ) ;
               } else {
                  sprintf( mhtchar, "%d", bi_mht-1 ) ;
               }

               char label[1000] ;
               sprintf( label, " %3d  %s %3d  Nj%d-Nb%d-MHT%s-HT%d",
                   bi_hist, (bi_mht==1)?"C":"S", (bi_mht==1)?bi_control:bi_search,
                   bi_nj, bi_nb-1, mhtchar, bi_ht ) ;

               //// printf("  label : %s   ,  hist label %s\n", label, hist_bin_label.Data() ) ;

               double ldp_stat_over_sqrtn(0.8), ldp_syst_over_n(0.15) ;
               if ( ldp_val > 0 ) {
                  ldp_stat_over_sqrtn = ldp_err / sqrt( ldp_val ) ;
                  ldp_syst_over_n = ldp_syst / ldp_val ;
                  if ( ldp_stat_over_sqrtn > 1.5 ) ldp_stat_over_sqrtn = 1.0 ;
               }
               double hdp_stat_over_sqrtn(0.8), hdp_syst_over_n(0.15) ;
               if ( hdp_val > 0 ) {
                  hdp_stat_over_sqrtn = hdp_err / sqrt( hdp_val ) ;
                  hdp_syst_over_n = hdp_syst / hdp_val ;
                  if ( hdp_stat_over_sqrtn > 1.5 ) hdp_stat_over_sqrtn = 1.0 ;
               }

               printf(               "%s      %8.1f +/- %5.1f +/- %5.1f          %8.1f +/- %5.1f +/- %5.1f\n",
                   label,
                   ldp_val, ldp_err, ldp_syst,
                   hdp_val, hdp_err, hdp_syst ) ;

               fprintf( ofp_combine, "%s      %8.1f +/- %5.1f +/- %5.1f         %8.1f +/- %5.1f +/- %5.1f\n",
                   label,    ldp_val, ldp_err, ldp_syst,   hdp_val, hdp_err, hdp_syst ) ;

               if ( bi_htmht > 3 ) {
                  char this_label[100] ;
                  sprintf( this_label, "%3d S-Nj%d-Nb%d-MHT%d-HT%d (S%d)", bi_search, bi_nj, bi_nb-1, bi_mht-1, bi_ht, bi_htmht-3 ) ;
                  fprintf( ofp_combine_stat_syst, "   %-30s   %6.3f  %6.3f       %6.3f  %6.3f\n",
                      this_label,
                      ldp_stat_over_sqrtn, ldp_syst_over_n,   hdp_stat_over_sqrtn, hdp_syst_over_n ) ;
               } else {
                  char this_label[100] ;
                  sprintf( this_label, "%3d C-Nj%d-Nb%d-MHT%d-HT%d (C%d)", bi_control, bi_nj, bi_nb-1, bi_mht-1, bi_ht, bi_htmht ) ;
                  fprintf( ofp_combine_stat_syst, "   %-30s   %6.3f  %6.3f       %6.3f  %6.3f\n",
                      this_label,
                      ldp_stat_over_sqrtn, ldp_syst_over_n,   hdp_stat_over_sqrtn, hdp_syst_over_n ) ;
               }

            } // bi_htmht
         } // bi_nb
      } // bi_nj

      fclose( ofp_combine ) ;
      printf("\n\n Wrote %s\n\n", output_text_file ) ;

     //-----

      for ( int bi_ht=1; bi_ht<=nBinsHT; bi_ht++ ) {
         for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {

            if ( bin_edges_nj[bi_nj-1] < 2.5 ) continue; // because znuznu input file lacks NJets = 2 bin

            float ldp_nbsum_val(0.) ;
            float hdp_nbsum_val(0.) ;

            float ldp_nbsum_stat_err2(0.) ;
            float hdp_nbsum_stat_err2(0.) ;

            double total_syst_lowdphi_events[100] ;
            double total_syst_highdphi_events[100] ;
            for ( int si=0; si<n_systerr; si++ ) {
               total_syst_lowdphi_events[si]  = 0 ;
               total_syst_highdphi_events[si] = 0 ;
            }

            for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {

               bi_hist = (bi_nj-1)*(nb_nb)*(nb_htmht) + (bi_nb-1)*(nb_htmht) + bi_ht ;

               double ldp_val = h_pred_lowdphi -> GetBinContent( bi_hist ) ;
               double ldp_hist_err = h_pred_lowdphi -> GetBinError( bi_hist ) ;
               double ldp_err = 1. ;
               if ( ldp_val > 0 ) ldp_err = ldp_hist_err ;

               double hdp_val = h_pred_highdphi -> GetBinContent( bi_hist ) ;
               double hdp_hist_err = h_pred_highdphi -> GetBinError( bi_hist ) ;
               double hdp_err = 1. ;
               if ( hdp_val > 0 ) hdp_err = hdp_hist_err ;


               //////////////double ldp_syst = 0.10 * ldp_val ; //*** flat 10% syst for now.
               //////////////double hdp_syst = 0.10 * hdp_val ; //*** flat 10% syst for now.

               for ( int si=0; si<n_systerr; si++ ) {
                  double syst_lowdphi = fabs( h_systerr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ) ;
                  double syst_highdphi = fabs( h_systerr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ) ;
                  if ( syst_lowdphi > 0 && syst_highdphi > 0 ) {
                     total_syst_lowdphi_events[si]  += syst_lowdphi  * ldp_val ;
                     total_syst_highdphi_events[si] += syst_highdphi * hdp_val ;
                  }
               } // si

               ldp_nbsum_val += ldp_val ;
               hdp_nbsum_val += hdp_val ;

               ldp_nbsum_stat_err2 += pow( ldp_err, 2. ) ;
               hdp_nbsum_stat_err2 += pow( hdp_err, 2. ) ;

               TString hist_bin_label( h_pred_lowdphi -> GetXaxis() -> GetBinLabel( bi_hist ) ) ;

               char label[1000] ;
               sprintf( label, " %3d  Nj%d-Nb%d-MHTC-HT%d", bi_hist, bi_nj, bi_nb-1, bi_ht ) ;

            } // bi_nb

            ///printf("    Systematics:\n") ;
            double total_syst_err2_lowdphi(0.) ;
            double total_syst_err2_highdphi(0.) ;
            for ( int si=0; si<n_systerr; si++ ) {
               total_syst_err2_lowdphi += pow( total_syst_lowdphi_events[si], 2.)   ;
               total_syst_err2_highdphi += pow( total_syst_highdphi_events[si], 2.)  ;
               ///printf("  %2d : %25s :   %7.1f  %7.1f\n", si, systerr_name[si], total_syst_lowdphi_events[si], total_syst_highdphi_events[si] ) ;
            }
            double total_syst_err_lowdphi = sqrt( total_syst_err2_lowdphi ) ;
            double total_syst_err_highdphi = sqrt( total_syst_err2_highdphi ) ;


            float ldp_nbsum_stat_err = sqrt( ldp_nbsum_stat_err2 ) ;
            float hdp_nbsum_stat_err = sqrt( hdp_nbsum_stat_err2 ) ;

            double ldp_syst_over_n(0.) ;
            double ldp_stat_over_sqrtn(0.) ;
            if ( ldp_nbsum_val > 0 ) ldp_syst_over_n = total_syst_err_lowdphi / ldp_nbsum_val  ;
            if ( ldp_nbsum_val > 0 ) ldp_stat_over_sqrtn = ldp_nbsum_stat_err / sqrt(ldp_nbsum_val)  ;

            double hdp_syst_over_n(0.) ;
            double hdp_stat_over_sqrtn(0.) ;
            if ( hdp_nbsum_val > 0 ) hdp_syst_over_n = total_syst_err_highdphi / hdp_nbsum_val  ;
            if ( hdp_nbsum_val > 0 ) hdp_stat_over_sqrtn = hdp_nbsum_stat_err / sqrt(hdp_nbsum_val)  ;

            printf(          "   Nj%d-HT%d      %8.1f +/- %5.1f +/- %5.1f  (%6.3f)        %8.1f +/- %5.1f +/- %5.1f   (%6.3f)\n",
                bi_nj, bi_ht,
                ldp_nbsum_val, ldp_nbsum_stat_err, total_syst_err_lowdphi,    ldp_syst_over_n,
                hdp_nbsum_val, hdp_nbsum_stat_err, total_syst_err_highdphi,   hdp_syst_over_n ) ;

            fprintf( ofp_nbsum, "   Nj%d-HT%d   %8.1f +/- %5.1f +/- %5.1f    %8.1f +/- %5.1f +/- %5.1f\n", bi_nj, bi_ht,
                  ldp_nbsum_val, ldp_nbsum_stat_err, total_syst_err_lowdphi,
                  hdp_nbsum_val, hdp_nbsum_stat_err, total_syst_err_highdphi   ) ;
            fprintf( ofp_nbsum_stat_syst, "   Nj%d-HT%d    %6.3f  %6.3f       %6.3f  %6.3f\n", bi_nj, bi_ht, 
                  ldp_stat_over_sqrtn, ldp_syst_over_n,    hdp_stat_over_sqrtn, hdp_syst_over_n ) ;

         } // bi_nj
      } // bi_ht

      fclose( ofp_nbsum ) ;
      fclose( ofp_nbsum_stat_syst ) ;
      printf("\n\n Wrote %s\n\n", nbsum_text_file ) ;
      printf("\n\n Wrote %s\n\n", systfile_nbsum.Data() ) ;
      printf("\n\n Wrote %s\n\n", systfile_combine.Data() ) ;



   } // make_hadtau_input_files1
Пример #4
0
void draw_closure_sums4( const char* plotname = "njet", const char* infile = "outputfiles/closure-sums4.root" ) {

      char hname[100] ;

      gStyle -> SetOptStat(0) ;
      gStyle -> SetPadLeftMargin(0.13) ;

      gDirectory -> Delete( "h*" ) ;

      loadHist( infile ) ;

      gDirectory -> ls() ;

      sprintf( hname, "h_closure_%s_model_fit", plotname ) ;
      TH1F* h_model_fit = get_hist( hname ) ;
      TString tsn( hname ) ;
      tsn.ReplaceAll( "fit", "zero_err" ) ;
      TH1F* h_model_zero_err = (TH1F*) h_model_fit -> Clone( tsn.Data() ) ;
      for ( int bi=1; bi<= h_model_zero_err->GetNbinsX(); bi++ ) {
         h_model_zero_err -> SetBinError( bi, 0.0000001 ) ;
      }

      sprintf( hname, "h_closure_%s_model_fit_and_syst", plotname ) ;
      TH1F* h_model_fit_and_syst = get_hist( hname ) ;

      sprintf( hname, "h_closure_%s_model_total", plotname ) ;
      TH1F* h_model_total = get_hist( hname ) ;

      sprintf( hname, "h_closure_%s_qcdmc", plotname ) ;
      TH1F* h_model_qcdmc = get_hist( hname ) ;

      h_model_qcdmc -> SetMarkerStyle(20) ;
      h_model_qcdmc -> SetMarkerSize(1.5) ;
      h_model_qcdmc -> SetLineWidth(2) ;

      TCanvas* can = (TCanvas*) gDirectory -> FindObject( "can_dcs" ) ;
      if ( can == 0x0 ) {
         can = new TCanvas( "can_dcs", "", 700, 800 ) ;
      }
      can -> Clear() ;
      if ( strcmp( plotname, "10boxes" ) == 0 ) {
         gPad -> SetBottomMargin( 0.20 ) ;
         h_model_total -> GetXaxis() -> LabelsOption("v") ;
      } else {
         gPad -> SetBottomMargin( 0.10 ) ;
      }

      TLegend* legend(0x0) ;
      if ( strcmp( plotname, "ht" ) == 0 ) {
         legend = new TLegend( 0.60, 0.15, 0.98, 0.40 ) ;
      } else {
         legend = new TLegend( 0.60, 0.70, 0.98, 0.95 ) ;
      }
      legend -> AddEntry( h_model_fit, "Model, Fit" ) ;
      legend -> AddEntry( h_model_fit_and_syst, "Model, Fit + MHT" ) ;
      legend -> AddEntry( h_model_total, "Model, Fit + MHT + MC" ) ;
      legend -> AddEntry( h_model_qcdmc, "QCD Monte Carlo" ) ;


      h_model_fit -> SetFillColor( kRed-7 ) ;
      h_model_fit_and_syst -> SetFillColor( kRed-9 ) ;
      h_model_total -> SetFillColor( kRed-10 ) ;
      h_model_zero_err -> SetLineColor( 4 ) ;

      h_model_total -> SetYTitle( "QCD BG events" ) ;
      h_model_total -> SetTitleSize( 0.05, "y" ) ;
      if ( strcmp( plotname, "njet" ) == 0 ) { h_model_total -> SetTitle( "Njet bins" ) ; }
      if ( strcmp( plotname, "nb" ) == 0 ) { h_model_total -> SetTitle( "Nb bins" ) ; }
      if ( strcmp( plotname, "mht" ) == 0 ) { h_model_total -> SetTitle( "MHT bins" ) ; }
      if ( strcmp( plotname, "ht" ) == 0 ) { h_model_total -> SetTitle( "HT bins" ) ; }
      if ( strcmp( plotname, "10boxes" ) == 0 ) { h_model_total -> SetTitle( "MHT-HT bins" ) ; }

      h_model_total -> Draw( "e2" ) ;
      h_model_fit_and_syst -> Draw( "e2 same" ) ;
      h_model_fit -> Draw("e2 same" ) ;
      h_model_zero_err -> Draw( "same" ) ;
      gPad -> SetGridy(1) ;

      h_model_qcdmc -> Draw( "same" ) ;
      h_model_total -> Draw( "axig same" ) ;
      h_model_total -> Draw( "axis same" ) ;

      legend -> Draw() ;

      char fname[1000] ;
      sprintf( fname, "outputfiles/closure-sum-%s.pdf", plotname ) ;
      can -> SaveAs( fname ) ;

} // draw_closure_sums4
   void make_hadtau_lh_input_files1( const char* input_root_file  = "../non-qcd-inputs-fall16c/ARElog98_36.35ifb_HadTauEstimation_data_formatted_V11.root",
                                  const char* output_text_file = "outputfiles/combine-input-hadtau.txt",
                                  const char* nbsum_ldp_text_file  = "outputfiles/nbsum-ldp-input-hadtau.txt",
                                  const char* nbsum_hdp_text_file  = "outputfiles/nbsum-hdp-input-hadtau.txt"
                               ) {

      setup_bins();

      gSystem -> Exec( "mkdir -p outputfiles" ) ;

      gDirectory -> Delete( "h*" ) ;

      TFile* tf_input = new TFile( input_root_file, "read" ) ;
      if ( tf_input == 0x0 ) { printf("\n\n *** Bad input file: %s\n\n", input_root_file ) ; return ; }
      if ( !(tf_input -> IsOpen() ) ) { printf("\n\n *** Bad input file: %s\n\n", input_root_file ) ; return ; }

      printf("\n") ;
      tf_input -> ls() ;
      printf("\n") ;

      FILE* ofp_combine ;
      if ( (ofp_combine = fopen( output_text_file, "w" ))==NULL ) {
         printf( "\n\n *** Problem opening combine output file: %s\n\n", output_text_file ) ;
         return ;
      }

      FILE* ofp_ldp_nbsum ;
      if ( (ofp_ldp_nbsum = fopen( nbsum_ldp_text_file, "w" ))==NULL ) {
         printf( "\n\n *** Problem opening LDP nbsum output file: %s\n\n", nbsum_ldp_text_file ) ;
         return ;
      }

      FILE* ofp_hdp_nbsum ;
      if ( (ofp_hdp_nbsum = fopen( nbsum_hdp_text_file, "w" ))==NULL ) {
         printf( "\n\n *** Problem opening HDP nbsum output file: %s\n\n", nbsum_hdp_text_file ) ;
         return ;
      }



      TH1* h_pred_lowdphi = get_hist( tf_input, "QCDBin_LowDphi_nominal" ) ;

      TH1* h_pred_highdphi = get_hist( tf_input, "QCDBin_HiDphi_nominal" ) ;




      TH1* h_systerr_lowdphi[100] ;
      TH1* h_systerr_highdphi[100] ;
      char systerr_name[100][100] ;
      int n_systerr(0) ;

      {
         int si(0) ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_closureUncertainty" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_closureUncertainty" ) ;
         sprintf( systerr_name[si], "Closure" ) ;
         si++ ;

     //----------

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_BMistagUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_BMistagUp" ) ;
         sprintf( systerr_name[si], "Btag" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MuRecoSysUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MuRecoSysUp" ) ;
         sprintf( systerr_name[si], "MuRecoSys" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MuIsoSysUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MuIsoSysUp" ) ;
         sprintf( systerr_name[si], "MuIsoSys" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MuRecoIsoUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MuRecoIsoUp" ) ;
         sprintf( systerr_name[si], "MuRecoIso" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_JECSysUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_JECSysUp" ) ;
         sprintf( systerr_name[si], "JEC" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MTSysUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MTSysUp" ) ;
         sprintf( systerr_name[si], "MT" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MtEffStat" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MtEffStat" ) ;
         sprintf( systerr_name[si], "MtEffStat" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_IsoTrkVetoEffUncertaintySys" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_IsoTrkVetoEffUncertaintySys" ) ;
         sprintf( systerr_name[si], "IsoTrkVetoSys" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_AccStat" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_AccStat" ) ;
         sprintf( systerr_name[si], "AccStat" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_AccSysPDFUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_AccSysPDFUp" ) ;
         sprintf( systerr_name[si], "AccSysPDF" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_AccSysScaleUp" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_AccSysScaleUp" ) ;
         sprintf( systerr_name[si], "AccSysScale" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_MuFromTauStat" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_MuFromTauStat" ) ;
         sprintf( systerr_name[si], "MuFromTauStat" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_DileptonUncertainty" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_DileptonUncertainty" ) ;
         sprintf( systerr_name[si], "Dilepton" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_input, "QCDBin_LowDphi_TrigEffUncertainty" ) ;
         h_systerr_highdphi[si] = get_hist( tf_input, "QCDBin_HiDphi_TrigEffUncertainty" ) ;
         sprintf( systerr_name[si], "TrigEff" ) ;
         si++ ;

         n_systerr = si ;
      }




      int bi_hist(0) ;
      int bi_control(0) ;
      int bi_search(0) ;
      for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {
         for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {
            for ( int bi_htmht=1; bi_htmht<=nb_htmht; bi_htmht++ ) {

               int bi_hist = hadtau_global_bin_with_mhtc( bi_nj, bi_nb, bi_htmht ) ;
               if ( bi_hist > 0 ) {
                  int hbl_nj, hbl_nb, hbl_mht, hbl_htmht ;
                  sscanf( h_pred_lowdphi->GetXaxis()->GetBinLabel( bi_hist ), "NJets%d_BTags%d_MHT%d_HT%d", &hbl_nj, &hbl_nb, &hbl_mht, &hbl_htmht ) ;
                  if ( bi_nj != (hbl_nj+1) ) { printf("\n\n*** Inconsistent Njets.  %d != %d\n", bi_nj, hbl_nj+1) ; gSystem -> Exit(-1) ; }
                  if ( bi_nb != (hbl_nb+1) ) { printf("\n\n*** Inconsistent Nb. %d != %d\n", bi_nb, hbl_nb+1 ) ; gSystem -> Exit(-1) ; }
               }

               double ldp_val(0.) ;
               double ldp_hist_err(0.) ;
               if ( bi_hist > 0 ) {
                  ldp_val = h_pred_lowdphi -> GetBinContent( bi_hist ) ;
                  ldp_hist_err = h_pred_lowdphi -> GetBinError( bi_hist ) ;
               }
               double ldp_err = 1. ;
               if ( ldp_val > 0 ) ldp_err = ldp_hist_err ;

               double hdp_val(0.) ;
               double hdp_hist_err(0.) ;
               if ( bi_hist > 0 ) {
                  hdp_val = h_pred_highdphi -> GetBinContent( bi_hist ) ;
                  hdp_hist_err = h_pred_highdphi -> GetBinError( bi_hist ) ;
               }
               double hdp_err = 1. ;
               if ( hdp_val > 0 ) hdp_err = hdp_hist_err ;


               double total_syst2_lowdphi_events(0.) ;
               double total_syst2_highdphi_events(0.) ;
               for ( int si=0; si<n_systerr; si++ ) {
                  double syst_lowdphi(0.) ;
                  double syst_highdphi(0.) ;
                  if ( bi_hist > 0 ) {
                     syst_lowdphi = fabs( h_systerr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ) ;
                     syst_highdphi = fabs( h_systerr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ) ;
                  }
                  if ( syst_lowdphi > 0 && syst_highdphi > 0 ) {
                     total_syst2_lowdphi_events  += pow( syst_lowdphi  * ldp_val, 2. ) ;
                     total_syst2_highdphi_events += pow( syst_highdphi * hdp_val, 2. ) ;
                  }
               } // si

               double ldp_syst = sqrt( total_syst2_lowdphi_events ) ;
               double hdp_syst = sqrt( total_syst2_highdphi_events ) ;

               TString hist_bin_label ;
               if ( bi_hist > 0 ) { hist_bin_label = h_pred_lowdphi -> GetXaxis() -> GetBinLabel( bi_hist ) ; }

               int bi_ht = 0, bi_mht = 0;

               if ( bi_htmht == 1 ) { bi_ht = 1; bi_mht = 1; }
               if ( bi_htmht == 2 ) { bi_ht = 2; bi_mht = 1; }
               if ( bi_htmht == 3 ) { bi_ht = 3; bi_mht = 1; }

               if ( bi_htmht == 4 ) { bi_ht = 1; bi_mht = 2; }
               if ( bi_htmht == 5 ) { bi_ht = 2; bi_mht = 2; }
               if ( bi_htmht == 6 ) { bi_ht = 3; bi_mht = 2; }

               if ( bi_htmht == 7 ) { bi_ht = 1; bi_mht = 3; }
               if ( bi_htmht == 8 ) { bi_ht = 2; bi_mht = 3; }
               if ( bi_htmht == 9 ) { bi_ht = 3; bi_mht = 3; }

               if ( bi_htmht ==10 ) { bi_ht = 2; bi_mht = 4; }
               if ( bi_htmht ==11 ) { bi_ht = 3; bi_mht = 4; }

               if ( bi_htmht ==12 ) { bi_ht = 2; bi_mht = 5; }
               if ( bi_htmht ==13 ) { bi_ht = 3; bi_mht = 5; }

               if ( bi_mht == 1 ) {
                  bi_control ++ ;
               } else {
                  bi_search ++ ;
               }

               char mhtchar[10] ;
               if ( bi_mht == 1 ) {
                  sprintf( mhtchar, "C" ) ;
               } else {
                  sprintf( mhtchar, "%d", bi_mht-1 ) ;
               }

               char label[1000] ;
               sprintf( label, " %3d  %s %3d  Nj%d-Nb%d-MHT%s-HT%d",
                   bi_hist, (bi_mht==1)?"C":"S", (bi_mht==1)?bi_control:bi_search,
                   bi_nj, bi_nb-1, mhtchar, bi_ht ) ;

               //// printf("  label : %s   ,  hist label %s\n", label, hist_bin_label.Data() ) ;
               if ( TMath::IsNaN( ldp_val ) ) ldp_val = 0. ;
               if ( TMath::IsNaN( ldp_err ) ) ldp_err = 0. ;
               if ( TMath::IsNaN( ldp_syst ) ) ldp_syst = 0. ;
               if ( TMath::IsNaN( hdp_val ) ) hdp_val = 0. ;
               if ( TMath::IsNaN( hdp_err ) ) hdp_err = 0. ;
               if ( TMath::IsNaN( hdp_syst ) ) hdp_syst = 0. ;


               printf(               "%s      %8.1f +/- %5.1f +/- %5.1f          %8.1f +/- %5.1f +/- %5.1f\n",
                   label,
                   ldp_val, ldp_err, ldp_syst,
                   hdp_val, hdp_err, hdp_syst ) ;

               fprintf( ofp_combine, "%s      %8.1f +/- %5.1f +/- %5.1f         %8.1f +/- %5.1f +/- %5.1f\n",
                   label,    ldp_val, ldp_err, ldp_syst,   hdp_val, hdp_err, hdp_syst ) ;


            } // bi_htmht
         } // bi_nb
      } // bi_nj

      fclose( ofp_combine ) ;
      printf("\n\n Wrote %s\n\n", output_text_file ) ;










     //-----

      fprintf( ofp_ldp_nbsum, "  hadtau ldp nsyst=%d\n", n_systerr ) ;
      fprintf( ofp_hdp_nbsum, "  hadtau hdp nsyst=%d\n", n_systerr ) ;

      fprintf( ofp_ldp_nbsum, "  bin label    value   stat  " ) ;
      fprintf( ofp_hdp_nbsum, "  bin label    value   stat  " ) ;
      fprintf( ofp_ldp_nbsum, " %15s ", "total-syst" ) ;
      fprintf( ofp_hdp_nbsum, " %15s ", "total-syst" ) ;
      for ( int si=0; si<n_systerr; si++ ) {
         fprintf( ofp_ldp_nbsum, " %15s ", systerr_name[si] ) ;
         fprintf( ofp_hdp_nbsum, " %15s ", systerr_name[si] ) ;
      } // si
      fprintf( ofp_ldp_nbsum, "\n") ;
      fprintf( ofp_hdp_nbsum, "\n") ;

      for ( int bi_ht=1; bi_ht<=nBinsHT; bi_ht++ ) {
         for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {

            if ( bi_ht==1 && bi_nj>3 ) continue ;

            float ldp_nbsum_val(0.) ;
            float hdp_nbsum_val(0.) ;

            float ldp_nbsum_stat_err2(0.) ;
            float hdp_nbsum_stat_err2(0.) ;

            double total_syst_lowdphi_events[100] ;
            double total_syst_highdphi_events[100] ;
            for ( int si=0; si<n_systerr; si++ ) {
               total_syst_lowdphi_events[si]  = 0 ;
               total_syst_highdphi_events[si] = 0 ;
            }

            for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {

               bi_hist = hadtau_global_bin_with_mhtc( bi_nj, bi_nb, bi_ht ) ;

               if ( bi_hist > 0 ) {
                  int hbl_nj, hbl_nb, hbl_mht, hbl_htmht ;
                  sscanf( h_pred_lowdphi->GetXaxis()->GetBinLabel( bi_hist ), "NJets%d_BTags%d_MHT%d_HT%d", &hbl_nj, &hbl_nb, &hbl_mht, &hbl_htmht ) ;
                  if ( bi_nj != (hbl_nj+1) ) { printf("\n\n*** Inconsistent Njets.  %d != %d\n", bi_nj, hbl_nj+1) ; gSystem -> Exit(-1) ; }
                  if ( bi_nb != (hbl_nb+1) ) { printf("\n\n*** Inconsistent Nb. %d != %d\n", bi_nb, hbl_nb+1 ) ; gSystem -> Exit(-1) ; }
               }

               double ldp_val(0.) ;
               double ldp_hist_err(0.) ;
               if ( bi_hist > 0 ) {
                  ldp_val = h_pred_lowdphi -> GetBinContent( bi_hist ) ;
                  ldp_hist_err = h_pred_lowdphi -> GetBinError( bi_hist ) ;
               }
               if ( TMath::IsNaN( ldp_val ) ) ldp_val = 0. ;
               if ( TMath::IsNaN( ldp_hist_err ) ) ldp_hist_err = 0. ;
               double ldp_err = 1. ;
               if ( ldp_val > 0 ) ldp_err = ldp_hist_err ;

               double hdp_val(0.) ;
               double hdp_hist_err (0.) ;
               if ( bi_hist > 0 ) {
                  hdp_val = h_pred_highdphi -> GetBinContent( bi_hist ) ;
                  hdp_hist_err = h_pred_highdphi -> GetBinError( bi_hist ) ;
               }
               if ( TMath::IsNaN( hdp_val ) ) hdp_val = 0. ;
               if ( TMath::IsNaN( hdp_hist_err ) ) hdp_hist_err = 0. ;
               double hdp_err = 1. ;
               if ( hdp_val > 0 ) hdp_err = hdp_hist_err ;


               for ( int si=0; si<n_systerr; si++ ) {
                  double syst_lowdphi(0.) ;
                  double syst_highdphi(0.) ;
                  if ( bi_hist > 0 ) {
                     syst_lowdphi = fabs( h_systerr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ) ;
                     syst_highdphi = fabs( h_systerr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ) ;
                  }
                  if ( syst_lowdphi > 0 && syst_highdphi > 0 ) {
                     total_syst_lowdphi_events[si]  += syst_lowdphi  * ldp_val ;
                     total_syst_highdphi_events[si] += syst_highdphi * hdp_val ;
                  }
               } // si

               ldp_nbsum_val += ldp_val ;
               hdp_nbsum_val += hdp_val ;

               ldp_nbsum_stat_err2 += pow( ldp_err, 2. ) ;
               hdp_nbsum_stat_err2 += pow( hdp_err, 2. ) ;

               TString hist_bin_label ;
               if ( bi_hist > 0 ) { hist_bin_label = h_pred_lowdphi -> GetXaxis() -> GetBinLabel( bi_hist ) ; }

               char label[1000] ;
               sprintf( label, " %3d  Nj%d-Nb%d-MHTC-HT%d", bi_hist, bi_nj, bi_nb-1, bi_ht ) ;

            } // bi_nb

            float ldp_nbsum_stat_err = sqrt( ldp_nbsum_stat_err2 ) ;
            float hdp_nbsum_stat_err = sqrt( hdp_nbsum_stat_err2 ) ;

            fprintf( ofp_ldp_nbsum, "   Nj%d-HT%d   %8.1f   %5.1f ", bi_nj, bi_ht, ldp_nbsum_val, ldp_nbsum_stat_err ) ;
            fprintf( ofp_hdp_nbsum, "   Nj%d-HT%d   %8.1f   %5.1f ", bi_nj, bi_ht, hdp_nbsum_val, hdp_nbsum_stat_err ) ;

            double total_syst_err2_lowdphi(0.) ;
            double total_syst_err2_highdphi(0.) ;
            for ( int si=0; si<n_systerr; si++ ) {
               total_syst_err2_lowdphi += pow( total_syst_lowdphi_events[si], 2.)   ;
               total_syst_err2_highdphi += pow( total_syst_highdphi_events[si], 2.)  ;
            }
            double total_syst_err_lowdphi = sqrt( total_syst_err2_lowdphi ) ;
            double total_syst_err_highdphi = sqrt( total_syst_err2_highdphi ) ;


            double rel_ldp_total_err(0.) ;
            if ( ldp_nbsum_val > 0 ) rel_ldp_total_err = total_syst_err_lowdphi / ldp_nbsum_val ;
            double rel_hdp_total_err(0.) ;
            if ( ldp_nbsum_val > 0 ) rel_hdp_total_err = total_syst_err_highdphi / hdp_nbsum_val ;
            fprintf( ofp_ldp_nbsum, "  %5.1f (%7.4f)", total_syst_err_lowdphi, rel_ldp_total_err ) ;
            fprintf( ofp_hdp_nbsum, "  %5.1f (%7.4f)", total_syst_err_highdphi, rel_hdp_total_err ) ;

            for ( int si=0; si<n_systerr; si++ ) {
               double rel_ldp_err(0.) ;
               if ( ldp_nbsum_val > 0 ) rel_ldp_err = total_syst_lowdphi_events[si] / ldp_nbsum_val ;
               double rel_hdp_err(0.) ;
               if ( ldp_nbsum_val > 0 ) rel_hdp_err = total_syst_highdphi_events[si] / hdp_nbsum_val ;
               fprintf( ofp_ldp_nbsum, "  %5.1f (%7.4f)", total_syst_lowdphi_events[si], rel_ldp_err ) ;
               fprintf( ofp_hdp_nbsum, "  %5.1f (%7.4f)", total_syst_highdphi_events[si], rel_hdp_err ) ;
            }

            fprintf( ofp_ldp_nbsum, "\n") ;
            fprintf( ofp_hdp_nbsum, "\n") ;



         } // bi_nj
      } // bi_ht

      fclose( ofp_ldp_nbsum ) ;
      printf("\n\n Wrote %s\n\n", nbsum_ldp_text_file ) ;
      fclose( ofp_hdp_nbsum ) ;
      printf("\n\n Wrote %s\n\n", nbsum_hdp_text_file ) ;



   } // make_hadtau_lh_input_files1
Пример #6
0
   void draw_qcd_ratio_v3( const char* infile = "outputfiles/hists-v2d-qcd.root", const char* outputdir = "outputfiles/" ) {
     
      setup_bins();
      TLine* line0 = new TLine() ;
      line0 -> SetLineColor(4) ;
      TString tstring ;
      TLine* rline = new TLine() ;
      rline -> SetLineColor(2) ;

      double ratio_max = 1.0 ;

      char command[10000] ;
      sprintf( command, "mkdir -p %s", outputdir ) ;
      gSystem -> Exec( command ) ;


      gStyle -> SetOptStat(0) ;

      gDirectory -> Delete( "h*" ) ;

      loadHist( infile ) ;

      char hname[1000] ;
      char label[100] ;

      TH1F* h_ldp = get_hist( "h_ldp" ) ;
      TH1F* h_hdp = get_hist( "h_hdp" ) ;
      TH1F* h_max_ldp_weight = get_hist( "h_max_ldp_weight" ) ;

      TH1F* h_ratio = new TH1F( "h_ratio", "QCD H/L ratio", nb_global_after_exclusion, 0.5, nb_global_after_exclusion + 0.5 ) ;
      TH1F* h_max_ldp_weight_search_bins = new TH1F( "h_max_ldp_weight_search_bins", "max LDP weight", nb_global_after_exclusion, 0.5, nb_global_after_exclusion + 0.5 ) ;
      TH1F* h_ldp_search_bins = new TH1F( "h_ldp_search_bins", "LDP counts, search bins", nb_global_after_exclusion, 0.5, nb_global_after_exclusion + 0.5 ) ;
      TH1F* h_hdp_search_bins = new TH1F( "h_hdp_search_bins", "HDP counts, search bins", nb_global_after_exclusion, 0.5, nb_global_after_exclusion + 0.5 ) ;

      TH1F * h_ratio_nb[10], * h_ratio_nj[10];

      for ( int nb_count = 0; nb_count < nb_nb; nb_count++)
      {

      TString nb_str; nb_str.Form("%d",nb_count);
      h_ratio_nb[nb_count] = new TH1F( "h_ratio_nb"+nb_str, "QCD H/L ratio, Nb"+nb_str, no_bin_bjet[nb_count], 0.5, no_bin_bjet[nb_count]+0.5 ) ;

      }

      for ( int nj_count = 1; nj_count <= nb_nj; nj_count++)
      {

      TString nj_str; nj_str.Form("%d",nj_count);
      h_ratio_nj[nj_count] = new TH1F( "h_ratio_nj"+nj_str, "QCD H/L ratio, Nj"+nj_str, no_bin_njet[nj_count-1], 0.5, no_bin_njet[nj_count-1]+0.5 ) ;

      }

      int bi_hist(0) ;
      int bi_search_hist(0) ;
      int bi_nb_hist[10] = {};
      int bi_nj_hist[10] = {};
      for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {
         for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {
            for ( int bi_htmht=1; bi_htmht<=nb_htmht; bi_htmht++ ) {

               bi_hist++ ;  // this line should be reviewd when updating the code that produces h_ldp and h_hdp

               if ( is_this_bin_excluded(bi_nj-1, bi_nb-1, bi_htmht-1) ) continue;
               sprintf( label, "%s", h_ldp -> GetXaxis() -> GetBinLabel( bi_hist ) ) ;
               //printf( " %3d : Nj%d Nb%d HTMHT%d : %30s\n", bi_hist, bi_nj, bi_nb-1, bi_htmht, label ) ;
               if ( bi_htmht > 3 ) {
                  bi_search_hist ++ ;
                  double ldp_val = h_ldp -> GetBinContent( bi_hist ) ;
                  double ldp_err = h_ldp -> GetBinError( bi_hist ) ;
                  double hdp_val = h_hdp -> GetBinContent( bi_hist ) ;
                  double hdp_err = h_hdp -> GetBinError( bi_hist ) ;
                  double ratio_val(0.) ;
                  double ratio_err(0.) ;
                  if ( ldp_val > 0. && hdp_val > 0. ) {
                     ratio_val = hdp_val / ldp_val ;
                     ratio_err = ratio_val * sqrt( pow( ldp_err/ldp_val, 2. ) + pow( hdp_err/hdp_val, 2. ) ) ;
                  }
                  h_ratio -> SetBinContent( bi_search_hist, ratio_val ) ;
                  h_ratio -> SetBinError( bi_search_hist, ratio_err ) ;
                  h_ratio -> GetXaxis() -> SetBinLabel( bi_search_hist, label ) ;
                  h_max_ldp_weight_search_bins -> SetBinContent( bi_search_hist, h_max_ldp_weight->GetBinContent( bi_hist ) ) ;
                  h_max_ldp_weight_search_bins -> GetXaxis() -> SetBinLabel( bi_search_hist, label ) ;
                  h_ldp_search_bins -> SetBinContent( bi_search_hist, ldp_val ) ;
                  h_ldp_search_bins -> SetBinError( bi_search_hist, ldp_err ) ;
                  h_ldp_search_bins -> GetXaxis() -> SetBinLabel( bi_search_hist, label ) ;
                  h_hdp_search_bins -> SetBinContent( bi_search_hist, hdp_val ) ;
                  h_hdp_search_bins -> SetBinError( bi_search_hist, hdp_err ) ;
                  h_hdp_search_bins -> GetXaxis() -> SetBinLabel( bi_search_hist, label ) ;
                  printf( "  search %3d : %30s : R= %6.4f +/- %6.4f\n", bi_search_hist, label, ratio_val, ratio_err ) ;
                  TH1F* hp_nb(0x0) ;
                  hp_nb = h_ratio_nb[bi_nb-1] ;
                  bi_nb_hist[bi_nb-1]++;
                  hp_nb -> SetBinContent( bi_nb_hist[bi_nb-1], ratio_val ) ;
                  hp_nb -> SetBinError( bi_nb_hist[bi_nb-1], ratio_err ) ;
                  hp_nb -> GetXaxis() -> SetBinLabel( bi_nb_hist[bi_nb-1], label ) ;
                  TH1F* hp_nj(0x0) ;
                  hp_nj = h_ratio_nj[bi_nj] ;
                  bi_nj_hist[bi_nj-1]++;
                  hp_nj -> SetBinContent( bi_nj_hist[bi_nj-1], ratio_val ) ;
                  hp_nj -> SetBinError  ( bi_nj_hist[bi_nj-1], ratio_err ) ;
                  hp_nj -> GetXaxis() -> SetBinLabel( bi_nj_hist[bi_nj-1], label ) ;
               } // not control bin.
            } // bi_htmht
         } // bi_nb
      } // bi_nj



      h_ratio -> GetXaxis() -> LabelsOption( "v" ) ;
      h_ratio -> SetMarkerStyle(20) ;

      h_max_ldp_weight_search_bins -> GetXaxis() -> LabelsOption( "v" ) ;
      h_ldp_search_bins -> GetXaxis() -> LabelsOption( "v" ) ;
      h_hdp_search_bins -> GetXaxis() -> LabelsOption( "v" ) ;


      for ( int nb_count = 0; nb_count < nb_nb; nb_count++)
      {
         h_ratio_nb[nb_count] -> GetXaxis() -> LabelsOption( "v" ) ;
         h_ratio_nb[nb_count] -> SetMarkerStyle(20) ;
      }

      for ( int nj_count = 1; nj_count <= nb_nj; nj_count++)
      {
         h_ratio_nj[nj_count] -> GetXaxis() -> LabelsOption( "v" ) ;
         h_ratio_nj[nj_count] -> SetMarkerStyle(20) ;
      }
      h_ratio -> Draw() ;
      gPad -> SetGridy(1) ;

      saveHist("outputfiles/qcdmc-ratio-v3.root","h*") ;

   } // draw_qcd_ratio_v3
   void make_lostlep_input_files2(
                                 const char* ldp_input_root_file = "non-qcd-inputs-fall16c/LLPrediction_QCDLDP_notCombined.root",
                                 const char* hdp_input_root_file = "non-qcd-inputs-fall16c/LLPrediction_QCDHDP_notCombined.root",
                                 const char* output_text_file = "outputfiles/combine-input-lostlep.txt",
                                 const char* nbsum_text_file = "outputfiles/nbsum-input-lostlep.txt"
                               ) {

      setup_bins();

      //bool verb(false) ;
      bool verb(true) ;

      gDirectory -> Delete( "h*" ) ;

      TFile* tf_ldp = new TFile( ldp_input_root_file, "read" ) ;
      if ( tf_ldp == 0x0 ) { printf("\n\n *** Bad input file: %s\n\n", ldp_input_root_file ) ; return ; }
      if ( !(tf_ldp -> IsOpen() ) ) { printf("\n\n *** Bad input file: %s\n\n", ldp_input_root_file ) ; return ; }

      TFile* tf_hdp = new TFile( hdp_input_root_file, "read" ) ;
      if ( tf_hdp == 0x0 ) { printf("\n\n *** Bad input file: %s\n\n", hdp_input_root_file ) ; return ; }
      if ( !(tf_hdp -> IsOpen() ) ) { printf("\n\n *** Bad input file: %s\n\n", hdp_input_root_file ) ; return ; }

      tf_ldp -> cd( "Prediction_data" ) ;
      tf_hdp -> cd( "Prediction_data" ) ;

      printf("\n") ;
      tf_ldp -> ls() ;
      printf("\n") ;

      FILE* ofp_combine ;
      if ( (ofp_combine = fopen( output_text_file, "w" ))==NULL ) {
         printf( "\n\n *** Problem opening combine output file: %s\n\n", output_text_file ) ;
         return ;
      }

      FILE* ofp_nbsum ;
      if ( (ofp_nbsum = fopen( nbsum_text_file, "w" ))==NULL ) {
         printf( "\n\n *** Problem opening nbsum output file: %s\n\n", nbsum_text_file ) ;
         return ;
      }

      FILE* ofp_nbsum_stat_syst ;
      TString systfile_nbsum( nbsum_text_file ) ;
      systfile_nbsum.ReplaceAll("input","stat-syst") ;
      if ( (ofp_nbsum_stat_syst = fopen( systfile_nbsum.Data(), "w" ))==NULL ) {
         printf( "\n\n *** Problem opening nbsum stat-syst output file: %s\n\n", systfile_nbsum.Data() ) ;
         return ;
      }

      FILE* ofp_combine_stat_syst ;
      TString systfile_combine( output_text_file ) ;
      systfile_combine.ReplaceAll("input","stat-syst") ;
      if ( (ofp_combine_stat_syst = fopen( systfile_combine.Data(), "w" ))==NULL ) {
         printf( "\n\n *** Problem opening combine stat-syst output file: %s\n\n", systfile_combine.Data() ) ;
         return ;
      }

      TH1F* h_ldp = (TH1F*) tf_ldp -> Get( "Prediction_data/totalPred_LL" ) ;
      if ( h_ldp == 0x0 ) { printf("\n\n *** Missing totalPred_LL for LDP\n\n") ; return ; }

      TH1F* h_hdp = (TH1F*) tf_hdp -> Get( "Prediction_data/totalPred_LL" ) ;
      if ( h_hdp == 0x0 ) { printf("\n\n *** Missing totalPred_LL for HDP\n\n") ; return ; }

      TH1* h_systerr_lowdphi[100] ;
      TH1* h_systerr_highdphi[100] ;
      char systerr_name[100][100] ;
      int n_systerr(0) ;

      {
         int si(0) ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredIsoTrackSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredIsoTrackSysUp_LL" ) ;
         sprintf( systerr_name[si], "IsoTrk" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredMTWSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredMTWSysUp_LL" ) ;
         sprintf( systerr_name[si], "MTW" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredPuritySysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredPuritySysUp_LL" ) ;
         sprintf( systerr_name[si], "Purity" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredSingleLepPuritySysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredSingleLepPuritySysUp_LL" ) ;
         sprintf( systerr_name[si], "SingleLepPurity" ) ;
         si++ ;

         ///////////h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredDiLepFoundSysUp_LL" ) ;
         ///////////h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredDiLepFoundSysUp_LL" ) ;
         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredDiLepSRSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredDiLepSRSysUp_LL" ) ;
         sprintf( systerr_name[si], "DiLepFound" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredMuIsoSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredMuIsoSysUp_LL" ) ;
         sprintf( systerr_name[si], "MuIso" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredMuRecoSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredMuRecoSysUp_LL" ) ;
         sprintf( systerr_name[si], "MuReco" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredMuAccSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredMuAccSysUp_LL" ) ;
         sprintf( systerr_name[si], "MuAcc" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredMuAccQsquareSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredMuAccQsquareSysUp_LL" ) ;
         sprintf( systerr_name[si], "MuAccQ2" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredElecIsoSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredElecIsoSysUp_LL" ) ;
         sprintf( systerr_name[si], "ElecIso" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredElecRecoSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredElecRecoSysUp_LL" ) ;
         sprintf( systerr_name[si], "ElecReco" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredElecAccSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredElecAccSysUp_LL" ) ;
         sprintf( systerr_name[si], "ElecAcc" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredElecAccQsquareSysUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredElecAccQsquareSysUp_LL" ) ;
         sprintf( systerr_name[si], "ElecAccQ2" ) ;
         si++ ;

         h_systerr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredNonClosureUp_LL" ) ;
         h_systerr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredNonClosureUp_LL" ) ;
         sprintf( systerr_name[si], "NonClosure" ) ;
         si++ ;


         n_systerr = si ;
      }




      TH1* h_staterr_lowdphi[100] ;
      TH1* h_staterr_highdphi[100] ;
      char staterr_name[100][100] ;
      int n_staterr(0) ;

      {
         int si(0) ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredIsoTrackStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredIsoTrackStatUp_LL" ) ;
         sprintf( staterr_name[si], "IsoTrk" ) ;
         si++ ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredMTWStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredMTWStatUp_LL" ) ;
         sprintf( staterr_name[si], "MTW" ) ;
         si++ ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredPurityStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredPurityStatUp_LL" ) ;
         sprintf( staterr_name[si], "Purity" ) ;
         si++ ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredSingleLepPurityStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredSingleLepPurityStatUp_LL" ) ;
         sprintf( staterr_name[si], "SingleLepPurity" ) ;
         si++ ;

         //////////////////////h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredDiLepFoundStatUp_LL" ) ;
         //////////////////////h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredDiLepFoundStatUp_LL" ) ;
         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredDiLepSRStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredDiLepSRStatUp_LL" ) ;
         sprintf( staterr_name[si], "DiLepFound" ) ;
         si++ ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredMuIsoStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredMuIsoStatUp_LL" ) ;
         sprintf( staterr_name[si], "MuIso" ) ;
         si++ ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredMuRecoStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredMuRecoStatUp_LL" ) ;
         sprintf( staterr_name[si], "MuReco" ) ;
         si++ ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredMuAccStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredMuAccStatUp_LL" ) ;
         sprintf( staterr_name[si], "MuAcc" ) ;
         si++ ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredElecIsoStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredElecIsoStatUp_LL" ) ;
         sprintf( staterr_name[si], "ElecIso" ) ;
         si++ ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredElecRecoStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredElecRecoStatUp_LL" ) ;
         sprintf( staterr_name[si], "ElecReco" ) ;
         si++ ;

         h_staterr_lowdphi[si]  = get_hist( tf_ldp, "Prediction_data/totalPredElecAccStatUp_LL" ) ;
         h_staterr_highdphi[si]  = get_hist( tf_hdp, "Prediction_data/totalPredElecAccStatUp_LL" ) ;
         sprintf( staterr_name[si], "ElecAcc" ) ;
         si++ ;

         n_staterr = si ;
      }










      int bi_hist(0) ;
      int bi_control(0) ;
      int bi_search(0) ;
      int count_all(0) ;
      for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {
         for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {
            for ( int bi_htmht=1; bi_htmht<=nb_htmht; bi_htmht++ ) {

               count_all++ ;

               int bi_hist = global_bin_with_mhtc( bi_nj, bi_nb, bi_htmht ) ;

               double ldp_val(0.) ;
               double ldp_hist_err(0.) ;

               double hdp_val(0.) ;
               double hdp_hist_err(0.) ;

               if ( bi_hist > 0 ) {
                  ldp_val = h_ldp -> GetBinContent( bi_hist ) ;
                  ldp_hist_err = h_ldp -> GetBinError( bi_hist ) ;

                  hdp_val = h_hdp -> GetBinContent( bi_hist ) ;
                  hdp_hist_err = h_hdp -> GetBinError( bi_hist ) ;
               }



               double total_syst_err2_lowdphi(0.) ;
               double total_syst_err2_highdphi(0.) ;
               for ( int si=0; si<n_systerr; si++ ) {
                  double syst_lowdphi(0.) ;
                  double syst_highdphi(0.) ;
                  if ( bi_hist > 0 ) {
                     syst_lowdphi = h_systerr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                     syst_highdphi = h_systerr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                  }
                  double syst_lowdphi_events(0.) ;
                  double syst_highdphi_events(0.) ;
                  if ( syst_lowdphi > 0 && syst_highdphi > 0 ) {
                     syst_lowdphi_events  = syst_lowdphi  * ldp_val ;
                     syst_highdphi_events = syst_highdphi * hdp_val ;
                  }
                  total_syst_err2_lowdphi  += pow( syst_lowdphi_events , 2. ) ;
                  total_syst_err2_highdphi += pow( syst_highdphi_events, 2. ) ;
               } // si

               double total_stat_err2_lowdphi(0.) ;
               double total_stat_err2_highdphi(0.) ;
               for ( int si=0; si<n_staterr; si++ ) {
                  double stat_lowdphi(0.) ;
                  double stat_highdphi(0.) ;
                  if ( bi_hist > 0 ) {
                     stat_lowdphi = h_staterr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                     stat_highdphi = h_staterr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                  }
                  double stat_lowdphi_events(0.) ;
                  double stat_highdphi_events(0.) ;
                  if ( stat_lowdphi > 0 && stat_highdphi > 0 ) {
                     stat_lowdphi_events  = stat_lowdphi  * ldp_val ;
                     stat_highdphi_events = stat_highdphi * hdp_val ;
                  }
                  total_stat_err2_lowdphi  += pow( stat_lowdphi_events , 2. ) ;
                  total_stat_err2_highdphi += pow( stat_highdphi_events, 2. ) ;
                  printf(" LDP stat err : %12s %6.3f  %8.1f\n", staterr_name[si], stat_lowdphi, stat_lowdphi_events ) ;
               } // si

               printf(" LDP total stat err :  %8.1f   %8.1f\n", sqrt(total_stat_err2_lowdphi), ldp_hist_err  ) ;
               ///////////////double combined_stat_err_lowdphi = sqrt( pow( total_stat_err2_lowdphi, 2. ) + pow( ldp_hist_err, 2. ) ) ; // BUG
               double combined_stat_err_lowdphi = sqrt( total_stat_err2_lowdphi + pow( ldp_hist_err, 2. ) ) ;
               double total_syst_err_lowdphi = sqrt( total_syst_err2_lowdphi ) ;

               ///////////double combined_stat_err_highdphi = sqrt( pow( total_stat_err2_highdphi, 2. ) + pow( hdp_hist_err, 2. ) ) ; // BUG
               double combined_stat_err_highdphi = sqrt( total_stat_err2_highdphi + pow( hdp_hist_err, 2. ) ) ;
               double total_syst_err_highdphi = sqrt( total_syst_err2_highdphi ) ;





               TString hist_bin_label( h_ldp -> GetXaxis() -> GetBinLabel( bi_hist ) ) ;

               int bi_ht = 0, bi_mht = 0;

               if ( bi_htmht == 1 ) { bi_ht = 1; bi_mht = 1; }
               if ( bi_htmht == 2 ) { bi_ht = 2; bi_mht = 1; }
               if ( bi_htmht == 3 ) { bi_ht = 3; bi_mht = 1; }

               if ( bi_htmht == 4 ) { bi_ht = 1; bi_mht = 2; }
               if ( bi_htmht == 5 ) { bi_ht = 2; bi_mht = 2; }
               if ( bi_htmht == 6 ) { bi_ht = 3; bi_mht = 2; }

               if ( bi_htmht == 7 ) { bi_ht = 1; bi_mht = 3; }
               if ( bi_htmht == 8 ) { bi_ht = 2; bi_mht = 3; }
               if ( bi_htmht == 9 ) { bi_ht = 3; bi_mht = 3; }

               if ( bi_htmht ==10 ) { bi_ht = 2; bi_mht = 4; }
               if ( bi_htmht ==11 ) { bi_ht = 3; bi_mht = 4; }

               if ( bi_htmht ==12 ) { bi_ht = 2; bi_mht = 5; }
               if ( bi_htmht ==13 ) { bi_ht = 3; bi_mht = 5; }

               if ( bi_mht == 1 ) {
                  bi_control ++ ;
               } else {
                  bi_search ++ ;
               }

               char mhtchar[10] ;
               if ( bi_mht == 1 ) {
                  sprintf( mhtchar, "C" ) ;
               } else {
                  sprintf( mhtchar, "%d", bi_mht-1 ) ;
               }

               char label[1000] ;
               sprintf( label, " %3d  %s %3d  Nj%d-Nb%d-MHT%s-HT%d",
                   count_all, (bi_mht==1)?"C":"S", (bi_mht==1)?bi_control:bi_search,
                   bi_nj, bi_nb-1, mhtchar, bi_ht ) ;

               //// printf("  label : %s   ,  hist label %s\n", label, hist_bin_label.Data() ) ;

               double ldp_stat_over_sqrtn(0.8), ldp_syst_over_n(0.15) ;
               if ( ldp_val > 0 ) {
                  ldp_stat_over_sqrtn = combined_stat_err_lowdphi / sqrt( ldp_val ) ;
                  ldp_syst_over_n = total_syst_err_lowdphi / ldp_val ;
               }
               double hdp_stat_over_sqrtn(0.8), hdp_syst_over_n(0.15) ;
               if ( hdp_val > 0 ) {
                  hdp_stat_over_sqrtn = combined_stat_err_highdphi / sqrt( hdp_val ) ;
                  hdp_syst_over_n = total_syst_err_highdphi / hdp_val ;
               }

               printf(               "%s      %8.1f +/- %5.1f +/- %5.1f         %8.1f +/- %5.1f +/- %5.1f\n",
                   label,    ldp_val, combined_stat_err_lowdphi, total_syst_err_lowdphi,   hdp_val, combined_stat_err_highdphi, total_syst_err_highdphi ) ;

               fprintf( ofp_combine, "%s      %8.1f +/- %5.1f +/- %5.1f         %8.1f +/- %5.1f +/- %5.1f\n",
                   label,    ldp_val, combined_stat_err_lowdphi, total_syst_err_lowdphi,   hdp_val, combined_stat_err_highdphi, total_syst_err_highdphi ) ;

               if ( bi_htmht > 3 ) {
                  char this_label[100] ;
                  sprintf( this_label, "%3d S-Nj%d-Nb%d-MHT%d-HT%d (S%d)", bi_search, bi_nj, bi_nb-1, bi_mht-1, bi_ht, bi_htmht-3 ) ;
                  fprintf( ofp_combine_stat_syst, "   %-30s   %6.3f  %6.3f       %6.3f  %6.3f\n",
                      this_label,
                      ldp_stat_over_sqrtn, ldp_syst_over_n,   hdp_stat_over_sqrtn, hdp_syst_over_n ) ;
               } else {
                  char this_label[100] ;
                  sprintf( this_label, "%3d C-Nj%d-Nb%d-MHT%d-HT%d (C%d)", bi_control, bi_nj, bi_nb-1, bi_mht-1, bi_ht, bi_htmht ) ;
                  fprintf( ofp_combine_stat_syst, "   %-30s   %6.3f  %6.3f       %6.3f  %6.3f\n",
                      this_label,
                      ldp_stat_over_sqrtn, ldp_syst_over_n,   hdp_stat_over_sqrtn, hdp_syst_over_n ) ;
               }

            } // bi_htmht
         } // bi_nb
      } // bi_nj

      fclose( ofp_combine ) ;
      printf("\n\n Wrote %s\n\n", output_text_file ) ;

     //---------

      for ( int bi_ht=1; bi_ht<=nBinsHT; bi_ht++ ) {
         for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {

            float nbsum_lowdphi_val(0.) ;
            float nbsum_lowdphi_err2(0.) ;

            float nbsum_highdphi_val(0.) ;
            float nbsum_highdphi_err2(0.) ;

            double total_syst_lowdphi_events[100] ;
            double total_syst_highdphi_events[100] ;
            for ( int si=0; si<n_systerr; si++ ) {
               total_syst_lowdphi_events[si]  = 0 ;
               total_syst_highdphi_events[si] = 0 ;
            }
            double total_stat2_lowdphi_events[100] ;
            double total_stat2_highdphi_events[100] ;
            for ( int si=0; si<n_staterr; si++ ) {
               total_stat2_lowdphi_events[si]  = 0 ;
               total_stat2_highdphi_events[si] = 0 ;
            }

            for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {

               int bi_hist = global_bin_with_mhtc( bi_nj, bi_nb, bi_ht ) ;

               double lowdphi_val(0.) ;
               double lowdphi_err(0.) ;
               if ( bi_hist > 0 ) {
                  lowdphi_val = h_ldp -> GetBinContent( bi_hist ) ;
                  lowdphi_err = h_ldp -> GetBinError( bi_hist ) ;
               }

               nbsum_lowdphi_val += lowdphi_val ;
               nbsum_lowdphi_err2 += pow( lowdphi_err, 2. ) ;

               double highdphi_val = h_hdp -> GetBinContent( bi_hist ) ;
               double highdphi_err = h_hdp -> GetBinError( bi_hist ) ;

               nbsum_highdphi_val += highdphi_val ;
               nbsum_highdphi_err2 += pow( highdphi_err, 2. ) ;

               for ( int si=0; si<n_systerr; si++ ) {
                  double syst_lowdphi(0.) ;
                  double syst_highdphi(0.) ;
                  if ( bi_hist > 0 ) {
                     syst_lowdphi = h_systerr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                     syst_highdphi = h_systerr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                  }
                  if ( syst_lowdphi > 0 && syst_highdphi > 0 ) {
                     total_syst_lowdphi_events[si]  += syst_lowdphi  * lowdphi_val ;
                     total_syst_highdphi_events[si] += syst_highdphi * highdphi_val ;
                  }
               } // si

               for ( int si=0; si<n_staterr; si++ ) {
                  double stat_lowdphi(0.) ;
                  double stat_highdphi(0.) ;
                  if ( bi_hist > 0 ) {
                     stat_lowdphi = h_staterr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                     stat_highdphi = h_staterr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                  }
                  if ( stat_lowdphi > 0 && stat_highdphi > 0 ) {
                     total_stat2_lowdphi_events[si]  += pow( stat_lowdphi  * lowdphi_val, 2 ) ;
                     total_stat2_highdphi_events[si] += pow( stat_highdphi * highdphi_val, 2 ) ;
                  }
               } // si
            } // bi_nb

            double total_syst_err2_lowdphi(0.) ;
            double total_syst_err2_highdphi(0.) ;
            for ( int si=0; si<n_systerr; si++ ) {
               total_syst_err2_lowdphi += pow( total_syst_lowdphi_events[si], 2.)   ;
               total_syst_err2_highdphi += pow( total_syst_highdphi_events[si], 2.)  ;
               if (verb) printf(" syst %2d : %25s :   %7.1f  %7.1f\n", si, systerr_name[si], total_syst_lowdphi_events[si], total_syst_highdphi_events[si] ) ;
            }
            double total_stat_err2_lowdphi(0.) ;
            double total_stat_err2_highdphi(0.) ;
            for ( int si=0; si<n_staterr; si++ ) {
               total_stat_err2_lowdphi +=  total_stat2_lowdphi_events[si]  ;
               total_stat_err2_highdphi +=  total_stat2_highdphi_events[si]  ;
               if (verb) printf(" stat %2d : %25s :   %7.1f  %7.1f\n", si, staterr_name[si], sqrt(total_stat2_lowdphi_events[si]), sqrt(total_stat2_highdphi_events[si]) ) ;
            }
            double total_syst_err_lowdphi = sqrt( total_syst_err2_lowdphi ) ;
            double total_syst_err_highdphi = sqrt( total_syst_err2_highdphi ) ;
            double total_stat_err_lowdphi = sqrt( nbsum_lowdphi_err2 + total_stat_err2_lowdphi ) ;
            double total_stat_err_highdphi = sqrt( nbsum_highdphi_err2 + total_stat_err2_highdphi ) ;

            double ldp_syst_over_n(0.5) ;
            double ldp_stat_over_sqrtn(0.5) ;
            if ( nbsum_lowdphi_val > 0 ) {
               ldp_syst_over_n =  total_syst_err_lowdphi / nbsum_lowdphi_val  ;
               ldp_stat_over_sqrtn = total_stat_err_lowdphi / sqrt(nbsum_lowdphi_val) ;
            }
            double hdp_syst_over_n(0.5) ;
            double hdp_stat_over_sqrtn(0.5) ;
            if ( nbsum_highdphi_val > 0 ) {
               hdp_syst_over_n =  total_syst_err_highdphi / nbsum_highdphi_val  ;
               hdp_stat_over_sqrtn = total_stat_err_highdphi / sqrt(nbsum_highdphi_val) ;
            }

            printf( "   Nj%d-HT%d   %8.1f +/- %5.1f +/- %5.1f (%6.3f)     %8.1f +/- %5.1f +/- %5.1f (%6.3f)\n", bi_nj, bi_ht,
                  nbsum_lowdphi_val, total_stat_err_lowdphi, total_syst_err_lowdphi,  ldp_syst_over_n,
                  nbsum_highdphi_val, total_stat_err_highdphi, total_syst_err_highdphi,  hdp_syst_over_n ) ;
            fprintf( ofp_nbsum, "   Nj%d-HT%d   %8.1f +/- %5.1f +/- %5.1f    %8.1f +/- %5.1f +/- %5.1f\n", bi_nj, bi_ht,
                  nbsum_lowdphi_val, total_stat_err_lowdphi, total_syst_err_lowdphi,
                  nbsum_highdphi_val, total_stat_err_highdphi, total_syst_err_highdphi ) ;
            fprintf( ofp_nbsum_stat_syst, "   Nj%d-HT%d    %6.3f  %6.3f       %6.3f  %6.3f\n", bi_nj, bi_ht, 
                ldp_stat_over_sqrtn, ldp_syst_over_n,   hdp_stat_over_sqrtn, hdp_syst_over_n ) ;

         } // bi_nj
      } // bi_ht

      fclose( ofp_nbsum ) ;
      fclose( ofp_nbsum_stat_syst ) ;
      fclose( ofp_combine_stat_syst ) ;
      printf("\n\n Wrote %s\n\n", nbsum_text_file ) ;
      printf("\n\n Wrote %s\n\n", systfile_nbsum.Data() ) ;
      printf("\n\n Wrote %s\n\n", systfile_combine.Data() ) ;



   } // make_lostlep_input_files2
Пример #8
0
void wfd_raw_hits(const int run_nr = 0) 
{
  int i;

  const int n_hists = 6;
  const char *h_names_hits[n_hists] = { "WFDRawHitsR0",
					"WFDRawHitsR1",
					"WFDRawHitsG0",
					"WFDRawHitsG1",
					"WFDRawHitsB0",
					"WFDRawHitsB1" };

  const char *h_names_coinc[n_hists] = { "WFDRawCoincR0",
					 "WFDRawCoincR1",
					 "WFDRawCoincG0",
					 "WFDRawCoincG1",
					 "WFDRawCoincB0",
					 "WFDRawCoincB1" };
  
  TH1D *h1_hits [n_hists];
  TH1D *h1_coinc[n_hists];
  TH1D *h1_diff [n_hists];
  char name [256];
  char title[256];

  //=========================================================
  //             *** initialize style ***
  //=========================================================

  init();
  gStyle->SetOptStat(11);

  //=========================================================
  //                  *** open canvas ***
  //=========================================================
  
  TCanvas *c1 = new TCanvas("c1","c1",0,0,800,1000);
  c1->Draw();
  c1->cd();

  c1->Divide(2,3,0.001,0.001,10);
  //c1->Divide(2,3);

  //=========================================================
  //          *** receive and plot histograms ***
  //=========================================================
  
  for (i=0; i<n_hists; i++) {

    h1_hits[i] = (TH1D*) get_hist(h_names_hits[i], run_nr);
    if ( !h1_hits[i] ) continue;

    h1_diff[i] = new TH1D( *h1_hits[i] );
    sprintf(name,"%s_diff",h1_hits[i]->GetName());
    h1_diff[i]->SetName(name);    

    h1_coinc[i] = (TH1D*) get_hist(h_names_coinc[i], run_nr);
    if ( !h1_coinc[i] ) continue;

    int ipad = i+1;

    c1->cd(ipad);

    c1->GetPad(ipad)->SetGridx(1);

    h1_hits [i]->SetLineColor(kBlack);
    h1_coinc[i]->SetLineColor(kBlue);
    h1_diff [i]->SetLineColor(kRed);

    h1_hits [i]->SetLineWidth(4);
    h1_coinc[i]->SetLineWidth(2);
    h1_diff [i]->SetLineWidth(2);
    h1_diff [i]->SetFillColor(kYellow);
    //h1_diff [i]->SetFillColor(kGreen);
    //h1_coinc [i]->SetFillColor(kGreen);
    //h1_coinc [i]->SetFillColor(17);
    //h1_hits  [i]->SetFillColor(18);
    //h1_coinc [i]->SetFillColor(18);
    h1_hits  [i]->SetFillColor(19);

    if ( h1_hits[i]->GetMaximum() > 2 ) {
      ;//h1_hits [i]->SetMinimum(0.9);
      ;//c1->GetPad(ipad)->SetLogy();
    } else {
      h1_hits [i]->SetMinimum(0.0);
      h1_hits [i]->SetMaximum(2.0);
    }

    //h1_hits [i]->GetXaxis()->SetRangeUser(0.0,12.0);


    h1_hits [i]->Draw();
    h1_hits [i]->SetXTitle("slot number");
    h1_hits [i]->SetYTitle("counts");

    h1_coinc[i]->Draw("Same");

    h1_diff [i]->Add(h1_coinc[i],-1);
    h1_diff [i]->Draw("Same");



    c1->GetPad(ipad)->Update();

  }
  
  c1->SaveAs("../png/wfd_raw_hits.png");

  //===========================================================================
  //      *** make comments to the plot as html output ***
  //===========================================================================

  ofstream *os = new ofstream("../html/wfd_raw_hits.html");
  *os << "<b>Black histogram: total number of islands in each channel (inclusive spectrum)<br>"
      << "<font color=\"#0000FF\"> Blue histogram: number of coincidences</font><br>"
      << "<font color=\"#FF0000\"> Red histogram: difference between black and blue</font><br>"
      << "</b>";


  delete os;

}
   void make_znunu_input_files1( const char* ldp_input_root_file = "non-qcd-inputs-topup2/ZinvHistos_ldp.root",
                                 const char* hdp_input_root_file = "non-qcd-inputs-topup2/ZinvHistos_hdp.root",
                                 const char* output_text_file = "outputfiles/combine-input-znunu.txt",
                                 const char* nbsum_text_file  = "outputfiles/nbsum-input-znunu.txt"
                               ) {
      setup_bins();


      gDirectory -> Delete( "h*" ) ;

      TFile* tf_ldp = new TFile( ldp_input_root_file, "read" ) ;
      if ( tf_ldp == 0x0 ) { printf("\n\n *** Bad input file: %s\n\n", ldp_input_root_file ) ; return ; }
      if ( !(tf_ldp -> IsOpen() ) ) { printf("\n\n *** Bad input file: %s\n\n", ldp_input_root_file ) ; return ; }

      TFile* tf_hdp = new TFile( hdp_input_root_file, "read" ) ;
      if ( tf_hdp == 0x0 ) { printf("\n\n *** Bad input file: %s\n\n", hdp_input_root_file ) ; return ; }
      if ( !(tf_hdp -> IsOpen() ) ) { printf("\n\n *** Bad input file: %s\n\n", hdp_input_root_file ) ; return ; }

      printf("\n") ;
      tf_ldp -> ls() ;
      printf("\n") ;

      FILE* ofp_combine ;
      if ( (ofp_combine = fopen( output_text_file, "w" ))==NULL ) {
         printf( "\n\n *** Problem opening combine output file: %s\n\n", output_text_file ) ;
         return ;
      }

      FILE* ofp_nbsum ;
      if ( (ofp_nbsum = fopen( nbsum_text_file, "w" ))==NULL ) {
         printf( "\n\n *** Problem opening nbsum output file: %s\n\n", nbsum_text_file ) ;
         return ;
      }

      FILE* ofp_nbsum_stat_syst ;
      TString systfile_nbsum( nbsum_text_file ) ;
      systfile_nbsum.ReplaceAll("input","stat-syst") ;
      if ( (ofp_nbsum_stat_syst = fopen( systfile_nbsum.Data(), "w" ))==NULL ) {
         printf( "\n\n *** Problem opening nbsum stat-syst output file: %s\n\n", systfile_nbsum.Data() ) ;
         return ;
      }

      FILE* ofp_combine_stat_syst ;
      TString systfile_combine( output_text_file ) ;
      systfile_combine.ReplaceAll("input","stat-syst") ;
      if ( (ofp_combine_stat_syst = fopen( systfile_combine.Data(), "w" ))==NULL ) {
         printf( "\n\n *** Problem opening combine stat-syst output file: %s\n\n", systfile_combine.Data() ) ;
         return ;
      }


      TH1F* h_ldp_nonzero = (TH1F*) tf_ldp -> Get( "ZinvBGpred" ) ;
      if ( h_ldp_nonzero == 0x0 ) { printf("\n\n *** Missing ZinvBGpred\n\n") ; return ; }

      TH1F* h_hdp_nonzero = (TH1F*) tf_hdp -> Get( "ZinvBGpred" ) ;
      if ( h_hdp_nonzero == 0x0 ) { printf("\n\n *** Missing ZinvBGpred\n\n") ; return ; }



      TH1F* h_ldp_zero = (TH1F*) tf_ldp -> Get( "ZinvBG0EVpred" ) ;
      if ( h_ldp_zero == 0x0 ) { printf("\n\n *** Missing ZinvBG0EVpred\n\n") ; return ; }

      TH1F* h_hdp_zero = (TH1F*) tf_hdp -> Get( "ZinvBG0EVpred" ) ;
      if ( h_hdp_zero == 0x0 ) { printf("\n\n *** Missing ZinvBG0EVpred\n\n") ; return ; }

      TH1F* h_ldp = (TH1F*) h_ldp_nonzero -> Clone( "h_ldp" ) ;
      h_ldp -> Add( h_ldp_zero ) ;

      TH1F* h_hdp = (TH1F*) h_hdp_nonzero -> Clone( "h_hdp" ) ;
      h_hdp -> Add( h_hdp_zero ) ;

      TH1* h_systerr_lowdphi[100] ;
      TH1* h_systerr_highdphi[100] ;
      char systerr_name[100][100] ;
      int n_systerr(0) ;

      {
         int si(0) ;

         TH1* h_syst_ldp_nonzero ;
         TH1* h_syst_ldp_zero ;
         TH1* h_syst_ldp ;

         TH1* h_syst_hdp_nonzero ;
         TH1* h_syst_hdp_zero ;
         TH1* h_syst_hdp ;

        //--- Note: These are in events.

         h_syst_ldp_nonzero = get_hist( tf_ldp, "ZinvBGsysUp" ) ;
         h_syst_ldp_zero = get_hist( tf_ldp, "ZinvBG0EVsysUp" ) ;
         h_syst_ldp = (TH1*) h_syst_ldp_nonzero -> Clone( "ZinvBGsysUp_combined" ) ;
         h_syst_ldp -> Add( h_syst_ldp_zero ) ;

         h_systerr_lowdphi[si] = h_syst_ldp ;

         h_syst_hdp_nonzero = get_hist( tf_hdp, "ZinvBGsysUp" ) ;
         h_syst_hdp_zero = get_hist( tf_hdp, "ZinvBG0EVsysUp" ) ;
         h_syst_hdp = (TH1*) h_syst_hdp_nonzero -> Clone( "ZinvBGsysUp_combined" ) ;
         h_syst_hdp -> Add( h_syst_hdp_zero ) ;

         h_systerr_highdphi[si] = h_syst_hdp ;


         sprintf( systerr_name[si], "Total" ) ;
         si++ ;

         n_systerr = si ;
      }







      int bi_hist(0) ;
      int bi_control(0) ;
      int bi_search(0) ;
      for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {
         for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {
            for ( int bi_htmht=1; bi_htmht<=nb_htmht; bi_htmht++ ) {

               if ( bin_edges_nj[bi_nj-1] < 2.5 ) continue; // because znuznu input file lasks NJets = 2 bin
                  bi_hist ++ ;

               double ldp_val = h_ldp -> GetBinContent( bi_hist ) ;
               double ldp_hist_err = h_ldp -> GetBinError( bi_hist ) ;

               double hdp_val = h_hdp -> GetBinContent( bi_hist ) ;
               double hdp_hist_err = h_hdp -> GetBinError( bi_hist ) ;

               double total_syst_lowdphi_events[100] ;
               double total_syst_highdphi_events[100] ;
               for ( int si=0; si<n_systerr; si++ ) {
                  total_syst_lowdphi_events[si]  = 0 ;
                  total_syst_highdphi_events[si] = 0 ;
               }
               for ( int si=0; si<n_systerr; si++ ) {
                  ////////////////double syst_lowdphi = h_systerr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                  ////////////////double syst_highdphi = h_systerr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                  double syst_lowdphi = h_systerr_lowdphi[si] -> GetBinContent( bi_hist ) ;
                  double syst_highdphi = h_systerr_highdphi[si] -> GetBinContent( bi_hist ) ;
                  ///////printf(" DEBUG1 syst hist content:  ldp %9.3f  hdp %9.3f\n", 
                      ///////h_systerr_lowdphi[si] -> GetBinContent( bi_hist ),
                      ///////h_systerr_highdphi[si] -> GetBinContent( bi_hist ) ) ;
                  if ( syst_lowdphi > 0 && syst_highdphi > 0 ) {
                     total_syst_lowdphi_events[si]  += syst_lowdphi  ;
                     total_syst_highdphi_events[si] += syst_highdphi  ;
                  }
               } // si
               double total_syst_err2_lowdphi(0.) ;
               double total_syst_err2_highdphi(0.) ;
               for ( int si=0; si<n_systerr; si++ ) {
                  total_syst_err2_lowdphi += pow( total_syst_lowdphi_events[si], 2.)   ;
                  total_syst_err2_highdphi += pow( total_syst_highdphi_events[si], 2.)  ;
                  //////printf("  %2d : %25s :   %7.1f  %7.1f\n", si, systerr_name[si], total_syst_lowdphi_events[si], total_syst_highdphi_events[si] ) ;
               }
               double total_syst_err_lowdphi = sqrt( total_syst_err2_lowdphi ) ;
               double total_syst_err_highdphi = sqrt( total_syst_err2_highdphi ) ;
               //////////printf("  DEBUG2 syst ldp %9.3f   syst hdp %9.3f\n", total_syst_err_lowdphi, total_syst_err_highdphi ) ;

               TString hist_bin_label( h_ldp -> GetXaxis() -> GetBinLabel( bi_hist ) ) ;

               int bi_ht = 0, bi_mht = 0;

               if ( bi_htmht == 1 ) { bi_ht = 1; bi_mht = 1; }
               if ( bi_htmht == 2 ) { bi_ht = 2; bi_mht = 1; }
               if ( bi_htmht == 3 ) { bi_ht = 3; bi_mht = 1; }

               if ( bi_htmht == 4 ) { bi_ht = 1; bi_mht = 2; }
               if ( bi_htmht == 5 ) { bi_ht = 2; bi_mht = 2; }
               if ( bi_htmht == 6 ) { bi_ht = 3; bi_mht = 2; }

               if ( bi_htmht == 7 ) { bi_ht = 1; bi_mht = 3; }
               if ( bi_htmht == 8 ) { bi_ht = 2; bi_mht = 3; }
               if ( bi_htmht == 9 ) { bi_ht = 3; bi_mht = 3; }

               /////////////////if ( bi_htmht ==10 ) { bi_ht = 1; bi_mht = 4; }
               /////////////////if ( bi_htmht ==11 ) { bi_ht = 2; bi_mht = 4; }

               /////////////////if ( bi_htmht ==12 ) { bi_ht = 1; bi_mht = 5; }
               /////////////////if ( bi_htmht ==13 ) { bi_ht = 2; bi_mht = 5; }

               if ( bi_htmht ==10 ) { bi_ht = 2; bi_mht = 4; }
               if ( bi_htmht ==11 ) { bi_ht = 3; bi_mht = 4; }

               if ( bi_htmht ==12 ) { bi_ht = 2; bi_mht = 5; }
               if ( bi_htmht ==13 ) { bi_ht = 3; bi_mht = 5; }

               if ( bi_mht == 1 ) {
                  bi_control ++ ;
               } else {
                  bi_search ++ ;
               }

               char mhtchar[10] ;
               if ( bi_mht == 1 ) {
                  sprintf( mhtchar, "C" ) ;
               } else {
                  sprintf( mhtchar, "%d", bi_mht-1 ) ;
               }

               char label[1000] ;
               sprintf( label, " %3d  %s %3d  Nj%d-Nb%d-MHT%s-HT%d",
                   bi_hist, (bi_mht==1)?"C":"S", (bi_mht==1)?bi_control:bi_search,
                   bi_nj, bi_nb-1, mhtchar, bi_ht ) ;

               //// printf("  label : %s   ,  hist label %s\n", label, hist_bin_label.Data() ) ;

               double ldp_stat_over_sqrtn(0.8), ldp_syst_over_n(0.20) ;
               if ( ldp_val > 0 ) {
                  ldp_stat_over_sqrtn = ldp_hist_err / sqrt( ldp_val ) ;
                  if ( total_syst_err_lowdphi > 0 ) ldp_syst_over_n = total_syst_err_lowdphi / ldp_val ;
               }
               double hdp_stat_over_sqrtn(0.8), hdp_syst_over_n(0.20) ;
               if ( hdp_val > 0 ) {
                  hdp_stat_over_sqrtn = hdp_hist_err / sqrt( hdp_val ) ;
                  if ( total_syst_err_highdphi ) hdp_syst_over_n = total_syst_err_highdphi / hdp_val ;
               }

               printf(               "%s      %8.1f +/- %5.1f +/- %5.1f         %8.1f +/- %5.1f +/- %5.1f\n",
                   label,    ldp_val, ldp_hist_err, total_syst_err_lowdphi,   hdp_val, hdp_hist_err, total_syst_err_highdphi ) ;

               fprintf( ofp_combine, "%s      %8.1f +/- %5.1f +/- %5.1f         %8.1f +/- %5.1f +/- %5.1f\n",
                   label,    ldp_val, ldp_hist_err, total_syst_err_lowdphi,   hdp_val, hdp_hist_err, total_syst_err_highdphi ) ;

               if ( bi_htmht > 3 ) {
                  char this_label[100] ;
                  sprintf( this_label, "%3d S-Nj%d-Nb%d-MHT%d-HT%d (S%d)", bi_search, bi_nj, bi_nb-1, bi_mht-1, bi_ht, bi_htmht-3 ) ;
                  fprintf( ofp_combine_stat_syst, "   %-30s   %6.3f  %6.3f       %6.3f  %6.3f\n",
                      this_label,
                      ldp_stat_over_sqrtn, ldp_syst_over_n,   hdp_stat_over_sqrtn, hdp_syst_over_n ) ;
               } else {
                  char this_label[100] ;
                  sprintf( this_label, "%3d C-Nj%d-Nb%d-MHT%d-HT%d (C%d)", bi_control, bi_nj, bi_nb-1, bi_mht-1, bi_ht, bi_htmht ) ;
                  fprintf( ofp_combine_stat_syst, "   %-30s   %6.3f  %6.3f       %6.3f  %6.3f\n",
                      this_label,
                      ldp_stat_over_sqrtn, ldp_syst_over_n,   hdp_stat_over_sqrtn, hdp_syst_over_n ) ;
               }


            } // bi_htmht
         } // bi_nb
      } // bi_nj

      fclose( ofp_combine ) ;
      printf("\n\n Wrote %s\n\n", output_text_file ) ;

     //-----

      for ( int bi_ht=1; bi_ht<=nBinsHT; bi_ht++ ) {
         for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {

            if ( bin_edges_nj[bi_nj-1] < 2.5 ) continue; // because znuznu input file lasks NJets = 2 bin

            float nbsum_lowdphi_val(0.) ;
            float nbsum_lowdphi_err2(0.) ;

            float nbsum_highdphi_val(0.) ;
            float nbsum_highdphi_err2(0.) ;

            double total_syst_lowdphi_events[100] ;
            double total_syst_highdphi_events[100] ;
            for ( int si=0; si<n_systerr; si++ ) {
               total_syst_lowdphi_events[si]  = 0 ;
               total_syst_highdphi_events[si] = 0 ;
            }

            for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {

               bi_hist = (bi_nj-1)*(nb_nb)*(nb_htmht) + (bi_nb-1)*(nb_htmht) + bi_ht ;

               double ldp_val = h_ldp -> GetBinContent( bi_hist ) ;
               double ldp_hist_err = h_ldp -> GetBinError( bi_hist ) ;

               double hdp_val = h_hdp -> GetBinContent( bi_hist ) ;
               double hdp_hist_err = h_hdp -> GetBinError( bi_hist ) ;


               nbsum_lowdphi_val += ldp_val ;
               nbsum_highdphi_val += hdp_val ;

               nbsum_lowdphi_err2 += pow( ldp_hist_err, 2. ) ;
               nbsum_highdphi_err2 += pow( hdp_hist_err, 2. ) ;

               for ( int si=0; si<n_systerr; si++ ) {
                  ////////double syst_lowdphi = h_systerr_lowdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                  ////////double syst_highdphi = h_systerr_highdphi[si] -> GetBinContent( bi_hist ) - 1. ;
                  double syst_lowdphi = h_systerr_lowdphi[si] -> GetBinContent( bi_hist )  ;
                  double syst_highdphi = h_systerr_highdphi[si] -> GetBinContent( bi_hist ) ;
                  if ( syst_lowdphi > 0 && syst_highdphi > 0 ) {
                     total_syst_lowdphi_events[si]  += syst_lowdphi  ;
                     total_syst_highdphi_events[si] += syst_highdphi  ;
                  }
               } // si


               TString hist_bin_label( h_ldp -> GetXaxis() -> GetBinLabel( bi_hist ) ) ;

               char label[1000] ;
               sprintf( label, " %3d  Nj%d-Nb%d-MHTC-HT%d", bi_hist, bi_nj, bi_nb-1, bi_ht ) ;

       ////    printf("  label : %s   ,  hist label %s\n", label, hist_bin_label.Data() ) ;


            } // bi_nb

            double total_syst_err2_lowdphi(0.) ;
            double total_syst_err2_highdphi(0.) ;
            for ( int si=0; si<n_systerr; si++ ) {
               total_syst_err2_lowdphi += pow( total_syst_lowdphi_events[si], 2.)   ;
               total_syst_err2_highdphi += pow( total_syst_highdphi_events[si], 2.)  ;
               //printf("  %2d : %25s :   %7.1f  %7.1f\n", si, systerr_name[si], total_syst_lowdphi_events[si], total_syst_highdphi_events[si] ) ;
            }
            double total_syst_err_lowdphi = sqrt( total_syst_err2_lowdphi ) ;
            double total_syst_err_highdphi = sqrt( total_syst_err2_highdphi ) ;

            double ldp_syst_over_n(0.2) ;
            double ldp_stat_over_sqrtn(0.8) ;
            if ( nbsum_lowdphi_val > 0 ) {
               ldp_syst_over_n =  total_syst_err_lowdphi / nbsum_lowdphi_val  ;
               ldp_stat_over_sqrtn = 1. ;
            }
            double hdp_syst_over_n(0.2) ;
            double hdp_stat_over_sqrtn(0.8) ;
            if ( nbsum_highdphi_val > 0 ) {
               hdp_syst_over_n =  total_syst_err_highdphi / nbsum_highdphi_val  ;
               hdp_stat_over_sqrtn = 1. ;
            }
            printf( "   Nj%d-HT%d   %8.1f +/- %5.1f +/- %5.1f  (%6.3f)      %8.1f +/- %5.1f +/- %5.1f  (%6.3f)\n", bi_nj, bi_ht,
                  nbsum_lowdphi_val, sqrt(nbsum_lowdphi_err2), total_syst_err_lowdphi,  ldp_syst_over_n,
                  nbsum_highdphi_val, sqrt(nbsum_highdphi_err2), total_syst_err_highdphi,  hdp_syst_over_n ) ;
            fprintf( ofp_nbsum, "   Nj%d-HT%d   %8.1f +/- %5.1f +/- %5.1f    %8.1f +/- %5.1f +/- %5.1f\n", bi_nj, bi_ht,
                  nbsum_lowdphi_val, sqrt(nbsum_lowdphi_err2), total_syst_err_lowdphi,
                  nbsum_highdphi_val, sqrt(nbsum_highdphi_err2), total_syst_err_highdphi ) ;
            fprintf( ofp_nbsum_stat_syst, "   Nj%d-HT%d    %6.3f  %6.3f      %6.3f  %6.3f\n", bi_nj, bi_ht,
                   ldp_stat_over_sqrtn, ldp_syst_over_n,      hdp_stat_over_sqrtn, hdp_syst_over_n ) ;

         } // bi_nj
      } // bi_ht

      fclose( ofp_nbsum ) ;
      fclose( ofp_nbsum_stat_syst ) ;
      printf("\n\n Wrote %s\n\n", nbsum_text_file ) ;
      printf("\n\n Wrote %s\n\n", systfile_nbsum.Data() ) ;
      printf("\n\n Wrote %s\n\n", systfile_combine.Data() ) ;



   } // make_znunu_input_files1
   void create_model_ratio_hist1( const char* model_pars_file = "outputfiles/model-pars-qcdmc3.txt",
                                  const char* qcd_ratio_file = "outputfiles/qcdmc-ratio-v3.root" ) {
      setup_bins(); 
      gDirectory -> Delete( "h*" ) ;

      loadHist( qcd_ratio_file, "qcdmc" ) ;

      read_pars( model_pars_file ) ;

      TH1F* h_ratio_all = new TH1F( "h_ratio_all", "QCD model H/L ratio", nb_global_after_exclusion, 0.5, nb_global_after_exclusion + 0.5 ) ;

      TH1F* h_max_ldp_weight_search_bins = get_hist( "h_max_ldp_weight_search_bins_qcdmc" ) ;
      TH1F* h_ldp_search_bins = get_hist( "h_ldp_search_bins_qcdmc" ) ;
      TH1F* h_hdp_search_bins = get_hist( "h_hdp_search_bins_qcdmc" ) ;
      TH1F* h_ratio_qcdmc = get_hist( "h_ratio_qcdmc" ) ;

      int bi_hist_with_exclusion(0) ;

      for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {
         for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {
            for ( int bi_htmht=4; bi_htmht<=nb_htmht; bi_htmht++ ) {
               
               if ( is_this_bin_excluded(bi_nj-1, bi_nb-1, bi_htmht-1) ) continue;

	       bi_hist_with_exclusion++;  // these few lines should be changed when we update the code that produces qcdmc-ratio-v3.root

               int bi_ht, bi_mht ;
               htmht_bin_to_ht_and_mht_bins( bi_htmht, bi_ht, bi_mht ) ;

               char label[100] ;
               sprintf( label, " %3d Nj%d-Nb%d-MHT%d-HT%d (%d)", bi_hist_with_exclusion, bi_nj, bi_nb-1, bi_mht-1, bi_ht, bi_htmht-3 ) ;

               double model_ratio_val = 0;
               double model_ratio_err = 0;

                  model_ratio_val = par_val_ht[bi_ht] * par_val_njet[bi_nj] * par_val_ht_mht[bi_ht][bi_mht] * par_val_nb[bi_nb] ;
                  model_ratio_err = model_ratio_val * sqrt(
                         pow( par_err_ht_fit[bi_ht]/par_val_ht[bi_ht], 2. )
                      +  pow( par_err_ht_syst[bi_ht]/par_val_ht[bi_ht], 2. )
                      +  pow( par_err_njet_fit[bi_nj]/par_val_njet[bi_nj], 2. )
                      +  pow( par_err_njet_syst[bi_nj]/par_val_njet[bi_nj], 2. )
                      +  pow( par_err_ht_mht[bi_ht][bi_mht]/par_val_ht_mht[bi_ht][bi_mht], 2. )
                      +  pow( par_err_nb[bi_nb]/par_val_nb[bi_nb], 2. )
                    ) ;
                  printf("  %s : Nj %6.4f Nb %6.4f MHT %6.4f HT %6.4f  model ratio = %6.4f +/- %6.4f\n", label,
                    par_val_njet[bi_nj], par_val_nb[bi_nb], par_val_ht_mht[bi_ht][bi_mht], par_val_ht[bi_ht], model_ratio_val, model_ratio_err  ) ;

               h_ratio_all -> GetXaxis() -> SetBinLabel( bi_hist_with_exclusion, label ) ;

               h_ratio_all -> SetBinContent( bi_hist_with_exclusion, model_ratio_val ) ;
               h_ratio_all -> SetBinError( bi_hist_with_exclusion, model_ratio_err ) ;

            } // bi_htmht
         } // bi_nb
      } // bi_nj

      gStyle -> SetOptStat(0) ;
      gStyle -> SetPadBottomMargin(0.30) ;

      h_ratio_all -> SetMarkerStyle( 22 ) ;
      h_ratio_all -> SetMarkerColor( 2 ) ;

      h_ratio_all -> GetXaxis() -> LabelsOption("v") ;
      h_ratio_all -> Draw() ;
      gPad -> SetGridy(1) ;


     //---------------

      TH1F* h_ratio_qcdmc_minus_model = new TH1F( "h_ratio_qcdmc_minus_model", "QCD H/L ratio difference (QCD MC - model)", nb_global_after_exclusion, 0.5, nb_global_after_exclusion + 0.5 ) ;

      printf("\n\n") ;
      bi_hist_with_exclusion = 0;
      for ( int bi_nj=1; bi_nj<=nb_nj; bi_nj++ ) {
         for ( int bi_nb=1; bi_nb<=nb_nb; bi_nb++ ) {
            for ( int bi_htmht=4; bi_htmht<=nb_htmht; bi_htmht++ ) {
               if ( is_this_bin_excluded(bi_nj-1, bi_nb-1, bi_htmht-1) ) continue;
               bi_hist_with_exclusion++; // these few lines should be changed when we update the code that produces qcdmc-ratio-v3.root

	       float model_val = h_ratio_all -> GetBinContent( bi_hist_with_exclusion ) ;
               float qcdmc_val = h_ratio_qcdmc -> GetBinContent( bi_hist_with_exclusion ) ;
               float ldp_val = h_ldp_search_bins -> GetBinContent( bi_hist_with_exclusion ) ;
               float hdp_val = h_hdp_search_bins -> GetBinContent( bi_hist_with_exclusion ) ;
               float max_ldp_weight = h_max_ldp_weight_search_bins -> GetBinContent( bi_hist_with_exclusion ) ;
               char label[100] ;
               sprintf( label, "%s", h_ratio_all -> GetXaxis() -> GetBinLabel( bi_hist_with_exclusion ) ) ;
               float diff_val(0.) ;
               float diff_err(0.) ;
               printf(" debug1 : model bin label = %s , qcdmc bin label = %s\n", h_ratio_all -> GetXaxis() -> GetBinLabel( bi_hist_with_exclusion ), h_ratio_qcdmc -> GetXaxis() -> GetBinLabel( bi_hist_with_exclusion ) ) ;
               if ( hdp_val > 0 ) {
                  diff_val = qcdmc_val - model_val ;
	std::cout << qcdmc_val << " " << model_val << " " << diff_val << std::endl;
                  diff_err = diff_val ;
                  printf("  %40s : LDP %7.1f  HDP %7.1f   max LDP weight %5.3f, diff err = %5.3f\n", label, ldp_val, hdp_val, max_ldp_weight, diff_err ) ;
               } else {
                  diff_val = 0. ;
                  if ( ldp_val > 0 ) {
                     diff_err = max_ldp_weight / ldp_val ;
                     printf("  %40s : LDP %7.1f  HDP %7.1f   max LDP weight %5.3f,  zero HDP H/L err = %5.3f\n", label, ldp_val, hdp_val, max_ldp_weight, diff_err ) ;
                  } else {
                     //diff_err = 0.5 ;
                     //diff_err = 0.2;
                     diff_err = 0.0;
                     printf("  %40s : LDP %7.1f  HDP %7.1f   max LDP weight %5.3f,  *** both zero\n", label, ldp_val, hdp_val, max_ldp_weight ) ;
                  }
               }
               h_ratio_qcdmc_minus_model -> SetBinContent( bi_hist_with_exclusion, diff_val ) ;
               h_ratio_qcdmc_minus_model -> SetBinError( bi_hist_with_exclusion, diff_err ) ;
               h_ratio_qcdmc_minus_model -> GetXaxis() -> SetBinLabel( bi_hist_with_exclusion, label ) ;
            } // bi_htmht
	 }//bi_nb
      }//bi_nj

      printf("\n\n") ;

      h_ratio_qcdmc_minus_model -> GetXaxis() -> LabelsOption( "v" ) ;


      saveHist("outputfiles/model-ratio-hist1.root", "h*" ) ;

   } // create_model_ratio_hist1
Пример #11
0
void wfd_raw_time_1d(const int run_nr = 0) 
{
  int i;

  const int n_hists = 6;
  const char *h_names[n_hists] = { "WFDRawTimeR0",
				   "WFDRawTimeR1",
				   "WFDRawTimeG0",
				   "WFDRawTimeG1",
				   "WFDRawTimeB0",
				   "WFDRawTimeB1" };
  
  TH2D *h2[n_hists];

  //=========================================================
  //             *** initialize style ***
  //=========================================================

  init();

  //=========================================================
  //                  *** open canvas ***
  //=========================================================
  
  TCanvas *c1 = new TCanvas("c1","c1",0,0,800,1000);
  c1->Draw();
  c1->cd();

  c1->Divide(2,3,0.001,0.001,10);

  //=========================================================
  //          *** receive and plot histograms ***
  //=========================================================
  
  for (i=0; i<n_hists; i++) {

    h2[i] = (TH2D*) get_hist(h_names[i], run_nr);

    if ( !h2[i] ) continue;

    int ipad = i+1;

    c1->cd(ipad);

    //h2[i]->Draw("ColZ");
    TH1D *h1 = h2[i]->ProjectionX();
    h1->SetLineColor(kRed);
    h1->Draw();
    h1->SetXTitle("time counter");
    h1->SetYTitle("counts");
    //h1->SetFillColor(kYellow);
    h1->GetXaxis()->SetRangeUser(-0.5,15000.0);

    if ( h1->GetMaximum() > 1 ) {
      c1->GetPad(ipad)->SetLogy();
    }

  }
  
  c1->SaveAs("../png/wfd_raw_time_1d.png");


}