コード例 #1
0
ファイル: gaus2d.cpp プロジェクト: MatsumotoSatoru/SATOROOT
int main(int argc, char** argv){
  if(argc!=2){
    std::cerr << "### Usage like ... \n   ./gaus2d 10000(imax)" << std::endl ;
    return EXIT_FAILURE ;
  }
  else{/* DO NOT ANYTHING */}
  TApplication app( "app", &argc, argv );  
  double x ;
  double y ;
  int imax = atoi(argv[1]) ;
  TString title("2D Gaussian") ;
  TString titleimax(argv[1])   ;
  title += titleimax ;
  
  TCanvas *c1 = new TCanvas("c1", "c1", 600, 600) ;
  gStyle->SetOptStat("enRM") ;
  c1->SetTicks(1,1) ;
  c1->SetGrid(1,1) ;
  c1->SetRightMargin(0.15) ;
  TH2D *hist    = new TH2D("hist",title,100, -5., 5., 100, -5., 5.) ;
  TF2 *gausfunc = new TF2("gausfunc","[0]*TMath::Exp( - TMath::Sqrt(  TMath::Power((x-[1])/[2],2)/2. + TMath::Power((y-[3])/[4],2)/2. ))", -5., 5., -5., 5.) ;
  gausfunc->SetParameters(1., 0., 0.5, 0., 0.5) ;
  gausfunc->SetNpx(300) ;
  gausfunc->SetNpy(300) ;

  gRandom->SetSeed(unsigned(time(NULL))) ;
  for(int i =0 ; i< imax ; i++){
    gausfunc->GetRandom2(x,y) ;
    hist->Fill(x,y) ;
  }
  hist->Draw("colz") ;
  gPad->Update();
  TPaveStats *st = (TPaveStats*)hist->FindObject("stats") ;
  st->SetX1NDC(0.60) ;
  st->SetX2NDC(0.85) ;
  st->SetY1NDC(0.70) ;
  st->SetY2NDC(0.90) ;
  c1->SaveAs("gaus2dc1.eps") ;
  app.Run() ;
  delete c1 ;
  delete hist ;
  delete gausfunc ;
  return EXIT_SUCCESS ;
}
コード例 #2
0
Int_t VisualizeSurface()
{
    std::string rfname = GetROOTFile();
    TFile *fle = new TFile(rfname.data());
    if (!fle->IsOpen()) return -1;

    Eta2C eta(fle);
    AngMarginalEta2C marg_eta(eta);
    fle->Close();

    ParamFunctorAdapter *pfa = new ParamFunctorAdapter(marg_eta);

    ROOT::Math::ParamFunctor pf;
    pf.SetFunction(pfa);
    TF2* f = new TF2("f", pf, -1, 1, -1.0*CLHEP::pi,CLHEP::pi,0);
    f->SetNpx(50);
    f->SetNpy(50);

//    TPaveText* pt = new TPaveText(0.5, 0.75, 0.8, 0.95);
//    std::ostringstream os(std::ios::out | std::ios::app);
//    os << "a = " << params[0]->GetValue();
//    pt->InsertText(os.str().data());
//    os.str("b = ");
//    os << params[1]->GetValue();
//    pt->InsertText(os.str().data());
//    os.str("c = ");
//    os << params[2]->GetValue();
//    pt->InsertText(os.str().data());
//    os.str("d = ");
//    os << params[3]->GetValue();
//    pt->InsertText(os.str().data());

    TCanvas* c = new TCanvas("c");
    c->Divide(2,1,0.001,0.001);
    c->cd(1);
    f->Draw("cont1 z");
    c->cd(2);
    f->DrawCopy("surf1 z");

//    pt->Draw();

    return 0;
}
コード例 #3
0
ファイル: glrose.C プロジェクト: digideskio/root
// Render a TF2 looking like a rose.
// Author: Timur Pocheptsov
void glrose()
{
  //Define and set user's palette,
   //use polar system.
   const Int_t paletteSize = 10;
   Float_t rgb[paletteSize * 3] =
      {0.80f, 0.55f, 0.40f,
       0.85f, 0.60f, 0.45f,
       0.90f, 0.65f, 0.50f,
       0.95f, 0.70f, 0.55f,
       1.f,   0.75f, 0.60f,
       1.f,   0.80f, 0.65f,
       1.f,   0.85f, 0.70f,
       1.f,   0.90f, 0.75f,
       1.f,   0.95f, 0.80f,
       1.f,   1.f,   0.85f};

   Int_t palette[paletteSize] = {0};

   for (Int_t i = 0; i < paletteSize; ++i)
      palette[i] = TColor::GetColor(rgb[i * 3], rgb[i * 3 + 1], rgb[i * 3 + 2]);

   gStyle->SetPalette(paletteSize, palette);

   gStyle->SetCanvasPreferGL(1);
   TCanvas *cnv = new TCanvas("glc", "Surface sample", 200, 10, 600, 550);

   TPaveLabel *title = new TPaveLabel(0.04, 0.86, 0.96, 0.98,
                           "\"glsurf2pol\" option + user defined palette.");
   title->SetFillColor(32);
   title->Draw();

   TPad *rosePad  = new TPad("box", "box", 0.04, 0.04, 0.96, 0.8);
   rosePad->Draw();


   TF2 *fun = new TF2("a", "cos(y)*sin(x)+cos(x)*sin(y)", -6, 6, -6, 6);
   fun->SetContour(paletteSize);
   fun->SetNpx(30);
   fun->SetNpy(30);
   rosePad->cd();
   fun->Draw("glsurf2pol");
}
コード例 #4
0
ファイル: Generate_LS.c プロジェクト: btcarlso/UserCode
void LS(int ups, int iy, int ipt){
	TString LS_name = Form("LS_y%d_pt%d_ups%d",iy,ipt,ups);
	double dm_scale_max;
	double dm_scale_min;
	if(ipt==fNpt){
		dm_scale_max=1.0+dm_scale_width_last[0];
		dm_scale_min=1.0-dm_scale_width_last[1];
	}
	else {
		dm_scale_min=1.0-dm_scale_width; 
		dm_scale_max=1.0+dm_scale_width; 
	}
	
	TF2 *LS = new TF2(LS_name, PDF_shape, 8.7,11.3,dm_scale_min,dm_scale_max,N_event*2); 

	//Main loop
	//R was 11.6
	int Ntail=static_cast<int>(static_cast<double>(N_event)/(R+1) );

	for(int iSample=0; iSample<N_event; iSample++){
		int im=2*iSample; 
		int is=2*iSample+1; 
		
		double zeta=get_dm(dm);//Get mass uncertainty 
		
		double m=0; 	
		if(iSample<Ntail)m=mass_function->GetRandom(8.7,fill_cutoff[ups-1]); //should be pm-0.002
		else m=PDG_mass[ups-1]; // Get Mass 
			
		LS->SetParameter(im,m);
		LS->SetParameter(is,zeta); 	
	}
	//Write output
	LS->SetNpx(Npx); 
	LS->SetNpy(Npy); 
	output_file->cd();
	LS->Write(); 
	//delete pointers 
	delete LS; 
	
}
コード例 #5
0
ファイル: annotation3d.C プロジェクト: davidlt/root
void annotation3d()
{
   TCanvas *c = new TCanvas("c", "c", 600, 600);
   c->SetTheta(30);
   c->SetPhi(50);
   gStyle->SetOptStat(0);
   gStyle->SetHistTopMargin(0);
   gStyle->SetOptTitle(kFALSE);

   // Define and draw a surface
   TF2 *f = new TF2("f", "[0]*cos(x)*cos(y)", -1, 1, -1, 1);
   f->SetParameter(0, 1);
   double s = 1./f->Integral(-1, 1, -1, 1);
   f->SetParameter(0, s);
   f->SetNpx(50);
   f->SetNpy(50);

   f->GetXaxis()->SetTitle("x");
   f->GetXaxis()->SetTitleOffset(1.4);
   f->GetXaxis()->SetTitleSize(0.04);
   f->GetXaxis()->CenterTitle();
   f->GetXaxis()->SetNdivisions(505);
   f->GetXaxis()->SetTitleOffset(1.3);
   f->GetXaxis()->SetLabelSize(0.03);
   f->GetXaxis()->ChangeLabel(2,-1,-1,-1,kRed,-1,"X_{0}");

   f->GetYaxis()->SetTitle("y");
   f->GetYaxis()->CenterTitle();
   f->GetYaxis()->SetTitleOffset(1.4);
   f->GetYaxis()->SetTitleSize(0.04);
   f->GetYaxis()->SetTitleOffset(1.3);
   f->GetYaxis()->SetNdivisions(505);
   f->GetYaxis()->SetLabelSize(0.03);

   f->GetZaxis()->SetTitle("dP/dx");
   f->GetZaxis()->CenterTitle();
   f->GetZaxis()->SetTitleOffset(1.3);
   f->GetZaxis()->SetNdivisions(505);
   f->GetZaxis()->SetTitleSize(0.04);
   f->GetZaxis()->SetLabelSize(0.03);

   f->SetLineWidth(1);
   f->SetLineColorAlpha(kAzure-2, 0.3);

   f->Draw("surf1 fb");

   // Lines for 3D annotation
   double x[11] = {-0.500, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.500};
   double y[11] = {-0.985, -0.8, -0.6, -0.4, -0.2,  0.0,  0.2,  0.4,  0.6,  0.8,  0.985};
   double z[11];
   for (int i = 0; i < 11; ++i) z[i] = s*cos(x[i])*cos(y[i]);
   TPolyLine3D *g2 = new TPolyLine3D(11, x, y, z);

   double xx[2] = {-0.5, -0.5};
   double yy[2] = {-0.985, -0.985};
   double zz[2] = {0.11, s*cos(-0.5)*cos(-0.985)};
   TPolyLine3D *l2 = new TPolyLine3D(2, xx, yy, zz);

   g2->SetLineColor(kRed);
   g2->SetLineWidth(3);
   g2->Draw();

   l2->SetLineColor(kRed);
   l2->SetLineStyle(2);
   l2->SetLineWidth(1);
   l2->Draw();

   // Draw text Annotations
   TLatex *txt = new TLatex(0.05, 0, "f(y,x_{0})");
   txt->SetTextFont(42);
   txt->SetTextColor(kRed);
   txt->Draw();

   TLatex *txt1 = new TLatex(0.12, 0.52, "f(x,y)");
   txt1->SetTextColor(kBlue);
   txt1->SetTextFont(42);
   txt1->Draw();
}
コード例 #6
0
void
plot2DSignalHisto(
    TString filename1,
    TString filename2, 
    TString histogramName,
//    TString drawopts = "",
    TString xtitle = "x",
    TString ytitle = "y",
    double xtitleOffset = 1.1,
    double ytitleOffset = 1.3
    )
{
// {{{
    InitgStyle();
    //gStyle->SetOptStat(0);
    //gCanvas = new TCanvas("gCanvas", "gCanvas", 0, 0, 800, 600);
    
    TFile *outputFile = new TFile("FitErgebnisse.root","RECREATE");
    TH2D *histogram__DiffAbs = new TH2D("histogram__DiffAbs","Differenz Fit - Input (Absolut)", 5, -1, 1, 5, -1, 1);
    TH2D *histogram__DiffRel = new TH2D("histogram__DiffRel","Differenz Fit - Input (Relativ)", 5, -1, 1, 5, -1, 1);
    TH2D *histogram__FitResult = new TH2D("histogram__FitResult ", "Ergebnis-Histogramm des Fits", 5, -1, 1, 5, -1, 1);


    
//    LoadHistogramTH2D(histogramName , filename1, 1.0, histogram);// Summe (SM)
    LoadHistogramTH2D("histogram__Correlation"+histogramName , filename1, 1.0, histogram);// Summe (SM

    //LoadHistogramTH2D(histogramName+"_LL" , filename2, 1.0, histo1);	// LL
    //LoadHistogramTH2D(histogramName+"_LR" , filename2, 1.0, histo2);	// LR
    //LoadHistogramTH2D(histogramName+"_RL" , filename2, 1.0, histo3);	// RL
    //LoadHistogramTH2D(histogramName+"_RR" , filename2, 1.0, histo4);	// RR
    
    //LoadHistogramTH2D("histogram__gen_N" , filename2, 1.0, histo1);
    //LoadHistogramTH2D("histogram__gen_A" , filename2, 1.0, histo2);
    
    LoadHistogramTH2D("histogram__N"+histogramName , filename2, 1.0, histo1);
    LoadHistogramTH2D("histogram__A"+histogramName , filename2, 1.0, histo2);


    //gCanvas->Clear();
  

    histogram->GetXaxis()->SetTitle(xtitle);
    histogram->GetXaxis()->SetTitleOffset(xtitleOffset);
    histogram->GetYaxis()->SetTitle(ytitle);
    histogram->GetYaxis()->SetTitleOffset(ytitleOffset);
    //histogram->GetZaxis()->SetTitle("d^{2}#sigma / dM_{#bar{t}}dM_{t} [pb]");
    //histogram->GetZaxis()->SetTitleOffset(ytitleOffset);

//    gCanvas->Update();

    /*    
    histo1->Scale(1.0/histo4->Integral());
    histo2->Scale(1.0/histo4->Integral());
    histo3->Scale(1.0/histo4->Integral());
    histo4->Scale(1.0/histo4->Integral());
    */

       
    //faktor = 1.0;
    faktor=Double_t(histogram->Integral())/Double_t(histo1->Integral());
    cout<<faktor<<endl; 
    
    TF2 *fitFunction = new TF2("fitFunction", HistoSum, -1, 1, -1, 1, 2);  //allgemeine "return"-Varianten
    //fitFunction->SetParameters(0.9,0.,0.);
    //fitFunction->SetLineColor(kRed);
    
    histogram->Fit(fitFunction, "N");
    fitFunction->SetNpx(5);
    fitFunction->SetNpy(5);
    
    double p0 = fitFunction->GetParameter(0);
    double p1 = fitFunction->GetParameter(1);
//    double p2 = fitFunction->GetParameter(2);
//    double p3 = fitFunction->GetParameter(3);

    for(int i =1; i <= 5; i++)
    {
        for(int j = 1; j <= 5; j++)
        {
            //double sigmaLL = p0*faktor*histo1->GetBinError(i,j);
            //double sigmaLR = p1*faktor*histo2->GetBinError(i,j);
            //double sigmaRL = p2*faktor*histo3->GetBinError(i,j);
            //double sigmaRR = p3*faktor*histo4->GetBinError(i,j);
            double sigmaN = p0*faktor*histo1->GetBinError(i,j);
            double sigmaA = p1*faktor*histo2->GetBinError(i,j);
            //histogram->SetBinError(i,j, sqrt( histogram->GetBinContent(i,j) + pow(sigmaLL,2) + pow(sigmaRR,2) + pow(sigmaRL,2) + pow(sigmaLR, 2) ));
            histogram->SetBinError(i,j, sqrt( histogram->GetBinContent(i,j) + pow(sigmaN,2) + pow(sigmaA,2) ));
        }
    }
    histogram->Fit(fitFunction, "NE");

    p0 = fitFunction->GetParameter(0);
    p1 = fitFunction->GetParameter(1);

    for(int i =1; i <= 5; i++)
    {
        for(int j = 1; j <= 5; j++)
        {
            //double sigmaLL = p0*faktor*histo1->GetBinError(i,j);
            //double sigmaLR = p1*faktor*histo2->GetBinError(i,j);
            //double sigmaRL = p2*faktor*histo3->GetBinError(i,j);
            //double sigmaRR = p3*faktor*histo4->GetBinError(i,j);
            double sigmaN = p0*faktor*histo1->GetBinError(i,j);
            double sigmaA = p1*faktor*histo2->GetBinError(i,j);
            //histogram->SetBinError(i,j, sqrt( histogram->GetBinContent(i,j) + pow(sigmaLL,2) + pow(sigmaRR,2) + pow(sigmaRL,2) + pow(sigmaLR, 2) ));
            histogram->SetBinError(i,j, sqrt( histogram->GetBinContent(i,j) + pow(sigmaN,2) + pow(sigmaA,2) ));
        }
    }
    histogram->Fit(fitFunction, "NE");

        
    //histogram->Draw("lego1");  
    //fitFunction->Draw("lego");
    cout << fitFunction->GetChisquare()/fitFunction->GetNDF() << endl;

    for(int i = 1; i <= 5; i++)
    {
        for(int j = 1; j <= 5; j++)
        {
            histogram__DiffAbs->SetBinContent(i,j, fitFunction->Eval(histogram->GetXaxis()->GetBinCenter(i),histogram->GetYaxis()->GetBinCenter(j))-histogram->GetBinContent(i,j) );
            histogram__DiffRel->SetBinContent(i,j, (fitFunction->Eval(histogram->GetXaxis()->GetBinCenter(i),histogram->GetYaxis()->GetBinCenter(j))-histogram->GetBinContent(i,j))/histogram->GetBinContent(i,j) );
            histogram__FitResult->SetBinContent(i,j, fitFunction->Eval(histogram->GetXaxis()->GetBinCenter(i),histogram->GetYaxis()->GetBinCenter(j)));
        }
    }
    
        
    outputFile->cd("");
    histogram__DiffAbs->Write("histogram__DiffAbs");
    histogram__DiffRel->Write("histogram__DiffRel");
    histogram__FitResult->Write("histogram__FitResult");
    outputFile->Close();
    delete outputFile;
       
    
    //gCanvas->Print(epsFilename(filename, histogramName)+".eps");
	//cout << histogram[0]->Integral() << endl;
// }}}
};
コード例 #7
0
void PrintVertexRosenbrock()
{
	// open file

	std::ifstream data ("Vertex.txt", std::ios::in);
	
	double buf;
	std::vector<double> x1;
	std::vector<double> x2;
	std::vector<double> x3;
	std::vector<double> y1;
	std::vector<double> y2;
	std::vector<double> y3;

	// loop on file
	while (1)
	{
		data >> buf;
		if (data.eof())
		{break;}
		x1.push_back(buf);
		data >> buf;
		y1.push_back(buf);
		data >> buf;
		x2.push_back(buf);
		data >> buf;
		y2.push_back(buf);
		data >> buf;
		x3.push_back(buf);
		data >> buf;
		y3.push_back(buf);	
	}

	// functions
	//TF2* f = new TF2 ("himmelblau", "(x*x + y - 11)*(x*x + y - 11) + (x + y*y - 7)*(x + y*y - 7)", 0, 10, 0, 10); // himmelblau
	gStyle->SetOptTitle(0);	
	TF2* f = new TF2 ("rosenbrock", "100*(y-x*x)*(y-x*x) + (1-x)*(1-x)", -1.5, 2.2, -0.5, 2.2); // rosenbrock
 	f->SetNpx(1000);
	f->SetNpy(1000);
	f->GetXaxis()->SetTitle("x");
	f->GetYaxis()->SetTitle("y");
	TCanvas* c1 = new TCanvas;
	c1->SetLogz();	
	rosenbrock->Draw("COLZ");

	
	// loop on vertex
	std::vector<TLine*> vl1;
	std::vector<TLine*> vl2;
	std::vector<TLine*> vl3;
	TLine* l1;
	TLine* l2;
	TLine* l3;	
	for (int i = 0; i < x1.size(); i++)
	{
		l1 = new TLine(0,0,0,0);
		l2 = new TLine(0,0,0,0);
		l3 = new TLine(0,0,0,0);	
		
		l1->SetLineWidth(1.5);
		l2->SetLineWidth(1.5);
		l3->SetLineWidth(1.5);

		l1->SetLineColor(kBlue -10 + i);
		l2->SetLineColor(kBlue -10 + i);
		l3->SetLineColor(kBlue -10 + i);

		l1->SetX1(x1.at(i));
		l1->SetY1(y1.at(i));
		l1->SetX2(x2.at(i));
		l1->SetY2(y2.at(i));

		l2->SetX1(x2.at(i));
		l2->SetY1(y2.at(i));
		l2->SetX2(x3.at(i));
		l2->SetY2(y3.at(i));

		l3->SetX1(x3.at(i));
		l3->SetY1(y3.at(i));
		l3->SetX2(x1.at(i));
		l3->SetY2(y1.at(i));

		l1->Draw("same");
		l2->Draw("same");
		l3->Draw("same");
	}

	TMarker* min = new TMarker (1,1,0);
	min ->SetMarkerColor (kBlue);
	min->SetMarkerStyle(20);
	min->SetMarkerSize (1.0);
	min->Draw();

}