Ejemplo n.º 1
0
void VFH::loadFeatureModels (const boost::filesystem::path &base_dir, const std::string &extension, 
                   std::vector<vfh_model> &models)
{
  if (!boost::filesystem::exists (base_dir) && !boost::filesystem::is_directory (base_dir))
    return;

  for (boost::filesystem::directory_iterator it (base_dir); it != boost::filesystem::directory_iterator (); ++it)
  {
    if (boost::filesystem::is_directory (it->status ()))
    {
      std::stringstream ss;
      ss << it->path ();
      pcl::console::print_highlight ("Loading %s (%lu models loaded so far).\n", ss.str ().c_str (), (unsigned long)models.size ());
      loadFeatureModels (it->path (), extension, models);
    }
    if(boost::filesystem::is_regular_file (it->status ()))
			std::cout<<boost::filesystem::extension (it->path ())<<" "<<extension<<std::endl;
		if(boost::filesystem::extension (it->path ()) == extension)
			std::cout<<"YES"<<std::endl;
		
    if (boost::filesystem::is_regular_file (it->status ()) && boost::filesystem::extension (it->path ()) == extension)
    {
            std::cout<<"in"<<std::endl;
      vfh_model m;
      if (loadHist (base_dir / it->path ().filename (), m))
        models.push_back (m);
    }
  }
}
Ejemplo n.º 2
0
   void qcd_study1( bool fillHists=false, bool savePlots=false, bool interactive=true, const char* datfile = "null" ) {

      TLine* line = new TLine() ;

      gStyle->SetPalette(1) ;
      gStyle->SetPadBottomMargin(0.20) ;

      gDirectory->Delete("h*") ;

      int nBinsBjets = 3 ;

        //-- met3-ht3-v5
        const int nBinsMET   = 3 ;
        const int nBinsHT    = 3 ;
         // const int version = 5;
        float Mbins[nBinsMET+1] = {125, 200.,350.,99999.};
        float Hbins[nBinsHT+1] = {400, 600.,1000.,99999.};

  //  ////-- met4-ht3-v3
  //  const int nBinsMET   = 4 ;
  //  const int nBinsHT    = 3 ;
  //      const int version = 3;
  //  float Mbins[nBinsMET+1] = {125, 150.,250.,350.,99999.};
  //  float Hbins[nBinsHT+1] = {400, 600.,1000.,99999.};

      ////-- met4-ht4-v15
      //const int nBinsMET   = 4 ;
      //const int nBinsHT    = 4 ;
      //    const int version = 15;
      //float Mbins[nBinsMET+1] = {125, 150.,250.,350.,99999.};
      //float Hbins[nBinsHT+1] = {400, 500.,800.,1000.,99999.};




      TH2F* hdummy = new TH2F("hdummy","",2, Mbins[0], 1500., 2, Hbins[0], 1500. ) ;

      const int nQcdSamples(9) ;

      char inputfile[9][1000] = {
        "files15fb_8TeV/QCD-120to170.root"
       ,"files15fb_8TeV/QCD-170to300.root"
       ,"files15fb_8TeV/QCD-300to470.root"
       ,"files15fb_8TeV/QCD-470to600.root"
       ,"files15fb_8TeV/QCD-600to800.root"
       ,"files15fb_8TeV/QCD-800to1000.root"
       ,"files15fb_8TeV/QCD-1000to1400.root"
       ,"files15fb_8TeV/QCD-1400to1800.root"
       ,"files15fb_8TeV/QCD-1800.root"
      } ;

      char samplename[9][100] = {
        "qcd_0120_to_0170"
       ,"qcd_0170_to_0300"
       ,"qcd_0300_to_0470"
       ,"qcd_0470_to_0600"
       ,"qcd_0600_to_0800"
       ,"qcd_0800_to_1000"
       ,"qcd_1000_to_1400"
       ,"qcd_1400_to_1800"
       ,"qcd_1800_to_9999"
      } ;

 //   int samplecolor[9] = {
 //      kOrange+8,
 //      kRed,
 //      KMagenta+2,
 //      KBlue+1,
 //      KAzure+2,
 //      KGreen+2,
 //      kPink-2,
 //      kViolet+2,
 //      kOrange+2
 //   } ;

      int samplecolor[9] = {
         800+8,
         632,
         616+2,
         600+1,
         860+2,
         416+2,
         900-2,
         880+2,
         800+2
      } ;

      TH2F*   h0lep[nQcdSamples][nBinsBjets] ;
      TH2F*   hldp [nQcdSamples][nBinsBjets] ;

      TCanvas* cqcd = (TCanvas*) gDirectory->FindObject("cqcd") ;
      if ( cqcd == 0x0 ) {
         cqcd = new TCanvas("cqcd", "qcd study", 700, 900 ) ;
      }

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

      if ( fillHists ) {

         TChain* qcdch[nQcdSamples] ;

         printf("\n\n") ;
         for ( int si=0; si<nQcdSamples; si++ ) {

            qcdch[si] = new TChain("tree") ;
            printf(" %2d : connecting to %s\n", si, inputfile[si] ) ;
            qcdch[si] -> Add( inputfile[si] ) ;

            for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

               sprintf( hname, "h_0lep_%db_%s", bbi+1, samplename[si] ) ;
               sprintf( htitle, "QCD 0lep yield, nb=%d, %s", bbi+1, samplename[si] ) ;
               printf("         booking hist %s : %s\n", hname, htitle ) ;
               h0lep[si][bbi] = new TH2F( hname, htitle, nBinsMET, Mbins, nBinsHT, Hbins ) ;
               h0lep[si][bbi] -> Sumw2() ;
               sprintf( hname, "h_ldp_%db_%s", bbi+1, samplename[si] ) ;
               sprintf( htitle, "QCD  LDP yield, nb=%d, %s", bbi+1, samplename[si] ) ;
               printf("         booking hist %s  : %s\n", hname, htitle ) ;
               hldp [si][bbi] = new TH2F( hname, htitle, nBinsMET, Mbins, nBinsHT, Hbins ) ;
               hldp [si][bbi] -> Sumw2() ;

            } // bbi.

         } // si.
         printf("\n\n") ;





         char basecuts[10000] ;
         sprintf( basecuts, "pt_1st_leadJet>50&&pt_2nd_leadJet>50&&pt_3rd_leadJet>50&&HT>400&&MET>125&&nMu==0&&nEl==0&&nB>=1&&nJets>=3" ) ;

         char bcut[3][100] = { "nB==1", "nB==2", "nB>=3" } ;


         for ( int si=0; si<nQcdSamples; si++ ) {

            printf(" %2d : %s : 0lep\n", si, samplename[si] ) ; cout << flush ;
            for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

               char arg1[1000] ;

               char cuts0lep[10000] ;
               sprintf( cuts0lep, "(%s)&&(minDelPhiN>4&&%s)", basecuts, bcut[bbi] ) ;
               printf("     %db, 0lep cuts : %s\n", bbi+1, cuts0lep ) ;
               sprintf( arg1, "HT:MET>>h_0lep_%db_%s", bbi+1, samplename[si] ) ;
               qcdch[si] -> Draw( arg1, cuts0lep ) ;
               hdummy->Draw() ;
               h0lep[si][bbi]->Draw("samecolz") ;
               cqcd->Update() ; cqcd->Draw() ;


               char cutsldp[10000] ;
               sprintf( cutsldp, "(%s)&&(minDelPhiN<=4&&%s)", basecuts, bcut[bbi] ) ;
               printf("     %db, ldp  cuts : %s\n", bbi+1, cutsldp  ) ;
               sprintf( arg1, "HT:MET>>h_ldp_%db_%s", bbi+1, samplename[si] ) ;
               qcdch[si] -> Draw( arg1, cutsldp, "colz" ) ;
               hdummy->Draw() ;
               hldp[si][bbi]->Draw("samecolz") ;
               cqcd->Update() ; cqcd->Draw() ;

            } // bbi.

         } // si.

         saveHist( "rootfiles/qcd-study1.root", "h*" ) ;

      }

      //--------

      gStyle->SetOptStat(0) ;

      gDirectory->Delete("h*") ;
      loadHist( "rootfiles/qcd-study1.root" ) ;

      for ( int si=0; si<nQcdSamples; si++ ) {
         for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

            sprintf( hname, "h_0lep_%db_%s", bbi+1, samplename[si] ) ;
            printf("  loading %s\n", hname ) ;
            h0lep[si][bbi] = (TH2F*) gDirectory->FindObject( hname ) ;
            if ( h0lep[si][bbi] == 0x0 ) { printf("\n\n *** %s missing.\n\n", hname ) ; return ; }
            sprintf( hname, "h_ldp_%db_%s", bbi+1, samplename[si] ) ;
            printf("  loading %s\n", hname ) ;
            hldp [si][bbi] = (TH2F*) gDirectory->FindObject( hname ) ;
            if ( hldp [si][bbi] == 0x0 ) { printf("\n\n *** %s missing.\n\n", hname ) ; return ; }

         } // bbi.
      } // si.






     //--- Flatten 2D histos and compute 0lep/LDP ratios for each sample.

      int nbins = nBinsMET*(nBinsHT+1) + 1 ;

      TH1F* hflat_0lep[nQcdSamples][nBinsBjets] ;
      TH1F* hflat_ldp [nQcdSamples][nBinsBjets] ;
      TH1F* hflat_0lepldp_ratio[nQcdSamples][nBinsBjets] ;

      sprintf( hname, "hflat_0lep_all" ) ;
      sprintf( htitle, "All QCD 0lep events" ) ;
      TH1F* hflat_0lep_all = bookHist( hname, htitle, nBinsMET, nBinsHT, 5 ) ;
      sprintf( hname, "hflat_ldp_all" ) ;
      sprintf( htitle, "All QCD ldp events" ) ;
      TH1F* hflat_ldp_all = bookHist( hname, htitle, nBinsMET, nBinsHT, 5 ) ;


      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {
         for ( int si=0; si<nQcdSamples; si++ ) {

            sprintf( hname, "hflat_0lep_%db_%s", bbi+1, samplename[si] ) ;
            sprintf( htitle, "QCD 0lep events, nb=%d, %s", bbi+1, samplename[si] ) ;
            hflat_0lep[si][bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, si ) ;
            hflat_0lep[si][bbi]->SetFillColor(11) ;
            hldp[si][bbi]->Print("all") ;

            sprintf( hname, "hflat_ldp_%db_%s", bbi+1, samplename[si] ) ;
            sprintf( htitle, "QCD LDP events, nb=%d, %s", bbi+1, samplename[si] ) ;
            hflat_ldp[si][bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, si ) ;
            hflat_ldp[si][bbi]->SetFillColor(11) ;

            sprintf( hname, "hflat_0lepldp_ratio_%db_%s", bbi+1, samplename[si] ) ;
            sprintf( htitle, "QCD 0lep/LDP ratio, nb=%d, %s", bbi+1, samplename[si] ) ;
            hflat_0lepldp_ratio[si][bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, si ) ;

            for ( int mbi=0; mbi<nBinsMET; mbi++ ) {
               for ( int hbi=0; hbi<nBinsHT; hbi++ ) {

                  int histbin = 1 + (nBinsHT+1)*mbi + hbi + 1 ;

                  float n0lep     = h0lep[si][bbi] -> GetBinContent( mbi+1, hbi+1 ) ;
                  float n0lep_err = h0lep[si][bbi] -> GetBinError( mbi+1, hbi+1 ) ;

                  float nldp      = hldp [si][bbi] -> GetBinContent( mbi+1, hbi+1 ) ;
                  float nldp_err  = hldp [si][bbi] -> GetBinError( mbi+1, hbi+1 ) ;

                  hflat_0lep[si][bbi] -> SetBinContent( histbin, n0lep ) ;
                  hflat_0lep[si][bbi] -> SetBinError( histbin, n0lep_err ) ;

                  hflat_ldp[si][bbi]  -> SetBinContent( histbin, nldp ) ;
                  hflat_ldp[si][bbi]  -> SetBinError( histbin, nldp_err ) ;

                  double ratio(0.) ;
                  if ( nldp > 0 ) { ratio = n0lep / nldp ; }
                  double ratio_err(0.) ;
                  if ( n0lep_err > 0. && nldp_err > 0. ) {
                     ratio_err = ratio * sqrt( pow(n0lep_err/n0lep,2) + pow(nldp_err/nldp,2) ) ;
                  }

                  hflat_0lepldp_ratio[si][bbi] -> SetBinContent( histbin, ratio ) ;
                  hflat_0lepldp_ratio[si][bbi] -> SetBinError( histbin, ratio_err ) ;


               } // hbi.
            } // mbi.

            hflat_0lep_all -> Add( hflat_0lep[si][bbi] ) ;
            hflat_ldp_all  -> Add( hflat_ldp [si][bbi] ) ;

            cqcd->Clear() ;
            cqcd->Divide(1,3) ;

            cqcd->cd(1) ;
            hflat_0lep[si][bbi] -> DrawCopy("histe") ;
            hflat_0lep[si][bbi] -> DrawCopy("samee") ;

            cqcd->cd(2) ;
            hflat_ldp[si][bbi] -> DrawCopy("histe") ;
            hflat_ldp[si][bbi] -> DrawCopy("samee") ;

            cqcd->cd(3) ;
            hflat_0lepldp_ratio[si][bbi]->SetMinimum(-0.1) ;
            hflat_0lepldp_ratio[si][bbi]->SetMaximum(0.6) ;
            hflat_0lepldp_ratio[si][bbi]->SetMarkerStyle(20) ;
            hflat_0lepldp_ratio[si][bbi]->SetLineWidth(2) ;
            hflat_0lepldp_ratio[si][bbi]->DrawCopy() ;
            gPad->SetGridx(1) ;
            gPad->SetGridy(1) ;
            line->DrawLine(0.5,0,nbins+0.5,0) ;


            cqcd->Update() ; cqcd->Draw() ;

         } // si.
      } // bbi.

      TH1F* hflat_0lep_all_sqrtNerrs = (TH1F*) hflat_0lep_all->Clone("hflat_0lep_all_sqrtNerrs") ;
      TH1F* hflat_ldp_all_sqrtNerrs  = (TH1F*) hflat_ldp_all ->Clone("hflat_ldp_all_sqrtNerrs") ;

      for ( int bi=1; bi<=nbins; bi++ ) {
         double val ;
         val = hflat_0lep_all_sqrtNerrs->GetBinContent( bi ) ;
         hflat_0lep_all_sqrtNerrs -> SetBinError( bi, sqrt(val) ) ;
         val = hflat_ldp_all_sqrtNerrs->GetBinContent( bi ) ;
         hflat_ldp_all_sqrtNerrs -> SetBinError( bi, sqrt(val) ) ;
      }












     //--- Compute sample average of 0lep/LDP ratio


      TH1F* hflat_0lepldp_ratio_ave[nBinsBjets] ;

      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

         sprintf( hname, "hflat_0lepldp_ratio_ave_%db", bbi+1 ) ;
         sprintf( htitle, "QCD 0lep/LDP average ratio, nb=%d", bbi+1 ) ;
         hflat_0lepldp_ratio_ave[bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, 5 ) ;

         hflat_0lepldp_ratio_ave[bbi] -> SetMarkerStyle(24) ;
         hflat_0lepldp_ratio_ave[bbi] -> SetMarkerSize(2.0) ;
         hflat_0lepldp_ratio_ave[bbi] -> SetLineWidth(3) ;

         for ( int binind=1; binind<=nbins; binind++ ) {

            double wvsum(0.) ;
            double wsum(0.) ;

            for ( int si=0; si<nQcdSamples; si++ ) {

               double val = hflat_0lepldp_ratio[si][bbi] -> GetBinContent( binind ) ;
               double err = hflat_0lepldp_ratio[si][bbi] -> GetBinError( binind ) ;
               if ( err > 0 ) {
                  double weight = 1./(err*err) ;
                  wvsum += val*weight ;
                  wsum  += weight ;
               }
            } // si.

            if ( wsum > 0. ) {
               hflat_0lepldp_ratio_ave[bbi] -> SetBinContent( binind, wvsum/wsum ) ;
               hflat_0lepldp_ratio_ave[bbi] -> SetBinError( binind, 1./sqrt(wsum) ) ;
            }

         } // binind

      } // bbi.








     //--- Compute RMS spread of samples and total uncertainty


      TH1F* hflat_0lepldp_ratio_ave_withRMSerror[nBinsBjets] ;

      printf("\n\n") ;
      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

         sprintf( hname, "hflat_0lepldp_ratio_ave_%db_withRMSerror", bbi+1 ) ;
         sprintf( htitle, "QCD 0lep/LDP average ratio, RMS included in error, nb=%d", bbi+1 ) ;
         hflat_0lepldp_ratio_ave_withRMSerror[bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, 5 ) ;

         hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetMarkerStyle(24) ;
         hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetMarkerSize(2.0) ;
         hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetLineWidth(3) ;

         for ( int binind=1; binind<=nbins; binind++ ) {

            double sumsquare(0.) ;
            int    nsum(0) ;

            double ave     = hflat_0lepldp_ratio_ave[bbi] -> GetBinContent( binind ) ;
            double ave_err = hflat_0lepldp_ratio_ave[bbi] -> GetBinError( binind ) ;

            for ( int si=0; si<nQcdSamples; si++ ) {

               double val = hflat_0lepldp_ratio[si][bbi] -> GetBinContent( binind ) ;
               double err = hflat_0lepldp_ratio[si][bbi] -> GetBinError( binind ) ;

               if ( err <= 0 ) { continue ; }
               if ( val <= 0 ) { continue ; }
               if ( err/val > 0.5 ) { continue ; } //-- do not include points with very large errors.


               double diff = val - ave ;

               sumsquare += diff*diff ;

               nsum ++ ;

            } // si.

            if ( nsum > 1 ) {
               double rms = sqrt(sumsquare/nsum) ;
               double totalerr = sqrt( ave_err*ave_err + rms*rms ) ;
               const char* binlabel = hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> GetXaxis() -> GetBinLabel( binind ) ;
               printf(" %s : %s : ratio = %5.3f, stat err = %5.3f, RMS = %5.3f,  total err = %5.3f\n",
                   hname, binlabel, ave, ave_err, rms, totalerr ) ;
               hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetBinContent( binind, ave ) ;
               hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetBinError( binind, totalerr ) ;
            } else {
               hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetBinContent( binind, ave ) ;
               hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetBinError( binind, ave_err ) ;
            }

         } // binind
         printf("\n") ;

      } // bbi.
      printf("\n\n") ;






     //--- compute global average 0lep/LDP ratio.

      double all0lep(0.) ;
      double allldp(0.) ;

      printf("\n\n") ;
      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {
         for ( int si=0; si<nQcdSamples; si++ ) {

            double sample_all0lep = h0lep[si][bbi] -> Integral() ;
            double sample_allldp  = hldp [si][bbi] -> Integral() ;
            double sample_ratio(0.) ;
            if ( sample_allldp > 0 ) { sample_ratio = sample_all0lep / sample_allldp ; }

            printf( "%s, nb=%d : 0lep = %8.1f,  LDP = %8.1f, ratio = %5.3f\n", samplename[si], bbi+1, sample_all0lep, sample_allldp, sample_ratio ) ;

            all0lep += sample_all0lep ;
            allldp += sample_allldp ;

         } // si.
         printf("\n") ;
      } // bbi.
      printf("\n\n") ;

      double global_0lepldp_ratio(0.) ;
      if ( allldp > 0.) {
         global_0lepldp_ratio = all0lep / allldp ;
      } else {
         printf("\n\n *** You screwed up.\n\n") ; return ;
      }
      printf("  overall : 0lep = %9.1f,  LDP = %9.1f, ratio = %5.3f\n", all0lep, allldp, global_0lepldp_ratio ) ;










     //--- Compute scale factors.  SF_i = (0lep/LDP)_i / global_(0lep/LDP)

      TH1F* hflat_scale_factor[nBinsBjets] ;
      TH1F* hflat_scale_factor_withRMSerror[nBinsBjets] ;

      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

         sprintf( hname, "hflat_scale_factor_%db", bbi+1 ) ;
         sprintf( htitle, "QCD scale factor, nb=%d", bbi+1 ) ;
         hflat_scale_factor[bbi] = (TH1F*) hflat_0lepldp_ratio_ave[bbi]->Clone( hname ) ;
         hflat_scale_factor[bbi] -> SetTitle( htitle ) ;
         hflat_scale_factor[bbi] -> Scale( 1./ global_0lepldp_ratio ) ;

         sprintf( hname, "hflat_scale_factor_%db_withRMSerror", bbi+1 ) ;
         sprintf( htitle, "QCD scale factor, nb=%d, RMS error included ", bbi+1 ) ;
         hflat_scale_factor_withRMSerror[bbi] = (TH1F*) hflat_0lepldp_ratio_ave_withRMSerror[bbi]->Clone( hname ) ;
         hflat_scale_factor_withRMSerror[bbi] -> SetTitle( htitle ) ;
         hflat_scale_factor_withRMSerror[bbi] -> Scale( 1./ global_0lepldp_ratio ) ;

      } // bbi.









     //--- set Scale Factor values in dat file if one is provided.

      if ( strcmp( datfile, "null" ) != 0 ) {

         printf("\n\n\n Setting QCD scale factors in %s\n\n", datfile ) ;

         for ( int mbi=0; mbi<nBinsMET; mbi++ ) {
            for ( int hbi=0; hbi<nBinsHT; hbi++ ) {
               for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {
                  char parname[1000] ;
                  int histbin = 1 + (nBinsHT+1)*mbi + hbi + 1 ;
                  double val = hflat_scale_factor_withRMSerror[bbi]->GetBinContent( histbin ) ;
                  double err = hflat_scale_factor_withRMSerror[bbi]->GetBinError( histbin ) ;
                  if ( err <= 0 ) {
                     val = 1.0 ;
                     err = 3.0 ;
                  }
                  sprintf( parname, "sf_qcd_M%d_H%d_%db", mbi+1, hbi+1, bbi+1 ) ;
                  updateFileValue( datfile, parname, val ) ;
                  sprintf( parname, "sf_qcd_M%d_H%d_%db_err", mbi+1, hbi+1, bbi+1 ) ;
                  updateFileValue( datfile, parname, err ) ;
               } // bbi.
            } // hbi.
         } // mbi.

      }







     //===========  End calculations.  Plots and other output below here.  ===================================


     //--- Plot all samples together

      TCanvas* cqcd2 = (TCanvas*) gDirectory->FindObject("cqcd2") ;
      if ( cqcd2 == 0x0 ) {
         cqcd2 = new TCanvas("cqcd2", "qcd study", 1700, 600 ) ;
      }

      TLegend* l2 = new TLegend( 0.79, 0.70,  0.99, 0.99 ) ;
      l2->AddEntry( hflat_0lepldp_ratio[0][0], "120 to 170" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[1][0], "170 to 300" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[2][0], "300 to 470" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[3][0], "470 to 600" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[4][0], "600 to 800" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[5][0], "800 to 1000" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[6][0], "1000 to 1400" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[7][0], "1400 to 1800" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[8][0], "> 1800" ) ;
      l2->AddEntry( hflat_0lepldp_ratio_ave[0], "Average ratio" ) ;


      cqcd2 -> Clear() ;
      cqcd2 -> Divide(3,1) ;

      cqcd2 -> cd(1) ;
      hflat_0lepldp_ratio[0][0] -> SetTitle("QCD 0lep/LDP ratio, nb=1") ;
      for ( int si=0; si<nQcdSamples; si++ ) {
         hflat_0lepldp_ratio[si][0] -> SetMarkerStyle(20+si) ;
         hflat_0lepldp_ratio[si][0] -> SetLineColor(samplecolor[si]) ;
         hflat_0lepldp_ratio[si][0] -> SetMarkerColor(samplecolor[si]) ;
         if ( si == 0 ) { hflat_0lepldp_ratio[si][0] -> DrawCopy() ; } else { hflat_0lepldp_ratio[si][0] -> DrawCopy("same") ; }
      }
      hflat_0lepldp_ratio_ave[0]->DrawCopy("same") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      l2->Draw() ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd2 -> cd(2) ;
      hflat_0lepldp_ratio[0][1] -> SetTitle("QCD 0lep/LDP ratio, nb=2") ;
      for ( int si=0; si<nQcdSamples; si++ ) {
         hflat_0lepldp_ratio[si][1] -> SetMarkerStyle(20+si) ;
         hflat_0lepldp_ratio[si][1] -> SetLineColor(samplecolor[si]) ;
         hflat_0lepldp_ratio[si][1] -> SetMarkerColor(samplecolor[si]) ;
         if ( si == 0 ) { hflat_0lepldp_ratio[si][1] -> DrawCopy() ; } else { hflat_0lepldp_ratio[si][1] -> DrawCopy("same") ; }
      }
      hflat_0lepldp_ratio_ave[1]->DrawCopy("same") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      l2->Draw() ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd2 -> cd(3) ;
      hflat_0lepldp_ratio[0][2] -> SetTitle("QCD 0lep/LDP ratio, nb>=3") ;
      for ( int si=0; si<nQcdSamples; si++ ) {
         hflat_0lepldp_ratio[si][2] -> SetMarkerStyle(20+si) ;
         hflat_0lepldp_ratio[si][2] -> SetLineColor(samplecolor[si]) ;
         hflat_0lepldp_ratio[si][2] -> SetMarkerColor(samplecolor[si]) ;
         if ( si == 0 ) { hflat_0lepldp_ratio[si][2] -> DrawCopy() ; } else { hflat_0lepldp_ratio[si][2] -> DrawCopy("same") ; }
      }
      hflat_0lepldp_ratio_ave[2]->DrawCopy("same") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      l2->Draw() ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;


      cqcd2->Update() ; cqcd2->Draw() ;

      if ( savePlots ) {
         cqcd2 -> SaveAs("outputfiles/qcd-study1-allonone.png") ;
         cqcd2 -> SaveAs("outputfiles/qcd-study1-allonone.pdf") ;
      }








     //--- Go through the samples, 1 by 1, and draw numerator, denominator, and ratio

      TCanvas* cqcd3 = (TCanvas*) gDirectory->FindObject("cqcd3") ;
      if ( cqcd3 == 0x0 ) {
         cqcd3 = new TCanvas("cqcd3", "qcd study", 1200, 900 ) ;
      }

      char oldtitle[1000] ;
      sprintf( oldtitle, "QCD 0lep/LDP ratio, nb=1, %s", samplename[0] ) ;
      hflat_0lepldp_ratio[0][0] -> SetTitle(oldtitle) ;
      sprintf( oldtitle, "QCD 0lep/LDP ratio, nb=2, %s", samplename[0] ) ;
      hflat_0lepldp_ratio[0][1] -> SetTitle(oldtitle) ;
      sprintf( oldtitle, "QCD 0lep/LDP ratio, nb>=3, %s", samplename[0] ) ;
      hflat_0lepldp_ratio[0][2] -> SetTitle(oldtitle) ;

      cqcd3->Clear() ;
      cqcd3->Divide(3,3) ;

      for ( int si=0; si<nQcdSamples; si++ ) {
         TLegend* l3 = new TLegend( 0.65, 0.78, 0.99, 0.92) ;
         l3->AddEntry( hflat_0lepldp_ratio[si][0], samplename[si] ) ;
         l3->AddEntry( hflat_0lepldp_ratio_ave[0], "Average") ;
         for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

            cqcd3->cd(1+bbi) ;
            hflat_0lep[si][bbi] -> DrawCopy("histe") ;
            hflat_0lep[si][bbi] -> DrawCopy("samee") ;

            cqcd3->cd(4+bbi) ;
            hflat_ldp[si][bbi] -> DrawCopy("histe") ;
            hflat_ldp[si][bbi] -> DrawCopy("samee") ;


            cqcd3->cd(7+bbi) ;
            gPad->SetGridx(1) ;
            gPad->SetGridy(1) ;
            hflat_0lepldp_ratio[si][bbi]->DrawCopy() ;
            hflat_0lepldp_ratio_ave[bbi]->DrawCopy("same") ;
            line->DrawLine(0.5,0,nbins+0.5,0) ;
            l3->Draw() ;

         } // bbi.

         cqcd3->Update() ; cqcd3->Draw() ;

         if ( savePlots ) {
            char filename[1000] ;
            sprintf( filename, "outputfiles/qcd-study1-%s.pdf", samplename[si] ) ;
            cqcd3 -> SaveAs( filename ) ;
            sprintf( filename, "outputfiles/qcd-study1-%s.png", samplename[si] ) ;
            cqcd3 -> SaveAs( filename ) ;
         }
         if ( interactive ) {
            char a = getchar() ;
            if ( a == 'q') { return ; }
         }

      } // si.







     //--- Draw the average 0lep/LDP ratio with MC stat error and total error.

      TCanvas* cqcd4 = (TCanvas*) gDirectory->FindObject("cqcd4") ;
      if ( cqcd4 == 0x0 ) {
         cqcd4 = new TCanvas("cqcd4", "qcd study", 1700, 600 ) ;
      }

      gStyle->SetEndErrorSize(5) ;

      cqcd4->Clear() ;
      cqcd4->Divide(3,1) ;

      cqcd4 -> cd(1) ;
      hflat_0lepldp_ratio_ave[0] -> SetTitle("Average QCD 0lep/LDP ratio, nb=1") ;
      hflat_0lepldp_ratio_ave[0] -> SetMarkerSize(1.2) ;
      hflat_0lepldp_ratio_ave[0] -> SetMarkerStyle(20) ;
      hflat_0lepldp_ratio_ave[0] -> SetMaximum(0.6) ;
      hflat_0lepldp_ratio_ave[0] -> SetMinimum(-0.1) ;
      hflat_0lepldp_ratio_ave[0]->DrawCopy("e1") ;
      hflat_0lepldp_ratio_ave_withRMSerror[0]->SetMarkerStyle() ;
      hflat_0lepldp_ratio_ave_withRMSerror[0]->SetLineColor(4) ;
      hflat_0lepldp_ratio_ave_withRMSerror[0]->DrawCopy("samee1") ;
      hflat_0lepldp_ratio_ave[0]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd4 -> cd(2) ;
      hflat_0lepldp_ratio_ave[1] -> SetTitle("Average QCD 0lep/LDP ratio, nb=2") ;
      hflat_0lepldp_ratio_ave[1] -> SetMarkerSize(1.2) ;
      hflat_0lepldp_ratio_ave[1] -> SetMarkerStyle(20) ;
      hflat_0lepldp_ratio_ave[1] -> SetMaximum(0.6) ;
      hflat_0lepldp_ratio_ave[1] -> SetMinimum(-0.1) ;
      hflat_0lepldp_ratio_ave[1]->DrawCopy("e1") ;
      hflat_0lepldp_ratio_ave_withRMSerror[1]->SetMarkerStyle() ;
      hflat_0lepldp_ratio_ave_withRMSerror[1]->SetLineColor(4) ;
      hflat_0lepldp_ratio_ave_withRMSerror[1]->DrawCopy("samee1") ;
      hflat_0lepldp_ratio_ave[1]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd4 -> cd(3) ;
      hflat_0lepldp_ratio_ave[2] -> SetTitle("Average QCD 0lep/LDP ratio, nb>=3") ;
      hflat_0lepldp_ratio_ave[2] -> SetMarkerSize(1.2) ;
      hflat_0lepldp_ratio_ave[2] -> SetMarkerStyle(20) ;
      hflat_0lepldp_ratio_ave[2] -> SetMaximum(0.6) ;
      hflat_0lepldp_ratio_ave[2] -> SetMinimum(-0.1) ;
      hflat_0lepldp_ratio_ave[2]->DrawCopy("e1") ;
      hflat_0lepldp_ratio_ave_withRMSerror[2]->SetMarkerStyle() ;
      hflat_0lepldp_ratio_ave_withRMSerror[2]->SetLineColor(4) ;
      hflat_0lepldp_ratio_ave_withRMSerror[2]->DrawCopy("samee1") ;
      hflat_0lepldp_ratio_ave[2]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;


      cqcd4->Update() ; cqcd4->Draw() ;

      if ( savePlots ) {
         cqcd4 -> SaveAs("outputfiles/qcd-study1-averatio.png") ;
         cqcd4 -> SaveAs("outputfiles/qcd-study1-averatio.pdf") ;
      }












     //--- Draw the QCD scale factor with MC stat error and total error.

      TCanvas* cqcd5 = (TCanvas*) gDirectory->FindObject("cqcd5") ;
      if ( cqcd5 == 0x0 ) {
         cqcd5 = new TCanvas("cqcd5", "qcd study", 1700, 600 ) ;
      }

      gStyle->SetEndErrorSize(5) ;

      cqcd5->Clear() ;
      cqcd5->Divide(3,1) ;

      cqcd5 -> cd(1) ;
      hflat_scale_factor[0] -> SetTitle("QCD Scale Factor, nb=1") ;
      hflat_scale_factor[0] -> SetMarkerSize(1.2) ;
      hflat_scale_factor[0] -> SetMarkerStyle(20) ;
      hflat_scale_factor[0] -> SetMaximum(2.6) ;
      hflat_scale_factor[0] -> SetMinimum(-0.1) ;
      hflat_scale_factor[0]->DrawCopy("e1") ;
      hflat_scale_factor_withRMSerror[0]->SetMarkerStyle() ;
      hflat_scale_factor_withRMSerror[0]->SetLineColor(4) ;
      hflat_scale_factor_withRMSerror[0]->DrawCopy("samee1") ;
      hflat_scale_factor[0]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd5 -> cd(2) ;
      hflat_scale_factor[1] -> SetTitle("QCD Scale Factor, nb=2") ;
      hflat_scale_factor[1] -> SetMarkerSize(1.2) ;
      hflat_scale_factor[1] -> SetMarkerStyle(20) ;
      hflat_scale_factor[1] -> SetMaximum(2.6) ;
      hflat_scale_factor[1] -> SetMinimum(-0.1) ;
      hflat_scale_factor[1]->DrawCopy("e1") ;
      hflat_scale_factor_withRMSerror[1]->SetMarkerStyle() ;
      hflat_scale_factor_withRMSerror[1]->SetLineColor(4) ;
      hflat_scale_factor_withRMSerror[1]->DrawCopy("samee1") ;
      hflat_scale_factor[1]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd5 -> cd(3) ;
      hflat_scale_factor[2] -> SetTitle("QCD Scale Factor, nb>=3") ;
      hflat_scale_factor[2] -> SetMarkerSize(1.2) ;
      hflat_scale_factor[2] -> SetMarkerStyle(20) ;
      hflat_scale_factor[2] -> SetMaximum(2.6) ;
      hflat_scale_factor[2] -> SetMinimum(-0.1) ;
      hflat_scale_factor[2]->DrawCopy("e1") ;
      hflat_scale_factor_withRMSerror[2]->SetMarkerStyle() ;
      hflat_scale_factor_withRMSerror[2]->SetLineColor(4) ;
      hflat_scale_factor_withRMSerror[2]->DrawCopy("samee1") ;
      hflat_scale_factor[2]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;


      cqcd5->Update() ; cqcd5->Draw() ;

      if ( savePlots ) {
         cqcd5 -> SaveAs("outputfiles/qcd-study1-scalefactor.png") ;
         cqcd5 -> SaveAs("outputfiles/qcd-study1-scalefactor.pdf") ;
      }







   } // qcd_study.
