TF1 *f_pol4(char *funcn, double min, double max, bool skippeak) { TF1 *retf = new TF1(funcn,&d_pol4,min,max,7); if (skippeak) { retf->FixParameter(5,0.74); retf->FixParameter(6,0.85); } else { retf->FixParameter(5,0); retf->FixParameter(6,0); } return retf; }
void Fit(TH1D* hAll,TH1D* hSignal){ Double_t par[3]; hSignal->Fit("gaus","Q",""); hSignal->GetFunction("gaus")->GetParameters(par); TF1* fitSB = new TF1("fitSB","gaus(0)+pol2(3)",1.10,1.13); fitSB->FixParameter(0,par[0]); fitSB->FixParameter(1,par[1]); fitSB->FixParameter(2,par[2]); hAll->Fit("fitSB","","",1.10,1.13); hSignal->GetFunction("gaus") ->SetLineWidth(2); hAll ->GetFunction("fitSB")->SetLineWidth(2); hSignal->GetFunction("gaus") ->SetLineColor(kBlue); hAll ->GetFunction("fitSB")->SetLineColor(kBlue); }
Double_t calc_dNdY(const char *data_file = "pt_RFE", Bool_t show = kFALSE) { TGraphErrors *g = new TGraphErrors(data_file); if (g->IsZombie()) return; TF1 *flt = new TF1("flt", LevyTsallis, 0., 5., 4); flt->SetParameters(2.93483e-02, 2.80382e-01, 8.10224e+00, 1.01944e+00); flt->FixParameter(3, 1.019445); Double_t fitmin = 0.25, fitmax = 5.25; // !!! g->Fit(flt, "Q", "", fitmin, fitmax); g->Fit(flt, "Q", "", fitmin, fitmax); g->Fit(flt, "Q", "", fitmin, fitmax); Double_t first, last; // !!! bining sensibility !!! Int_t graph_range[2] = {2, 23}; // [2] = 0.05 - 0.01, [23] = 4.70 + 0.01 // interval 1 first = 0.0; // !!! last = g->GetX()[graph_range[0]] - g->GetErrorX(graph_range[0]); Double_t fi1 = flt->Integral(first, last); // interval 2 first = last; last = g->GetX()[graph_range[1]] + g->GetErrorX(graph_range[1]); Double_t fi2 = flt->Integral(first, last); Double_t gi2 = 0.0; for (Int_t ip = graph_range[0]; ip <= graph_range[1]; ip++) gi2 += g->GetY()[ip]*g->GetErrorX(ip)*2.0; // interval 3 first = last; last = 30.0; // !!! Double_t fi3 = flt->Integral(first, last); Double_t result = fi1 + gi2 + fi3; if (!show) { delete g; delete flt; return result; } Printf("function: %f \t %f \t %f", fi1, fi2, fi3); Printf("graph: \t \t \t %f", gi2); Printf("result => %f", result); g->Draw("AP"); gPad->SetLogy(); return result; }
void example(double E0 = 50, int nevents = 100000) { TStopwatch timer; // 12C* -> 3(4He) // compound nucleus = carbon KVNucleus CN(6, 12); CN.SetExcitEnergy(E0); // decay products KVEvent decay; KVNucleus* n = decay.AddParticle(); n->SetZandA(2, 4); n = decay.AddParticle(); n->SetZandA(2, 4); n = decay.AddParticle(); n->SetZandA(2, 4); MicroStat::mdweight gps; Double_t etot = E0 + decay.GetChannelQValue(); if (etot <= 0) { printf("Break-up channel is not allowed\n"); return; } gps.SetWeight(&decay, etot); gps.initGenerateEvent(&decay); TH1F* h1 = new TH1F("h1", "Kinetic energy of alpha particle 3", 200, 0, etot * 2. / 3.); h1->Sumw2(); KVEvent event; while (nevents--) { gps.GenerateEvent(&decay, &event); h1->Fill(event.GetParticle(3)->GetKE()); gps.resetGenerateEvent(); } h1->Draw(); TF1* EDis = new TF1("EDis", edist, 0., etot, 3); EDis->SetNpx(500); EDis->SetParLimits(0, 0, 1.e+08); EDis->SetParLimits(1, 0, 2 * etot); EDis->FixParameter(2, 3); gStyle->SetOptFit(1); h1->Fit(EDis, "EM"); timer.Print(); }
TF1* GetFitFunc_ZYAM_poor(TH1D* h) { TH1D* hcorrphi = (TH1D*)h->Clone(h->GetName()); double histminY = hcorrphi->GetBinContent(10); double histminX = 1.0; //hcorrphi->SetAxisRange(-0.01,1.2,"X"); TF1* fitfunc = new TF1(Form("fitfunc_%s",h->GetName()),"[0]+[1]*(x-[2])*(x-[2])+[3]*(x-[2])*(x-[2])*(x-[2])",0.5,1.5); //std 0.6 1.55 vs pT ; 0.6 1.8 vs eta fitfunc->SetParameters(histminY,0.0002,histminX,0.0001); fitfunc->SetParLimits(1,0,1000); fitfunc->SetParLimits(2,0.5,1000); fitfunc->FixParameter(3,0); for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit(Form("fitfunc_%s",h->GetName()),"RNO"); return fitfunc; }
TH1D* GetJetCorrFunc1D_ZYA1(int itrg, int jass) { TH1D* hcorrphi = (TH1D*)GetRawCorrFunc1D_ratio(itrg,jass); TH1D* hcorrphi_clone = (TH1D*)hcorrphi->Clone(Form("corrphi_clone_itrg%d_jass%d",itrg,jass)); hcorrphi->SetAxisRange(0.5,2.0,"X"); double histminY = hcorrphi->GetMinimum(); TF1* fitfunc = new TF1("fitfunc","[0]+[1]*x",0.8,1.2); fitfunc->SetParameters(histminY,0); fitfunc->FixParameter(1,0); for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit("fitfunc","RNO"); float level = fitfunc->GetParameter(0); for(int ibin=1;ibin<=hcorrphi_clone->GetNbinsX();ibin++) hcorrphi_clone->SetBinContent(ibin,hcorrphi_clone->GetBinContent(ibin)-level); float max = hcorrphi_clone->GetBinContent(hcorrphi_clone->GetMaximumBin()); hcorrphi_clone->SetAxisRange(ymin,max*1.3,"Y"); hcorrphi_clone->SetAxisRange(-PI/2.,3.*PI/2.,"X"); delete fitfunc; return hcorrphi_clone; }
TF1* GetFitFunc_ZYAM_pp(TH1D* h) { TH1D* hcorrphi = (TH1D*)h->Clone(h->GetName()); // double histminY = hcorrphi->GetBinContent(hcorrphi->GetMinimumBin()); // double histminX = hcorrphi->GetBinCenter(hcorrphi->GetMinimumBin()); double histminY = hcorrphi->GetBinContent(hcorrphi->FindBin(1.2)); double histminX = hcorrphi->GetBinCenter(hcorrphi->FindBin(1.2)); //hcorrphi->SetAxisRange(-0.01,1.2,"X"); TF1* fitfunc = new TF1(Form("fitfunc_%s",h->GetName()),"[0]+[1]*(x-[2])*(x-[2])+[3]*abs((x-[2])*(x-[2])*(x-[2]))",0.5,2.5); //std 0.6 1.55 vs pT ; 0.6 1.8 vs eta fitfunc->SetParameters(histminY,0.002,histminX,0.0); fitfunc->SetParLimits(1,0,1000); fitfunc->SetParLimits(2,0.2,2.0); // fitfunc->SetParLimits(3,0,100); fitfunc->FixParameter(3,0); for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit(Form("fitfunc_%s",h->GetName()),"NO","",histminX-0.6,histminX+0.6); fitfunc->SetName(Form("fitfunc_%s_%.3f",h->GetName(),fitfunc->GetParameter(0))); return fitfunc; }
void vertexAssociationAnalysis(TH1* fraction, unsigned int index, double& slope,double& slopeError,double& constNorm,double& constError,TGraphErrors*& graph,TFitResultPtr fitRes) { // do the fit if(constrainSlope) { fraction->Fit("expo","LS","",xminfit[index],xmaxfit[index]); TF1* expo = (TF1*)gROOT->FindObjectAny("expo"); expo->FixParameter(1,contrainedSlopeParameters[0]+contrainedSlopeParameters[1]*(index+1)); fitRes = fraction->Fit("expo","LSB","",xminfit[index],xmaxfit[index]); expo->SetParLimits(1,-10000,10000); } else { // fitRes = fraction->Fit("expo","LS","",xminfit[index],xmaxfit[index]); fitRes = fraction->Fit("expo","LS","",getConstrainedMinimum(fraction,0.1,0.3),getConstrainedMaximum(fraction,0.7,0.9)); } // estimate efficiency and purity as a function of the cut double *efficiency, *purity, *efferror, *purerror; efficiency = new double[nSteps]; purity = new double[nSteps]; efferror = new double[nSteps]; purerror = new double[nSteps]; unsigned int step = 0; for(float cut=cutmin; cut<cutmax; cut += (cutmax-cutmin)/float(nSteps), ++step) { estimateEfficiencyAndPurity(fraction,cut,efficiency[step],purity[step],efferror[step],purerror[step],fitRes); } // output: the graph with efficiency and purity vs cut and the expo slope slope = fraction->GetFunction("expo")->GetParameter(1); slopeError = fraction->GetFunction("expo")->GetParError(1); constNorm = fraction->GetFunction("expo")->GetParameter(0); constError = fraction->GetFunction("expo")->GetParError(0); //slope = result->Parameter(1); graph = new TGraphErrors(nSteps,purity,efficiency,purerror,efferror); //graph = new TGraph(nSteps,purity,efficiency); delete[] efficiency; delete[] purity; delete[] efferror; delete[] purerror; }
void massfitvn_Jpsi() { double fit_range_low = 2.6; double fit_range_high = 3.5; double JPsi_mass = 3.097; int npt = 7; TFile* file1 = TFile::Open("HM185_JpsivnHist_etagap1p5_v30_eff_extdeta.root"); TFile ofile("v2vspt_fromfit_jpsi_HM185_250_deta1p5_doubleCB_v30_eff_exp_extdeta.root","RECREATE"); //v12 double alpha_fit[14] = {4.30986,3.50841,3.03436,2.73741,2.37934,2.10685,2.03615}; double n_fit[14] = {1.88853,1.9839,2.03198,2.07295,2.11001,2.15234,2.10154}; TF1* fmasssig[9]; TF1* fmassbkg[9]; TF1* fmasstotal[9]; TF1* fvn[9]; double pt[13]; double KET_ncq[13]; double v2[13]; double v2e[13]; double v2_bkg[13]; double v2_ncq[13]; double v2e_ncq[13]; double ptbin[14] = {0.2, 1.8, 3.0, 4.5, 6.0, 8.0, 10, 20}; double a[13]; double b[13]; double sigfrac[13]; TCanvas* c[10]; for(int i=0;i<npt;i++) { c[i] = new TCanvas(Form("c_%d",i),Form("c_%d",i),800,400); c[i]->Divide(2,1); } for(int i=0;i<npt;i++) { c[i]->cd(1)->SetTopMargin(0.06); c[i]->cd(1)->SetLeftMargin(0.18); c[i]->cd(1)->SetRightMargin(0.043); c[i]->cd(1)->SetBottomMargin(0.145); c[i]->cd(2)->SetTopMargin(0.06); c[i]->cd(2)->SetLeftMargin(0.18); c[i]->cd(2)->SetRightMargin(0.043); c[i]->cd(2)->SetBottomMargin(0.145); } TCanvas* c2 = new TCanvas("c2","c2",100,100); TLatex* tex = new TLatex; tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); TLatex* texCMS = new TLatex; texCMS->SetNDC(); texCMS->SetTextFont(42); texCMS->SetTextSize(0.05); texCMS->SetTextAlign(12); TH1D* hist = new TH1D("hist","",10,2.6,3.5); hist->SetLineWidth(0); //hist->GetYaxis()->SetRangeUser(0,0.3); hist->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)"); hist->GetYaxis()->SetTitle("v_{2}^{S+B}"); hist->GetXaxis()->CenterTitle(); hist->GetYaxis()->CenterTitle(); hist->GetXaxis()->SetTitleOffset(1.3); hist->GetYaxis()->SetTitleOffset(2); hist->GetXaxis()->SetLabelOffset(0.007); hist->GetYaxis()->SetLabelOffset(0.007); hist->GetXaxis()->SetTitleSize(0.045); hist->GetYaxis()->SetTitleSize(0.045); hist->GetXaxis()->SetTitleFont(42); hist->GetYaxis()->SetTitleFont(42); hist->GetXaxis()->SetLabelFont(42); hist->GetYaxis()->SetLabelFont(42); hist->GetXaxis()->SetLabelSize(0.04); hist->GetYaxis()->SetLabelSize(0.04); hist->SetMinimum(0.01); hist->SetMaximum(0.33); c2->cd(); hist->Draw(); for(int i=0;i<npt;i++) { TH1D* h_data = (TH1D*)file1->Get(Form("massjpsi_pt%d",i)); h_data->SetMinimum(0); h_data->SetMarkerSize(0.8); h_data->SetMarkerStyle(20); h_data->SetLineWidth(1); h_data->SetOption("e"); h_data->Rebin(2); h_data->GetXaxis()->SetRangeUser(2.6,3.5); h_data->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)"); h_data->GetYaxis()->SetTitle("Entries / 10 MeV"); h_data->GetXaxis()->CenterTitle(); h_data->GetYaxis()->CenterTitle(); h_data->GetXaxis()->SetTitleOffset(1.3); h_data->GetYaxis()->SetTitleOffset(2); h_data->GetXaxis()->SetLabelOffset(0.007); h_data->GetYaxis()->SetLabelOffset(0.007); h_data->GetXaxis()->SetTitleSize(0.045); h_data->GetYaxis()->SetTitleSize(0.045); h_data->GetXaxis()->SetTitleFont(42); h_data->GetYaxis()->SetTitleFont(42); h_data->GetXaxis()->SetLabelFont(42); h_data->GetYaxis()->SetLabelFont(42); h_data->GetXaxis()->SetLabelSize(0.04); h_data->GetYaxis()->SetLabelSize(0.04); h_data->GetXaxis()->SetNoExponent(true); ((TGaxis*)h_data->GetXaxis())->SetMaxDigits(7); h_data->SetMaximum(h_data->GetMaximum()*1.5); TH1D* h_pt = (TH1D*)file1->Get(Form("Ptjpsi_eff_pt%d",i)); TH1D* h_KET = (TH1D*)file1->Get(Form("KETjpsi_eff_pt%d",i)); pt[i] = h_pt->GetMean(); KET_ncq[i] = h_KET->GetMean()/2.0; c[i]->cd(1); /*p definitions [0] CB1 yield; [1] Common mean of CB and Gaus; [2] CB1 sigma; [3] CB n; [4] CB alpha; [5] CB2 yield; [6] CB2 sigma; [7-10] poly 3; [11] v2 signal; [12-13] v2 bkg; */ TF1* f = new TF1(Form("f_%d",i), crystalball_function_total, fit_range_low, fit_range_high, 11); f->SetLineColor(2); f->SetLineWidth(1); f->SetParNames("CB1_Yield","common_mean","CB1_sigma","CB_N","CB_Alpha","CB2_Yield","CB2_Sigma","Pol0","Pol1","Pol2","Pol3"); //first fit data mass signal + bkg f->SetParameter(0,10000.); f->SetParameter(1,JPsi_mass); f->SetParameter(2,0.03); f->SetParameter(3,1.0); f->SetParameter(4,1.0); f->SetParameter(5,10000); f->SetParameter(6,0.03); f->SetParLimits(2,0.01,0.1); f->SetParLimits(6,0.01,0.1); //fix alpha & n from MC f->FixParameter(4,alpha_fit[i]); f->FixParameter(3,n_fit[i]); f->FixParameter(1,JPsi_mass); //for first few attempt fix mean of gaussian to get reasonable estimation of other pars; later open it up h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high); f->ReleaseParameter(1); //now let gaussian mean float h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"L m","",fit_range_low,fit_range_high); //draw D0 signal separately TF1* f1 = new TF1(Form("f_sig_%d",i), crystalball_function_signal, fit_range_low, fit_range_high, 7); f1->SetLineColor(kOrange-3); f1->SetLineWidth(1); f1->SetLineStyle(2); f1->SetFillColorAlpha(kOrange-3,0.3); f1->SetFillStyle(1001); f1->FixParameter(0,f->GetParameter(0)); f1->FixParameter(1,f->GetParameter(1)); f1->FixParameter(2,f->GetParameter(2)); f1->FixParameter(3,f->GetParameter(3)); f1->FixParameter(4,f->GetParameter(4)); f1->FixParameter(5,f->GetParameter(5)); f1->FixParameter(6,f->GetParameter(6)); fmasssig[i] = (TF1*)f1->Clone(); fmasssig[i]->SetName(Form("masssigfcn_pt%d",i)); fmasssig[i]->Write(); f1->Draw("LSAME"); //draw poly bkg separately TF1* f3 = new TF1(Form("f_bkg_%d",i),"[7] + [8]*x + [9]*x*x + [10]*x*x*x", fit_range_low, fit_range_high); f3->SetLineColor(4); f3->SetLineWidth(1); f3->SetLineStyle(2); f3->FixParameter(7,f->GetParameter(7)); f3->FixParameter(8,f->GetParameter(8)); f3->FixParameter(9,f->GetParameter(9)); f3->FixParameter(10,f->GetParameter(10)); fmassbkg[i] = (TF1*)f3->Clone(); fmassbkg[i]->SetName(Form("massbkgfcn_pt%d",i)); fmassbkg[i]->Write(); f3->Draw("LSAME"); tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250"); tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1])); tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94"); texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}"); //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}"); texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}"); TLegend* leg = new TLegend(0.21,0.4,0.5,0.65,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.045); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h_data,"data","p"); leg->AddEntry(f,"Fit","L"); leg->AddEntry(f1,"J/#psi Signal","f"); leg->AddEntry(f3,"Combinatorial","l"); leg->Draw("SAME"); sigfrac[i] = f1->Integral(2.94,3.24)/f->Integral(2.94,3.24); //c->Print(Form("plots/massfit_pt%d.pdf",i)); //fit vn //[9] is vn_sig //[10-11] is vn bkg, const + linear vn(pT) TGraphErrors* vn_data = (TGraphErrors*)file1->Get(Form("v2_mass_pt%d",i)); c[i]->cd(2); hist->Draw(); TF1* fmass_combinemassvnfit = new TF1(Form("fmass_combinemassvnfit_%d",i),crystalball_function_total, fit_range_low, fit_range_high, 11); TF1* fvn_combinemassvnfit = new TF1(Form("fvn_combinemassvnfit_%d",i), crystalball_function_v2, fit_range_low, fit_range_high, 15); fmass_combinemassvnfit->SetLineColor(2); fmass_combinemassvnfit->SetLineWidth(1); fvn_combinemassvnfit->SetLineColor(2); fvn_combinemassvnfit->SetLineWidth(1); ROOT::Math::WrappedMultiTF1 wfmass_combinemassvnfit(*fmass_combinemassvnfit,1); ROOT::Math::WrappedMultiTF1 wfvn_combinemassvnfit(*fvn_combinemassvnfit,1); ROOT::Fit::DataOptions opt; ROOT::Fit::DataRange range_massfit; range_massfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datamass(opt,range_massfit); ROOT::Fit::FillData(datamass, h_data); ROOT::Fit::DataRange range_vnfit; range_vnfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datavn(opt,range_vnfit); ROOT::Fit::FillData(datavn, vn_data); ROOT::Fit::Chi2Function chi2_B(datamass, wfmass_combinemassvnfit); ROOT::Fit::Chi2Function chi2_SB(datavn, wfvn_combinemassvnfit); GlobalChi2_poly3bkg_floatwidth globalChi2(chi2_B, chi2_SB); ROOT::Fit::Fitter fitter; const int Npar = 15; double par0[Npar]; for( int ipar = 0; ipar < f->GetNpar(); ipar++ ) par0[ipar] = f->GetParameter(ipar); par0[11] = 0.01; par0[12] = 0.10; par0[13] = 0.05; par0[14] = 0.01; fitter.Config().SetParamsSettings(Npar,par0); // fix parameter fitter.Config().ParSettings(0).Fix(); fitter.Config().ParSettings(1).Fix(); fitter.Config().ParSettings(2).Fix(); fitter.Config().ParSettings(3).Fix(); fitter.Config().ParSettings(4).Fix(); fitter.Config().ParSettings(5).Fix(); fitter.Config().ParSettings(6).Fix(); fitter.Config().ParSettings(7).Fix(); fitter.Config().ParSettings(8).Fix(); fitter.Config().ParSettings(9).Fix(); fitter.Config().ParSettings(10).Fix(); fitter.Config().MinimizerOptions().SetPrintLevel(0); fitter.Config().SetMinimizer("Minuit2","Migrad"); fitter.FitFCN(Npar,globalChi2,0,datamass.Size()+datavn.Size(),true); ROOT::Fit::FitResult result = fitter.Result(); result.Print(std::cout); fmass_combinemassvnfit->SetFitResult( result, iparmassfit_poly3bkg_floatwidth); fmass_combinemassvnfit->SetRange(range_massfit().first, range_massfit().second); fmass_combinemassvnfit->SetLineColor(kRed); h_data->GetListOfFunctions()->Add(fmass_combinemassvnfit); //c->cd(); //h_data->Draw(); fvn_combinemassvnfit->SetFitResult( result, iparvnfit_poly3bkg_floatwidth); fvn_combinemassvnfit->SetRange(range_vnfit().first, range_vnfit().second); fvn_combinemassvnfit->SetLineColor(2); //fvn_combinemassvnfit->SetLineStyle(2); vn_data->GetListOfFunctions()->Add(fvn_combinemassvnfit); vn_data->SetTitle(""); vn_data->SetMarkerSize(0.8); vn_data->SetLineWidth(1); //c1->cd(); vn_data->Draw("PESAME"); fvn[i] = (TF1*)fvn_combinemassvnfit->Clone(); fvn[i]->SetName(Form("vnfit_pt%d",i)); fvn[i]->Write(); fmasstotal[i] = (TF1*)fmass_combinemassvnfit->Clone(); fmasstotal[i]->SetName(Form("masstotalfcn_pt%d",i)); fmasstotal[i]->Write(); tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250"); tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1])); //tex->DrawLatex(0.22,0.74,"1.4 < |y_{cm}+0.46| < 2.4"); tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94"); //tex->DrawLatex(0.22,0.68,"|#Delta#eta| > 2"); //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}"); texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}"); texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}"); v2[i] = fvn_combinemassvnfit->GetParameter(11); v2e[i] = fvn_combinemassvnfit->GetParError(11); v2_bkg[i] = fvn_combinemassvnfit->GetParameter(12) + fvn_combinemassvnfit->GetParameter(13) * JPsi_mass; v2_ncq[i] = v2[i]/2.0; v2e_ncq[i] = v2e[i]/2.0; a[i] = fvn_combinemassvnfit->GetParameter(12); b[i] = fvn_combinemassvnfit->GetParameter(13); TF1* fvnbkg = new TF1(Form("fvnbkg_%d",1),"( [0] + [1] * x)", fit_range_low, fit_range_high); fvnbkg->FixParameter(0,fvn_combinemassvnfit->GetParameter(12)); fvnbkg->FixParameter(1,fvn_combinemassvnfit->GetParameter(13)); fvnbkg->SetName(Form("fvnbkg_fcn_pt%d",i)); fvnbkg->Write(); fvnbkg->SetLineStyle(7); //fvnbkg->Draw("LSAME"); TF1* fvnsig = new TF1(Form("fvnsig_%d",i),function_v2_sig,fit_range_low,fit_range_high,12); for(int k=0;k<12;k++) { fvnsig->FixParameter(k,fvn_combinemassvnfit->GetParameter(k)); } fvnsig->SetLineColor(kOrange-3); fvnsig->SetLineWidth(1); fvnsig->SetLineStyle(2); fvnsig->SetFillColorAlpha(kOrange-3,0.3); fvnsig->SetFillStyle(1001); //fvnsig->Draw("LSAME"); TLegend* leg1 = new TLegend(0.72,0.525,0.91,0.65,NULL,"brNDC"); leg1->SetBorderSize(0); leg1->SetTextSize(0.045); leg1->SetTextFont(42); leg1->SetFillStyle(0); leg1->AddEntry(h_data,"data","p"); leg1->AddEntry(fvn_combinemassvnfit,"Fit","l"); //leg1->AddEntry(fvnsig,"#alpha(#it{m}_{#mu#mu})v_{2}^{S}","f"); leg1->Draw("SAME"); double xmass[200]; double pullmass[200]; float Chi2=0; int ndf = (fit_range_high - fit_range_low)/0.01 - 8; for(int k=0;k<h_data->GetNbinsX();k++) { xmass[k] = h_data->GetBinCenter(k); pullmass[k] = (h_data->GetBinContent(k) - fmass_combinemassvnfit->Eval(xmass[k]))/h_data->GetBinError(k); if(fabs(pullmass[k])<5) { //cout<<pullmass[k]<<endl; Chi2 += pullmass[k]*pullmass[k]; } } c[i]->cd(1); tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.0f/%d",Chi2,ndf)); double xv2[200]; double pullv2[200]; double v2y[200]; float Chi2v2=0; int ndfv2 = 8 - 4; //Nbin - Npar for(int k=0;k<vn_data->GetN()-1;k++) { vn_data->GetPoint(k,xv2[k],v2y[k]); //xv2[k] = vn_dara->GetBinCenter(k); pullv2[k] = (v2y[k] - fvn_combinemassvnfit->Eval(xv2[k]))/vn_data->GetErrorY(k); cout<<k<<": "<<pullv2[k]<<endl; if(fabs(pullv2[k])<1000) { //cout<<pullmass[k]<<endl; Chi2v2 += pullv2[k]*pullv2[k]; } cout<<"fcn: "<<fvn_combinemassvnfit->Eval(xv2[k])<<endl; cout<<"data: "<<v2y[k]<<endl; } c[i]->cd(2); tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.1f/%d",Chi2v2,ndfv2)); } for(int i=0;i<npt;i++) { c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.pdf",i)); c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.gif",i)); } TGraphErrors* v2plot = new TGraphErrors(npt,pt,v2,0,v2e); TGraphErrors* v2ncqplot = new TGraphErrors(npt,KET_ncq,v2_ncq,0,v2e_ncq); TGraphErrors* v2bkgplot = new TGraphErrors(npt,pt,v2_bkg,0,0); v2plot->SetName("v2vspt"); v2ncqplot->SetName("v2vsKET_ncq"); v2bkgplot->SetName("v2bkgvspt"); v2plot->Write(); v2ncqplot->Write(); v2bkgplot->Write(); }
//________________________________________________________________________________ void peaks(TH1* h, Int_t np=10, Int_t ij=0) { if (! h) return; npeaks = TMath::Abs(np); if (! c1) c1 = new TCanvas(); else c1->Clear(); if (c2 && ij > 0) {c2->cd(ij); h->Draw(); c2->Update();} c1->Divide(1,2); c1->cd(1); h->Draw(); TH1F *h2 = (TH1F*)h->Clone("h2"); //Use TSpectrum to find the peak candidates TSpectrum *s = new TSpectrum(2*npeaks); Int_t nfound = s->Search(h,5,"",0.05); printf("Found %d candidate peaks to fit\n",nfound); if (! nfound) return; //Estimate background using TSpectrum::Background TH1 *hb = s->Background(h,20,"same"); hb->Draw("same"); c1->Update(); if (c2 && ij > 0) {c2->cd(ij); h->Draw(); c2->Update();} if (np <0) return; //estimate linear background using a fitting method c1->cd(2); TF1 *fline = new TF1("fline","pol1",0,1000); fline->FixParameter(1,0.); h->Fit("fline","qnlw"); if (c2 && ij > 0) {c2->cd(ij+1); h->Draw(); c2->Update(); c1->cd(2);} //Loop on all found peaks. Eliminate peaks at the background level Double_t par[3000]; par[0] = fline->GetParameter(0); par[1] = fline->GetParameter(1); npeaks = 0; Float_t *xpeaks = s->GetPositionX(); Float_t ymax = 0; for (Int_t p=0;p<nfound;p++) { Float_t xp = xpeaks[p]; Int_t bin = h->GetXaxis()->FindBin(xp); Float_t yp = h->GetBinContent(bin); if (yp-3*TMath::Sqrt(yp) < fline->Eval(xp)) continue; par[3*npeaks+2] = yp; if (yp > ymax) ymax = yp; par[3*npeaks+3] = xp; par[3*npeaks+4] = 3; npeaks++; } cout << "Found " << npeaks << " useful peaks to fit" << endl; Int_t NP = 0; Int_t nbad = 0; TString LineH(" {\""); LineH += h->GetName(); LineH += "\""; TString Line(""); struct ParErr_t {Double_t par, err;}; ParErr_t parErr[10]; TF1 *fit = 0; if (ymax > 2*par[0]) { cout << "Now fitting: Be patient" << endl; fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks); TVirtualFitter::Fitter(h2,10+3*npeaks); //we may have more than the default 25 parameters fit->SetParameter(0,par[0]); fit->FixParameter(1,0.); for (Int_t p = 0; p < npeaks; p++) { fit->SetParName(3*p+2,Form("A%i",p)); fit->SetParLimits(3*p+2,0,1e6); fit->SetParameter(3*p+2,par[3*p+2]); fit->SetParName(3*p+3,Form("#mu%i",p)); fit->SetParLimits(3*p+3,TMath::Max(0.,par[3*p+3]-2), TMath::Min(240.,par[3*p+3]+2)); fit->SetParameter(3*p+3,par[3*p+3]); fit->SetParName(3*p+4,Form("#sigma%i",p)); fit->SetParLimits(3*p+4,0.01,20); fit->SetParameter(3*p+4,par[3*p+4]); } fit->SetNpx(1000); h2->SetStats(0); h2->Fit("fit","l"); if (c2 && ij > 0) {c2->cd(ij); h2->Draw("same"); c2->Update(); c1->cd(2);} fit->GetParameters(par); for (Int_t p = 0; p<np;p++) { if (p < npeaks && par[3*p+2] > 5*fit->GetParError(3*p+2) && par[3*p+2] > par[0]) { if (TMath::Abs(par[3*p+4]) > 5.0) nbad++; // Line += Form(",%f,%f,%7.2f,%5.2f",par[3*p+2],fit->GetParError(3*p+2),par[3*p+3],TMath::Abs(par[3*p+4])); parErr[NP].par = par[3*p+3]; parErr[NP].err = TMath::Abs(par[3*p+4]); for (Int_t i = 0; i < NP; i++) { if (parErr[i].par > parErr[NP].par) { ParErr_t temp = parErr[i]; parErr[i] = parErr[NP]; parErr[NP] = temp; } } NP++; } } } for (Int_t p = 0; p < np; p++) { if (p < NP) Line += Form(",%7.2f,%5.2f",parErr[p].par,parErr[p].err); else Line += ",0,0"; } Line += "},"; if (nbad > 1) NP = -NP; // reject whole hybrid LineH += Form(",%3i",NP); cout << LineH << Line << endl; out << LineH << Line << endl; c1->Update(); if (c2) c2->Update(); delete fit; delete s; }
TF1* fitDstar5prongs(TTree* nt, Double_t ptmin, Double_t ptmax) { static int count5p=0; count5p++; TCanvas* c = new TCanvas(Form("c_5p_%d",count5p),"",600,600); TH1D* h = new TH1D(Form("h_5p_%d",count5p),"",60,0.140,0.160); TF1* f = new TF1(Form("f_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*((1-[8])*TMath::Gaus(x,[6],[7])/(sqrt(2*3.14159)*[7])+[8]*TMath::Gaus(x,[6],[9])/(sqrt(2*3.14159)*[9]))",minmass3prong,maxmass3prong); nt->Project(Form("h_5p_%d",count5p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata5p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); f->SetLineColor(4); f->SetParameters(0,0,0,0,0,2e2,1.45491e-1,9e-4,0.1,8e-4); f->FixParameter(9,15e-4); f->FixParameter(6,0.145491); f->FixParameter(7,8e-4); f->SetParLimits(8,0,1); f->SetParLimits(5,0,100000); h->Fit(Form("f_5p_%d",count5p),"LL"); h->Fit(Form("f_5p_%d",count5p),"LL"); h->Fit(Form("f_5p_%d",count5p),"LL","",minmass3prong,maxmass3prong); f->ReleaseParameter(6); f->ReleaseParameter(7); f->ReleaseParameter(9); f->SetParLimits(6,0.144,0.147); f->SetParLimits(7,1e-4,9e-4); f->SetParLimits(9,1e-4,9e-4); h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.148); h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16); TF1* background = new TF1(Form("background_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x"); background->SetParameter(0,f->GetParameter(0)); background->SetParameter(1,f->GetParameter(1)); background->SetParameter(2,f->GetParameter(2)); background->SetParameter(3,f->GetParameter(3)); background->SetParameter(4,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(minmass3prong,maxmass3prong); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_5p_%d",count5p),"[0]*((1-[3])*TMath::Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+[3]*TMath::Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(5),f->GetParameter(6),f->GetParameter(7),f->GetParameter(8),f->GetParameter(9)); mass->SetParError(0,f->GetParError(5)); mass->SetParError(1,f->GetParError(6)); mass->SetParError(2,f->GetParError(7)); mass->SetParError(3,f->GetParError(8)); mass->SetParError(4,f->GetParError(9)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})"); h->SetYTitle("Entries / (1/3 MeV/c^{2})"); h->SetStats(0); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(0.142,0.152); mass->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong; Double_t yieldErr = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong*mass->GetParError(0)/mass->GetParameter(0); TLatex* tex; TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.20,0.79,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); c->SaveAs(Form("plots/pp/DMass_%s_5prongs-%d.pdf",texData[isData].Data(),count5p)); return mass; }
int makeInvMassHistosNoBGKK(){ //Set global style stuff gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetCanvasColor(kWhite); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetTitleBorderSize(0); gStyle->SetOptStat(0); gStyle->SetOptFit(1); gStyle->SetErrorX(0); gStyle->SetTitleW(0.9); gStyle->SetTitleSize(0.05, "xyz"); gStyle->SetTitleSize(0.06, "h"); int NUM_PT_BINS = 20; int NUM_MASS_BINS = 1000; double MASS_LOW = 0.0; double MASS_HIGH = 2.0; string particles [8]; particles[0] = "K*^{+} + K*^{0}"; particles[1] = "K*^{-} + #bar{K}*^{0}"; particles[2] = "K*^{+}"; particles[3] = "K*^{-}"; particles[4] = "K*^{0}"; particles[5] = "#bar{K}*^{0}"; particles[6] = "K*^{0} + #bar{K}*^{0}"; particles[7] = "K*^{+} + K*^{-}"; //at decay point // string folder = "/Users/jtblair/Downloads/kstar_data/decayed/pt02/"; //reconstructed string folder = "/Users/jtblair/Downloads/kstar_data/reconstructed/pt02/"; string files[20]; files[0] = "invm_[0.0,0.2].dat"; files[1] = "invm_[0.2,0.4].dat"; files[2] = "invm_[0.4,0.6].dat"; files[3] = "invm_[0.6,0.8].dat"; files[4] = "invm_[0.8,1.0].dat"; files[5] = "invm_[1.0,1.2].dat"; files[6] = "invm_[1.2,1.4].dat"; files[7] = "invm_[1.4,1.6].dat"; files[8] = "invm_[1.6,1.8].dat"; files[9] = "invm_[1.8,2.0].dat"; files[10] = "invm_[2.0,2.2].dat"; files[11] = "invm_[2.2,2.4].dat"; files[12] = "invm_[2.4,2.6].dat"; files[13] = "invm_[2.6,2.8].dat"; files[14] = "invm_[2.8,3.0].dat"; files[15] = "invm_[3.0,3.2].dat"; files[16] = "invm_[3.2,3.4].dat"; files[17] = "invm_[3.4,3.6].dat"; files[18] = "invm_[3.6,3.8].dat"; files[19] = "invm_[3.8,4.0].dat"; /* string files[8]; files[0] = "invm_[0.0,0.5].dat"; files[1] = "invm_[0.5,1.0].dat"; files[2] = "invm_[1.0,1.5].dat"; files[3] = "invm_[1.5,2.0].dat"; files[4] = "invm_[2.0,2.5].dat"; files[5] = "invm_[2.5,3.0].dat"; files[6] = "invm_[3.0,3.5].dat"; files[7] = "invm_[3.5,4.0].dat"; */ Int_t PARTICLE_NUM = 5; TFile *output = new TFile("20170721_KKbarAdded2_fixedwidth42_recon_pf100_scaled_error05.root", "RECREATE"); TH1D *kstar0mass = new TH1D("kstar0mass", Form("Fit value of M*_{0} vs. p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS, 0.0, 4.0); TH1D *kstar0width = new TH1D("kstar0width", Form("#Gamma_{tot}(M=M*_{0}) vs p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS, 0.0, 4.0); TH1D *kstar0collWidth = new TH1D("kstar0collWidth", Form("Fit value of #Gamma_{coll} component vs. p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS,0.0, 4.0); TH1D *kstar0decWidth = new TH1D("kstar0decWidth", Form("#Gamma_{dec}(M=M*_{0}) component vs. p_{T} for %s;p_{T} (GeV/c);Width (GeV/c^2)", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS,0.0, 4.0); kstar0mass->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0mass->GetYaxis()->SetTitle("Mass (GeV/c^{2})"); kstar0width->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0width->GetYaxis()->SetTitle("Width (GeV/c^2)"); kstar0collWidth->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0collWidth->GetYaxis()->SetTitle("Width (GeV/c^2)"); kstar0mass->SetStats(kFALSE); kstar0width->SetStats(kFALSE); kstar0collWidth->SetStats(kFALSE); kstar0decWidth->SetStats(kFALSE); TF1 *massline = new TF1("massline", "[0]", 0.0, 4.0); massline->SetParameter(0, 0.892); massline->SetLineColor(2); massline->SetLineStyle(7); TF1 *widthline = new TF1("widthline", "[0]", 0.0, 4.0); widthline->SetParameter(0, 0.042); double mass = 0.0, width = 0.0, collWidth = 0.0, massBG=0.0; double massError = 0.0, widthError= 0.0, collWidthError = 0.0, massBGError=0.0; TCanvas *canvas[9]; TCanvas *diffCanvas[9]; TPaveStats *st; TPad *pad; //ofstream integrals; //integrals.open("kstarbar_integrals.txt"); for(int nfile = 0; nfile < NUM_PT_BINS; nfile++){ double meanPT = (double)(nfile*2+1)/10.0; string filename = folder+files[nfile]; string ptLower = filename.substr(filename.find("[")+1, 3); string ptHigher = filename.substr(filename.find(",")+1, 3); TH1D* histos[8]; TH1D* newHistos[8]; TH1D* diffHistos[8]; TH1D* bg[8]; for(int i=0; i<8; i++){ if(nfile<5){ histos[i] = new TH1D(Form("ptbin0%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), NUM_MASS_BINS, MASS_LOW, MASS_HIGH); newHistos[i] = new TH1D(Form("newptbin0%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), 250, MASS_LOW, MASS_HIGH); }else{ histos[i] = new TH1D(Form("ptbin%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), NUM_MASS_BINS, MASS_LOW, MASS_HIGH); newHistos[i] = new TH1D(Form("newptbin%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), 250, MASS_LOW, MASS_HIGH); } histos[i]->GetXaxis()->SetTitle("Invariant Mass (GeV/c^{2})"); histos[i]->GetYaxis()->SetTitle("Counts"); } ifstream input; input.open(filename.c_str()); string line = ""; if(input.good()){ getline(input, line); } double massBin=0.0; double invMass[8]; for(int i=0; i<8; i++){ invMass[i] = 0.0; } int lineNumber = 1; while(1){ input >> massBin >> invMass[0] >> invMass[1] >> invMass[2] >> invMass[3] >> invMass[4] >> invMass[5] >> invMass[6] >> invMass[7]; if(!input.good())break; for(int i =0; i<8; i++){ histos[i]->SetBinContent(lineNumber, invMass[i]/500.0); } if(lineNumber > 440 && lineNumber < 460 && nfile==6){ // printf("mass: %.12f invMass[6]: %.12f\n", massBin, invMass[6]); } lineNumber++; } printf("****** Fits for file: %s ******\n", filename.c_str()); for(int i=PARTICLE_NUM; i<PARTICLE_NUM+1; i++){ //add the K*0 distribution to the K*0bar (K*0 = 4 for decay, K*0 = 3 for reconstructed) histos[i]->Add(histos[3]); if(nfile==0){ canvas[i] = new TCanvas(Form("c%i", i),Form("c%i", i), 0,0,900,900); canvas[i]->Divide(5,4); diffCanvas[i] = new TCanvas(Form("diffC%i", i),Form("diffC%i", i), 0,0,900,900); diffCanvas[i]->Divide(5,4); } //rebin //histos[i]->Sumw2(); histos[i]->Rebin(4); //Fixing the errors to a percentage of the signal region: for(int ibin=1; ibin < histos[i]->GetNbinsX(); ibin++){ histos[i]->SetBinError(ibin, histos[i]->GetBinContent((int)(0.892*(250.0/2.0)))*0.05); newHistos[i]->SetBinContent(ibin, histos[i]->GetBinContent(ibin)); newHistos[i]->SetBinError(ibin, histos[i]->GetBinError(ibin)); } pad = (TPad*)canvas[i]->cd(nfile+1); histos[i]->SetLineColor(1); histos[i]->SetLineWidth(1); histos[i]->GetXaxis()->SetRangeUser(0.7, 1.2); histos[i]->GetYaxis()->SetRangeUser(0, 1.5*histos[i]->GetBinContent(histos[i]->GetMaximumBin())); //histos[i]->SetStats(kFALSE); //histos[i]->Draw("HIST"); printf("mean PT: %f\n", meanPT); TF1 *fit = new TF1(Form("fitPTbin%d00particle%d", nfile*2+1, i), FitFunRelBW, 0.68, 1.05, 5); //TF1 *fit = new TF1(Form("fitPTbin%d00particle%d", nfile*2+1, i), "gaus(0)", 0.86, 0.92); fit->SetParNames("BW Area", "Mass", "Width", "PT", "Temp"); fit->SetParameters(TMath::Power(10.0, (float)(nfile)/1.7), 0.89, 0.1, 0.5, 0.130); //fit->SetParNames("BW Area", "Mass", "Width"); //fit->SetParameters(100, 0.89, 0.0474); //fit->SetParLimits(0, -10, 1.5e9); Float_t max = histos[i]->GetXaxis()->GetBinCenter(histos[i]->GetMaximumBin()); //if(max < 0.91 && max > 0.892){ // fit->SetParLimits(1, max-0.001, max+0.001); //}else{ fit->SetParLimits(1, 0.82, 0.98); //} //fit->SetParLimits(2, 0.005, 0.15); fit->FixParameter(2, 0.042); fit->FixParameter(3, meanPT); //fit->SetParLimits(4, 0.05, 0.2); fit->FixParameter(4, 0.100001); fit->SetLineColor(2); printf("%s\n", fit->GetName()); histos[i]->Fit(Form("fitPTbin%d00particle%d", nfile*2+1, i), "BRIM", "SAME"); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); histos[i]->SetStats(1); histos[i]->Draw(); gPad->Update(); pad->Update(); st = (TPaveStats*)histos[i]->FindObject("stats"); st->SetX1NDC(0.524); st->SetY1NDC(0.680); st->SetX2NDC(0.884); st->SetY2NDC(0.876); //fit->Draw("SAME"); //histos[i]->Draw(); gPad->Update(); pad->Update(); printf("\n"); diffHistos[i] = (TH1D*)histos[i]->Clone(Form("diffPTbin%d00particl%d", nfile*2+1, i)); diffHistos[i]->Add(fit, -1); diffCanvas[i]->cd(nfile+1); diffHistos[i]->Draw("HIST E"); diffHistos[i]->Write(); //counting bins Float_t integral = histos[i]->Integral(1, 500)*500.0; //integrals << integral <<" \n"; histos[i]->Write(); fit->Write(); //Do mass and width vs. pT plots just for K*0 if(i==PARTICLE_NUM){ mass = fit->GetParameter(1); massError = fit->GetParError(1); collWidth = fit->GetParameter(2); collWidthError = fit->GetParError(2); width = Gamma(mass, collWidth); kstar0mass->SetBinContent(nfile+1, mass); kstar0mass->SetBinError(nfile+1, massError); kstar0width->SetBinContent(nfile+1, width); Double_t widthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1) + fitter->GetCovarianceMatrixElement(2,2) + 2.0*GammaDerivative(mass)*fitter->GetCovarianceMatrixElement(1,2)); kstar0width->SetBinError(nfile+1, widthError); kstar0collWidth->SetBinContent(nfile+1, collWidth); kstar0collWidth->SetBinError(nfile+1, collWidthError); kstar0decWidth->SetBinContent(nfile+1, width - collWidth); Double_t decWidthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1)); kstar0decWidth->SetBinError(nfile+1, decWidthError); if(nfile==4){ TCanvas *singlecanvas = new TCanvas("singlecanvas", "singlecanvas", 0,0,600,600); singlecanvas->cd(); printf("Got here! \n"); histos[i]->Draw("HIST E SAME"); fit->SetLineColor(8); fit->SetLineStyle(1); fit->Draw("SAME"); if(fitter){ printf("sig11: %f, sig12: %f, sig21: %f, sig22: %f GammaDer(0.8): %f GammaDer(0.85): %f GammaDer(0.9): %f\n", TMath::Sqrt(fitter->GetCovarianceMatrixElement(1,1)), fitter->GetCovarianceMatrixElement(2,1), fitter->GetCovarianceMatrixElement(1,2), TMath::Sqrt(fitter->GetCovarianceMatrixElement(2,2)), GammaDerivative(0.8), GammaDerivative(0.85), GammaDerivative(0.9)); } } } } printf("************************************************************\n"); } //integrals.close(); /* TH2D *gammaPlot = new TH2D("gammaPlot", "#Gamma_{tot}(M_{0}*);M_{0}*;#Gamma_{coll};#Gamma_{tot}", 100, 0.82, 0.9, 100, 0.0, 0.08); for(int im = 0; im<100; im++){ for(int ig = 0; ig < 100; ig++){ gammaPlot->SetBinContent(im+1, ig+1, Gamma(((0.9-0.82)/(100.0))*((double)(im)) + 0.82, ((0.08)/100.0)*((double)(ig)))); } } TH1D *gammaMassDpnd = gammaPlot->ProjectionX("gammaMassDpnd"); */ TCanvas *masscanvas = new TCanvas("masscanvas", "masscanvas", 50,50, 600, 600); masscanvas->cd(); kstar0mass->Draw(); massline->Draw("SAME"); masscanvas->Write(); for(int i=PARTICLE_NUM; i<PARTICLE_NUM+1; i++){ canvas[i]->Write(); } kstar0mass->Write(); kstar0collWidth->Write(); kstar0decWidth->Write(); kstar0width->Write(); // gammaPlot->Write(); // gammaMassDpnd->Write(); }
void UpsilonMassFit_All(int iSpec = 3, int PutWeight=1) { //See pT Cut double PtCut= 4.0; //minbias integrated, |y|<1.2 and |y|\in[1.2,2.4], centrality [0,10][10,20][20,100]%, pt [0,6.5], [6.5, 10] [10,20] gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetFrameBorderMode(0); gStyle->SetFrameFillColor(0); gStyle->SetCanvasColor(0); gStyle->SetTitleFillColor(0); gStyle->SetStatColor(0); gStyle->SetPadBorderSize(0); gStyle->SetCanvasBorderSize(0); gStyle->SetOptTitle(1); // at least most of the time gStyle->SetOptStat(1); // most of the time, sometimes "nemriou" might be useful to display name, //number of entries, mean, rms, integral, overflow and underflow gStyle->SetOptFit(1); // set to 1 only if you want to display fit results //==================================== Define Histograms==================================================== ofstream dataFile(Form("Eff_Upsilon.txt")); TH1D *diMuonsInvMass_Gen = new TH1D("diMuonsInvMass_Gen","diMuonsInvMass_Gen", 100,8.0,12.0); TH1D *diMuonsPt_Gen = new TH1D("diMuonsPt_Gen","diMuonsPt_Gen", 100,0,30); //Rapidity Gen TH1D *diMuonsRap_Gen0 = new TH1D("diMuonsRap_Gen0","diMuonsRap_Gen0", 100,-5,5); TH1D *diMuonsRap_Gen1 = new TH1D("diMuonsRap_Gen1","diMuonsRap_Gen1", 100,-5,5); TH1D *diMuonsRap_Gen2 = new TH1D("diMuonsRap_Gen2","diMuonsRap_Gen2", 100,-5,5); TH1D *diMuonsRap_Gen3 = new TH1D("diMuonsRap_Gen3","diMuonsRap_Gen3", 100,-5,5); TH1D *diMuonsRap_Gen4 = new TH1D("diMuonsRap_Gen4","diMuonsRap_Gen4", 100,-5,5); TH1D *diMuonsRap_Gen5 = new TH1D("diMuonsRap_Gen5","diMuonsRap_Gen5", 100,-5,5); ////Rapidity Reco TH1D *diMuonsRap_Rec0 = new TH1D("diMuonsRap_Rec0","diMuonsRap_Rec0", 100,-5,5); diMuonsRap_Rec0->SetLineColor(2); TH1D *diMuonsRap_Rec1 = new TH1D("diMuonsRap_Rec1","diMuonsRap_Rec1", 100,-5,5); diMuonsRap_Rec1->SetLineColor(2); TH1D *diMuonsRap_Rec2 = new TH1D("diMuonsRap_Rec2","diMuonsRap_Rec2", 100,-5,5); diMuonsRap_Rec2->SetLineColor(2); TH1D *diMuonsRap_Rec3 = new TH1D("diMuonsRap_Rec3","diMuonsRap_Rec3", 100,-5,5); diMuonsRap_Rec3->SetLineColor(2); TH1D *diMuonsRap_Rec4 = new TH1D("diMuonsRap_Rec4","diMuonsRap_Rec4", 100,-5,5); diMuonsRap_Rec4->SetLineColor(2); TH1D *diMuonsRap_Rec5 = new TH1D("diMuonsRap_Rec5","diMuonsRap_Rec5", 100,-5,5); diMuonsRap_Rec5->SetLineColor(2); TH1D *Bin_Gen = new TH1D("Bin_Gen","Bin_Gen", 40,0,40); //==============================================Define AccEff Stuff here=========================================== // Pt bin sizes int Nptbin=1; double pt_bound[100] = {0}; if(iSpec == 1) { Nptbin = 8; //for plots pt_bound[0] = 0.0; pt_bound[1] = 2.0; pt_bound[2] = 4.0; pt_bound[3] = 6.0; pt_bound[4] = 8.0; pt_bound[5] = 10.0; pt_bound[6] = 14.0; pt_bound[7] = 20.0; pt_bound[8] = 30.0; //pt_bound[0] = 0; //pt_bound[1] = 20.0; //pt_bound[2] = 0.0; //pt_bound[3] = 6.5; //pt_bound[4] = 10.0; //pt_bound[5] = 20.0; } if(iSpec == 2) { Nptbin = 8; pt_bound[0] = -2.4; pt_bound[1] = -1.6; pt_bound[2] = -1.2; pt_bound[3] = -0.8; pt_bound[4] = 0.0; pt_bound[5] = 0.8; pt_bound[6] = 1.2; pt_bound[7] = 1.6; pt_bound[8] = 2.4; //pt_bound[0] = 0.0; //pt_bound[1] = 1.2; //pt_bound[2] = 2.4; } if(iSpec == 3) { Nptbin = 8; // pt_bound[0] = 0.0;//0 //pt_bound[1] = 8.0;//20 //pt_bound[2] = 24.0;//60 //pt_bound[3] = 40.0;//100 //for plots pt_bound[0] = 0.0;//0 pt_bound[1] = 4.0;//10 pt_bound[2] = 8.0;//20 pt_bound[3] = 12.0;//25 pt_bound[4] = 16.0;//50 pt_bound[5] = 20.0;//100 pt_bound[6] = 24.0; pt_bound[7] = 32.0; pt_bound[8] = 40.0; } //X Axis error on Eff graph double PT[100], DelPT[100], mom_err[100]; for (Int_t ih = 0; ih < Nptbin; ih++) { PT[ih] = (pt_bound[ih] + pt_bound[ih+1])/2.0; DelPT[ih] = pt_bound[ih+1] - pt_bound[ih]; mom_err[ih] = DelPT[ih]/2.0; } double genError, recError; double gen_pt[100]={0}, gen_ptError[100]={0}; double rec_pt[100]={0}, rec_ptError[100]={0}; double Eff_cat_1[100]={0},Err_Eff_cat_1[100]={0}; // Histogram arrays TH1D *diMuonsInvMass_GenA[10][1000]; TH1D *diMuonsInvMass_RecA[10][1000]; TH1D *diMuonsPt_GenA[10][1000]; TH1D *diMuonsPt_RecA[10][1000]; char nameGen[10][500], nameRec[10][500], nameGenPt[10][500], nameRecPt[10][500]; for (int ifile = 0; ifile <= 5; ifile++) { for (Int_t ih = 0; ih < Nptbin; ih++) { sprintf(nameGen[ifile],"DiMuonMassGen_pt_%d_%d",ih,ifile); sprintf(nameRec[ifile],"DiMuonMassRec_pt_%d_%d",ih,ifile); sprintf(nameGenPt[ifile],"DiMuonPtGen_pt_%d_%d",ih,ifile); sprintf(nameRecPt[ifile],"DiMuonPtRec_pt_%d_%d",ih,ifile); diMuonsInvMass_GenA[ifile][ih]= new TH1D(nameGen[ifile],nameGen[ifile], 100,8.0,12.0); //for eff Gen; diMuonsInvMass_GenA[ifile][ih]->Sumw2(); diMuonsInvMass_GenA[ifile][ih]->SetMarkerStyle(7); diMuonsInvMass_GenA[ifile][ih]->SetMarkerColor(4); diMuonsInvMass_GenA[ifile][ih]->SetLineColor(4); diMuonsInvMass_RecA[ifile][ih] = new TH1D(nameRec[ifile],nameRec[ifile], 100,8.0,12.0); //for eff Rec; diMuonsInvMass_RecA[ifile][ih]->Sumw2(); diMuonsInvMass_RecA[ifile][ih]->SetMarkerStyle(8); diMuonsInvMass_RecA[ifile][ih]->SetMarkerColor(4); diMuonsInvMass_RecA[ifile][ih]->SetLineColor(4); diMuonsPt_GenA[ifile][ih]= new TH1D(nameGenPt[ifile],nameGenPt[ifile], 100,0,40); //for eff Gen; diMuonsPt_RecA[ifile][ih]= new TH1D(nameRecPt[ifile],nameRecPt[ifile], 100,0,40); //for eff Rec; } } //===========================================Input Root File============================================================ char fileName[10][500]; //0.0380228 0.0480769 0.0293255 0.0125156 0.00336587 0.00276319*2/5 = 0.001105276 //Scales double scale[10]={0}; scale[0]=(6.8802); // pT [0-3] scale[1]=(8.6995); // pT [3-6] scale[2]=(5.3065); // pT [6-9] scale[3]=(2.2647); // pT [9-12] scale[4]=(3.0453); // pT [12-15] scale[5]=(1.0000); // pT [15-30] sprintf(fileName[0],"/home/vineet/HiData/UpsilonData/UpsilonEff/DimuonOnia2Dplots_UpsilonPt03_N.root"); sprintf(fileName[1],"/home/vineet/HiData/UpsilonData/UpsilonEff/DimuonOnia2Dplots_UpsilonPt36_N.root"); sprintf(fileName[2],"/home/vineet/HiData/UpsilonData/UpsilonEff/DimuonOnia2Dplots_UpsilonPt69_N.root"); sprintf(fileName[3],"/home/vineet/HiData/UpsilonData/UpsilonEff/DimuonOnia2Dplots_UpsilonPt912_N.root"); sprintf(fileName[4],"/home/vineet/HiData/UpsilonData/UpsilonEff/DimuonOnia2Dplots_UpsilonPt1215_N.root"); sprintf(fileName[5],"/home/vineet/HiData/UpsilonData/UpsilonEff/DimuonOnia2Dplots_UpsilonPt1530_N.root"); TFile *infile; TTree *tree; TTree *gentree; //===========File loop ====================== for(int ifile =0; ifile<=5; ifile++){ infile=new TFile(fileName[ifile],"R"); tree=(TTree*)infile->Get("SingleMuonTree"); gentree=(TTree*)infile->Get("SingleGenMuonTree"); //Event variables int eventNb,runNb,lumiBlock, gbin, rbin; //Jpsi Variables Double_t JpsiMass,JpsiPt,JpsiRap, JpsiCharge; Double_t JpsiVprob; //2.) muon variables RECO double muPosPx, muPosPy, muPosPz, muPosEta, muPosPt,muPosP; double muNegPx, muNegPy, muNegPz, muNegEta, muNegPt,muNegP; //(1).Positive Muon double muPos_nchi2In, muPos_dxy, muPos_dz, muPos_nchi2Gl; int muPos_found, muPos_pixeLayers, muPos_nValidMuHits,muPos_arbitrated; bool muPos_matches,muPos_tracker; //(2).Negative Muon double muNeg_nchi2In, muNeg_dxy, muNeg_dz, muNeg_nchi2Gl; int muNeg_found, muNeg_pixeLayers, muNeg_nValidMuHits,muNeg_arbitrated; bool muNeg_matches,muNeg_tracker; //Gen Level variables //Gen JPsi Variables double GenJpsiMass, GenJpsiPt, GenJpsiRap; double GenJpsiPx, GenJpsiPy, GenJpsiPz; //2.) Gen muon variables double GenmuPosPx, GenmuPosPy, GenmuPosPz, GenmuPosEta, GenmuPosPt; double GenmuNegPx, GenmuNegPy, GenmuNegPz, GenmuNegEta, GenmuNegPt; //Event variables tree->SetBranchAddress("eventNb",&eventNb); tree->SetBranchAddress("runNb",&runNb); tree->SetBranchAddress("lumiBlock",&lumiBlock); //Jpsi Variables tree->SetBranchAddress("JpsiCharge",&JpsiCharge); tree->SetBranchAddress("JpsiMass",&JpsiMass); tree->SetBranchAddress("JpsiPt",&JpsiPt); tree->SetBranchAddress("JpsiRap",&JpsiRap); tree->SetBranchAddress("JpsiVprob",&JpsiVprob); tree->SetBranchAddress("rbin",&rbin); //muon variable tree->SetBranchAddress("muPosPx",&muPosPx); tree->SetBranchAddress("muPosPy",&muPosPy); tree->SetBranchAddress("muPosPz",&muPosPz); tree->SetBranchAddress("muPosEta",&muPosEta); tree->SetBranchAddress("muNegPx", &muNegPx); tree->SetBranchAddress("muNegPy", &muNegPy); tree->SetBranchAddress("muNegPz", &muNegPz); tree->SetBranchAddress("muNegEta", &muNegEta); //1). Positive Muon tree->SetBranchAddress("muPos_nchi2In", &muPos_nchi2In); tree->SetBranchAddress("muPos_dxy", &muPos_dxy); tree->SetBranchAddress("muPos_dz", &muPos_dz); tree->SetBranchAddress("muPos_nchi2Gl", &muPos_nchi2Gl); tree->SetBranchAddress("muPos_found", &muPos_found); tree->SetBranchAddress("muPos_pixeLayers", &muPos_pixeLayers); tree->SetBranchAddress("muPos_nValidMuHits", &muPos_nValidMuHits); tree->SetBranchAddress("muPos_matches", &muPos_matches); tree->SetBranchAddress("muPos_tracker", &muPos_tracker); tree->SetBranchAddress("muPos_arbitrated", &muPos_arbitrated); //2). Negative Muon tree->SetBranchAddress("muNeg_nchi2In", &muNeg_nchi2In); tree->SetBranchAddress("muNeg_dxy", &muNeg_dxy); tree->SetBranchAddress("muNeg_dz", &muNeg_dz); tree->SetBranchAddress("muNeg_nchi2Gl", &muNeg_nchi2Gl); tree->SetBranchAddress("muNeg_found", &muNeg_found); tree->SetBranchAddress("muNeg_pixeLayers", &muNeg_pixeLayers); tree->SetBranchAddress("muNeg_nValidMuHits", &muNeg_nValidMuHits); tree->SetBranchAddress("muNeg_matches", &muNeg_matches); tree->SetBranchAddress("muNeg_tracker", &muNeg_tracker); tree->SetBranchAddress("muNeg_arbitrated", &muNeg_arbitrated); //====================================Gen Variables========================================================= //Gen Jpsi Variables gentree->SetBranchAddress("GenJpsiMass", &GenJpsiMass); gentree->SetBranchAddress("GenJpsiPt", &GenJpsiPt); gentree->SetBranchAddress("GenJpsiRap", &GenJpsiRap); gentree->SetBranchAddress("GenJpsiPx", &GenJpsiPx); gentree->SetBranchAddress("GenJpsiPy", &GenJpsiPy); gentree->SetBranchAddress("GenJpsiPz", &GenJpsiPz); gentree->SetBranchAddress("gbin",&gbin); //muon variable gentree->SetBranchAddress("GenmuPosPx", &GenmuPosPx); gentree->SetBranchAddress("GenmuPosPy", &GenmuPosPy); gentree->SetBranchAddress("GenmuPosPz", &GenmuPosPz); gentree->SetBranchAddress("GenmuPosEta", &GenmuPosEta); gentree->SetBranchAddress("GenmuNegPx", &GenmuNegPx); gentree->SetBranchAddress("GenmuNegPy", &GenmuNegPy); gentree->SetBranchAddress("GenmuNegPz", &GenmuNegPz); gentree->SetBranchAddress("GenmuNegEta", &GenmuNegEta); //====================================================== Gen tree loop ================================================ int NAccep=0; int nGenEntries=gentree->GetEntries(); cout<<" Total Entries in GenLevel Tree for pT range: "<<fileName[ifile]<<" "<< nGenEntries<< " ========="<<endl; //dataFile<<" Total Entries in GenLevel Tree for pT range: "<<fileName[ifile]<<" "<< nGenEntries<< " ====="<<endl; for(int i=0; i< nGenEntries; i++) { gentree->GetEntry(i); if(i%1000==0){ cout<<" processing record "<<i<<endl; cout<<" Mass "<< GenJpsiMass<< " pT "<< GenJpsiPt << " Y " <<GenJpsiRap<<endl; } bool GenPosIn=0, GenNegIn=0,GenPosPass=0,GenNegPass=0; GenmuPosPt= TMath::Sqrt(GenmuPosPx*GenmuPosPx + GenmuPosPy*GenmuPosPy); GenmuNegPt= TMath::Sqrt(GenmuNegPx*GenmuNegPx + GenmuNegPy*GenmuNegPy); diMuonsInvMass_Gen->Fill(GenJpsiMass); diMuonsPt_Gen->Fill(GenJpsiPt); if(IsAccept(GenmuPosPt, GenmuPosEta)) {GenPosIn=1;} if(IsAccept(GenmuNegPt, GenmuNegEta)) {GenNegIn=1;} if(GenPosIn && GenNegIn ) NAccep++; if(GenPosIn==1 && GenmuPosPt> PtCut) {GenPosPass=1;} if(GenNegIn==1 && GenmuNegPt> PtCut) {GenNegPass=1;} double GenCenWeight=0,GenWeight=0; GenCenWeight=FindCenWeight(gbin); Bin_Gen->Fill(gbin); GenWeight=GenCenWeight*scale[ifile]; if(PutWeight==0){GenWeight=1;} if(GenPosIn && GenNegIn){ if(ifile==0){diMuonsRap_Gen0->Fill(GenJpsiRap);} if(ifile==1){diMuonsRap_Gen1->Fill(GenJpsiRap);} if(ifile==2){diMuonsRap_Gen2->Fill(GenJpsiRap);} if(ifile==3){diMuonsRap_Gen3->Fill(GenJpsiRap);} if(ifile==4){diMuonsRap_Gen4->Fill(GenJpsiRap);} if(ifile==5){diMuonsRap_Gen5->Fill(GenJpsiRap);} } for (Int_t ih = 0; ih < Nptbin; ih++) { //adding pT of all pt bins to see diss is cont if(iSpec == 1) if( (GenPosPass==1 && GenNegPass==1) && (TMath::Abs(GenJpsiRap)<2.4 ) && (GenJpsiPt>pt_bound[ih] && GenJpsiPt<=pt_bound[ih+1])){diMuonsPt_GenA[ifile][ih]->Fill(GenJpsiPt,GenWeight);} if(iSpec == 1) if( (GenPosPass==1 && GenNegPass==1) && (TMath::Abs(GenJpsiRap)<2.4 )&&(GenJpsiPt>pt_bound[ih] && GenJpsiPt<=pt_bound[ih+1])){diMuonsInvMass_GenA[ifile][ih]->Fill(GenJpsiMass,GenWeight);} //if(iSpec == 2) if((GenPosPass==1 && GenNegPass==1) && (GenJpsiPt<20.0) && (TMath::Abs(GenJpsiRap) > pt_bound[ih] && TMath::Abs(GenJpsiRap) <=pt_bound[ih+1] )){diMuonsInvMass_GenA[ifile][ih]->Fill(GenJpsiMass,GenWeight);} //for non symetric plots if(iSpec == 2) if((GenPosPass==1 && GenNegPass==1) && (GenJpsiPt<20.0) && ((GenJpsiRap) > pt_bound[ih] && (GenJpsiRap) <=pt_bound[ih+1] )){diMuonsInvMass_GenA[ifile][ih]->Fill(GenJpsiMass,GenWeight);} if(iSpec == 3) if( (GenPosPass==1 && GenNegPass==1) && (GenJpsiPt < 20.0) && (TMath::Abs(GenJpsiRap)<2.4 ) && (gbin>=pt_bound[ih] && gbin<pt_bound[ih+1])){diMuonsInvMass_GenA[ifile][ih]->Fill(GenJpsiMass,GenWeight);} } }//gen loop end cout<<" accepted no "<< NAccep<<endl; //dataFile<<" accepted no "<< NAccep<<endl; // new TCanvas; //diMuonsInvMass_Gen->Draw(); //gPad->Print("plots/diMuonsInvMass_Gen.png"); //new TCanvas; //diMuonsPt_Gen->Draw(); //gPad->Print("plots/diMuonsPt_Gen.png"); //new TCanvas; //diMuonsRap_Gen0->Draw(); //sprintf(PlotName,"plots/diMuonsRap_Gen_%d.pdf",ifile); //gPad->Print(PlotName); //new TCanvas; //Bin_Gen->Draw(); //gPad->Print("plots/Bin_Gen.png"); //=============== Rec Tree Loop ============================================================================== int nRecEntries=tree->GetEntries(); cout<<"Total Entries in reconstructed Tree for pT range "<<fileName[ifile]<<" "<<nRecEntries<< "====="<<endl; //dataFile<<"Total Entries in reconstructed Tree for pT range "<<fileName[ifile]<<" "<<nRecEntries<<endl; for(int i=0; i<nRecEntries; i++) { tree->GetEntry(i); if(i%100000==0){ cout<<" processing record "<<i<<endl; cout<<" processing Run " <<runNb <<" event "<<eventNb<<" lum block "<<lumiBlock<<endl; cout<<" Mass "<< JpsiMass<< " pT "<< JpsiPt << " Y " <<JpsiRap<<" "<<JpsiVprob<<" charge "<<JpsiCharge<<endl; } bool PosPass=0, NegPass=0, AllCut=0 ,PosIn=0, NegIn=0; muPosPt= TMath::Sqrt(muPosPx*muPosPx + muPosPy*muPosPy); muPosP = TMath::Sqrt(muPosPx*muPosPx + muPosPy*muPosPy+ muPosPz*muPosPz); muNegPt= TMath::Sqrt(muNegPx*muNegPx + muNegPy*muNegPy); muNegP = TMath::Sqrt(muNegPx*muNegPx + muNegPy*muNegPy +muNegPz*muNegPz); if(IsAccept(muPosPt, muPosEta)){PosIn=1;} if(IsAccept(muNegPt, muNegEta)){NegIn=1;} if(muPos_found > 10 && muPos_pixeLayers > 0 && muPos_nchi2In < 4.0 && muPos_dxy < 3 && muPos_dz < 15 && muPos_nchi2Gl < 20 && muPos_arbitrated==1 && muPos_tracker==1 ){PosPass=1;} if((muNeg_found >10 && muNeg_pixeLayers >0 && muNeg_nchi2In <4.0 && muNeg_dxy < 3 && muNeg_dz < 15 && muNeg_nchi2Gl < 20 && muNeg_arbitrated==1 && muNeg_tracker==1)){NegPass=1;} // cout<<muPos_matches<<" "<<muNeg_matches<<endl; if((muPosPt > PtCut && muNegPt > PtCut) && (muPos_matches==1 && muNeg_matches==1) && (PosIn==1 && NegIn==1) && (PosPass==1 && NegPass==1)){AllCut=1;} //without muon ID cuts //if((muPosPt > PtCut && muNegPt > PtCut) && (muPos_matches==1 && muNeg_matches==1) && (PosIn==1 && NegIn==1)){AllCut=1;} //without trigger //if( (muPosPt > PtCut && muNegPt > PtCut) && (PosIn==1 && NegIn==1 ) && (PosPass==1 && NegPass==1)){AllCut=1;} double RecCenWeight=0,RecWeight=0; RecCenWeight=FindCenWeight(rbin); RecWeight=RecCenWeight*scale[ifile]; if(PutWeight==0){RecWeight=1;} if(i%100000==0){ cout<<" eff loop for reco "<<endl; } if(AllCut==1){ if(ifile==0){diMuonsRap_Rec0->Fill(JpsiRap);} if(ifile==1){diMuonsRap_Rec1->Fill(JpsiRap);} if(ifile==2){diMuonsRap_Rec2->Fill(JpsiRap);} if(ifile==3){diMuonsRap_Rec3->Fill(JpsiRap);} if(ifile==4){diMuonsRap_Rec4->Fill(JpsiRap);} if(ifile==5){diMuonsRap_Rec5->Fill(JpsiRap);} } //Eff loop for reco if((JpsiCharge == 0) && (JpsiVprob > 0.01)) { for (Int_t ih = 0; ih < Nptbin; ih++) { //to see cont reco pT if(iSpec == 1)if((AllCut==1) && (TMath::Abs(JpsiRap) < 2.4) && (JpsiPt>pt_bound[ih] && JpsiPt<=pt_bound[ih+1])) {diMuonsPt_RecA[ifile][ih]->Fill(JpsiPt,RecWeight);} if(iSpec == 1)if((AllCut==1) && (TMath::Abs(JpsiRap)<2.4 ) && (JpsiPt > pt_bound[ih] && JpsiPt <=pt_bound[ih+1])){diMuonsInvMass_RecA[ifile][ih]->Fill(JpsiMass, RecWeight);} //if(iSpec == 2) if( (AllCut==1) && (JpsiPt<20.0) && (TMath::Abs(JpsiRap) > pt_bound[ih] && TMath::Abs(JpsiRap) <=pt_bound[ih+1])){diMuonsInvMass_RecA[ifile][ih]->Fill(JpsiMass,RecWeight);} //for non symetric plots if(iSpec == 2) if( (AllCut==1) && (JpsiPt<20.0) && ((JpsiRap) > pt_bound[ih] && (JpsiRap) <=pt_bound[ih+1])){diMuonsInvMass_RecA[ifile][ih]->Fill(JpsiMass,RecWeight);} if(iSpec == 3) if((AllCut==1) && (JpsiPt<20.0) && (TMath::Abs(JpsiRap) < 2.4) && (rbin>=pt_bound[ih] && rbin < pt_bound[ih+1])){diMuonsInvMass_RecA[ifile][ih]->Fill(JpsiMass,RecWeight);} } } } /* new TCanvas; if(ifile==0){diMuonsRap_Gen0->Draw();new TCanvas; diMuonsRap_Rec0->Draw(); gPad->Print("plots/NPdiMuonsRap_Gen0.png");} if(ifile==1){diMuonsRap_Gen1->Draw();new TCanvas; diMuonsRap_Rec1->Draw(); gPad->Print("plots/NPdiMuonsRap_Gen1.png");} if(ifile==2){diMuonsRap_Gen2->Draw();new TCanvas; diMuonsRap_Rec2->Draw(); gPad->Print("plots/NPdiMuonsRap_Gen2.png");} if(ifile==3){diMuonsRap_Gen3->Draw();new TCanvas; diMuonsRap_Rec3->Draw(); gPad->Print("plots/NPdiMuonsRap_Gen3.png");} if(ifile==4){diMuonsRap_Gen4->Draw();new TCanvas; diMuonsRap_Rec4->Draw(); gPad->Print("plots/NPdiMuonsRap_Gen4.png");} if(ifile==5){diMuonsRap_Gen5->Draw();new TCanvas; diMuonsRap_Rec5->Draw(); gPad->Print("plots/NPdiMuonsRap_Gen5.png");} */ } // file loop ends /////////////////////////////////////////////////////////////////// cout<< " adding "<<endl; TH1D *diMuonsInvMass_RecA1[100]; TH1D *diMuonsInvMass_GenA1[100]; TH1D *diMuonsPt_GenA1[100]; TH1D *diMuonsPt_RecA1[100]; TF1 *backfun_1; char namePt_1B[500];//for bkg func for(Int_t ih = 0; ih < Nptbin; ih++){ diMuonsInvMass_RecA1[ih] = diMuonsInvMass_RecA[0][ih]; diMuonsInvMass_GenA1[ih] = diMuonsInvMass_GenA[0][ih]; diMuonsPt_GenA1[ih] = diMuonsPt_GenA[0][ih]; diMuonsPt_RecA1[ih] = diMuonsPt_RecA[0][ih]; for (int ifile = 1; ifile <= 5; ifile++) { diMuonsInvMass_RecA1[ih]->Add(diMuonsInvMass_RecA[ifile][ih]); diMuonsInvMass_GenA1[ih]->Add(diMuonsInvMass_GenA[ifile][ih]); diMuonsPt_GenA1[ih]->Add(diMuonsPt_GenA[ifile][ih]); diMuonsPt_RecA1[ih]->Add(diMuonsPt_RecA[ifile][ih]); } } //===========================Fitting===================================================================// // Fit ranges double mass_low, mass_high; double MassUpsilon, WeidthUpsilon; // Low mass range upsilon width 54 KeV MassUpsilon = 9.46; WeidthUpsilon = 0.060; mass_low = 8.8; mass_high = 10.0; // Fit ranges // Fit Function crystall ball // TF1 *GAUSPOL = new TF1("GAUSPOL",CrystalBall,8.0,12.0,5); //GAUSPOL->SetParNames("#alpha","n","Mean","#sigma","N"); //GAUSPOL->SetLineWidth(2.0); //GAUSPOL->SetLineColor(2); //GAUSPOL->SetParameter(0, 1.756); //GAUSPOL->SetParameter(1, 2.636); //GAUSPOL->SetParameter(2, MassUpsilon); //GAUSPOL->SetParameter(3, WeidthUpsilon); //GAUSPOL->SetParLimits(2, 0.1*MassUpsilon,2.0*MassUpsilon); //GAUSPOL->SetParLimits(3, 0.1*WeidthUpsilon,2.0*WeidthUpsilon); // Fit Function crystall ball TF1 *GAUSPOL = new TF1("GAUSPOL",CrystalBall,8.0,12.0,6); GAUSPOL->SetParNames("Yield (#Upsilon)","BinWidth","Mean","Sigma","#alpha","n"); GAUSPOL->SetParameter(2, MassUpsilon); GAUSPOL->SetParameter(3, WeidthUpsilon); GAUSPOL->SetParLimits(3, 0.1*WeidthUpsilon,2.0*WeidthUpsilon); GAUSPOL->SetParameter(4, 1.0); GAUSPOL->SetParameter(5, 20.0); GAUSPOL->SetLineWidth(2.0); GAUSPOL->SetLineColor(2); //=====================Loop for eff=========================================================== double GenNo[100]={0}; double Eff[100]={0}; double GenError[100]={0}; double RecError[100]={0}; double errEff_cat_S1[100]={0}; double errEff_cat_S2[100]={0}; double errEff_cat_S1_1[100]={0},errEff_cat_S1_2[100]={0}; double errEff_cat_S2_1[100]={0},errEff_cat_S2_2[100]={0}; char PlotName[500],PlotName1[500], PlotName2[500]; char GPlotName[500],GPlotName1[500], GPlotName2[500]; for (Int_t ih = 0; ih < Nptbin; ih++) { cout<<" no of gen dimuons from diMuons Pt histo "<<diMuonsPt_GenA1[ih]->Integral(1,100)<<endl; cout<<" no of gen dimuons from diMuons Mass histo "<<diMuonsInvMass_GenA1[ih]->Integral(1,100)<<endl; //from pT histogram //gen_pt[ih] =diMuonsPt_GenA1[ih]->IntegralAndError(1,100,genError); gen_pt[ih] = diMuonsInvMass_GenA1[ih]->IntegralAndError(1,100,genError); gen_ptError[ih]= genError; if(iSpec==1) sprintf(PlotName,"plots/DiMuonMass_PtBin_%d.png",ih); if(iSpec==2) sprintf(PlotName,"plots/DiMuonMass_RapBin_%d.png",ih); if(iSpec==3) sprintf(PlotName,"plots/DiMuonMass_CentBin_%d.png",ih); if(iSpec==1) sprintf(PlotName1,"plots/DiMuonMass_PtBin_%d.pdf",ih); if(iSpec==2) sprintf(PlotName1,"plots/DiMuonMass_RapBin_%d.pdf",ih); if(iSpec==3) sprintf(PlotName1,"plots/DiMuonMass_CentBin_%d.pdf",ih); if(iSpec==1) sprintf(PlotName2,"plots/DiMuonMass_PtBin_%d.eps",ih); if(iSpec==2) sprintf(PlotName2,"plots/DiMuonMass_RapBin_%d.eps",ih); if(iSpec==3) sprintf(PlotName2,"plots/DiMuonMass_CentBin_%d.eps",ih); //giving inetial value for crystall ball fourth parameter diMuonsInvMass_RecA1[ih]->Rebin(2); //GAUSPOL->SetParameter(0, diMuonsInvMass_RecA1[ih]->GetMaximum()); GAUSPOL->SetParameter(0, diMuonsInvMass_RecA1[ih]->Integral(0,50)); GAUSPOL->FixParameter(1, diMuonsInvMass_RecA1[ih]->GetBinWidth(1)); new TCanvas; diMuonsInvMass_RecA1[ih]->Fit("GAUSPOL","LLMERQ", "", mass_low, mass_high); double UpsilonMass = GAUSPOL->GetParameter(2); double UpsilonWidth = GAUSPOL->GetParameter(3); double UpsilonYield = GAUSPOL->GetParameter(0); double UpsilonYieldError = GAUSPOL->GetParError(0); double par[20]; GAUSPOL->GetParameters(par); sprintf(namePt_1B,"pt_1B_%d",ih); backfun_1 = new TF1(namePt_1B, Pol2, mass_low, mass_high, 3); backfun_1->SetParameters(&par[4]); double MassLow=(UpsilonMass-3*UpsilonWidth); double MassHigh=(UpsilonMass+3*UpsilonWidth); int binlow =diMuonsInvMass_RecA1[ih]->GetXaxis()->FindBin(MassLow); int binhi =diMuonsInvMass_RecA1[ih]->GetXaxis()->FindBin(MassHigh); double binwidth=diMuonsInvMass_RecA1[ih]->GetBinWidth(1); //yield by function //rec_pt[ih] = UpsilonYield; //rec_ptError[ih]=UpsilonYieldError; cout<<"Rec diMuons from Pt histo "<<diMuonsPt_RecA1[ih]->Integral(1,100)<<endl; cout<<"Rec dimuons from mass "<<diMuonsInvMass_RecA1[ih]->Integral(1,100)<<endl; //from pT histo //rec_pt[ih]=diMuonsPt_RecA1[ih]->IntegralAndError(1, 100,recError); //yield by histogram integral rec_pt[ih] = diMuonsInvMass_RecA1[ih]->IntegralAndError(binlow, binhi,recError); rec_ptError[ih]= recError; //Cal eff Eff_cat_1[ih] = rec_pt[ih]/gen_pt[ih]; //calculate error on eff GenNo[ih]=gen_pt[ih]; Eff[ih]= Eff_cat_1[ih]; GenError[ih]=gen_ptError[ih]; RecError[ih]=rec_ptError[ih]; //error errEff_cat_S1_1[ih]= ( (Eff[ih] * Eff[ih]) /(GenNo[ih] * GenNo[ih]) ); errEff_cat_S1_2[ih]= (RecError[ih] * RecError[ih]); errEff_cat_S1[ih]= (errEff_cat_S1_1[ih] * errEff_cat_S1_2[ih]); errEff_cat_S2_1[ih]= ( (1 - Eff[ih])* (1 - Eff[ih]) ) / ( GenNo[ih] * GenNo[ih]); errEff_cat_S2_2[ih]= (GenError[ih] * GenError[ih] ) - ( RecError[ih] * RecError[ih] ); errEff_cat_S2[ih]=errEff_cat_S2_1[ih]*errEff_cat_S2_2[ih]; Err_Eff_cat_1[ih]=sqrt(errEff_cat_S1[ih] + errEff_cat_S2[ih]); //error for no weights //Err_Eff_cat_1[ih]= Eff_cat_1[ih]*TMath::Sqrt(gen_ptError[ih]*gen_ptError[ih]/(gen_pt[ih]*gen_pt[ih]) + rec_ptError[ih]*rec_ptError[ih]/(rec_pt[ih]* rec_pt[ih])); cout<<"Upsilon Yield by integral of histo: "<< diMuonsInvMass_RecA1[ih]->IntegralAndError(binlow, binhi,recError) <<" error "<< rec_ptError[ih]<<endl; cout<<"UpsilonYield by CB yield det: "<< UpsilonYield << " UpsilonWidth "<< UpsilonWidth<<" UpsilonMass "<<UpsilonMass <<endl; cout<<"Upsilon Yield by Function integral: "<< GAUSPOL->Integral(MassLow,MassHigh)/binwidth <<endl; cout<<" rec_pt[ih] "<< rec_pt[ih] <<" gen_pt[ih] "<<gen_pt[ih]<<endl; //dataFile<<" rec_pt[ih] "<< rec_pt[ih] <<" gen_pt[ih] "<<gen_pt[ih]<<endl; cout<<" eff "<< Eff_cat_1[ih]<<" error "<<Err_Eff_cat_1[ih]<<endl; dataFile<<"ih " <<ih<<" eff "<< Eff_cat_1[ih]<<" error "<<Err_Eff_cat_1[ih]<<endl; if(iSpec==1) sprintf(GPlotName,"plots/GenDiMuonMass_PtBin_%d.png",ih); if(iSpec==2) sprintf(GPlotName,"plots/GenDiMuonMass_RapBin_%d.png",ih); if(iSpec==3) sprintf(GPlotName,"plots/GenDiMuonMass_CentBin_%d.png",ih); if(iSpec==1) sprintf(GPlotName1,"plots/GenDiMuonMass_PtBin_%d.pdf",ih); if(iSpec==2) sprintf(GPlotName1,"plots/GenDiMuonMass_RapBin_%d.pdf",ih); if(iSpec==3) sprintf(GPlotName1,"plots/GenDiMuonMass_CentBin_%d.pdf",ih); if(iSpec==1) sprintf(GPlotName2,"plots/GenDiMuonMass_PtBin_%d.eps",ih); if(iSpec==2) sprintf(GPlotName2,"plots/GenDiMuonMass_RapBin_%d.eps",ih); if(iSpec==3) sprintf(GPlotName2,"plots/GenDiMuonMass_CentBin_%d.eps",ih); backfun_1->SetLineColor(4); backfun_1->SetLineWidth(1); //backfun_1->Draw("same"); gPad->Print(PlotName); gPad->Print(PlotName1); gPad->Print(PlotName2); new TCanvas; diMuonsInvMass_GenA1[ih]->Draw(); gPad->Print(GPlotName); gPad->Print(GPlotName1); gPad->Print(GPlotName2); // new TCanvas; //diMuonsPt_GenA1[ih]->Draw(); //new TCanvas; //diMuonsPt_RecA1[ih]->Draw(); } dataFile.close(); TFile *outfile; if(iSpec==1)outfile =new TFile("EffUpsilon_Pt.root","Recreate"); if(iSpec==2)outfile =new TFile("EffUpsilon_Rap.root","Recreate"); if(iSpec==3)outfile =new TFile("EffUpsilon_Cent.root","Recreate"); TGraphErrors *Eff_Upsilon = new TGraphErrors(Nptbin, PT, Eff_cat_1, mom_err,Err_Eff_cat_1); Eff_Upsilon->SetMarkerStyle(21); Eff_Upsilon->SetMarkerColor(2); Eff_Upsilon->GetYaxis()->SetTitle("Reco Eff"); if(iSpec==1) Eff_Upsilon->GetXaxis()->SetTitle("#Upsilon pT (GeV/c^{2})"); if(iSpec==2) Eff_Upsilon->GetXaxis()->SetTitle("#Upsilon rapidity"); if(iSpec==3) Eff_Upsilon->GetXaxis()->SetTitle("bin"); Eff_Upsilon->GetYaxis()->SetRangeUser(0,1.0); TLegend *legend_GP = new TLegend( 0.50,0.79,0.80,0.89); legend_GP->SetBorderSize(0); legend_GP->SetFillStyle(0); legend_GP->SetFillColor(0); legend_GP->SetTextSize(0.032); legend_GP->AddEntry(Eff_Upsilon,"PythiaEvtGen + HydjetBass", "P"); new TCanvas; Eff_Upsilon->Draw("AP"); legend_GP->Draw("Same"); Eff_Upsilon->Write(); if(iSpec==1){ gPad->Print("plots/Eff_Upsilon_Pt.pdf");gPad->Print("plots/Eff_Upsilon_Pt.png");gPad->Print("plots/Eff_Upsilon_Pt.eps");} if(iSpec==2){ gPad->Print("plots/Eff_Upsilon_Rap.pdf");gPad->Print("plots/Eff_Upsilon_Rap.png"); gPad->Print("plots/Eff_Upsilon_Rap.eps");} if(iSpec==3){ gPad->Print("plots/Eff_Upsilon_Cent.pdf");gPad->Print("plots/Eff_Upsilon_Cent.png"); gPad->Print("plots/Eff_Upsilon_Cent.eps"); } outfile->Write(); outfile->Close(); }
Float_t doCoinc(const char *fileIn="coincCERN_0102n.root",TCanvas *cout=NULL,Float_t &rate,Float_t &rateErr){ // Print settings printf("SETTINGS\nAnalyze output from new Analyzer\n"); printf("Input file = %s\n",fileIn); printf("School distance = %f m, angle = %f deg\n",distance,angle); printf("School orientation: tel1=%f deg, tel2=%f deg\n",phi1Corr,phi2Corr); printf("Max Chi2 = %f\n",maxchisquare); printf("Theta Rel Range = %f - %f deg\n",minthetarel,maxthetarel); printf("Range for N sattellite in each run = (tel1) %f - %f, (tel2) %f - %f \n",minAvSat[0],maxAvSat[0],minAvSat[1],maxAvSat[1]); printf("Min N satellite in a single event = %i\n",satEventThr); Int_t adayMin = (yearRange[0]-2014) * 1000 + monthRange[0]*50 + dayRange[0]; Int_t adayMax = (yearRange[1]-2014) * 1000 + monthRange[1]*50 + dayRange[1]; Float_t nsigPeak=0; Float_t nbackPeak=0; angle *= TMath::DegToRad(); // define some histos TH1F *hDeltaTheta = new TH1F("hDeltaTheta","#Delta#theta below the peak (500 ns);#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhi = new TH1F("hDeltaPhi","#Delta#phi below the peak (500 ns);#Delta#phi (#circ)",200,-360,360); TH1F *hDeltaThetaBack = new TH1F("hDeltaThetaBack","#Delta#theta out of the peak (> 1000 ns) - normalized;#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhiBack = new TH1F("hDeltaPhiBack","#Delta#phi out of the peak (> 1000 ns) - normalized;#Delta#phi (#circ)",200,-360,360); TH1F *hThetaRel = new TH1F("hThetaRel","#theta_{rel} below the peak (500 ns);#theta_{rel} (#circ)",100,0,120); TH1F *hThetaRelBack = new TH1F("hThetaRelBack","#theta_{rel} out of the peak (> 1000 ns) - normalized;#theta_{rel} (#circ)",100,0,120); TH2F *hAngle = new TH2F("hAngle",";#Delta#theta (#circ);#Delta#phi (#circ}",20,-60,60,20,-360,360); TH2F *hAngleBack = new TH2F("hAngleBack",";#Delta#theta (#circ);#Delta#phi (#circ}",20,-60,60,20,-360,360); TProfile *hModulation = new TProfile("hModulation","#theta^{rel} < 10#circ;#phi - #alpha;dist (m)",50,0,360); TProfile *hModulation2 = new TProfile("hModulation2","#theta^{rel} < 10#circ;#phi - #alpha;dist (m)",50,0,360); TProfile *hModulationAv = new TProfile("hModulationAv","#theta^{rel} < 10#circ;#phi - #alpha;dist (m)",50,0,360); TProfile *hModulationAvCorr = new TProfile("hModulationAvCorr","#theta^{rel} < 10#circ;#phi - #alpha;diff (ns)",50,0,360); TH1F *hnsigpeak = new TH1F("hnsigpeak","",50,0,360); TH1F *hnbackpeak = new TH1F("hnbackpeak","",50,0,360); TProfile *hSinTheta = new TProfile("hSinTheta",";#phi - #alpha;sin(#theta)",50,0,360); TProfile *hSinTheta2 = new TProfile("hSinTheta2",";#phi - #alpha;sin(#theta)",50,0,360); TH1F *hRunCut[2]; hRunCut[0] = new TH1F("hRunCut1","Reason for Run Rejection Tel-1;Reason;runs rejected",11,0,11); hRunCut[1] = new TH1F("hRunCut2","Reason for Run Rejection Tel-2;Reason;runs rejected",11,0,11); for(Int_t i=0;i<2;i++){ hRunCut[i]->Fill("DateRange",0); hRunCut[i]->Fill("LowFractionGT",0); hRunCut[i]->Fill("TimeDuration",0); hRunCut[i]->Fill("rateGT",0); hRunCut[i]->Fill("RunNumber",0); hRunCut[i]->Fill("MissingHitFrac",0); hRunCut[i]->Fill("DeadStripBot",0); hRunCut[i]->Fill("DeadStripMid",0); hRunCut[i]->Fill("DeadStripTop",0); hRunCut[i]->Fill("NSatellites",0); hRunCut[i]->Fill("NoGoodWeather",0); } TFile *f = new TFile(fileIn); TTree *t = (TTree *) f->Get("tree"); TTree *tel[2]; tel[0] = (TTree *) f->Get("treeTel1"); tel[1] = (TTree *) f->Get("treeTel2"); TTree *telC = (TTree *) f->Get("treeTimeCommon"); // quality info of runs const Int_t nyearmax = 5; Bool_t runstatus[2][nyearmax][12][31][500]; //#telescope, year-2014, month, day, run Float_t effTel[2][nyearmax][12][31][500]; Int_t nStripDeadBot[2][nyearmax][12][31][500]; Int_t nStripDeadMid[2][nyearmax][12][31][500]; Int_t nStripDeadTop[2][nyearmax][12][31][500]; Float_t nstripDeadB[2]={0,0},nstripDeadM[2]={0,0},nstripDeadT[2]={0,0}; // sat info Float_t NsatAv[2][nyearmax][12][31][500]; // weather info Float_t pressureTel[2][nyearmax][12][31][500]; Float_t TempInTel[2][nyearmax][12][31][500]; Float_t TempOutTel[2][nyearmax][12][31][500]; Float_t timeWeath[2][nyearmax][12][31][500]; Float_t rateGT; Float_t phirelative; Float_t phirelative2; Float_t phirelativeAv; printf("Check Run quality\n"); if(tel[0] && tel[1]){ for(Int_t i=0;i < 2;i++){ // loop on telescopes printf("Tel-%i\n",i+1); for(Int_t j=0;j < tel[i]->GetEntries();j++){ // loop on runs tel[i]->GetEvent(j); rateGT = tel[i]->GetLeaf("FractionGoodTrack")->GetValue()*tel[i]->GetLeaf("rateHitPerRun")->GetValue(); Int_t aday = (tel[i]->GetLeaf("year")->GetValue()-2014) * 1000 + tel[i]->GetLeaf("month")->GetValue()*50 + tel[i]->GetLeaf("day")->GetValue(); if(i==1) printf("%f %f\n",rateGT , rateMin[i]); if(aday < adayMin || aday > adayMax){ hRunCut[i]->Fill("DateRange",1); continue;} if(tel[i]->GetLeaf("FractionGoodTrack")->GetValue() < fracGT[i]){ hRunCut[i]->Fill("LowFractionGT",1); continue;} // cut on fraction of good track if(tel[i]->GetLeaf("timeduration")->GetValue()*tel[i]->GetLeaf("rateHitPerRun")->GetValue() < hitevents[i]){ hRunCut[i]->Fill("TimeDuration",1); continue;} // cut on the number of event if(rateGT < rateMin[i] || rateGT > rateMax[i]){ hRunCut[i]->Fill("rateGT",1); continue;} // cut on the rate if(tel[i]->GetLeaf("run")->GetValue() > 499){ hRunCut[i]->Fill("RunNumber",1); continue;} // run < 500 if(i==1) printf("GR\n"); Float_t missinghitfrac = (tel[i]->GetLeaf("ratePerRun")->GetValue()-tel[i]->GetLeaf("rateHitPerRun")->GetValue()-2)/(tel[i]->GetLeaf("ratePerRun")->GetValue()-2); if(missinghitfrac < minmissingHitFrac[i] || missinghitfrac > maxmissingHitFrac[i]){ hRunCut[i]->Fill("MissingHitFrac",1); continue;} // active strip maps if(tel[i]->GetLeaf("maskB")) nStripDeadBot[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = countBits(Int_t(tel[i]->GetLeaf("maskB")->GetValue())); if(tel[i]->GetLeaf("maskM")) nStripDeadMid[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = countBits(Int_t(tel[i]->GetLeaf("maskM")->GetValue())); if(tel[i]->GetLeaf("maskT")) nStripDeadTop[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = countBits(Int_t(tel[i]->GetLeaf("maskT")->GetValue())); if(nStripDeadBot[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > ndeadBotMax[i] || nStripDeadBot[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < ndeadBotMin[i]) { hRunCut[i]->Fill("DeadStripBot",1); continue;} if(nStripDeadMid[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > ndeadMidMax[i] || nStripDeadMid[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < ndeadMidMin[i]){ hRunCut[i]->Fill("DeadStripMid",1); continue;} if(nStripDeadTop[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > ndeadTopMax[i] || nStripDeadTop[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < ndeadTopMin[i]){ hRunCut[i]->Fill("DeadStripTop",1); continue;} // nsat averaged per run if(tel[i]->GetLeaf("nSat")) NsatAv[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("nSat")->GetValue(); if(NsatAv[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < minAvSat[i] || NsatAv[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > maxAvSat[i]){ hRunCut[i]->Fill("NSatellites",1); continue;} // weather info if(tel[i]->GetLeaf("Pressure")) pressureTel[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("Pressure")->GetValue(); if(tel[i]->GetLeaf("IndoorTemperature")) TempInTel[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("IndoorTemperature")->GetValue(); if(tel[i]->GetLeaf("OutdoorTemperature")) TempOutTel[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("OutdoorTemperature")->GetValue(); if(tel[i]->GetLeaf("TimeWeatherUpdate")) timeWeath[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("TimeWeatherUpdate")->GetValue(); if(timeWeath[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < minWeathTimeDelay[i] || timeWeath[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > maxWeathTimeDelay[i]){ hRunCut[i]->Fill("NoGoodWeather",1); continue; } // Set good runs runstatus[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = kTRUE; effTel[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = 1;//rateGT/refRate[i]; } } } else{ telC = NULL; } printf("Start to process correlations\n"); Int_t n = t->GetEntries(); // counter for seconds Int_t nsec = 0; Int_t nsecGR = 0; // for good runs Int_t isec = -1; // used only in case the tree with time info is not available Float_t neventsGR = 0; Float_t neventsGRandSat = 0; if(telC){ for(Int_t i=0; i < telC->GetEntries();i++){ telC->GetEvent(i); nsec += telC->GetLeaf("timeduration")->GetValue(); if(telC->GetLeaf("run")->GetValue() > 499 || telC->GetLeaf("run2")->GetValue() > 499) continue; if(!runstatus[0][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())]) continue; if(!runstatus[1][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run2")->GetValue())]) continue; nsecGR += telC->GetLeaf("timeduration")->GetValue(); nstripDeadB[0] += countBits(nStripDeadBot[0][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadM[0] += countBits(nStripDeadMid[0][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadT[0] += countBits(nStripDeadTop[0][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadB[1] += countBits(nStripDeadBot[1][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadM[1] += countBits(nStripDeadMid[1][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadT[1] += countBits(nStripDeadTop[1][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); } nstripDeadB[0] /= nsecGR; nstripDeadM[0] /= nsecGR; nstripDeadT[0] /= nsecGR; nstripDeadB[1] /= nsecGR; nstripDeadM[1] /= nsecGR; nstripDeadT[1] /= nsecGR; printf("Dead channel tel1 = %f - %f - %f\n",nstripDeadB[0],nstripDeadM[0],nstripDeadT[0]); printf("Dead channel tel2 = %f - %f - %f\n",nstripDeadB[1],nstripDeadM[1],nstripDeadT[1]); } char title[300]; TH1F *h; sprintf(title,"correction assuming #Delta#phi = %4.2f, #DeltaL = %.1f m;#Deltat (ns);entries",angle,distance); h = new TH1F("hCoinc",title,nbint,tmin,tmax); Float_t DeltaT; Float_t phiAv,thetaAv,corr; Float_t Theta1,Theta2; Float_t Phi1,Phi2; Int_t nsatel1cur,nsatel2cur,ntrack1,ntrack2; Float_t v1[3],v2[3],vSP; // variable to recompute ThetaRel on the fly Float_t eff = 1; for(Int_t i=0;i<n;i++){ t->GetEvent(i); if(t->GetLeaf("RunNumber1") && (t->GetLeaf("RunNumber1")->GetValue() > 499 || t->GetLeaf("RunNumber2")->GetValue() > 499)) continue; if(tel[0] && !runstatus[0][Int_t(t->GetLeaf("year")->GetValue())-2014][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber1")->GetValue())]) continue; if(tel[1] && !runstatus[1][Int_t(t->GetLeaf("year")->GetValue())-2014][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]) continue; eff = effTel[0][Int_t(t->GetLeaf("year")->GetValue())-2014][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber1")->GetValue())]; eff *= effTel[1][Int_t(t->GetLeaf("year")->GetValue())-2014][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]; Int_t timec = t->GetLeaf("ctime1")->GetValue(); if(! telC){ if(isec == -1) isec = timec; if(timec != isec){ if(timec - isec < 20){ // printf("diff = %i\n",timec-isec); nsec +=(timec - isec); nsecGR +=(timec - isec); } isec = timec; } } Float_t thetarel = t->GetLeaf("ThetaRel")->GetValue(); Theta1 = (t->GetLeaf("Theta1")->GetValue())*TMath::DegToRad(); Theta2 = t->GetLeaf("Theta2")->GetValue()*TMath::DegToRad(); Phi1 = t->GetLeaf("Phi1")->GetValue()*TMath::DegToRad(); Phi2 = t->GetLeaf("Phi2")->GetValue()*TMath::DegToRad(); nsatel1cur = t->GetLeaf("Nsatellite1")->GetValue(); nsatel2cur = t->GetLeaf("Nsatellite2")->GetValue(); ntrack1 = t->GetLeaf("Ntracks1")->GetValue(); ntrack2 = t->GetLeaf("Ntracks2")->GetValue(); if(recomputeThetaRel){ // recompute ThetaRel applying corrections Phi1 += phi1Corr*TMath::DegToRad(); Phi2 += phi2Corr*TMath::DegToRad(); if(Phi1 > 2*TMath::Pi()) Phi1 -= 2*TMath::Pi(); if(Phi1 < 0) Phi1 += 2*TMath::Pi(); if(Phi2 > 2*TMath::Pi()) Phi2 -= 2*TMath::Pi(); if(Phi2 < 0) Phi2 += 2*TMath::Pi(); v1[0] = TMath::Sin(Theta1)*TMath::Cos(Phi1); v1[1] = TMath::Sin(Theta1)*TMath::Sin(Phi1); v1[2] = TMath::Cos(Theta1); v2[0] = TMath::Sin(Theta2)*TMath::Cos(Phi2); v2[1] = TMath::Sin(Theta2)*TMath::Sin(Phi2); v2[2] = TMath::Cos(Theta2); v1[0] *= v2[0]; v1[1] *= v2[1]; v1[2] *= v2[2]; vSP = v1[0] + v1[1] + v1[2]; thetarel = TMath::ACos(vSP)*TMath::RadToDeg(); } // cuts if(thetarel < minthetarel) continue; if(thetarel > maxthetarel) continue; if(t->GetLeaf("ChiSquare1")->GetValue() > maxchisquare) continue; if(t->GetLeaf("ChiSquare2")->GetValue() > maxchisquare) continue; neventsGR++; // reject events with not enough satellites if(nsatel1cur < satEventThr || nsatel1cur < satEventThr) continue; neventsGRandSat++; DeltaT = t->GetLeaf("DiffTime")->GetValue(); // get primary direction if(TMath::Abs(Phi1-Phi2) < TMath::Pi()) phiAv = (Phi1+Phi2)*0.5; else phiAv = (Phi1+Phi2)*0.5 + TMath::Pi(); thetaAv = (Theta1+Theta2)*0.5; // extra cuts if needed // if(TMath::Cos(Phi1-Phi2) < 0.) continue; Float_t resFactor = 1; if(thetarel > 10 ) resFactor *= 0.5; if(thetarel > 20 ) resFactor *= 0.5; if(thetarel > 30 ) resFactor *= 0.5; corr = distance * TMath::Sin(thetaAv)*TMath::Cos(phiAv-angle)/2.99792458000000039e-01 + deltatCorr; phirelative = (Phi1-angle)*TMath::RadToDeg(); if(phirelative < 0) phirelative += 360; if(phirelative < 0) phirelative += 360; if(phirelative > 360) phirelative -= 360; if(phirelative > 360) phirelative -= 360; phirelative2 = (Phi2-angle)*TMath::RadToDeg(); if(phirelative2 < 0) phirelative2 += 360; if(phirelative2 < 0) phirelative2 += 360; if(phirelative2 > 360) phirelative2 -= 360; if(phirelative2 > 360) phirelative2 -= 360; phirelativeAv = (phiAv-angle)*TMath::RadToDeg(); if(phirelativeAv < 0) phirelativeAv += 360; if(phirelativeAv < 0) phirelativeAv += 360; if(phirelativeAv > 360) phirelativeAv -= 360; if(phirelativeAv > 360) phirelativeAv -= 360; // if(TMath::Abs(DeltaT- deltatCorr) < windowAlignment){ // } if(thetarel < 10){//cos(thetarel*TMath::DegToRad())>0.98 && sin(thetaAv)>0.1){ if(TMath::Abs(DeltaT- corr) < windowAlignment) hModulationAvCorr->Fill(phirelativeAv,DeltaT-corr); if(TMath::Abs(DeltaT- deltatCorr) < windowAlignment){ hModulation->Fill(phirelative,(DeltaT-deltatCorr)/sin(thetaAv)*2.99792458000000039e-01); hModulation2->Fill(phirelative2,(DeltaT-deltatCorr)/sin(thetaAv)*2.99792458000000039e-01); hModulationAv->Fill(phirelativeAv,(DeltaT-deltatCorr)/sin(thetaAv)*2.99792458000000039e-01); hSinTheta->Fill(phirelative,sin(thetaAv)); hSinTheta2->Fill(phirelative2,sin(thetaAv)); nsigPeak++; hnsigpeak->Fill(phirelativeAv); } else if(TMath::Abs(DeltaT- deltatCorr) < windowAlignment*10){ nbackPeak++; hnbackpeak->Fill(phirelativeAv); } } h->Fill(DeltaT-corr,1./eff); if(TMath::Abs(DeltaT-corr) < windowAlignment){ hDeltaTheta->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhi->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRel->Fill(thetarel); hAngle->Fill((Theta1-Theta2)*TMath::RadToDeg(),(Phi1-Phi2)*TMath::RadToDeg()); } else if(TMath::Abs(DeltaT-corr) > windowAlignment*2 && TMath::Abs(DeltaT-corr) < windowAlignment*12){ hDeltaThetaBack->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhiBack->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRelBack->Fill(thetarel); hAngleBack->Fill((Theta1-Theta2)*TMath::RadToDeg(),(Phi1-Phi2)*TMath::RadToDeg()); } } // compute (S+B)/S for(Int_t i=1;i<=50;i++){ Float_t corrfactorPeak = 1; if(nsigPeak-nbackPeak*0.1 > 0) corrfactorPeak = hnsigpeak->GetBinContent(i)/(hnsigpeak->GetBinContent(i)-hnbackpeak->GetBinContent(i)*0.1); else printf("bin %i) not enough statistics\n",i); hnsigpeak->SetBinContent(i,corrfactorPeak); } TF1 *fpol0 = new TF1("fpol0","pol0"); hnsigpeak->Fit(fpol0); hModulation->Scale(fpol0->GetParameter(0)); hModulation2->Scale(fpol0->GetParameter(0)); hModulationAv->Scale(fpol0->GetParameter(0)); hModulationAvCorr->Scale(fpol0->GetParameter(0)); TF1 *fmod = new TF1("fmod","[0] + [1]*cos((x-[2])*TMath::DegToRad())"); hModulationAv->Fit(fmod); printf("Estimates from time delay: Distance = %f +/- %f m -- Angle = %f +/- %f deg\n",fmod->GetParameter(1),fmod->GetParError(1),fmod->GetParameter(2),fmod->GetParError(2)); h->SetStats(0); hDeltaThetaBack->Sumw2(); hDeltaPhiBack->Sumw2(); hThetaRelBack->Sumw2(); hDeltaThetaBack->Scale(0.1); hDeltaPhiBack->Scale(0.1); hThetaRelBack->Scale(0.1); hAngleBack->Scale(0.1); hAngle->Add(hAngleBack,-1); printf("bin counting: SIGNAL = %f +/- %f\n",hDeltaPhi->Integral()-hDeltaPhiBack->Integral(),sqrt(hDeltaPhi->Integral())); rate = (hDeltaPhi->Integral()-hDeltaPhiBack->Integral())/nsecGR*86400; rateErr = sqrt(hDeltaPhi->Integral())/nsecGR*86400; Float_t val,eval; TCanvas *c1=new TCanvas(); TF1 *ff = new TF1("ff","[0]*[4]/[2]/sqrt(2*TMath::Pi())*TMath::Exp(-(x-[1])*(x-[1])*0.5/[2]/[2]) + [3]*[4]/6/[2]"); ff->SetParName(0,"signal"); ff->SetParName(1,"mean"); ff->SetParName(2,"sigma"); ff->SetParName(3,"background"); ff->SetParName(4,"bin width"); ff->SetParameter(0,42369); ff->SetParameter(1,0); ff->SetParLimits(2,10,maxwidth); ff->SetParameter(2,350); // fix witdh if needed ff->SetParameter(3,319); ff->FixParameter(4,(tmax-tmin)/nbint); // bin width ff->SetNpx(1000); if(cout) cout->cd(); h->Fit(ff,"EI","",-10000,10000); val = ff->GetParameter(2); eval = ff->GetParError(2); printf("significance = %f\n",ff->GetParameter(0)/sqrt(ff->GetParameter(0) + ff->GetParameter(3))); h->Draw(); new TCanvas; TF1 *func1 = (TF1 *) h->GetListOfFunctions()->At(0); func1->SetLineColor(2); h->SetLineColor(4); TPaveText *text = new TPaveText(1500,(h->GetMinimum()+(h->GetMaximum()-h->GetMinimum())*0.6),9500,h->GetMaximum()); text->SetFillColor(0); sprintf(title,"width = %5.1f #pm %5.1f",func1->GetParameter(2),func1->GetParError(2)); text->AddText(title); sprintf(title,"signal (S) = %5.1f #pm %5.1f",func1->GetParameter(0),func1->GetParError(0)); text->AddText(title); sprintf(title,"background (B) (3#sigma) = %5.1f #pm %5.1f",func1->GetParameter(3),func1->GetParError(3)); text->AddText(title); sprintf(title,"significance (S/#sqrt{S+B}) = %5.1f",func1->GetParameter(0)/sqrt(func1->GetParameter(0)+func1->GetParameter(3))); text->AddText(title); text->SetFillStyle(0); text->SetBorderSize(0); text->Draw("SAME"); // correct nsecGR for the event rejected because of the number of satellites (event by event cut) nsecGR *= neventsGRandSat/neventsGR; printf("n_day = %f\nn_dayGR = %f\n",nsec*1./86400,nsecGR*1./86400); text->AddText(Form("rate = %f #pm %f per day",func1->GetParameter(0)*86400/nsecGR,func1->GetParError(0)*86400/nsecGR)); TFile *fo = new TFile("outputCERN-01-02.root","RECREATE"); h->Write(); hDeltaTheta->Write(); hDeltaPhi->Write(); hThetaRel->Write(); hDeltaThetaBack->Write(); hDeltaPhiBack->Write(); hThetaRelBack->Write(); hAngle->Write(); hModulation->Write(); hModulation2->Write(); hModulationAv->Write(); hModulationAvCorr->Write(); hSinTheta->Write(); hSinTheta2->Write(); hnsigpeak->Write(); hRunCut[0]->Write(); hRunCut[1]->Write(); fo->Close(); return nsecGR*1./86400; }
TF1 *GausBF::Bfit(TGraph *gr) { TF1 *func = new TF1("func", FB(), -200, 200); gr->Fit("gaus", "q0"); TF1 *fg0 = gr->GetFunction("gaus"); Int_t ip = 3; for (Int_t i = 0; i < 3; i++) func->SetParameter(i, fg0->GetParameter(i)); TGraph gd; TGraph gm; Double_t min = 0, max = 0; Double_t xmn = gr->GetY()[0]; Double_t xmx = gr->GetY()[0]; Double_t xb = gr->GetX()[0]; Double_t db = 0; Double_t mmin = 0.002; for (Int_t i = 0; i < gr->GetN(); i++) { Double_t x = gr->GetX()[i]; Double_t y = gr->GetY()[i]; Double_t d = y-func->Eval(x); gd.SetPoint(i, x, d); gm.SetPoint(i, x, -d); if (db*d < 0) { if ((d > 0 && min < -mmin) || (d < 0 && max > mmin)) { Double_t xm = (d > 0) ? xmn : xmx; Double_t w1 = x-xm; Double_t w2 = xm-xb; Double_t w = (w1 > w2) ? w2 : w1; Double_t par[3]; if (d < 0) { gd.Fit("gaus", "q0", "", xm-w, xm+w); TF1 *fg = gd.GetFunction("gaus"); for (Int_t j = 0; j < 3; j++) par[j] = fg->GetParameter(j); } else { gm.Fit("gaus", "q0", "", xm-w, xm+w); TF1 *fg = gm.GetFunction("gaus"); for (Int_t j = 0; j < 3; j++) par[j] = fg->GetParameter(j); par[0] = -par[0]; } for (Int_t j = 0; j < 3; j++) func->SetParameter(ip+j, par[j]); ip += 3; } xb = x; if (d < 0) min = 0; if (d > 0) max = 0; } db = d; if (d < min) { min = d; xmn = x; } if (d > max) { max = d; xmx = x; } } for (Int_t i = ip; i < Np; i++) func->FixParameter(i, (i%3 == 2) ? 1 : 0); gr->Fit(func, "q0"); return func; }
//TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, float NPpar[]) TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, TString npfit) { TString tMC; if(isMC==1) tMC="MC"; else tMC="Data"; TCanvas* c = new TCanvas(Form("c_%s_%.0f",tMC.Data(),ibin),"",600,600); TFile* infile = new TFile(Form("%s_%s_%s_%s_%.0f.root",infname.Data(),collisionsystem.Data(),varname.Data(),tMC.Data(),ibin)); TH1D* h = (TH1D*)infile->Get("h"); h->SetName(Form("h_%s_%.0f",tMC.Data(),ibin)); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); hMCSignal->SetName(Form("hMCSignal_%s_%.0f",tMC.Data(),ibin)); //TString iNP=Form("TMath::Erf((x-%f)/%f)+1", NPpar[0], NPpar[1]); TString iNP = npfit; TF1* f = new TF1(Form("f_%s_%.0f",tMC.Data(),ibin),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*("+iNP+")"); f->SetParLimits(3,0,1e5); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(5,0,1000); if(isMC) { f->SetParLimits(3,0,1e2); f->SetParLimits(4,-100,0); } f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); f->FixParameter(5,0); h->GetEntries(); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(5); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); f->ReleaseParameter(1); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); TF1 *background = new TF1(Form("background_%s_%.0f",tMC.Data(),ibin),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1 *Bkpi = new TF1(Form("fBkpi_%s_%.0f",tMC.Data(),ibin),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(5)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetRange(minhisto,maxhisto); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); Bkpi->SetFillColor(kGreen+1); TF1 *mass = new TF1(Form("fmass_%s_%.0f",tMC.Data(),ibin),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); h->SetXTitle("m_{#mu#muK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"B^{+} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol; if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","pp")); else texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","PbPb")); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.04); texCol->SetTextFont(42); texCol->Draw(); TLatex* tex; if(ibin>0) { if(isLarger==1) tex = new TLatex(0.22,0.78,Form("%s > %.3f",vartex.Data(),varval)); else tex = new TLatex(0.22,0.78,Form("%s < %.3f",vartex.Data(),varval)); } else tex = new TLatex(0.22,0.78,Form("%s",_nominalcut.Data())); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 2.4"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.73,Form("N_{B} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); c->SaveAs(Form("plotFits/DMass_%s_%s_%s_%.0f.pdf",collisionsystem.Data(),varname.Data(),tMC.Data(),ibin)); return mass; }
void fitDstar(char *infname = "/data/wangj/MC2015/Dntuple/PbPb/ntD_Pythia8_5020GeV_DstarD0kpipipi_755patch3_GEN_SIM_PU_20151120_Dstar5p_tkPt2_20151126_Evt_All.root") { TFile *inf = new TFile(infname); //TTree *ntmix=(TTree*)inf->Get("ntDD0kpipipipi"); TTree *ntmix=(TTree*)inf->Get("ntDD0kpipi"); TH1D *h = new TH1D("h","",100,0.139,0.159); TCut cutTrk = "";//"trk1PixelHit>=2&&trk1StripHit>=10&&trk1Chi2ndf<5&&trk2PixelHit>=2&&trk2StripHit>=10&&trk2Chi2ndf<5"; TCanvas *c = new TCanvas("c","",750,750); ntmix->Draw("Dmass-DtktkResmass>>h","abs(DtktkResmass-1.86486)<0.015&&Dpt>10&&(DsvpvDistance/DsvpvDisErr)>0.&&Dchi2cl>0.05&&Dalpha<1."&&cutTrk,"",10000000); //ntmix->Draw("Dmass-DtktkResmass>>h","abs(DtktkResmass-1.86486)<0.015&&Dpt>10&&Dtrk1Pt>0.5&&DRestrk1Pt>0.5&&DRestrk2Pt>0.5&&DRestrk3Pt>0.5&&DRestrk4Pt>0.5&&Dchi2cl>0.1&&Dalpha<0.2&&(DsvpvDistance/DsvpvDisErr)>.0"&&cutTrk,"",10000000); h->Sumw2(); // TF1 *f = new TF1("f","(1-exp(-(x-[8])/[0]))*(((x)/[8])**[1]+[2]*(((x)/[8])-1))*[3]+[4]*(TMath::Voigt(x-[5],[6],[7]))"); TF1* f = new TF1("f","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*((1-[8])*TMath::Gaus(x,[6],[7])/(sqrt(2*3.14159)*[7])+[8]*TMath::Gaus(x,[6],[9])/(sqrt(2*3.14159)*[9]))",minmass3prong,maxmass3prong); // TF1 *f = new TF1("f","(1-exp(-(x-0.13957018)/[0]))*(((x)/0.13957018)**[1]+[2]*(((x)/0.13957018)-1))*[3]+[4]*(TMath::Gaus(x,[5],[6]))"); //TF1 *f = new TF1("f","(1-exp(-(x-1.86486-0.13957018)/[0]))*(((x-1.86486)/0.13957018)**[1]+[2]*(((x-1.86486)/0.13957018)-1))*[3]+[4]*TMath::Gaus(x,[5],[6])"); f->SetLineColor(4); // f->SetParameters(-2.3825e6,-7.99713e-1,-1.42957,-5.50069e10,5.33573,1.45491e-1,2.78677e-6,1.43145e-3,0.13957018); // f->SetParameters(-7.3e5,-2.2e1,5.24e-1,-7.18e9,2e2,1.45491e-1,9e-4,0.1,8e-4); f->SetParameters(0,0,0,0,0,2e2,1.45491e-1,9e-4,0.1,8e-4); f->FixParameter(9,15e-4); f->FixParameter(6,0.145491); f->FixParameter(7,8e-4); f->SetParLimits(8,0,1); h->Fit("f","LL"); h->Fit("f","LL"); h->Fit("f","LL","",0.142,0.147); f->ReleaseParameter(6); f->ReleaseParameter(7); f->ReleaseParameter(9); f->SetParLimits(7,1e-4,9e-4); f->SetParLimits(9,1e-4,9e-4); h->Fit("f","LL","",0.142,0.148); h->Fit("f","LL","",0.142,0.16); h->Fit("f","LL","",0.142,0.16); h->Fit("f","LL","",0.141,0.16); h->Fit("f","LL","",0.141,0.16); h->Fit("f","LL","",0.141,0.16); h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})"); h->SetYTitle("Entries"); h->SetStats(0); h->SetAxisRange(1,h->GetMaximum()*1.3,"Y"); TF1 *f2 = (TF1*)f->Clone("f2"); f2->SetParameter(5,0); f2->SetRange(0.141,0.16); TF1 *f3 = (TF1*)f->Clone("f3"); f3->SetParameter(0,0); f3->SetParameter(1,0); f3->SetParameter(2,0); f3->SetParameter(3,0); f3->SetParameter(4,0); f->SetLineColor(4); f2->SetLineColor(4); f2->SetLineStyle(2); f3->SetLineStyle(2); f2->Draw("same"); f3->SetLineColor(2); f3->SetFillStyle(3004); f3->SetFillColor(2); f3->Draw("same"); c->SaveAs("canvasDstar.pdf"); }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax){ //cout<<cut.Data()<<endl; static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",50,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); TString iNP="(7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01)))"; TF1* fNP = new TF1("fNP",iNP); float normNP = fNP->Integral(5,6); TString signal = "([5]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[5])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))"; TF1 *f = new TF1(Form("f%d",count),Form("[0]*%s+[3]+[4]*x+(%s/%f)*([0]/%f)",signal.Data(),iNP.Data(),Ratio*(1+Change),normNP)); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(6,0.01,0.05); f->SetParLimits(5,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(6,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(5,f->GetParameter(5)); f->FixParameter(6,f->GetParameter(6)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); //cout<<"======="<<normNP<<"======="<<endl; // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),Form("([0]/(%f*%f))*%s",Ratio*(1+Change),normNP,iNP.Data())); Bkpi->SetParameter(0,f->GetParameter(0)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(5),f->GetParameter(6)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B^{+} meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); TLegend *leg3 = myLegend(0.02,0.83,0.37,0.92); if(Change==0) leg3->AddEntry((TObject*)0,Form("Ratio=%.2f",Ratio),""); else leg3->AddEntry((TObject*)0,Form("Ratio=%.2f(%.1f%)",Ratio*(1+Change),Change*100),""); leg3->Draw(); if(Change==0) c->SaveAs("BplusApplyRatio.pdf"); if(Change>0) c->SaveAs("BplusApplyRatioPlus.pdf"); if(Change<0) c->SaveAs("BplusApplyRatioMinus.pdf"); return mass; }
int main() { float const conS =.3/2.35; ofstream fout("cal/backN.cal"); ofstream fwhm("cal/fwhmback.dat"); TFile f("sort.root"); TCanvas* canvas[14]; int Ntele = 14; int Nstrip = 32; ostringstream outstring; TH2I frame("frame","",10,4.5,9.5,10,0,130); frame.SetStats(kFALSE); double xx[14*32]; double yy[14*32]; TF1 *func = new TF1("fit",ThPeaks,3,9,4); double para[5]; ifstream file("cal/back.cal"); float intercept, slope; int i1,i2; string name; TH1F con("con","",500,0,10); for (int itele=0;itele<Ntele;itele++) { outstring.str(""); outstring << "B"<<itele; name = outstring.str(); canvas[itele] = new TCanvas(name.c_str()); canvas[itele]->Divide(6,6); for (int istrip =0;istrip<Nstrip;istrip++) { canvas[itele]->cd(istrip+1); file >> i1 >> i2 >> slope >> intercept; outstring.str(""); outstring << "back/cal/EBC"<<itele<<"_"<<istrip; string name = outstring.str(); cout << name << endl; TH1I * hist = (TH1I*) f.Get(name.c_str()); frame.Draw(); hist->SetStats(kFALSE); hist->GetXaxis()->SetRangeUser(4.5,9.5); con.GetXaxis()->SetRangeUser(4.5,9.5); for (int i=1;i<=500;i++) for (int j=1;j<500;j++) { float deltax = hist->GetBinCenter(i)-con.GetBinCenter(j); if (fabs(deltax) > 10.*conS)continue; float fact = gauss(deltax,0.,conS); float y = fact*hist->GetBinContent(i)*hist->GetBinWidth(i); con.SetBinContent(j,y+con.GetBinContent(j)); } for (int i=1;i<=500;i++) { hist->SetBinContent(i,con.GetBinContent(i)); con.SetBinContent(i,0.); } hist->Draw("same"); func->SetParameter(0,0); func->SetParameter(1,1.); func->FixParameter(2,conS); //func->SetParameter(2,0.1); func->SetParameter(3,8.); func->SetLineColor(2); //func->Draw("same"); hist->Fit(func); func->GetParameters(para); cout << "chisq=" << func->GetChisquare() << endl; if (fabs(para[1]-1.) < .2) { slope *= para[1]; intercept = intercept*para[1] + para[0]; } fout << itele << " " << istrip << " " << slope << " " << intercept << endl; fwhm << itele << " " << istrip << " " << para[2]*2.35 << endl; int ii = itele*32+istrip; xx[ii] = (float)ii; yy[ii] = para[2]*2.35; cout << para[0] << " " << para[1] << " " << para[2] << endl; } } TFile g("ThBack.root","RECREATE"); for (int itele=0;itele<Ntele;itele++) canvas[itele]->Write(); TCanvas fwhmCan("fwhm"); TH2I frame2("frame2","",10,0,448,10,0,0.12); frame2.SetStats(kFALSE); frame2.GetYaxis()->SetTitle("FWHM [MeV]"); frame2.GetXaxis()->SetTitle("back strip"); frame2.Draw(); TGraph graph(32*14,xx,yy); graph.Draw("*"); graph.Write(); fwhmCan.Write(); g.Write(); }
TF1* fit(float ptmin, float ptmax, int s, int b, int widVar) { static int count=0; count++; TCanvas* c = new TCanvas(Form("c_%.0f_%.0f",ptmin,ptmax),"",400,400); TFile* infile = new TFile(Form("%s/%s_%.0f_%.0f.root",infname.Data(),collisionsystem.Data(),ptmin,ptmax)); TH1D* h = (TH1D*)infile->Get("h"); h->SetName(Form("h_%.0f_%.0f",ptmin,ptmax)); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); hMCSignal->SetName(Form("hMCSignal_%.0f_%.0f",ptmin,ptmax)); TF1* f; TF1* background; TF1* bkpi; TF1* mass; if(b==0) f = new TF1(Form("f%d",count),Form("%s+%s+%s",sig[s].Data(),sig_bkg[s].Data(),bkgerf.Data()), 5.0, 6.0); else f = new TF1(Form("f%d",count),Form("%s+%s+%s",sig[s].Data(),bkg[b].Data(),bkgerf.Data()), 5.0, 6.0); clean0(h); h->Draw(); double hmin = h->GetBinContent(h->GetMinimumBin()); double hmax = h->GetBinContent(h->GetMaximumBin()); double havg = h->Integral(); double mcmin = hMCSignal->GetBinContent(h->GetMinimumBin()); double mcmax = hMCSignal->GetBinContent(h->GetMaximumBin()); double mcavg = hMCSignal->Integral(); f->SetParLimits(0,0,2*hmax); f->SetParLimits(1,5.27,5.29); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(6,0,1); if(s==1) f->SetParLimits(9,0,1); //if(s==2) f->SetParLimits(10,1,10); if(b==0 && sigmax[s]==8) { //f->SetParLimits(9,0.5*hmin,1.5*hmax); f->SetParLimits(10,-1000,0); } if(b==0 && sigmax[s]==10) { //f->SetParLimits(11,0.5*hmin,1.5*hmax); f->SetParLimits(12,-1000,0); } if(b==3) { //f->SetParLimits(9,0,1.5*hmax); f->SetParLimits(10,-100,0); } f->SetParLimits(3,0,1000); f->FixParameter(4,NPpar[0]); f->FixParameter(5,NPpar[1]); f->SetParameter(0,100); f->SetParameter(1,5.28); f->SetParameter(2,0.05); f->SetParameter(8,0.03); f->FixParameter(1,5.279); f->FixParameter(3,0); if(s==2) f->FixParameter(7,0); if(s>0 && bkgmax[b]>=11) f->FixParameter(11,0); if(s>0 && bkgmax[b]>=12) f->FixParameter(12,0); h->GetEntries(); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,5.27,5.29); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->FixParameter(6,f->GetParameter(6)); if(sigmax[s]>=9) f->FixParameter(9,f->GetParameter(9)); if(sigmax[s]>=10) f->FixParameter(10,f->GetParameter(10)); if(s==2) { f->ReleaseParameter(7); f->SetParLimits(7,0,1); } if(s>0 && bkgmax[b]>=11) f->ReleaseParameter(11); if(s>0 && bkgmax[b]>=12) f->ReleaseParameter(12); f->ReleaseParameter(3); f->SetParLimits(3,0,1000); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,5.27,5.29); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); if(b==0) { background = new TF1(Form("background%d",count),bkg_new[b].Data(),minhisto,maxhisto); background->SetParameter(0,f->GetParameter(sigmax[s]+1)); background->SetParameter(1,f->GetParameter(sigmax[s]+2)); } else { background = new TF1(Form("background%d",count),bkg_new[b].Data(),minhisto,maxhisto); background->SetParameter(0,f->GetParameter(9)); background->SetParameter(1,f->GetParameter(10)); if(bkgmax[b]>=11) background->SetParameter(2,f->GetParameter(11)); if(bkgmax[b]>=12) background->SetParameter(3,f->GetParameter(12)); } bkpi = new TF1(Form("bpki%d",count),bkgerf_new.Data(),minhisto,maxhisto); bkpi->SetParameter(0,f->GetParameter(3)); bkpi->SetParameter(1,NPpar[0]); bkpi->SetParameter(2,NPpar[1]); mass = new TF1(Form("fmass%d",count),sig_new[s].Data(),minhisto,maxhisto); if(s==0 || s==3) mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8),f->GetParameter(6)); if(s==1) mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8),f->GetParameter(6),f->GetParameter(9)); if(s==2) mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8),f->GetParameter(6),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(8)); mass->SetParError(5,f->GetParError(6)); if(sigmax[s]>=9) mass->SetParError(6,f->GetParError(9)); if(sigmax[s]>=10) mass->SetParError(7,f->GetParError(10)); f->SetLineColor(kRed); f->SetLineWidth(2); background->SetLineColor(4); background->SetLineStyle(2); background->SetLineWidth(3); background->SetRange(minhisto,maxhisto); bkpi->SetFillColor(kGreen+4); bkpi->SetFillStyle(3005); bkpi->SetLineColor(kGreen+4); bkpi->SetLineWidth(3); mass->SetLineColor(kOrange-3); mass->SetLineStyle(2); mass->SetLineWidth(3); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); h->SetXTitle("m_{#mu#muK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.0); h->GetYaxis()->SetTitleOffset(1.5); h->GetXaxis()->SetLabelOffset(0.008); h->GetYaxis()->SetLabelOffset(0.008); h->GetXaxis()->SetTitleSize(0.060); h->GetYaxis()->SetTitleSize(0.060); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.06); h->GetYaxis()->SetLabelSize(0.06); h->Draw("e"); double axisymin = -0.05; h->SetAxisRange(axisymin,h->GetMaximum()*1.2,"Y"); h->GetXaxis()->SetNdivisions(-50205); int ci = TColor::GetColor("#000099"); h->SetLineColor(ci); h->SetStats(0); h->SetMarkerStyle(20); // 24? h->SetMarkerSize(0.8); h->Draw("e"); bkpi->Draw("same"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); f->Draw("same"); yield = mass->Integral(minhisto,maxhisto)/binwidthmass; yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); TLegend* leg = new TLegend(0.55,0.45,0.875,0.76,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.05); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"B^{+} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->AddEntry(bkpi,"B #rightarrow J/#psi X","f"); leg->Draw("same"); TLatex* texCms = new TLatex(0.225,0.87, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol; if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.39,0.94, Form("25.8 pb^{-1} (%s #sqrt{s_{NN}} = 5.02 TeV)","pp")); else texCol= new TLatex(0.35,0.94, Form("345 #mub^{-1} (%s #sqrt{s_{NN}} = 5.02 TeV)","PbPb")); texCol->SetNDC(); texCol->SetTextSize(0.05); texCol->SetLineWidth(2); texCol->SetTextFont(42); texCol->Draw(); TLatex* tex; tex = new TLatex(0.53,0.85,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.05); tex->SetLineWidth(2); tex->Draw(); if(centmax>0){ TString texper="%"; tex = new TLatex(0.225,0.78,Form("Centrality %.0f-%.0f%s",centmin,centmax,texper.Data()));//0.2612903,0.8425793 tex->SetNDC(); tex->SetTextColor(1); tex->SetTextFont(42); tex->SetTextSize(0.05); tex->SetLineWidth(2); tex->Draw(); } tex = new TLatex(0.77,0.78,"|y_{lab}| < 2.4"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.05); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.30,0.54,"B^{+}"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.06); tex->SetLineWidth(2); tex->Draw(); if(widVar==0) c->SaveAs(Form("SystPDF/%s_%s_%s_%.0f_%.0f.pdf",collisionsystem.Data(),signame[s].Data(),bkgname[b].Data(),ptmin,ptmax)); else c->SaveAs(Form("SystPDF/%s_%s_%.0f_%.0f.pdf",collisionsystem.Data(),"widvar",ptmin,ptmax)); return mass; }
void produceTF() { gROOT->SetBatch(); setTDRStyle(); TChain ch("trGEN"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hut-MadGraph5-pythia8/data.root"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hct-MadGraph5-pythia8/data.root"); float dMetPx, dMetPy; float dTopLepBJetPx, dTopLepBJetPy, dTopLepBJetPz, dTopLepBJetE; float dHiggsBJet1Px, dHiggsBJet1Py, dHiggsBJet1Pz, dHiggsBJet1E; float dHiggsBJet2Px, dHiggsBJet2Py, dHiggsBJet2Pz, dHiggsBJet2E; float dElecPx, dElecPy, dElecPz, dElecE; float dMuonPx, dMuonPy, dMuonPz, dMuonE; float TopLepWM, TopLepRecM, TopHadRecM, HiggsRecM; ch.SetBranchAddress("dMetPx",&dMetPx); ch.SetBranchAddress("dMetPy",&dMetPy); ch.SetBranchAddress("dTopLepBJetPx",&dTopLepBJetPx); ch.SetBranchAddress("dTopLepBJetPy",&dTopLepBJetPy); ch.SetBranchAddress("dTopLepBJetPz",&dTopLepBJetPz); ch.SetBranchAddress("dTopLepBJetE",&dTopLepBJetE); ch.SetBranchAddress("dHiggsBJet1Px",&dHiggsBJet1Px); ch.SetBranchAddress("dHiggsBJet1Py",&dHiggsBJet1Py); ch.SetBranchAddress("dHiggsBJet1Pz",&dHiggsBJet1Pz); ch.SetBranchAddress("dHiggsBJet1E",&dHiggsBJet1E); ch.SetBranchAddress("dHiggsBJet2Px",&dHiggsBJet2Px); ch.SetBranchAddress("dHiggsBJet2Py",&dHiggsBJet2Py); ch.SetBranchAddress("dHiggsBJet2Pz",&dHiggsBJet2Pz); ch.SetBranchAddress("dHiggsBJet2E",&dHiggsBJet2E); ch.SetBranchAddress("dElecPx",&dElecPx); ch.SetBranchAddress("dElecPy",&dElecPy); ch.SetBranchAddress("dElecPz",&dElecPz); ch.SetBranchAddress("dElecE",&dElecE); ch.SetBranchAddress("dMuonPx",&dMuonPx); ch.SetBranchAddress("dMuonPy",&dMuonPy); ch.SetBranchAddress("dMuonPz",&dMuonPz); ch.SetBranchAddress("dMuonE",&dMuonE); ch.SetBranchAddress("TopLepWM",&TopLepWM); ch.SetBranchAddress("TopLepRecM",&TopLepRecM); ch.SetBranchAddress("HiggsRecM",&HiggsRecM); int nHist = 0; TH1D *h[1000]; std::string hName[1000]; std::string hLab[1000]; TFile *fOut = new TFile("pdf.root","RECREATE"); h[nHist] = new TH1D("h_TopLepRecM","h_TopLepRecM",100,80.,260.); h[nHist]->Sumw2(); hName[nHist] = "TopLepRecM"; hLab[nHist] = "m(t) [GeV]"; nHist++; h[nHist] = new TH1D("h_TopLepWM","h_TopLepWM",100,60.,100.); h[nHist]->Sumw2(); hName[nHist] = "TopLepWM"; hLab[nHist] = "m(W) [GeV]"; nHist++; h[nHist] = new TH1D("h_HiggsRecM","h_HiggsRecM",100,20.,220.); h[nHist]->Sumw2(); hName[nHist] = "HiggsRecM"; hLab[nHist] = "m(H) [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPx","h_dMetPx",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPx"; hLab[nHist] = "MetPx_{gen} - MetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPy","h_dMetPy",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPy"; hLab[nHist] = "MetPy_{gen} - MetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPx","h_dBJetPx",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPx"; hLab[nHist] = "BJetPx_{gen} - BJetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPy","h_dBJetPy",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPy"; hLab[nHist] = "BJetPy_{gen} - BJetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPz","h_dBJetPz",100,-80.,80.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPz"; hLab[nHist] = "BJetPz_{gen} - BJetPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetE","h_dBJetE",100,-300.,120.); h[nHist]->Sumw2(); hName[nHist] = "dBJetE"; hLab[nHist] = "BJetE_{gen} - BJetE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPx","h_dElecPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPx"; hLab[nHist] = "ElecPx_{gen} - ElecPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPy","h_dElecPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPy"; hLab[nHist] = "ElecPy_{gen} - ElecPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPz","h_dElecPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecPz"; hLab[nHist] = "ElecPz_{gen} - ElecPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecE","h_dElecE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecE"; hLab[nHist] = "ElecE_{gen} - ElecE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPx","h_dMuonPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPx"; hLab[nHist] = "MuonPx_{gen} - MuonPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPy","h_dMuonPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPy"; hLab[nHist] = "MuonPy_{gen} - MuonPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPz","h_dMuonPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPz"; hLab[nHist] = "MuonPz_{gen} - MuonPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonE","h_dMuonE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonE"; hLab[nHist] = "MuonE_{gen} - MuonE_{reco} [GeV]"; nHist++; int nev = ch.GetEntries(); TRandom3 *rnd = new TRandom3(); for(int i=0;i<nev;i++) { ch.GetEntry(i); for(int ih=0;ih<nHist;ih++) { if( hName[ih] == "TopLepRecM" ) h[ih]->Fill(TopLepRecM); else if( hName[ih] == "TopLepWM" ) h[ih]->Fill(TopLepWM); else if( hName[ih] == "HiggsRecM" ) h[ih]->Fill(HiggsRecM); else if( hName[ih] == "dMetPx" ) h[ih]->Fill(dMetPx); else if( hName[ih] == "dMetPy" ) h[ih]->Fill(dMetPy); else if( hName[ih] == "dBJetPx" ) {h[ih]->Fill(dHiggsBJet1Px);h[ih]->Fill(dHiggsBJet2Px);h[ih]->Fill(dTopLepBJetPx);} else if( hName[ih] == "dBJetPy" ) {h[ih]->Fill(dHiggsBJet1Py);h[ih]->Fill(dHiggsBJet2Py);h[ih]->Fill(dTopLepBJetPy);} else if( hName[ih] == "dBJetPz" ) {h[ih]->Fill(dHiggsBJet1Pz);h[ih]->Fill(dHiggsBJet2Pz);h[ih]->Fill(dTopLepBJetPz);} else if( hName[ih] == "dBJetE" ) {h[ih]->Fill(dHiggsBJet1E);h[ih]->Fill(dHiggsBJet2E);h[ih]->Fill(dTopLepBJetE);} else if( hName[ih] == "dElecPx" ) {h[ih]->Fill(dElecPx);} else if( hName[ih] == "dElecPy" ) {h[ih]->Fill(dElecPy);} else if( hName[ih] == "dElecPz" ) {h[ih]->Fill(dElecPz);} else if( hName[ih] == "dElecE" ) {h[ih]->Fill(dElecE);} else if( hName[ih] == "dMuonPx" ) {h[ih]->Fill(dMuonPx);} else if( hName[ih] == "dMuonPy" ) {h[ih]->Fill(dMuonPy);} else if( hName[ih] == "dMuonPz" ) {h[ih]->Fill(dMuonPz);} else if( hName[ih] == "dMuonE" ) {h[ih]->Fill(dMuonE);} } } delete rnd; // Plots TCanvas *c1 = new TCanvas(); c1->Draw(); c1->cd(); TPad *c1_1; gStyle->SetHistTopMargin(0); for(int i=0;i<nHist;i++) { // addbin(h[i]); h[i]->Scale(1./h[i]->Integral()); h[i]->Scale(1./h[i]->GetMaximum()); h[i]->SetLineWidth(2); h[i]->SetLineColor(kRed); h[i]->SetMarkerColor(kRed); h[i]->SetMarkerStyle(20); h[i]->Draw("hist e1"); h[i]->GetXaxis()->SetTitle(hLab[i].c_str()); // h[i]->GetYaxis()->SetTitle("Normalized to unity"); float max = h[i]->GetMaximum(); h[i]->SetMaximum(1.2*max); if( hName[i] == "TopLepWM" || hName[i] == "TopLepM" ) { std::string funcName = hName[i]+"_Fit"; TF1 *func = new TF1(funcName.c_str(),BW,h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins()),3); double mean = 80.4; if( hName[i] == "TopLepM" ) mean = 173.0; double sigma = 2.0; if( hName[i] == "TopLepM" ) sigma = 2.0; func->SetParameter(0,mean); func->SetParName(0,"mean"); func->SetParameter(1,sigma); func->SetParName(1,"sigma"); func->SetParameter(2,1.0); func->SetParName(2,"constant"); func->FixParameter(2,1.); h[i]->Fit(funcName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->Write(); std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"gaus(0)",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->Write(); } if( hName[i] == "dMetPx" || hName[i] == "dMetPy" ) { double mean = 0.; double sigma = 50.; std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->SetParameter(3,0.5); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dBJetPx" || hName[i] == "dBJetPy" || hName[i] == "dBJetPz" || hName[i] == "dBJetE" ) { double mean = 0.; double sigma = 20.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[12]*(gaus(0)+gaus(3)+gaus(6)+gaus(9))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(12,1.0); funcGaus->SetParameter(0,1.0); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(0,0.6); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(0,0.6); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(3,0.3); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(5,sigma*4); if( hName[i] == "dBJetPy" ) funcGaus->SetParameter(3,0.2); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(8,sigma/3.); funcGaus->SetParameter(9,0.5); funcGaus->SetParameter(10,mean); funcGaus->SetParameter(11,sigma); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); if( hName[i] == "dBJetE" ) { c1->Update(); TPaveStats *st = (TPaveStats*)h[i]->FindObject("stats"); st->SetX1NDC(0.20); st->SetX2NDC(0.47); } fit->Draw("same"); fit->SetParameter(12,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dElecPx" || hName[i] == "dElecPy" || hName[i] == "dElecPz" || hName[i] == "dElecE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dElecE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dMuonPx" || hName[i] == "dMuonPy" || hName[i] == "dMuonPz" || hName[i] == "dMuonE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(3,0.2); if( hName[i] == "dMuonE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "HiggsRecM" || hName[i] == "TopLepRecM" ) { double mean = 125.; double sigma = 10.; if( hName[i] == "TopLepRecM" ) { mean = 170; sigma = 20; } std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] != "TopLepRecM" ) funcGaus->FixParameter(0,0.7); funcGaus->SetParameter(3,0.3); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(3,0.7); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(4,150); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } std::string figName = "pics/"+hName[i]+".eps"; c1->Print(figName.c_str()); c1->Clear(); } fOut->Write(); fOut->Close(); gApplication->Terminate(); }
void doCoinc3(const char *fileIn="SAVO-01-SAVO-02-SAVO-03-2016-01-26.root"){ Int_t adayMin = (yearRange[0]-2007) * 1000 + monthRange[0]*50 + dayRange[0]; Int_t adayMax = (yearRange[1]-2007) * 1000 + monthRange[1]*50 + dayRange[1]; // define some histos TH1F *hDeltaTheta12 = new TH1F("hDeltaTheta12","#Delta#theta_{12} below the peak (500 ns);#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhi12 = new TH1F("hDeltaPhi12","#Delta#phi_{12} below the peak (500 ns);#Delta#phi (#circ)",200,-360,360); TH1F *hDeltaThetaBack12 = new TH1F("hDeltaThetaBack12","#Delta#theta_{12} out of the peak (> 1000 ns) - normalized;#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhiBack12 = new TH1F("hDeltaPhiBack12","#Delta#phi_{12} out of the peak (> 1000 ns) - normalized;#Delta#phi (#circ)",200,-360,360); TH1F *hThetaRel12 = new TH1F("hThetaRel12","#theta_{rel}_{12} below the peak (500 ns);#theta_{rel} (#circ)",100,0,120); TH1F *hThetaRelBack12 = new TH1F("hThetaRelBack12","#theta_{rel}_{12} out of the peak (> 1000 ns) - normalized;#theta_{rel} (#circ)",100,0,120); TH1F *hDeltaTheta13 = new TH1F("hDeltaTheta13","#Delta#theta_{13} below the peak (500 ns);#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhi13 = new TH1F("hDeltaPhi13","#Delta#phi_{13} below the peak (500 ns);#Delta#phi (#circ)",200,-360,360); TH1F *hDeltaThetaBack13 = new TH1F("hDeltaThetaBack13","#Delta#theta_{13} out of the peak (> 1000 ns) - normalized;#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhiBack13 = new TH1F("hDeltaPhiBack13","#Delta#phi_{13} out of the peak (> 1000 ns) - normalized;#Delta#phi (#circ)",200,-360,360); TH1F *hThetaRel13 = new TH1F("hThetaRel13","#theta_{rel}_{13} below the peak (500 ns);#theta_{rel} (#circ)",100,0,120); TH1F *hThetaRelBack13 = new TH1F("hThetaRelBack13","#theta_{rel}_{13} out of the peak (> 1000 ns) - normalized;#theta_{rel} (#circ)",100,0,120); TFile *f = new TFile(fileIn); TTree *t = (TTree *) f->Get("tree"); TTree *tel[3]; tel[0] = (TTree *) f->Get("treeTel1"); tel[1] = (TTree *) f->Get("treeTel2"); tel[2] = (TTree *) f->Get("treeTel3"); TTree *telC = (TTree *) f->Get("treeTimeCommon"); // quality info of runs Bool_t runstatus[3][10][12][31][500]; //#telescope, year-2007, month, day, run if(tel[0] && tel[1] && tel[2]){ for(Int_t i=0;i < 3;i++){ // loop on telescopes for(Int_t j=0;j < tel[i]->GetEntries();j++){ // loop on runs tel[i]->GetEvent(j); Int_t aday = (tel[i]->GetLeaf("year")->GetValue()-2007) * 1000 + tel[i]->GetLeaf("month")->GetValue()*50 + tel[i]->GetLeaf("day")->GetValue(); if(aday < adayMin || aday > adayMax) continue; if(tel[i]->GetLeaf("FractionGoodTrack")->GetValue() < fracGT[i]) continue; // cut on fraction of good track if(tel[i]->GetLeaf("timeduration")->GetValue()*tel[i]->GetLeaf("rateHitPerRun")->GetValue() < hitevents[i]) continue; // cut on the number of event if(tel[i]->GetLeaf("ratePerRun")->GetValue() < rateMin[i] || tel[i]->GetLeaf("ratePerRun")->GetValue() > rateMax[i]) continue; // cut on the rate if(tel[i]->GetLeaf("run")->GetValue() > 499) continue; // run < 500 Float_t missinghitfrac = (tel[i]->GetLeaf("ratePerRun")->GetValue()-tel[i]->GetLeaf("rateHitPerRun")->GetValue()-2)/(tel[i]->GetLeaf("ratePerRun")->GetValue()-2); if(missinghitfrac < minmissingHitFrac[i] || missinghitfrac > maxmissingHitFrac[i]) continue; runstatus[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2007][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = kTRUE; } } } else{ telC = NULL; } Int_t n = t->GetEntries(); // counter for seconds Int_t nsec = 0; Int_t nsecGR = 0; // for good runs Int_t isec = -1; // used only in case the tree with time info is not available if(telC){ for(Int_t i=0; i < telC->GetEntries();i++){ telC->GetEvent(i); nsec += telC->GetLeaf("timeduration")->GetValue(); if(telC->GetLeaf("run")->GetValue() > 499 || telC->GetLeaf("run2")->GetValue() > 499 || telC->GetLeaf("run3")->GetValue() > 499) continue; if(!runstatus[0][Int_t(telC->GetLeaf("year")->GetValue())-2007][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())]) continue; if(!runstatus[1][Int_t(telC->GetLeaf("year")->GetValue())-2007][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run2")->GetValue())]) continue; if(!runstatus[2][Int_t(telC->GetLeaf("year")->GetValue())-2007][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run2")->GetValue())]) continue; nsecGR += telC->GetLeaf("timeduration")->GetValue(); } } char title[600]; TH1F *h; TH2F *h2; sprintf(title,"correction assuming #Delta#phi_{12} = %4.2f, #DeltaL_{12} = %.1f m, #Delta#phi_{13} = %4.2f, #DeltaL_{13} = %.1f m;#Deltat_{13} (ns) when |#Deltat_{12}| < %i ns;entries",angle12,distance12,angle13,distance13,timeCutOn12); h = new TH1F("hCoinc",title,nbint,tmin,tmax); sprintf(title,"correction assuming #Delta#phi_{12} = %4.2f, #DeltaL_{12} = %.1f m, #Delta#phi_{13} = %4.2f, #DeltaL_{13} = %.1f m;#Deltat_{12} (ns);#Deltat_{13} (ns);entries",angle12,distance12,angle13,distance13,timeCutOn12); h2 = new TH2F("hCoinc2D",title,nbint,tmin,tmax,nbint,tmin,tmax); Float_t DeltaT12,DeltaT13; Float_t phiAv,thetaAv,corr12,corr13; Float_t Theta1,Theta2,Theta3; Float_t Phi1,Phi2,Phi3; Float_t v1[3],v2[3],v3[3],vSP12,vSP13; // variable to recompute ThetaRel on the fly for(Int_t i=0;i<n;i++){ t->GetEvent(i); // if(t->GetLeaf("RunNumber1") && (t->GetLeaf("RunNumber1")->GetValue() > 499 || t->GetLeaf("RunNumber2")->GetValue() > 499) || t->GetLeaf("RunNumber3")->GetValue() > 499)) continue; // if(tel[0] && !runstatus[0][Int_t(t->GetLeaf("year")->GetValue())-2007][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber1")->GetValue())]) continue; // if(tel[1] && !runstatus[1][Int_t(t->GetLeaf("year")->GetValue())-2007][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]) continue; // if(tel[2] && !runstatus[2][Int_t(t->GetLeaf("year")->GetValue())-2007][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]) continue; Int_t timec = t->GetLeaf("ctime1")->GetValue(); if(! telC){ if(isec == -1) isec = timec; if(timec != isec){ if(timec - isec < 20){ // printf("diff = %i\n",timec-isec); nsec +=(timec - isec); nsecGR +=(timec - isec); } isec = timec; } } Float_t thetarel12 = t->GetLeaf("ThetaRel12")->GetValue(); Float_t thetarel13 = t->GetLeaf("ThetaRel13")->GetValue(); Theta1 = t->GetLeaf("Theta1")->GetValue()*TMath::DegToRad(); Theta2 = t->GetLeaf("Theta2")->GetValue()*TMath::DegToRad(); Theta3 = t->GetLeaf("Theta3")->GetValue()*TMath::DegToRad(); Phi1 = t->GetLeaf("Phi1")->GetValue()*TMath::DegToRad(); Phi2 = t->GetLeaf("Phi2")->GetValue()*TMath::DegToRad(); Phi3 = t->GetLeaf("Phi3")->GetValue()*TMath::DegToRad(); if(recomputeThetaRel){ // recompute ThetaRel applying corrections Phi1 -= phi1Corr*TMath::DegToRad(); Phi2 -= phi2Corr*TMath::DegToRad(); Phi3 -= phi3Corr*TMath::DegToRad(); if(Phi1 > 2*TMath::Pi()) Phi1 -= 2*TMath::Pi(); if(Phi1 < 0) Phi1 += 2*TMath::Pi(); if(Phi2 > 2*TMath::Pi()) Phi2 -= 2*TMath::Pi(); if(Phi2 < 0) Phi2 += 2*TMath::Pi(); if(Phi3 > 2*TMath::Pi()) Phi3 -= 2*TMath::Pi(); if(Phi3 < 0) Phi3 += 2*TMath::Pi(); v1[0] = TMath::Sin(Theta1)*TMath::Cos(Phi1); v1[1] = TMath::Sin(Theta1)*TMath::Sin(Phi1); v1[2] = TMath::Cos(Theta1); v2[0] = TMath::Sin(Theta2)*TMath::Cos(Phi2); v2[1] = TMath::Sin(Theta2)*TMath::Sin(Phi2); v2[2] = TMath::Cos(Theta2); v3[0] = TMath::Sin(Theta3)*TMath::Cos(Phi3); v3[1] = TMath::Sin(Theta3)*TMath::Sin(Phi3); v3[2] = TMath::Cos(Theta3); v2[0] *= v1[0]; v2[1] *= v1[1]; v2[2] *= v1[2]; v3[0] *= v1[0]; v3[1] *= v1[1]; v3[2] *= v1[2]; vSP12 = v2[0] + v2[1] + v2[2]; vSP13 = v3[0] + v3[1] + v3[2]; thetarel12 = TMath::ACos(vSP12)*TMath::RadToDeg(); thetarel13 = TMath::ACos(vSP13)*TMath::RadToDeg(); } // cuts if(thetarel12 > maxthetarel) continue; if(thetarel13 > maxthetarel) continue; if(t->GetLeaf("ChiSquare1")->GetValue() > maxchisquare) continue; if(t->GetLeaf("ChiSquare2")->GetValue() > maxchisquare) continue; if(t->GetLeaf("ChiSquare3")->GetValue() > maxchisquare) continue; DeltaT12 = t->GetLeaf("DiffTime12")->GetValue(); DeltaT13 = t->GetLeaf("DiffTime13")->GetValue(); // get primary direction if(TMath::Abs(Phi1-Phi2) < TMath::Pi()) phiAv = (Phi1+Phi2)*0.5; else phiAv = (Phi1+Phi2)*0.5 + TMath::Pi(); if(TMath::Abs(phiAv-Phi3) < TMath::Pi()) phiAv = (phiAv*2+Phi2)*0.33333333333; else if(phiAv > Phi3) phiAv = (phiAv*2+Phi3+2*TMath::Pi())*0.33333333333; else phiAv = (phiAv*2+4*TMath::Pi()+Phi3)*0.33333333333; thetaAv = (Theta1+Theta2+Theta3)*0.333333333333; // extra cuts if needed // if(TMath::Cos(Phi1-Phi2) < 0.) continue; corr12 = distance12 * TMath::Sin(thetaAv)*TMath::Cos(phiAv-angle12)/2.99792458000000039e-01 + deltatCorr12; corr13 = distance13 * TMath::Sin(thetaAv)*TMath::Cos(phiAv-angle13)/2.99792458000000039e-01 + deltatCorr13; if(TMath::Abs(DeltaT12-corr12) < timeCutOn12) h->Fill(DeltaT13-corr13); h2->Fill(DeltaT12-corr12,DeltaT13-corr13); if(TMath::Abs(DeltaT12-corr12) < 500){ hDeltaTheta12->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhi12->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRel12->Fill(thetarel12); } else if(TMath::Abs(DeltaT12-corr12) > 1000 && TMath::Abs(DeltaT12-corr12) < 6000){ hDeltaThetaBack12->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhiBack12->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRelBack12->Fill(thetarel12); } if(TMath::Abs(DeltaT13-corr13) < 500){ hDeltaTheta13->Fill((Theta1-Theta3)*TMath::RadToDeg()); hDeltaPhi13->Fill((Phi1-Phi3)*TMath::RadToDeg()); hThetaRel13->Fill(thetarel13); } else if(TMath::Abs(DeltaT13-corr13) > 1000 && TMath::Abs(DeltaT13-corr13) < 6000){ hDeltaThetaBack13->Fill((Theta1-Theta3)*TMath::RadToDeg()); hDeltaPhiBack13->Fill((Phi1-Phi3)*TMath::RadToDeg()); hThetaRelBack13->Fill(thetarel13); } } h->SetStats(0); hDeltaThetaBack12->Sumw2(); hDeltaPhiBack12->Sumw2(); hThetaRelBack12->Sumw2(); hDeltaThetaBack12->Scale(0.1); hDeltaPhiBack12->Scale(0.1); hThetaRelBack12->Scale(0.1); hDeltaThetaBack13->Sumw2(); hDeltaPhiBack13->Sumw2(); hThetaRelBack13->Sumw2(); hDeltaThetaBack13->Scale(0.1); hDeltaPhiBack13->Scale(0.1); hThetaRelBack13->Scale(0.1); Float_t val,eval; TCanvas *c1=new TCanvas(); TF1 *ff = new TF1("ff","[0]*[4]/[2]/sqrt(2*TMath::Pi())*TMath::Exp(-(x-[1])*(x-[1])*0.5/[2]/[2]) + [3]*[4]/6/[2]"); ff->SetParName(0,"signal"); ff->SetParName(1,"mean"); ff->SetParName(2,"sigma"); ff->SetParName(3,"background"); ff->SetParName(4,"bin width"); ff->SetParameter(0,42369); ff->SetParameter(1,0); ff->SetParLimits(2,10,1000); ff->SetParameter(2,150); // fix witdh if needed ff->SetParameter(3,319); ff->FixParameter(4,20000./nbint); // bin width ff->SetNpx(1000); h->Fit(ff); val = ff->GetParameter(2); eval = ff->GetParError(2); printf("significance = %f\n",ff->GetParameter(0)/sqrt(ff->GetParameter(0) + ff->GetParameter(3))); h->Draw(); TF1 *func1 = (TF1 *) h->GetListOfFunctions()->At(0); func1->SetLineColor(2); h->SetLineColor(4); TPaveText *text = new TPaveText(1500,(h->GetMinimum()+(h->GetMaximum()-h->GetMinimum())*0.6),9500,h->GetMaximum()); text->SetFillColor(0); sprintf(title,"width = %5.1f #pm %5.1f",func1->GetParameter(2),func1->GetParError(2)); text->AddText(title); sprintf(title,"signal (S) = %5.1f #pm %5.1f",func1->GetParameter(0),func1->GetParError(0)); text->AddText(title); sprintf(title,"background (B) (3#sigma) = %5.1f #pm %5.1f",func1->GetParameter(3),func1->GetParError(3)); text->AddText(title); sprintf(title,"significance (S/#sqrt{S+B}) = %5.1f",func1->GetParameter(0)/sqrt(func1->GetParameter(0)+func1->GetParameter(3))); text->AddText(title); text->SetFillStyle(0); text->SetBorderSize(0); text->Draw("SAME"); printf("n_day = %f\nn_dayGR = %f\n",nsec*1./86400,nsecGR*1./86400); text->AddText(Form("rate = %f #pm %f per day",func1->GetParameter(0)*86400/nsecGR,func1->GetParError(0)*86400/nsecGR)); TFile *fo = new TFile("output-SAVO-010203.root","RECREATE"); h->Write(); h2->Write(); hDeltaTheta12->Write(); hDeltaPhi12->Write(); hThetaRel12->Write(); hDeltaThetaBack12->Write(); hDeltaPhiBack12->Write(); hThetaRelBack12->Write(); hDeltaTheta13->Write(); hDeltaPhi13->Write(); hThetaRel13->Write(); hDeltaThetaBack13->Write(); hDeltaPhiBack13->Write(); hThetaRelBack13->Write(); fo->Close(); }
TF1* fitDstar3prongs(TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax) { static int count3p=0; count3p++; TCanvas* c = new TCanvas(Form("c_3p_%d",count3p),"",600,600); TH1D* h = new TH1D(Form("h_3p_%d",count3p),"",60,0.14,0.16); TH1D* hMCSignal = new TH1D(Form("hMCSignal_3p_%d",count3p),"",60,0.14,0.16); TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_3p_%d",count3p),"",60,0.14,0.16); TF1* f = new TF1(Form("f_3p_%d",count3p),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*([12]*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10])+(1-[12])*Gaus(x,[1],[13])/(sqrt(2*3.14159)*[13])))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x+[11]*x*x*x*x",0.14,0.16); f->SetLineColor(kRed); nt->Project(Form("h_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata3p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); ntMC->Project(Form("hMCSignal_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23333))",weight.Data(),selmc3p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); ntMC->Project(Form("hMCSwapped_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23344))",weight.Data(),selswp3p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); f->FixParameter(7,1.); f->FixParameter(1,0.145491); f->FixParameter(2,2.e-3); f->FixParameter(10,5.e-4); f->FixParameter(13,1.e-4); f->FixParameter(3,0.); f->FixParameter(4,0.); f->FixParameter(5,0.); f->FixParameter(6,0.); f->FixParameter(11,0.); f->SetParLimits(9,0,1); f->SetParLimits(12,0,1); f->SetParLimits(0,0,1000000); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL"); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL"); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.142,0.155); f->ReleaseParameter(1); f->ReleaseParameter(2); f->ReleaseParameter(10); f->ReleaseParameter(13); f->SetParLimits(1,0.144,0.147); if(isData==0||isData==2) f->SetParLimits(2,5.e-4,5.e-3); else f->SetParLimits(2,5.e-4,7.e-3); f->SetParLimits(10,1.e-4,2.e-3); if(isData==0||isData==2) f->SetParLimits(13,5.e-5,3.e-4); else if(ptmin>20) f->SetParLimits(13,5.e-5,4.e-4); else f->SetParLimits(13,5.e-5,5.e-4); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.143,0.147); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(13,f->GetParameter(13)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(12,f->GetParameter(12)); f->FixParameter(7,0); f->SetParLimits(8,2.e-4,2.e-3); hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16); hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->ReleaseParameter(11); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); f->ReleaseParameter(1); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); TF1* background = new TF1(Form("background_3p_%d",count3p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetParameter(4,f->GetParameter(11)); background->SetLineColor(4); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_3p_%d",count3p),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*([6]*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])+(1-[6])*Gaus(x,[1],[7])/(sqrt(2*3.14159)*[7]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(12),f->GetParameter(13)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetParError(6,f->GetParError(12)); mass->SetParError(7,f->GetParError(13)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); h->SetXTitle("M_{K#pi#pi}-M_{K#pi} (GeV/c^{2})"); h->SetYTitle("Entries / (1/3 MeV/c^{2})"); h->SetStats(0); h->SetAxisRange(1,h->GetMaximum()*1.3,"Y"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(0.142,0.152); mass->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(0.14,0.16)/binwidth3prong; Double_t yieldErr = mass->Integral(0.14,0.16)/binwidth3prong*mass->GetParError(0)/mass->GetParameter(0); TLatex* tex; TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry((TObject*)0,"D* D^{0}(K#pi)#pi",NULL); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.20,0.79,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); c->SaveAs(Form("plots/pp/DMass_%s_3prongs-%d.pdf",texData[isData].Data(),count3p)); return mass; }
PMTCalibration(){ // Variable declarations // NOTE - Make sure the number of elements in Voltage is correct. If its not, this will // confuse the forloop. float Voltage[19] = {1.432,1.434,1.436,1.438,1.440,1.442,1.444,1.446,1.448,1.450,1.452,1.454, 1.456, 1.458, 1.460, 1.462, 1.464, 1.466, 1.468}; // LED Voltages float PedestalFitMin = -6e-12; // Minimum for pedestal fitting range float PedestalFitMax = 2e-8; // Maximum for pedestal fitting range float SignalNorm = 100; // Normalization for signal fitting float SignalMean = 5e-10; // Mean of signal distribution float SignalWidth = 1e-10; // Width of signal distribution float MaxADCforPlot = 7e-10; // Maximum of x-axis for linearity plot float MaxNPEforPlot = 60; // Maximum of y-axis for linearity plot string IsPedestalFit; // String for user interface string IsFullADCFit; // String for user interface string IsPlotPretty; // String for user interface int dummy; // Dummy variable used in sprintf stuff char filename[50]; // Array of filenames char plotname[50]; // Array of ADC plot names // Ntuple for storing the derived quantities at each voltage TNtuple *ntuple = new TNtuple("ntuple","data for each voltage","V:mean:sigma:meanerr:sigmaerr"); // Begin loop over all files/voltages for (unsigned int i=0; i<sizeof(Voltage)/sizeof(Voltage[0]); i++) { // To learn about sprintf: // http://www.cplusplus.com/reference/cstdio/sprintf/ // To learn about "%.3f": // http://en.wikibooks.org/wiki/C++_Programming/Code/Standard_C_Library/Functions/printf dummy=sprintf(filename,"F3squarepmt_1300v_%.3fv00000.txt",Voltage[i]); dummy=sprintf(plotname,"F3squarepmt_1300v_%.3fv00000.pdf",Voltage[i]); cout<<"filename: "<<filename<<endl; // Put contents of text file into TGraph TGraph *OrignalADC = new TGraph(filename); OrignalADC->Draw("A*"); // While-loop to continue iterating over the fit until the user approves it // To learn about cin and cout: // http://www.cplusplus.com/doc/tutorial/basic_io/ IsPedestalFit = "N"; while (IsPedestalFit != "Y") { // Fit a gaussian over the pedestal only. Use fit output to shift ADC plot. // The 'gpad' lines are necessary so that the plot continues to display while waiting // for user input (https://root.cern.ch/phpBB3/viewtopic.php?f=3&t=18852) PedestalFit = new TF1("h1","gaus",PedestalFitMin,PedestalFitMax); OrignalADC->Fit(PedestalFit,"R"); OrignalADC->Draw("A*"); gPad->Modified(); gPad->Update(); gSystem->ProcessEvents(); cout << "Is the pedestal fit correctly?"<< endl; cout << "Return Y for yes and N for no."<< endl; cin >> IsPedestalFit; // If pedestal fit is incorrect, change pedestal fit range and try again if (IsPedestalFit != "Y") { cout << "Enter the minimum fit range for the pedestal (ie -2e10)"<<endl; cin >> PedestalFitMin; cout << "Enter the minimum fit range for the pedestal (ie 2e10)"<<endl; cin >> PedestalFitMax; } } // Define a New TGraph with x-axis rescaled using the function below TGraph *ModifiedADC = rescaleaxis(OrignalADC,-1.0,-1.0*PedestalFit->GetParameter(1)); // Use another while loop to assure that the pedestal plus signal fit is good IsFullADCFit = "N"; while (IsFullADCFit != "Y") { // Fit with two gaussians. 0-2 are signal. 3-5 are pedestal. The 'FixParameter' keeps the pedestal gaussian fixed at 0. TF1 *FullADCFit = new TF1("FullADCFit","([0]*exp(-0.5*((x-[1])/[2])^2))+([3]*exp(-0.5*((x-[4])/[5])^2))",-1,1); FullADCFit->SetParameters(SignalNorm,SignalMean,SignalWidth,PedestalFit->GetParameter(0), 0.0, PedestalFit->GetParameter(2)); FullADCFit->FixParameter(4,0); ModifiedADC->Fit(FullADCFit,"R"); ModifiedADC->Draw("A*"); gPad->Modified(); gPad->Update(); cout << "Is the full ADC distribution fit correctly?"<< endl; cout << "Return Y for yes and N for no."<< endl; cin >> IsFullADCFit; // If ADC isn't fit correctly, give the user a chance to change the inital values of the signal fit. if (IsFullADCFit != "Y") { cout << "Enter a new initial value for the signal normalization (ie 100)"<<endl; cin >> SignalNorm; cout << "Enter a new initial value for the signal mean (ie 5e10)"<<endl; cin >> SignalMean; cout << "Enter a new initial value for the standard deviation (ie 1e10)"<<endl; cin >> SignalWidth; } }
TF1* fitDstar(TTree* nt, TTree* ntMC, Float_t ptmin, Bool_t plotgenmatch) { TCanvas* c = new TCanvas(Form("c_5p_%.0f",ptmin),"",600,600); TH1D* h = new TH1D(Form("h_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSignal = new TH1D(Form("hMCSignal_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSignalplot = new TH1D(Form("hMCSignalplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSwappedplot = new TH1D(Form("hMCSwappedplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TF1* f = new TF1(Form("f_5p_%.0f",ptmin),"[0]*([4]*([6]*([12]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[12])*Gaus(x,[1],[11])/(sqrt(2*3.14159)*[11]))+(1-[6])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5]))+(1-[4])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3]))+[10]*((1-exp((0.13957-x)/[7]))*pow(x/0.13957,[8])+[9]*(x/0.13957-1))",BINMIN,BINMAX); nt->Project(Form("h_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightdata[isData].Data(),seldata5p[isData].Data(),triggerselectiondata[isData].Data(),ptmin)); ntMC->Project(Form("hMCSignal_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selmc5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin)); ntMC->Project(Form("hMCSwapped_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selswp5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin)); for(int ibin=0;ibin<BINNUM;ibin++) hMCSignalplot->SetBinContent(ibin+1,hMCSignal->GetBinContent(ibin+1)); for(int ibin=0;ibin<BINNUM;ibin++) hMCSwappedplot->SetBinContent(ibin+1,hMCSwapped->GetBinContent(ibin+1)); f->FixParameter(4,1.); f->FixParameter(1,0.145491); f->FixParameter(10,0); f->SetParLimits(0,0,1.e+5); f->SetParLimits(6,0,1.); f->SetParLimits(12,0,1.); f->SetParLimits(2,3.e-4,1.e-3); f->SetParameter(2,5.e-4); f->SetParLimits(11,1.6e-4,3.e-4);//1.5e-4 keyong f->SetParameter(11,2.e-4); f->SetParLimits(5,1.e-3,1.6e-3); f->SetParameter(5,1.e-3); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); f->ReleaseParameter(1); f->SetParLimits(1,minmass,maxmass); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(5,f->GetParameter(5)); f->FixParameter(11,f->GetParameter(11)); f->FixParameter(6,f->GetParameter(6)); f->FixParameter(12,f->GetParameter(12)); f->FixParameter(4,0); f->SetParLimits(3,2.e-4,2.e-3); f->SetParameter(3,1.e-3); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass); f->FixParameter(4,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(3,f->GetParameter(3)); f->SetParLimits(7,5.e-4,1.e-2); f->SetParameter(7,1.6e-3); f->SetParLimits(8,0.,15.); f->SetParameter(8,0.35); f->SetParLimits(9,-2.e+1,2.e+1); f->SetParameter(9,13.); f->ReleaseParameter(10); f->SetParLimits(10,0,1.e+6); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); f->ReleaseParameter(1); f->SetParLimits(1,minmass,maxmass); f->SetParameter(1,f->GetParameter(1)); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); TF1* background = new TF1(Form("background_5p_%.0f",ptmin),"[3]*((1-exp((0.13957-x)/[0]))*pow(x/0.13957,[1])+[2]*(x/0.13957-1))"); background->SetParameters(f->GetParameter(7),f->GetParameter(8),f->GetParameter(9),f->GetParameter(10)); background->SetRange(BINMIN,BINMAX); background->SetLineColor(4); background->SetLineWidth(3); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_5p_%.0f",ptmin),"[0]*[3]*([5]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))+(1-[5])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(4),f->GetParameter(5),f->GetParameter(6),f->GetParameter(11),f->GetParameter(12)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(4)); mass->SetParError(4,f->GetParError(5)); mass->SetParError(5,f->GetParError(6)); mass->SetRange(BINMIN,BINMAX); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap_5p_%.0f",ptmin),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(4),f->GetParameter(3)); massSwap->SetRange(BINMIN,BINMAX); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})"); h->SetYTitle("Entries / (0.4 MeV/c^{2})"); h->SetStats(0); h->SetAxisRange(0,h->GetMaximum()*1.3,"Y"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); mass->Draw("same"); massSwap->Draw("same"); background->Draw("same"); f->Draw("same"); if(plotgenmatch&&(isData==MC_MB||isData==MC)) { hMCSignalplot->SetMarkerSize(0.8); hMCSignalplot->SetMarkerColor(kMagenta+2); hMCSignalplot->Draw("psame"); hMCSwappedplot->SetMarkerSize(0.8); hMCSwappedplot->SetMarkerColor(kGray+2); hMCSwappedplot->Draw("psame"); } Float_t yield = mass->Integral(BINMIN,BINMAX)/BINWID; Float_t yieldErr = mass->Integral(BINMIN,BINMAX)/BINWID*mass->GetParError(0)/mass->GetParameter(0); cout<<mass->GetParameter(0)<<" "<<mass->Integral(BINMIN,BINMAX)<<endl; TLatex* tex; TLegend* leg = new TLegend(0.60,0.57,0.85,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); tex = new TLatex(0.61,0.52,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.20,0.79,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.20,0.84,Form("p_{T} > %.1f GeV/c",ptmin)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); c->SaveAs(Form("plots/pp/fitDstar5p/DMass_%s_%.0f.pdf",texData[isData].Data(),ptmin)); return mass; }
TF1 *fit(TH1D* h, TTree *ntMC, TTree *ntMC2,double ptmin,double ptmax) { static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); // Fit function TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])+(1-[7])*Gaus(x,[1],[8]))+[3]+[4]*x+[6]*(38.42*Gaus(x,5.25,0.03473)+15.04*Gaus(x,5.25,0.1121)+104.3*Gaus(x,5.026,0.0935))"); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata.Data(),ptmin,ptmax)); ntMC2->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.1); f->SetParLimits(7,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x+[3]*(38.42*Gaus(x,5.25,0.03473)+15.04*Gaus(x,5.25,0.1121)+104.3*Gaus(x,5.026,0.0935))"); // TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*(1.24e2*Gaus(x,5.107,0.02987)+1.886e2*Gaus(x,5.0116,5.546e-2))"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*(38.42*Gaus(x,5.25,0.03473)+15.04*Gaus(x,5.25,0.1121)+104.3*Gaus(x,5.026,0.0935))"); Bkpi->SetParameter(0,f->GetParameter(6)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); Bkpi->SetRange(5.00,5.45); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3005); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])+(1-[3])*Gaus(x,[1],[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.4,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); // hBck->Draw("hist same"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); cout <<"fit result:"<<f->GetParameter(0)*2.5<<" "<<f->Integral(5,6)/h->GetBinWidth(1)<<endl; double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.92); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",f->GetParameter(1)*1000.,f->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f",yield,yieldErr),""); leg2->Draw(); //c->SaveAs(Form("ResultsCheckStatErr/BMass-%d.C",count)); c->SaveAs(Form("ResultsCheckStatErr/BMass-%d.gif",count)); //c->SaveAs(Form("ResultsBzero/BMass-%d.eps",count)); return mass; }
void SPEFit(char * fLEDname, char * fPEDname, int run, int LED_amp, double cutmax = 250.0) { //set plotting styles gStyle->SetCanvasColor(0); gStyle->SetPadColor(0); gStyle->SetCanvasBorderMode(0); gStyle->SetFrameBorderMode(0); gStyle->SetStatColor(0); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); //set file names stringstream out_fname; stringstream out_fname1; out_fname<<"SPEconstants_Run_"<<run<<".txt"; out_fname1<<"SPEspec_Run_"<<run<<".txt"; ofstream constants_file(out_fname.str().c_str(),ios_base::trunc); //ofstream constants_file1(out_fname1.str().c_str(),ios_base::trunc); constants_file<<"Run "<<run<<endl; constants_file<<"type SPE"<<endl; constants_file<<"LED_amplitude "<<LED_amp<<endl<<endl; constants_file<<endl<<"LED_amplitude Depth Phi Eta Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl; out_fname.str(""); out_fname<<"SPEdistributions_Run_"<<run<<".txt"; out_fname.str(""); out_fname<<"SPEextra_Run_"<<run<<".txt"; //ofstream extra_file(out_fname.str().c_str(),ios_base::trunc); double scale = 1.0; scale = 2.6; //Need to scale up HF charge double fC2electrons = 6240.; //convert fC to #electrons char spename[128], pedname[128], spehistname[128]; TFile *tfLED = new TFile(fLEDname); TFile *tfPED = new TFile(fPEDname); //const int NnewBins = 106; //double binsX[NnewBins] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,180,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500}; const int NnewBins = 80; double binsX[NnewBins] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500}; TH1F* hspe = new TH1F("hspe","hspe",NnewBins-1,binsX); int NDepth = 2; //number of depths int MinDepth = 1; int MaxDepth = 2; int MinEta = 29; int MaxEta = 41; int MinPhi = 41; int MaxPhi = 53; TCanvas *Carray[NDepth+1][MaxPhi+1]; bool drawflag[NDepth+1][MaxPhi+1]; TH1F *LED[NDepth+1][MaxEta+1][MaxPhi+1]; TH1F *PED[NDepth+1][MaxEta+1][MaxPhi+1]; for(int iDepth = MinDepth; iDepth <= MaxDepth; iDepth++){ for(int iPhi = MinPhi; iPhi <= MaxPhi; iPhi++){ bool nonNull = false; for(int iEta = MinEta; iEta <= MaxEta; iEta++){ sprintf(spename,"Analyzer/CommonDir/ResPlotDir/Histo_for_Depth_%d_Eta_%d_Phi_%d",iDepth,iEta,iPhi); LED[iDepth][iEta][iPhi]=(TH1F *)tfLED->Get(spename); if(LED[iDepth][iEta][iPhi]) nonNull = true; sprintf(spename,"Analyzer/CommonDir/ResPlotDir/Histo_for_Depth_%d_Eta_%d_Phi_%d",iDepth,iEta,iPhi); PED[iDepth][iEta][iPhi]=(TH1F *)tfPED->Get(spename); } drawflag[iDepth][iPhi] = false; char canvname[16]; sprintf(canvname, "c_%d_%d", iDepth,iPhi); if(nonNull){ //only create canvas if distributions exist Carray[iDepth][iPhi] = new TCanvas(canvname,canvname,1200,700); Carray[iDepth][iPhi]->Divide(5,3); } } } int HV=0; for(int iDepth = MinDepth; iDepth <= MaxDepth; iDepth++){ for(int iPhi = MinPhi; iPhi <= MaxPhi; iPhi++){ for(int iEta = MinEta; iEta <= MaxEta; iEta++){ //cout<<iDepth<<" "<<iPhi<<" "<<iEta<<endl; if(!LED[iDepth][iEta][iPhi]) continue; sprintf(spehistname,"led %d %d %d",iDepth,iEta,iPhi); TH1F *hspe_temp = (TH1F *)LED[iDepth][iEta][iPhi]->Clone(spehistname); sprintf(spehistname,"ped %d %d %d",iDepth,iEta,iPhi); TH1F *hped = (TH1F *)PED[iDepth][iEta][iPhi]->Clone(spehistname); hspe->Reset(); sprintf (spehistname, "SumLED_Depth_%d_Eta_%d_Phi_%d",iDepth,iEta,iPhi); hspe->SetTitle(spehistname); //combine bins of original SPE histogram for(int ib=1; ib<=hspe_temp->GetNbinsX(); ib++) { double bin_center = hspe_temp->GetBinCenter(ib); if(bin_center>hspe->GetXaxis()->GetXmax()) continue; int newbin = hspe->FindBin(bin_center); double new_content = hspe->GetBinContent(newbin) + hspe_temp->GetBinContent(ib); double new_error = sqrt(pow(hspe->GetBinError(newbin),2)+pow(hspe_temp->GetBinError(ib),2)); hspe->SetBinContent(newbin,new_content); hspe->SetBinError(newbin,new_error); } TH1F* hspe_unscaled = (TH1F*)hspe->Clone("hspe_unscaled"); //renormalize bins of new SPE histogram for(int ib=1; ib<=hspe->GetNbinsX(); ib++) { double new_content = hspe->GetBinContent(ib)/hspe->GetXaxis()->GetBinWidth(ib)*hspe_temp->GetXaxis()->GetBinWidth(1); double new_error = hspe->GetBinError(ib)/hspe->GetXaxis()->GetBinWidth(ib)*hspe_temp->GetXaxis()->GetBinWidth(1); hspe->SetBinContent(ib,new_content); hspe->SetBinError(ib,new_error); } if(hspe_temp->Integral()==0) continue; else drawflag[iDepth][iPhi] = true; Nev = hspe_temp->Integral()*hspe_temp->GetXaxis()->GetBinWidth(1); TF1 *fped = new TF1("fped","gaus",0, 80); hped->Fit(fped,"NQR"); double pploc = fped->GetParameter(1), ppwidth = fped->GetParameter(2); hspe->Fit(fped, "NQ", "", pploc - 3*ppwidth, pploc + ppwidth); //estimate SPE peak location int max_SPE_bin, maxbin, Nbins; double max_SPE_height=0, minheight, max_SPE_location; bool minflag = false; maxbin=hspe->FindBin(fped->GetParameter(1)); //location of pedestal peak minheight=hspe->GetBinContent(maxbin); //initialize minheight Nbins = hspe->GetNbinsX(); for(int j=maxbin+1; j<Nbins-1; j++) { //start from pedestal peak and loop through bins if(hspe->GetBinContent(j) > minheight && !minflag) minflag=true; //only look for SPE peak when minflag=true if(hspe->GetBinContent(j) < minheight ) minheight = hspe->GetBinContent(j); if(minflag && hspe->GetBinContent(j) > max_SPE_height){ max_SPE_bin = j; max_SPE_location = hspe->GetBinCenter(max_SPE_bin); max_SPE_height = hspe->GetBinContent(j); } } //start from pedestal peak and loop through bins //find minimum bin between pedestal and SPE peaks hspe->GetXaxis()->SetRange(maxbin,max_SPE_bin); int minbin = hspe->GetMinimumBin(); double minbin_location = hspe->GetBinCenter(minbin); hspe->GetXaxis()->SetRange(1,Nbins); TF1 *fit = new TF1("fit", FitFun, 0, 500, 5); double mu = - log(fped->Integral(0,100)/Nev); if(mu<0) mu=0.01; double gain_est = max_SPE_location-1.0*fped->GetParameter(1); if(max_SPE_bin > (minbin+1)) fit->SetParameters(mu, 20, 1, gain_est, gain_est*0.5); else fit->SetParameters(mu, 20, 1, 2.1*fped->GetParameter(2), 10); //case of no clear minimum; start looking for SPE peak at 2sigma away from pedestal peak fit->SetParLimits(0, 0, 10); fit->FixParameter(1, fped->GetParameter(1)); fit->FixParameter(2, fped->GetParameter(2)); fit->SetParLimits(3, fped->GetParameter(2)*2, 350); fit->SetParLimits(4, fped->GetParameter(2)*1.01, 250); double maxfitrange = 500.; double minfitrange = 0.; hspe->Fit(fit, "MNQL", "", minfitrange, maxfitrange); maxfitrange = fped->GetParameter(1)+4*fit->GetParameter(3)+fit->GetParameter(4); if(500<maxfitrange) maxfitrange = 500; hspe->Fit(fit, "MNQL", "", minfitrange, maxfitrange); //calculate NDOF of fit excluding bins with 0 entries int myNDOF=-3; //three free parameters for(int j=hspe->FindBin(minfitrange); j<=hspe->FindBin(maxfitrange); j++) { //loop through fitted spe bins if(hspe->GetBinContent(j)) myNDOF++; } //loop through fitted spe bins //calculate means and integrals of the fit and data double fint, fint_error, hint, favg, havg; int temp_lowbin, temp_highbin; temp_lowbin = hspe->FindBin(minfitrange); temp_highbin = hspe->FindBin(maxfitrange); hspe_unscaled->GetXaxis()->SetRangeUser(minfitrange, maxfitrange); havg = hspe_unscaled->GetMean(); hint = hspe->Integral(temp_lowbin,temp_highbin,"width"); double min_frange = hspe->GetBinLowEdge(temp_lowbin); favg = fit->Mean(min_frange, maxfitrange); fint = fit->Integral(min_frange, maxfitrange); //fint_error = fit->IntegralError(min_frange, maxfitrange); double PE5int = 0; //integral of events with >=5 PE double PE5loc = fped->GetParameter(1)+ 5*fit->GetParameter(3); if(PE5loc>500) PE5int = 0; else { int PE5bin = hspe_temp->FindBin(PE5loc); temp_highbin = hspe_temp->FindBin(maxfitrange)-1; PE5int = hspe_temp->Integral(PE5bin,temp_highbin,"width"); } int PE5flag = 0; if(PE5int/hint>0.05) PE5flag = 1; //set flag if more than 5% of events in the fit correspond to >=5PE //========================================= //for(int i1=1;i1<hspe->GetNbinsX();i1++){ //constants_file1<<HV<<"\t"<<iDepth<<"\t"<<iEta<<"\t"<<iPhi<<"\t"<<2.6*hspe->GetBinCenter(i1)<<"\t"<<hspe->GetBinContent(i1)<<"\t"<<fit->Eval(hspe->GetBinCenter(i1))<<"\n"; //} //========================================= //printf("%d\n",myNDOF); //output calibrations constants //constants_file<<endl<<"LED_amplitude HV Spigot Channel Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl; constants_file<<LED_amp<<" "<<iDepth<<" "<<iPhi<<" "<<iEta<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParError(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fped->GetParError(2)<<" "<<scale*fit->GetParameter(4)<<" "<<scale*fit->GetParError(4)<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<scale*fit->GetParError(3)*fC2electrons<<" "<<fit->GetChisquare()/myNDOF/*fit->GetNDF()*/<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<endl; /* if(iDepth==2 && iPhi==53 && iEta==36){ cout<<iDepth<<" "<<iPhi<<" "<<iEta<<" "<<gain_est<<" "<<fit->GetParameter(3)<<endl; cout<<LED_amp<<" "<<iDepth<<" "<<iPhi<<" "<<iEta<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParError(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fped->GetParError(2)<<" "<<scale*fit->GetParameter(4)<<" "<<scale*fit->GetParError(4)<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<scale*fit->GetParError(3)*fC2electrons<<" "<<fit->GetChisquare()/myNDOF<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<endl; } */ Carray[iDepth][iPhi]->cd(iEta-MinEta+1); gPad->SetBorderMode(0); gPad->SetBorderSize(0); gPad->SetRightMargin(0.01); gPad->SetBottomMargin(0.1); gPad->SetLogy(true); hspe->GetXaxis()->SetRangeUser(0, 200 /*300*//*508*/); hspe->SetLineColor(kBlue); hspe->DrawClone("hist"); fit->SetLineWidth(2); fit->Draw("same"); } if(drawflag[iDepth][iPhi]) { //draw plots of fit if data for the HV is present stringstream plot_name; plot_name<<"Plots/SPEFits_Run_"<<run<<"_Depth"<<iDepth<<"_Phi"<<iPhi<<".pdf"; Carray[iDepth][iPhi]->SaveAs(plot_name.str().c_str()); plot_name.str( std::string() ); } } } constants_file.close(); //constants_file1.close(); }
void calc(TFile *file1, TFile *file2, const char* basename, int projnumb) { TH1D *hp5_1 = (TH1D *)file1->Get(Form("%s_VMIN_SIPM1_meanHistSub_hproj_%d",basename,projnumb)); TH1D *hp5_2 = (TH1D *)file2->Get(Form("%s_VMIN_SIPM2_meanHistSub_hproj_%d",basename,projnumb)); if(hp5_1==NULL) {cout<<"cannot find hp5_1"<<endl; return;} if(hp5_2==NULL) {cout<<"cannot find hp5_2"<<endl; return;} int nbins = hp5_1->GetNbinsX(); // ---------------------------------------------------------------------------- // --- one of the preamps was broken, so we only had measurements from 1 SiPM // --- I made this fake data part to help in the code development while waiting // --- for new data with both SiPMs to be available // ---------------------------------------------------------------------------- bool makefakedata = false; if(makefakedata) { for(int i=0; i<nbins; i++) { hp5_2->SetBinContent(i+1,hp5_1->GetBinContent(nbins-i)); } } double max1 = hp5_1->GetMaximum(); double max2 = hp5_2->GetMaximum(); hp5_1->GetXaxis()->SetTitle("Distance (cm)"); hp5_2->GetXaxis()->SetTitle("Distance (cm)"); hp5_1->GetYaxis()->SetTitle("Number of photoelectrons"); hp5_2->GetYaxis()->SetTitle("Number of photoelectrons"); if(max1>=max2) { // case 1 hp5_1->Draw(); hp5_2->Draw("same"); } else { // case 2 hp5_2->Draw(); hp5_1->Draw("same"); } hp5_1->SetLineColor(kBlue); hp5_2->SetLineColor(kRed); hp5_1->SetLineWidth(2); hp5_2->SetLineWidth(2); // legend coordinates may occasionally need to be relocated TLegend *leg = new TLegend(0.4,0.2,0.6,0.4); leg->AddEntry(hp5_1,"SiPM1","l"); leg->AddEntry(hp5_2,"SiPM2","l"); leg->SetFillStyle(0); leg->Draw(); // generalize c1->Print(Form("Figures/ATOGETHER_%s_p%d.png",basename,projnumb)); c1->Print(Form("Figures/ATOGETHER_%s_p%d.pdf",basename,projnumb)); ofstream fout(Form("Data/Text/Asymmetry/%s_asymmetry_p%d.txt",basename,projnumb)); TH1D *hp5_asymm = (TH1D *)hp5_1->Clone(); double x[58]; double y[58]; double y1[58]; double y2[58]; TH1D *h1 = new TH1D("h1","",50,0,25); TH1D *h2 = new TH1D("h2","",50,0,25); for(int i=0; i<nbins; i++) { double A = hp5_1->GetBinContent(i+1); double B = hp5_2->GetBinContent(i+1); double content = (B-A)/(B+A); hp5_asymm->SetBinContent(i+1,content); hp5_asymm->SetBinError(i+1,0); // --- x[i] = hp5_1->GetBinCenter(i+1); y[i] = content; y1[i] = A; y2[i] = B; x[i] -= 2.0; // offset for off-panel part of scan, needs manual adjustment if(i>3&&i<54) { // offset for off-panel, needs manual adjustment h1->SetBinContent(i-3,A); h2->SetBinContent(i-3,B); h1->SetBinError(i-3,0); h2->SetBinError(i-3,0); } // --- fout<<hp5_asymm->GetBinCenter(i+1)<<" " <<hp5_asymm->GetBinContent(i+1)<<endl; } fout.close(); hp5_asymm->SetMarkerColor(kBlack); hp5_asymm->SetMarkerStyle(kFullCircle); hp5_asymm->Draw("ex0p"); hp5_asymm->GetYaxis()->SetTitle("Asymmetry of light yields"); hp5_asymm->SetMinimum(-1); hp5_asymm->SetMaximum(1); TLine line(0.0,0.0,29.0,0.0); line.SetLineStyle(2); line.SetLineWidth(2); line.Draw(); // generalize c1->Print(Form("Figures/ASYMMETRY_%s_p%d.png",basename,projnumb)); c1->Print(Form("Figures/ASYMMETRY_%s_p%d.pdf",basename,projnumb)); // --- h1->SetLineColor(kBlue); h2->SetLineColor(kRed); h1->SetLineWidth(2); h2->SetLineWidth(2); h1->SetMinimum(0); h2->SetMinimum(0); h1->GetXaxis()->SetTitle("Distance (cm)"); h2->GetXaxis()->SetTitle("Distance (cm)"); h1->GetYaxis()->SetTitle("Number of photoelectrons"); h2->GetYaxis()->SetTitle("Number of photoelectrons"); TGraph *tgy1 = new TGraph(58,x,y1); TGraph *tgy2 = new TGraph(58,x,y2); tgy1->SetLineColor(kBlue); tgy2->SetLineColor(kRed); tgy1->SetLineWidth(2); tgy2->SetLineWidth(2); tgy1->SetMinimum(0); tgy2->SetMinimum(0); tgy1->GetXaxis()->SetTitle("Distance (cm)"); tgy2->GetXaxis()->SetTitle("Distance (cm)"); tgy1->GetYaxis()->SetTitle("Number of photoelectrons"); tgy2->GetYaxis()->SetTitle("Number of photoelectrons"); double maxx = 0; if(max1>=max2) { // case 1 maxx = max1; h1->Draw(); h2->Draw("same"); } else { // case 2 maxx = max2; h2->Draw(); h1->Draw("same"); } TF1 *funx1 = new TF1("funx1","[0]+[1]*TMath::Exp(-x/[2])",0,25); funx1->SetLineColor(kBlue); funx1->SetParameter(0,5.0); // number of photoelectrons in core funx1->SetParameter(1,5.0); // number of photoelectrons in clad funx1->FixParameter(2,cld); // clad decay constant tgy1->Fit(funx1,"","",1,24); // need to use TGraph here, fitting h1 produces "Warning in <Fit>: Fit data is empty" // I don't know why this happening, probably some dumb mistake I'm making TF1 *funx2 = new TF1("funx2","[0]+[1]*TMath::Exp((x-25)/[2])",0,25); funx2->SetLineColor(kRed); funx2->SetParameter(0,5.0); // number of photoelectrons in core funx2->SetParameter(1,5.0); // number of photoelectrons in clad funx2->FixParameter(2,cld); // clad decay constant tgy2->Fit(funx2,"","",1,24); // need to use TGraph here, fitting h2 produces "Warning in <Fit>: Fit data is empty" // I don't know why this happening, probably some dumb mistake I'm making // tgy1->Draw("same"); // looks cool but distracting // tgy2->Draw("same"); // looks cool but distracting funx1->Draw("same"); funx2->Draw("same"); double numcore1 = funx1->GetParameter(0); double numclad1 = funx1->GetParameter(1); double numcore2 = funx2->GetParameter(0); double numclad2 = funx2->GetParameter(1); double Enumcore1 = funx1->GetParError(0); double Enumclad1 = funx1->GetParError(1); double Enumcore2 = funx2->GetParError(0); double Enumclad2 = funx2->GetParError(1); double fracore1 = (numcore1)/(numcore1+numclad1); double fracore2 = (numcore2)/(numcore2+numclad2); // --- double partB; partB = sqrt(Enumcore1**2+Enumclad2**2); double Efracore1 = fracore1*sqrt((Enumcore1/numcore1)**2+(partB/(numcore1+numclad1))**2); partB = sqrt(Enumcore2**2+Enumclad2**2); double Efracore2 = fracore2*sqrt((Enumcore2/numcore2)**2+(partB/(numcore2+numclad2))**2); TLatex *texAC1 = new TLatex(2,0.27*maxx,Form("f_{core} = %.3f #pm %.3f",fracore1,Efracore1)); texAC1->SetTextColor(kBlue); texAC1->Draw(); TLatex *texAC2 = new TLatex(15,0.27*maxx,Form("f_{core} = %.3f #pm %.3f",fracore2,Efracore2)); texAC2->SetTextColor(kRed); texAC2->Draw(); // --- TLatex *texAA1 = new TLatex(2,0.18*maxx,Form("N_{core} = %.3f #pm %.3f",numcore1,Enumcore1)); texAA1->SetTextColor(kBlue); texAA1->Draw(); TLatex *texAA2 = new TLatex(15,0.18*maxx,Form("N_{core} = %.3f #pm %.3f",numcore2,Enumcore2)); texAA2->SetTextColor(kRed); texAA2->Draw(); TLatex *texAB1 = new TLatex(2,0.1*maxx,Form("N_{clad} = %.3f #pm %.3f",numclad1,Enumclad1)); texAB1->SetTextColor(kBlue); texAB1->Draw(); TLatex *texAB2 = new TLatex(15,0.1*maxx,Form("N_{clad} = %.3f #pm %.3f",numclad2,Enumclad2)); texAB2->SetTextColor(kRed); texAB2->Draw(); // --- c1->Print(Form("Figures/FITATOGETHER_%s_p%d.png",basename,projnumb)); c1->Print(Form("Figures/FITATOGETHER_%s_p%d.pdf",basename,projnumb)); // --- // define a function to describe the data // this function defines and asymmetry B-A/A+B // it assumes the light yield has two components, core and cladding TF1 *fun = new TF1("fun","(([0]*TMath::Exp((x-25)/[1])+(1-[0])*TMath::Exp((x-25)/[2]))-([0]*TMath::Exp(-x/[1])+(1-[0])*TMath::Exp(-x/[2])))/(([0]*TMath::Exp(-x/[1])+(1-[0])*TMath::Exp(-x/[2]))+([0]*TMath::Exp((x-25)/[1])+(1-[0])*TMath::Exp((x-25)/[2])))",0,29); fun->SetParameter(0,0.5); // light fraction in fiber core fun->FixParameter(1,350); // decay constant in fiber core fun->FixParameter(2,cld); // decay constant in fiber cladding TF1 *fun2 = new TF1("fun2","[3]+(([0]*TMath::Exp((x-25)/[1])+(1-[0])*TMath::Exp((x-25)/[2]))-([0]*TMath::Exp(-x/[1])+(1-[0])*TMath::Exp(-x/[2])))/(([0]*TMath::Exp(-x/[1])+(1-[0])*TMath::Exp(-x/[2]))+([0]*TMath::Exp((x-25)/[1])+(1-[0])*TMath::Exp((x-25)/[2])))",0,29); fun2->SetParameter(0,0.5); // light fraction in fiber core fun2->FixParameter(1,350); // decay constant in fiber core fun2->FixParameter(2,cld); // decay constant in fiber cladding fun2->SetParameter(3,0.01); TGraph *tg = new TGraph(58,x,y); tg->SetMarkerStyle(kFullCircle); tg->Draw("ap"); tg->GetYaxis()->SetTitle("Asymmetry of light yields"); tg->GetXaxis()->SetTitle("Distance (cm)"); tg->GetXaxis()->SetLimits(0,25); double scale = 0.4; tg->SetMinimum(-1*scale); tg->SetMaximum(1*scale); tg->Fit("fun2","","",0,25); TLine line2(0.0,0.0,25.0,0.0); line2.SetLineStyle(2); line2.SetLineWidth(2); line2.Draw(); // get the fit parameters double frac = fun2->GetParameter(0); double core = fun2->GetParameter(1); double clad = fun2->GetParameter(2); double Efrac = fun2->GetParError(0); double off = fun2->GetParameter(3); double Eoff = fun2->GetParError(3); // use the fit parameters to put text boxes with fit information on the plt TLatex *tex1 = new TLatex(15,-0.30*scale,Form("f_{core} = %.3f #pm %.3f",frac,Efrac)); tex1->SetTextColor(kGreen+2); tex1->Draw(); TLatex *tex2 = new TLatex(15,-0.45*scale,Form("#lambda_{core} = %.1f (FIXED)",core)); tex2->SetTextColor(kBlack); tex2->Draw(); TLatex *tex3 = new TLatex(15,-0.60*scale,Form("#lambda_{clad} = %.1f (FIXED)",clad)); tex3->SetTextColor(kBlack); tex3->Draw(); TLatex *texX = new TLatex(15,-0.75*scale,Form("offset = %.3f #pm %.3f",off,Eoff)); texX->SetTextColor(kGreen+2); texX->Draw(); // generalize c1->Print(Form("Figures/FITASYMMETRY_%s_p%d.png",basename,projnumb)); c1->Print(Form("Figures/FITASYMMETRY_%s_p%d.pdf",basename,projnumb)); // --- frac1[projnumb] = fracore1; frac2[projnumb] = fracore2; fracAv[projnumb] = (fracore1+fracore2)/2.0; fracAs[projnumb] = frac; delete h1; delete h2; }
void DrawPhi(Int_t step=1,Float_t ptmin=0,Float_t ptmax=10){ TFile *fcur = TFile::Open(Form("step%i.root",step)); TFile *fpre = TFile::Open(Form("step%i.root",step-1)); TH2D *hcurT = (TH2D *) fcur->Get("truePidPhiKaKa"); TH2D *hcurP = (TH2D *) fcur->Get("priorsPhiKaKa"); TH2D *hpreT = (TH2D *) fpre->Get("truePidPhiLaKa"); TH2D *hpreP = (TH2D *) fpre->Get("priorsPhiKaKa"); TH2D *hPion = (TH2D *) fcur->Get("priorsPhiPiPi"); // hPion->Add((TH2D *) fcur->Get("priorsPhiPiKa")); // hPion->Add((TH2D *) fcur->Get("priorsPhiPiPr")); // hPion->Add((TH2D *) fcur->Get("priorsPhiKaPi")); // hPion->Add((TH2D *) fcur->Get("priorsPhiPrPi")); TH1D *hprior = hcurP->ProjectionX("meas",hcurP->GetYaxis()->FindBin(ptmin+0.001),hcurP->GetYaxis()->FindBin(ptmax-0.001)); TH1D *htrue = hcurT->ProjectionX("true",hcurT->GetYaxis()->FindBin(ptmin+0.001),hcurT->GetYaxis()->FindBin(ptmax-0.001)); TH1D *hpriorOld = hpreP->ProjectionX("measOld",hpreP->GetYaxis()->FindBin(ptmin+0.001),hpreP->GetYaxis()->FindBin(ptmax-0.001)); TH1D *hnorm = hPion->ProjectionX("norm",hPion->GetYaxis()->FindBin(ptmin+0.001),hPion->GetYaxis()->FindBin(ptmax-0.001)); for(Int_t i=1;i <= hprior->GetNbinsX();i++){ Float_t err = TMath::Abs(hprior->GetBinContent(i)-hpriorOld->GetBinContent(i)); if(hprior->GetBinContent(i)){ err *= hnorm->GetBinContent(i); err /= hprior->GetBinContent(i); } hprior->SetBinError(i,err); //htrue->SetBinError(i,0); } TF1 *bw = new TF1("bw","[0]/((x-[1])*(x-[1]) +([2]*[2]*0.25)) + pol1(3)",1,1.05); TF1 *bwsig = new TF1("bw","[0]/((x-[1])*(x-[1]) +([2]*[2]*0.25))",1,1.05); bw->SetLineColor(2); bw->SetParameter(0,100); bw->FixParameter(1,1.02); bw->FixParameter(2,0.00426); bw->SetParameter(3,0); bw->SetParameter(4,0); bw->SetParameter(5,0); TCanvas *c = new TCanvas(); c->Divide(1,2); c->cd(1); hprior->Draw("ERR3"); htrue->SetLineColor(2); htrue->Draw("SAME"); htrue->Fit(bw,"W","",1,1.05); for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i)); Float_t truesig = bwsig->Integral(1,1.05) / htrue->GetBinWidth(1); hprior->Fit(bw,"W","",1,1.05); for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i)); Float_t meassig = bwsig->Integral(1,1.05) / htrue->GetBinWidth(1); c->cd(2); bw->SetParameter(0,100); bw->SetParameter(3,0); bw->SetParameter(4,0); bw->SetParameter(5,0); TH1D *hr=new TH1D(*hprior); hr->Add(htrue,-1); hr->GetYaxis()->SetTitle("(meas-true)/true"); hr->Divide(htrue); hr->Draw(); hr->GetYaxis()->UnZoom(); hr->Fit("pol0"); hr->Fit(bw,"W","",1,1.05); for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i)); Float_t deltasig = bwsig->Integral(1,1.05) / hr->GetBinWidth(1); printf("signal = %f -- delta = %f (%f) --> Precision = %f(%f)%c\n",truesig,meassig-truesig,deltasig,(meassig-truesig)/truesig,deltasig/truesig*100,'%'); }
TF1* fitMass(TH1D* hData, TH1D* hMCSignal, TH1D* hMCSwapped) { Double_t setparam0=100.; Double_t setparam1=1.865; Double_t setparam2=0.03; Double_t setparam10=0.005; Double_t setparam8=0.1; Double_t setparam9=0.1; Double_t fixparam1=1.865; Double_t minhisto=1.7; Double_t maxhisto=2.0; TF1* f = new TF1("fMass","[0]*([7]*([9]*Gaus(x,[1],[2]*(1+[11]))/(sqrt(2*3.1415927)*[2]*(1+[11]))+(1-[9])*Gaus(x,[1],[10]*(1+[11]))/(sqrt(2*3.1415927)*[10]*(1+[11])))+(1-[7])*Gaus(x,[1],[8]*(1+[11]))/(sqrt(2*3.1415927)*[8]*(1+[11])))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.005,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); f->FixParameter(11,0); hMCSignal->Fit("fMass","q","",minhisto,maxhisto); hMCSignal->Fit("fMass","q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit("fMass","L q","",minhisto,maxhisto); hMCSignal->Fit("fMass","L q","",minhisto,maxhisto); hMCSignal->Fit("fMass","L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); hData->Fit("fMass","q","",minhisto,maxhisto); hData->Fit("fMass","q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,1.86,1.87); f->ReleaseParameter(11); f->SetParLimits(11,-0.2,0.2); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L m","",minhisto,maxhisto); TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1("fSignal","[0]*([3]*([4]*Gaus(x,[1],[2]*(1+[6]))/(sqrt(2*3.1415927)*[2]*(1+[6]))+(1-[4])*Gaus(x,[1],[5]*(1+[6]))/(sqrt(2*3.1415927)*[5]*(1+[6]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(11)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1("fBackground","[0]*(1-[2])*Gaus(x,[1],[3]*(1+[4]))/(sqrt(2*3.1415927)*[3]*(1+[4]))"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8),f->GetParameter(11)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); hData->SetXTitle("m_{#piK} (GeV/c^{2})"); hData->SetYTitle("Entries / (5 MeV/c^{2})"); hData->SetAxisRange(0,hData->GetBinContent(hData->GetMaximumBin())*1.4*1.2,"Y"); hData->SetMarkerSize(0.3); hData->Draw("e"); cout<<"hData->GetMaximum(): "<<hData->GetMaximum()<<endl; background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/hData->GetBinWidth(1); Double_t yieldErr = mass->Integral(minhisto,maxhisto)/hData->GetBinWidth(1)*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"integral function yield: "<<yield<<" fit yield: "<<f->GetParameter(0)*f->GetParameter(7)/hData->GetBinWidth(1)<<" +- "<<f->GetParError(0)*f->GetParameter(7)/hData->GetBinWidth(1)<<std::endl; TLegend* leg = new TLegend(0.65,0.5,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.06); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(hData,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); hData->GetFunction("fMass")->Delete(); TH1D* hDataNoFitFun = (TH1D*) hData->Clone("hDataNoFitFun"); hDataNoFitFun->Draw("esame"); return f; }