TF1* fit(TH1D* h, TH1D* hMCSignal, TH1D* hMCSwapped, Float_t ptmin, Float_t ptmax, Int_t j) { TCanvas* c = new TCanvas(Form("c_%.0f_%.0f_%d",ptmin,ptmax,j),"",600,600); TF1* f = new TF1(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]*([7]*([9]*Gaus(x,[1],[2]*(1+[11]))/(sqrt(2*3.14159)*[2]*(1+[11]))+(1-[9])*Gaus(x,[1],[10]*(1+[11]))/(sqrt(2*3.14159)*[10]*(1+[11])))+(1-[7])*Gaus(x,[1],[8]*(1+[11]))/(sqrt(2*3.14159)*[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.001,0.05); f->SetParLimits(2,0.01,0.5); 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); h->GetEntries(); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"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(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"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); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,1.86,1.87); /* f->ReleaseParameter(11); f->SetParLimits(11,-1.,1.); */ h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L m","",minhisto,maxhisto); TF1* background = new TF1(Form("background_%.0f_%.0f_%d",ptmin,ptmax,j),"[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(Form("mass_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]*([3]*([4]*Gaus(x,[1],[2]*(1+[6]))/(sqrt(2*3.14159)*[2]*(1+[6]))+(1-[4])*Gaus(x,[1],[5]*(1+[6]))/(sqrt(2*3.14159)*[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(Form("massSwap_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]*(1-[2])*Gaus(x,[1],[3]*(1+[4]))/(sqrt(2*3.14159)*[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); h->SetXTitle("m_{#piK} (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"); 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)/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,"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"); DrawCmsTlatex("PbPb"); TLatex* tex; tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); TString texper="%"; tex = new TLatex(0.22,0.72,Form("Centrality %.0f-%.0f%s",centMin,centMax,texper.Data())); tex->SetNDC(); tex->SetTextColor(1); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); tex->Draw(); c->SaveAs(Form("plots/Mass_cent_%.0f_%.0f_pt_%.0f_%.0f_%s.pdf",centMin,centMax,ptmin,ptmax,tfend[j].Data())); return mass; }
void recurseFile(TDirectory *indir, TDirectory *outdir, double etawid, double etamid) { TDirectory *curdir = gDirectory; // Automatically go through the list of keys (directories) TList *keys = indir->GetListOfKeys(); TListIter itkey(keys); TObject *key, *obj; TDirectory *dir; while ( (key = itkey.Next()) ) { if (_debug) cout << key->GetName() << endl << flush; obj = ((TKey*)key)->ReadObj(); assert(obj); dir = indir; // Found a subdirectory: copy it to output and go deeper if (obj->InheritsFrom("TDirectory")) { //assert(outdir->mkdir(obj->GetName())); outdir->mkdir(obj->GetName()); assert(outdir->cd(obj->GetName())); TDirectory *outdir2 = outdir->GetDirectory(obj->GetName()); assert(outdir2); outdir2->cd(); assert(indir->cd(obj->GetName())); TDirectory *indir2 = indir->GetDirectory(obj->GetName()); indir2->cd(); // Check if directory name contains information on eta bin width float etamin, etamax; if ( (sscanf(indir->GetName(),"Eta_%f-%f",&etamin,&etamax)==2) && (etamax>etamin) ) { etawid = 2.*(etamax-etamin); etamid = 0.5*(etamax+etamin); //cout << "Eta bin width: " << etawid << flush << endl; } recurseFile(indir2, outdir2, etawid, etamid); //outdir2->Write(); // does this speedup or slow down? } // inherits from TDirectory // Found a plot: normalize if hpt, then copy to output if (obj->InheritsFrom("TH1")) { outdir->cd(); TObject *obj2 = obj->Clone(obj->GetName()); // Normalize hpt and hselpt histograms // Same for hbpt if (string(obj2->GetName())=="hpt" || string(obj2->GetName())=="hpt_evt" || string(obj2->GetName())=="hpt_jet" || string(obj2->GetName())=="hpt_pre" || string(obj2->GetName())=="hpt0" || string(obj2->GetName())=="hpt1" || string(obj2->GetName())=="hpt2" || string(obj2->GetName())=="hpt3" || string(obj2->GetName())=="hpt_jk1" || string(obj2->GetName())=="hpt_jk2" || string(obj2->GetName())=="hpt_jk3" || string(obj2->GetName())=="hpt_jk4" || string(obj2->GetName())=="hpt_jk5" || string(obj2->GetName())=="hpt_jk6" || string(obj2->GetName())=="hpt_jk7" || string(obj2->GetName())=="hpt_jk8" || string(obj2->GetName())=="hpt_jk9" || string(obj2->GetName())=="hpt_jk10" || string(obj2->GetName())=="hpt_l1off" || string(obj2->GetName())=="hpt_l1fast" || string(obj2->GetName())=="hpt_plus" || string(obj2->GetName())=="hpt_minus" || string(obj2->GetName())=="hpt0_plus" || string(obj2->GetName())=="hpt0_minus" || string(obj2->GetName())=="hpt_noid" || string(obj2->GetName())=="hpt_noevtid" || string(obj2->GetName())=="hpt_nojetid" || string(obj2->GetName())=="hpt_ak5calo" || string(obj2->GetName())=="hpt_ak5pf" || string(obj2->GetName())=="hpt_evt_ak5pf" || string(obj2->GetName())=="hpt_jet_ak5pf" || string(obj2->GetName())=="hselpt" || string(obj2->GetName())=="hpt_r" || string(obj2->GetName())=="hpt_g" || string(obj2->GetName())=="hpt_gg" || string(obj2->GetName())=="hpt_g0" || string(obj2->GetName())=="hpt_g0tw" || string(obj2->GetName())=="hdjmass" || string(obj2->GetName())=="hdjmass0" || string(obj2->GetName())=="hdjmass0_hgg") { cout << "." << flush; TH1D *hpt = (TH1D*)obj2; bool isgen = TString(obj2->GetName()).Contains("pt_g"); bool isoth = (TString(obj2->GetName()).Contains("pt_no") || TString(obj2->GetName()).Contains("djmass") || TString(obj2->GetName()).Contains("hpt0") || TString(obj2->GetName()).Contains("l1off") || TString(obj2->GetName()).Contains("l1fast")); bool iscalo = (TString(obj2->GetName()).Contains("_ak5calo")); bool ispf5 = (TString(obj2->GetName()).Contains("_ak5pf")); bool ispre = (TString(obj2->GetName()).Contains("_pre")); bool isjk = (TString(obj2->GetName()).Contains("hpt_jk")); bool isjet = (TString(obj2->GetName()).Contains("hpt_jet")); TProfile *peff = (TProfile*)dir->Get("peff"); assert(peff); TH1D *hlumi = (TH1D*)dir->Get("hlumi"); assert(hlumi); TH1D *hlumi0 = (TH1D*)dir->Get("../jt450/hlumi"); assert(hlumi0); if (_jp_usetriglumi) { TH1D *hlumi_orig = (TH1D*)outdir->FindObject("hlumi_orig"); if (!hlumi_orig) hlumi_orig = (TH1D*)hlumi->Clone("hlumi_orig"); // regular prescaled luminosity TH1D *hlumi_new = (TH1D*)outdir->FindObject("hlumi"); if (hlumi_new) hlumi = hlumi_new; string strg = dir->GetName(); double lumi = triglumi[strg]; for (int i = 1; i != hlumi->GetNbinsX()+1; ++i) { hlumi->SetBinContent(i, lumi); } // unprescaled luminosity double lumi0 = triglumi["jt450"]; for (int i = 1; i != hlumi0->GetNbinsX()+1; ++i) { hlumi0->SetBinContent(i, lumi0); } } // _jp_usetriglumi // Test MC-based normalization for trigger efficiency bool dotrigeff = ((string(obj2->GetName())=="hpt") || isjk || isjet); TH1D *htrigeff = (TH1D*)outdir->FindObject("htrigeff"); TH1D *htrigeffmc = (TH1D*)outdir->FindObject("htrigeffmc"); TH1D *htrigeffsf = (TH1D*)outdir->FindObject("htrigeffsf"); TH1D *hpt_notrigeff = 0; if (!htrigeff && _jp_dotrigeff) { TFile *fmc = new TFile("output-MC-1.root","READ"); assert(fmc && !fmc->IsZombie()); assert(fmc->cd("Standard")); fmc->cd("Standard"); TDirectory *dmc0 = fmc->GetDirectory("Standard"); //assert(gDirectory->cd(Form("Eta_%1.1f-%1.1f", // etamid-0.25*etawid,etamid+0.25*etawid))); //TDirectory *dmc = gDirectory; TDirectory *dmc = dmc0->GetDirectory(Form("Eta_%1.1f-%1.1f", etamid-0.25*etawid,etamid+0.25*etawid)); assert(dmc); dmc->cd(); // Add MC truth based trigger efficiency if(!htrigeffmc && dmc->cd(dir->GetName())) { TDirectory *dir1 = dmc->GetDirectory(dir->GetName()); assert(dir1); TH1D *hpty = (TH1D*)dir1->Get("hpt"); assert(hpty); assert(dmc->cd("mc")); dmc->cd("mc"); TDirectory *dir2 = dmc->GetDirectory("mc"); assert(dir2); TH1D *hptx = (TH1D*)dir2->Get(Form("hpt_%s",dir->GetName())); outdir->cd(); if (hpty && hptx) htrigeffmc = (TH1D*)hpty->Clone("htrigeffmc"); if (hpty && hptx) htrigeffmc->Divide(hpty,hptx,1,1,"B"); } // Add data/MC scale factor for trigger efficiency if (_nh_dt && !htrigeffsf) { assert(dmc->cd(dir->GetName())); dmc->cd(dir->GetName()); TDirectory *dirmc = dmc->GetDirectory(dir->GetName()); assert(dirmc); TProfile *pm = (TProfile*)dirmc->Get("ptrigefftp"); TProfile *pd = (TProfile*)dir->Get("ptrigefftp"); outdir->cd(); if (pm && pd) htrigeffsf = pm->ProjectionX("htrigeffsf"); if (pm && pd) htrigeffsf->Divide(pd,pm,1); } // Combine MC trigger efficiency and scalefactor if (htrigeffmc) { // not available for 'mc' directory outdir->cd(); htrigeff = (TH1D*)htrigeffmc->Clone("htrigeff"); assert(!_nh_dt || htrigeffsf); if (_nh_dt) htrigeff->Multiply(htrigeffsf); TH1D *h = (TH1D*)dir->Get("hpt"); assert(outdir->FindObject("hpt_notrigeff")==0); outdir->cd(); hpt_notrigeff = (TH1D*)h->Clone("hpt_notrigeff"); } fmc->Close(); } // dotrigeff // Scale data to account for time dependence bool dotimedep = ((string(obj2->GetName())=="hpt") || isjk || isjet); TH1D *htimedep = (TH1D*)outdir->FindObject("htimedep"); TH1D *htimefit = (TH1D*)outdir->FindObject("htimefit"); TH1D *hpt_notimedep = 0, *hpt_withtimedep = 0; double ktime = 1.; if (!htimedep) { TH1D *h = (TH1D*)dir->Get("hpt"); TH1D *hsel = (TH1D*)dir->Get("hselpt"); TH1D *hpre = (TH1D*)dir->Get("hpt_pre"); //TH1D *hlumi0 = (TH1D*)dir->Get("../jt450/hlumi"); // Fix luminosity for unprescaled trigger //string strg = dir->GetName(); //double lum0 = triglumi["jt450"]; //for (int i = 1; i != hlumi0->GetNbinsX()+1; ++i) { //hlumi0->SetBinContent(i, lum0); //} outdir->cd(); if (h) hpt_notimedep = (TH1D*)h->Clone("hpt_notimedep"); if (hpre && h) htimedep = (TH1D*)hpre->Clone("htimedep"); if (hpre && h) htimedep->Divide(hpre,h);//,1,1,"B"); // Figure out trigger luminosities double lumi = 0; if (hlumi) lumi = hlumi->GetBinContent(1); double lumi0 = 0; if (hlumi0) lumi0 = hlumi0->GetBinContent(1); if (htimedep && lumi && lumi0) { htimedep->Scale(lumi / lumi0); } // Find proper pT range and fit double minpt = 0.; double maxpt = 6500.; if (hsel) { for (int i = 1; i != hsel->GetNbinsX()+1; ++i) { if (hsel->GetBinContent(i)!=0 && hsel->GetBinLowEdge(i)>=_jp_xmin57) { if (minpt<20) minpt = hsel->GetBinLowEdge(i); maxpt = hsel->GetBinLowEdge(i+1); } } } TF1 *ftmp = new TF1("ftmp","[0]",minpt,maxpt); ftmp->SetParameter(0,1); if (htimedep && htimedep->Integral()>0) htimedep->Fit(ftmp,"QRN"); if (htimedep && ftmp->GetParameter(0)>0) ktime = 1./ftmp->GetParameter(0); if (htimedep) { outdir->cd(); htimefit = (TH1D*)hsel->Clone("htimefit"); hpt_withtimedep = (TH1D*)h->Clone("hpt_withtimedep"); for (int i = 1; i != htimefit->GetNbinsX()+1; ++i) { if (hsel->GetBinContent(i)!=0) { htimefit->SetBinContent(i, ftmp->GetParameter(0)); htimefit->SetBinError(i, ftmp->GetParError(0)); } // Calculate with time dependence here to add ktime fit error hpt_withtimedep->SetBinContent(i, hpt_notimedep->GetBinContent(i) * htimefit->GetBinContent(i)); double err1 = hpt_notimedep->GetBinError(i) / hpt_notimedep->GetBinContent(i); double err2 = htimefit->GetBinError(i) / htimefit->GetBinContent(i); hpt_withtimedep->SetBinError(i, hpt_notimedep->GetBinContent(i) * sqrt(pow(err1,2) + pow(err2,2))); } } } // dotimedep if (!(hpt->GetNbinsX()==peff->GetNbinsX() || isoth || isgen) || !(hpt->GetNbinsX()==hlumi->GetNbinsX() || isoth || isgen)) { cerr << "Hist " << hpt->GetName() << " " << dir->GetName() << " Nbins=" << hpt->GetNbinsX() << endl << flush; assert(hpt->GetNbinsX()==peff->GetNbinsX() || isoth); assert(hpt->GetNbinsX()==hlumi->GetNbinsX() || isoth); } for (int i = 1; i != hpt->GetNbinsX()+1; ++i) { // Normalization for bin width in y, pT double norm = hpt->GetBinWidth(i) * etawid; double trigeff = 1.; double pt = hpt->GetBinCenter(i); // Normalization for all the common efficiencies if (peff->GetBinContent(i)!=0 && !isgen) norm *= peff->GetBinContent(i); // Test MC-based normalization for trigger efficiency if (dotrigeff && htrigeff && _jp_dotrigeff) { if (htrigeff->GetBinContent(i)!=0) { trigeff = min(1.,max(0.,htrigeff->GetBinContent(i))); if (_jp_dotrigefflowptonly && pt>=114) trigeff = 1; norm *= trigeff; } } // Normalization for luminosity if (hlumi->GetBinContent(i)!=0 && !isoth && !isgen && !ispre) norm *= hlumi->GetBinContent(i); if (hlumi->GetBinContent(1)!=0 && isoth && !isgen && !ispre) norm *= hlumi->GetBinContent(1); if (hlumi0->GetBinContent(1)!=0 && !isoth && !isgen && ispre) norm *= hlumi0->GetBinContent(1); // Fix luminosity from .csv VTX to lumiCalc vdM if (!_nh_mc) norm *= _lumiscale; // Scale normalization for jackknife if (isjk) norm *= 0.9; if (_nh_mc && _jp_pthatbins) norm *= 1.; if (_nh_mc && !_jp_pthatbins) { norm /= 2500.; //(xsecw / (sumw * adhocw) ); // equals 2551.; } // Correct data for time-dependence double norm_notime = norm; if (dotimedep && htimedep && _jp_dotimedep) { norm *= ktime; } if (!(peff->GetBinContent(i)!=0||hpt->GetBinContent(i)==0 || isgen || iscalo || ispf5 || isoth || hpt->GetBinCenter(i)<_jp_recopt || hpt->GetBinCenter(i)*cosh(etamid)>3500.)) { cerr << "Hist " << hpt->GetName() << " " << dir->GetName() << " pt=" << hpt->GetBinCenter(i) << " etamid = " << etamid << endl << flush; assert(peff->GetBinContent(i)!=0||hpt->GetBinContent(i)==0||isgen|| hpt->GetBinCenter(i)<_jp_recopt); } /* if (!(hlumi->GetBinContent(i)!=0 || hpt->GetBinContent(i)==0 || isoth || isgen || hpt->GetBinCenter(i)<_jp_recopt)) { cerr << "Hist " << hpt->GetName() << " " << dir->GetName() << " pt=" << hpt->GetBinCenter(i) << endl << flush; assert(hlumi->GetBinContent(i)!=0 || hpt->GetBinContent(i)==0 || isoth || hpt->GetBinCenter(i)<_jp_recopt); } */ assert(norm!=0); hpt->SetBinContent(i, hpt->GetBinContent(i) / norm); hpt->SetBinError(i, hpt->GetBinError(i) / norm); if (hpt_notrigeff) { hpt_notrigeff->SetBinContent(i, hpt_notrigeff->GetBinContent(i) / norm * trigeff); hpt_notrigeff->SetBinError(i, hpt_notrigeff->GetBinError(i) / norm * trigeff); } if (hpt_notimedep) { hpt_notimedep->SetBinContent(i, hpt_notimedep->GetBinContent(i) / norm_notime); hpt_notimedep->SetBinError(i, hpt_notimedep->GetBinError(i) / norm_notime); } if (hpt_withtimedep) { // ktime already applied => use norm_notime hpt_withtimedep->SetBinContent(i, hpt_withtimedep->GetBinContent(i) / norm_notime); hpt_withtimedep->SetBinError(i, hpt_withtimedep->GetBinError(i) / norm_notime); } } // for i } // hpt dir->cd(); } // inherits from TH1 } // while key curdir->cd(); } // recurseFile
// // Analyze_ECvsP - fit the EC/P vs P distributions // // fAna = output from eg2a DMS // target = target name // void Analyze_ECvsP(char *fAna="Ana.root", char *target) { Int_t i, j; const Int_t NPARAM = 3; TH1D *h1D[NSECTORS][NPARAM]; TH2D *h2D[NSECTORS]; char HistName2D[50]; char strname[50]; char *yname[NPARAM] = {"Amplitude","Mean","Sigma"}; // open text file for the yields char OutFile[100]; sprintf(OutFile,"ECvsP_Fit_%s.dat",target); ofstream fout(OutFile); TCanvas *can[NSECTORS]; // Canvas to plot histogram Double_t par[3]={1.0,1.0,1.0}; TF1 *pol; TF1 *sig; // data files contain the trees printf("Analyzing file %s\n",fAna); TFile *fm = new TFile(fAna,"READ"); TDirectory *tmp = fm->GetDirectory("ElectronID"); for(j=0; j<NSECTORS; j++){ sprintf(cname,"can%i",j+1); sprintf(cname,"Canvas, Sector %i",j+1); can[j] = new TCanvas(cname,ctitle,50*j,0,600,600); can[j]->SetBorderMode(1); //Bordermode (-1=down, 0 = no border, 1=up) can[j]->SetBorderSize(5); gStyle->SetOptStat(1111); can[j]->SetFillStyle(4000); can[j]->Divide(2,2); sprintf(HistName2D,"ECtotP_VS_P_Sector%i",j+1); h2D[j] = (TH2D*)tmp->Get(HistName2D); can[j]->cd(1); gPad->SetLeftMargin(Lmar); gPad->SetRightMargin(Rmar); gPad->SetFillColor(0); h2D[j]->GetXaxis()->CenterTitle(); h2D[j]->GetYaxis()->CenterTitle(); h2D[j]->GetYaxis()->SetTitleOffset(yoff); h2D[j]->SetAxisRange(0.0,3.0,"X"); h2D[j]->Draw("colz"); h2D[j]->FitSlicesY(0,0,-1,20); fout<<j+1<<"\t"; for(i=0; i<NPARAM; i++){ can[j]->cd(i+2); gPad->SetLeftMargin(Lmar); gPad->SetRightMargin(Rmar); gPad->SetFillColor(0); sprintf(strname,"%s_%i",HistName2D,i); h1D[j][i] = (TH1D*)gDirectory->Get(strname); h1D[j][i]->GetXaxis()->CenterTitle(); h1D[j][i]->GetYaxis()->CenterTitle(); h1D[j][i]->GetYaxis()->SetTitle(yname[i]); h1D[j][i]->GetYaxis()->SetTitleOffset(yoff); h1D[j][i]->SetAxisRange(0.0,2.5,"X"); if (i==0){ h1D[j][i]->SetAxisRange(0.0,40.0,"Y"); } if (i==1) { h1D[j][i]->SetAxisRange(0.15,0.35,"Y"); pol = new TF1("pol","pol2",0.5,3.0); h1D[j][i]->Fit("pol","R"); fout<<pol->GetParameter(0)<<"\t"<<pol->GetParameter(1)<<"\t"<<pol->GetParameter(2)<<"\t"; } if (i==2) { par[0] = 10.0; par[1] = 0.1; par[2] = 0.1; h1D[j][i]->SetAxisRange(0.0,0.3,"Y"); sig = new TF1("sig",SigmaFit,0.5,3.0,2); sig->SetParameters(par); h1D[j][i]->Fit("sig","R"); fout<<sig->GetParameter(0)<<"\t"<<sig->GetParameter(1)<<endl; } h1D[j][i]->Draw(); } sprintf(OutCan,"Analyze_ECvsP_S%i_%s.gif",j+1,target); can[j]->Print(OutCan); sprintf(OutCan,"Analyze_ECvsP_S%i_%s.eps",j+1,target); can[j]->Print(OutCan); } fout.close(); // close the text file }
void drawMixedEvent() { gStyle->SetOptStat(0); gStyle->SetLabelFont(132, "x"); gStyle->SetLabelFont(132, "y"); gStyle->SetTitleFont(132, "x"); gStyle->SetTitleFont(132, "y"); gStyle->SetLegendFont(132); TFile *f = new TFile("mixedEventSeparatedByCharge.root"); const float massFrom = 0; const float massTo = 3; const float fixedBinWidth = 0.01; const int massNBins = (massTo - massFrom) / fixedBinWidth; TCanvas *C = new TCanvas("C", "mass plot", 500, 500); TH1D* sig = new TH1D("sig", "", massNBins, massFrom, massTo); TH1D* bkgSELS = new TH1D("bkgSELS", "", massNBins, massFrom, massTo); TH1D* bkgMEUS = new TH1D("bkgMEUS", "", massNBins, massFrom, massTo); TH1D* bkgMELS = new TH1D("bkgMELS", "", massNBins, massFrom, massTo); //-------------------------------------------------- for (int iCent = minCent; iCent < maxCent; ++iCent) { for (int iVz = 0; iVz < 10; ++iVz) { std::string baseName = Form("Cent_%i_Vz_%i",iCent,iVz); TH2F* hSE_LS = static_cast<TH2F*>(f->Get(Form("%s_se_ls_mass", baseName.data()))); TH2F* hSE_US_plus = static_cast<TH2F*>(f->Get(Form("%s_se_us_plus_mass", baseName.data()))); TH2F* hSE_US_minus = static_cast<TH2F*>(f->Get(Form("%s_se_us_minus_mass", baseName.data()))); TH2F* hME_LS = static_cast<TH2F*>(f->Get(Form("%s_me_ls_mass", baseName.data()))); TH2F* hME_US_plus = static_cast<TH2F*>(f->Get(Form("%s_me_us_plus_mass", baseName.data()))); TH2F* hME_US_minus = static_cast<TH2F*>(f->Get(Form("%s_me_us_minus_mass", baseName.data()))); const int firstPtBin = 10.*minPt + 1; cout << "first bin " << firstPtBin << endl; const int lastPtBin = 10.*maxPt; cout << "last bin " << lastPtBin << endl; TH1D* massProj_SE_LS = hSE_LS->ProjectionY(Form("%s_se_ls_mass_proj", baseName.data()), firstPtBin, lastPtBin); TH1D* massProj_SE_US_plus = hSE_US_plus->ProjectionY(Form("%s_se_us_plus_mass_proj", baseName.data()), firstPtBin, lastPtBin); TH1D* massProj_SE_US_minus = hSE_US_minus->ProjectionY(Form("%s_se_us_minus_mass_proj", baseName.data()), firstPtBin, lastPtBin); TH1D* massProj_ME_LS = hME_LS->ProjectionY(Form("%s_me_ls_mass_proj", baseName.data()), firstPtBin, lastPtBin); TH1D* massProj_ME_US_plus = hME_US_plus->ProjectionY(Form("%s_me_us_plus_mass_proj", baseName.data()), firstPtBin, lastPtBin); TH1D* massProj_ME_US_minus = hME_US_minus->ProjectionY(Form("%s_me_us_minus_mass_proj", baseName.data()), firstPtBin, lastPtBin); // add the bin content const int firstBin = massFrom / fixedBinWidth; for (int iBin = 0; iBin < massNBins; ++iBin) { const int histBin = iBin+1; const int movedBin = firstBin + iBin + 1; sig->SetBinContent(histBin, massProj_SE_US_plus->GetBinContent(movedBin) + sig->GetBinContent(histBin)); sig->SetBinContent(histBin, massProj_SE_US_minus->GetBinContent(movedBin) + sig->GetBinContent(histBin)); bkgSELS->SetBinContent(histBin, massProj_SE_LS->GetBinContent(movedBin) + bkgSELS->GetBinContent(histBin)); bkgMEUS->SetBinContent(histBin, massProj_ME_US_plus->GetBinContent(movedBin) + bkgMEUS->GetBinContent(histBin)); bkgMEUS->SetBinContent(histBin, massProj_ME_US_minus->GetBinContent(movedBin) + bkgMEUS->GetBinContent(histBin)); bkgMELS->SetBinContent(histBin, massProj_ME_LS->GetBinContent(movedBin) + bkgMELS->GetBinContent(histBin)); sig->SetBinError(histBin, addErrors(sig->GetBinError(histBin), massProj_SE_US_plus->GetBinError(movedBin)) ); sig->SetBinError(histBin, addErrors(sig->GetBinError(histBin), massProj_SE_US_minus->GetBinError(movedBin)) ); bkgSELS->SetBinError(histBin, addErrors(bkgSELS->GetBinError(histBin), massProj_SE_LS->GetBinError(movedBin)) ); bkgMEUS->SetBinError(histBin, addErrors(bkgMEUS->GetBinError(histBin), massProj_ME_US_plus->GetBinError(movedBin)) ); bkgMEUS->SetBinError(histBin, addErrors(bkgMEUS->GetBinError(histBin), massProj_ME_US_minus->GetBinError(movedBin)) ); bkgMELS->SetBinError(histBin, addErrors(bkgMELS->GetBinError(histBin), massProj_ME_LS->GetBinError(movedBin)) ); } } } //-------------------------------------------------- const float sigma = 7.76446e-03; // taken from fit of the whole dataset +-3.64310e-03 const float meanInclusive = 2.28359; // +-2.14540e-03 const float nSigma = 8.; const float sideBandTo = roundToPreviousBin(meanInclusive - nSigma*sigma, massNBins, massFrom, massTo); const float sideBandFrom = roundToNextBin(meanInclusive + nSigma*sigma, massNBins, massFrom, massTo); const float sideBand = sig->Integral(massFrom, sideBandTo) + sig->Integral(sideBandFrom, massTo); cout << "Side-band yield = " << sideBand << endl; // scaling the mixed event BKG by the yield of the side-band float sideBandYield = 0; float mixedSideBandYield = 0; for (int i = 0; i < massNBins; ++i) { const float binCenter = sig->GetXaxis()->GetBinCenter(i+1); if(binCenter < sideBandTo || binCenter > sideBandFrom) { sideBandYield += sig->GetBinContent(i+1); mixedSideBandYield += bkgMEUS->GetBinContent(i+1); } } TH1D* sideBandMarker = new TH1D("sideBandMarker","marker for the sideband in the form of a histogram", massNBins, massFrom, massTo); const float binWidth = (massTo - massFrom) / static_cast<float>(massNBins); for(int i = 0; i < massNBins; ++i) sideBandMarker->SetBinContent(i+1, 1000); for(float bin = sideBandTo; bin < sideBandFrom; bin += binWidth) { // cout << bin << endl; sideBandMarker->Fill(bin + 0.5*binWidth, -1e6); } sideBandMarker->SetFillColor(kRed); sideBandMarker->SetFillStyle(3004); sideBandMarker->SetLineColorAlpha(kRed,0); bkgSELS->Scale(1./3.); cout << "Scaling mixed event bg by " << sideBandYield / mixedSideBandYield << endl; bkgMEUS->Scale(sideBandYield / (mixedSideBandYield) ); TF1 *line = new TF1("line", "[0] + [1]*x"); TF1 *gaussPlusLine = new TF1("gaussPlusLine", "[0] + [1]*x + [2]*TMath::Gaus(x,[3],[4],1)"); bkgMEUS->Fit(line, "", "", 2.1, 2.5); double offset = line->GetParameter(0); double slope = line->GetParameter(1); const double LcMass = 2.28646; gaussPlusLine->FixParameter(0,offset); gaussPlusLine->FixParameter(1,slope); gaussPlusLine->SetParameter(3,LcMass); gaussPlusLine->SetParameter(2,1); gaussPlusLine->SetParameter(4,sigma); sig->Fit(gaussPlusLine, "", "", 2.1, 2.5); // -- Drawing sig->GetXaxis()->SetTitle("#font[12]{m}_{pK#pi} (GeV/#font[12]{c}^{2})"); sig->GetXaxis()->CenterTitle(); sig->GetXaxis()->SetLabelSize(0.04); sig->GetXaxis()->SetTitleSize(0.055); sig->GetXaxis()->SetTitleOffset(0.8); // sig->GetXaxis()->SetTickLength(0.001); sig->GetYaxis()->SetTitle("#font[12]{N}/(10 MeV/#font[12]{c}^{2})"); sig->GetYaxis()->CenterTitle(); sig->GetYaxis()->SetLabelSize(0.04); sig->GetYaxis()->SetTitleSize(0.055); sig->GetYaxis()->SetTitleOffset(0.8); // sig->GetYaxis()->SetRangeUser(17, 95); sig->SetMarkerStyle(20); sig->SetLineColor(kBlack); bkgMEUS->SetMarkerStyle(21); bkgMEUS->SetMarkerColor(kOrange+5); bkgMEUS->SetLineColor(kOrange+5); bkgMEUS->GetFunction("line")->SetLineColor(kRed); bkgMEUS->GetFunction("line")->SetLineStyle(2); bkgMEUS->GetFunction("line")->SetNpx(10000); bkgSELS->SetMarkerStyle(22); bkgSELS->SetMarkerColor(kBlue-7); bkgSELS->SetLineColor(kBlue-7); bkgMELS->SetMarkerStyle(23); bkgMELS->SetMarkerColor(kGreen+2); bkgMELS->SetLineColor(kGreen+2); sig->GetFunction("gaussPlusLine")->SetLineColor(kRed); sig->GetFunction("gaussPlusLine")->SetNpx(10000); sig->GetXaxis()->SetRangeUser(2.1,2.5); sig->Draw("E"); bkgMEUS->Draw("Esame"); bkgSELS->Draw("Esame"); // bkgMELS->Draw("Esame"); TLegend *leg = new TLegend(0.5,0.6,0.89,0.8); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->AddEntry(sig, "Same event correct sign", "pl"); leg->AddEntry(bkgSELS, "Same event wrong sign", "pl"); leg->AddEntry(bkgMEUS, "Mixed event correct sign", "pl"); // leg->AddEntry(bkgMELS, "Mixed event wrong sign", "pl"); leg->Draw(); // sideBandMarker->Draw("same BAR"); TLegend *dataSet = new TLegend(0., 0.7, 0.4, 0.89); dataSet->SetFillStyle(0); dataSet->SetBorderSize(0); dataSet->AddEntry("", "#font[22]{Au+Au 200 GeV, 10-60%}",""); dataSet->AddEntry("",Form("%1.0f GeV/#font[12]{c} < #font[12]{p}_{T} < %1.0f GeV/#font[12]{c}", minPt, maxPt),""); dataSet->Draw(); // -- yield calculation const float min = 2.26; const float max = 2.31; // -- get part of the Gauss curve TF1 *normGaus = new TF1("normGaus", "TMath::Gaus(x,[0],[1],1)"); double mean = gaussPlusLine->GetParameter(3); double width= gaussPlusLine->GetParameter(4); normGaus->SetParameter(0,mean); normGaus->SetParameter(1,width); double norm = normGaus->Integral(min, max); int minBin = sig->FindBin(min) + 1; int maxBin = sig->FindBin(max); cout << "integral from " << sig->GetBinCenter(minBin) - 0.005 << " to " << sig->GetBinCenter(maxBin) + 0.005 << endl; float NSig = sig->Integral(minBin,maxBin); float NBkg = bkgMEUS->Integral(minBin, maxBin); float Nlc = (NSig - NBkg)/norm; float error = std::sqrt(NSig/norm); cout << "N Sig = " << NSig << endl; cout << "N Bkg = " << NBkg << endl; cout << "norm = " << norm << endl; cout << "N Lambda_c = " << Nlc << endl; cout << "sigma = " << error << endl; }
//------------------------------------ //function to fit energy distributions energyRes* get_res(int snum, Double_t energy, bool do_pion, bool use_f_pion, bool do_fit, bool do_show, bool do_print=false, bool do_batch=false){ Sample* sp = sample_map[snum]; if(!sp) { std::cout << "Sample " << snum << " is not loaded." << std::endl; energyRes* theRes = new energyRes(0,0); return theRes; } //select correct file std::string fpre = sp->fpre; if(do_pion) fpre += "_pion"; else fpre += "_elec"; //make filenames std::stringstream drawname, fname, piname; fname << sp->dir << "/" << fpre << "_" << energy << "gev_10k.root"; if(do_pion) piname << "#pi^{-} " << energy << " GeV"; else piname << "e^{-} " << energy << " GeV"; //open file and tree TFile* _file; _file = TFile::Open((fname.str()).c_str()); TTree* totalTree = (TTree*)_file->Get("Total"); //default histo settings //double Emin = 0.1*energies[num]; //lower cut to remove weird peaks near E=zero double Emin = 0; double Emax = 2*energy; int nbins = 100; //ecal & hcal energies need to be calibrated get_sampling_factors(snum); //make tree drawing expressions //define mip as ecal < 1 gev = 1000 mev if(use_f_pion) drawname << sp->sam_pion; else drawname << sp->sam_elec; if(sp->det==Hcal) drawname << "*(hcal+" << sp->zeroWt << "*zero)/1000"; else drawname << "*ecal/1000"; drawname << ">>htemp(" << nbins << "," << Emin << "," << Emax << ")"; //std::cout << drawname.str() << std::endl; TH1F* h_res; //to store histos drawn from tree TF1* gfit; TF1* gsnL; TF1* gsnR; //plotting variables TCanvas* can; TPad* pad; TLegend* leg; TPaveText* pave; TPaveText* pave_par; TLine *aLline; TLine *aRline; //create instance of energyRes object energyRes* theRes = new energyRes(energy,2); //draw w/ appropriate cut totalTree->Draw((drawname.str()).c_str(),"","hist goff"); h_res = (TH1F*)gDirectory->Get("htemp"); h_res->SetTitle(""); h_res->GetXaxis()->SetTitle("Energy [GeV]"); h_res->SetLineWidth(2); h_res->SetLineColor(kBlack); //names std::string ofit; if(do_fit) ofit = "fit"; else ofit = "nofit"; std::stringstream oname; oname << pdir << "/" << fpre; if(use_f_pion) oname << "_fpion"; oname << "_response_" << ofit << "_" << energy << "gev"; //get values from histo Double_t m = h_res->GetMean(); Double_t me = h_res->GetMeanError(); //Double_t m = h_res->GetBinCenter(h_res->GetMaximumBin()); //peak Double_t s = h_res->GetRMS(); Double_t se = h_res->GetRMSError(); Int_t N = h_res->GetEntries(); std::vector<Double_t> stats(3,0); std::vector<Double_t> stat_err(3,0); stats[0] = N; stat_err[0] = 0; stats[1] = m; stat_err[1] = me; stats[2] = s; stat_err[2] = se; //find peak TSpectrum *spec = new TSpectrum(5); if(nbins < 100) spec->Search(h_res,6,"nobackground nodraw goff"); //turn off background removal when nbins too small else spec->Search(h_res,6,"nodraw goff"); Float_t* xpos = spec->GetPositionX(); Float_t* ypos = spec->GetPositionY(); Double_t p = xpos[0]; Double_t ph = ypos[0]; if(do_show) std::cout << "peak: " << p << std::endl; //setup fitting function & do fit if (do_fit){ gfit = new TF1("resp","gaus",0,h_res->GetXaxis()->GetXmax()); //if(do_jet){ // gfit->SetParameters(ph,p,s); // if(m > p) gfit->SetRange(p-1.5*s,p+1.0*s); //high tail // else gfit->SetRange(p-1.0*s,p+1.5*s); //low tail //} //else{ gfit->SetParameters((Double_t)N,m,s); gfit->SetRange(m-2*s,m+1*s); //fit within 2 std devs //if(m > p) gfit->SetRange(p-2*s,p+1*s); //high tail //else gfit->SetRange(p-1*s,p+2*s); //low tail //} //formatting gfit->SetLineColor(kRed); gfit->SetMarkerColor(kRed); gfit->SetLineWidth(2); //fit h_res->Fit(gfit,"LNQR"); } //store parameters theRes->setStats(stats,stat_err); if(do_fit) theRes->setFit(gfit); //store histo h_res->SetDirectory(0); theRes->setHist(h_res); std::stringstream muname, signame, musigname, aLname, nLname, aRname, nRname, Nname, chiname; muname.precision(2); signame.precision(2); musigname.precision(3); aLname.precision(2); nLname.precision(2); aRname.precision(2); nRname.precision(2); chiname.precision(5); if (do_fit) { muname << fixed << "#mu = " << gfit->GetParameter(1) << " #pm " << gfit->GetParError(1); signame << fixed << "#sigma = " << gfit->GetParameter(2) << " #pm " << gfit->GetParError(2); musigname << fixed << "#sigma/#mu = " << gfit->GetParameter(2)/gfit->GetParameter(1) << " #pm " << gfit->GetParameter(2)/gfit->GetParameter(1) * sqrt( Power(gfit->GetParError(1),2)/Power(gfit->GetParameter(1),2) + Power(gfit->GetParError(2),2)/Power(gfit->GetParameter(2),2) ); //aLname << fixed << "a_{L} = " << gfit->GetParameter(3) << " #pm " << gfit->GetParError(3); //nLname << fixed << "n_{L} = " << gfit->GetParameter(4) << " #pm " << gfit->GetParError(4); //aRname << fixed << "a_{R} = " << gfit->GetParameter(5) << " #pm " << gfit->GetParError(5); //nRname << fixed << "n_{R} = " << gfit->GetParameter(6) << " #pm " << gfit->GetParError(6); chiname << fixed << "#chi^{2}/ndf = " << gfit->GetChisquare()/gfit->GetNDF(); } else { muname << fixed << "Mean = " << m << " #pm " << me; signame << fixed << "RMS = " << s << " #pm " << se; musigname << fixed << "RMS/Mean = " << s/m << " #pm " << s/m*sqrt((me*me)/(m*m)+(se*se)/(s*s)); } Nname << "N = " << N; //plotting if (do_show){ can = new TCanvas((oname.str()).c_str(),(oname.str()).c_str(),700,500); can->cd(); pad = new TPad("graph","",0,0,1,1); pad->SetMargin(0.12,0.05,0.15,0.05); pad->Draw(); pad->cd(); //formatting h_res->SetStats(kTRUE); gStyle->SetOptStat("mr"); h_res->GetYaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetYaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetXaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetXaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetYaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetXaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC())); //plot histo and fit h_res->Draw("hist"); if(do_fit) gfit->Draw("same"); //determine placing of legend and paves - par pave goes on side with more space Double_t xmin; if (m/((h_res->GetXaxis()->GetXmax() + h_res->GetXaxis()->GetXmin())/2) < 1) xmin = 0.65; else xmin = 0.2; if(do_fit) { //legend leg = new TLegend(xmin,0.78,xmin+0.2,0.88); leg->AddEntry(h_res,"Standalone"); leg->AddEntry(gfit,"Fit"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextSize(0.05); leg->SetTextFont(42); leg->Draw("same"); can->Update(); /* //left line Double_t bndL = gfit->GetParameter(1) - gfit->GetParameter(2)*gfit->GetParameter(3); aLline = new TLine(bndL,pad->GetUymin(),bndL,pad->GetUymax()); aLline->SetLineStyle(2); aLline->SetLineWidth(3); aLline->SetLineColor(kBlue); aLline->Draw("same"); //left gaussian gsnL = new TF1("gsn","gaus",Emin,bndL); gsnL->SetParameters(gfit->GetParameter(0),gfit->GetParameter(1),gfit->GetParameter(2)); gsnL->SetLineColor(kRed); gsnL->SetMarkerColor(kRed); gsnL->SetLineWidth(2); gsnL->SetLineStyle(2); gsnL->Draw("same"); //line Double_t bndR = gfit->GetParameter(1) + gfit->GetParameter(2)*gfit->GetParameter(5); aRline = new TLine(bndR,pad->GetUymin(),bndR,pad->GetUymax()); aRline->SetLineStyle(2); aRline->SetLineWidth(3); aRline->SetLineColor(kBlue); aRline->Draw("same"); //right gaussian gsnR = new TF1("gsn","gaus",bndR,Emax); gsnR->SetParameters(gfit->GetParameter(0),gfit->GetParameter(1),gfit->GetParameter(2)); gsnR->SetLineColor(kRed); gsnR->SetMarkerColor(kRed); gsnR->SetLineWidth(2); gsnR->SetLineStyle(2); gsnR->Draw("same"); */ } //pave pave = new TPaveText(xmin,0.68,xmin+0.2,0.78,"NDC"); pave->AddText(sp->name.c_str()); pave->AddText((piname.str()).c_str()); pave->SetFillColor(0); pave->SetBorderSize(0); pave->SetTextFont(42); pave->SetTextSize(0.05); pave->Draw("same"); //par pave Double_t ymin1; //if(do_fit) ymin1 = 0.26; //else ymin1 = 0.51; ymin1 = 0.47; pave_par = new TPaveText(xmin,ymin1,xmin+0.2,ymin1+0.05*4,"NDC"); pave_par->AddText((Nname.str()).c_str()); pave_par->AddText((muname.str()).c_str()); pave_par->AddText((signame.str()).c_str()); pave_par->AddText((musigname.str()).c_str()); //if(do_fit){ // pave_par->AddText((aLname.str()).c_str()); // pave_par->AddText((nLname.str()).c_str()); // pave_par->AddText((aRname.str()).c_str()); // pave_par->AddText((nRname.str()).c_str()); // pave_par->AddText((chiname.str()).c_str()); //} pave_par->SetFillColor(0); pave_par->SetBorderSize(0); pave_par->SetTextFont(42); pave_par->SetTextSize(0.05); pave_par->Draw("same"); std::cout << "response:" << std::endl; std::cout << Nname.str() << std::endl; std::cout << muname.str() << std::endl; std::cout << signame.str() << std::endl; std::cout << musigname.str() << std::endl; if(do_fit){ // std::cout << "aL = " << gfit->GetParameter(3) << " +/- " << gfit->GetParError(3) << std::endl; // std::cout << "nL = " << gfit->GetParameter(4) << " +/- " << gfit->GetParError(4) << std::endl; // std::cout << "aR = " << gfit->GetParameter(5) << " +/- " << gfit->GetParError(5) << std::endl; // std::cout << "nR = " << gfit->GetParameter(6) << " +/- " << gfit->GetParError(6) << std::endl; std::cout << "chi^2/ndf = " << gfit->GetChisquare()/gfit->GetNDF() << std::endl; } if(do_print) can->Print((oname.str()+"."+pformat).c_str(),pformat.c_str()); if(do_batch) _file->Close(); } else { _file->Close(); } //return data structure with relevant info return theRes; }
//void asymmetry(std::string algoType="caloItCone5") { void asymmetry() { int nBins = 5; TChain* chain = new TChain("jetTree"); int nFiles=49; for(int i=1; i<(nFiles+1); ++i) { char name[100]; sprintf(name, "2ndLevelOutputFiles/2ndLevelOutputFile_%d.root/jetTree", i); chain->Add(name); } int nJetReco_caloItCone5; chain->SetBranchAddress("nJetReco_caloItCone5", &nJetReco_caloItCone5); Float_t ptReco_caloItCone5[40]; chain->SetBranchAddress("ptReco_caloItCone5", ptReco_caloItCone5); Float_t phiReco_caloItCone5[40]; chain->SetBranchAddress("phiReco_caloItCone5", phiReco_caloItCone5); std::vector< TH1F* > h1_asymmetry_less10; std::vector< TH1F* > h1_asymmetry_less12; std::vector< TH1F* > h1_asymmetry_less15; std::vector< TH1F* > h1_asymmetry_less17; std::vector< TH1F* > h1_asymmetry_less20; std::vector< TH1F* > h1_asymmetry_less30; for(int i=0; i<nBins; ++i) { char histName[40]; sprintf(histName, "less10_bin%d", i); TH1F* less10 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less10.push_back(less10); sprintf(histName, "less12_bin%d", i); TH1F* less12 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less12.push_back(less12); sprintf(histName, "less15_bin%d", i); TH1F* less15 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less15.push_back(less15); sprintf(histName, "less17_bin%d", i); TH1F* less17 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less17.push_back(less17); sprintf(histName, "less20_bin%d", i); TH1F* less20 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less20.push_back(less20); sprintf(histName, "less30_bin%d", i); TH1F* less30 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less30.push_back(less30); } TRandom t; Int_t nEntries = chain->GetEntries(); //for(int iEntry=0; iEntry<100000; ++iEntry) { for(int iEntry=0; iEntry<nEntries; ++iEntry) { if( (iEntry % 100000) == 0 ) std::cout << "Entry #" << iEntry << " /" << nEntries << std::endl; chain->GetEntry(iEntry); //------------ CALO IT CONE 0.5 if( nJetReco_caloItCone5 > 2 ) { Float_t pt1(0.), pt2(0.), pt3(0.); Float_t phi1(0.), phi2(0.); for(int iJet = 0; iJet<nJetReco_caloItCone5; ++iJet ) { Float_t ptJet = ptReco_caloItCone5[iJet]; if( ptJet > pt1 ) { pt3=pt2; pt2=pt1; pt1=ptJet; phi1=phiReco_caloItCone5[iJet]; } else if( ptJet > pt2 ) { pt3=pt2; pt2=ptJet; phi2=phiReco_caloItCone5[iJet]; } else if( ptJet > pt3 ) { pt3=ptJet; } } //for jets Float_t pi = 3.14159; //Float_t deltaPhi = acos(cos(phi1-phi2)); Float_t deltaPhi = phi1-phi2; if( deltaPhi > pi ) deltaPhi-=2*pi; if( deltaPhi < -pi ) deltaPhi+=2*pi; if( (pt3 < 30.) && (deltaPhi>2.7) ) { Float_t asymmetry = (pt1-pt2)/(pt1+pt2); Float_t oneHalfProb = t.Uniform(1.); if(oneHalfProb<0.5) asymmetry *= -1.; Float_t averagePt = (pt1+pt2)/2.; int iBin=-1; if( (averagePt > 80.)&&(averagePt < 100.) ) iBin=0; else if( (averagePt > 100.)&&(averagePt < 125.) ) iBin=1; else if( (averagePt > 125.)&&(averagePt < 160.) ) iBin=2; else if( (averagePt > 160.)&&(averagePt < 190.) ) iBin=3; else if( (averagePt > 190.)&&(averagePt < 215.) ) iBin=4; if(iBin!=-1) { h1_asymmetry_less30[iBin]->Fill(asymmetry); if( pt3 < 20. ) h1_asymmetry_less20[iBin]->Fill(asymmetry); if( pt3 < 17. ) h1_asymmetry_less17[iBin]->Fill(asymmetry); if( pt3 < 15. ) h1_asymmetry_less15[iBin]->Fill(asymmetry); if( pt3 < 12. ) h1_asymmetry_less12[iBin]->Fill(asymmetry); if( pt3 < 10. ) h1_asymmetry_less10[iBin]->Fill(asymmetry); } // if ibin } //if pt3 < 30 } //if nJet>2 } //for entries TCanvas* c_prova = new TCanvas("c_prova", "c_prova", 800, 600); c_prova->cd(); Double_t Lower[nBins]; Lower[0] = 80.; Lower[1] = 100.; Lower[2] = 125.; Lower[3] = 160.; Lower[4] = 190.; Lower[5] = 215.; TH1F* h1_resolution_vs_pt = new TH1F("resolution_vs_pt", "Jet Energy Resolution vs. Average Jet p_{T}", nBins, Lower); h1_resolution_vs_pt->SetXTitle("Average p_{T}^{RECO} [GeV/c]"); h1_resolution_vs_pt->SetYTitle("#sigma(p_{T})/p_{T}"); for(int iBin=0; iBin<nBins; ++iBin) { int nPoints = 6; Float_t x[nPoints], y[nPoints]; Float_t err_x[nPoints], err_y[nPoints]; x[0] = 10.; x[1] = 12.; x[2] = 15.; x[3] = 17.; x[4] = 20.; x[5] = 30.; y[0] = sqrt(2)*h1_asymmetry_less10[iBin]->GetRMS(); y[1] = sqrt(2)*h1_asymmetry_less12[iBin]->GetRMS(); y[2] = sqrt(2)*h1_asymmetry_less15[iBin]->GetRMS(); y[3] = sqrt(2)*h1_asymmetry_less17[iBin]->GetRMS(); y[4] = sqrt(2)*h1_asymmetry_less20[iBin]->GetRMS(); y[5] = sqrt(2)*h1_asymmetry_less30[iBin]->GetRMS(); err_x[0] = 0.; err_x[1] = 0.; err_x[2] = 0.; err_x[3] = 0.; err_x[4] = 0.; err_x[5] = 0.; err_y[0] = y[0]/sqrt(h1_asymmetry_less10[iBin]->GetEntries()); err_y[1] = y[1]/sqrt(h1_asymmetry_less12[iBin]->GetEntries()); err_y[2] = y[2]/sqrt(h1_asymmetry_less15[iBin]->GetEntries()); err_y[3] = y[3]/sqrt(h1_asymmetry_less17[iBin]->GetEntries()); err_y[4] = y[4]/sqrt(h1_asymmetry_less20[iBin]->GetEntries()); err_y[5] = y[5]/sqrt(h1_asymmetry_less30[iBin]->GetEntries()); TGraphErrors* resolution_vs_pt3 = new TGraphErrors(nPoints, x, y, err_x, err_y); resolution_vs_pt3->SetMarkerStyle(20); TF1* line = new TF1("line", "[0] + [1]*x"); line->SetParameter(0, y[0]); line->SetParameter(1, (y[1]-y[0])/(x[1]-x[0])); line->SetRange(0., 32.); resolution_vs_pt3->Fit(line, "R"); char plotName[70]; sprintf(plotName, "asymmetry/asymmetry_less10_%d.eps", iBin); h1_asymmetry_less10[iBin]->Draw(); c_prova->SaveAs(plotName); sprintf(plotName, "asymmetry/asymmetry_less20_%d.eps", iBin); h1_asymmetry_less20[iBin]->Draw(); c_prova->SaveAs(plotName); sprintf(plotName, "asymmetry/asymmetry_less30_%d.eps", iBin); h1_asymmetry_less30[iBin]->Draw(); c_prova->SaveAs(plotName); sprintf(plotName, "asymmetry/resolution_vs_pt3_%d.eps", iBin); resolution_vs_pt3->Draw("AP"); c_prova->SaveAs(plotName); h1_resolution_vs_pt->SetBinContent(iBin+1, line->GetParameter(0)); h1_resolution_vs_pt->SetBinError(iBin+1, line->GetParError(0)); } //for pt bins TFile* outFile = new TFile("asymmetryOutputFile.root", "RECREATE"); outFile->cd(); h1_resolution_vs_pt->Write(); outFile->Close(); outFile->Write(); } //asymmetry
void fitResSlope::Loop() { if (fChain == 0) return; gROOT->SetStyle("Plain"); gStyle->SetOptFit(0111); gStyle->SetMarkerStyle(20); gStyle->SetMarkerSize(0.7); Long64_t nentries = fChain->GetEntriesFast(); //indexes are wheel,sector,station,SL,ttrig Double_t Ares_mean[5][14][4][3][5]; Double_t Ares_mean_err[5][14][4][3][5]; Double_t t0res_mean[5][14][4][3][5]; Double_t deltaTtrig[5] = {-4.,-2.,0.,2.,4.}; TCanvas c1; TCanvas c2; Int_t count = 0; Long64_t nbytes = 0, nb = 0; for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; int tmp_ttrig; if(ttrig == -2) tmp_ttrig = 0; else if(ttrig == -1) tmp_ttrig = 1; else if(ttrig == 0) tmp_ttrig = 2; else if(ttrig == 1) tmp_ttrig = 3; else if(ttrig == 2) tmp_ttrig = 4; //cout << "w " << wheel << " sec " << sector << " station " << " sl " << endl; Ares_mean[wheel+2][sector-1][station-1][sl-1][tmp_ttrig] = res_mean; Ares_mean_err[wheel+2][sector-1][station-1][sl-1][tmp_ttrig] = res_mean_err; t0res_mean[wheel+2][sector-1][station-1][sl-1][tmp_ttrig] = t0seg; //cout << "resmean" << Ares_mean[wheel+2][sector-1][station-1][sl-1][tmp_ttrig] << endl; } TH2F *hCorr = new TH2F("hCorr","DTtrig from t0 vs DTrig from res (ns)", 60, -15, 15, 60, -15, 15); TH1F *hPar1_phi = new TH1F("hPar1_phi", "VDrift from fit (cm/ns)", 500, 0.001, 0.006); TH2F *hPar1VsSect_phi = new TH2F("hPar1VsSect_phi", "VDrift from fit (cm/ns) vs sector", 12,1,13,50, 0.0035, 0.0055); TH2F *hPar1VsWheel_phi = new TH2F("hPar1VsWheel_phi", "VDrift from fit (cm/ns) vs wheel", 5,-2,3,50, 0.0035, 0.0055); TH2F *hPar1VsStat_phi = new TH2F("hPar1VsStat_phi", "VDrift from fit (cm/ns) vs station", 4,1,5,50, 0.0035, 0.0055); TH2F *hPar1VsChi2_phi = new TH2F("hPar1VsChi2_phi", "VDrift from fit (cm/ns) vs chi2", 50,0,10,50, 0.0035, 0.0055); TH1F *hPar1_theta = new TH1F("hPar1_theta", "VDrift from fit (cm/ns)", 500, 0.001, 0.006); ofstream fout("failed_sl.txt"); for(Int_t mywheel = -2; mywheel<=2; mywheel++){ for(Int_t mysector = 1; mysector<=12; mysector++){ for(Int_t mystation = 1; mystation<=4; mystation++){ for(Int_t mySL = 1; mySL<=3; mySL++){ // FIXME: skip SL theta for the moment if(mySL == 2) continue; //if(count == 10) break; vector<Double_t> mymean; vector<Double_t> mymean_err; vector<Double_t> x_mean; vector<Double_t> x_err; vector<Double_t> myt0; vector<Double_t> myt0_err; vector<Double_t> x_t0; vector<Double_t> x_err_t0; int count_valid_points(0); for(Int_t myttrig = 0; myttrig < 5; myttrig++){ if(Ares_mean_err[mywheel+2][mysector-1][mystation-1][mySL-1][myttrig] > 0.2) continue; mymean.push_back(Ares_mean[mywheel+2][mysector-1][mystation-1][mySL-1][myttrig]); mymean_err.push_back(Ares_mean_err[mywheel+2][mysector-1][mystation-1][mySL-1][myttrig]); x_err.push_back(0.); x_mean.push_back(deltaTtrig[myttrig]); myt0.push_back(t0res_mean[mywheel+2][mysector-1][mystation-1][mySL-1][myttrig]); myt0_err.push_back(0.5); x_err_t0.push_back(0.); x_t0.push_back(deltaTtrig[myttrig]); count_valid_points++; } //cout << " res mean " << t0res_mean[mywheel+2][mysector-1][mystation-1][mySL-1][2] << endl; if(count_valid_points < 2){ fout << mywheel << " " << mysector << " " << mystation << " " << mySL << endl; continue; } TGraphErrors mygr(mymean.size(),&x_mean[0],&mymean[0],&x_err[0],&mymean_err[0]); mygr.Fit("pol1"); TF1 * mygrFit = mygr.GetFunction("pol1"); double par0res = mygrFit->GetParameter("p0"); double par1res = mygrFit->GetParameter("p1"); double ttrigCorrRes = 99999; if(par1res != 0) ttrigCorrRes = -par0res/par1res; ttrigCorr[mywheel+2][mysector-1][mystation-1][mySL-1] = par1res; string stringName1; stringstream theStream1; theStream1 << "Wh" << mywheel << "_Sect" << mysector << "_St"<< mystation << "_SL" << mySL; theStream1 >> stringName1; mygr.SetTitle(stringName1.c_str()); c1.cd(); mygr.Draw("AP"); if(count == 0) c1.SaveAs("resplots.ps("); else c1.SaveAs("resplots.ps"); TGraphErrors mygrt0(myt0.size(),&x_t0[0],&myt0[0],&x_err_t0[0],&myt0_err[0]); mygrt0.Fit("pol1"); TF1 * mygrt0Fit = mygrt0.GetFunction("pol1"); double par0t0 = mygrt0Fit->GetParameter("p0"); double par1t0 = mygrt0Fit->GetParameter("p1"); double ttrigCorrT0 = 99999; if(par1t0 != 0) ttrigCorrT0 = -par0t0/par1t0; if(mySL != 2) { hCorr->Fill(ttrigCorrRes, ttrigCorrT0); hPar1_phi->Fill(-par1res); hPar1VsSect_phi->Fill(mysector,-par1res); hPar1VsWheel_phi->Fill(mywheel,-par1res); hPar1VsStat_phi->Fill(mystation,-par1res); hPar1VsChi2_phi->Fill(mygrFit->GetChisquare(), -par1res); cout << " VDrift: " << par1res << endl; } else { hPar1_theta->Fill(-par1res); } mygrt0.SetTitle(stringName1.c_str()); c2.cd(); mygrt0.Draw("AP"); if(count == 0) c2.SaveAs("t0plots.ps("); else c2.SaveAs("t0plots.ps"); count++; } } } } c1.cd(); c1.SetGrid(1,1); hCorr->Draw("box"); c1.SaveAs("resplots.ps"); c1.cd(); hPar1_phi->Draw(); c1.SaveAs("resplots.ps"); c1.cd(); hPar1_theta->Draw(); c1.SaveAs("resplots.ps"); c1.cd(); hPar1VsSect_phi->Draw("box"); c1.SaveAs("resplots.ps"); c1.cd(); hPar1VsWheel_phi->Draw("box"); c1.SaveAs("resplots.ps"); c1.cd(); hPar1VsStat_phi->Draw("box"); c1.SaveAs("resplots.ps"); c1.cd(); hPar1VsChi2_phi->Draw("box"); c1.SaveAs("resplots.ps)"); c2.SaveAs("t0plots.ps)"); return; }
void SimpleFitter() { TFile*output=new TFile("histoX.root","read"); TH1D*h=(TH1D*)output->Get("h"); h->Sumw2(); TF1 *f = new TF1("f","[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) +[3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5])+[6]+[7]*x+[8]*x*x+[9]*x*x*x"); f->SetLineColor(4); f->SetParameters(21,3.68,0.0057,1.34714e+00,3.86,0.006,-2.21334e+04,1.01661e+04,-1.05364e+03,1.95474e+04); f->FixParameter(1,3.686); f->FixParameter(2,0.00357); f->FixParameter(4,3.8725); f->FixParameter(5,0.005); h->Fit("f","LL"); h->Fit("f",""); h->Fit("f","LL"); h->Fit("f","LL","",3.65,3.94); h->Fit("f","LL","",3.65,3.94); f->ReleaseParameter(1); f->ReleaseParameter(2); f->ReleaseParameter(4); f->ReleaseParameter(5); h->Fit("f","LL","",3.65,3.94); h->SetXTitle("m(J/#psi#pi^{+}#pi^{-}) [GeV]"); h->SetYTitle("Entries"); h->SetStats(0); h->SetAxisRange(0,h->GetMaximum()*1.3 ,"Y"); TF1 *f2 = new TF1("f2","[6]+[7]*x+[8]*x*x+[9]*x*x*x"); f2->SetParameter(6,f->GetParameter(6)); f2->SetParameter(7,f->GetParameter(7)); f2->SetParameter(8,f->GetParameter(8)); f2->SetParameter(9,f->GetParameter(9)); TF1 *f3 = new TF1("f3","[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])"); f3->SetParameter(0,f->GetParameter(0)); f3->SetParameter(1,f->GetParameter(1)); f3->SetParameter(2,f->GetParameter(2)); TF1 *f4 = new TF1("f4","[3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5])"); f4->SetParameter(3,f->GetParameter(3)); f4->SetParameter(4,f->GetParameter(4)); f4->SetParameter(5,f->GetParameter(5)); f->SetLineColor(4); f2->SetLineColor(4); f3->SetRange(3.65,3.94); f4->SetRange(3.65,3.94); f2->SetRange(3.65,3.94); f2->SetLineStyle(2); f3->SetLineStyle(2); f4->SetLineStyle(2); f2->Draw("same"); f3->SetLineColor(2); f3->SetFillStyle(3004); f3->SetFillColor(2); f3->Draw("same"); f4->SetLineColor(2); f4->SetFillStyle(3004); f4->SetFillColor(2); f4->Draw("same"); TLatex *l = new TLatex(3.7,70./80*h->GetMaximum(),"#psi(2S)"); l->Draw(); TLatex *l2 = new TLatex(3.875,50./80*h->GetMaximum(),"X(3872)"); l2->Draw(); TLatex *l3 = new TLatex(3.812,70./80*h->GetMaximum(),"CMS Preliminary"); l3->Draw(); TLatex *l4 = new TLatex(3.78,60./80*h->GetMaximum(),"pp #sqrt{s_{NN}}=5.02 TeV"); l4->Draw(); cout<<"********************* SIGNIFICANCE *********************"<<endl; double meanX=f4->GetParameter(4); double sigmaX=f4->GetParameter(5); double signalX=f4->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0); double bkgX=f2->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0); double signalpsi2=f4->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0); double bkgpsi2=f2->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0); double significanceX=signalX/TMath::Sqrt(signalX+bkgX); double meanpsi2=f3->GetParameter(1); double sigmapsi2=f3->GetParameter(2); double signalpsi2=f3->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0); double bkgpsi2=f2->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0); double signalpsi2=f3->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0); double bkgpsi2=f2->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0); double significancepsi2=signalpsi2/TMath::Sqrt(signalpsi2+bkgpsi2); cout<<"significance X ="<<significanceX<<endl; cout<<"significance psi(2S)="<<significancepsi2<<endl; cout<<"yield X="<<signalX<<endl; cout<<"yield 2S="<<signalpsi2<<endl; cout<<"yield X/yield 2S="<<signalX/signalpsi2<<endl; }
int piRandom() { TRandom r0; TRandom1 r1; TRandom2 r2; TRandom3 r3; //Random<GSLRngRand> r1; // Random<GSLRngTaus> r2; // Random<GSLRngRanLux> r3; double n = NEVT; int nloop = NLOOP; double dy = 15/std::sqrt(n); TH1D * h0 = new TH1D("h0","TRandom delta",100,-dy,dy); TH1D * h1 = new TH1D("h1","TRandom1 delta",100,-dy,dy); TH1D * h2 = new TH1D("h2","TRandom2 delta",100,-dy,dy); TH1D * h3 = new TH1D("h3","TRandom3 delta",100,-dy,dy); double sigma = std::sqrt( PI * (4 - PI)/n ); std::cout << "**********************************************************" << std::endl; std::cout << " Generate " << int(n) << " for " << nloop << " times " << std::endl; std::cout << "**********************************************************" << std::endl; std::cout << "\tExpected Sigma = " << sigma << std::endl; #define INTERACTIVE #ifdef INTERACTIVE double del, err; TCanvas * c1 = new TCanvas("c1_piRandom","PI Residuals"); gStyle->SetOptFit(1111); gStyle->SetOptLogy(); c1->Divide(2,2); c1->cd(1); generate(r0,h0); h0->Fit("gaus"); h0->Draw(); TF1 * fg = (TF1*) h0->FindObject("gaus"); if (fg) { del = (fg->GetParameter(2)-sigma); err = fg->GetParError(2); } else { del = -999; err = 1; } char text[20]; sprintf(text,"Spread %8.4f",del/err); TPaveLabel * pl0 = new TPaveLabel(0.6,0.3,0.9,0.4,text,"brNDC"); pl0->Draw(); c1->cd(2); generate(r1,h1); h1->Fit("gaus"); h1->Draw(); fg = (TF1*) h1->FindObject("gaus"); if (fg) { del = (fg->GetParameter(2)-sigma); err = fg->GetParError(2); } else { del = -999; err = 1; } sprintf(text,"Spread %8.4f",del/err); TPaveLabel * pl1 = new TPaveLabel(0.6,0.3,0.9,0.4,text,"brNDC"); pl1->Draw(); c1->cd(3); generate(r2,h2); h2->Fit("gaus"); h2->Draw(); fg = (TF1*) h2->FindObject("gaus"); if (fg) { del = (fg->GetParameter(2)-sigma); err = fg->GetParError(2); } else { del = -999; err = 1; } sprintf(text,"Spread %8.4f",del/err); TPaveLabel * pl2 = new TPaveLabel(0.6,0.3,0.9,0.4,text,"brNDC"); pl2->Draw(); c1->cd(4); generate(r3,h3); h3->Fit("gaus"); h3->Draw(); fg = (TF1*) h3->FindObject("gaus"); if (fg) { del = (fg->GetParameter(2)-sigma); err = fg->GetParError(2); } else { del = -999; err = 1; } sprintf(text,"Spread %8.4f",del/err); TPaveLabel * pl3 = new TPaveLabel(0.6,0.3,0.9,0.4,text,"brNDC"); pl3->Draw(); #else generate(r0,h0); generate(r1,h1); generate(r2,h2); generate(r3,h3); #endif return 0; }
void ABCD2vari_p3(const char* ISO) { //Only iso is external, all the regions go in a loop!!! to be fed in the macro at once TString PREFIX = "./"; //Get the fractions //gStyle->SetOptStat(0); TFile* fB = new TFile(PREFIX+"factor_qcd_"+TString(ISO)+"_B.root", "open"); fB->cd(); TH1D* hRatioB = (TH1D*)gDirectory->Get("hfactor"); hRatioB->Fit("pol0"); //2D needs, preliminary TH1D* hRatioB2030 = (TH1D*)gDirectory->Get("hfactor2030"); hRatioB2030->Fit("pol0"); TH1D* hRatioB3045 = (TH1D*)gDirectory->Get("hfactor3045"); hRatioB3045->Fit("pol0"); TH1D* hRatioB4560 = (TH1D*)gDirectory->Get("hfactor4560"); hRatioB4560->Fit("pol0"); TH1D* hRatioB60120 = (TH1D*)gDirectory->Get("hfactor60120"); hRatioB60120->Fit("pol0"); TH1D* hRatioB120200 = (TH1D*)gDirectory->Get("hfactor120200"); hRatioB120200->Fit("pol0"); TH1D* hRatioB2001500 = (TH1D*)gDirectory->Get("hfactor2001500"); hRatioB2001500->Fit("pol0"); TF1 *myfitB = (TF1*)hRatioB->GetFunction("pol0"); Double_t factor_B = myfitB->GetParameter(0); Double_t factor_B_err = myfitB->GetParError(0); //2D needs, preliminary TF1 *myfitB2030 = (TF1*)hRatioB2030->GetFunction("pol0"); Double_t factor_B2030 = myfitB2030->GetParameter(0); Double_t factor_B_err2030 = myfitB2030->GetParError(0); TF1 *myfitB3045 = (TF1*)hRatioB3045->GetFunction("pol0"); Double_t factor_B3045 = myfitB3045->GetParameter(0); Double_t factor_B_err3045 = myfitB3045->GetParError(0); TF1 *myfitB4560 = (TF1*)hRatioB4560->GetFunction("pol0"); Double_t factor_B4560 = myfitB4560->GetParameter(0); Double_t factor_B_err4560 = myfitB4560->GetParError(0); TF1 *myfitB60120 = (TF1*)hRatioB60120->GetFunction("pol0"); Double_t factor_B60120 = myfitB60120->GetParameter(0); Double_t factor_B_err60120 = myfitB60120->GetParError(0); TF1 *myfitB120200 = (TF1*)hRatioB120200->GetFunction("pol0"); Double_t factor_B120200 = myfitB120200->GetParameter(0); Double_t factor_B_err120200 = myfitB120200->GetParError(0); TF1 *myfitB2001500 = (TF1*)hRatioB2001500->GetFunction("pol0"); Double_t factor_B2001500 = myfitB2001500->GetParameter(0); Double_t factor_B_err2001500 = myfitB2001500->GetParError(0); //repeat for region D TFile* fD = new TFile(PREFIX+"factor_qcd_"+TString(ISO)+"_D.root", "open"); fD->cd(); TH1D* hRatioD = (TH1D*)gDirectory->Get("hfactor"); hRatioD->Fit("pol0"); //2D needs, preliminary TH1D* hRatioD2030 = (TH1D*)gDirectory->Get("hfactor2030"); hRatioD2030->Fit("pol0"); TH1D* hRatioD3045 = (TH1D*)gDirectory->Get("hfactor3045"); hRatioD3045->Fit("pol0"); TH1D* hRatioD4560 = (TH1D*)gDirectory->Get("hfactor4560"); hRatioD4560->Fit("pol0"); TH1D* hRatioD60120 = (TH1D*)gDirectory->Get("hfactor60120"); hRatioD60120->Fit("pol0"); TH1D* hRatioD120200 = (TH1D*)gDirectory->Get("hfactor120200"); hRatioD120200->Fit("pol0"); TH1D* hRatioD2001500 = (TH1D*)gDirectory->Get("hfactor2001500"); hRatioD2001500->Fit("pol0"); TF1 *myfitD = (TF1*)hRatioD->GetFunction("pol0"); Double_t factor_D = myfitD->GetParameter(0); Double_t factor_D_err = myfitD->GetParError(0); //2D needs, preliminary TF1 *myfitD2030 = (TF1*)hRatioD2030->GetFunction("pol0"); Double_t factor_D2030 = myfitD2030->GetParameter(0); Double_t factor_D_err2030 = myfitD2030->GetParError(0); TF1 *myfitD3045 = (TF1*)hRatioD3045->GetFunction("pol0"); Double_t factor_D3045 = myfitD3045->GetParameter(0); Double_t factor_D_err3045 = myfitB3045->GetParError(0); TF1 *myfitD4560 = (TF1*)hRatioD4560->GetFunction("pol0"); Double_t factor_D4560 = myfitD4560->GetParameter(0); Double_t factor_D_err4560 = myfitD4560->GetParError(0); TF1 *myfitD60120 = (TF1*)hRatioD60120->GetFunction("pol0"); Double_t factor_D60120 = myfitD60120->GetParameter(0); Double_t factor_D_err60120 = myfitD60120->GetParError(0); TF1 *myfitD120200 = (TF1*)hRatioD120200->GetFunction("pol0"); Double_t factor_D120200 = myfitD120200->GetParameter(0); Double_t factor_D_err120200 = myfitD120200->GetParError(0); TF1 *myfitD2001500 = (TF1*)hRatioD2001500->GetFunction("pol0"); Double_t factor_D2001500 = myfitD2001500->GetParameter(0); Double_t factor_D_err2001500 = myfitD2001500->GetParError(0); // directory with data TString protocol = "file://"; TString dirname = "/scratch/lustreC/a/asvyatko/DY2013/rootfiles/"; // EWK TFileCollection* c6 = new TFileCollection("WJets","WJets"); c6->Add(protocol+dirname+"WJets_PU"+"/*.root"); // diboson TFileCollection* c7a = new TFileCollection("WZJetsTo3LNu","WZJetsTo3LNu"); c7a->Add(protocol+dirname+"WZJetsTo3LNu_PU"+"/*.root"); TFileCollection* c7b = new TFileCollection("WZJetsTo2L2Q","WZJetsTo2L2Q"); c7b->Add(protocol+dirname+"WZJetsTo2L2Q_PU"+"/*.root"); TFileCollection* c7c = new TFileCollection("ZZJetsTo2L2Nu","ZZJetsTo2L2Nu"); c7c->Add(protocol+dirname+"ZZJetsTo2L2Nu_PU"+"/*.root"); TFileCollection* c7d = new TFileCollection("ZZJetsTo4L","ZZJetsTo4L"); c7d->Add(protocol+dirname+"ZZJetsTo4L_PU"+"/*.root"); TFileCollection* c7e = new TFileCollection("ZZJetsTo2L2Q","ZZJetsTo2L2Q"); c7e->Add(protocol+dirname+"ZZJetsTo2L2Q_PU"+"/*.root"); TFileCollection* c7f = new TFileCollection("WWJetsTo2L2Nu","WWJetsTo2L2Nu"); c7f->Add(protocol+dirname+"WWJetsTo2L2Nu_PU"+"/*.root"); //ttbar TFileCollection* c8a = new TFileCollection("tW","tW"); c8a->Add(protocol+dirname+"tW_PU"+"/*.root"); TFileCollection* c8b = new TFileCollection("tbarW","tbarW"); c8b->Add(protocol+dirname+"tbarW_PU"+"/*.root"); TFileCollection* c8c = new TFileCollection("tt1000","ttbar1000"); c8c->Add(protocol+dirname+"tt1000_PU"+"/*.root"); TFileCollection* c8d = new TFileCollection("tt700","ttbar700"); c8d->Add(protocol+dirname+"tt700_PU"+"/*.root"); TFileCollection* c8a = new TFileCollection("tW","tW"); c8a->Add(protocol+dirname+"tW_PU"+"/*.root"); TFileCollection* c8b = new TFileCollection("tbarW","tbarW"); c8b->Add(protocol+dirname+"tbarW_PU"+"/*.root"); TFileCollection* c8c = new TFileCollection("tt1000","ttbar1000"); c8c->Add(protocol+dirname+"tt1000_PU"+"/*.root"); TFileCollection* c8d = new TFileCollection("tt700","ttbar700"); c8d->Add(protocol+dirname+"tt700_PU"+"/*.root"); TFileCollection* c8e = new TFileCollection("ttjets","ttjets"); c8e->Add(protocol+dirname+"ttjets_PU_p1"+"/*.root"); c8e->Add(protocol+dirname+"ttjets_PU_p2"+"/*.root"); gEnv->SetValue("ProofLite.Sandbox", "/home/ba01/u115/asvyatko/DYStudy/CMSSW_5_3_3_patch2/src/DimuonAnalysis/DYPackage/test/ABCDmethod/proofbox_p3"); TProof* p = TProof::Open("workers=10"); //"workers=1"); ////proof://pccmspurdue3:-1"); // set number of works to 2: TProof::Open("//lite:///?workers=2"); p->RegisterDataSet("WJets", c6,"OV"); p->RegisterDataSet("WZJetsTo3LNu", c7a,"OV"); p->RegisterDataSet("WZJetsTo2L2Q", c7b,"OV"); p->RegisterDataSet("ZZJetsTo2L2Nu", c7c,"OV"); p->RegisterDataSet("ZZJetsTo4L", c7d,"OV"); p->RegisterDataSet("ZZJetsTo2L2Q", c7e,"OV"); p->RegisterDataSet("WWJetsTo2L2Nu", c7f,"OV"); p->RegisterDataSet("tW", c8a,"OV"); p->RegisterDataSet("tbarW", c8b,"OV"); p->RegisterDataSet("tt1000", c8c,"OV"); p->RegisterDataSet("tt700", c8d,"OV"); p->RegisterDataSet("ttjets", c8e,"OV"); p->ShowDataSets(); //FIXME try not to ue the class, just define the parameters you need and load them with AdInoput //this is correct TObjString* useNtupleWeightFlag = new TObjString("False"); p->AddInput(new TNamed("useNtupleWeightFlag","False")); TObjString* iso = new TObjString(ISO); p->AddInput(new TNamed("iso",ISO)); gROOT->ProcessLine(".L ../tools/misctools.C"); TObjString* factorB = new TObjString(fota(factor_B)); p->AddInput(new TNamed("factorB",fota(factor_B))); TObjString* factorB_err = new TObjString(fota(factor_B_err)); p->AddInput(new TNamed("factorB_err",fota(factor_B_err))); TObjString* factorB2030 = new TObjString(fota(factor_B2030)); p->AddInput(new TNamed("factorD2030",fota(factor_B2030))); TObjString* factorB_err2030 = new TObjString(fota(factor_B_err2030)); p->AddInput(new TNamed("factorB_err2030",fota(factor_B_err2030))); TObjString* factorB3045 = new TObjString(fota(factor_B3045)); p->AddInput(new TNamed("factorB3045",fota(factor_B3045))); TObjString* factorB_err3045 = new TObjString(fota(factor_B_err3045)); p->AddInput(new TNamed("factorB_err3045",fota(factor_B_err3045))); TObjString* factorB4560 = new TObjString(fota(factor_B4560)); p->AddInput(new TNamed("factorB4560",fota(factor_B4560))); TObjString* factorB_err4560 = new TObjString(fota(factor_B_err4560)); p->AddInput(new TNamed("factorB_err4560",fota(factor_B_err4560))); TObjString* factorB60120 = new TObjString(fota(factor_B60120)); p->AddInput(new TNamed("factorB60120",fota(factor_B60120))); TObjString* factorB_err60120 = new TObjString(fota(factor_B_err60120)); p->AddInput(new TNamed("factorB_err60120",fota(factor_B_err60120))); TObjString* factorB120200 = new TObjString(fota(factor_B120200)); p->AddInput(new TNamed("factorB120200",fota(factor_B120200))); TObjString* factorB_err120200 = new TObjString(fota(factor_B_err120200)); p->AddInput(new TNamed("factorB_err120200",fota(factor_B_err120200))); TObjString* factorB2001500 = new TObjString(fota(factor_B2001500)); p->AddInput(new TNamed("factorB2001500",fota(factor_B2001500))); TObjString* factorB_err2001500 = new TObjString(fota(factor_B_err2001500)); p->AddInput(new TNamed("factorB_err2001500",fota(factor_B_err2001500))); /*TObjString* factorC = new TObjString(fota(factor_C)); p->AddInput(new TNamed("factorC",fota(factor_C))); TObjString* factorC_err = new TObjString(fota(factor_C_err)); p->AddInput(new TNamed("factorC_err",fota(factor_C_err))); */ TObjString* factorD = new TObjString(fota(factor_D)); p->AddInput(new TNamed("factorD",fota(factor_D))); TObjString* factorD_err = new TObjString(fota(factor_D_err)); p->AddInput(new TNamed("factorD_err",fota(factor_D_err))); TObjString* factorD2030 = new TObjString(fota(factor_D2030)); p->AddInput(new TNamed("factorD2030",fota(factor_D2030))); TObjString* factorD_err2030 = new TObjString(fota(factor_D_err2030)); p->AddInput(new TNamed("factorD_err2030",fota(factor_D_err2030))); TObjString* factorD3045 = new TObjString(fota(factor_D3045)); p->AddInput(new TNamed("factorD3045",fota(factor_D3045))); TObjString* factorD_err3045 = new TObjString(fota(factor_D_err3045)); p->AddInput(new TNamed("factorD_err3045",fota(factor_D_err3045))); TObjString* factorD4560 = new TObjString(fota(factor_D4560)); p->AddInput(new TNamed("factorD4560",fota(factor_D4560))); TObjString* factorD_err4560 = new TObjString(fota(factor_D_err4560)); p->AddInput(new TNamed("factorD_err4560",fota(factor_D_err4560))); TObjString* factorD60120 = new TObjString(fota(factor_D60120)); p->AddInput(new TNamed("factorD60120",fota(factor_D60120))); TObjString* factorD_err60120 = new TObjString(fota(factor_D_err60120)); p->AddInput(new TNamed("factorD_err60120",fota(factor_D_err60120))); TObjString* factorD120200 = new TObjString(fota(factor_D120200)); p->AddInput(new TNamed("factorD120200",fota(factor_D120200))); TObjString* factorD_err120200 = new TObjString(fota(factor_D_err120200)); p->AddInput(new TNamed("factorD_err120200",fota(factor_D_err120200))); TObjString* factorD2001500 = new TObjString(fota(factor_D2001500)); p->AddInput(new TNamed("factorD2001500",fota(factor_D2001500))); TObjString* factorD_err2001500 = new TObjString(fota(factor_D_err2001500)); p->AddInput(new TNamed("factorD_err2001500",fota(factor_D_err2001500))); gROOT->Time(); p->SetParameter("PROOF_LookupOpt", "all"); p->Process("WJets#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("WZJetsTo3LNu#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("WZJetsTo2L2Q#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("ZZJetsTo2L2Nu#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("ZZJetsTo4L#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("ZZJetsTo2L2Q#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("WWJetsTo2L2Nu#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("tW#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("tbarW#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("tt1000#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("tt700#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); p->Process("ttjets#/recoTree/DiMuonTree","EventSelector_Bkg2.C+"); }
void MakeMinvMix(Int_t cen=6){ TFile fout("raw_MBmix.root","update") ; TFile * f = new TFile("LHC13bc_MB.root") ; //result of data scan TH1F * hev = (TH1F*)f->Get("hSelEvents") ; TH1F * hCentrality1 = (TH1F*)f->Get("hCentrality") ; printf("TotSelEvents: %f \n",hev->GetBinContent(7)) ; printf("Centrality: %f \n",hCentrality1->Integral()) ; Int_t nbin=33 ; Double_t xa[34] ={0.8,1.0,1.2,1.4,1.6, 1.8,2.0,2.2,2.4,2.6, 2.8,3.0,3.2,3.4,3.6, 3.8,4.0,4.5,5.0,5.5, 6.,7.,8.,10.,12.,16.,20.,22., 24.,26.,28.,30.,35., 40.}; // Int_t nbin=26 ; // Double_t xa[27] ={0.8,1.0,1.2,1.4,1.6, 1.8,2.0,2.2,2.4,2.6, 2.8,3.0,3.2,3.4,3.6, 3.8,4.0,4.5,5.0,5.5, 6.,7.,8.,10.,12.,16.,20.}; const Int_t nPID=4 ; char cPID[14][15] ; snprintf(cPID[0],15,"Emin3_All") ; snprintf(cPID[1],15,"Emin3_Disp"); snprintf(cPID[2],15,"Emin3_CPV") ; snprintf(cPID[3],15,"Emin3_Both"); TH2F * hRe[20] ; TH2F * hMi[20] ; TH2F * tmp = 0x0 ; if(cen==6){ //6:0-20, 7:0-10 for(Int_t iPID=0;iPID<nPID;iPID++){ hRe[iPID] = (TH2F*)f->Get(Form("hInvM_Re_%s_cent0",cPID[iPID])) ; tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent1",cPID[iPID])) ; hRe[iPID]->Add(tmp) ;delete tmp ; tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent2",cPID[iPID])) ; hRe[iPID]->Add(tmp) ;delete tmp ; tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent3",cPID[iPID])) ; hRe[iPID]->Add(tmp) ;delete tmp ; tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent4",cPID[iPID])) ; hRe[iPID]->Add(tmp) ;delete tmp ; hRe[iPID]->Sumw2() ; hMi[iPID] = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent0",cPID[iPID])) ; tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent1",cPID[iPID])) ; hMi[iPID]->Add(tmp) ;delete tmp ; tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent2",cPID[iPID])) ; hMi[iPID]->Add(tmp) ;delete tmp ; tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent3",cPID[iPID])) ; hMi[iPID]->Add(tmp) ;delete tmp ; tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent4",cPID[iPID])) ; hMi[iPID]->Add(tmp) ;delete tmp ; hMi[iPID]->Sumw2() ; } } else{ for(Int_t iPID=0;iPID<nPID;iPID++){ hRe[iPID] = (TH2F*)f->Get(Form("hInvM_Re_%s_cent%d",cPID[iPID],cen)) ; hRe[iPID]->Sumw2() ; hMi[iPID] = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent%d",cPID[iPID],cen)) ; hMi[iPID]->Sumw2() ; } } PPRstyle(); gStyle->SetPadLeftMargin(0.14); gStyle->SetPadRightMargin(0.01); gStyle->SetPadTopMargin(0.01); gStyle->SetPadBottomMargin(0.08); //Gaus TH1D *mr1[nPID],*sr1[nPID],*nr1[nPID],*nr1int[nPID] ; for(Int_t iPID=0;iPID<nPID;iPID++){ mr1[iPID] = new TH1D(Form("mass1_GS_%s_cen%d",cPID[iPID],cen),"Mass",nbin,xa) ; sr1[iPID] = new TH1D(Form("width1_GS_%s_cen%d",cPID[iPID],cen),"Width",nbin,xa) ; nr1[iPID] = new TH1D(Form("yeild1_GS_%s_cen%d",cPID[iPID],cen),"Raw yield",nbin,xa) ; nr1int[iPID] = new TH1D(Form("yeild1_int_GS_%s_cen%d",cPID[iPID],cen),"Raw yield, integrated",nbin,xa) ; } //CB TH1D *mr2[nPID],*sr2[nPID],*nr2[nPID],*nr2int[nPID] ; for(Int_t iPID=0;iPID<nPID;iPID++){ mr2[iPID] = new TH1D(Form("mass2_CB_%s_cen%d",cPID[iPID],cen),"Mass",nbin,xa) ; sr2[iPID] = new TH1D(Form("width2_CB_%s_cen%d",cPID[iPID],cen),"Width",nbin,xa) ; nr2[iPID] = new TH1D(Form("yeild2_CB_%s_cen%d",cPID[iPID],cen),"Raw yield",nbin,xa) ; nr2int[iPID] = new TH1D(Form("yeild2_int_CB_%s_cen%d",cPID[iPID],cen),"Raw yield, integrated",nbin,xa) ; } TF1 * fun1 = new TF1("ft1",CB1,0.,1.,8) ; fun1->SetParName(0,"A") ; fun1->SetParName(1,"m_{0}") ; fun1->SetParName(2,"#sigma") ; fun1->SetParName(3,"n") ; fun1->SetParName(4,"#alpha") ; fun1->SetParName(5,"a_{0}") ; fun1->SetParName(6,"a_{1}") ; fun1->SetParName(7,"a_{2}") ; fun1->FixParameter(3,3.28) ; fun1->FixParameter(4,1.56) ; fun1->SetLineWidth(2) ; fun1->SetLineColor(4) ; fun1->SetLineStyle(2) ; TF1 * fun2 = new TF1("ft2",CB2,0.,1.,9) ; fun2->SetParName(0,"A") ; fun2->SetParName(1,"m_{0}") ; fun2->SetParName(2,"#sigma") ; fun2->SetParName(3,"n") ; fun2->SetParName(4,"#alpha") ; fun2->SetParName(5,"a_{0}") ; fun2->SetParName(6,"a_{1}") ; fun2->SetParName(7,"a_{2}") ; fun2->SetParName(8,"a_{3}") ; fun2->FixParameter(3,3.28) ; fun2->FixParameter(4,1.56) ; fun2->SetLineWidth(2) ; fun2->SetLineColor(4) ; fun2->SetLineStyle(2) ; TF1 * funGS1 = new TF1("ft1",GS1,0.,1.,6) ; funGS1->SetParName(0,"A") ; funGS1->SetParName(1,"m_{0}") ; funGS1->SetParName(2,"#sigma") ; funGS1->SetParName(3,"a_{0}") ; funGS1->SetParName(4,"a_{1}") ; funGS1->SetParName(5,"a_{2}") ; funGS1->SetLineWidth(2) ; funGS1->SetLineColor(8) ; // funGS1->SetLineStyle(2) ; TF1 * funGS2 = new TF1("ft2",GS2,0.,1.,7) ; funGS2->SetParName(0,"A") ; funGS2->SetParName(1,"m_{0}") ; funGS2->SetParName(2,"#sigma") ; funGS2->SetParName(3,"a_{0}") ; funGS2->SetParName(4,"a_{1}") ; funGS2->SetParName(5,"a_{2}") ; funGS2->SetParName(6,"a_{3}") ; funGS2->SetLineWidth(2) ; funGS2->SetLineColor(8) ; // funGS2->SetLineStyle(2) ; TF1 * fit1=0x0 ; TF1 * fit2=0x0 ; TF1 * fbgP0 = new TF1("bg",BG,0.,1.,2) ; TF1 * fbgP1 = new TF1("bg1",BG1,0.,1.,3) ; TF1 * fbgP2 = new TF1("bg2",BG2,0.,1.,4) ; TF1 * fbg1=0x0 ; TF1 * fbg2=0x0 ; TF1 * fgs = new TF1("gs",GSs,0.,1.,4) ; TF1 * fcb = new TF1("cb",CBs,0.,1.,6) ; fgs->SetLineColor(8) ; fgs->SetLineWidth(2) ; fcb->SetLineColor(4) ; fcb->SetLineWidth(2) ; fcb->SetLineStyle(2) ; fcb->FixParameter(3,3.28) ; fcb->FixParameter(4,1.56) ; TCanvas * c1[nPID] ; TCanvas * c2[nPID] ; TCanvas * c1b[nPID] ; TCanvas * c2b[nPID] ; for(Int_t iPID=0;iPID<nPID;iPID++){ c1[iPID] = new TCanvas(Form("Ratio_%s",cPID[iPID]),Form("Ratio_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ; c1[iPID]->Divide(4,4) ; c2[iPID] = new TCanvas(Form("Signal_%s",cPID[iPID]),Form("Signal_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ; c2[iPID]->Divide(4,4) ; c1b[iPID] = new TCanvas(Form("RatioB_%s",cPID[iPID]),Form("Ratio_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ; c1b[iPID]->Divide(4,3) ; c2b[iPID] = new TCanvas(Form("SignalB_%s",cPID[iPID]),Form("Signal_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ; c2b[iPID]->Divide(4,3) ; } c1[0]->cd(0) ; TAxis * pta=hRe[0]->GetYaxis() ; TAxis * ma=hRe[0]->GetXaxis() ; for(Int_t i=1;i<=nbin;i++){ Int_t imin=pta->FindBin(xa[i-1]+0.0001); Int_t imax=pta->FindBin(xa[i]-0.0001) ; TH1D *hp; Double_t pt=(xa[i]+xa[i-1])/2. ; for(Int_t iPID=0;iPID<nPID;iPID++){ if(i<17) c1[iPID]->cd(i) ; else c1b[iPID]->cd(i-16) ; hp = hRe[iPID]->ProjectionX(Form("re%d_%d",i,iPID),imin,imax) ; // hp->Sumw2() ; hpm= hMi[iPID]->ProjectionX(Form("mi%d_%d",i,iPID),imin,imax) ; // hpm->Sumw2() ; if(pt>12.){ hp ->Rebin(2) ; hpm->Rebin(2) ; } if(pt<2.){ //2pol,3pol fit1=funGS2 ; fit2=fun2 ; fbg1=fbgP2 ; fbg2=fbgP2 ; } else{ //pol1,pol2 fit1=funGS1 ; fit2=fun1 ; fbg1=fbgP1 ; fbg2=fbgP1 ; } // for(Int_t ib=1; ib<=hp->GetNbinsX();ib++){if(hp ->GetBinContent(ib)==0)hp ->SetBinError(ib,1.);} // for(Int_t ib=1; ib<=hp->GetNbinsX();ib++){if(hpm->GetBinContent(ib)==0)hpm->SetBinError(ib,1.);} TH1D * hpm2 = (TH1D*)hpm->Clone(Form("Bg1_%d",iPID)) ; TH1D * hpcopy = (TH1D*)hp ->Clone(Form("hpcopy_%d",iPID)) ; TH1D * hp2 = (TH1D*)hp ->Clone(Form("hp2_%d",iPID)) ; hpcopy->SetXTitle("M_{#gamma#gamma} (GeV/c^{2})"); hp2 ->SetXTitle("M_{#gamma#gamma} (GeV/c^{2})"); hpcopy->Divide(hpm) ; hpcopy->SetTitle(Form("%3.1f<p_{T}<%3.1f GeV/c",xa[i-1],xa[i])) ; hpcopy->SetMarkerStyle(20) ; hpcopy->SetMarkerSize(0.7) ; hpcopy->GetXaxis()->SetRangeUser(0.05,0.25) ; // fit1->SetParameters(0.0002+0.0001*i*i,0.136,0.011,0.0002,-0.002,0.0) ; fit1->SetParameters(0.0002+0.0001*i*i,0.136,0.005,0.0002,-0.002,0.0) ; // fit1->SetParameters(0.0002,0.136,0.011,0.0002,-0.002,0.0) ; if(cen==0) fit1->SetParameters(0.001,0.146,0.005,0.12,-0.002,0.0) ; fit1->SetParLimits(0,0.000,2.*hpcopy->GetMaximum()) ; fit1->SetParLimits(1,0.125,0.145) ; fit1->SetParLimits(2,0.0045,0.010) ; Double_t rangeMin=0.07 ;//TMath::Max(0.06,0.11-0.01*i) ; Double_t rangeMax=0.22; //TMath::Min(0.25,0.18+0.01*i) ; // if(pt>10){ // rangeMax=0.18; // rangeMin=0.10; // } // Double_t rangeMin=TMath::Max(0.06,0.12-0.01*i) ; // Double_t rangeMax=TMath::Min(0.25,0.16+0.01*i) ; hpcopy->Fit(fit1,"Q","",rangeMin,rangeMax) ; hpcopy->Fit(fit1,"MQ","",rangeMin,rangeMax) ; fit2->SetParameters(fit1->GetParameters()) ; fit2->SetParameter(3,3.2) ; fit2->SetParameter(4,1.56) ; fit2->SetParameter(5,fit1->GetParameter(3)) ; fit2->SetParameter(6,fit1->GetParameter(4)) ; fit2->SetParameter(7,fit1->GetParameter(5)) ; fit2->SetParLimits(0,0.000,2.*hpcopy->GetMaximum()) ; fit2->SetParLimits(1,0.125,0.145) ; fit2->SetParLimits(2,0.0045,0.010) ; hpcopy->Fit(fit2,"+QN","",rangeMin,rangeMax) ; hpcopy->Fit(fit2,"+MQ","",rangeMin,rangeMax) ; c1[iPID]->cd(i) ; hpcopy->Draw() ; if(i<17) c1[iPID]->Update() ; else c1b[iPID]->Update() ; if(i<17) c2[iPID]->cd(i) ; else c2b[iPID]->cd(i-16) ; fbg1->SetParameters(fit1->GetParameter(3),fit1->GetParameter(4),fit1->GetParameter(5),fit1->GetParameter(6)); fbg2->SetParameters(fit2->GetParameter(5),fit2->GetParameter(6),fit2->GetParameter(7),fit2->GetParameter(8)); Double_t intRangeMin = PeakPosition(pt)-3.*PeakWidth(pt) ; Double_t intRangeMax = PeakPosition(pt)+3.*PeakWidth(pt) ; Int_t intBinMin = hp->GetXaxis()->FindBin(intRangeMin) ; Int_t intBinMax = hp->GetXaxis()->FindBin(intRangeMax) ; Double_t errStat = hpm->Integral(intBinMin,intBinMax); hpm ->Multiply(fbg1) ; hpm2->Multiply(fbg2) ; if(pt<10.){ hp ->Add(hpm ,-1.) ; hp2 ->Add(hpm2,-1.) ; } Int_t binPi0 = hp->FindBin(kMean); fgs->SetParameters(hp->Integral(binPi0-1,binPi0+1)/3.,fit1->GetParameter(1),0.006) ; fgs->SetParLimits(0,0.000,10.*hp->GetMaximum()) ; fgs->SetParLimits(1,0.120,0.175) ; fgs->SetParLimits(2,0.0055,0.010) ; hp->Fit(fgs,"QL","",rangeMin,rangeMax) ; hp->Fit(fgs,"QML","",rangeMin,rangeMax) ; hp->SetMaximum(hp->GetMaximum()*1.4) ; hp->SetMinimum(hp->GetMinimum()*1.1) ; hp->SetMarkerStyle(20) ; hp->SetMarkerSize(0.7) ; mr1[iPID]->SetBinContent(i,fgs->GetParameter(1)) ; mr1[iPID]->SetBinError (i,fgs->GetParError(1) ) ; sr1[iPID]->SetBinContent(i,TMath::Abs(fgs->GetParameter(2))) ; sr1[iPID]->SetBinError (i,fgs->GetParError(2) ) ; Double_t y=fgs->GetParameter(0)/hp->GetXaxis()->GetBinWidth(1) ; nr1[iPID]->SetBinContent(i,y) ; Double_t ey=fgs->GetParError(0)/hp->GetXaxis()->GetBinWidth(1) ; nr1[iPID]->SetBinError(i,ey) ; Double_t npiInt = hp->Integral(intBinMin,intBinMax)-(intBinMax-intBinMin)*fgs->GetParameter(3) ; Double_t norm = fbg1->GetParameter(0) ; Double_t normErr= fbg1->GetParError(0) ; if(npiInt>0.){ nr1int[iPID]->SetBinContent(i,npiInt) ; nr1int[iPID]->SetBinError(i,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ; } //printf(" Nint1 =%f+-%f \n",npiInt,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ; hp2->GetXaxis()->SetRangeUser(rangeMin,rangeMax) ; hp2->SetMaximum(hp2->GetMaximum()*1.4) ; hp2->SetMinimum(hp2->GetMinimum()*1.1) ; hp2->SetMarkerStyle(24) ; hp2->SetMarkerSize(0.8) ; fcb->SetParameters(hp->Integral(binPi0-1,binPi0+1)/3.,fit2->GetParameter(1),0.006,fit2->GetParameter(3),fit2->GetParameter(4)) ; fcb->SetParLimits(0,0.000,10.*hp->GetMaximum()) ; fcb->SetParLimits(1,0.120,0.175) ; fcb->SetParLimits(2,0.005,0.010) ; hp2->Fit(fcb,"QL","",rangeMin,rangeMax) ; hp2->Fit(fcb,"QML","",rangeMin,rangeMax) ; mr2[iPID]->SetBinContent(i,fcb->GetParameter(1)) ; mr2[iPID]->SetBinError (i,fcb->GetParError(1)) ; sr2[iPID]->SetBinContent(i,TMath::Abs(fcb->GetParameter(2))) ; sr2[iPID]->SetBinError (i,fcb->GetParError(2)) ; y=(fcb->Integral(0.05,0.25)-fcb->GetParameter(5)*(0.25-0.05))/hp->GetXaxis()->GetBinWidth(1) ; nr2[iPID]->SetBinContent(i,y) ; Double_t ey=fcb->IntegralError(0.05,0.25)/hp->GetXaxis()->GetBinWidth(1) ; nr2[iPID]->SetBinError(i,ey) ; npiInt=hp2->Integral(intBinMin,intBinMax)-(intBinMax-intBinMin)*fgs->GetParameter(3) ; norm=fbg2->GetParameter(0) ; normErr=fbg2->GetParError(0) ; if(npiInt>0.){ nr2int[iPID]->SetBinContent(i,npiInt) ; nr2int[iPID]->SetBinError(i,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ; } //printf(" Nint2 =%f+-%f \n",npiInt,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ; hp2->SetTitle(Form("%3.1f<p_{T}<%3.1f GeV/c",xa[i-1],xa[i])) ; hp2->Draw() ; hp->SetMarkerColor(6) ; hp->Draw("same") ; hp2->Draw("same") ; c2[iPID]->Update() ; // delete hp ; // delete hp2 ; // delete hpcopy ; delete hpm ; // delete hpm2 ; } } /* for(Int_t iPID=0; iPID<4; iPID++){ c1[iPID]->Print(Form("Ratio_%s_cen%d.eps",cPID[iPID],cen)) ; c2[iPID]->Print(Form("Signal_%s_cen%d.eps",cPID[iPID],cen)) ; } */ //Normalize by the number of events Int_t cMin,cMax; if (cen == 0) { cMin=1; cMax=20; } else if (cen == 1) { cMin=21; cMax=40; } else if (cen == 2) { cMin=41; cMax=60; } else if (cen == 3) { cMin=61; cMax=80; } else if (cen == 4) { cMin=81; cMax=100; } else if (cen == 5) { cMin=61; cMax=80; } else if (cen == 6) { cMin=1; cMax=100; } else if (cen == 7) { cMin=1; cMax=10; } else if (cen == 8) { cMin=41; cMax=80; } else if (cen == 9) { cMin=1; cMax=40; } Double_t nevents = hCentrality1->Integral(cMin,cMax); printf("Nevents=%f \n",nevents) ; for(Int_t iPID=0;iPID<nPID;iPID++){ nr1[iPID] ->Scale(1./nevents) ; nr1int[iPID]->Scale(1./nevents) ; nr2[iPID] ->Scale(1./nevents) ; nr2int[iPID]->Scale(1./nevents) ; nr1[iPID]->SetMarkerStyle(20) ; nr1[iPID]->SetMarkerColor(2) ; nr1[iPID]->SetTitle("#pi^{0} raw yield per event") ; nr2[iPID]->SetTitle("#pi^{0} raw yield per event") ; } fout.cd() ; for(Int_t iPID=0;iPID<nPID;iPID++){ nr1[iPID]->Write(0,TObject::kOverwrite) ; nr2[iPID]->Write(0,TObject::kOverwrite) ; nr1int[iPID]->Write(0,TObject::kOverwrite) ; nr2int[iPID]->Write(0,TObject::kOverwrite) ; mr1[iPID]->Write(0,TObject::kOverwrite) ; mr2[iPID]->Write(0,TObject::kOverwrite) ; sr1[iPID]->Write(0,TObject::kOverwrite) ; sr2[iPID]->Write(0,TObject::kOverwrite) ; } fout.Close() ; }
void toyMC_sigTemp(int runIeta=-1, int runIpt=-1){ cout << "ROOT version = " << gROOT->GetVersion() << endl; // gSystem->mkdir("toysPlot"); char tmp[1000]; TH1D* htoyResult_pull[nEtaBin][nPtBin]; TH1D* htoyResult_bias[nEtaBin][nPtBin]; TFile *fsumFile = new TFile("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/proj_comb_comb3Iso_template.root"); TFile* finFile = new TFile("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/template_comb3Iso_template.root"); TFile* zeeFile = new TFile("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/anadipho_Zee_Vg_3pb.root"); TH1D* hTemplate = (TH1D*)finFile->FindObjectAny("h_EB_comb3Iso_EGdata_pt21"); hTemplate->Reset(); char* dec[2] = {"EB","EE"}; for(int ieta=0; ieta<nEtaBin; ieta++){ for(int ipt=0; ipt < nPtBin; ipt++){ htoyResult_pull[ieta][ipt] = new TH1D(Form("hpull_%s_pt_%d", dec[ieta], (int)fBinsPt[ipt]), "",50,-5.0,5.0); htoyResult_bias[ieta][ipt] = new TH1D(Form("hbias_%s_pt_%d", dec[ieta], (int)fBinsPt[ipt]), "",100,-0.5,0.5); } } TH1D* hfit_sig; TH1D* hfit_bkg; TH1D* hTemplate_S[nEtaBin][nPtBin]; TH1D* hTemplate_B[nEtaBin][nPtBin]; TH1D* hZeeTemplate_S[nEtaBin]; TH1D* hdata_data[nEtaBin][nPtBin]; TH1D* htemp; for(int ieta=0; ieta< nEtaBin; ieta++){ // getting a different signal template if(ieta==0){ sprintf(tmp,"h_%s_combIso",dec[ieta]); cout << "looking for histogram " << tmp << " in file " << zeeFile->GetName() << endl; hZeeTemplate_S[ieta]= (TH1D*)zeeFile->FindObjectAny(tmp); hZeeTemplate_S[ieta]->Rebin(REBINNINGS_TEMP); } else { sprintf(tmp,"h_%s_comb3Iso_sig_sum_SIG",dec[ieta]); //no pt dep. cout << "looking for histogram " << tmp << " in file " << fsumFile->GetName() << endl; hZeeTemplate_S[ieta]= (TH1D*)fsumFile->FindObjectAny(tmp); hZeeTemplate_S[ieta]->Rebin(REBINNINGS_TEMP); } for(int ipt=0; ipt < nPtBin; ipt++){ if(runIeta>=0 && ieta!=runIeta)continue; if(runIpt>=0 && ipt!=runIpt)continue; // getting histograms from data root file sprintf(tmp,"h_%s_comb3Iso_EGdata_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hdata_data[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); hdata_data[ieta][ipt]->Rebin(REBINNINGS_DATA); // filling unbinned data htemp = (TH1D*)hdata_data[ieta][ipt]->Clone("htemp"); htemp->Reset(); sprintf(tmp,"h_%s_comb3Iso_sig_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hTemplate_S[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); hTemplate_S[ieta][ipt]->Rebin(REBINNINGS_TEMP); if(ieta==0 && fBinsPt[ipt]>=50) sprintf(tmp,"h_%s_comb3Iso_bkg_pt%d",dec[ieta],50); else if(ieta==0 ) sprintf(tmp,"h_%s_comb3Iso_bkg_pt%d",dec[ieta],(int)fBinsPt[ipt]); else if(ieta==1 && fBinsPt[ipt]>=60) sprintf(tmp,"h_%s_comb3IsoSB_EGdata_pt%d",dec[ieta],60); else if(ieta==1) sprintf(tmp,"h_%s_comb3IsoSB_EGdata_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hTemplate_B[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); hTemplate_B[ieta][ipt]->Rebin(REBINNINGS_TEMP); const int NRETURN = 3*NPAR; Double_t myFitPar[NRETURN]={0}; Double_t* FuncFitResult; FuncFitResult = Ifit("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/EGdata_comb3Iso_et.dat", hZeeTemplate_S[ieta],hTemplate_B[ieta][ipt], hdata_data[ieta][ipt], myFitPar, (int)fBinsPt[ipt], dec[ieta],2); Double_t nsig_input = FuncFitResult[0]; Double_t nsigerr_input = FuncFitResult[1]; Double_t nbkg_input = FuncFitResult[2]; Double_t nbkgerr_input = FuncFitResult[3]; Double_t nsig_input5GeV = FuncFitResult[4]; Double_t nsigerr_input5GeV = FuncFitResult[5]; // force the parameters since EE pt=40 fails if(ieta==1 && ipt==5) { nsig_input = 3172.0; nbkg_input = 10031.0; nsig_input5GeV = 3158.7; Double_t tempPar[NRETURN]={ 22517.049862, 0.900766, 0.044772, 0.191920, 313.878244, -0.545069, -0.281830, 0.026143, 2.549494, 0., 0., 22517.049862, 0.900766, 0.044772, 0.191920, 313.878244, -0.545069, -0.281830, 0.026143, 2.549494, 0., 0., 22517.049862, 0.900766, 0.044772, 0.191920, 313.878244, -0.545069, -0.281830, 0.026143, 2.549494, 0., 0. }; for(int ipar=0; ipar <NRETURN; ipar++) myFitPar[ipar] = tempPar[ipar]; } // end if EE, Et=40 GeV Double_t sigFitPar[NPAR]={0}; for(int ipar=0; ipar<NPAR; ipar++) sigFitPar[ipar] = myFitPar[ipar]; Double_t bkgFitPar[NPAR]={0}; for(int ipar=0; ipar<NPAR; ipar++) bkgFitPar[ipar] = myFitPar[ipar+NPAR]; Double_t sumFitPar[NPAR]={0}; for(int ipar=0; ipar<NPAR; ipar++) sumFitPar[ipar] = myFitPar[ipar+NPAR*2]; TF1* fsig = new TF1("fsig", exp_conv, fit_lo, fit_hi, 11); fsig->SetParameters(sigFitPar); fsig->SetParameter(0,1.0); // changing the signal tail Double_t current = fsig->GetParameter(1); cout << "Current parameter = " << current << endl; current = fCentralTail[ieta][ipt]; fsig->SetParameter(1, current); cout << "Now Current parameter = " << fsig->GetParameter(1) << endl; mySigPDFnorm = fsig->Integral(fit_lo,fit_hi); cout << "mySigPDFnorm = " << mySigPDFnorm << endl; TF1* fbkg = new TF1("fbkg", expinv_power, fit_lo, fit_hi, 11); fbkg->SetParameters(bkgFitPar); fbkg->SetParameter(4,1.0); myBkgPDFnorm = fbkg->Integral(fit_lo, fit_hi); cout << "myBkgPDFnorm = " << myBkgPDFnorm << endl; TF1* fsum = new TF1("fsum",mysum_norm, fit_lo, fit_hi,11); fsum->SetParameters(sumFitPar); cout << "Using nsig_input = " << nsig_input << endl; cout << "Using nbkg_input = " << nbkg_input << endl; cout << "Using nsig_input5GeV = " << nsig_input5GeV << endl; fsum->SetParameter(0, nsig_input*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetParameter(4, nbkg_input*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetLineColor(2); fsum->SetNpx(2500); // cout << "fsum integral = " << fsum->Integral(fit_lo,fit_hi) << endl; // for(int ipar=0; ipar<NPAR; ipar++)cout << "fsum par " << ipar << " = " << fsum->GetParameter(ipar) << endl; // FILE *infile = fopen("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/EGdata_comb3Iso_et.dat","r"); // Double_t xdata, xdata1, xdata2; // combined isolation, pt, eta // int flag = 1; // while (flag!=-1){ // flag =fscanf(infile,"%f %f %f",&xdata, &xdata1, &xdata2); // if( xdata1 >= fBinsPt[ipt] && xdata1 < fBinsPt[ipt+1] && xdata<20.) { // if((ieta==0 && TMath::Abs(xdata2)<1.5) || // (ieta==1 && TMath::Abs(xdata2)>1.5) ) { // htemp->Fill(xdata); // } // } // }// keep reading files as long as text exists // TCanvas* myCanvas = new TCanvas("myCanvas","myCanvas"); // htemp->Draw(); // fsum->Draw("same"); // // loops over toys for(int iexp=0; iexp<NEXP; iexp++){ TH1D* htoyMC_data = (TH1D*)hdata_data[ieta][ipt]->Clone("htoyMC_data"); htoyMC_data->Reset(); TH1D* htoyMC_sig = (TH1D*)hZeeTemplate_S[ieta]->Clone("htoyMC_sig"); TH1D* htoyMC_bkg = (TH1D*)hTemplate_B[ieta][ipt]->Clone("htoyMC_bkg"); UInt_t nowSeed = (unsigned long)gSystem->Now(); gRandom->SetSeed(nowSeed); int nsiggen = gRandom->Poisson(nsig_input); int nbkggen = gRandom->Poisson(nbkg_input); int ndata = nsiggen + nbkggen; // reset toy MC data htoyMC_data->Reset(); ofstream fout; std::string toyData = Form("/tmp/syu/MCsigtailtoy_%d_%d.dat",ieta,ipt); fout.open(toyData.data()); for(int ieve=0; ieve < nsiggen; ieve++) { Double_t xvalue = fsig->GetRandom(fit_lo,fit_hi); fout << xvalue << " " << 0.5*(fBinsPt[ipt]+fBinsPt[ipt+1]) << " " << fBinsEta[ieta] << endl; htoyMC_data->Fill(xvalue); } for(int ieve=0; ieve < nbkggen; ieve++) { Double_t xvalue = fbkg->GetRandom(fit_lo,fit_hi); fout << xvalue << " " << 0.5*(fBinsPt[ipt]+fBinsPt[ipt+1]) << " " << fBinsEta[ieta] << endl; htoyMC_data->Fill(xvalue); } fout.close(); Double_t* toyFitResult; Double_t toyMyFitPar[NRETURN]={0}; toyFitResult = Ifit(toyData.data(), htoyMC_sig, htoyMC_bkg, htoyMC_data, toyMyFitPar, (int)fBinsPt[ipt], dec[ieta],2); Double_t nsigtoyfit = toyFitResult[0]; Double_t errnsigtoyfit = toyFitResult[1]; Double_t nbkgtoyfit = toyFitResult[2]; Double_t errnbkgtoyfit = toyFitResult[3]; Double_t nsigtoyfit_5GeV = toyFitResult[4]; Double_t errnsigtoyfit_5GeV = toyFitResult[5]; if(errnsigtoyfit < 1e-6 || errnbkgtoyfit < 1e-6 || nsigtoyfit < 1e-6 || nbkgtoyfit < 1e-6 || nsig_input < 1e-6 || fabs(nsigtoyfit - nsig_input)<1e-4)continue; Double_t toySumFitPar[NPAR]={0}; for(int ipar=0; ipar<NPAR; ipar++) toySumFitPar[ipar] = toyMyFitPar[ipar+NPAR*2]; // fsum->SetParameters(toySumFitPar); // fsum->SetParameter(0, nsigtoyfit*hdata_data[ieta][ipt]->GetBinWidth(2)); // fsum->SetParameter(4, nbkgtoyfit*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetParameter(0, (Double_t)nsiggen*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetParameter(4, (Double_t)nbkggen*hdata_data[ieta][ipt]->GetBinWidth(2)); // if(iexp%20==0){ // TCanvas* myCanvas = new TCanvas("myCanvas","SHIT"); // htoyMC_data->SetMaximum(htoyMC_data->GetMaximum()*1.5); // htoyMC_data->Draw(); // fsum->Draw("same"); // myCanvas->Print(Form("toysPlot/fit_%03i.gif",iexp)); // delete myCanvas; // } // cout << "fsum integral = " << fsum->Integral(-1,20) << endl; // for(int ipar=0; ipar<NPAR; ipar++)cout << "fsum par " << ipar << " = " << fsum->GetParameter(ipar) << endl; Double_t pull = (nsigtoyfit - nsig_input)/errnsigtoyfit; Double_t bias = (nsigtoyfit - nsig_input)/nsig_input; htoyResult_pull[ieta][ipt]->Fill(pull); htoyResult_bias[ieta][ipt]->Fill(bias); } // end loops of toys delete fsig; delete fbkg; } // end of loop over pt bins } TFile* outFile = new TFile(Form("MCSigTail_%s_pt%d.root", dec[runIeta], (int)fBinsPt[runIpt]), "recreate"); for(int ieta=0; ieta < nEtaBin; ieta++){ for(int ipt=0; ipt < nPtBin; ipt++){ if(htoyResult_pull[ieta][ipt]->GetEntries()>0) htoyResult_pull[ieta][ipt]->Write(); if(htoyResult_bias[ieta][ipt]->GetEntries()>0) htoyResult_bias[ieta][ipt]->Write(); } } outFile->Close(); }
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 *f = new TF1(Form("f%d",count),"[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+")"); 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(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(5,0,1000); 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); cout<<"======= MC ======="<<endl; cout<<f->GetParameter(2)<<" "<<f->GetParameter(8)<<endl; cout<<"===== MC end ====="<<endl; cout<<endl; 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; cout<<"======= data ======="<<endl; cout<<f->GetParameter(2)<<" "<<f->GetParameter(8)<<endl; cout<<"===== data end ====="<<endl; cout<<endl; cout<<"======= chi2 ======="<<endl; cout<<f->GetChisquare()<<endl; cout<<"===== chi2 end ====="<<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->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]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(5)); 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(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.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"); 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.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(); if(inclusive==0) c->SaveAs(Form("PDFVariation/data/width-float/ResultsBplus/BMass-%d.pdf",count)); else c->SaveAs(Form("PDFVariation1Bin/data/width-float/ResultsBplus/BMass-%d.pdf",count)); return mass; }
void plot() { TGraph * gr1 = new TGraph(); gr1->SetMarkerStyle(21); int nPoints1 = 0; TGraph * gr2 = new TGraph(); gr2->SetMarkerStyle(21); int nPoints2 = 0; TGraph * gr3 = new TGraph(); gr3->SetMarkerStyle(21); int nPoints3 = 0; TGraph * gr4 = new TGraph(); gr4->SetMarkerStyle(21); int nPoints4 = 0; TGraph * gr5 = new TGraph(); gr5->SetMarkerStyle(21); int nPoints5 = 0; while (M1[nPoints1].bath!=-999.0) { gr1->SetPoint(nPoints1, M1[nPoints1].ambient, M1[nPoints1].slope); nPoints1++; gr2->SetPoint(nPoints2, M1[nPoints2].bath, M1[nPoints2].ambient); nPoints2++; gr3->SetPoint(nPoints3, M1[nPoints3].bottom, M1[nPoints3].ambient); nPoints3++; gr4->SetPoint(nPoints4, M1[nPoints4].top, M1[nPoints4].ambient); nPoints4++; gr5->SetPoint(nPoints5, M1[nPoints5].top, M1[nPoints5].slope); nPoints5++; } TF1 * fit = new TF1("fit", myfunction, 5, 35, 2); fit->SetLineColor(2); gr3->Draw("AP"); gr3->Fit(fit, "NR"); fit->Draw("same"); double Tbottom = fit->GetParameter(0) / (1.0 - fit->GetParameter(1)); cout << Tbottom << endl; gr4->Draw("AP"); gr4->Fit(fit, "NR"); fit->Draw("same"); double Ttop = fit->GetParameter(0) / (1.0 - fit->GetParameter(1)); cout << Ttop << endl; gr5->Draw("AP"); gr5->Fit(fit, "NR"); fit->Draw("same"); cout << fit->Eval(Tbottom) << endl; cout << fit->Eval(Ttop) << endl; cout << fit->Eval(Ttop + (Ttop-Tbottom)) << endl; }
void fitD(TString inputdata="/data/dmeson2015/DataDntuple/nt_20160112_DfinderData_pp_20160111_dPt0tkPt1_D0Dstar3p5p_DCSJSON_v2.root", TString inputmc="/afs/cern.ch/work/w/wangj/public/Dmeson/ntD_20151110_DfinderMC_20151110_EvtMatching_Pythia_D0pt15p0_Pthat15_TuneZ2_5020GeV_GENSIM_75x_1015_20151110_ppGlobaTrackingPPmenuHFlowpuv11_MBseed_twang-Pythia_1107.root", TString trgselection="((HLT_DmesonPPTrackingGlobal_Dpt15_v1&&Dpt>25&&Dpt<40)||(HLT_DmesonPPTrackingGlobal_Dpt30_v1&&Dpt>40&&Dpt<60)||(HLT_DmesonPPTrackingGlobal_Dpt50_v1&&Dpt>60))", TString cut="Dy>-1.&&Dy<1.&&(Dtrk1highPurity&&Dtrk2highPurity)&&(DsvpvDistance/DsvpvDisErr)>3.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1Pt>1.5&&Dtrk2Pt>1.5", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))", int isMC=0, Double_t luminosity=26., int doweight=0, TString collsyst="PbPb", TString outputfile="mytest.root") { collisionsystem=collsyst; seldata = Form("%s&&%s",trgselection.Data(),cut.Data()); selmc = Form("%s",cut.Data()); gStyle->SetTextSize(0.05); gStyle->SetTextFont(42); gStyle->SetPadRightMargin(0.043); gStyle->SetPadLeftMargin(0.18); gStyle->SetPadTopMargin(0.1); gStyle->SetPadBottomMargin(0.145); gStyle->SetTitleX(.0f); void clean0 (TH1D* h); TF1* fit (TTree* nt, TTree* ntMC, double ptmin, double ptmax, int isMC); if(!doweight) weight="1"; TFile* inf = new TFile(inputdata.Data()); TFile* infMC = new TFile(inputmc.Data()); TTree* nt = (TTree*) inf->Get("ntDkpi"); TTree* HltTree= (TTree*) inf->Get("ntHlt"); HltTree->AddFriend(nt); nt->AddFriend(HltTree); TTree* ntHid = (TTree*) inf->Get("ntHi"); nt->AddFriend(ntHid); TTree* ntMC = (TTree*)infMC->Get("ntDkpi"); TTree* ntGen = (TTree*)infMC->Get("ntGen"); TTree* ntHi = (TTree*)infMC->Get("ntHi"); ntGen->AddFriend(ntMC); ntGen->AddFriend(ntHi); ntMC->AddFriend(ntGen); ntMC->AddFriend(ntHi); ntHi->AddFriend(ntMC); TH1D* hPt = new TH1D("hPt","",nBins,ptBins); TH1D* hPtRecoTruth = new TH1D("hPtRecoTruth","",nBins,ptBins); TH1D* hPtMC = new TH1D("hPtMC","",nBins,ptBins); TH1D* hPtGen = new TH1D("hPtGen","",nBins,ptBins); TH1D* hMean = new TH1D("hMean","",nBins,ptBins); TH1D* hSigmaGaus1 = new TH1D("hSigmaGaus1","",nBins,ptBins); TH1D* hSigmaGaus2 = new TH1D("hSigmaGaus2","",nBins,ptBins); TH1D* hRelMagnGaus1Gaus2 = new TH1D("hRelMagnGaus1Gaus2","",nBins,ptBins); for(int i=0;i<nBins;i++) { TF1* f = fit(nt,ntMC,ptBins[i],ptBins[i+1],isMC); double yield = f->Integral(minhisto,maxhisto)/binwidthmass; double yieldErr = f->Integral(minhisto,maxhisto)/binwidthmass*f->GetParError(0)/f->GetParameter(0); hPt->SetBinContent(i+1,yield/(ptBins[i+1]-ptBins[i])); hPt->SetBinError(i+1,yieldErr/(ptBins[i+1]-ptBins[i])); hMean->SetBinContent(i+1,f->GetParameter(1)); hMean->SetBinError(i+1,f->GetParError(1)); hSigmaGaus1->SetBinContent(i+1,f->GetParameter(2)); hSigmaGaus1->SetBinError(i+1,f->GetParError(2)); hSigmaGaus2->SetBinContent(i+1,f->GetParameter(5)); hSigmaGaus2->SetBinError(i+1,f->GetParError(5)); hRelMagnGaus1Gaus2->SetBinContent(i+1,f->GetParameter(4)); hRelMagnGaus1Gaus2->SetBinError(i+1,f->GetParError(4)); } ntMC->Project("hPtMC","Dpt",TCut(weight)*(TCut(selmc.Data())&&"(Dgen==23333)")); divideBinWidth(hPtMC); ntMC->Project("hPtRecoTruth","Dpt",TCut(selmc.Data())&&"(Dgen==23333)"); divideBinWidth(hPtRecoTruth); ntGen->Project("hPtGen","Gpt",TCut(weight)*(TCut(selmcgen.Data()))); divideBinWidth(hPtGen); TCanvas* cPt = new TCanvas("cPt","",600,600); cPt->SetLogy(); hPt->SetXTitle("D^{0} p_{T} (GeV/c)"); hPt->SetYTitle("Uncorrected dN(D^{0})/dp_{T}"); hPt->Sumw2(); hPt->Draw(); if(isMC) { hPtMC->Draw("same hist"); TLegend* legPt = myLegend(0.55,0.80,0.90,0.94); legPt->AddEntry(hPt,"Signal extraction","pl"); legPt->AddEntry(hPtMC,"Matched reco","lf"); legPt->Draw("same"); } hPtMC->Sumw2(); TH1D* hEff = (TH1D*)hPtMC->Clone("hEff"); hEff->SetTitle(";D^{0} p_{T} (GeV/c);Efficiency"); hEff->Sumw2(); hEff->Divide(hPtGen); TCanvas* cEff = new TCanvas("cEff","",600,600); hEff->Draw(); TH1D* hPtCor = (TH1D*)hPt->Clone("hPtCor"); hPtCor->SetTitle(";D^{0} p_{T} (GeV/c);Corrected dN(D^{0})/dp_{T}"); hPtCor->Divide(hEff); TCanvas* cPtCor= new TCanvas("cCorResult","",600,600); cPtCor->SetLogy(); hPtCor->Draw(); if(isMC) { hPtGen->Draw("same hist"); TLegend* legPtCor = myLegend(0.55,0.80,0.90,0.94); legPtCor->AddEntry(hPtCor,"Corrected signal","pl"); legPtCor->AddEntry(hPtGen,"Generated D^{0}","lf"); legPtCor->Draw("same"); } TH1D* hPtSigma= (TH1D*)hPtCor->Clone("hPtSigma"); hPtSigma->SetTitle(";D^{0} p_{T} (GeV/c);d#sigma(D^{0})/dp_{T} (pb/GeV)"); hPtSigma->Scale(1./(2*luminosity*BRchain)); TCanvas* cPtSigma= new TCanvas("cPtSigma","",600,600); cPtSigma->SetLogy(); hPtSigma->Draw(); TFile* outf = new TFile(outputfile.Data(),"recreate"); outf->cd(); hPt->Write(); hEff->Write(); hPtGen->Write(); hPtMC->Write(); hPtCor->Write(); hPtSigma->Write(); hMean->Write(); hSigmaGaus1->Write(); hSigmaGaus2->Write(); hRelMagnGaus1Gaus2->Write(); outf->Close(); }
void RescaleH() { Char_t Name[256]; Char_t *VarName; TH1D *h1PhotonFluxBut, *h1PhotonFluxH; TH1D *h1PhotonFluxCorrection; //Connect to all existing histograms RootFileButHistograms = new TFile(Str_RootFilesButResults); h1PhotonFluxBut = (TH1D*)gROOT->FindObject("PhotonFluxLTCorrected"); RootFileHHistograms = new TFile(Str_RootFilesHResults); h2TempH = (TH2D*)gROOT->FindObject("MissingMassCombinedSignalLTCorrected"); h1PhotonFluxH = (TH1D*)gROOT->FindObject("PhotonFluxLTCorrected"); //Calculate RootFileHHistograms_Rescaled = new TFile(Str_RootFilesHResults_Rescaled,"RECREATE"); //Ratio of Photon Flux betwen Combined But and H TH1D *hFluxRatio = (TH1D*)h1PhotonFluxBut->Clone("PhotonFluxRatio"); hFluxRatio->Divide(h1PhotonFluxH); for (int i=1;i<=(hFluxRatio->GetNbinsX());i++) { if (hFluxRatio->GetBinContent(i) > 1E3) { hFluxRatio->SetBinContent(i,0); hFluxRatio->SetBinError(i,0); } } TF1 *AverageRatioFit = new TF1("AvgRatioFit","[0]",0,351); TFitResultPtr MyFitResult = hFluxRatio->Fit("AvgRatioFit", "0qFUW"); //0 = do not draw, q=quiet, R = respect range, f = special min finder, W=Set all weights to 1 for non empty bins; ignore error bars Int_t MyFitStatus = MyFitResult; //0 = alles okay, 4 fehler beim Fit, -1 = no data, //see: http://root.cern.ch/root/html/TH1.html#TH1:Fit%1 double AverageRatio = 0; if (MyFitStatus == 0) { AverageRatio = AverageRatioFit->GetParameter(0); printf("Flux Ratio Fit result: %f +- %f\n", AverageRatioFit->GetParameter(0), AverageRatioFit->GetParError(0)); } else { printf("ERROR: Fit did not converge.\n"); } double ScaleFactor = 1/AverageRatio; hFluxRatio->Scale(ScaleFactor); if (DebugOptionAllChannelsRatioEqual) { printf("WARNING: Debug Option active: Flux Ratio is set to 1 for channels.\n"); for (int i=1;i<=(hFluxRatio->GetNbinsX());i++) { hFluxRatio->SetBinContent(i,1); hFluxRatio->SetBinError(i,0); } } //Now Rescale the H-Results individually Scale2D("MissingMassCombinedSignal", hFluxRatio); CopyElement("CountNumberOfHistos"); CopyElement("hDroppedEvents"); Scale1D("TaggerScalerAccum", hFluxRatio); Scale2D("hTaggerTime", hFluxRatio); CopyElement("LiveTimeAccum"); Scale2D("MissingMassCombinedSignalLTCorrected", hFluxRatio); Scale1D("TaggerScalerAccumLTCorrected", hFluxRatio); Scale1D("PhotonFluxLTCorrectedWOTaggEff", hFluxRatio); Scale1D("PhotonFluxLTCorrected", hFluxRatio); CopyElement("TaggEffAbsAll"); RootFileHHistograms_Rescaled->Write(); RootFileButHistograms->Close(); RootFileHHistograms->Close(); RootFileHHistograms_Rescaled->Close(); printf("Finished.\n"); }
void draw_clouds_profiles() { // gROOT->ProcessLine(".L ../utils.C"); // gROOT->ProcessLine(".L AliLRCFit.cxx"); TFile *f[8]; // f[0] = new TFile( "output_classesByV0M_LHC10h.root" ); // f[0] = new TFile( "output_classesByV0M_LHC10h_c10_5_1.root" ); f[0] = new TFile( "output_classesByV0M_LHC10h_c10_5_25_1_05.root" ); // f[0] = new TFile( "output_classesByV0M_LHC11h_FemtoPlus_c10_5_CUT_OUTLIERS.root" ); // f[0] = new TFile( "output_classesByV0M_LHC15o_fieldMM_c10_5_CUT_OUTLIERS.root" ); // f[0] = new TFile( "output_classesByV0M_LHC15o_fieldPP_c10_5_CUT_OUTLIERS.root" ); // const int nCW = 2; //nCentrWidths // const double cWidths[nCW] = { 10, 5 }; //width of the centrality bins // const double cStep[nCW] = { 5, 2.5 }; //centrality bins step // const int nCentrBins[nCW] = { 17, 35 }; //n centrality bins // const int nCW = 3; //nCentrWidths // const double cWidths[nCW] = { 10, 5, 1.0 }; //width of the centrality bins // const double cStep[nCW] = { 5, 2.5, 1.0 }; //centrality bins step // const int nCentrBins[nCW] = { 17, 35, 90 }; //n centrality bins // const int nCW = 4; //nCentrWidths // const double cWidths[nCW] = { 10, 5, 1.0, 0.5 }; //width of the centrality bins // const double cStep[nCW] = { 5, 2.5, 1.0, 1.0 }; //centrality bins step // const int nCentrBins[nCW] = { 17, 35, 90, 90 }; //n centrality bins const int nCW = 5; //nCentrWidths const double cWidths[nCW] = { 10, 5, 2.5, 1.0, 0.5 }; //width of the centrality bins const double cStep[nCW] = { 5, 2.5, 2.5, 1.0, 1.0 }; //centrality bins step const int nCentrBins[nCW] = { 17, 35, 36, 90, 90 }; //n centrality bins TH2D *hist2D;//[200][3]; TProfile *profile;//[200][3]; int cW = 2; int etaW = 1; int phiW = 0; const int kCorrType = 1; //0-NN, 1-PtPt, 2-PtN TCanvas *canv_tmp_for_fit = new TCanvas("canv_tmp_for_fit","canv_tmp_for_fit",50,50,300,300 ); TCanvas *canv_2D_clouds = new TCanvas("canv_2D_clouds","canv_2D_clouds",150,250,1400,600 ); tuneCanvas(canv_2D_clouds); canv_2D_clouds->Divide(2,1); gStyle->SetOptStat( kFALSE ); TGraph *grFromFit2D = new TGraph; bool firstDraw = true; // for ( int cBin = 0; cBin < nCentrBins[cW]; cBin++ ) for ( int cBin = nCentrBins[cW]-1; cBin >= 0; cBin-- ) { if (cBin%2!=0) continue; // cout << "cBin=" << cBin << endl; float cBinMin = cStep[cW] * cBin; float cBinMax = cWidths[cW] + cStep[cW] * cBin; // ##### pad 1 - clouds tunePad( canv_2D_clouds->cd(1) ); if ( kCorrType == 0 ) { hist2D = (TH2D*)f[0]->Get( Form("hist2D_NN_c%.1f-%.1f_etaW_%d_phiW_%d", cBinMin, cBinMax, etaW, phiW) ); hist2D->SetTitle( ""); hist2D->GetXaxis()->SetTitle( "N_{ch} Forward"); hist2D->GetYaxis()->SetTitle( "N_{ch} Backward"); hist2D->GetXaxis()->SetRangeUser(0,650); hist2D->GetYaxis()->SetRangeUser(0,650); } else if ( kCorrType == 1 ) { hist2D = (TH2D*)f[0]->Get( Form("hist2D_PtPt_c%.1f-%.1f_etaW_%d_phiW_%d", cBinMin, cBinMax, etaW, phiW) ); hist2D->SetTitle( ""); hist2D->GetXaxis()->SetTitle( "#LTp_{T}#GT Forward"); hist2D->GetYaxis()->SetTitle( "#LTp_{T}#GT Backward"); } hist2D->SetMarkerColor(kOrange-9+cBin); tuneHist2D_onPad(hist2D); hist2D->GetXaxis()->CenterTitle(); hist2D->GetYaxis()->CenterTitle(); // removeBinsWithFewEntries(hist2D); hist2D->DrawCopy( firstDraw ? "" : "same" ); // ##### pad 2 - profiles tunePad( canv_2D_clouds->cd(2) ); profile = hist2D->ProfileX(); //(TProfile*)f[0]->Get( Form("hist2D_c%.1f-%.1f_etaW_%d_phiW_%d_pfx", cBinMin, cBinMax, etaW, phiW) ); if ( kCorrType == 0 ) { profile->SetTitle( ""); profile->GetYaxis()->SetTitle( "#LTN_{ch}#GT Backward"); profile->GetXaxis()->SetRangeUser(0,650); profile->GetYaxis()->SetRangeUser(0,650); } else if ( kCorrType == 1 ) { profile->SetTitle( ""); profile->GetYaxis()->SetTitle( "#LT#LTp_{T}#GT#GT Backward"); } profile->SetLineColor(kOrange-9+cBin); profile->SetMarkerStyle(7); tuneProfile_onPad( profile ); profile->GetYaxis()->CenterTitle(); deleteProfileEmptyBinErrors(profile); canv_tmp_for_fit->cd(); profile->Fit("pol1","Q");//,"",0.25,1.2);//,"N"); canv_2D_clouds->cd(2); TF1 *fit = profile->GetFunction("pol1"); Double_t p0 = fit->GetParameter(0); Double_t p1 = fit->GetParameter(1); grFromFit2D->SetPoint(grFromFit2D->GetN(), (cBinMax+cBinMin)/2, p1); double meanX = hist2D->ProjectionX()->GetMean(); double rmsX = hist2D->ProjectionX()->GetRMS(); fit->SetRange( meanX-3*rmsX, meanX+3*rmsX ); fit->SetLineColorAlpha( kRed, 0.6 ); fit->Draw("same"); profile->DrawCopy( firstDraw ? "" : "same" ); firstDraw = false; } TGraphErrors *grByFormula; /*[cW][etaW]*/ if ( kCorrType == 0 ) { grByFormula = (TGraphErrors*)f[0]->Get( Form( "grNN_c%d_eta%d", cW, etaW ) ); } else if ( kCorrType == 1 ) { grByFormula = (TGraphErrors*)f[0]->Get( Form( "grPtPt_c%d_eta%d", cW, etaW ) ); } TCanvas *canv_GrCoeff = new TCanvas("canv_GrCoeff","canv_GrCoeff",20,150,900,700 ); grByFormula->Draw("APL"); grFromFit2D->SetLineColor(kRed); grFromFit2D->DrawClone("PL"); return; TGraphErrors *gr[10][10]; for ( int cW = 0; cW < 2; cW++ ) for ( int etaW = 0; etaW < 3; etaW++ ) gr[cW][etaW] = (TGraphErrors*)f[0]->Get( Form( "grPtPt_c%d_eta%d", cW, etaW ) ); drawGraph( gr[1][0], 24, kBlack, "APL" ); drawGraph( gr[0][0], 20, kBlack, "PL" ); // drawGraph( gr[1][1], 24, kBlue, "PL" ); // drawGraph( gr[0][1], 20, kBlue, "PL" ); // drawGraph( gr[1][2], 24, kGreen, "PL" ); // drawGraph( gr[0][2], 20, kGreen, "PL" ); //// drawGraph( gr[6], 24, kRed, "PL" ); // drawGraph( gr[7], 20, kRed, "PL" ); f[1] = new TFile( "output_histos_graphs_LHC15o_fieldMM.root" ); TGraphErrors *grMM[10][10]; for ( int cW = 0; cW < 2; cW++ ) for ( int etaW = 0; etaW < 3; etaW++ ) grMM[cW][etaW] = (TGraphErrors*)f[1]->Get( Form( "grPtPt_c%d_eta%d", cW, etaW ) ); drawGraph( grMM[1][0], 24, kGreen, "PL" ); drawGraph( grMM[0][0], 20, kGreen, "PL" ); // drawGraph( grMM[1][1], 24, kRed, "PL" ); // drawGraph( grMM[0][1], 20, kRed, "PL" ); // drawGraph( grMM[1][2], 24, kGreen, "PL" ); // drawGraph( grMM[0][2], 20, kGreen, "PL" ); // gROOT->ProcessLine( ".q"); }
void Fithistograms(TH1D * histo[], TH1D * mc_matched_signal[], TH1D * mc_matched_kpiswapped[], TString MBorDtrig, int iptstart, int iptend, bool isPbPb, int centlow, int centhigh, TH1D * dNdpt, TString fitoption) { for(int ipt = iptstart; ipt < iptend; ipt++) { TF1* signalfittedfunc = NULL; int iptmc = ipt; // if( ipt > 2 ) // iptmc = ipt; // else // iptmc = 3; if( fitoption == "poly3bkg_floatwidth") signalfittedfunc = fit_histo_poly3bkg_floatwidth( isPbPb, centlow, centhigh, histo[ipt], mc_matched_signal[iptmc], mc_matched_kpiswapped[iptmc], ipt, MBorDtrig); if( fitoption == "expobkg_2nd_floatwidth") signalfittedfunc = fit_histo_expobkg_2nd_floatwidth( isPbPb, centlow, centhigh, histo[ipt], mc_matched_signal[iptmc], mc_matched_kpiswapped[iptmc], ipt, MBorDtrig); if( fitoption == "poly2bkg_floatwidth") signalfittedfunc = fit_histo_poly2bkg_floatwidth( isPbPb, centlow, centhigh, histo[ipt], mc_matched_signal[iptmc], mc_matched_kpiswapped[iptmc], ipt, MBorDtrig); if( fitoption == "poly3bkg") signalfittedfunc = fit_histo_poly3bkg( isPbPb, centlow, centhigh, histo[ipt], mc_matched_signal[iptmc], mc_matched_kpiswapped[iptmc], ipt, MBorDtrig); if( fitoption == "expobkg_2nd") signalfittedfunc = fit_histo_expobkg_2nd( isPbPb, centlow, centhigh, histo[ipt], mc_matched_signal[iptmc], mc_matched_kpiswapped[iptmc], ipt, MBorDtrig); if( fitoption == "poly2bkg") signalfittedfunc = fit_histo_poly2bkg( isPbPb, centlow, centhigh, histo[ipt], mc_matched_signal[iptmc], mc_matched_kpiswapped[iptmc], ipt, MBorDtrig); double histomassbinsize = histo[ipt]->GetBinWidth(10); double yield = signalfittedfunc->Integral(massmin,massmax)/histomassbinsize; double yieldErr = signalfittedfunc->Integral(massmin,massmax)/histomassbinsize * signalfittedfunc->GetParError(0)/signalfittedfunc->GetParameter(0); dNdpt->SetBinContent(ipt+1,yield/(ptbins[ipt+1]-ptbins[ipt])); dNdpt->SetBinError(ipt+1,yieldErr/(ptbins[ipt+1]-ptbins[ipt])); } }
void plot(char* v, int run, int cut, TCanvas* cvs, int fit=0, int bin1=-1, int bin2=-1, float ymax=0.0, int rebin=0){ int bin0=1; char c[100]; char c2[100]; readfile(OPT,run); gStyle->SetOptStat(0); gStyle->SetOptFit(0); gStyle->SetOptTitle(0); cvs->Clear(); int b1=bin1, b2=bin1+1, b3=bin2, b4=b3; if(bin1<0) {cvs->Divide(kNPtBin-bin0,kNPtBin-bin0); b1=bin0; b2=kNPtBin; b3=bin0;} float ptcut[kNPtBin+1]={0.5,1.0,1.5,2.0,2.5,3.0,10.0}; memset(PAR,0,sizeof(PAR)); TText* t; for(int i=b1; i<b2; i++){ if(bin1<0) b4=i; for(int j=b3; j<=b4; j++){ int cc=cut; if(cut==99 && (v=="m1" || v=="m2")) cc=0; if(cut==99 && v=="dphi") cc=1; TH1F *h,*h2,*h3,*h4; TH2F *h2d; //get normalizations float norm0=1.0; float norm1=1.0; float norm2=1.0; float norm3=1.0; if(v=="m0" || v=="phi0"){} else{ sprintf(c,"m0_%1d_c%d",i,cc); TH1F* h0 = (TH1F*)mTFile->Get(c); norm0 = h0->GetEntries(); sprintf(c,"m2_%1d%1d_c%d",i,j,cc); TH1F* h1 = (TH1F*)mTFile->Get(c); norm1 = h1->GetEntries(); printf("n0=%d n1=%d\n",norm0,norm1); norm2=norm1/norm0; norm3=norm2/ZggCut; } int opt=1, log=0; if(v=="mix"){ h3=mix(run,cc,i,j,0,1,h,h2); h1->SetLineColor(1); h2->SetLineColor(6); }else if(v=="corr"){ h = mix(run,cc,i,j,0,1); if(rebin>0) h->Rebin(rebin); if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0); int nbin = h->GetNbinsX(); h->Sumw2(); if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);} else {h->Scale(1.0/norm0*nbin/2.0/PI);} }else if(v=="norm"){ sprintf(c,"dphi_%1d%1d_c%d",i,j,cc); h = (TH1F*)mTFile->Get(c); if(rebin>0) h->Rebin(rebin); if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0); int nbin = h->GetNbinsX(); h->Sumw2(); if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);} else {h->Scale(1.0/norm0*nbin/2.0/PI);} }else if(v=="mall"){ sprintf(c,"m0_%1d_c%d",i,0); sprintf(c2,"m0_%1d%1d_c%d",i,j,0); h4 = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); float norm4 = h4->Integral(h4->GetXaxis()->FindBin(MassCut0),h4->GetXaxis()->FindBin(MassCut1)); h4->Scale(norm1/norm4); h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); sprintf(c,"m0_%1d_c%d",i,cc); sprintf(c2,"m0_%1d%1d_c%d",i,j,cc); h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); h->SetLineColor(6); h->Scale(norm2); sprintf(c,"m1_%1d%1d_c%d",i,j,cc); h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(2); sprintf(c,"m2_%1d%1d_c%d",i,j,cc); h3 = (TH1F*)mTFile->Get(c); h3->SetLineColor(4); }else if(v=="z12"){ sprintf(c,"z1_%1d%1d_c%d",i,j,cc); h = (TH1F*)mTFile->Get(c); h->SetLineColor(2); sprintf(c,"z2_%1d%1d_c%d",i,j,cc); h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(4); }else if(v=="m0" || v=="phi0"){ sprintf(c,"%s_%1d_c%d",v,i,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); }else if(v=="bbce"){ opt=1; log=1; sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); h->SetMinimum(0.1); }else if(v=="phi1" || v=="phi2"){ opt=1; sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); }else if(v=="phi1dphi"){ opt=2; sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); }else{ sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); } if(bin1<0){ TVirtualPad *pad = cvs->cd((i-bin0)*(kNPtBin-bin0)+(j-bin0)+1); pad->SetRightMargin(0.01); pad->SetLeftMargin(0); pad->SetTopMargin(0); pad->SetBottomMargin(0.01); pad->Draw(); } h->SetMinimum(0.0); if(ymax>0.0) h->SetMaximum(ymax); if(opt==0) h->Draw("e"); if(opt==1) h->Draw(); if(opt==2) h->Draw("colz"); if(v=="mall"){ h4->Draw("same"); h2->Draw("same"); h3->Draw("same"); } if(v=="z12" || v=="mix") h2->Draw("same"); TF1* f; if((v=="norm" || v=="corr") && fit==1){ f=new TF1("oneGaus",oneGaus,+PI/2.0,+PI*3.0/2.0,3); f->SetParameters(norm3/10.0,norm3/2.0,0.3); f->SetParNames("Const","IntFar","SigFar"); f->SetParLimits(0,0.0,1.0); f->SetParLimits(1,0.0,1.0); f->SetParLimits(2,0.0,3.0); f->SetLineColor(2); f->SetLineWidth(1); h->Fit("oneGaus","Q"); PAR[i][j][0]=f->GetParameter(0); PAR[i][j][1]=f->GetParameter(1); PAR[i][j][2]=f->GetParameter(2); printf("norm=%8.6f Int=%8.6f IntFar=%8.6 SigFar=%6.3f C=%8.6f\n", norm3,PAR[i][j][1]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][2],PAR[i][j][0]); } if((v=="norm" || v="corr") && fit==2){ f=new TF1("twoGaus",twoGaus,-PI/2.0,+PI*3.0/2.0,5); f->SetParameters(norm3/10.0,norm3/2.0,0.3,norm3/2.0,0.3); f->SetParNames("Const","IntNear","SigNear","IntFar","SigFar"); f->SetParLimits(0,0.0,1.0); f->SetParLimits(1,0.0,1.0); f->SetParLimits(2,0.0,3.0); f->SetParLimits(3,0.0,1.0); f->SetParLimits(4,0.0,3.0); f->SetLineColor(2); f->SetLineWidth(1); h->Fit("twoGaus","Q"); PAR[i][j][0]=f->GetParameter(0); PAR[i][j][1]=f->GetParameter(1); PAR[i][j][2]=f->GetParameter(2); PAR[i][j][3]=f->GetParameter(3); PAR[i][j][4]=f->GetParameter(4); printf("norm=%8.6f Int=%8.6f IntNear=%8.6f IntFar=%8.6f SigNear=%6.3f SigFar=%6.3f C=%8.6f\n", norm3,PAR[i][j][1]+PAR[i][j][3]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][3], PAR[i][j][2],PAR[i][j][4],PAR[i][j][0]); } float xx=0.60, yy=0.85, dy=0.04, size=0.04; if(bin1<0){xx=0.45, yy=0.90, dy=0.08, size=0.08;} if(v=="z12") {xx=0.1; yy=0.35;} t = new TText(xx, yy, Form("pT1=%3.1f-%3.1f",ptcut[i],ptcut[i+1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy, Form("pT2=%3.1f-%3.1f",ptcut[j],ptcut[j+1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); if(norm3>0.0){ t = new TText(xx, yy-dy*2, Form("P=%7.5f",norm3)); t->SetNDC(); t->SetTextSize(size); t->Draw(); } if((v=="norm" || v="corr") && fit==1){ t = new TText(xx, yy-dy*3, Form("PBg=%7.5f", PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*5, Form("Saway=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw(); } if((v=="norm" || v="corr") && fit==2){ t = new TText(xx, yy-dy*3, Form("Pnear=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][3])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*5, Form("PBg=%7.5f", PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*6, Form("Snear=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*7, Form("Saway=%4.2f",PAR[i][j][4])); t->SetNDC(); t->SetTextSize(size); t->Draw(); } if(cut==88) h->SetLineColor(2); if(cut==99 && (v=="m1"|| v=="m2")){ sprintf(c,"%s_%1d%1d_c%d",v,i,j,1); h = (TH1F*)mTFile->Get(c); h->SetLineColor(4); h->Draw("same"); sprintf(c,"%s_%1d%1d_c%d",v,i,j,2); h = (TH1F*)mTFile->Get(c); h->SetLineColor(2); h->Draw("same"); } if(cut==99 && v=="dphi"){ h->SetLineColor(4); sprintf(c,"%s_%1d%1d_c%d",v,i,j,2); h = (TH1F*)mTFile->Get(c); h->SetLineColor(2); h->Draw("same"); } if(bin1>0){ t = new TText(0.1, 0.92,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.07); t->SetTextColor(1); t->Draw(); if (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d_bin%d%d.png",v,cut,i,j);} else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d_bin%d%d.png",v,cut,i,j);} else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d_bin%d%d.png",v,cut,i,j);} else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d_bin%d%d.png",v,cut,i,j);} else {sprintf(c,"plot/dipi0_%d_%s_c%d_bin%d%d.png",run,v,cut,i,j);} printf("Saving %s\n",c); cvs->SaveAs(c); } } } if(bin1<0){ cvs->cd(2); t = new TText(0.0, 0.85,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(1); t->Draw(); } if(v=="mall"){ t = new TText(0.05, 0.65,"M1(no mass, scaled)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(1); t->Draw(); t = new TText(0.05, 0.55,"M1(without M2)/P"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(6); t->Draw(); t = new TText(0.05, 0.45,"M1(with M2)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw(); t = new TText(0.05, 0.35,"M2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw(); } if(v=="z12"){ t = new TText(0.05, 0.65,"Zgg1"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw(); t = new TText(0.05, 0.55,"Zgg2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw(); } if(cut==99) { t = new TText(0.0, 0.65, "Inclusive Pair"); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(4); t->Draw(); t = new TText(0.0, 0.45, "Exclusive Pair"); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(2); t->Draw(); } if(bin1<0){ if (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d.png",v,cut);} else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d.png",v,cut);} else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d.png",v,cut);} else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d.png",v,cut);} else {sprintf(c,"plot/dipi0_%d_%s_c%d.png",run,v,cut);} printf("Saving %s\n",c); cvs->SaveAs(c); } }
void DrawLc3D(Int_t step=1,Float_t ptmin=0,Float_t ptmax=10){ Double_t nev = 13E6; Double_t nsig = 1.5E5; Double_t nback = 1.5; TFile *fcur = TFile::Open(Form("step%i.root",step)); TFile *fpre = TFile::Open(Form("step%i.root",step-1)); if(! fpre) fpre = fcur; const char *comb = "PiKaPr"; Int_t rebin=1; TH3D *hcurT = (TH3D *) fcur->Get(Form("truePidLc%s",comb)); TH3D *hcurP = (TH3D *) fcur->Get(Form("priorsLc%s",comb)); TH3D *htrueLc = (TH3D *) fcur->Get(Form("trueLc")); TH3D *hmypidLc = (TH3D *) fcur->Get(Form("mypidLc")); TH3D *hpreT = (TH3D *) fpre->Get(Form("truePidLc%s",comb)); TH3D *hpreP = (TH3D *) fpre->Get(Form("priorsLc%s",comb)); TH3D *hPion = (TH3D *) fcur->Get("priorsLcPiPiPi"); // hPion->Add((TH2D *) fcur->Get("priorsKsPiKa")); // hPion->Add((TH2D *) fcur->Get("priorsKsPiPr")); // hPion->Add((TH2D *) fcur->Get("priorsKsKaKa")); // hPion->Add((TH2D *) fcur->Get("priorsKsKaPr")); // hPion->Add((TH2D *) fcur->Get("priorsKsKaPi")); // hPion->Add((TH2D *) fcur->Get("priorsKsPrKa")); // hPion->Add((TH2D *) fcur->Get("priorsKsPrPr")); // hPion->Add((TH2D *) fcur->Get("priorsKsPrPi")); hcurT->RebinX(rebin); hcurP->RebinX(rebin); hpreT->RebinX(rebin); hpreP->RebinX(rebin); hPion->RebinX(rebin); htrueLc->RebinX(rebin); if(hmypidLc) hmypidLc->RebinX(rebin); TH1D *hprior = hcurP->ProjectionX("meas",hcurP->GetYaxis()->FindBin(ptmin+0.001),hcurP->GetYaxis()->FindBin(ptmax-0.001),0,-1); TH1D *htrue = hcurT->ProjectionX("true",hcurT->GetYaxis()->FindBin(ptmin+0.001),hcurT->GetYaxis()->FindBin(ptmax-0.001),0,-1); TH1D *hreal = htrueLc->ProjectionX("real",hcurT->GetYaxis()->FindBin(ptmin+0.001),hcurT->GetYaxis()->FindBin(ptmax-0.001),0,-1); TH1D *hmypid = NULL; if(hmypidLc) hmypid = hmypidLc->ProjectionX("mypid",hcurT->GetYaxis()->FindBin(ptmin+0.001),hcurT->GetYaxis()->FindBin(ptmax-0.001),0,-1); TH1D *hpriorOld = hpreP->ProjectionX("measOld",hpreP->GetYaxis()->FindBin(ptmin+0.001),hpreP->GetYaxis()->FindBin(ptmax-0.001),0,-1); TH1D *hnorm = hPion->ProjectionX("norm",hPion->GetYaxis()->FindBin(ptmin+0.001),hPion->GetYaxis()->FindBin(ptmax-0.001),0,-1); for(Int_t i=1;i <= hprior->GetNbinsX();i++){ Float_t err = TMath::Abs(hprior->GetBinContent(i)-hpriorOld->GetBinContent(i)); if(hnorm->GetBinContent(i) > hprior->GetBinContent(i)){ err *= hnorm->GetBinContent(i); err /= hprior->GetBinContent(i); } err = sqrt(err*err + hprior->GetBinContent(i)); if(err < 1) err = 1; if(htrue->GetBinError(i)<1)htrue->SetBinError(i,1); hprior->SetBinError(i,err); } TF1 *bw = new TF1("bw","gaus(0) + pol1(3)",2.23,2.35); TF1 *bwsig = new TF1("bw","gaus(0)",0.8,1); bw->SetLineColor(2); bw->SetParameter(0,100); bw->FixParameter(1,2.28646); bw->FixParameter(2,0.008); 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"); hprior->SetMinimum(0); htrue->Draw("SAME"); htrue->SetLineColor(2); htrue->Fit(bw,"EI","",2.15,2.42); for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i)); Float_t truesig = bwsig->Integral(2.28646-3*0.008,2.28646+3*0.008) / htrue->GetBinWidth(1); Float_t backgrd = bw->Integral(2.28646-3*0.008,2.28646+3*0.008) / htrue->GetBinWidth(1); backgrd -= truesig; hprior->Draw("SAME"); hprior->Fit(bw,"EI","",2.15,2.42); Float_t fiterror = 0; if(bw->GetParameter(0)) fiterror = TMath::Abs(bw->GetParError(0)/bw->GetParameter(0)); hreal->Draw("SAME"); for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i)); Float_t meassig = bwsig->Integral(2.28646-3*0.008,2.28646+3*0.008) / htrue->GetBinWidth(1); // hpriorOld->SetLineColor(4); // hpriorOld->Draw("SAME"); // for(Int_t i=1;i<= htrue->GetNbinsX();i++) // htrue->SetBinError(i,0); 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->GetYaxis()->SetTitle("(meas - true)/true"); hr->Add(htrue,-1); hr->Divide(htrue); hr->Draw(); hr->GetYaxis()->UnZoom(); // hr->Fit(bw,"","",0.8,1.); for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i)); Float_t deltasig = bwsig->Integral(2.28646-3*0.008,2.28646+3*0.008) / hr->GetBinWidth(1); printf("signal = %f(true) %f(meas) -- delta = %f (%f) --> Relative Error = %f(stat=%f, fit=%f)%c\n",truesig,meassig,meassig-truesig,deltasig,(meassig-truesig)/truesig*100,100./sqrt(TMath::Abs(truesig)),fiterror*100,'%'); Float_t signal = hreal->Integral(1,hreal->GetNbinsX())*nev/nsig; Float_t signalback = signal + backgrd*nev/nback; Float_t signalmeas = meassig*nev/nsig; printf("significance = %f (yield=%f)\n",signal/sqrt(signalback),signal); printf("S/B = %f (back=%f)\n",signal/signalback,signalback); printf("significance measured = %f\n",signal/sqrt(signalback)); printf("reco Lambdac = %i\n",hreal->Integral(1,hreal->GetNbinsX())); if(!hmypidLc) return; new TCanvas(); hmypid->Draw(); hmypid->Fit(bw,"EI","",2.15,2.42); for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i)); Float_t mypidsig = bwsig->Integral(2.28646-3*0.008,2.28646+3*0.008) / hmypid->GetBinWidth(1); backgrd = bw->Integral(2.28646-3*0.008,2.28646+3*0.008) / hmypid->GetBinWidth(1); backgrd -= mypidsig; signal = mypidsig*nev/nsig; signalback = signal + backgrd*nev/nback; printf("my pid signal = %f\n",mypidsig); printf("my pid significance = %f\n",signal/sqrt(signalback)); }
void toyMC_background(){ char tmp[1000]; setTDRStyle(); // settings for purity TGraphAsymmetryErrors Double_t fBinsPtMidPoint[nPtBin]={0}; Double_t fBinsPtError[nPtBin]={0}; for(int ipt=0; ipt < nPtBin; ipt++) { fBinsPtMidPoint[ipt] = 0.5*(fBinsPt[ipt+1]+fBinsPt[ipt]); fBinsPtError[ipt] = 0.5*(fBinsPt[ipt+1]-fBinsPt[ipt]); } Double_t nsig_func[nEtaBin][nPtBin]={{0}}; Double_t nbkg_func[nEtaBin][nPtBin]={{0}}; Double_t nsig_err_func[nEtaBin][nPtBin]={{0}}; Double_t nbkg_err_func[nEtaBin][nPtBin]={{0}}; TH1F* hTemplate_S[nEtaBin][nPtBin]; TH1F* hTemplate_B[nEtaBin][nPtBin]; TH1F* hTemplate_data[nEtaBin][nPtBin]; TH1F* hdata_S[nEtaBin][nPtBin]; TH1F* hdata_B[nEtaBin][nPtBin]; TH1F* hdata_data[nEtaBin][nPtBin]; std::string dataFile = "rawYield_SBMC.root"; std::string templateFile = "rawYield_SBdata.root"; TFile* inf_data = new TFile(dataFile.data()); TFile* inf_template = new TFile(templateFile.data()); TH1F* htoyResult_pull[nEtaBin][nPtBin]; TH1F* htoyResult_diff[nEtaBin][nPtBin]; char* dec[2] = {"EB","EE"}; for(int ieta=0; ieta<nEtaBin; ieta++){ for(int ipt=0; ipt < nPtBin; ipt++){ htoyResult_pull[ieta][ipt] = new TH1F(Form("hpull_Eta_%.2f_%.2f_Et_%d_%d", fBinsEta[ieta*2],fBinsEta[ieta*2+1], (int)fBinsPt[ipt], (int)fBinsPt[ipt+1]), "",200,-20.0,20.0); htoyResult_diff[ieta][ipt] = new TH1F(Form("hdiff_Eta_%.2f_%.2f_Et_%d_%d", fBinsEta[ieta*2],fBinsEta[ieta*2+1], (int)fBinsPt[ipt], (int)fBinsPt[ipt+1]), "",50,-1.0,1.0); // getting histograms from data root file sprintf(tmp,"hOutputData_%s_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << inf_data->GetName() << endl; hdata_data[ieta][ipt] = (TH1F*)inf_data->FindObjectAny(tmp); hdata_data[ieta][ipt]->Rebin(REBINNINGS); // setting titles sprintf(tmp,"%.2f < |#eta(#gamma)| < %.2f, %d < p_{T}(#gamma) < %d GeV", fBinsEta[ieta*2],fBinsEta[ieta*2+1], (int)fBinsPt[ipt], (int)fBinsPt[ipt+1]); hdata_data[ieta][ipt]->SetTitle(tmp); sprintf(tmp,"hOutputSig_%s_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << inf_data->GetName() << endl; hdata_S[ieta][ipt] = (TH1F*)inf_data->FindObjectAny(tmp); hdata_S[ieta][ipt]->Rebin(REBINNINGS); sprintf(tmp,"hOutputBkg_%s_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << inf_data->GetName() << endl; hdata_B[ieta][ipt] = (TH1F*)inf_data->FindObjectAny(tmp); hdata_B[ieta][ipt]->Rebin(REBINNINGS); // getting histogram for template root file sprintf(tmp,"hOutputData_%s_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << inf_template->GetName() << endl; hTemplate_data[ieta][ipt] = (TH1F*)inf_template->FindObjectAny(tmp); hTemplate_data[ieta][ipt]->Rebin(REBINNINGS); sprintf(tmp,"%.2f < |#eta(#gamma)| < %.2f, %d < p_{T}(#gamma) < %d GeV", fBinsEta[ieta*2],fBinsEta[ieta*2+1], (int)fBinsPt[ipt], (int)fBinsPt[ipt+1]); hTemplate_data[ieta][ipt]->SetTitle(tmp); sprintf(tmp,"hOutputSig_%s_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << inf_template->GetName() << endl; hTemplate_S[ieta][ipt] = (TH1F*)inf_template->FindObjectAny(tmp); hTemplate_S[ieta][ipt]->Rebin(REBINNINGS); sprintf(tmp,"hOutputBkg_%s_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << inf_template->GetName() << endl; hTemplate_B[ieta][ipt] = (TH1F*)inf_template->FindObjectAny(tmp); hTemplate_B[ieta][ipt]->Rebin(REBINNINGS); } } TH1F* htoyMC_data = (TH1F*)hdata_data[0][0]->Clone(); // htoyMC_data->SetName("htoyMC_data"); htoyMC_data->Reset(); TH1F* htoyMC_sig = (TH1F*)hTemplate_S[0][0]->Clone(); // htoyMC_sig->SetName("htoyMC_sig"); htoyMC_sig->Reset(); TH1F* htoyMC_bkg = (TH1F*)hTemplate_B[0][0]->Clone(); // htoyMC_bkg->SetName("htoyMC_bkg"); htoyMC_bkg->Reset(); TH1F* hfit_sig; TH1F* hfit_bkg; for(int ieta=0; ieta< nEtaBin; ieta++){ for(int ipt=0; ipt < nPtBin; ipt++){ // first obtain fit for the template hfit_sig = (TH1F*)hdata_S[ieta][ipt]->Clone(); hfit_sig -> SetName("hfit_sig"); if(ieta==0) hfit_sig -> Rebin(2); // hfit_sig->Scale(1.0/(float)hfit_sig->Integral()); hfit_bkg = (TH1F*)hdata_B[ieta][ipt]->Clone(); hfit_bkg -> SetName("hfit_bkg"); if(ieta==0) hfit_bkg -> Rebin(2); // hfit_bkg->Scale(1.0/(float)hfit_bkg->Integral()); double sigPar[20] = {hfit_sig->GetMaximum(), 1., 0.5, 0.3, hfit_bkg->GetMaximum(),-.3,-1., 0.01, 0.5, 0.01, 1., 1.}; TF1 *fsig = new TF1("fsig", exp_conv, -1., 11., 12); fsig->SetParameters(sigPar); hfit_sig->Fit(fsig,"","",-1,5.0); TF1 *fbkg = new TF1("fbkg", expinv_power, -1., 11., 12); fbkg->SetParameters(fsig->GetParameters()); fbkg->SetParLimits(5,-10.,1.); fbkg->SetParLimits(6,-1.,2.); fbkg->SetParLimits(7,0.,0.09); if(ieta==1 && ipt==3) { // cout << "find EE in pt bin 50--80" << endl; fbkg->FixParameter(5,-0.1); } if(ieta==0 && ipt==4) { // cout << "find EB in pt bin 80--120" << endl; fbkg->FixParameter(5,-0.1); } fbkg->FixParameter(8,0.5); fbkg->FixParameter(0,fbkg->GetParameter(0)); fbkg->FixParameter(1,fbkg->GetParameter(1)); fbkg->FixParameter(2,fbkg->GetParameter(2)); fbkg->FixParameter(3,fbkg->GetParameter(3)); hfit_bkg->Fit(fbkg,"b"); // for(int i=0;i<12;i++)cout << "parameter " << i << " = " << // fbkg->GetParameter(i) << endl; htoyMC_sig = (TH1F*)hTemplate_S[ieta][ipt]->Clone(); htoyMC_bkg = (TH1F*)hTemplate_B[ieta][ipt]->Clone(); // loops over toys for(int iexp=0; iexp<NEXP; iexp++){ htoyMC_data->Reset(); UInt_t nowSeed = (unsigned long)gSystem->Now(); gRandom->SetSeed(nowSeed); int ndata = hdata_data[ieta][ipt]->Integral(); int nsig = gRandom->Poisson(nsig_data[ieta][ipt]); int nbkg = gRandom->Poisson(ndata - nsig_data[ieta][ipt]); // htoyMC_data->FillRandom(hTemplate_S[ieta][ipt],nsig); // htoyMC_data->FillRandom(hTemplate_B[ieta][ipt],nbkg); htoyMC_data->FillRandom("fsig",nsig); htoyMC_data->FillRandom("fbkg",nbkg); htoyMC_data->Draw(); cout << "ndata = " << ndata << "\t nsig = " << nsig << " \t nbkg = " << nbkg << endl; Double_t scaleNumber[20]; for(int i=0;i<20;i++)scaleNumber[i]=1.; // 2nd, get unbinned fit Double_t* FuncFitResult; FuncFitResult = Ifit(htoyMC_data, htoyMC_sig, htoyMC_bkg,0,"EGdata_100628.dat", fBinsEta[ieta*2],fBinsEta[ieta*2+1], fBinsPt[ipt],fBinsPt[ipt+1], NULL ); Double_t nsigfunc = FuncFitResult[0]; Double_t errnsigfunc = FuncFitResult[1]; Double_t nbkgfunc = FuncFitResult[2]; Double_t errnbkgfunc = FuncFitResult[3]; Double_t pull = (nsigfunc - nsig_data[ieta][ipt])/errnsigfunc; Double_t diff = (nsigfunc - nsig_data[ieta][ipt])/nsig_data[ieta][ipt]; // // Double_t* TemplateFitResult; // // TemplateFitResult = IfitBin(htoyMC_data, // // htoyMC_sig, // // htoyMC_bkg); // // Double_t nsigtemplate = TemplateFitResult[0]; // // Double_t errnsigtemplate = TemplateFitResult[1]; // // Double_t nbkgtemplate = TemplateFitResult[2]; // // Double_t errnbkgtemplate = TemplateFitResult[3]; // // Double_t pull = (nsigtemplate - nsig_data[ieta][ipt])/errnsigtemplate; htoyResult_diff[ieta][ipt]->Fill(diff); htoyResult_pull[ieta][ipt]->Fill(pull); } // end loops of toys delete fsig; delete fbkg; } // end of loop over pt bins } for(int ieta=0; ieta < nEtaBin; ieta++){ TFile* outFile = new TFile(Form("fitterTest_%s.root",dec[ieta]), "recreate"); for(int ipt=0; ipt < nPtBin; ipt++){ htoyResult_pull[ieta][ipt]->Write(); htoyResult_diff[ieta][ipt]->Write(); } outFile->Close(); } }
void MakePi0Analysis(){ gStyle->SetPadLeftMargin(0.15); gStyle->SetPadRightMargin(0.01); gStyle->SetPadTopMargin(0.09); gStyle->SetPadBottomMargin(0.11); //gStyle->SetOptStat(0); //gStyle->SetOptTitle(1); //gStyle->SetPadTickX(1); //gStyle->SetPadTickY(1); TGaxis::SetMaxDigits(3); Double_t bins[] = {1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0, 3.2, 3.4, 3.6,3.8,4.0,4.5, 5.0, 5.5,6.0,6.5,7.0,7.5,8.0,8.5,9.0,10.0,11,12}; //Nicolas LHC12d PHI const Int_t binnum = sizeof(bins)/sizeof(Double_t) - 1; TString cwd = gSystem->WorkingDirectory(); TH1F* fHistPeakMean = new TH1F("fHistPeakMean","",binnum,bins); TH1F* fHistPeakWidth = new TH1F("fHistPeakWidth","",binnum,bins); TH1F* fHistRawYield = new TH1F("fHistRawYield","",binnum,bins); TH1F* fHistRawYieldPerEvent = new TH1F("fHistRawYieldPerEvent","",binnum,bins); TCanvas *c1[binnum]; TCanvas *c2[binnum]; TCanvas *c3; TFile* ef = TFile::Open("../AnalysisResults.root"); TList* list = (TList*)ef->Get("list_kINT7_Pi0"); TList *listEv = (TList*)ef->Get("list_kINT7_Event"); TH1F* fHistEvents = (TH1F*)listEv->FindObject("fHistAnalyzedEvents"); Double_t nEvt = fHistEvents->GetEntries(); TString tofName[] = {"","_TOFcut1","_TOFcut2"}; TString fitName[] = {"CrystalBall","AsymmGauss"}; TString modName[] = {"","_M1","_M3"}; Int_t ntof = 3; Double_t signal_range_min=0.11; Double_t signal_range_max=0.15; Double_t bg_range_min=0.050; Double_t bg_range_max=0.250; for(Int_t itof=0; itof<ntof; ++itof){ for(Int_t iMod=0; iMod<1; iMod++){ for(Int_t iFit=0; iFit<2; iFit++){ for(Int_t iPol=0; iPol<3; iPol++){ Int_t pol = iPol; TString fNameSame = "fHistMassTwoGammas"+tofName[itof]+modName[iMod]; TString fNameMix = "fHistMixMassTwoGammas"+tofName[itof]+modName[iMod]; THnSparse *fTHnSparseRecPi0; THnSparse *fTHnSparseRecMixPi0; THnSparse *fTHnSparseGeneratePi0; TH2* hPi0A08 = 0x0; TH2* hMixPi0A08 = 0x0; hPi0A08 = (TH2*)list->FindObject(fNameSame)->Clone(); hMixPi0A08 = (TH2*)list->FindObject(fNameMix)->Clone(); Int_t sbin = 0; Int_t lbin = 0; TH1F* fHistFinalRatio[binnum]; TH1F* fHistFinalSame[binnum]; TH1F* fHistFinalBG[binnum]; TH1F* fHistFinalSignal[binnum]; TH1F* fHistOnlyFitSignal[binnum]; TF1* fFitFinalRatio[binnum]; TF1* fFitFinalSignal[binnum]; TF1* fFitOnlyFitSignal[binnum]; for(Int_t i=0; i<binnum; i++){ Double_t bin_width = (bins[i+1]-bins[i]); Double_t bin_mean = (bins[i+1]+bins[i])/2; Int_t rebin = 1; if(bin_mean>5.0){ rebin=10; } else{ rebin=5; } Int_t sproj_bin = hPi0A08->GetYaxis()->FindBin(bins[i]); Int_t lproj_bin = hPi0A08->GetYaxis()->FindBin(bins[i+1])-1; TH1* fHistBasicSame = (TH1*)hPi0A08 ->ProjectionX(Form("fHistBasicSame_No%d",i+1),sproj_bin,lproj_bin,""); TH1* fHistBasicMix = (TH1*)hMixPi0A08->ProjectionX(Form("fHistBasicMix_No%d",i+1),sproj_bin,lproj_bin,""); fHistBasicSame->Rebin(rebin); fHistBasicMix->Rebin(rebin); fHistBasicSame->Sumw2(); fHistBasicMix->Sumw2(); fHistBasicSame->GetYaxis()->SetTitle(Form("dN/dM per %.0f MeV/c^{2}",fHistBasicSame->GetBinWidth(1)*1000)); fHistBasicMix->GetYaxis()->SetTitle(Form("dN/dM per %.0f MeV/c^{2}",fHistBasicSame->GetBinWidth(1)*1000)); fHistBasicSame->GetXaxis()->SetRange(fHistBasicSame->GetXaxis()->FindBin(0.),fHistBasicSame->GetXaxis()->FindBin(0.3)-1); fHistBasicMix->GetXaxis()->SetRange(fHistBasicSame->GetXaxis()->FindBin(0.),fHistBasicSame->GetXaxis()->FindBin(0.3)-1); fHistBasicSame->SetMarkerStyle(20); fHistBasicMix->SetMarkerStyle(24); fHistBasicSame->SetMarkerColor(kBlack); fHistBasicMix->SetMarkerColor(kBlue); fHistBasicSame->SetLineColor(kBlack); fHistBasicMix->SetLineColor(kBlue); fHistFinalSame[i] = (TH1F*)fHistBasicSame->Clone(); fHistOnlyFitSignal[i] = (TH1F*)fHistBasicSame->Clone(); fHistOnlyFitSignal[i]->SetName(Form("fHistOnlyFitSignal_Pol%d_No%d",pol,i+1)+fitName[iFit]+tofName[itof]+modName[iMod]); TH1F* fHistOnlyFit_Signal = (TH1F*)fHistOnlyFitSignal[i]->Clone(); TH1F* fHistOnlyFit_BG = (TH1F*)fHistOnlyFitSignal[i]->Clone(); TH1F* fHistRatio = (TH1F*)fHistBasicSame->Clone(); fHistRatio->Divide(fHistBasicMix); fHistRatio->SetName(Form("cRatioSameBG_Pol%d_No%d",pol,i+1)+fitName[iFit]+tofName[itof]+modName[iMod]); TH1F* fHistRatio_Signal = (TH1F*)fHistRatio->Clone(); TH1F* fHistRatio_BG = (TH1F*)fHistRatio->Clone(); Int_t ssignal_bin = fHistRatio_Signal->GetXaxis()->FindBin(signal_range_min); Int_t lsignal_bin = fHistRatio_Signal->GetXaxis()->FindBin(signal_range_max); Int_t sbg_bin = fHistRatio_BG->GetXaxis()->FindBin(bg_range_min); Int_t lbg_bin = fHistRatio_BG->GetXaxis()->FindBin(bg_range_max); for(Int_t j=ssignal_bin; j<lsignal_bin; ++j){ fHistRatio_BG->SetBinContent(j,0); fHistRatio_BG->SetBinError(j,0); fHistOnlyFit_BG->SetBinContent(j,0); fHistOnlyFit_BG->SetBinError(j,0); } for(Int_t j=sbg_bin; j<ssignal_bin; ++j){ fHistRatio_Signal->SetBinContent(j,0); fHistRatio_Signal->SetBinError(j,0); fHistOnlyFit_Signal->SetBinContent(j,0); fHistOnlyFit_Signal->SetBinError(j,0); } for(Int_t j=lsignal_bin; j<lbg_bin; ++j){ fHistRatio_Signal->SetBinContent(j,0); fHistRatio_Signal->SetBinError(j,0); fHistOnlyFit_Signal->SetBinContent(j,0); fHistOnlyFit_Signal->SetBinError(j,0); } /////////////////////////////////////////////////////////////////////////////////////////////////// // Combinatrial background analysis /////////////////////////////////////////////////////////////////////////////////////////////////// TF1 *fFitRatio_Signal = NULL; if(iFit==0){ fFitRatio_Signal = new TF1("fFitRatio_Signal", "[4]*((x-[2])/[3] > -[0] ? 1.0:0.0 )*exp(-pow(x-[2],2)/(2*pow([3],2))) + ((x-[2])/[3] <= -[0] ? 1.0:0.0 )*[4]*pow([1]/[0],[1])*exp(-[0]*[0]/2) * pow([1]/[0]-[0]-(x-[2])/[3],-[1])+[5]", signal_range_min,signal_range_max); fFitRatio_Signal->SetParameters(1.,6.,0.135,0.005,0.01); fFitRatio_Signal->FixParameter(0,1.16053); fFitRatio_Signal->FixParameter(1,6.); fFitRatio_Signal->SetParLimits(2,0.130,0.140); fFitRatio_Signal->SetParLimits(3,0.005,0.03); } else if(iFit==1){//[0]=A, [1]=M_pi0, [2]=sigma, [3]=lamda fFitRatio_Signal = new TF1("fFitRatio_Signal", "[0] *( ([1]>x ? 1.0:0.0 ) * (1 - exp(-0.5*pow((x-[1])/[2],2))) * exp((x-[1])/[3]) + exp(-0.5*pow((x-[1])/[2],2)) )", signal_range_min,signal_range_max); fFitRatio_Signal->SetParameters(1,0.135,6.46624e-03,7.47626e-03); fFitRatio_Signal->SetParLimits(1,0.130,0.140); fFitRatio_Signal->SetParLimits(2,0.001,0.03); fFitRatio_Signal->SetParLimits(3,0.001,0.03); } fHistRatio_Signal->Fit(fFitRatio_Signal,"RNQ"); fHistRatio_Signal->Fit(fFitRatio_Signal,"RNQ"); fHistRatio_Signal->Fit(fFitRatio_Signal,"RNQ"); TF1 *fFitRatio_BG = 0x0; if(pol==0){ fFitRatio_BG = new TF1("fFitRatio_BG","[0]",0,1); } else if(pol==1){ fFitRatio_BG = new TF1("fFitRatio_BG","[0]+[1]*x",0,1); } else if(pol==2){ fFitRatio_BG = new TF1("fFitRatio_BG","[0]+[1]*x+[2]*x*x",0,1); } fHistRatio_BG->Fit(fFitRatio_BG,"RNQ","",bg_range_min,bg_range_max); fHistRatio_BG->Fit(fFitRatio_BG,"RNQ","",bg_range_min,bg_range_max); fHistRatio_BG->Fit(fFitRatio_BG,"RNQ","",bg_range_min,bg_range_max); TF1 *fFitRatio_SignalBG = 0x0; TF1 *fFitScale = 0x0; if(iFit==0){ if(pol==0){ fFitRatio_SignalBG= new TF1("fFitRatio_SignalBG", "[4]*((x-[2])/[3] > -[0] ? 1.0:0.0 )*exp(-pow(x-[2],2)/(2*pow([3],2))) + ((x-[2])/[3] <= -[0] ? 1.0:0.0 )*[4]*pow([1]/[0],[1])*exp(-[0]*[0]/2) * pow([1]/[0]-[0]-(x-[2])/[3],-[1])+[5]",0,1); fFitRatio_SignalBG->SetParameter(0,fFitRatio_Signal->GetParameter(0)); fFitRatio_SignalBG->SetParameter(1,fFitRatio_Signal->GetParameter(1)); fFitRatio_SignalBG->SetParameter(2,fFitRatio_Signal->GetParameter(2)); fFitRatio_SignalBG->SetParameter(3,fFitRatio_Signal->GetParameter(3)); fFitRatio_SignalBG->SetParameter(4,fFitRatio_Signal->GetParameter(4)); fFitRatio_SignalBG->SetParameter(5,fFitRatio_BG->GetParameter(0)); fFitScale = new TF1("fFitScale","pol0",0.,1); } else if(pol==1){ fFitRatio_SignalBG = new TF1("fFitRatio_SignalBG", "[4]*((x-[2])/[3] > -[0] ? 1.0:0.0 )*exp(-pow(x-[2],2)/(2*pow([3],2))) + ((x-[2])/[3] <= -[0] ? 1.0:0.0 )*[4]*pow([1]/[0],[1])*exp(-[0]*[0]/2) * pow([1]/[0]-[0]-(x-[2])/[3],-[1])+[5]+[6]*x", 0,1); fFitRatio_SignalBG->SetParameter(0,fFitRatio_Signal->GetParameter(0)); fFitRatio_SignalBG->SetParameter(1,fFitRatio_Signal->GetParameter(1)); fFitRatio_SignalBG->SetParameter(2,fFitRatio_Signal->GetParameter(2)); fFitRatio_SignalBG->SetParameter(3,fFitRatio_Signal->GetParameter(3)); fFitRatio_SignalBG->SetParameter(4,fFitRatio_Signal->GetParameter(4)); fFitRatio_SignalBG->SetParameter(5,fFitRatio_BG->GetParameter(0)); fFitScale = new TF1("fFitScale","pol1",0,1); } else if(pol==2){ fFitRatio_SignalBG = new TF1("fFitRatio_SignalBG", "[4]*((x-[2])/[3] > -[0] ? 1.0:0.0 )*exp(-pow(x-[2],2)/(2*pow([3],2))) + ((x-[2])/[3] <= -[0] ? 1.0:0.0 )*[4]*pow([1]/[0],[1])*exp(-[0]*[0]/2) * pow([1]/[0]-[0]-(x-[2])/[3],-[1])+[5]+[6]*x+[7]*x*x",0,1); fFitRatio_SignalBG->SetParameter(0,fFitRatio_Signal->GetParameter(0)); fFitRatio_SignalBG->SetParameter(1,fFitRatio_Signal->GetParameter(1)); fFitRatio_SignalBG->SetParameter(2,fFitRatio_Signal->GetParameter(2)); fFitRatio_SignalBG->SetParameter(3,fFitRatio_Signal->GetParameter(3)); fFitRatio_SignalBG->SetParameter(4,fFitRatio_Signal->GetParameter(4)); fFitRatio_SignalBG->SetParameter(5,fFitRatio_BG->GetParameter(0)); fFitRatio_SignalBG->SetParameter(6,fFitRatio_BG->GetParameter(1)); fFitRatio_SignalBG->SetParameter(7,fFitRatio_BG->GetParameter(2)); fFitScale = new TF1("fFitScale","pol2",0,1); } fFitRatio_SignalBG->FixParameter(0,1.16053); fFitRatio_SignalBG->FixParameter(1,6.); fFitRatio_SignalBG->SetParLimits(2,0.130,0.140); fFitRatio_SignalBG->SetParLimits(3,0.005,0.03); } if(iFit==1){ if(pol==0){ fFitRatio_SignalBG= new TF1("fFitRatio_SignalBG", "[0] *( ([1]>x ? 1.0:0.0 ) * (1 - exp(-0.5*pow((x-[1])/[2],2))) * exp((x-[1])/[3]) + exp(-0.5*pow((x-[1])/[2],2)) ) + [4]", 0,1); fFitRatio_SignalBG->SetParameter(0,fFitRatio_Signal->GetParameter(0)); fFitRatio_SignalBG->SetParameter(1,fFitRatio_Signal->GetParameter(1)); fFitRatio_SignalBG->SetParameter(2,fFitRatio_Signal->GetParameter(2)); fFitRatio_SignalBG->SetParameter(3,fFitRatio_Signal->GetParameter(3)); fFitRatio_SignalBG->SetParameter(4,fFitRatio_BG->GetParameter(0)); fFitScale = new TF1("fFitScale","pol0",0,1); } else if(pol==1){ fFitRatio_SignalBG = new TF1("fFitRatio_SignalBG", "[0] *( ([1]>x ? 1.0:0.0 ) * (1 - exp(-0.5*pow((x-[1])/[2],2))) * exp((x-[1])/[3]) + exp(-0.5*pow((x-[1])/[2],2)) ) + [4]+[5]*x", 0,1); fFitRatio_SignalBG->SetParameter(0,fFitRatio_Signal->GetParameter(0)); fFitRatio_SignalBG->SetParameter(1,fFitRatio_Signal->GetParameter(1)); fFitRatio_SignalBG->SetParameter(2,fFitRatio_Signal->GetParameter(2)); fFitRatio_SignalBG->SetParameter(3,fFitRatio_Signal->GetParameter(3)); fFitRatio_SignalBG->SetParameter(4,fFitRatio_BG->GetParameter(0)); fFitRatio_SignalBG->SetParameter(5,fFitRatio_BG->GetParameter(1)); fFitScale = new TF1("fFitScale","pol1",0,1); } else if(pol==2){ fFitRatio_SignalBG = new TF1("fFitRatio_SignalBG", "[0] *( ([1]>x ? 1.0:0.0 ) * (1 - exp(-0.5*pow((x-[1])/[2],2))) * exp((x-[1])/[3]) + exp(-0.5*pow((x-[1])/[2],2)) ) + [4]+[5]*x+[6]*x*x", 0,1); fFitRatio_SignalBG->SetParameter(0,fFitRatio_Signal->GetParameter(0)); fFitRatio_SignalBG->SetParameter(1,fFitRatio_Signal->GetParameter(1)); fFitRatio_SignalBG->SetParameter(2,fFitRatio_Signal->GetParameter(2)); fFitRatio_SignalBG->SetParameter(3,fFitRatio_Signal->GetParameter(3)); fFitRatio_SignalBG->SetParameter(4,fFitRatio_BG->GetParameter(0)); fFitRatio_SignalBG->SetParameter(5,fFitRatio_BG->GetParameter(1)); fFitRatio_SignalBG->SetParameter(6,fFitRatio_BG->GetParameter(2)); fFitScale = new TF1("fFitScale","pol2",0,1); } fFitRatio_SignalBG->SetParLimits(1,0.130,0.140); fFitRatio_SignalBG->SetParLimits(2,0.005,0.03); fFitRatio_SignalBG->SetParLimits(3,0.005,0.03); } fHistRatio->Fit(fFitRatio_SignalBG,"NRQ","",bg_range_min,bg_range_max); fHistRatio->Fit(fFitRatio_SignalBG,"NRQ","",bg_range_min,bg_range_max); fHistRatio->Fit(fFitRatio_SignalBG,"NRQ","",bg_range_min,bg_range_max); fHistFinalRatio[i] = (TH1F*)fHistRatio->Clone();; fFitFinalRatio[i] = (TF1*)fFitRatio_SignalBG->Clone(); if(iFit==0){ if(pol==0){ fFitScale->SetParameter(0,fFitRatio_SignalBG->GetParameter(5)); } else if(pol==1){ fFitScale->SetParameters(fFitRatio_SignalBG->GetParameter(5),fFitRatio_SignalBG->GetParameter(6)); } else if(pol==2){ fFitScale->SetParameters(fFitRatio_SignalBG->GetParameter(5),fFitRatio_SignalBG->GetParameter(6),fFitRatio_SignalBG->GetParameter(7)); } } if(iFit==1){ if(pol==0){ fFitScale->SetParameter(0,fFitRatio_SignalBG->GetParameter(4)); } else if(pol==1){ fFitScale->SetParameters(fFitRatio_SignalBG->GetParameter(4),fFitRatio_SignalBG->GetParameter(5)); } else if(pol==2){ fFitScale->SetParameters(fFitRatio_SignalBG->GetParameter(4),fFitRatio_SignalBG->GetParameter(5),fFitRatio_SignalBG->GetParameter(6)); } } c3 = new TCanvas("c3","c3",600,600); c3->cd(); fHistRatio->Draw(); fFitRatio_SignalBG->Draw("same"); fFitScale->Draw("same"); c3->SetName(Form("cRatioSameBG_Pol%d_No%d",pol,i+1)+fitName[iFit]+tofName[itof]+modName[iMod]); tfout->WriteTObject(c3); TH1F* fHistScaledMix = (TH1F*)fHistBasicMix->Clone(); fHistScaledMix->Multiply(fFitScale); fHistFinalBG[i] = (TH1F*)fHistScaledMix->Clone();; TH1F* fHistSignal = (TH1F*)fHistBasicSame->Clone(); fHistSignal->SetName(Form("fHistSignal_Pol%d_No%d",pol,i+1)+fitName[iFit]+tofName[itof]+modName[iMod]); fHistScaledMix->SetName(Form("fHistScaledMix_Pol%d_No%d",pol,i+1)+fitName[iFit]+tofName[itof]+modName[iMod]); tfout->WriteTObject(fHistSignal); tfout->WriteTObject(fHistScaledMix); for(Int_t j=0; j<fHistBasicSame->GetXaxis()->FindBin(0.3); ++j){ Double_t same = fHistSignal->GetBinContent(j); Double_t e_same = fHistSignal->GetBinError(j); Double_t mix = fHistScaledMix->GetBinContent(j); Double_t e_mix = fHistScaledMix->GetBinError(j); Double_t signal = same - mix; Double_t e_signal = sqrt(pow(e_same,2)+pow(e_mix,2)); if(same>0){ signal = same - mix; e_signal = sqrt(pow(e_same,2)+pow(e_mix,2)); } else{ signal = same; e_signal = e_same; } fHistSignal->SetBinContent(j,signal); fHistSignal->SetBinError(j,e_signal); } fHistFinalSignal[i] = (TH1F*)fHistSignal->Clone(); fHistFinalSignal[i]->SetTitle(Form("%.2f < #it{p}_{T} %.2f (GeV/c)", bins[i], bins[i+1])); TF1 *fFitSignal = NULL; if(iFit==0){ fFitSignal = new TF1("fFitSignal", "[4]*((x-[2])/[3] > -[0] ? 1.0:0.0 )*exp(-pow(x-[2],2)/(2*pow([3],2))) + ((x-[2])/[3] <= -[0] ? 1.0:0.0 )*[4]*pow([1]/[0],[1])*exp(-[0]*[0]/2) * pow([1]/[0]-[0]-(x-[2])/[3],-[1])", 0,0.3); fFitSignal->SetParameters(1.,6.,0.135,0.005,0.01); fFitSignal->FixParameter(0,1.16053); fFitSignal->FixParameter(1,6.); fFitSignal->SetParLimits(2,0.120,0.140); fFitSignal->SetParLimits(3,0.005,0.03); } else if(iFit==1){ fFitSignal = new TF1("fFitSignal", "[0] *( ([1]>x ? 1.0:0.0 ) * (1 - exp(-0.5*pow((x-[1])/[2],2))) * exp((x-[1])/[3]) + exp(-0.5*pow((x-[1])/[2],2)) )", 0,0.3); fFitSignal->SetParameters(1,0.135,6.46624e-03,7.47626e-03); fFitSignal->SetParLimits(1,0.125,0.140); fFitSignal->SetParLimits(2,0.001,0.01); fFitSignal->SetParLimits(3,0.001,0.01); } fHistSignal->Fit(fFitSignal,"RNQ","",signal_range_min,signal_range_max); fHistSignal->Fit(fFitSignal,"RNQ","",0.12,signal_range_max); if(iFit==0){ fHistSignal->Fit(fFitSignal,"RNQ","",0.12,0.150); } else{ fHistSignal->Fit(fFitSignal,"RNQ","",0.12,0.150); } fFitFinalSignal[i] = (TF1*)fFitSignal->Clone(); Double_t mean = 0; Double_t e_mean = 0; Double_t signal_sigma = 0; Double_t e_signal_sigma = 0; Double_t signal_window_min = 0; Double_t signal_window_max = 0; if(iFit==0){ mean = fFitSignal->GetParameter(2); e_mean = fFitSignal->GetParError(2); signal_sigma = fabs(fFitSignal->GetParameter(3)); e_signal_sigma = fabs(fFitSignal->GetParError(3)); signal_window_min = mean - signal_sigma*5; signal_window_max = mean + signal_sigma*3; } else if(iFit==1){ mean = fFitSignal->GetParameter(1); e_mean = fFitSignal->GetParError(1); signal_sigma = fabs(fFitSignal->GetParameter(2)); e_signal_sigma = fabs(fFitSignal->GetParError(2)); signal_window_min = mean - signal_sigma*5; signal_window_max = mean + signal_sigma*3; } fHistPeakMean->SetBinContent(i+1,mean); fHistPeakMean->SetBinError(i+1,e_mean); fHistPeakWidth->SetBinContent(i+1,signal_sigma); fHistPeakWidth->SetBinError(i+1,e_signal_sigma); Int_t signal_window_bin_min = fHistSignal->GetXaxis()->FindBin(signal_window_min); Int_t signal_window_bin_max = fHistSignal->GetXaxis()->FindBin(signal_window_max); Double_t num_pi0 = 0; Double_t e_num_pi0 = 0; for(Int_t j=signal_window_bin_min; j<signal_window_bin_max; ++j){ num_pi0 += fHistSignal->GetBinContent(j); e_num_pi0 += pow(fHistSignal->GetBinError(j),2); } e_num_pi0 = sqrt(e_num_pi0); fHistRawYield->SetBinContent(i+1,num_pi0/bin_width); fHistRawYield->SetBinError(i+1,e_num_pi0/bin_width); } fHistRawYield->SetName(Form("fHistRawYieldPol%d",pol)+fitName[iFit]+tofName[itof]+modName[iMod]); tfout->WriteTObject(fHistRawYield); fHistRawYieldPerEvent = (TH1F*)fHistRawYield->Clone(); fHistRawYieldPerEvent->Scale(1./nEvt); fHistRawYieldPerEvent->SetName(Form("fHistRawYieldPerEventPol%d",pol)+fitName[iFit]+tofName[itof]+modName[iMod]); tfout->WriteTObject(fHistRawYieldPerEvent); fHistPeakMean->SetName(Form("fHistPeakMeanPol%d",pol)+fitName[iFit]+tofName[itof]+modName[iMod]); fHistPeakWidth->SetName(Form("fHistPeakWidthPol%d",pol)+fitName[iFit]+tofName[itof]+modName[iMod]); tfout->WriteTObject(fHistPeakMean); tfout->WriteTObject(fHistPeakWidth); c1[itof] = new TCanvas("c1"+fitName[iFit]+tofName[itof],"",1200,1800); c2[itof] = new TCanvas("c2"+fitName[iFit]+tofName[itof],"",1200,1800); c1[itof]->Divide(4,6); for(Int_t i=0; i<binnum; ++i){ c1[itof]->cd(i+1); fHistFinalSignal[i]->Draw(); fFitFinalSignal[i]->Draw("same"); } c1[itof]->SaveAs(Form("cInvariantMassSpectrumPol%d",pol)+fitName[iFit]+tofName[itof]+modName[iMod]+".eps"); c2[itof]->Divide(4,6); for(Int_t i=0; i<binnum; ++i){ c2[itof]->cd(i+1); fHistFinalSame[i]->Draw(); fHistFinalBG[i]->Draw("same"); } c2[itof]->SaveAs(Form("cSameScaledMixPol%d",pol)+fitName[iFit]+tofName[itof]+modName[iMod]+".eps"); for(Int_t i=0; i<binnum; ++i){ fHistFinalSignal[i]->SetName(Form("fHistFinalSignal_No%d_Pol%d",i+1,iPol)+fitName[iFit]+tofName[itof]+modName[iMod]); fFitFinalSignal[i]->SetName(Form("fFitFinalSignal_No%d_Pol%d",i+1,iPol)+fitName[iFit]+tofName[itof]+modName[iMod]); fHistFinalSame[i]->SetName(Form("fHistFinalSame_No%d_Pol%d",i+1,iPol)+fitName[iFit]+tofName[itof]+modName[iMod]); fHistFinalBG[i]->SetName(Form("fHistFinalBG_No%d_Pol%d",i+1,iPol)+fitName[iFit]+tofName[itof]+modName[iMod]); tfout->WriteTObject(fHistFinalSignal[i]); tfout->WriteTObject(fFitFinalSignal[i]); tfout->WriteTObject(fHistFinalSame[i]); tfout->WriteTObject(fHistFinalBG[i]); c3 = new TCanvas("c3","",600,600); c3->cd(1); fHistFinalSame[i]->Draw(); fHistFinalBG[i]->Draw("same"); c3->SetName(Form("cRawSignalBG_Pol%d_No%d",pol,i+1)+fitName[iFit]+tofName[itof]+modName[iMod]); //tfout->WriteTObject(c3); } for(Int_t i=0; i<binnum; ++i){ c3 = new TCanvas("c3","",600,600); c3->cd(1); fHistFinalSignal[i]->Draw(""); fFitFinalSignal[i]->Draw("same"); c3->SetName(Form("cRawSignal_Pol%d_No%d",pol,i+1)+fitName[iFit]+tofName[itof]+modName[iMod]); //tfout->WriteTObject(c3); } } } } } }
void plots::drawHists( bool MuAddOrNot, TString HTBins, int whichpart, int rebin, TString xAxisName, TString yAxisName, double xAxisRange1, double xAxisRange2, TString whichplot, TLegend * len, double lowy, double highy, int OneDTwoD, int startNJet, int nJets, TString MuonNumber, TString FolderLabel, TString axis ){ TCanvas *c1=new TCanvas("c1","c1", 1000, 900 ); playHist1D pf1d=playHist1D(); vector<TH1D*> vh; vector<TString> vhnames; vector<TString> vlenname; vector<unsigned int> vcolor; vector<bool> vh_special; vector<unsigned int> vh_linestype; if( hasT2cc_NoFilter_combined200_190_ ){ vlenname.push_back("T2cc (200, 190)"); vhnames.push_back("T2cc_NoFilter_combined200_190"); vcolor.push_back(kRed); vh_special.push_back(1); vh_linestype.push_back(1); TH1D *MCh_T1tttt= (getHists( MuAddOrNot, HTBins, whichpart, rebin, xAxisName, yAxisName, xAxisRange1, xAxisRange2, 2, whichplot, true, "SMS_Madgraph_T2cc_NoFilter_combined200_190", lowy, highy, OneDTwoD, startNJet, nJets, MuonNumber, FolderLabel, axis ))[0]; MCh_T1tttt->Scale(1./(630563/18524.5*10.)); cout<<whichplot <<"="<<MCh_T1tttt->Integral(1,100000) <<" 200, 190 " <<MCh_T1tttt->Integral(2,100000)<<endl; vh.push_back(MCh_T1tttt); } if( hasT2cc_NoFilter_combined200_180_ ){ vlenname.push_back("T2cc (200, 180)"); vhnames.push_back("T2cc_NoFilter_combined200_180"); vcolor.push_back(kBlue); vh_special.push_back(1); vh_linestype.push_back(1); TH1D *MCh_T1tttt= (getHists( MuAddOrNot, HTBins, whichpart, rebin, xAxisName, yAxisName, xAxisRange1, xAxisRange2, 2, whichplot, true, "SMS_Madgraph_T2cc_NoFilter_combined200_180", lowy, highy, OneDTwoD, startNJet, nJets, MuonNumber, FolderLabel, axis ))[0]; MCh_T1tttt->Scale(1./(629864/18524.5*10.)); vh.push_back(MCh_T1tttt); } if( hasT2cc_NoFilter_combined200_170_ ){ vlenname.push_back("T2cc (200, 170)"); vhnames.push_back("T2cc_NoFilter_combined200_170"); vcolor.push_back(kOrange-3); vh_special.push_back(1); vh_linestype.push_back(1); TH1D *MCh_T1tttt= (getHists( MuAddOrNot, HTBins, whichpart, rebin, xAxisName, yAxisName, xAxisRange1, xAxisRange2, 2, whichplot, true, "SMS_Madgraph_T2cc_NoFilter_combined200_170", lowy, highy, OneDTwoD, startNJet, nJets, MuonNumber, FolderLabel, axis ))[0]; MCh_T1tttt->Scale(1./(630069/18524.5*10.)); vh.push_back(MCh_T1tttt); } if( hasT2cc_NoFilter_combined200_160_ ){ vlenname.push_back("T2cc (200, 160)"); vhnames.push_back("T2cc_NoFilter_combined200_160"); vcolor.push_back(kMagenta); vh_special.push_back(1); vh_linestype.push_back(1); TH1D *MCh_T1tttt= (getHists( MuAddOrNot, HTBins, whichpart, rebin, xAxisName, yAxisName, xAxisRange1, xAxisRange2, 2, whichplot, true, "SMS_Madgraph_T2cc_NoFilter_combined200_160", lowy, highy, OneDTwoD, startNJet, nJets, MuonNumber, FolderLabel, axis ))[0]; MCh_T1tttt->Scale(1./(630313/18524.5*10.)); vh.push_back(MCh_T1tttt); } if( hasT2cc_NoFilter_combined200_140_ ){ vlenname.push_back("T2cc (200, 140)"); vhnames.push_back("T2cc_NoFilter_combined200_140"); vcolor.push_back(kCyan+1); vh_special.push_back(1); vh_linestype.push_back(1); TH1D *MCh_T1tttt= (getHists( MuAddOrNot, HTBins, whichpart, rebin, xAxisName, yAxisName, xAxisRange1, xAxisRange2, 2, whichplot, true, "SMS_Madgraph_T2cc_NoFilter_combined200_140", lowy, highy, OneDTwoD, startNJet, nJets, MuonNumber, FolderLabel, axis ))[0]; MCh_T1tttt->Scale(1./(568158/18524.5*10.)); vh.push_back(MCh_T1tttt); } if( hasT2cc_NoFilter_combined200_120_ ){ vlenname.push_back("T2cc (200, 120)"); vhnames.push_back("T2cc_NoFilter_combined200_120"); vcolor.push_back(kGreen+2); vh_special.push_back(1); vh_linestype.push_back(1); TH1D *MCh_T1tttt= (getHists( MuAddOrNot, HTBins, whichpart, rebin, xAxisName, yAxisName, xAxisRange1, xAxisRange2, 2, whichplot, true, "SMS_Madgraph_T2cc_NoFilter_combined200_120", lowy, highy, OneDTwoD, startNJet, nJets, MuonNumber, FolderLabel, axis ))[0]; MCh_T1tttt->Scale(1./(630587/18524.5*10.)); cout<<whichplot <<"="<<MCh_T1tttt->Integral(1,100000) <<" 200, 120 "<<MCh_T1tttt->Integral(2,100000)<<endl; vh.push_back(MCh_T1tttt); } if( hasT2cc_3jets_mStop_200_mLSP_190_ ){ vlenname.push_back("T2cc_3p (200, 190)"); vhnames.push_back("T2cc_3jets_mStop_200_mLSP_190"); vcolor.push_back(kRed); vh_special.push_back(1); vh_linestype.push_back(2); TH1D *MCh_T1tttt= (getHists( MuAddOrNot, HTBins, whichpart, rebin, xAxisName, yAxisName, xAxisRange1, xAxisRange2, 2, whichplot, true, "T2cc_3jets_mStop_200_mLSP_190", lowy, highy, OneDTwoD, startNJet, nJets, MuonNumber, FolderLabel, axis ))[0]; MCh_T1tttt->Scale(1./(714441/18524.5*10.)); vh.push_back(MCh_T1tttt); } if( hasT2cc_3jets_mStop_200_mLSP_120_ ){ vlenname.push_back("T2cc_3p (200, 120)"); vhnames.push_back("T2cc_3jets_mStop_200_mLSP_120"); vcolor.push_back(kGreen+2); vh_special.push_back(1); vh_linestype.push_back(2); TH1D *MCh_T1tttt= (getHists( MuAddOrNot, HTBins, whichpart, rebin, xAxisName, yAxisName, xAxisRange1, xAxisRange2, 2, whichplot, true, "T2cc_3jets_mStop_200_mLSP_120", lowy, highy, OneDTwoD, startNJet, nJets, MuonNumber, FolderLabel, axis ))[0]; MCh_T1tttt->Scale(1./(620669/18524.5*10.)); vh.push_back(MCh_T1tttt); } vector<TH1D*> svh=pf1d.SortHists(vh); vector<unsigned int> svh_index=pf1d.SortHists_index(vh); vector<TH1D*> invsvh=pf1d.invSortHists(vh); vector<unsigned int> invsvh_index=pf1d.invSortHists_index(vh); c1->cd(); TPad *pad1; if( plotRatio_ ){ pad1=new TPad("pad1","pad1",0,0.3,1,1); } else { pad1=new TPad("pad1","pad1",0,0,1,1); } pad1->Draw(); pad1->cd(); pad1->SetTopMargin(0.1); if( doCumulative_ ){ TH1D* svh0clone=(TH1D*)( svh[0]->Clone("svh0clone") ); TH1D *ih0=pf1d.CumulativeH( svh0clone, totalEV_ ); ih0->SetLineColor(0); ih0->SetMarkerColor(0); ih0->Draw(); ih0->GetXaxis()->SetLabelFont(63); ih0->GetXaxis()->SetLabelSize(18); ih0->GetYaxis()->SetLabelFont(63); ih0->GetYaxis()->SetLabelSize(18); ih0->GetXaxis()->SetTitleSize(0.06); ih0->GetYaxis()->SetTitleSize(0.06); ih0->SetMinimum(0.5); for( unsigned int i=0; i<svh.size(); i++ ){ TH1D *ih1=pf1d.CumulativeH( svh[i], totalEV_ ); ih1->Draw("same"); ih1->SetLineColor( vcolor[svh_index[i] ] ); ih1->SetMarkerColor( vcolor[svh_index[i] ] ); len->AddEntry(ih1,vlenname[ svh_index[i] ]); } } else { TH1D* svh0clone=(TH1D*)(svh[0]->Clone("svh0clone")); svh0clone->Scale(1.5); svh0clone->SetLineColor(0); svh0clone->SetMarkerColor(0); svh0clone->Draw(); svh0clone->GetXaxis()->SetLabelFont(63); svh0clone->GetXaxis()->SetLabelSize(34); svh0clone->GetXaxis()->SetLabelOffset(0.013); svh0clone->GetYaxis()->SetLabelFont(63); svh0clone->GetYaxis()->SetLabelSize(34); svh0clone->GetYaxis()->SetTitleOffset(1.4); svh0clone->GetXaxis()->SetTitleOffset(1.4); svh0clone->GetXaxis()->SetTitleSize(0.048); svh0clone->GetYaxis()->SetTitleSize(0.048); svh0clone->SetMinimum(0.5); if( !drawStack_ ){ for( unsigned int i=0; i<svh.size(); i++ ){ if( vhnames[ svh_index[i] ] == "Data"){ len->AddEntry(svh[i], "Data"); } } gStyle->SetPaintTextFormat(".0f"); // TString DrawOpt="same 9 text45"; TString DrawOpt="same 9 hist"; for( unsigned int i=0; i<svh.size(); i++ ){ svh[i]->SetLineWidth(4); if( vhnames[ svh_index[i] ] != "Data" && vhnames[ svh_index[i] ] != "MCtotal"){ svh[i]->Draw(DrawOpt); svh[i]->SetLineColor( vcolor[svh_index[i] ] ); // svh[i]->SetFillColor( vcolor[svh_index[i] ] ); svh[i]->SetMarkerColor( vcolor[svh_index[i] ] ); svh[i]->SetLineStyle( vh_linestype[ svh_index[i] ] ); } else if( vhnames[ svh_index[i] ] == "MCtotal" ){ svh[i]->SetLineColor(5); svh[i]->SetLineWidth(3); // svh[i]->SetFillColor(5); svh[i]->SetMarkerColor(5); svh[i]->Draw(DrawOpt); len->AddEntry(svh[i],vlenname[ svh_index[i] ]); } } } else if( drawStack_ ){ if( vh.size() > 0 && vhnames[0] == "Data"){ len->AddEntry(vh[0], "Data"); } THStack *hs=new THStack("hs",""); for( unsigned int i=0; i<invsvh.size(); i++ ){ if( vhnames[ invsvh_index[i] ] != "Data" && vhnames[ invsvh_index[i] ] != "MCtotal" ){ if( debug_ >= 2 ){ cout<<"sample: "<< vhnames[ invsvh_index[i] ]<<" number: "<<invsvh[i]->Integral(1,10000)<<endl; } if( !( vh_special[ invsvh_index[i] ] ) ){ invsvh[i]->SetLineColor( vcolor[ invsvh_index[i] ] ); invsvh[i]->SetFillColor( vcolor[ invsvh_index[i] ] ); invsvh[i]->SetLineStyle( vh_linestype[ invsvh_index[i] ] ); // invsvh[i]->SetFillStyle(3001); invsvh[i]->SetMarkerColor( vcolor[ invsvh_index[i] ] ); hs->Add(invsvh[i]); } } } if( hs ){ hs->Draw("HIST 9 same"); } for( unsigned int i=0; i<vh.size(); i++ ){ if( vhnames[ invsvh_index[i] ] != "Data" && vhnames[ invsvh_index[i] ] != "MCtotal" && vh_special[ invsvh_index[i] ] ){ invsvh[i]->SetLineColor( vcolor[ invsvh_index[i] ] ); invsvh[i]->SetMarkerColor( vcolor[ invsvh_index[i] ] ); invsvh[i]->SetLineWidth(6); invsvh[i]->Draw("HIST 9 same"); } } }//if( drawStack_ ) //Draw total MC error and data for( unsigned int i=0; i<vh.size(); i++ ){ if( vhnames[i]=="MCtotal"){ TH1D *mche=(TH1D*)(vh[i]->Clone("mche")); for( int ib=1; ib<=mche->GetNbinsX(); ib++ ){ mche->SetBinContent(ib, vh[i]->GetBinContent(ib) ); mche->SetBinError(ib, vh[i]->GetBinError(ib) ); } mche->SetFillColor(5); mche->SetFillStyle(3001); mche->SetLineColor(5); mche->SetLineWidth(2); mche->SetMarkerSize(0); mche->Draw("e2same"); } } for( unsigned int i=0; i<invsvh.size(); i++ ){ if( vhnames[ invsvh_index[i] ] == "Data" ){ invsvh[i]->Draw("same P 9"); invsvh[i]->SetLineColor(1); invsvh[i]->SetLineWidth(2); invsvh[i]->SetMarkerSize(1); invsvh[i]->SetMarkerStyle(20); invsvh[i]->SetMarkerColor(1); } } //Legend for( unsigned int i=0; i<vh.size(); i++ ){ if( vhnames[ svh_index[i] ] != "Data" && vhnames[ svh_index[i] ] != "MCtotal" ){ if( !( vh_special[ svh_index[i] ] ) ){ len->AddEntry(svh[i], vlenname[ svh_index[i] ]); } } } for( unsigned int i=0; i<vh.size(); i++ ){ if( vhnames[ svh_index[i] ] != "Data" && vhnames[ svh_index[i] ] != "MCtotal" ){ if( vh_special[ svh_index[i] ] ){ len->AddEntry(svh[i], vlenname[ svh_index[i] ]); } } } }//else comulative // TLegend *len1=new TLegend( 0.56, 0.70, 0.93, 0.90 ); // len1->AddEntry("", "CMS Preliminary 2012 8 TeV",""); // len1->AddEntry("", Form("#int L dt = %.2f fb^{-1}", mcscale_/10.),""); TLegend *len1=new TLegend( 0.20, 0.9, 0.65, 0.97 ); if( useCommonJson_ ){ len1->AddEntry("", Form("CMS Preliminary 2012 8 TeV, #int L dt = %.2f fb^{-1}", mcscale_/10.),""); } else { if( whichpart == 1 ){ len1->AddEntry("", Form("CMS Preliminary 2012 8 TeV, #int L dt = %.2f fb^{-1}", mcscale_HT_/10.),""); } else { if( MuonNumber == "OneMuon_"){ len1->AddEntry("", Form("CMS Preliminary 2012 8 TeV, #int L dt = %.2f fb^{-1}", mcscale_SingleMu_/10.),""); } else if( MuonNumber == "DiMuon_"){ len1->AddEntry("", Form("CMS Preliminary 2012 8 TeV, #int L dt = %.2f fb^{-1}", mcscale_DiMu_/10.),""); } else if( MuonNumber == "Photon_" ){ len1->AddEntry("", Form("CMS Preliminary 2012 8 TeV, #int L dt = %.2f fb^{-1}", mcscale_Photon_/10.),""); } } } len1->SetFillColor(0); len1->SetMargin(0.01); len1->SetLineColor(0); len1->SetBorderSize(0); len1->Draw(); len->Draw(); //Ratio plots if( plotRatio_ ){ c1->cd(); TPad *pad2=new TPad("pad2","pad2",0,0.03,1,0.3); pad2->SetGridy(); pad2->Draw(); pad2->cd(); if( useVariantRatioPlot_ && vh.size() > 1 ){ int ifirst_d=pf1d.getFirstBinHasContent(vh[0]); double firstbin=vh[0]->GetBinLowEdge( ifirst_d ); double x1=xAxisRange1; if( firstbin > xAxisRange1 ){ x1=firstbin; } vector<TH1D*> vratio=pf1d.getRatioPlot( vh[0], vh[1], xAxisRange1, xAxisRange2 ); TH1D *ratio_o=vratio[0]; TH1D *mc=vratio[1]; TH1D *ratio=vratio[2]; mc->SetFillColor(kGray+1); mc->SetFillStyle(3008); mc->SetLineColor(0); mc->SetMarkerSize(0); TH1D *mch11=(TH1D*)(ratio_o->Clone("mch11")); for( int ib=1; ib<=mch11->GetNbinsX(); ib++ ){ mch11->SetBinContent(ib, 1.); mch11->SetBinError(ib, 0.); } mch11->SetLineWidth(1); mch11->SetLineColor(1); mch11->SetMarkerSize(0); TF1* fit = new TF1("fit","pol0",x1, xAxisRange2); ratio->GetXaxis()->SetRangeUser(xAxisRange1, xAxisRange2); ratio->Draw(); ratio->SetLineColor(kWhite); ratio->SetMarkerColor(kWhite); ratio->Fit(fit,"Rsame"); ratio->GetXaxis()->SetLabelFont(63); ratio->GetXaxis()->SetLabelSize(18); ratio->GetXaxis()->SetTitleOffset(10); ratio->GetYaxis()->SetNdivisions(2,0,0,kFALSE); ratio->GetYaxis()->SetLabelFont(63); ratio->GetYaxis()->SetLabelSize(18); ratio->GetYaxis()->SetTitle("Data/MC"); ratio->GetYaxis()->SetTitleSize(0.15); ratio->GetYaxis()->SetTitleOffset(0.3); ratio->SetMarkerSize(0.5); ratio->GetYaxis()->SetRangeUser(0.,2.); mc->GetXaxis()->SetRangeUser(xAxisRange1, xAxisRange2); mch11->GetXaxis()->SetRangeUser(xAxisRange1, xAxisRange2); mc->Draw("e2same"); mch11->Draw("same L hist"); ratio_o->Draw("same"); TLegend *len2=new TLegend(0.6,0.8,0.95,0.9); len2->SetFillColor(0); len2->SetMargin(0.3); len2->SetLineColor(0); len2->SetBorderSize(0); len2->AddEntry("", Form("p0 = %.3f #pm %.4f", fit->GetParameter(0), fit->GetParError(0) ), "" ); len2->Draw(); } else { if( vh.size() > 1){ int ifirst_d=pf1d.getFirstBinHasContent(vh[0]); double firstbin=vh[0]->GetBinLowEdge( ifirst_d ); double x1=xAxisRange1; if( firstbin > xAxisRange1 ){ x1=firstbin; } TH1D* datah=(TH1D*)(vh[0]->Clone("datah")); TH1D* mch=(TH1D*)(vh[1]->Clone("mch")); datah->Divide(datah, mch); datah->GetXaxis()->SetLabelFont(63); datah->GetXaxis()->SetLabelSize(18); datah->GetXaxis()->SetTitleOffset(10); datah->GetYaxis()->SetNdivisions(2,0,0,kFALSE); datah->GetYaxis()->SetLabelFont(63); datah->GetYaxis()->SetLabelSize(18); datah->GetYaxis()->SetTitle("Data/MC"); // datah->GetYaxis()->SetTitle("t#bar{t}/t#bar{t}_MasiveBin"); datah->GetYaxis()->SetTitleSize(0.15); datah->GetYaxis()->SetTitleOffset(0.3); datah->SetMarkerSize(0.5); datah->GetYaxis()->SetRangeUser(0.,2.); TH1D *mch1=(TH1D*)(datah->Clone("mch1")); for( int ib=1; ib<=mch1->GetNbinsX(); ib++ ){ mch1->SetBinContent(ib, 1.); if(vh[1]->GetBinContent(ib) > 1E-2){ mch1->SetBinError(ib, vh[1]->GetBinError(ib)/vh[1]->GetBinContent(ib) ); } } mch1->SetFillColor(kGray+1); mch1->SetFillStyle(3008); mch1->SetLineColor(0); mch1->SetMarkerSize(0); TH1D *mch11=(TH1D*)(datah->Clone("mch11")); for( int ib=1; ib<=mch11->GetNbinsX(); ib++ ){ mch11->SetBinContent(ib, 1.); mch11->SetBinError(ib, 0.); } mch11->SetLineWidth(1); mch11->SetLineColor(1); mch11->SetMarkerSize(0); TH1D *datah1=(TH1D*)(datah->Clone("datah1")); for( int ib=1; ib<=datah1->GetNbinsX(); ib++ ){ datah1->SetBinContent(ib, datah->GetBinContent(ib)); double err=pf1d.getRatioErr( vh[0]->GetBinContent(ib), vh[0]->GetBinError(ib), vh[1]->GetBinContent(ib), vh[1]->GetBinError(ib) ); } TH1D *datah2=(TH1D*)(datah->Clone("datah2")); for( int ib=1; ib<=datah2->GetNbinsX(); ib++ ){ datah2->SetBinContent(ib, datah->GetBinContent(ib)); if( vh[0]->GetBinContent(ib) > 0 ){ datah2->SetBinError(ib, vh[0]->GetBinError(ib)/vh[0]->GetBinContent(ib)); } } TF1* fit = new TF1("fit","pol0",x1, xAxisRange2); datah1->Draw(); datah1->SetLineColor(kWhite); datah1->SetMarkerColor(kWhite); datah1->Fit(fit,"Rsame"); datah1->GetXaxis()->SetRangeUser(xAxisRange1, xAxisRange2); datah1->GetXaxis()->SetLabelFont(63); datah1->GetXaxis()->SetLabelSize(18); datah1->GetXaxis()->SetTitleOffset(10); datah1->GetYaxis()->SetNdivisions(2,0,0,kFALSE); datah1->GetYaxis()->SetLabelFont(63); datah1->GetYaxis()->SetLabelSize(18); datah1->GetYaxis()->SetTitle("Data/MC"); datah1->GetYaxis()->SetTitleSize(0.15); datah1->GetYaxis()->SetTitleOffset(0.3); datah1->SetMarkerSize(0.5); datah1->GetYaxis()->SetRangeUser(0.,2.); mch1->Draw("e2same"); mch11->Draw("same L hist"); datah2->Draw("same"); TLegend *len2=new TLegend(0.6,0.8,0.95,0.9); len2->SetFillColor(0); len2->SetMargin(0.3); len2->SetLineColor(0); len2->SetBorderSize(0); len2->AddEntry("", Form("p0 = %.3f #pm %.4f", fit->GetParameter(0), fit->GetParError(0) ), "" ); len2->Draw(); } // delete len2; } } TString stack=""; if ( doCumulative_ ){ stack="Cumu_"; } else { if(drawStack_){ stack="Stack_"; } } TString borj="j"; if( useBTag_ ){ borj = "b"; } TString sele=""; if( whichpart == 1 ){ sele="HadSele_"; } else if( whichpart == 2 && MuAddOrNot == true && normalEstimation_ == false ){ sele="MuonAdded_"; } else if( whichpart == 2 && MuAddOrNot == false && normalEstimation_ == false ){ sele="MuonNotAdded_"; } else if( whichpart == 2 && normalEstimation_ == true ){ sele="Muon_"; } else if( whichpart == 3 && normalEstimation_ == true ){ sele="Photo_"; } TString jetorder=""; if( highy == 1 ){ jetorder="1st"; } if( highy == 2 ){ jetorder="2nd"; } if( highy == 3 ){ jetorder="3rd"; } if( highy == 4 ){ jetorder="4th"; } pad1->SetLogy(0); pad1->RedrawAxis(); c1->SaveAs( Form( "%s"+whichplot+jetorder+"_%s%s_%s%s%iTo%i%s.%s", stack.Data(), sele.Data(), HTBins.Data(), MuonNumber.Data(), FolderLabel.Data(), startNJet-1, nJets+startNJet-2, borj.Data(), epspng_.Data() ) ); pad1->SetLogy(); pad1->RedrawAxis(); c1->SaveAs( Form( "%s"+whichplot+jetorder+"_%s%s_%s%s%iTo%i%s_log.%s", stack.Data(), sele.Data(), HTBins.Data(), MuonNumber.Data(), FolderLabel.Data(), startNJet-1, nJets+startNJet-2, borj.Data(), epspng_.Data() ) ); delete pad1; // delete pad2; delete c1; vlenname.clear(); vhnames.clear(); vh_special.clear(); vh.clear(); svh.clear(); delete len1; len->Clear(); closefV(); }
void DrawCalibrationPlotsEB( Char_t* infile1 = "/data1/rgerosa/L3_Weight/PromptSkim_Single_Double_Electron_recoFlag/EB/WZAnalysis_PromptSkim_W-DoubleElectron_FT_R_42_V21B_Z_noEP.root", Char_t* infile2 = "/data1/rgerosa/L3_Weight/PromptSkim_Single_Double_Electron_recoFlag/EB/Even_WZAnalysis_PromptSkim_W-DoubleElectron_FT_R_42_V21B_Z_noEP.root", Char_t* infile3 = "/data1/rgerosa/L3_Weight/PromptSkim_Single_Double_Electron_recoFlag/EB/Odd_WZAnalysis_PromptSkim_W-DoubleElectron_FT_R_42_V21B_Z_noEP.root", int evalStat = 0, Char_t* fileType = "png", Char_t* dirName = ".") { bool printPlots = false; // by TT int nbins = 500; // by xtal //int nbins = 500; // Set style options gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetOptTitle(0); gStyle->SetOptStat(1110); gStyle->SetOptFit(0); gStyle->SetFitFormat("6.3g"); gStyle->SetPalette(1); gStyle->SetTextFont(42); gStyle->SetTextSize(0.05); gStyle->SetTitleFont(42,"xyz"); gStyle->SetTitleSize(0.05); gStyle->SetLabelFont(42,"xyz"); gStyle->SetLabelSize(0.05); gStyle->SetTitleXOffset(0.8); gStyle->SetTitleYOffset(1.1); gROOT->ForceStyle(); if ( !infile1 ) { cout << " No input file specified !" << endl; return; } if ( evalStat && (!infile2 || !infile3 )){ cout << " No input files to evaluate statistical precision specified !" << endl; return; } cout << "Making calibration plots for: " << infile1 << endl; TFile *f = new TFile(infile1); TH2F *h_scale_EB = (TH2F*)f->Get("h_scale_EB"); TH2F *hcmap = (TH2F*) h_scale_EB->Clone("hcmap"); hcmap -> Reset("ICEMS"); // Mean over phi for (int iEta = 1 ; iEta < h_scale_EB->GetNbinsY()+1 ; iEta ++) { float SumIC = 0; int numIC = 0; for(int iPhi = 1 ; iPhi < h_scale_EB->GetNbinsX()+1 ; iPhi++) { if( h_scale_EB->GetBinContent(iPhi,iEta) !=0) { SumIC = SumIC + h_scale_EB->GetBinContent(iPhi,iEta); numIC ++ ; } } for (int iPhi = 1; iPhi< h_scale_EB->GetNbinsX()+1 ; iPhi++) { if(numIC!=0 && SumIC!=0) hcmap->SetBinContent(iPhi,iEta,h_scale_EB->GetBinContent(iPhi,iEta)/(SumIC/numIC)); } } //----------------------------------------------------------------- //--- Build the precision vs ieta plot starting from the TH2F of IC //----------------------------------------------------------------- TH1F *hoccall = new TH1F("hoccall", "hoccall", 1000,0.,1000.); for (int jbin = 1; jbin < h_occupancy-> GetNbinsY()+1; jbin++){ for (int ibin = 1; ibin < h_occupancy-> GetNbinsX()+1; ibin++){ float ic = h_occupancy->GetBinContent(ibin,jbin); hoccall->Fill(ic); } } TH1F *hspreadall = new TH1F("hspreadall", "hspreadall", 800,0.,2.); for (int jbin = 1; jbin < hcmap-> GetNbinsY()+1; jbin++){ for (int ibin = 1; ibin < hcmap-> GetNbinsX()+1; ibin++){ float ic = hcmap->GetBinContent(ibin,jbin); if (ic>0 && ic<2 && ic !=1) { hspreadall->Fill(ic); } } } TH1F *hspread[172]; char hname[100]; char htitle[100]; for (int jbin = 1; jbin < hcmap-> GetNbinsY()+1; jbin++){ //float etaring = hcmap-> GetYaxis()->GetBinLowEdge(jbin); float etaring = hcmap-> GetYaxis()->GetBinCenter(jbin); sprintf(hname,"hspread_ring_ieta%02d",etaring); hspread[jbin-1]= new TH1F(hname, hname, nbins/2,0.5,1.5); for (int ibin = 1; ibin < hcmap-> GetNbinsX()+1; ibin++){ float ic = hcmap->GetBinContent(ibin,jbin); if (ic>0 && ic<2 && ic!=1) { hspread[jbin-1]->Fill(ic); } } } TGraphErrors *sigma_vs_ieta = new TGraphErrors(); sigma_vs_ieta->SetMarkerStyle(20); sigma_vs_ieta->SetMarkerSize(1); sigma_vs_ieta->SetMarkerColor(kBlue+2); TGraphErrors *scale_vs_ieta = new TGraphErrors(); scale_vs_ieta->SetMarkerStyle(20); scale_vs_ieta->SetMarkerSize(1); scale_vs_ieta->SetMarkerColor(kBlue+2); TF1 *fgaus = new TF1("fgaus","gaus",-10,10); int np = 0; for (int i = 1; i < hcmap-> GetNbinsY()+1; i++){ float etaring = hcmap-> GetYaxis()->GetBinCenter(i); //float etaring = hcmap-> GetYaxis()->GetBinLowEdge(i); if (int(etaring)==0) continue; if (hspread[i-1]-> GetEntries() == 0) continue; if (fabs(etaring) > 60) hspread[i-1]->Rebin(2); float e = 0.5*hcmap-> GetYaxis()->GetBinWidth(i); fgaus->SetParameter(1,1); fgaus->SetParameter(2,hspread[i-1]->GetRMS()); fgaus->SetRange(1-5*hspread[i-1]->GetRMS(),1+5*hspread[i-1]->GetRMS()); hspread[i-1]->Fit("fgaus","QR"); sigma_vs_ieta-> SetPoint(np,etaring,fgaus->GetParameter(2)/fgaus->GetParameter(1)); //cout << etaring << " " << fgaus->GetParameter(2)/fgaus->GetParameter(1) << endl; sigma_vs_ieta-> SetPointError(np, e ,fgaus->GetParError(2)/fgaus->GetParameter(1)); scale_vs_ieta-> SetPoint(np,etaring,fgaus->GetParameter(1)); scale_vs_ieta-> SetPointError(np,e,fgaus->GetParError(1)); np++; } if (evalStat){ TFile *f2 = new TFile(infile2); TH2F *h_scale_EB_2 = (TH2F*)f2->Get("h_scale_EB"); TH2F *hcmap2 = (TH2F*) h_scale_EB->Clone("hcmap2"); hcmap2 -> Reset("ICEMS"); // Mean over phi for (int iEta = 1 ; iEta < h_scale_EB_2->GetNbinsY()+1 ; iEta ++) { float SumIC = 0; int numIC = 0; for(int iPhi = 1 ; iPhi < h_scale_EB_2->GetNbinsX()+1 ; iPhi++) { if( h_scale_EB_2->GetBinContent(iPhi,iEta) !=0) { SumIC = SumIC + h_scale_EB_2->GetBinContent(iPhi,iEta); numIC ++ ; } } for (int iPhi = 1; iPhi< h_scale_EB_2->GetNbinsX()+1 ; iPhi++) { if(numIC!=0 && SumIC!=0) hcmap2->SetBinContent(iPhi,iEta,h_scale_EB_2->GetBinContent(iPhi,iEta)/(SumIC/numIC)); } } TFile *f3 = new TFile(infile3); TH2F *h_scale_EB_3 = (TH2F*)f3->Get("h_scale_EB"); TH2F *hcmap3 = (TH2F*) h_scale_EB->Clone("hcmap3"); hcmap3 -> Reset("ICEMS"); // Mean over phi for (int iEta = 1 ; iEta < h_scale_EB_3->GetNbinsY()+1 ; iEta ++) { float SumIC = 0; int numIC = 0; for(int iPhi = 1 ; iPhi < h_scale_EB_3->GetNbinsX()+1 ; iPhi++) { if( h_scale_EB_3->GetBinContent(iPhi,iEta) !=0) { SumIC = SumIC + h_scale_EB_3->GetBinContent(iPhi,iEta); numIC ++ ; } } for (int iPhi = 1; iPhi< h_scale_EB_3->GetNbinsX()+1 ; iPhi++) { if(numIC!=0 && SumIC!=0) hcmap3->SetBinContent(iPhi,iEta,h_scale_EB_3->GetBinContent(iPhi,iEta)/(SumIC/numIC)); } } TH1F *hstatprecision[171]; for (int jbin = 1; jbin < hcmap2-> GetNbinsY()+1; jbin++){ //int etaring = -85+(jbin-1); float etaring = hcmap2-> GetYaxis()->GetBinCenter(jbin); sprintf(hname,"hstatprecision_ring_ieta%02d",etaring); hstatprecision[jbin-1] = new TH1F(hname, hname, nbins,-0.5,0.5); for (int ibin = 1; ibin < hcmap2-> GetNbinsX()+1; ibin++){ float ic1 = hcmap2->GetBinContent(ibin,jbin); float ic2 = hcmap3->GetBinContent(ibin,jbin); if (ic1>0 && ic1<2 && ic1!=1 && ic2>0 && ic2 <2 && ic2!=1){ hstatprecision[jbin-1]->Fill((ic1-ic2)/(ic1+ic2)); // sigma (diff/sum) gives the stat. precision on teh entire sample } } } TGraphErrors *statprecision_vs_ieta = new TGraphErrors(); statprecision_vs_ieta->SetMarkerStyle(20); statprecision_vs_ieta->SetMarkerSize(1); statprecision_vs_ieta->SetMarkerColor(kRed+2); int n = 0; for (int i = 1; i < hcmap2-> GetNbinsY()+1; i++){ etaring = hcmap2-> GetYaxis()->GetBinCenter(i); //etaring = hcmap2-> GetYaxis()->GetBinLowEdge(i); if (etaring==0) continue; if ( hstatprecision[i-1]->GetEntries() == 0) continue; if (fabs(etaring) > 60)hstatprecision[i-1]->Rebin(2); float e = 0.5*hcmap2-> GetYaxis()->GetBinWidth(i); fgaus->SetParameter(1,1); fgaus->SetParameter(2,hstatprecision[i-1]->GetRMS()); fgaus->SetRange(-5*hstatprecision[i-1]->GetRMS(),5*hstatprecision[i-1]->GetRMS()); hstatprecision[i-1]->Fit("fgaus","QR"); statprecision_vs_ieta-> SetPoint(n,etaring,fgaus->GetParameter(2)); statprecision_vs_ieta-> SetPointError(n,e,fgaus->GetParError(2)); n++; } TGraphErrors *residual_vs_ieta = new TGraphErrors(); residual_vs_ieta->SetMarkerStyle(20); residual_vs_ieta->SetMarkerSize(1); residual_vs_ieta->SetMarkerColor(kGreen+2); for (int i= 0; i < statprecision_vs_ieta-> GetN(); i++){ double spread, espread; double stat, estat; double residual, eresidual; double xdummy,ex; sigma_vs_ieta-> GetPoint(i, xdummy, spread ); espread = sigma_vs_ieta-> GetErrorY(i); statprecision_vs_ieta-> GetPoint(i, xdummy, stat ); estat = statprecision_vs_ieta-> GetErrorY(i); ex = statprecision_vs_ieta-> GetErrorX(i); if (spread > stat ){ residual = sqrt( spread*spread - stat*stat ); eresidual = sqrt( pow(spread*espread,2) + pow(stat*estat,2))/residual; } else { residual = 0; eresidual = 0; } cout << residual << " " << eresidual << endl; residual_vs_ieta->SetPoint(i,xdummy, residual); residual_vs_ieta->SetPointError(i,ex,eresidual); } } //------------------------------------------------------------------------ //----------------------------------------------------------------- //--- Draw plots //----------------------------------------------------------------- TCanvas *c[10]; // --- plot 0 : map of coefficients c[0] = new TCanvas("cmap","cmap"); c[0] -> cd(); c[0]->SetLeftMargin(0.1); c[0]->SetRightMargin(0.13); c[0]->SetGridx(); hcmap->GetXaxis()->SetNdivisions(1020); hcmap->GetXaxis() -> SetLabelSize(0.03); hcmap->Draw("COLZ"); hcmap->GetXaxis() ->SetTitle("i#phi"); hcmap->GetYaxis() ->SetTitle("i#eta"); hcmap->GetZaxis() ->SetRangeUser(0.9,1.1); c[7] = new TCanvas("cmap2","cmap2"); c[7] -> cd(); c[7]->SetLeftMargin(0.1); c[7]->SetRightMargin(0.13); c[7]->SetGridx(); h_scale_EB->GetXaxis()->SetNdivisions(1020); h_scale_EB->GetXaxis() -> SetLabelSize(0.03); h_scale_EB->Draw("COLZ"); h_scale_EB->GetXaxis() ->SetTitle("i#phi"); h_scale_EB->GetYaxis() ->SetTitle("i#eta"); h_scale_EB->GetZaxis() ->SetRangeUser(0.9,1.1); // --- plot 1 : ring precision vs ieta c[1] = new TCanvas("csigma","csigma"); c[1]->SetGridx(); c[1]->SetGridy(); sigma_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(0.00,0.10); sigma_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); sigma_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("#sigma_{c}"); sigma_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); sigma_vs_ieta->Draw("ap"); if (evalStat){ statprecision_vs_ieta->Draw("psame"); sigma_vs_ieta->Draw("psame"); TLegend * leg = new TLegend(0.6,0.7,0.89, 0.89); leg->SetFillColor(0); leg->AddEntry(statprecision_vs_ieta,"statistical precision", "LP"); leg->AddEntry(sigma_vs_ieta,"spread", "LP"); leg->Draw("same"); } // --- plot 2 : scale vs ieta c[2] = new TCanvas("c_scale_vs_ieta","c_scale_vs_ieta"); c[2]->SetGridx(); c[2]->SetGridy(); scale_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(0.95,1.05); scale_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); scale_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("scale"); scale_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); scale_vs_ieta->Draw("ap"); // --- plot 3 : spread all coefficients c[3] = new TCanvas("cspread","cspread",500,500); hspreadall->SetFillStyle(3004); hspreadall->SetFillColor(kGreen+2); hspreadall->GetXaxis()-> SetRangeUser(0.8,1.2); hspreadall->GetXaxis()-> SetTitle("c"); hspreadall->Draw("hs"); gPad->Update(); TPaveStats *s_spread = (TPaveStats*)(hspreadall->GetListOfFunctions()->FindObject("stats")); s_spread -> SetX1NDC(0.55); //new x start position s_spread -> SetX2NDC(0.85); //new x end position s_spread -> SetY1NDC(0.750); //new x start position s_spread -> SetY2NDC(0.85); //new x end position s_spread -> SetOptStat(1110); s_spread -> SetTextColor(kGreen+2); s_spread -> SetTextSize(0.03); s_spread -> Draw("sames"); //--- plot 4 : occupancy map c[4] = new TCanvas("cOcc","cOcc"); c[4]->SetLeftMargin(0.1); c[4]->SetRightMargin(0.13); c[4]-> cd(); c[4]->SetGridx(); h_occupancy->GetXaxis()->SetNdivisions(1020); h_occupancy->GetXaxis() -> SetLabelSize(0.03); h_occupancy->Draw("COLZ"); h_occupancy->GetXaxis() ->SetTitle("i#phi"); h_occupancy->GetYaxis() ->SetTitle("i#eta"); // --- plot 5 : statistical precision vs ieta if (evalStat){ c[5] = new TCanvas("cstat","cstat"); c[5]->SetGridx(); c[5]->SetGridy(); statprecision_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(0.0001,0.10); statprecision_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); statprecision_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("#sigma((c_{P}-c_{D})/(c_{P}+c_{D}))"); statprecision_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); statprecision_vs_ieta->Draw("ap"); // TF1 *fp = new TF1("fp","pol0"); // fp->SetRange(-40,40); // statprecision_vs_ieta->Fit("fp","QRN"); // float stat = fp->GetParameter(0); // float estat = fp->GetParError(0); // cout << "Statistical precision in |ieta| < 40 --> " << stat << " +/- " << estat << endl; // sigma_vs_ieta->Fit("fp","QRN"); // float spread = fp->GetParameter(0); // float espread = fp->GetParError(0); // cout << "Spread in |ieta| < 40 --> " << spread << " +/- " << espread << endl; // float residual = sqrt( spread*spread - stat*stat ); // float eresidual = sqrt( pow(spread*espread,2) + pow(stat*estat,2))/residual; // cout << "Residual miscalibration : " << residual << " +/- " << eresidual << endl; c[6] = new TCanvas("cresidual","cresidual"); c[6]->SetGridx(); c[6]->SetGridy(); residual_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(0.0001,0.05); residual_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); residual_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("residual spread"); residual_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); residual_vs_ieta->Draw("ap"); } //----------------------------------------------------------------- //--- Print plots //----------------------------------------------------------------- if (printPlots){ //gStyle->SetOptStat(1110); c[0]->Print("IC_map.png",fileType); c[1]->Print("IC_precision_vs_ieta.png",fileType); c[2]->Print("IC_scale_vs_ieta.png",fileType); c[3]->Print("IC_spread.png",fileType); c[4]->Print("occupancy_map.png",fileType); } }
//--------------------------------------------------------------------------- //function to plot res vs. energy for pions (uses current dir, etc. settings) //qty: 0 = response, 1 = resolution, 2 = sampling factor TGraphErrors* g4_plot_res(int snum, int qty, bool do_pion, bool use_f_pion, bool do_fit, bool do_show, bool do_print=false){ Sample* sp = sample_map[snum]; if(!sp) { std::cout << "Sample " << snum << " is not loaded." << std::endl; return 0; } //store values from get_res Double_t* vals = new Double_t[maxHDe]; //sigma or mean Double_t* xvals = new Double_t[maxHDe]; //sigma or mean Double_t* y_errors = new Double_t[maxHDe]; //errors on pars Double_t* logxvals = new Double_t[maxHDe]; //sigma or mean //for storage of output info energyRes* res_temp; for (int i = 0; i < maxHDe; i++){ double energy = energies[i]; Double_t v, ve; if(qty==2){ //get sampling factor for energy without setting value std::pair<Double_t,Double_t> f_temp = g4_sample(snum,energy,do_pion,0); v = f_temp.first; ve = f_temp.second; } else { res_temp = get_res(snum,energy,do_pion,use_f_pion,do_fit,0,0,1); Double_t m, me, s, se; if(do_fit){ TF1* fit = res_temp->getFit(); m = fit->GetParameter(1); me = fit->GetParError(1); s = fit->GetParameter(2); se = fit->GetParError(2); } else{ m = res_temp->getStat(1); me = res_temp->getStatErr(1); s = res_temp->getStat(2); se = res_temp->getStatErr(2); } if(qty==1){ v = s/m; ve = v*sqrt(se*se/(s*s)+me*me/(m*m)); } else if(qty==0){ v = m/energy; ve = me/energy; } } xvals[i] = energy; logxvals[i] = log(energy); vals[i] = v; y_errors[i] = ve; } TCanvas* can; TPaveText* pave; TGraphErrors* val_graph; TGraphErrors* fit_graph; Int_t col, mrk; col = kBlue; mrk = 21; //graph values std::string qtyaxes[] = {"Response (#mu/E_{true})","Resolution (#sigma/#mu)","sampling factor"}; if(do_pion) qtyaxes[0] = sp->name_rat + " #pi^{-} Response (R_{cal}/E_{gen})"; else qtyaxes[0] = sp->name_rat + " e^{-} Response (R_{cal}/E_{gen})"; fit_graph = new TGraphErrors(maxHDe,logxvals,vals,0,y_errors); val_graph = new TGraphErrors(maxHDe,xvals,vals,0,y_errors); val_graph->GetXaxis()->SetTitle("Energy [GeV]"); val_graph->GetYaxis()->SetTitle(qtyaxes[qty].c_str()); val_graph->SetTitle(""); val_graph->SetMarkerStyle(mrk); val_graph->SetMarkerColor(col); val_graph->SetMarkerSize(1.5); val_graph->SetLineColor(col); val_graph->SetFillColor(0); //fit response for e/pi from pions TF1* gfit = 0; TF1* gline = 0; double c, ce, k, ke; std::stringstream epiname, ehname, kname; if(qty==0 && do_pion){ gfit = new TF1("epi_fit","pol1",fit_graph->GetXaxis()->GetXmin(),fit_graph->GetXaxis()->GetXmax()); //gfit = new TF1("epi_fit","(1+([0]-1)*([1]*x))/[0]",val_graph->GetXaxis()->GetXmin(),val_graph->GetXaxis()->GetXmax()); //gfit = new TF1("epi","(1+([0]-1)*([1]*x^[2]))/[0]",val_graph->GetXaxis()->GetXmin(),val_graph->GetXaxis()->GetXmax()); gfit->SetParameter(0,0.9); gfit->SetParameter(1,0.01); //gfit->SetParameter(2,-2.8); fit_graph->Fit(gfit,"NR"); //results double a, ae, b, be; a = gfit->GetParameter(0); ae = gfit->GetParError(0); b = gfit->GetParameter(1); be = gfit->GetParError(1); //transform to desired params c = 1./a; ce = ae/(a*a); k = b/(1.-a); ke = sqrt(pow(be/(1.-a),2) + pow(ae*b/pow(1-a,2),2)); std::cout.precision(2); std::cout << "e/h = " << c << " +/- " << ce << ", k = " << k << " +/- " << ke << std::endl; //store params in sample sp->eh = c; sp->eh_err = ce; sp->k = k; sp->k_err = ke; epiname.precision(2); epiname << "#frac{R}{E} = #frac{#pi}{e}(E) = #frac{1 + (e/h - 1) #upoint k ln(E)}{e/h}"; ehname.precision(2); ehname << "e/h = " << c << " #pm " << ce; kname.precision(2); kname << "k = " << k << " #pm " << ke; //line for E instead of log(E) gline = new TF1("epi","(1+([0]-1)*([1]*log(x)))/[0]",val_graph->GetXaxis()->GetXmin(),val_graph->GetXaxis()->GetXmax()); gline->SetParameter(0,c); gline->SetParameter(1,k); //formatting gline->SetLineColor(kRed); gline->SetMarkerColor(kRed); gline->SetLineWidth(2); } if(do_show){ std::string cname; cname = "res"; can = new TCanvas(cname.c_str(),cname.c_str(),700,500); can->cd(); //can->SetLogx(); //if(qty) val_graph->GetYaxis()->SetRangeUser(0,0.4); //else val_graph->GetYaxis()->SetRangeUser(0,1.1); val_graph->Draw("APZ"); //legend, pave coords double y1; if(qty) y1 = 0.5; else y1 = 0.2; std::string pavename = sp->name; if(do_pion) pavename += " #pi^{-}"; else pavename += " e^{-}"; pave = new TPaveText(0.5,y1,0.95,y1+0.2,"NDC"); if(qty==0 && do_pion){ pave->AddText((epiname.str()).c_str()); pave->AddText((ehname.str()).c_str()); pave->AddText((kname.str()).c_str()); } else{ pave->AddText(pavename.c_str()); } pave->SetFillColor(0); pave->SetBorderSize(0); pave->SetTextFont(42); pave->SetTextSize(0.05); pave->Draw("same"); if(gline) gline->Draw("same"); if(do_print){ std::string fpre = sp->fpre; if(do_pion) fpre += "_pion"; else fpre += "_elec"; //names std::string ofit; if(do_fit) ofit = "fit"; else ofit = "nofit"; std::string qtyname[] = {"mu","sigma","sam"}; std::stringstream oname; oname << pdir << "/" << fpre; if(use_f_pion) oname << "_fpion"; oname << "_" << qtyname[qty] << "_" << ofit; oname << "." << pformat; can->Print((oname.str()).c_str(),pformat.c_str()); } } return val_graph; }
void getX0() { gROOT->Reset(); gROOT->LoadMacro("fitfun.C"); // fit function for localY, local Z const Int_t N = 120; const Int_t M = 7; // number of module angle groups //histograms to check the par2 and par3 distributions TH1D *hPar2 = new TH1D("Par2","",500,0., 5.); TH1D *hPar3 = new TH1D("Par3","",500,0., 1.); Double_t a[M] = {0., 16., 20., 22., 26., 30., 32.}; TH2D *zLocal2D[M]; TH1D *zLocal[N][M]; TFile *fin = new TFile("align.root"); for(int j=0;j<M;j++) { char inhis[100]; sprintf(inhis,"zLocal_%d",j); zLocal2D[j] = (TH2D *)fin->Get(inhis); zLocal2D[j]->RebinY(5); for(int i=0;i<N;i++) { char hisname[100]; sprintf(hisname,"Tray_%d_A_%d",i+1,j); zLocal[i][j] = zLocal2D[j]->ProjectionY(hisname,i+1,i+1); zLocal[i][j]->Sumw2(); } } TF1 *fitfun = new TF1("fitfun",fitfun,-6.,6.,5); double t[N]; double z0[N][M], ze[N][M]; gStyle->SetOptStat(101); gStyle->SetOptFit(100); gStyle->SetTextSize(0.06); gStyle->SetTextFont(42); TCanvas *c1 = new TCanvas("c1","c1",0,0,800,600); c1->SetFillColor(10); c1->SetBorderMode(0); c1->SetBorderSize(2); c1->Divide(4,3); TPostScript *ps = new TPostScript("fig/xLocalFit.ps",112); for(int j=0;j<M;j++) { for(int i=0;i<N;i++) { t[i] = i+1; // tray number if(i%12==0) ps->NewPage(); // 12 trays per page c1->cd(i%12+1); double par[5], err[5]; fitfun->SetParameters(0., zLocal[i][j]->GetBinContent(50), 0.1, 1., 0.); fitfun->SetLineWidth(2); zLocal[i][j]->Draw("e"); double entries = zLocal[i][j]->Integral(1,100); if(entries>10) { fitfun->SetParLimits(0, -3., 3.); fitfun->SetParLimits(2, 2.9, 3.1); fitfun->SetParLimits(3, 0.01, 0.16); zLocal[i][j]->Fit("fitfun","R"); fitfun->GetParameters(&par[0]); err[0] = fitfun->GetParError(0); } else { par[0] = 0.; err[0] = 0.; } hPar2->Fill(par[2]); hPar3->Fill(par[3]); char text[100]; sprintf(text, "Z0 = %5.3f #pm %5.3f", par[0], err[0]); TLatex *tex = new TLatex(-3, par[1]/3., text); tex->SetTextSize(0.07); tex->SetTextFont(12); tex->Draw("same"); z0[i][j] = par[0]; ze[i][j] = err[0]; c1->Update(); } } gStyle->SetOptStat(0); gStyle->SetOptFit(0); gStyle->SetEndErrorSize(0.01); TF1 *fitangle = new TF1("fitangle","[0]*sin(x*3.14159/180.)+[1]",-10.,40.); double z00[N], ze0[N]; // angle=0 modules zOffset double z0F[N], zeF[N]; // angle=0 modules zOffset after fitangle fit double x0[N], xe[N]; for(int i=0;i<N;i++) { if(i%12==0) ps->NewPage(); // 12 trays per page c1->cd(i%12+1); z00[i] = z0[i][0]; ze0[i] = ze[i][0]; double x1 = -10.; double x2 = 50.; double y1 = -2.5; double y2 = 1.5; char title[100]; sprintf(title,"Tray_%d",i+1); TH1D *h0 = new TH1D("h0",title,1, x1, x2); h0->SetMinimum(y1); h0->SetMaximum(y2); h0->GetXaxis()->SetNdivisions(208); h0->GetXaxis()->CenterTitle(); h0->GetXaxis()->SetTitle("Module Angle (deg)"); h0->GetXaxis()->SetTitleOffset(1.0); h0->GetXaxis()->SetTitleSize(0.07); h0->GetXaxis()->SetLabelOffset(0.01); h0->GetXaxis()->SetLabelSize(0.045); h0->GetXaxis()->SetLabelFont(42); h0->GetXaxis()->SetTitleFont(42); h0->GetYaxis()->SetNdivisions(210); h0->GetYaxis()->SetTitle("zLocal Offset"); h0->GetYaxis()->SetTitleOffset(1.0); h0->GetYaxis()->SetTitleSize(0.07); h0->GetYaxis()->SetLabelOffset(0.01); h0->GetYaxis()->SetLabelSize(0.045); h0->GetYaxis()->SetLabelFont(42); h0->GetYaxis()->SetTitleFont(42); h0->Draw(); TGraphErrors *gr = new TGraphErrors(M, a, z0[i], 0, ze[i]); gr->SetMarkerStyle(24); gr->SetMarkerSize(1.5); gr->SetLineWidth(2); gr->Draw("p"); fitangle->SetParameters(-0.5, 0.0); gr->Fit("fitangle","R"); x0[i] = fitangle->GetParameter(0); z0F[i] = fitangle->GetParameter(1); xe[i] = fitangle->GetParError(0); zeF[i] = fitangle->GetParError(1); c1->Update(); } ps->NewPage(); gStyle->SetOptStat(0); gStyle->SetOptFit(0); gStyle->SetEndErrorSize(0.01); TCanvas *c1 = new TCanvas("c1","c1",0,0,800,600); c1->SetFillColor(10); c1->SetBorderMode(0); c1->SetBorderSize(2); c1->SetLeftMargin(0.14); c1->SetBottomMargin(0.15); c1->SetTopMargin(0.02); c1->SetRightMargin(0.04); c1->Draw(); double x1 = 0.5; double x2 = 120.5; double y1 = -3.; double y2 = 1.; TH1D *h0 = new TH1D("h0","",1, x1, x2); h0->SetMinimum(y1); h0->SetMaximum(y2); h0->GetXaxis()->SetNdivisions(208); h0->GetXaxis()->CenterTitle(); h0->GetXaxis()->SetTitle("Tray #"); h0->GetXaxis()->SetTitleOffset(1.0); h0->GetXaxis()->SetTitleSize(0.07); h0->GetXaxis()->SetLabelOffset(0.01); h0->GetXaxis()->SetLabelSize(0.05); h0->GetXaxis()->SetLabelFont(42); h0->GetXaxis()->SetTitleFont(42); h0->GetYaxis()->SetNdivisions(210); h0->GetYaxis()->SetTitle("zLocal Offset"); h0->GetYaxis()->SetTitleOffset(1.0); h0->GetYaxis()->SetTitleSize(0.07); h0->GetYaxis()->SetLabelOffset(0.01); h0->GetYaxis()->SetLabelSize(0.045); h0->GetYaxis()->SetLabelFont(42); h0->GetYaxis()->SetTitleFont(42); h0->Draw(); TLine *l1 = new TLine(x1,y1,x2,y1); l1->SetLineWidth(3); l1->Draw("same"); TLine *l2 = new TLine(x1,y2,x2,y2); l2->SetLineWidth(3); l2->Draw("same"); TLine *l3 = new TLine(x1,y1,x1,y2); l3->SetLineWidth(3); l3->Draw("same"); TLine *l4 = new TLine(x2,y1,x2,y2); l4->SetLineWidth(3); l4->Draw("same"); TGraphErrors *gr = new TGraphErrors(N, t, z00, 0, ze0); gr->SetMarkerStyle(20); gr->SetMarkerSize(1.5); gr->SetLineWidth(2); gr->Draw("p"); TGraphErrors *gr = new TGraphErrors(N, t, z0F, 0, zeF); gr->SetMarkerStyle(24); gr->SetMarkerSize(1.5); gr->SetLineWidth(2); gr->Draw("p"); c1->Update(); ps->NewPage(); gStyle->SetOptStat(0); gStyle->SetOptFit(0); gStyle->SetEndErrorSize(0.01); TCanvas *c1 = new TCanvas("c1","c1",0,0,800,600); c1->SetFillColor(10); c1->SetBorderMode(0); c1->SetBorderSize(2); c1->SetLeftMargin(0.14); c1->SetBottomMargin(0.15); c1->SetTopMargin(0.02); c1->SetRightMargin(0.04); c1->Draw(); double x1 = 0.5; double x2 = 120.5; double y1 = -2.; double y2 = 3.; TH1D *h0 = new TH1D("h0","",1, x1, x2); h0->SetMinimum(y1); h0->SetMaximum(y2); h0->GetXaxis()->SetNdivisions(208); h0->GetXaxis()->CenterTitle(); h0->GetXaxis()->SetTitle("Tray #"); h0->GetXaxis()->SetTitleOffset(1.0); h0->GetXaxis()->SetTitleSize(0.07); h0->GetXaxis()->SetLabelOffset(0.01); h0->GetXaxis()->SetLabelSize(0.05); h0->GetXaxis()->SetLabelFont(42); h0->GetXaxis()->SetTitleFont(42); h0->GetYaxis()->SetNdivisions(210); h0->GetYaxis()->SetTitle("xLocal Offset"); h0->GetYaxis()->SetTitleOffset(1.0); h0->GetYaxis()->SetTitleSize(0.07); h0->GetYaxis()->SetLabelOffset(0.01); h0->GetYaxis()->SetLabelSize(0.045); h0->GetYaxis()->SetLabelFont(42); h0->GetYaxis()->SetTitleFont(42); h0->Draw(); TLine *l1 = new TLine(x1,y1,x2,y1); l1->SetLineWidth(3); l1->Draw("same"); TLine *l2 = new TLine(x1,y2,x2,y2); l2->SetLineWidth(3); l2->Draw("same"); TLine *l3 = new TLine(x1,y1,x1,y2); l3->SetLineWidth(3); l3->Draw("same"); TLine *l4 = new TLine(x2,y1,x2,y2); l4->SetLineWidth(3); l4->Draw("same"); TGraphErrors *gr = new TGraphErrors(N, t, x0, 0, xe); gr->SetMarkerStyle(20); gr->SetMarkerSize(1.5); gr->SetLineWidth(2); gr->Draw("p"); c1->Update(); ps->Close(); ofstream outData; outData.open("xOffset.dat"); for(int i=0;i<N;i++) { outData << setw(15) << z00[i] << setw(15) << ze0[i] << setw(15) << x0[i] << setw(15) << xe[i] << endl; } outData.close(); TFile *fout = new TFile("xFitPar.root","recreate"); hPar2->Write(); hPar3->Write(); fout->Close(); }
// Soft radiation corrections for L3Res void softrad(double etamin=0.0, double etamax=1.3, bool dodijet=false) { setTDRStyle(); writeExtraText = false; // for JEC paper CWR TDirectory *curdir = gDirectory; // Open jecdata.root produced by reprocess.C TFile *fin = new TFile("rootfiles/jecdata.root","UPDATE"); assert(fin && !fin->IsZombie()); const int ntypes = 3; const char* types[ntypes] = {"data", "mc", "ratio"}; const int nmethods = 2; const char* methods[nmethods] = {"mpfchs1", "ptchs"}; const int nsamples = (dodijet ? 4 : 3); const char* samples[4] = {"gamjet", "zeejet", "zmmjet", "dijet"}; string sbin = Form("eta%02.0f-%02.0f",10*etamin,10*etamax); const char* bin = sbin.c_str(); const int nalphas = 4; const int alphas[nalphas] = {30, 20, 15, 10}; // Z+jet bins const double ptbins1[] = {30, 40, 50, 60, 75, 95, 125, 180, 300, 1000}; const int npt1 = sizeof(ptbins1)/sizeof(ptbins1[0])-1; TH1D *hpt1 = new TH1D("hpt1","",npt1,&ptbins1[0]); TProfile *ppt1 = new TProfile("ppt1","",npt1,&ptbins1[0]); // gamma+jet bins const double ptbins2[] = {30, 40, 50, 60, 75, 100, 125, 155, 180, 210, 250, 300, 350, 400, 500, 600, 800}; const int npt2 = sizeof(ptbins2)/sizeof(ptbins2[0])-1; TH1D *hpt2 = new TH1D("hpt2","",npt2,&ptbins2[0]); TProfile *ppt2 = new TProfile("ppt2","",npt2,&ptbins2[0]); // dijet bins const double ptbins4[] = {20, 62, 107, 175, 242, 310, 379, 467, 628, 839, 1121, 1497, 2000}; const int npt4 = sizeof(ptbins4)/sizeof(ptbins4[0])-1; TH1D *hpt4 = new TH1D("hpt4","",npt4,&ptbins4[0]); TProfile *ppt4 = new TProfile("ppt4","",npt4,&ptbins4[0]); TLatex *tex = new TLatex(); tex->SetNDC(); tex->SetTextSize(0.045); map<string,const char*> texlabel; texlabel["gamjet"] = "#gamma+jet"; texlabel["zeejet"] = "Z#rightarrowee+jet"; texlabel["zmmjet"] = "Z#rightarrow#mu#mu+jet"; texlabel["dijet"] = "Dijet"; texlabel["ptchs"] = "p_{T} balance (CHS)"; texlabel["mpfchs"] = "MPF raw (CHS)"; texlabel["mpfchs1"] = "MPF type-I (CHS)"; // overlay of various alpha values TCanvas *c1 = new TCanvas("c1","c1",ntypes*400,nmethods*400); c1->Divide(ntypes,nmethods); TH1D *h1 = new TH1D("h1",";p_{T} (GeV);Response",1270,30,1300); // extrapolation vs alpha for each pT bin vector<TCanvas*> c2s(ntypes*nmethods); for (unsigned int icanvas = 0; icanvas != c2s.size(); ++icanvas) { TCanvas *c2 = new TCanvas(Form("c2_%d",icanvas),Form("c2_%d",icanvas), 1200,1200); c2->Divide(3,3); c2s[icanvas] = c2; } TH1D *h2 = new TH1D("h2",";#alpha;Response",10,0.,0.4); h2->SetMaximum(1.08); h2->SetMinimum(0.88); // krad corrections TCanvas *c3 = new TCanvas("c3","c3",ntypes*400,nmethods*400); c3->Divide(ntypes,nmethods); TH1D *h3 = new TH1D("h3",";p_{T,ref} (GeV);FSR sensitivity: -dR/d#alpha [%]", 1270,30,1300); cout << "Reading in data" << endl << flush; // Read in plots vs pT (and alpha) map<string, map<string, map<string, map<int, TGraphErrors*> > > > gemap; map<string, map<string, map<string, map<int, TGraphErrors*> > > > gamap; for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { for (int isample = 0; isample != nsamples; ++isample) { for (int ialpha = 0; ialpha != nalphas; ++ialpha) { fin->cd(); assert(gDirectory->cd(types[itype])); assert(gDirectory->cd(bin)); TDirectory *d = gDirectory; const char *ct = types[itype]; const char *cm = methods[imethod]; const char *cs = samples[isample]; const int a = alphas[ialpha]; // Get graph made vs pT string s = Form("%s/%s/%s_%s_a%d",types[itype],bin,cm,cs,a); TGraphErrors *g = (TGraphErrors*)fin->Get(s.c_str()); if (!g) cout << "Missing " << s << endl << flush; assert(g); // Clean out empty points // as well as trigger-biased ones for dijets // as well as weird gamma+jet high pT point for (int i = g->GetN()-1; i != -1; --i) { if (g->GetY()[i]==0 || g->GetEY()[i]==0 || (string(cs)=="dijet" && g->GetX()[i]<70.) || (string(cs)=="gamjet" && g->GetX()[i]>600. && etamin!=0)) g->RemovePoint(i); } gemap[ct][cm][cs][a] = g; // Sort points into new graphs vs alpha TH1D *hpt = (isample==0 ? hpt2 : hpt1); TProfile *ppt = (isample==0 ? ppt2 : ppt1); if (isample==3) { hpt = hpt4; ppt = ppt4; } // pas-v6 for (int i = 0; i != g->GetN(); ++i) { double pt = g->GetX()[i]; ppt->Fill(pt, pt); int ipt = int(hpt->GetBinLowEdge(hpt->FindBin(pt))+0.5); //int ipt = int(pt+0.5); TGraphErrors *ga = gamap[ct][cm][cs][ipt]; if (!ga) { ga = new TGraphErrors(0); ga->SetMarkerStyle(g->GetMarkerStyle()); ga->SetMarkerColor(g->GetMarkerColor()); ga->SetLineColor(g->GetLineColor()); gamap[ct][cm][cs][ipt] = ga; } int n = ga->GetN(); ga->SetPoint(n, 0.01*a, g->GetY()[i]); ga->SetPointError(n, 0, g->GetEY()[i]); } // for i } // for ialpha } // for isample } // for imethod } // for itype cout << "Drawing plots vs pT for each alpha" << endl << flush; // 2x6 plots for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { const char *ct = types[itype]; const char *cm = methods[imethod]; int ipad = ntypes*imethod + itype + 1; assert(ipad<=6); c1->cd(ipad); gPad->SetLogx(); h1->SetMaximum(itype<2 ? 1.15 : 1.08); h1->SetMinimum(itype<2 ? 0.85 : 0.93); h1->SetYTitle(Form("Response (%s)",ct)); h1->DrawClone("AXIS"); tex->DrawLatex(0.20,0.85,texlabel[cm]); tex->DrawLatex(0.20,0.80,"|#eta| < 1.3, #alpha=0.1--0.3"); TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90); for (int isample = 0; isample != nsamples; ++isample) { for (int ialpha = 0; ialpha != nalphas; ++ialpha) { const char *cs = samples[isample]; const int a = alphas[ialpha]; TGraphErrors *g = gemap[ct][cm][cs][a]; assert(g); // Clean out points with very large uncertainty for plot readability for (int i = g->GetN()-1; i != -1; --i) { if (g->GetEY()[i]>0.02) g->RemovePoint(i); } g->Draw("SAME Pz"); if (ialpha==0) leg->AddEntry(g,texlabel[cs],"P"); } } // for isample // Individual plots for JEC paper if ( true ) { // paper TH1D *h = new TH1D(Form("h_5%s_%s",ct,cm), Form(";p_{T} (GeV);Response (%s)",ct), 1270,30,1300); h->GetXaxis()->SetMoreLogLabels(); h->GetXaxis()->SetNoExponent(); h->SetMinimum(0.88); h->SetMaximum(1.13); writeExtraText = true; extraText = (string(ct)=="mc" ? "Simulation" : ""); lumi_8TeV = (string(ct)=="mc" ? "" : "19.7 fb^{-1}"); TCanvas *c0 = tdrCanvas(Form("c0_%s_%s",cm,ct), h, 2, 11, true); c0->SetLogx(); TLegend *leg = tdrLeg(0.55,0.68,0.85,0.83); tex->DrawLatex(0.55,0.85,texlabel[cm]); tex->DrawLatex(0.55,0.18,"|#eta| < 1.3, #alpha=0.3"); //tex->DrawLatex(0.55,0.18,"Anti-k_{T} R=0.5"); // Loop over Z+jet and gamma+jet (only, no dijet/multijet) for (int isample = 0; isample != min(3,nsamples); ++isample) { const char *cs = samples[isample]; TGraphErrors *g = gemap[ct][cm][cs][30]; assert(g); g->Draw("SAME Pz"); leg->AddEntry(g,texlabel[cs],"P"); } // for isample if (etamin==0) { c0->SaveAs(Form("pdf/paper_softrad_%s_%s_vspt.pdf",ct,cm)); c0->SaveAs(Form("pdfC/paper_softrad_%s_%s_vspt.C",ct,cm)); } else { c0->SaveAs(Form("pdf/an_softrad_%s_%s_eta%1.0f-%1.0f_vspt.pdf", ct,cm,10*etamin,10*etamax)); } } // paper } // for imethod } // for itype c1->cd(0); //cmsPrel(_lumi, true); CMS_lumi(c1, 2, 33); c1->SaveAs("pdf/softrad_2x6_vspt.pdf"); cout << "Drawing plots vs alpha for each pT" << endl << flush; cout << "...and fitting slope vs alpha" << endl << flush; map<string, map<string, map<string, TGraphErrors* > > > gkmap; // 2x6 plots for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { int icanvas = nmethods*imethod + itype; assert(icanvas<=6); TCanvas *c2 = c2s[icanvas]; assert(c2); const char *ct = types[itype]; const char *cm = methods[imethod]; const int npads = 9; for (int ipad = 0; ipad != npads; ++ipad) { c2->cd(ipad+1); h2->SetYTitle(Form("Response (%s)",ct)); h2->DrawClone("AXIS"); tex->DrawLatex(0.20,0.85,texlabel[cm]); tex->DrawLatex(0.20,0.80,"|#eta| < 1.3"); tex->DrawLatex(0.20,0.75,Form("%1.0f < p_{T} < %1.0f GeV", hpt1->GetBinLowEdge(ipad+1), hpt1->GetBinLowEdge(ipad+2))); TLegend *leg = tdrLeg(0.65,0.75,0.90,0.90); leg->AddEntry(gemap[ct][cm]["gamjet"][30], texlabel["gamjet"], "P"); leg->AddEntry(gemap[ct][cm]["zeejet"][30], texlabel["zeejet"], "P"); leg->AddEntry(gemap[ct][cm]["zmmjet"][30], texlabel["zmmjet"], "P"); leg->AddEntry(gemap[ct][cm]["dijet"][30], texlabel["dijet"], "P"); } for (int isample = 0; isample != nsamples; ++isample) { const char *cs = samples[isample]; map<int, TGraphErrors*> &gam = gamap[ct][cm][cs]; map<int, TGraphErrors*>::iterator itpt; for (itpt = gam.begin(); itpt != gam.end(); ++itpt) { int ipt = itpt->first; int jpt = hpt1->FindBin(ipt); if (jpt>npads) continue; assert(jpt<=npads); c2->cd(jpt); TGraphErrors *ga = itpt->second; assert(ga); ga->Draw("SAME Pz"); // Fit slope TF1 *f1 = new TF1(Form("f1_%s_%s_%s_%d",ct,cm,cs,ipt), "(x<1)*([0]+[1]*x) + (x>1 && x<2)*[0] +" "(x>2)*[1]",-1,1); f1->SetLineColor(ga->GetLineColor()); f1->SetParameters(1,0); const double minalpha = (isample==0 ? 10./ipt : 5./ipt); // Constrain slope to within reasonable values // in the absence of sufficient data using priors if (true) { // use priors int n = ga->GetN(); // For response, limit to 1+/-0.02 (we've corrected for L3Res ga->SetPoint(n, 1.5, 1); ga->SetPointError(n, 0, 0.02); n = ga->GetN(); if (imethod==1) { // pT balance // For pT balance, estimate slope of <vecpT2>/alpha from data // => 7.5%/0.30 = 25% // Approximate uncertainty on this to be // 0.5%/0.30 ~ 1.5% for data, 0.5%/0.30 ~ 1.5% for Z+jet MC, and // 2%/0.30 ~ 6% for gamma+jet MC (same as slope) if (itype==0) ga->SetPoint(n, 2.5, -0.250); // DT if (itype==1 && isample!=0) ga->SetPoint(n, 2.5, -0.250); // MC if (itype==1 && isample==0) ga->SetPoint(n, 2.5, -0.190); if (itype==2 && isample!=0) ga->SetPoint(n, 2.5, -0.000); // rt if (itype==2 && isample==0) ga->SetPoint(n, 2.5, -0.060); // // BUG: found 2015-01-08 (no effect on ratio) //if (itype==1) ga->SetPointError(n, 0, -0.015); if (itype==0) ga->SetPointError(n, 0, -0.015); // DT if (itype==1 && isample!=0) ga->SetPointError(n, 0, -0.015); // MC if (itype==1 && isample==0) ga->SetPointError(n, 0, -0.060); if (itype==2 && isample!=0) ga->SetPointError(n, 0, -0.015); // rt if (itype==2 && isample==0) ga->SetPointError(n, 0, -0.060); } if (imethod==0) { // MPF // For MPF, expectation is no slope // Maximal slope would be approximately // (<vecpT2>/alpha ~ 25% from pT balance) times // (response difference between pT1 and vecpT2~10%) // => 0.25*0.10 = 2.5% // For data/MC, estimate uncertainty as half of this // => 1.25% ga->SetPoint(n, 2.5, 0.); if (itype!=2) ga->SetPointError(n, 0, 0.025); if (itype==2) ga->SetPointError(n, 0, 0.0125); } // MPF } // use priors if (ga->GetN()>2) { f1->SetRange(minalpha, 3.); ga->Fit(f1,"QRN"); if (f1->GetNDF()>=0) { f1->DrawClone("SAME"); f1->SetRange(0,0.4); f1->SetLineStyle(kDashed); f1->DrawClone("SAME"); // Store results TGraphErrors *gk = gkmap[ct][cm][cs]; if (!gk) { gk = new TGraphErrors(0); gk->SetMarkerStyle(ga->GetMarkerStyle()); gk->SetMarkerColor(ga->GetMarkerColor()); gk->SetLineColor(ga->GetLineColor()); gkmap[ct][cm][cs] = gk; } int n = gk->GetN(); TProfile *ppt = (isample==0 ? ppt2 : ppt1); if (isample==3) { ppt = ppt4; } // pas-v6 double pt = ppt->GetBinContent(ppt->FindBin(ipt)); gk->SetPoint(n, pt, f1->GetParameter(1)); gk->SetPointError(n, 0, f1->GetParError(1)); } // f1->GetNDF()>=0 } // ga->GetN()>2 } // for itpt } // for isample c2->SaveAs(Form("pdf/softrad_3x3_%s_%s_vsalpha.pdf",ct,cm)); } } cout << "Drawing plots of kFSR vs pT" << endl; // 2x6 plots for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { const char *ct = types[itype]; const char *cm = methods[imethod]; TMultiGraph *mgk = new TMultiGraph(); int ipad = ntypes*imethod + itype + 1; assert(ipad<=6); c3->cd(ipad); gPad->SetLogx(); h3->SetMaximum(imethod==0 ? 0.05 : (itype!=2 ? 0.1 : 0.25)); h3->SetMinimum(imethod==0 ? -0.05 : (itype!=2 ? -0.4 : -0.25)); h3->SetYTitle(Form("k_{FSR} = dR/d#alpha (%s)",ct)); h3->DrawClone("AXIS"); tex->DrawLatex(0.20,0.85,texlabel[cm]); tex->DrawLatex(0.20,0.80,"|#eta| < 1.3"); TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90); for (int isample = 0; isample != nsamples; ++isample) { const char *cs = samples[isample]; TGraphErrors *gk = gkmap[ct][cm][cs]; assert(gk); leg->AddEntry(gk,texlabel[cs],"P"); // Fit each sample separately for pT balance if (true) { TF1 *fk = new TF1(Form("fk_%s_%s_%s",ct,cm,cs), "[0]+[1]*log(0.01*x)+[2]*pow(log(0.01*x),2)", 30,1300); fk->SetParameters(-0.25,-0.5); fk->SetLineColor(gk->GetLineColor()); gk->Fit(fk, "QRN"); tex->SetTextColor(fk->GetLineColor()); tex->DrawLatex(0.55,0.27-0.045*isample, Form("#chi^{2}/NDF = %1.1f / %d", fk->GetChisquare(), fk->GetNDF())); tex->SetTextColor(kBlack); // Error band const int n = fk->GetNpar(); TMatrixD emat(n,n); gMinuit->mnemat(emat.GetMatrixArray(), n); TF1 *fke = new TF1(Form("fk_%s_%s_%s",ct,cm,cs), sr_fitError, 30, 1300, 1); _sr_fitError_func = fk; _sr_fitError_emat = &emat; fke->SetLineStyle(kSolid); fke->SetLineColor(fk->GetLineColor()-10); fke->SetParameter(0,-1); fke->DrawClone("SAME"); fke->SetParameter(0,+1); fke->DrawClone("SAME"); fk->DrawClone("SAME"); gk->DrawClone("SAME Pz"); // Store soft radiation corrections in fsr subdirectory assert(fin->cd(ct)); assert(gDirectory->cd(bin)); if (!gDirectory->FindObject("fsr")) gDirectory->mkdir("fsr"); assert(gDirectory->cd("fsr")); TH1D *hk = (TH1D*)(isample==0 ? hpt2->Clone() : hpt1->Clone()); hk->SetName(Form("hkfsr_%s_%s",cm,cs)); TProfile *ppt = (isample==0 ? ppt2 : ppt1); if (isample==3) { ppt = ppt4; } // pas-v6 for (int i = 1; i != hk->GetNbinsX()+1; ++i) { double pt = ppt->GetBinContent(i); if (pt>30 && pt<1300) { hk->SetBinContent(i, fk->Eval(pt)); hk->SetBinError(i, fabs(fke->Eval(pt)-fk->Eval(pt))); } else { hk->SetBinContent(i, 0); hk->SetBinError(i, 0); } } hk->Write(hk->GetName(), TObject::kOverwrite); // Factorize error matrix into eigenvectors // Remember: A = Q*Lambda*Q^-1, where // A is emat, Q is eigmat, and Lambda is a diagonal matrix with // eigenvalues from eigvec on the diagonal. For eigenmatrix // Q^-1 = Q^T, i.e. inverse matrix is the original transposed TVectorD eigvec(n); TMatrixD eigmat = emat.EigenVectors(eigvec); // Eigenvectors are the columns and sum of eigenvectors squared // equals original uncertainty. Calculate histograms from the // eigenvectors and store them TF1 *fkeig = (TF1*)fk->Clone(Form("%s_eig",fk->GetName())); fkeig->SetLineStyle(kDotted); for (int ieig = 0; ieig != n; ++ieig) { // Eigenvector functions for (int i = 0; i != n; ++i) { fkeig->SetParameter(i, fk->GetParameter(i) + eigmat[i][ieig] * sqrt(eigvec[ieig])); } fkeig->DrawClone("SAMEL"); // Eigenvector histograms evaluated at bin mean pT TH1D *hke = (TH1D*)hk->Clone(Form("%s_eig%d",hk->GetName(),ieig)); hke->Reset(); for (int i = 0; i != gk->GetN(); ++i) { double pt = gk->GetX()[i]; int ipt = hke->FindBin(pt); // Need to store central value as well, because // uncertainty sources are signed hke->SetBinContent(ipt, fkeig->Eval(pt)-fk->Eval(pt)); hke->SetBinError(ipt, fabs(fkeig->Eval(pt)-fk->Eval(pt))); } hke->Write(hke->GetName(), TObject::kOverwrite); } cout << "." << flush; } // if tree } // for isample } // for imethod } // for itype c3->cd(0); //cmsPrel(_lumi, true); CMS_lumi(c3, 2, 33); c3->SaveAs("pdf/softrad_2x6_kfsr.pdf"); fin->Close(); curdir->cd(); } // softrad
TF1* fit(TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax, int isMC) { static int count=0; count++; TCanvas* c= new TCanvas(Form("c%d",count),"",600,600); TH1D* h = new TH1D(Form("h-%d",count),"",nbinsmasshisto,minhisto,maxhisto); TH1D* hMCSignal = new TH1D(Form("hMCSignal-%d",count),"",nbinsmasshisto,minhisto,maxhisto); TH1D* hMCSwapped = new TH1D(Form("hMCSwapped-%d",count),"",nbinsmasshisto,minhisto,maxhisto); TF1* f = new TF1(Form("f%d",count),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); if(isMC==1) nt->Project(Form("h-%d",count),"Dmass",Form("%s*(%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata.Data(),ptmin,ptmax)); else nt->Project(Form("h-%d",count),"Dmass",Form("(%s&&Dpt>%f&&Dpt<%f)",seldata.Data(),ptmin,ptmax)); ntMC->Project(Form("hMCSignal-%d",count),"Dmass",Form("%s*(%s&&Dpt>%f&&Dpt<%f&&(Dgen==23333))",weight.Data(),selmc.Data(),ptmin,ptmax)); ntMC->Project(Form("hMCSwapped-%d",count),"Dmass",Form("%s*(%s&&Dpt>%f&&Dpt<%f&&(Dgen==23344))",weight.Data(),selmc.Data(),ptmin,ptmax)); /* TFile *fout=new TFile(Form("FitsFiles/Fits_%s_%d.root",collisionsystem.Data(),count),"recreate"); fout->cd(); hMCSignal->Write(); hMCSwapped->Write(); h->Write(); */ f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,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); h->GetEntries(); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); 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(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"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); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); //f->ReleaseParameter(2); // you need to release these two parameters if you want to perform studies on the sigma shape //f->ReleaseParameter(10); // you need to release these two parameters if you want to perform studies on the sigma shape 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); TF1* background = new TF1(Form("background%d",count),"[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(Form("fmass%d",count),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),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(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(Form("fmassSwap%d",count),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8)); 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); h->SetXTitle("m_{#piK} (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"); 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)/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,"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"); TLatex Tl; Tl.SetNDC(); Tl.SetTextAlign(12); Tl.SetTextSize(0.04); Tl.SetTextFont(42); Tl.DrawLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); Tl.DrawLatex(0.65,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); TLatex* tex; tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); h->GetFunction(Form("f%d",count))->Delete(); TH1F* histo_copy_nofitfun = ( TH1F * ) h->Clone("histo_copy_nofitfun"); histo_copy_nofitfun->Draw("esame"); // if(nBins==1) c->SaveAs(Form("DMass-inclusive%s_%d.pdf",collisionsystem.Data(),count)); else c->SaveAs(Form("DMass%s_%d.pdf",collisionsystem.Data(),count)); return mass; }
void SPEFit(char * fname, 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 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<<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 Polya_shape Polya_shape_err Polya_mode"<<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); //extra_file<<endl<<"LED_amplitude HV Spigot Channel PedSubtracted_mean Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl; 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]; bool drawflag; TFile *tf = new TFile(fname); TCanvas *c1 = new TCanvas("c1","c1",1200,700); c1->Divide(6,4); c1->SetBorderMode(0); c1->SetBorderSize(0); TCanvas *c2 = new TCanvas("c2","c2",1200,700); c2->Divide(6,4); c2->SetBorderMode(0); c2->SetBorderSize(0); TCanvas *c3 = new TCanvas("c3","c3",1200,700); c3->Divide(6,4); c3->SetBorderMode(0); c3->SetBorderSize(0); 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}; TH1F* hspe = new TH1F("hspe","hspe",NnewBins-1,binsX); int Npoints; TH2D *tmp; for(Npoints=0;Npoints<10;Npoints++){ sprintf(spename,"spetest/spigot_%d/bb_%d/LED_HVset_%d_sp_%d_BB_%d",0,1,Npoints,0,1); tmp=(TH2D *)tf->Get(spename); if(tmp==0) break; } TH2D *LED[3][3][20]; TH2D *PED[3][3]; for(int iSpig = 0; iSpig < 3; iSpig++)for(int bb = 1; bb < 4; bb++){ for(int ii=0; ii<Npoints; ii++){ sprintf(spename,"spetest/spigot_%d/bb_%d/LED_HVset_%d_sp_%d_BB_%d",iSpig,bb,ii,iSpig,bb); LED[iSpig][bb-1][ii]=(TH2D *)tf->Get(spename); } sprintf(spename,"spetest/spigot_%d/bb_%d/PED_sp_%d_BB_%d",iSpig,bb,iSpig,bb); PED[iSpig][bb-1]=(TH2D *)tf->Get(spename); } for(int ii=0; ii<Npoints; ii++) { drawflag=false; int HV=0; for (int iSpig = 0; iSpig < 3; iSpig++) { for(int i = 0; i < 24; i++) { int bb=BB_MAP[i]; int pmt=PMT_MAP[i]; sprintf(spehistname,"led %d %d %d",ii,iSpig,i); TH1D *hspe_temp = (TH1D *)LED[iSpig][bb-1][ii]->ProjectionX(spehistname,pmt,pmt,"")->Clone(); sprintf(spehistname,"ped %d %d %d",ii,iSpig,i); TH1D *hped = (TH1D *)PED[iSpig][bb-1]->ProjectionX(spehistname,pmt,pmt,"")->Clone(); sscanf(&hspe_temp->GetTitle()[7],"%d",&HV); hspe->Reset(); sprintf (spehistname, "SumLED%d_sp_%d_ch_%d", HV, iSpig, i); 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=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); //cout<<"Ped only: ped mean "<<fped->GetParameter(1)<<", ped width "<<fped->GetParameter(2)<<" normalization "<<fped->GetParameter(0)<<endl; hspe->Fit(fped, "NQ", "", pploc - 3*ppwidth, pploc + ppwidth); //cout<<"SPE distribution: ped mean "<<fped->GetParameter(1)<<", ped width "<<fped->GetParameter(2)<<" normalization "<<fped->GetParameter(0)<<endl; //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 /* int maxped_bin = hspe->GetMaximumBin(); int maxped_binheight = hspe->GetBinContent(maxped_bin); minheight = maxped_binheight; */ Nbins = hspe->GetNbinsX(); for(int j=/*maxped_bin*/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, 3.0); else fit->SetParameters(mu, 20, 1, 2.1*fped->GetParameter(2), 3.0); //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, 1.01, 100.); double maxfitrange = 500.; double minfitrange = 0.; hspe->Fit(fit, "MNQL", "", minfitrange, maxfitrange); double rms_estimate = fit->GetParameter(3)/sqrt(fit->GetParameter(4)); maxfitrange = fped->GetParameter(1)+4*fit->GetParameter(3)+rms_estimate; // cout<<"estimate of gain "<<gain_est<<", fit "<<fit->GetParameter(3)<<endl; // cout<<"Shape Parameter "<<fit->GetParameter(4)<<endl; // cout<<"SPE width "<<rms_estimate<<endl; // cout<<"maxfitrange "<<maxfitrange<<endl; 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 // cout<<"estimate of gain "<<gain_est<<", fit "<<fit->GetParameter(3)<<endl; // cout<<"Shape Parameter "<<fit->GetParameter(4)<<endl; // double SPE_rms = fit->GetParameter(3)/sqrt(fit->GetParameter(4)); // cout<<"SPE width "<<SPE_rms<<endl; //cout<<"SPE width "<<fit->GetParameter(4)<<endl; //cout<<"Fit normalization constant: estimate "<<mu<<" fit "<<fit->GetParameter(0)<<endl; //cout<<spename<<endl; //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"<<iSpig<<"\t"<<i<<"\t"<<2.6*hspe->GetBinCenter(i1)<<"\t"<<hspe->GetBinContent(i1)<<"\t"<<fit->Eval(hspe->GetBinCenter(i1))<<"\n"; } //========================================= //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 Polya_shape Polya_shape_err Polya_mode"<<endl; constants_file<<LED_amp<<" "<<HV<<" "<<iSpig<<" "<<(bb-1)*8+pmt<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParError(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fped->GetParError(2)<<" "<<scale*fit->GetParameter(3)/sqrt(fit->GetParameter(4))<<" "<<0<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<scale*fit->GetParError(3)*fC2electrons<<" "<<fit->GetChisquare()/myNDOF/*fit->GetNDF()*/<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<" "<<fit->GetParameter(4)<<" "<<fit->GetParError(4)<<" "<<scale*(fit->GetParameter(4)-1.0)/fit->GetParameter(4)*fit->GetParameter(3)*fC2electrons<<endl; // cout<<LED_amp<<" "<<HV<<" "<<iSpig<<" "<<QIECh[i]<<" "<<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()/fit->GetNDF()<<" "<<fit->GetChisquare()<<" "<<fit->GetNDF()<<" "<<myNDOF<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<endl; //extra_file<<endl<<"LED_amplitude HV Spigot Channel SignalAvg_inFitRange FitAvg_inFitRange SignalInt_inFitRange FitInt_inFitRange PEge5Int Gain(fC) Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl; //extra_file<<LED_amp<<" "<<HV<<" "<<iSpig<<" "<<QIECh[i]<<" "<<scale*havg<<" "<<scale*favg<<" "<<hint<<" "<<fint<<" "<<PE5int<<" "<<scale*fit->GetParameter(3)<<" "<<scale*fit->GetParError(3)<<" "<<fit->GetChisquare()/myNDOF<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<endl; //cout<<"# Spigot Channel Ped_mean Ped_RMS SPE_PeakRMS Gain Normalized_Chi2 Avg_PE"<<endl; //cout<<iSpig<<" "<<i<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fit->GetParameter(4)<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<fit->GetChisquare()/fit->GetNDF()<<" "<<fit->GetParameter(0)<<endl<<endl; if(iSpig==0) c1->cd(i+1); else if(iSpig==1) c2->cd(i+1); else if(iSpig==2) c3->cd(i+1); gPad->SetBorderMode(0); gPad->SetBorderSize(0); gPad->SetRightMargin(0.01); gPad->SetBottomMargin(0.1); gPad->SetLogy(true); hspe->GetXaxis()->SetRangeUser(0, /*300*/508); hspe->SetLineColor(kBlue); hspe->DrawClone("hist"); fit->SetLineWidth(2); fit->Draw("same"); } } if(drawflag) { //draw plots of fit if data for the HV is present stringstream plot_name; //plot_name<<"Plots/SPEFits_Spigot0_Run_"<<run<<"_HV"<<HV<<".pdf"; plot_name<<"Plots/SPEFits_Spigot0_Run_"<<run<<"_HV"<<HV<<"_config"<<ii<<".pdf"; c1->SaveAs(plot_name.str().c_str()); plot_name.str( std::string() ); //plot_name<<"Plots/SPEFits_Spigot1_Run_"<<run<<"_HV"<<HV<<".pdf"; plot_name<<"Plots/SPEFits_Spigot1_Run_"<<run<<"_HV"<<HV<<"_config"<<ii<<".pdf"; c2->SaveAs(plot_name.str().c_str()); plot_name.str( std::string() ); //plot_name<<"Plots/SPEFits_Spigot2_Run_"<<run<<"_HV"<<HV<<".pdf"; plot_name<<"Plots/SPEFits_Spigot2_Run_"<<run<<"_HV"<<HV<<"_config"<<ii<<".pdf"; c3->SaveAs(plot_name.str().c_str()); } } //HV loop constants_file.close(); constants_file1.close(); }
void fitMassHisto(TString inputfile="outfiles/MassHisto", TString outputfile="outfiles/YieldHisto", Float_t centmin=0., Float_t centmax=100.) { infname = inputfile; centMin = centmin; centMax = centmax; gStyle->SetTextSize(0.05); gStyle->SetTextFont(42); gStyle->SetPadRightMargin(0.043); gStyle->SetPadLeftMargin(0.18); gStyle->SetPadTopMargin(0.1); gStyle->SetPadBottomMargin(0.145); gStyle->SetTitleX(.0f); TF1* fit(TH1D* h, TH1D* hMCSignal, TH1D* hMCSwapped, Float_t ptmin, Float_t ptmax, Int_t j); TH1D** hYield = new TH1D*[4]; for(int i=0;i<4;i++) hYield[i] = new TH1D(Form("hYield_%s",tfend[i].Data()),"",nPtBins,ptBins); for(int i=0;i<nPtBins;i++) { TFile* infile = new TFile(Form("%s_cent_%.0f_%.0f_pt_%.0f_%.0f.root",infname.Data(),centMin,centMax,ptBins[i],ptBins[i+1])); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); TH1D* hMCSwapped = (TH1D*)infile->Get("hMCSwapped"); for(int j=0;j<4;j++) { TH1D* h = (TH1D*)infile->Get(Form("h_%s",tfend[j].Data())); TF1* f = fit(h,hMCSignal,hMCSwapped,ptBins[i],ptBins[i+1],j); Double_t yield = f->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = f->Integral(minhisto,maxhisto)/binwidthmass*f->GetParError(0)/f->GetParameter(0); hYield[j]->SetBinContent(i+1,yield); hYield[j]->SetBinError(i+1,yieldErr); delete h; } delete hMCSwapped; delete hMCSignal; delete infile; } TFile* outf = new TFile(Form("%s_cent_%.0f_%.0f.root",outputfile.Data(),centmin,centmax),"recreate"); outf->cd(); for(int i=0;i<4;i++) hYield[i]->Write(); outf->Close(); delete []hYield; delete outf; cout<<endl; }