Ejemplo n.º 3
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
Ejemplo n.º 4
0
void draw_analysis_mht_plots3( const char* infile = "outputfiles/analysis-output3-default.root", bool with_numbers = true, const char* save_file_base = "plot-dtt-analysis3" ) {

    gDirectory -> Delete( "h*" ) ;

    gStyle -> SetOptStat(0) ;

    loadHist( infile ) ;

    int wx(50), wy(50) ;





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

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

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

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

        int ci(1) ;

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

                can -> cd( ci++ ) ;

                char hname[100] ;

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

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

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

            } // nji
        } // hti


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

    } // nbi.




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


    {   // sum over Nb

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

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

        int ci(1) ;

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

                can -> cd( ci++ ) ;

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

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

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

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

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

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

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

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

                } // nbi.

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

            } // nji
        } // hti


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

    } // sum over Nb






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

    {   // HT bins canvas

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

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

        int ci(1) ;

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

            can -> cd( ci++ ) ;

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

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

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

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

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

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

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

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

                } // nbi
            } // nji

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

        } // hti

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

    } // HT bins canvas



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

    {   // Njet bins canvas

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

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

        int ci(1) ;

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

            can -> cd( ci++ ) ;

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

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

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

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

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

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

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

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

                } // nbi
            } // hti

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

        } // hti

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

    } // Njet bins canvas


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

    {   // Nb bins canvas

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

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

        int ci(1) ;

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

            can -> cd( ci++ ) ;

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

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

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

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

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

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

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

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

                } // nji
            } // hti

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

        } // hti

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

    } // Nb bins canvas





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

    {   // sum over all

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

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

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

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

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

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

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

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

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

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

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

                } // nji
            } // hti

        } // nbi

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

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

    } // sum over all


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

    {

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

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

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

        int ci(1) ;

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

            can -> cd(ci++ ) ;

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

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

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

        } // sbi


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

    } // superbins for mht2, ht12


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

    {

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

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

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

        int ci(1) ;

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

            can -> cd(ci++ ) ;

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

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

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

        } // sbi


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

    } // superbins for mht2, ht3



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

    {

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

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

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

        int ci(1) ;

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

            can -> cd(ci++ ) ;

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

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

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

        } // sbi


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

    } // superbins for mht3


} // draw_analysis_mht_plots3
Ejemplo n.º 5
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
Ejemplo n.º 6
0
   void draw_syst_hists( const char* inwsfile, const char* syst_name, int sig_mass = 0, float max_msig_evts = 8., float max_msb_evts = 16. ) {

      gStyle -> SetOptStat(0) ;
      gStyle -> SetPadLeftMargin(0.15) ;
      gStyle -> SetTitleW( 0.9 ) ;


      gDirectory -> Delete( "h*" ) ;

      loadHist( inwsfile ) ;

      TLine* line = new TLine() ;
      line -> SetLineStyle(2) ;

     //----

      gSystem -> Exec( "mkdir -p outputfiles/syst-plots" ) ;

      TString infile_ts( inwsfile ) ;
      TObjArray* tokens = infile_ts.Tokenize("/") ;

      TObjString* tos = (TObjString*) (tokens -> At( tokens->GetEntries() - 1 ) ) ;
      TString fname( tos->GetString() ) ;
      printf( "ws file name : %s\n", fname.Data() ) ;

      TString pdfbasename = fname.ReplaceAll(".root","") ;
      printf(" pdf base name : %s\n", pdfbasename.Data() ) ;


      char sigsb_str[2][10] = { "msig", "msb" } ;

      for ( int ssbi=0; ssbi<2; ssbi++ ) {

         char cname[100] ;

         sprintf( cname, "can_evts_%s", sigsb_str[ssbi] ) ;
         TCanvas* can_evts = (TCanvas*) gDirectory -> FindObject( cname ) ;
         if ( can_evts == 0x0 ) {
            if ( ssbi == 0 ) {
               can_evts = new TCanvas( cname, "SIG observables", 1100, 300 ) ;
            } else {
               can_evts = new TCanvas( cname, "SB observables", 1100, 300 ) ;
            }
         }

         sprintf( cname, "can_frac_%s", sigsb_str[ssbi] ) ;
         TCanvas* can_frac = (TCanvas*) gDirectory -> FindObject( cname ) ;
         if ( can_frac == 0x0 ) {
            if ( ssbi == 0 ) {
               can_frac = new TCanvas( cname, "SIG observables, syst (%)", 1100, 300 ) ;
            } else {
               can_frac = new TCanvas( cname, "SB observables, syst (%)", 1100, 300 ) ;
            }
         }


         can_evts -> Clear() ;
         can_evts -> Divide(4,1) ;

         can_frac -> Clear() ;
         can_frac -> Divide(4,1) ;

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


            char hname[1000] ;
            char hnamev[1000] ;
            char hnamenf[1000] ;

            sprintf( hname, "h_syst_%s_%s_met%d_nom", syst_name, sigsb_str[ssbi], ci ) ;
            TH1F* hist_nom = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hist_nom == 0x0 ) { printf("\n\n *** Can't find %s\n\n", hname ) ; return ; }
            sprintf( hnamenf, "%s_nf", hname ) ;
            TH1F* hist_nom_nf = (TH1F*) hist_nom -> Clone( hnamenf ) ;

            sprintf( hname, "h_syst_%s_%s_met%d_m1s", syst_name, sigsb_str[ssbi], ci ) ;
            TH1F* hist_m1s = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hist_m1s == 0x0 ) { printf("\n\n *** Can't find %s\n\n", hname ) ; return ; }
            sprintf( hnamev, "%s_var", hname ) ;
            TH1F* hist_m1s_var = (TH1F*) hist_m1s -> Clone( hnamev ) ;

            sprintf( hname, "h_syst_%s_%s_met%d_p1s", syst_name, sigsb_str[ssbi], ci ) ;
            TH1F* hist_p1s = (TH1F*) gDirectory -> FindObject( hname ) ;
            if ( hist_p1s == 0x0 ) { printf("\n\n *** Can't find %s\n\n", hname ) ; return ; }
            sprintf( hnamev, "%s_var", hname ) ;
            TH1F* hist_p1s_var = (TH1F*) hist_p1s -> Clone( hnamev ) ;

            TString htitle ;

            htitle = hist_nom -> GetTitle() ;
            if ( sig_mass > 0 ) {
               char sigmassstr[1000] ;
               sprintf( sigmassstr, ", higgsino mass = %d", sig_mass ) ;
               htitle.ReplaceAll( ", nominal", sigmassstr ) ;
            } else {
               htitle.ReplaceAll( ", nominal", "" ) ;
            }
            hist_nom -> SetTitle( htitle ) ;

            htitle = hist_m1s_var -> GetTitle() ;
            if ( sig_mass > 0 ) {
               char sigmassstr[1000] ;
               sprintf( sigmassstr, ", higgsino mass = %d", sig_mass ) ;
               htitle.ReplaceAll( ", -1 sigma", sigmassstr ) ;
            } else {
               htitle.ReplaceAll( ", -1 sigma", "" ) ;
            }
            hist_m1s_var -> SetTitle( htitle ) ;



            hist_nom -> SetLineWidth( 2 ) ;
            hist_nom_nf -> SetLineWidth( 2 ) ;
            hist_m1s -> SetLineWidth( 2 ) ;
            hist_p1s -> SetLineWidth( 2 ) ;

        //  hist_m1s -> SetLineColor( 4 ) ;
        //  hist_p1s -> SetLineColor( 2 ) ;

            hist_m1s -> SetLineColor( 2 ) ;
            hist_p1s -> SetLineColor( 4 ) ;

            hist_nom -> SetFillColor( 18 ) ;


            float max_evts(0.) ;
            if ( ssbi == 0 ) {
               max_evts = max_msig_evts ;
            } else {
               max_evts = max_msb_evts ;
            }

            float hmax(0.) ;
            if ( max_evts < 0 ) {
               if ( 1.2*(hist_nom->GetMaximum()) > hmax ) { hmax = 1.2*(hist_nom->GetMaximum()) ; }
               if ( 1.2*(hist_m1s->GetMaximum()) > hmax ) { hmax = 1.2*(hist_m1s->GetMaximum()) ; }
               if ( 1.2*(hist_p1s->GetMaximum()) > hmax ) { hmax = 1.2*(hist_p1s->GetMaximum()) ; }
            } else {
               hmax = max_evts ;
            }

            hist_nom -> SetMaximum( hmax ) ;

            for ( int hbi=1; hbi <= hist_nom -> GetNbinsX(); hbi++ ) {
               float nom_val, p1s_val, m1s_val ;
               nom_val = hist_nom -> GetBinContent( hbi ) ;
               p1s_val = hist_p1s -> GetBinContent( hbi ) ;
               m1s_val = hist_m1s -> GetBinContent( hbi ) ;
               hist_p1s_var -> SetBinContent( hbi, 0. ) ;
               hist_m1s_var -> SetBinContent( hbi, 0. ) ;
               if ( nom_val > 0 ) {
                  hist_p1s_var -> SetBinContent( hbi, (p1s_val - nom_val)/nom_val ) ;
                  hist_m1s_var -> SetBinContent( hbi, (m1s_val - nom_val)/nom_val ) ;
                  printf( " hbi=%d : p1s, nom, m1s : %.2f %.2f %.2f\n", hbi, p1s_val, nom_val, m1s_val ) ;
               }
            } // hbi

            hist_m1s_var -> SetMinimum( -0.3 ) ;
            hist_m1s_var -> SetMaximum(  0.3 ) ;

         // hist_m1s_var -> SetLineColor( 4 ) ;
         // hist_p1s_var -> SetLineColor( 2 ) ;
         // hist_m1s_var -> SetLineWidth( 2 ) ;
         // hist_p1s_var -> SetLineWidth( 2 ) ;

            hist_m1s_var -> SetLineColor( 2 ) ;
            hist_p1s_var -> SetLineColor( 4 ) ;
            hist_m1s_var -> SetLineWidth( 2 ) ;
            hist_p1s_var -> SetLineWidth( 2 ) ;

         // hist_m1s_var -> SetFillColor( 4 ) ;
            hist_m1s_var -> SetFillColor( 2 ) ;
            hist_m1s_var -> SetFillStyle( 3354 ) ;

         // hist_p1s_var -> SetFillColor( 2 ) ;
            hist_p1s_var -> SetFillColor( 4 ) ;
            hist_p1s_var -> SetFillStyle( 3345 ) ;

            hist_nom     -> SetTitleOffset( 1.5, "y" ) ;
            hist_m1s_var -> SetTitleOffset( 1.5, "y" ) ;
            hist_nom     -> SetTitleSize( 0.05, "y" ) ;
            hist_m1s_var -> SetTitleSize( 0.05, "y" ) ;
            hist_nom     -> SetLabelSize( 0.07, "x" ) ;
            hist_m1s_var -> SetLabelSize( 0.07, "x" ) ;
            hist_nom     -> SetLabelSize( 0.05, "y" ) ;
            hist_m1s_var -> SetLabelSize( 0.05, "y" ) ;
            hist_nom     -> SetLabelOffset( 0.01, "x" ) ;
            hist_m1s_var -> SetLabelOffset( 0.01, "x" ) ;
            hist_nom     -> SetLabelOffset( 0.01, "y" ) ;
            hist_m1s_var -> SetLabelOffset( 0.01, "y" ) ;

            hist_nom -> SetYTitle( "Events at theory Xsec" ) ;
            hist_m1s_var -> SetYTitle( "Systematic (var-nom)/nom" ) ;


            can_evts -> cd( ci ) ;
            hist_nom -> Draw() ;
            hist_m1s -> Draw("same" ) ;
            hist_p1s -> Draw("same" ) ;
            hist_nom_nf -> Draw("same" ) ;
            hist_nom -> Draw("same axis" ) ;

            can_frac -> cd( ci ) ;
            hist_m1s_var -> Draw( ) ;
            hist_p1s_var -> Draw("same" ) ;
            line -> DrawLine( hist_m1s_var->GetBinLowEdge(1), 0., hist_m1s_var->GetBinLowEdge( hist_nom -> GetNbinsX() + 1 ), 0. ) ;



         } // ci

         char pdfname[10000] ;

         sprintf( pdfname, "outputfiles/syst-plots/%s-syst-%s-events-%s.pdf", pdfbasename.Data(), syst_name, sigsb_str[ssbi] ) ;
         can_evts -> SaveAs( pdfname ) ;
         sprintf( pdfname, "outputfiles/syst-plots/%s-syst-%s-frac-%s.pdf", pdfbasename.Data(), syst_name, sigsb_str[ssbi] ) ;
         can_frac -> SaveAs( pdfname ) ;

      } // ssbi.





   } // draw_syst_hists
