#include #include #include #include #include #include #include #include #include #include #include //root[0] .x fitD0InvMass.C+ //root[1] fitD0(...) //input: nsigma is the number of sigma in which significance, signal and background are calculated //fit of histograms in the directory PWG3_D2H_D0InvMass of AnalysisResults.root . Must specify the list name where the histo are stored. Produce a root file with the fitted histos and a text file with signal, background and significance void fitD0(Int_t rebin=0,TString listname="coutputmassD0mycuts",Int_t nsigma=3, TString pathin="./",TString pathout="./",Int_t btype=2){ TString file="AnalysisResults.root"; //"D0InvMass.root"; file.Prepend(pathin); cout<<"Opening "<IsOpen()){ cout<<"File "<SetOptFit(0111); gStyle->SetOptStat("nemrou"); const Int_t npt=5; TString dirname="PWG3_D2H_D0InvMass"; TDirectoryFile *dir=(TDirectoryFile*)fin->GetDirectory(dirname); TList *lista = (TList*) dir->Get(listname.Data()); if(!lista) { cout<FindObject(nameall); if(!hMass){ cout<GetEntries()<<" * "; //SIGNAL from MC TString namesgn="histSgn_"; namesgn+=(ipt+1); TH1F *hSgn=(TH1F*)lista->FindObject(namesgn); if(!hSgn){ cout<GetEntries()<<" * "; //BACKGROUND from MC TString namebkg="histBkg_"; namebkg+=(ipt+1); TH1F *hBkg=(TH1F*)lista->FindObject(namebkg); if(!hBkg){ cout<GetEntries()<<" * "; //REFLECTED SIGNAL from MC TString namerfl="histRfl_"; namerfl+=(ipt+1); TH1F *hRfl=(TH1F*)lista->FindObject(namerfl); if(!hRfl){ cout<GetEntries()<<" *\n"; out<<"*************************************************\n"; if(rebin!=0){ hSgn->Rebin(rebin); hBkg->Rebin(rebin); hRfl->Rebin(rebin); } Double_t min, max; Int_t nbin; Double_t sgn,errsgn,errsgn2=0,bkg,errbkg,errbkg2=0,sgnf,errsgnf,sgnfMC; Double_t meanfrfit,sigmafrfit, meanMC=hSgn->GetMean(),sigmaMC=hSgn->GetRMS(); Double_t width=0; nbin=hMass->GetNbinsX(); min=hMass->GetBinLowEdge(1); max=min+nbin*hMass->GetBinWidth(nbin); //FIT: TString namentu="ntupt3bin"; if(init) fitter->InitNtuParam((char*)namentu.Data()); // - all fitter->SetHisto(hMass); fitter->SetRangeFit(min, max); //fitter->SetRangeFit(1.83,1.89); fitter->SetType(btype,0);//(b,s) if(rebin!=0) fitter->RebinMass(rebin); Bool_t fitOK=fitter->MassFitter(kFALSE); //kFALSE = do not draw if(!fitOK) { out<<"Fit return kFALSE, skip "<GetName()<Reset(); //delete histogram set continue; } width=fitter->GetHistoClone()->GetBinWidth(3); cout<<"\nChi^2 = "<GetChiSquare()<<"\t Reduced Chi^2 = "<GetReducedChiSquare()<GetMean(); sigmafrfit=fitter->GetSigma(); out<<"mean = "<GetName(); out<<": \nSgn not available"<WriteHisto(pathout); hMass= fitter->GetHistoClone(); //TH1F *hc=fitter->GetHistoClone(); //TF1 *fbtest=hc->GetFunction("funcbkgRecalc"); //new version of ALiHFMassFitter fitter->FillNtuParam(); Double_t limsx,limdx; limsx=meanfrfit-nsigma*sigmafrfit; limdx=meanfrfit+nsigma*sigmafrfit; // limsx=meanMC-nsigma*sigmaMC; //limdx=meanMC+nsigma*sigmaMC; //determine limit of nsigma in bins Int_t binsx,bindx; binsx=hMass->FindBin(limsx); if (limsx > hMass->GetBinCenter(binsx)) binsx++; bindx=hMass->FindBin(limdx); if (limdx < hMass->GetBinCenter(bindx)) bindx--; //reconvert bin in x Double_t sxr,dxr; sxr=hMass->GetBinLowEdge(binsx); dxr=hMass->GetBinLowEdge(bindx+1); fitter->Signal(sxr,dxr,sgn,errsgn); fitter->Background(sxr,dxr,bkg,errbkg); fitter->Significance(sxr,dxr,sgnf,errsgnf); Float_t inttot,intsgn,intsgnerr; Int_t np=-99; switch (btype){ case 0: //expo np=2; break; case 1: //linear np=2; break; case 2: //pol2 np=3; break; case 3: //no bkg np=1; break; } TF1 *fmass=hMass->GetFunction("funcmass"); if (fmass){ inttot=fmass->GetParameter(0); intsgn=fmass->GetParameter(np); intsgnerr=fmass->GetParError(np); //cout<<"i = "<WriteNtuple(pathout); out<Reset(); //delete histogram set init=kFALSE; } out.close(); }