/* * FitResponsePtEta.C * * Created on: 30.08.2011 * Author: huelsing */ void FitResponsePtEta() { TH1::AddDirectory(kFALSE); TH1::SetDefaultSumw2(true); TFile *f = new TFile("/atlas_tmp/huelsing/ganga/JetResponse2.root"); TH3D* input = (TH3D*) f->Get("Kt6TopoEM_response_eta_pt"); TH2D* ouput2 = (TH2D*) f->Get("Response_eta_Kt6TopoEM_bad_1"); TH1D* output = ouput2->ProjectionX("output"); TString name; TCanvas c; c.cd(); output->GetYaxis()->SetRangeUser(0, 5.5); double response; TH1D *htemp; TH2D *h2; TH1D* v_output[34]; // tried to store the histograms in an array and draw them later... TF1* f_fit; int binpt; int hist = 0; //================================= // run over z-axis of 3D-histogram //================================= for (int ptbin = 1; ptbin < input->GetNbinsZ(); ptbin = ptbin + 30) { output->Clear(); //====Generate name for hists name = "fittedresponse"; binpt = input->GetZaxis()->GetBinLowEdge(ptbin); name += binpt; //====Produce projections for (int bin = 1; bin < input->GetNbinsY(); bin++) { //Get only one slice in z input->GetZaxis()->SetRangeUser(ptbin, ptbin + 30); //Projection h2 = (TH2D*) input->Project3D("xy"); htemp = h2->ProjectionY("response", bin, bin + 1, "e"); //Fit Landau in every Histogram if (htemp->GetEntries() != 0) { htemp->Fit("landau", "Q", "S"); f_fit = htemp->GetFunction("landau"); response = f_fit->GetParameter(1); //Fill peak position and width as content and error output->SetBinContent(bin, response); output->SetBinError(bin, f_fit->GetParameter(2)); } else { //if no fit data exists, set to 0 output->SetBinContent(bin, 0); output->SetBinError(bin, 0); } } // v_output[hist] = output; //fill array and indrease couter for array // hist++; if (ptbin == 1) output->Draw(); else output->Draw(""); // output->Draw("same"); c.SaveAs("plots/" + name + ".gif"); } c.SaveAs("test.gif"); // TCanvas c2; // c2.cd(); // v_output[0]->Draw(); // for (int i = 1; i < 34; i++) // { // if (v_output[i] != 0) // { // v_output[i]->Draw("SAME *HIST"); // cout << "Hist " << i << " filled" << endl; // } // else // cout << "HAAALT" << endl; // c2.SaveAs("plots/CHICHI.gif"); // } c2.SaveAs("plots/CHICHI.gif"); }