Ejemplo n.º 7
0
   void draw_analysis_ratio_plots3( const char* infile = "outputfiles/cdtt_input.root", const char* save_file_base = "plot-dtt-analysis3" ) {

      gDirectory -> Delete( "h*" ) ;

      gStyle -> SetOptStat(0) ;

      loadHist( infile ) ;

      int wx(50), wy(50) ;


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

      TCanvas* can ;
      int ci ;

      char savefile[10000] ;




    //--- 3x3 Njet vs HT grid

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

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

      ci = 1 ;

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

            can -> cd( ci++ ) ;

            char hname[100] ;

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

            do_plots( hp ) ;

         } // wpti
      } // hti


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





    //--- 3 Njet plots

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

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

      ci = 1 ;

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

         can -> cd( ci++ ) ;

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

            char hname[100] ;

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

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


         } // hti
      } // nji


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




    //--- 3 HT plots

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

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

      ci = 1 ;

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

         can -> cd( ci++ ) ;

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

            char hname[100] ;

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

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


         } // nji
      } // hti


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








   } // draw_analysis_ratio_plots3
   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
Ejemplo n.º 9
0
int
main (int argc, char** argv)
{
  int k = 6;

  double thresh = DBL_MAX;     // No threshold, disabled by default

  if (argc < 2)
  {
    pcl::console::print_error 
      ("Need at least three parameters! Syntax is: %s <query_vfh_model.pcd> [options] {kdtree.idx} {training_data.h5} {training_data.list}\n", argv[0]);
    pcl::console::print_info ("    where [options] are:  -k      = number of nearest neighbors to search for in the tree (default: "); 
    pcl::console::print_value ("%d", k); pcl::console::print_info (")\n");
    pcl::console::print_info ("                          -thresh = maximum distance threshold for a model to be considered VALID (default: "); 
    pcl::console::print_value ("%f", thresh); pcl::console::print_info (")\n\n");
    return (-1);
  }

  // this won't be needed for flann > 1.6.10
  flann::ObjectFactory<flann::IndexParams, flann_algorithm_t>::instance().register_<flann::LinearIndexParams>(FLANN_INDEX_LINEAR);

  std::string extension (".pcd");
  transform (extension.begin (), extension.end (), extension.begin (), (int(*)(int))tolower);

  // Load the test histogram
  std::vector<int> pcd_indices = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");
  vfh_model histogram;
  if (!loadHist (argv[pcd_indices.at (0)], histogram))
  {
    pcl::console::print_error ("Cannot load test file %s\n", argv[pcd_indices.at (0)]);
    return (-1);
  }

  pcl::console::parse_argument (argc, argv, "-thresh", thresh);
  // Search for the k closest matches
  pcl::console::parse_argument (argc, argv, "-k", k);
  pcl::console::print_highlight ("Using "); pcl::console::print_value ("%d", k); pcl::console::print_info (" nearest neighbors.\n");

  std::string kdtree_idx_file_name = "kdtree.idx";
  std::string training_data_h5_file_name = "training_data.h5";
  std::string training_data_list_file_name = "training_data.list";

  std::vector<vfh_model> models;
  flann::Matrix<int> k_indices;
  flann::Matrix<float> k_distances;
  flann::Matrix<float> data;
  // Check if the data has already been saved to disk
  if (!boost::filesystem::exists ("training_data.h5") || !boost::filesystem::exists ("training_data.list"))
  {
    pcl::console::print_error ("Could not find training data models files %s and %s!\n", 
        training_data_h5_file_name.c_str (), training_data_list_file_name.c_str ());
    return (-1);
  }
  else
  {
    loadFileList (models, training_data_list_file_name);
    flann::load_from_file (data, training_data_h5_file_name, "training_data");
    pcl::console::print_highlight ("Training data found. Loaded %d VFH models from %s/%s.\n", 
        (int)data.rows, training_data_h5_file_name.c_str (), training_data_list_file_name.c_str ());
  }

  // Check if the tree index has already been saved to disk
  if (!boost::filesystem::exists (kdtree_idx_file_name))
  {
    pcl::console::print_error ("Could not find kd-tree index in file %s!", kdtree_idx_file_name.c_str ());
    return (-1);
  }
  else
  {
    flann::Index<flann::ChiSquareDistance<float> > index (data, flann::SavedIndexParams ("kdtree.idx"));
    index.buildIndex ();
    nearestKSearch (index, histogram, k, k_indices, k_distances);
  }

  // Output the results on screen
  pcl::console::print_highlight ("The closest %d neighbors for %s are:\n", k, argv[pcd_indices[0]]);
  for (int i = 0; i < k; ++i)
    pcl::console::print_info ("    %d - %s (%d) with a distance of: %f\n", 
        i, models.at (k_indices[0][i]).first.c_str (), k_indices[0][i], k_distances[0][i]);

  // Load the results
  pcl::visualization::PCLVisualizer p (argc, argv, "VFH Cluster Classifier");
  int y_s = (int)floor (sqrt ((double)k));
  int x_s = y_s + (int)ceil ((k / (double)y_s) - y_s);
  double x_step = (double)(1 / (double)x_s);
  double y_step = (double)(1 / (double)y_s);
  pcl::console::print_highlight ("Preparing to load "); 
  pcl::console::print_value ("%d", k); 
  pcl::console::print_info (" files ("); 
  pcl::console::print_value ("%d", x_s);    
  pcl::console::print_info ("x"); 
  pcl::console::print_value ("%d", y_s); 
  pcl::console::print_info (" / ");
  pcl::console::print_value ("%f", x_step); 
  pcl::console::print_info ("x"); 
  pcl::console::print_value ("%f", y_step); 
  pcl::console::print_info (")\n");

  int viewport = 0, l = 0, m = 0;
  for (int i = 0; i < k; ++i)
  {
    std::string cloud_name = models.at (k_indices[0][i]).first;
    boost::replace_last (cloud_name, "_vfh", "");

    p.createViewPort (l * x_step, m * y_step, (l + 1) * x_step, (m + 1) * y_step, viewport);
    l++;
    if (l >= x_s)
    {
      l = 0;
      m++;
    }

    sensor_msgs::PointCloud2 cloud;
    pcl::console::print_highlight (stderr, "Loading "); pcl::console::print_value (stderr, "%s ", cloud_name.c_str ());
    if (pcl::io::loadPCDFile (cloud_name, cloud) == -1)
      break;

    // Convert from blob to PointCloud
    pcl::PointCloud<pcl::PointXYZ> cloud_xyz;
    pcl::fromROSMsg (cloud, cloud_xyz);

    if (cloud_xyz.points.size () == 0)
      break;

    pcl::console::print_info ("[done, "); 
    pcl::console::print_value ("%d", (int)cloud_xyz.points.size ()); 
    pcl::console::print_info (" points]\n");
    pcl::console::print_info ("Available dimensions: "); 
    pcl::console::print_value ("%s\n", pcl::getFieldsList (cloud).c_str ());

    // Demean the cloud
    Eigen::Vector4f centroid;
    pcl::compute3DCentroid (cloud_xyz, centroid);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz_demean (new pcl::PointCloud<pcl::PointXYZ>);
    pcl::demeanPointCloud<pcl::PointXYZ> (cloud_xyz, centroid, *cloud_xyz_demean);
    // Add to renderer*
    p.addPointCloud (cloud_xyz_demean, cloud_name, viewport);
    
    // Check if the model found is within our inlier tolerance
    std::stringstream ss;
    ss << k_distances[0][i];
    if (k_distances[0][i] > thresh)
    {
      p.addText (ss.str (), 20, 30, 1, 0, 0, ss.str (), viewport);  // display the text with red

      // Create a red line
      pcl::PointXYZ min_p, max_p;
      pcl::getMinMax3D (*cloud_xyz_demean, min_p, max_p);
      std::stringstream line_name;
      line_name << "line_" << i;
      p.addLine (min_p, max_p, 1, 0, 0, line_name.str (), viewport);
      p.setShapeRenderingProperties (pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 5, line_name.str (), viewport);
    }
    else
      p.addText (ss.str (), 20, 30, 0, 1, 0, ss.str (), viewport);

    // Increase the font size for the score*
    p.setShapeRenderingProperties (pcl::visualization::PCL_VISUALIZER_FONT_SIZE, 18, ss.str (), viewport);

    // Add the cluster name
    p.addText (cloud_name, 20, 10, cloud_name, viewport);
  }
  // Add coordianate systems to all viewports
  p.addCoordinateSystem (0.1, 0);

  p.spin ();
  return (0);
}