// strahlungsgesetz.C
{
	gROOT->Reset();
	gROOT->SetStyle("Plain");
	using namespace std;
	
	// Parameter
	double temp = 2700;         // [K]
	double sichtbar_min = 380;  // [nm]
	double sichtbar_max = 780;  // [nm]
	
	// Funktion generieren
	double min = 0, max = 5; // [µm]
	#define n 300;
	
	TF1 *f = new TF1("planck", "TMath::Hbar()*TMath::Power(TMath::C(),2)/TMath::Power(x*1e-6,5) * 1/(TMath::Exp(TMath::H()*TMath::C()/(x*1e-6)/TMath::K()/[0]) - 1)", min,max);
	f->SetParameter(0,temp); // Temperatur [K]
	
	double x[n], y[n], y_max = 0;
	for (Int_t i=0; i<n; i++) {
		x[i] = (double)i * max / (double)n;
		y[i] = f->Eval(x[i]);
		if ( y[i] > y_max ) y_max = y[i];
	}
	
	
	// Graph zeichnen
	TCanvas *c1 = new TCanvas("strahlungsgesetz","Plancksches Strahlungsgesetz",100,30,1200,500);
	c1->SetTopMargin( 0.05 );
	c1->SetLeftMargin( 0.07 );
	c1->SetRightMargin( 0.02 );
	
	TGraph *gr = new TGraph(n, x, y);
	gr->SetTitle("");
	gr->GetYaxis()->SetTitle("Strahlungsleistung  [Wm^{-3}]");
	gr->GetYaxis()->SetTitleOffset( 0.8 );
	gr->GetYaxis()->SetTickLength( 0.02 );
	gr->GetXaxis()->SetTitle("Wellenl#ddot{a}nge  [#mum]");
	gr->GetXaxis()->SetLimits( min, max );
	gr->Draw("AC");
	
	// Lichtspektrum (Grenzen)
	TLine *l1 = new TLine( sichtbar_min*1e-3,0, sichtbar_min*1e-3,y_max*1.08 );
	l1->SetLineColor(kGray);
	l1->SetLineStyle(3);
	l1->Draw("SAME");
	TLine *l2 = new TLine( sichtbar_max*1e-3,0, sichtbar_max*1e-3,y_max*1.08 );
	l2->SetLineColor(kGray);
	l2->SetLineStyle(3);
	l2->Draw("SAME");
	
	
	// Berechne Flächen
	double I_ges = f->Integral(0,100);
	double I_sichtbar = f->Integral(sichtbar_min*1e-3, sichtbar_max*1e-3);
	double I_nicht_sichtbar = I_ges - I_sichtbar;
	double prozent_sichtbar = I_sichtbar / I_ges * 100;
	double prozent_nicht_sichtbar = I_nicht_sichtbar / I_ges * 100;
	
	char text[400];
	TPaveText *box = new TPaveText( 0.54,0.73, 0.99,0.98, "NDC" );
	box->SetFillColor( kWhite );
	box->SetBorderSize( 3 );
	box->SetTextSize( 0.05 );
	box->SetTextAlign( 12 );
	
	box->AddText( 0.03,0.87, "Fl#ddot{a}che (gesamt):" );
    sprintf( text, "%4.1f #upoint 10^{9} Wm^{-2}  (%5.1f%%)", I_ges*1e-9, 100 ); box->AddText( 0.52,0.87, text );
	box->AddText( 0.03,0.55, "Fl#ddot{a}che (sichtbar):" );
    sprintf( text, "%5.1f #upoint 10^{9} Wm^{-2}  (%7.1f%%)", I_sichtbar*1e-9, prozent_sichtbar ); box->AddText( 0.52,0.55, text );
	box->AddText( 0.03,0.23, "Fl#ddot{a}che (nicht sichtbar):" );
    sprintf( text, "%4.1f #upoint 10^{9} Wm^{-2}  (%6.1f%%)", I_nicht_sichtbar*1e-9, prozent_nicht_sichtbar  ); box->AddText( 0.52,0.23, text );
	box->Draw();
	
	return c1;
}

