예제 #1
0
//------------------------------------------------------------------------------
// InvertAxis
//------------------------------------------------------------------------------
TH2F* InvertAxis(TH2* h2, TString hname)
{
  TArrayD* xarray = (TArrayD*)h2->GetXaxis()->GetXbins();
  TArrayD* yarray = (TArrayD*)h2->GetYaxis()->GetXbins();

  const UInt_t xsize = xarray->GetSize();
  const UInt_t ysize = yarray->GetSize();

  Double_t* xbins = new Double_t[xsize];
  Double_t* ybins = new Double_t[ysize];
  
  for (UInt_t i=0; i<xsize; i++) xbins[i] = xarray->GetAt(i);
  for (UInt_t i=0; i<ysize; i++) ybins[i] = yarray->GetAt(i);

  TH2F* h2inverted = new TH2F(hname, hname,
			      h2->GetNbinsY(), ybins,
			      h2->GetNbinsX(), xbins);

  for (UInt_t i=1; i<=h2inverted->GetNbinsX(); i++) {
    for (UInt_t j=1; j<=h2inverted->GetNbinsY(); j++) {

      h2inverted->SetBinContent(i, j, h2->GetBinContent(j, i));
      h2inverted->SetBinError  (i, j, h2->GetBinError  (j, i));
    }
  }

  delete [] xbins;
  delete [] ybins;

  return h2inverted;
}
void showFunction2d(TF1* function, 
		    const TArrayD& testValuesX, const TArrayD& testValuesY, double metResolution, double metErr,
		    const TString& xAxisTitle, const TString& yAxisTitle,
		    const std::string& outputFileName)
{
  int numTestValuesX = testValuesX.GetSize();
  for ( int iTestValueX = 0; iTestValueX < numTestValuesX; ++iTestValueX ) {
    double testValueX = testValuesX[iTestValueX];

    std::vector<TF1*> functions;
    std::vector<std::string> legendEntries;

    int numTestValuesY = testValuesY.GetSize();
    for ( int iTestValueY = 0; iTestValueY < numTestValuesY; ++iTestValueY ) {
      double testValueY = testValuesY[iTestValueY];

      std::string functionName_nll = Form("%s_nll_%i", function->GetName(), iTestValueY);
      TF1* function_nll = 0;
      if ( metResolution > 0. ) {
	function_nll = 
	  new TF1(functionName_nll.data(), 
		  Form("-TMath::Log((%s)*TMath::Gaus(([1] - [0])*x, ([1] - [0]) + [2], [3]))", 
		       function->GetTitle()),
		  function->GetXmin(), function->GetXmax());
      } else {
	function_nll = new TF1(functionName_nll.data(), function->GetTitle(), function->GetXmin(), function->GetXmax());
      }
      function_nll->SetParameter(0, testValueX);
      function_nll->SetParameter(1, testValueY);
      function_nll->SetParameter(2, metErr);
      function_nll->SetParameter(3, metResolution);
      functions.push_back(function_nll);

      legendEntries.push_back(std::string(Form("m_{2} = %1.1f", testValueY)));
    }
 
    double yMax = 0.5*(0.1 + testValueX);

    size_t idx = outputFileName.find_last_of('.');
    TString outputFileName_plot = std::string(outputFileName, 0, idx).data();
    outputFileName_plot.Append(Form("_m1Eq%1.1f", testValueX));
    outputFileName_plot.ReplaceAll(".", "_");
    if ( idx != std::string::npos ) outputFileName_plot.Append(std::string(outputFileName, idx).data());
    showFunctions1d(functions, legendEntries, xAxisTitle, 0., yMax, yAxisTitle, outputFileName_plot.Data());

    for ( std::vector<TF1*>::iterator it = functions.begin();
	  it != functions.end(); ++it ) {
      delete (*it);
    }
  }
}
예제 #3
0
double* Divide(const TArrayD* array , double val){
  TArrayD* temp = new TArrayD();
  array->Copy(*temp);
  for(int i = 0 ; i < temp->GetSize() ; i++)
    temp->SetAt(array->At(i) / val , i);
  
  return temp->GetArray();  
}