//basic C++ commands #include #include using namespace std; // ROOT header #include "Riostream.h" #include "TROOT.h" #include "TBuffer.h" #include "TApplication.h" #include "TCanvas.h" #include "TStyle.h" #include "TLegend.h" #include "TLatex.h" #include "TH1.h" #include "TH2.h" #include "TF1.h" #include "TH1D.h" #include "TGraph.h" #include "TGraphErrors.h" #include "TMarker.h" #include "TString.h" #include "TFile.h" #include "TMath.h" #include "TVector3.h" #include "TLine.h" #include "TBranch.h" #include "TTree.h" #include "TPad.h" #include "TChain.h" #include "TSystem.h" #include "TRandom.h" //fitfunction algorithm double fitFunction(double *x, double *par) { if (x[0] <= par[1] ) { //for four/second fit function .79, .791 TF1::RejectPoint(); return 0; } return (par[0]*(x[0]-par[1])*TMath::Exp(-(x[0]-par[1])*(x[0]-par[1])/(2*par[2]*par[2]))); } void run() { double a; double tzero; //TH1F *h1 = new TH1F("h1","h11", 24, 0, 24); TH1F *htzero = new TH1F("htzero","htzero", 1000, -7, 12); TH1F *hg = new TH1F("hg","hg", 100, 0, 3); TH2F *hgall = new TH2F("hgall","hgall", 100, 0, 4, 100, 0, 4); TF1 *f1 = new TF1("f1","(x-[0])*TMath::Exp(-((x-[0])*(x-[0]))/(2*[1]*[1]))",0,24); TF1 *fitFcn = new TF1("fitFcn",fitFunction, 0, 24, 3); TCanvas *c6 = new TCanvas("c6", "Z Inv Mass from Different Tags /2 Binning", 1500, 900); for (int k=0; k<20000; k++) { TH1F *h1 = new TH1F("h1","h11", 24, 0, 24); double start=-2; double final=10; double g=start + (gRandom->Rndm() * (final-start)); double b=2.5; hg->Fill(g); f1->SetParameter(0,g); f1->SetParameter(1, b); for (int i=0; i<1000; i++) { a=f1->GetRandom(); if (a>g) h1->Fill(a); } h1->Scale(11); fitFcn->SetParameter(0,h1->GetMaximum()); fitFcn->SetParameter(1,1.7); fitFcn->SetParameter(2,2.5); h1->Fit("fitFcn","Q","RNO"); tzero=fitFcn->GetParameter(1); htzero->Fill(tzero); hgall->Fill(g,tzero); h1->Delete(); } htzero->Draw(); // 2D TCanvas *c5 = new TCanvas("c5", "nt Tags /2 Binning", 1500, 900); gStyle->SetPalette(1); hgall->Draw("COLZ"); hgall->SetXTitle("g"); hgall->SetYTitle("g from fit"); }