Beispiel #1
0
  ///output operator
  ostream& StatSample::print_tex (ostream& os, const string title) const {
    
    bool weightMode = _weight->nevents() > 0 ?  true : false ;

    os << "" << endl;
    os << "% Efficiency table %" << endl;
    os << "" << endl;
    os << "\\begin{table}[p]" << endl;
    os << "\\begin{center}" << endl;
    os << "\\begin{tabular}{lrrr" ; 
    if (weightMode) os << "r" ;
    os << "}" << endl;
    os << "  \\hline  \\hline" << endl;
    os << "  Selection & Events & Relative  & Total  " ;
    if (weightMode) os << "& Total Corrected by Event Weights " ;
    os << "\\\\ \\hline" << endl;
    
    os << tex(eventSelection(0)->name()) << " & " ;
    os <<  nevents(0) << " & & " ;
    if (weightMode) os << " & " ;
    os << "\\\\ " << endl ; 

    for (unsigned int n = 1; n < size() ; n++) {
      
      os << tex(eventSelection(n)->name()) << " & " ;
      os <<  nevents(n) << " & ";

      if (eventSelection(n)->isWeight()) {	
	os << " $\\mathit{ " << eff(n) << " \\pm " 
	   << effErr(n) << " }$ & & " ;
	if (weightMode) os << " & " ;
      } else {	
	os << " $ " << 100.0*eff(n) << " \\pm " 
	   << 100.0*effErr(n) << " ~\\% $ & " ;
	os << " $ " << 100.0*effGlob(n) << " \\pm " 
	   << 100.0*effErrGlob(n) << "~\\% $ " ;
	if (weightMode) 
	  os << " $ " << 100.0*correctedEfficiency(n) << " \\pm " 
	     << 100.0*correctedEffErr(n) << "~\\% $ " ;
      }

      os << " \\\\ " << endl ; 
    }

    os << "  \\hline " << endl;
    os << " \\hline" << endl;
    os << " \\end{tabular}" << endl;
    os << " \\caption{" << title << " Sample " << name() << " }" << endl;
    os << " \\label{Table:" <<  title.c_str() << ":" << name() << "}" << endl;
    os << "\\end{center}" << endl;
    os << "\\end{table}" << endl; 
    os << endl;

    return os ;    
  }
Beispiel #2
0
void gatherAEff(const char *inpFile=NULL) {
  std::string line;
  std::vector<std::string> lines;

  if (!inpFile) {
    std::cout << "\ninpFile=NULL\n";
    std::cout << "Creating sample input file\n";
    const char *sampleFName="aeff_sample.inp";
    std::ofstream fout(sampleFName);
    fout << "../root_files/constants/DY_j22_19789pb/acceptance_constants1D.root\n";
    fout << "../root_files/constants/DY_j22_19789pb/event_efficiency_constants1D.root\n";
    fout << "../root_files/constants/DY_j22_19789pb/scale_factors_1D_Full2012_hltEffOld_PU.root\n";
    fout.close();
    std::cout << "check the file <" << sampleFName << ">\n";
    std::cout << "1D/2D in the name does not matter\n";
    return;
  }
  else { // load input
    std::ifstream finput(inpFile);
    if (!finput) {
      std::cout << "failed to open file <" << inpFile << ">\n";
      return;
    }
    getline(finput,line); lines.push_back(line);
    std::cout << "line1=<" << line << ">\n";
    getline(finput,line); lines.push_back(line);
    std::cout << "line2=<" << line << ">\n";
    getline(finput,line); lines.push_back(line);
    std::cout << "line3=<" << line << ">\n";
    finput.close();
  }
  std::cout << dashline;

  std::string fnameAcc,fnameEff,fnameRho;
  int count=0;
  for (unsigned int i=0; i<lines.size(); ++i) {
    line=lines[i];
    AdjustDim(line);
    if (PosOk(line,"acceptance")) { fnameAcc=line; count++; }
    else if (PosOk(line,"efficiency")) { fnameEff=line; count++; }
    else if (PosOk(line,"scale_factors")) { fnameRho=line; count++; }
    else {
      std::cout << "could not identify the file <" << line << ">\n";
      return;
    }
  }
  if (count!=3) { 
    std::cout << "not all files were identified\n";
    return;
  }
  std::cout << "files were identified ok\n";
  std::cout << dashline;

  TMatrixD effM(DYTools::nMassBins,DYTools::nYBinsMax);
  TMatrixD effErrM(effM);
  TMatrixD accM(effM), accErrM(effM);
  TMatrixD rhoM(effM), rhoErrM(effM);

  if (!LoadMatrix(fnameAcc,accM,accErrM,"acceptanceMatrix","acceptanceErrMatrix") ||
      !LoadMatrix(fnameEff,effM,effErrM,"efficiencyArray","efficiencyErrArray") ||
      !LoadMatrix(fnameRho,rhoM,rhoErrM,"scaleFactor","scaleFactorErr") ) {
    std::cout << "failed to load field\n";
    return;
  }

  TString outFName;
  if (DYTools::study2D) {
    outFName="dyee_aeff_2D.root";
    TFile fout(outFName,"recreate");
    accM.Write("acceptance");
    accErrM.Write("acceptanceErr");
    effM.Write("efficiency");
    effErrM.Write("efficiencyErr");
    rhoM.Write("scaleFactor");
    rhoErrM.Write("scaleFactorErr");
    unfolding::writeBinningArrays(fout);

    for (int i=0; i<DYTools::nMassBins; ++i) {
      TString massRange=Form("_%1.0lf_%2.0lf",DYTools::massBinLimits[i],DYTools::massBinLimits[i+1]);
      TString hAccName=TString("hAcc") + massRange;
      Histo_t *hAcc=extractRapidityDependence(hAccName,"",accM,accErrM,i,0);
      TString hEffName=TString("hEff") + massRange;
      Histo_t *hEff=extractRapidityDependence(hEffName,"",effM,effErrM,i,0);
      TString hRhoName=TString("hRho") + massRange;
      Histo_t *hRho=extractRapidityDependence(hRhoName,"",rhoM,rhoErrM,i,0);
      if (!hAcc || !hEff || !hRho) {
	std::cout << "got unexpected null histo\n";
	break;
      }

      hAcc->Write();
      hEff->Write();
      hRho->Write();
    }
    fout.Close();
  }
  else { // 1D case
    outFName="dyee_aeff_1D.root";
    std::cout << "accM: rows " << accM.GetNrows() << ", cols " << accM.GetNcols() << "\n";
    TVectorD eff(DYTools::nMassBins), effErr(eff);
    TVectorD acc(eff), accErr(eff);
    TVectorD rho(eff), rhoErr(eff);

    GetMassProfile1D(accM,accErrM, acc,accErr);
    GetMassProfile1D(effM,effErrM, eff,effErr);
    GetMassProfile1D(rhoM,rhoErrM, rho,rhoErr);
    
    Histo_t *hAcc=extractMassDependence("hAcc","",accM,accErrM,0,0,0);
    Histo_t *hEff=extractMassDependence("hEff","",effM,effErrM,0,0,0);
    Histo_t *hRho=extractMassDependence("hRho","",rhoM,rhoErrM,0,0,0);

    if (!hAcc || !hEff || !hRho) {
      std::cout << "got unexpected null histo\n";
    }
    else {
      TFile fout(outFName,"recreate");
      acc.Write("acceptance");
      accErr.Write("acceptanceErr");
      eff.Write("efficiency");
      effErr.Write("efficiencyErr");
      rho.Write("scaleFactor");
      rhoErr.Write("scaleFactorErr");
      unfolding::writeBinningArrays(fout);

      hAcc->Write();
      hEff->Write();
      hRho->Write();
      fout.Close();
    }
  }
  std::cout << "file <" << outFName << "> created\n";

  return;
}
Beispiel #3
0
  ostream& StatSample::HtmlTable(ostream& os) const {
    
    bool weightMode = _weight->nevents() > 0 ?  true : false ;

    os << "<TABLE BORDERCOLORDARK=\"996633\"  BORDERCOLOR=\"CC9966\"    BORDERCOLORLIGHT=\"FFCC99\"   border=3 cellPadding=5 width=\"99%\">" << endl ;
    os << "<TBODY align=right>" << endl ;
    
    os << "<TR>" << endl ;
    os << "<TH align=left>" << endl ;
    os << "SELECTION"   ;
    os << " </TH>" << endl ;
    if (weightMode) 
      os << "<TH align=center colspan=4>" << endl ; 
    else 
      os << "<TH align=center colspan=3>" << endl ; 
    os <<  name() << endl ;
    os << "</TH>" << endl ; 
    os << "</TR>" << endl ;
      
    bool color = false ;
    
    for (unsigned int n = 0; n < size() ; n++) {
      
      if (color) {
	os << "<TR BGCOLOR=#bfefff>" << endl ; 
	color = !color ;
      } else { 
	os << "<TR>" << endl ; 
	color = !color ;
      }      
     
      os << "<TD align=left>" << endl ; 
      os <<  eventSelection(n)->name() << endl ;
      os << "</TD>" << endl ; 

      os << "<TD TITLE=\"Number of events\">" << endl ; 
      os <<  nevents(n) << endl ;
      if (n==0) {
	os << "<TD>&#160;</TD> <TD>&#160;</TD>" ;
	if (weightMode) os << "<TD>&#160;</TD> " ;
	os << endl ; 
	continue ;
      }
	
      if (eventSelection(n)->isWeight()) {
	  if (eventSelection(n)->name() == eventWeight()->name()) 
	    os << "</TD> <TD TITLE=\"Global event weight\">" << endl ; 
	  else 
	    os << "</TD> <TD TITLE=\"Average weight\">" << endl ; 
	  os << eff(n) << "&#177;" << effErr(n)<< endl ;
	  os << "</TD> <TD> &#160;</TD>";
	  if (weightMode) os << "<TD> &#160;</TD>";	  
	  os << endl ;
	  continue ;
      } 
      
      os << "</TD><TD TITLE=\"Selection efficiency\">"<< endl ;
      os << 100.0*eff(n) << "&#177;" << 100.0*effErr(n) << "%" << endl ;
      os << "</TD><TD TITLE=\"Global efficiency\">"<< endl ;
      os << 100.0*effGlob(n) << "&#177;" << 100.0*effErrGlob(n) << "%" 
	 << endl ;
      os << "</TD>" << endl ;       
      if (weightMode) {
	os << "</TD><TD TITLE=\"Global efficiency corrected by the event weight\">"<< endl ;
	os << 100.0*correctedEfficiency(n) << "&#177;" << 100.0*correctedEffErr(n) << "%" 
	   << endl ;
	os << "</TD>" << endl ;       	
      }
      os << "</TR>" << endl ; 
    }
    
    os << "</TBODY></TABLE>" << endl ;

    return os ;
  }