void Enemy::update1() { if (!air) { // check if we are moving onto empty space TEG_MAP *map = parent->getMap(); int xx = x + ((dx > 0) ? getw() : 0); int yy = y + geth() + 1; int mx = xx / map->tilelist->tilew; int my = yy / map->tilelist->tileh; int tileflags = getTileStackFlags(mx, my); if ((tileflags & TS_SOLID) == 0) { // turn around dx = -dx; } } if (bulletTimer >= 301) { spawn(EBullet::ENERGY); bulletTimer = 0; } else { bulletTimer++; } }
void checkpthat(TString fnameevt, TString filename, TString prefix, TString jtptvar) { TFile *f = new TFile(fnameevt); auto nt = (TTree *)f->Get("nt"); auto h = geth(prefix+"mcpthat", 80, 0, 400); nt->Project(h->GetName(),"pthat",""); int minbin = nt->GetMinimum("pthatbin"); int maxbin = nt->GetMaximum("pthatbin"); //assumes ints between min and max int N = maxbin-minbin+1; vector<TString> pthatcuts; pthatcuts = {"pthat>30 && pthat<50","pthat>50 && pthat<80","pthat>80 && pthat<120","pthat>120"}; auto hs = getstack(nt, prefix+"mcpthatstack","pthat",pthatcuts,80,0,400); hs->SetMinimum(1E-2); fout->cd(); hs->Write(); h->Write(); f->Close(); f = new TFile(filename); nt = (TTree *)f->Get("nt"); auto hj = geth(prefix+"mcjtpt", 80, 0, 400); nt->Project(hj->GetName(),jtptvar,"weight*(subid==0)",jtptvar); vector<TString> jtptcuts; jtptcuts = {"pthat>30 && pthat<50 && subid==0","pthat>50 && pthat<80 && subid==0","pthat>80 && pthat<120 && subid==0","pthat>120 && subid==0"}; // for (int i=0;i<N;i++) jtptcuts.push_back(Form("pthatbin==%d",i)); auto hsjtpt = getstack(nt, prefix+"mcjtptstack",jtptvar,jtptcuts,80,0,400); hsjtpt->SetMinimum(1E-2); fout->cd(); hsjtpt->Write(); hj->Write(); // fout->Write(); f->Close(); }
void checkbjetdatatrig(TString filename) { TFile *f = new TFile(filename); auto nt = (TTree *)f->Get("nt"); auto h = geth("incdatajtpt",48,0,120); nt->Project(h->GetName(),"jtpt1","weight"); auto h2 = geth("incdatajtpt60",48,0,120); nt->Project(h2->GetName(),"jtpt1","weight*(hltCSV60)"); auto hr = geth("incdatajtpt60ratio",48,0,120); hr->Divide(h2,h); vector<TString> trigcuts = {"hltCSV80", "hltCSV60 && !hltCSV80"}; auto hs = getstack(nt, "trigcomb","jtpt1",trigcuts, 72, 0, 180); fout->cd(); h->Write(); hs->Write(); hr->Write(); f->Close(); }
void quenchedMC() { auto fpythia = new TFile("/data_CMS/cms/lisniak/bjet2015/mcPbqcdakVs4PF_djt.root"); auto fpyquen = new TFile("/data_CMS/cms/lisniak/bjet2015/mcPbpqcakVs4PF_djt.root"); auto hpythia = geth("pythia"); auto hpyquen = geth("pyquen"); TString jet1 = "jtpt1";//"refpt1";// TString jet2 = "jtptSignal2";// "jtpt2";//"refpt2";// TString dphi = "dphiSignal21";// "dphi21"; float pt1 = 120; float pt2 = 40; Fill(fpythia, {"weight",jet1,jet2,"dphi21","pthatsample"}, [&] (dict &m) { float w = m["weight"]; if (m["pthatsample"]==30) return; if (m[jet1]>pt1 && m[jet2]>pt2 && m["dphi21"]>2.1) hpythia->Fill(m[jet2]/m[jet1],w); }); Fill(fpyquen, {"weight",jet1,jet2,"dphi21"}, [&] (dict &m) { float w = m["weight"]; if (m[jet1]>pt1 && m[jet2]>pt2 && m["dphi21"]>2.1) hpyquen->Fill(m[jet2]/m[jet1],w); }); plotputmean = true; Normalize({hpythia,hpyquen}); Draw({hpythia,hpyquen}); }
THStack *getstack(TTree *nt, TString name, TString var, vector<TString> cuts,int bins = 100, float xmin = 0, float xmax = 200) { THStack *hs = new THStack(name,name); int N = cuts.size(); vector<TH1F *> vh(N); for (int i=0;i<N;i++) { vh[i] = geth(Form("%s%d",name.Data(),i),bins,xmin,xmax); vh[i]->SetFillColor(TColor::GetColorDark(i+2)); vh[i]->SetFillStyle(1001); nt->Project(vh[i]->GetName(),var.Data(),Form("weight*(%s)",cuts[i].Data()),"");//,1000); hs->Add(vh[i],"hist"); cout<<vh[i]->Integral()<<endl; } hs->SetMinimum(1E-2); return hs; }
int CSprite::colision(CSprite sp) { int w1,h1,w2,h2,x1,y1,x2,y2; w1=getw(); // ancho del sprite1 h1=geth(); // altura del sprite1 w2=sp.getw(); // ancho del sprite2 h2=sp.geth(); // alto del sprite2 x1=getx(); // pos. X del sprite1 y1=gety(); // pos. Y del sprite1 x2=sp.getx(); // pos. X del sprite2 y2=sp.gety(); // pos. Y del sprite2 if ( ( (x1+w1) > x2) && ( (y1+h1) > y2) && ( (x2+w2) > x1) && ( (y2+h2) > y1) ) { return TRUE; } else { return FALSE; } }
void checkclosure() { vector<TH1F *>hsig(Nbins); vector<TH1F *>hasd(Nbins); vector<TH1F *>hbkg(Nbins); vector<TH1F *>hsub(Nbins); vector<TH1F *>hhyj(Nbins); vector<TH1F *>hshj(Nbins); vector<TH1F *>hsbn(Nbins); for (int i=0;i<Nbins;i++) { seth(10,0,1); hsig[i] = geth(Form("hsig%d",i),Form("Signal away-side %s;x_{J}",binnames[i].Data())) ; hasd[i] = geth(Form("hasd%d",i),Form("Measured away-side %s;x_{J}",binnames[i].Data())); hbkg[i] = geth(Form("hbkg%d",i),Form("Near-side %s;x_{J}",binnames[i].Data())); hhyj[i] = geth(Form("hhyj%d",i),Form("Near-side hydjet %s;x_{J}",binnames[i].Data())); hsub[i] = geth(Form("hsub%d",i),Form("Subtracted NS %s;x_{J}",binnames[i].Data())); hshj[i] = geth(Form("hshj%d",i),Form("Subtracted Hydjet %s;x_{J}",binnames[i].Data())); hsbn[i] = geth(Form("hsbn%d",i),Form("Subtracted Naive %s;x_{J}",binnames[i].Data())); } auto fmcPb = config.getfile_djt("mcPbbfa"); Fill(fmcPb,{"pthat","weight","jtpt1","refpt1","bProdCode","jtptSL","refptSL","dphiSL1","refparton_flavorForB1","subidSL","bin","pairCodeSL1","discr_csvV1_1","jteta1","jtetaSL"},[&] (dict d) { if (d["pthat"]<pthatcut) return; if (d["jtpt1"]>pt1cut && d["refpt1"]>50 && abs(d["refparton_flavorForB1"])==5 && d["jtptSL"]>pt2cut) { int bin = getbinindex(d["bin"]); float xj = d["jtptSL"]/d["jtpt1"]; float w = weight1SLPbPb(d); if (AwaySide(d)) hasd[bin]->Fill(xj, w); if (AwaySide(d) && IsSignal(d)) hsig[bin]->Fill(xj,w); if (NearSide(d)) hbkg[bin]->Fill(xj,w); if (NearSide(d) && !IsSignal(d)) hhyj[bin]->Fill(xj,w); } }); for (int i=0;i<Nbins;i++) { hsub[i]->Add(hasd[i],hbkg[i],1,-1*bkgfractionInNearSide[i]); hsbn[i]->Add(hasd[i],hbkg[i],1,-1); hshj[i]->Add(hasd[i],hhyj[i],1,-1); } // for (int i=0;i<Nbins;i++) // hincsub[i]->Add(hincasd[i],hincbkg[i],1,-1); seth(bins);//Nbins,0,100); auto hcentrSubSIG = geth("hcentrSubSIG","Signal;bin;#LTx_{J}#GT"); auto hcentrSubASD = geth("hcentrSubASD","Unsubtracted;bin;#LTx_{J}#GT"); auto hcentrSubBKS = geth("hcentrSubBKS","Subtracted w/o bkg scaling;bin;#LTx_{J}#GT"); auto hcentrSubCLS = geth("hcentrSubCLS","Subtracted with bkg scaling;bin;#LTx_{J}#GT"); auto hcentrSubHJS = geth("hcentrSubHJS","Subtracted Hydjet;bin;#LTx_{J}#GT"); plotlegendpos = BottomRight; for (int i=0;i<Nbins;i++) { hcentrSubSIG->SetBinContent(i+1,hsig[i]->GetMean());hcentrSubSIG->SetBinError(i+1,hsig[i]->GetMeanError()); hcentrSubASD->SetBinContent(i+1,hasd[i]->GetMean());hcentrSubASD->SetBinError(i+1,hasd[i]->GetMeanError()); hcentrSubBKS->SetBinContent(i+1,hsbn[i]->GetMean());hcentrSubBKS->SetBinError(i+1,hsbn[i]->GetMeanError()); hcentrSubCLS->SetBinContent(i+1,hsub[i]->GetMean());hcentrSubCLS->SetBinError(i+1,hsub[i]->GetMeanError()); hcentrSubHJS->SetBinContent(i+1,hshj[i]->GetMean());hcentrSubHJS->SetBinError(i+1,hshj[i]->GetMeanError()); Draw({hsig[i],hsub[i],hshj[i]}); } plotymin = 0.55;//0.4; plotymax = 0.7;//0.8; plotlegendpos = BottomRight; aktstring = ""; plotputmean = false; //hcentrSubHJS - hydjet only subtraction // SetMC({hcentrSubSIG, hcentrSubBKS, hcentrSubASD}); // SetData({hcentrSubCLS}); hcentrSubSIG->SetMarkerStyle(kOpenSquare); hcentrSubBKS->SetMarkerStyle(kOpenSquare); hcentrSubASD->SetMarkerStyle(kOpenSquare); hcentrSubCLS->SetMarkerStyle(kFullCircle); hcentrSubSIG->SetMarkerColor(TColor::GetColorDark(2)); hcentrSubSIG->SetLineColor(TColor::GetColorDark(2)); hcentrSubBKS->SetMarkerColor(TColor::GetColorDark(3)); hcentrSubBKS->SetLineColor(TColor::GetColorDark(3)); hcentrSubASD->SetMarkerColor(TColor::GetColorDark(4)); hcentrSubASD->SetLineColor(TColor::GetColorDark(4)); hcentrSubCLS->SetMarkerColor(TColor::GetColorDark(3)); hcentrSubCLS->SetLineColor(TColor::GetColorDark(3)); plotoverwritecolors = false; plotlegenddx = -0.15; Draw({hcentrSubSIG,hcentrSubASD, hcentrSubBKS, hcentrSubCLS}); auto syst = (TH1F *)hcentrSubSIG->Clone("syst"); syst->Add(hcentrSubCLS,-1); map<TString,float> m; for (unsigned i=0;i<bins.size()-1;i++) { float misclosure = syst->GetBinContent(i+1); float err = hcentrSubCLS->GetBinError(i+1); m[Form("closure%d%d",(int)bins[i],(int)bins[i+1])]=sqrt(misclosure*misclosure+err*err); } WriteToFile(plotfoldername+"/hydjetclosuresyst.root",m); }
void checkdatainc(TString datafilename, TString incfilename) { TFile *f = new TFile(datafilename); nt = (TTree *)f->Get("nt"); auto h = new TH1F("data_rawpt","data_rawpt",ptbins,ptmin,ptmax); nt->Project(h->GetName(),"rawpt","weight"); auto h4 = new TH1F("data_jtpt","data_jtpt",ptbins,ptmin,ptmax); nt->Project(h4->GetName(),"jtpt","weight"); auto h2 = new TH1F("data_jteta","data_jteta",30,-2.4,2.4); nt->Project(h2->GetName(),"jteta","weight*(jtpt>120)"); auto h3 = new TH1F("data_jtphi","data_jtphi",30,-3.14,3.14); nt->Project(h3->GetName(),"jtphi","weight*(jtpt>120)"); fout->cd(); h->Write(); h2->Write(); h3->Write(); h4->Write(); f->Close(); f = new TFile(incfilename); nt = (TTree *)f->Get("nt"); auto hinc = geth("inc_pthat"); nt->Project(hinc->GetName(),"pthat","weight"); auto hraw = new TH1F("inc_rawpt","inc_rawpt",ptbins,ptmin,ptmax); nt->Project(hraw->GetName(),"rawpt","weight"); auto hpt = new TH1F("inc_jtpt","inc_jtpt",ptbins,ptmin,ptmax); nt->Project(hpt->GetName(),"jtpt","weight"); auto heta = new TH1F("inc_jteta","inc_jteta",30,-2.4,2.4); nt->Project(heta->GetName(),"jteta","weight*(jtpt>120)"); auto hphi = new TH1F("inc_jtphi","inc_jtphi",30,-3.14,3.14); nt->Project(hphi->GetName(),"jtphi","weight*(jtpt>120)"); auto hJES = new TProfile("inc_JES","inc_JES",ptbins,0,ptmax);//30,200); nt->Project(hJES->GetName(),"jtpt/refpt:refpt","weight*(jtpt>20 && refpt>30)","prof"); // auto hJER = new TProfile("inc_JER","inc_JER",ptbins,30,200); // nt->Project(hJER->GetName(),"abs(jtpt-refpt)/refpt:refpt","weight","prof"); auto hJER = new TH1F("inc_JER","inc_JER",ptbins,0,ptmax); auto htemp=new TProfile("htemp","htemp",ptbins,0,ptmax,"CHOPT='S'"); //easily calculates RMS nt->Project("htemp","jtpt/refpt:refpt","weight*(jtpt>20 && refpt>30)","prof"); for (int i=1;i<ptbins;i++) { hJER->SetBinContent(i,htemp->GetBinError(i)); hJER->SetBinError(i,htemp->GetBinError(i)/1000); //should be fixed } fout->cd(); hinc->Write(); hpt->Write(); hraw->Write(); heta->Write(); hphi->Write(); hJES->Write(); hJER->Write(); f->Close(); }
int main() { const int iinf = 0x7f7f7f7f; const short sinf = 0x7f7f; short n, u, v, w, mm, d[500]; int i, m, l, ll; scanf("%hd%d", &n, &m); memset(g, 0x7f, sizeof(g)); for (i = 0; i < m; i++) { scanf("%hhd%hhd%hd", &u, &v, &mm); u--; v--; g[u][v] = g[v][u] = mm; } memset(b, 0, sizeof(b)); memset(p, 0, sizeof(p)); memcpy(d, &g[0], sizeof(d)); b[0] = 1; d[0] = 0; p[0] = -1; l = 0; for (i = 1; i < n; i++) { mm = sinf; for (u = 0; u < n; u++) if (!b[u] && d[u] < mm) { mm = d[u]; v = u; } b[v] = 1; l += mm; for (u = 0; u < n; u++) if (!b[u] && g[v][u] < d[u]) { d[u] = g[v][u]; p[u] = v; } } memset(h, 0xff, sizeof(h)); for (u = 0; u < n; u++) h[u] = geth(u); memset(lca, 0xff, sizeof(lca)); memset(gm, 0x7f, sizeof(gm)); for (u = 0; u < n; u++) { v = u; mm = 0; while (p[v] != -1) { mm = max(mm, g[v][p[v]]); v = p[v]; gm[u][v] = gm[v][u] = mm; } } ll = iinf; for (u = 0; u < n; u++) for (v = u + 1; v < n; v++) { if (gm[u][v] == sinf) { w = getlca(u, v); gm[u][v] = max(gm[w][u], gm[w][v]); } if (g[u][v] != sinf && p[u] != v && p[v] != u) ll = min(ll, l - gm[u][v] + g[u][v]); } printf("Cost: %d\nCost: %d\n", l, ll == iinf ? -1 : ll); return 0; }
void findfunc() { //dijet case // auto fmcppbjt = config.getfile_djt("mcppbfa"); // auto nt = (TTree *)fmcppbjt->Get("nt"); // seth(18,40,220); // auto hd = geth("hd"); // auto hn = geth("hn"); // nt->Project("hd","jtpt2","weight*(pthat>80 && jtpt1>100 && abs(refparton_flavorForB1)==5 && abs(refparton_flavorForB2)!=5 && dphi21>2.1)"); // nt->Project("hn","jtpt2","weight*(pthat>80 && jtpt1>100 && abs(refparton_flavorForB1)==5 && abs(refparton_flavorForB2)!=5 && dphi21>2.1 && discr_csvV1_2>0.9)"); // hn->Divide(hn,hd,1,1,"B") // hn->Fit(f) auto fpp = new TF1("fpp","expo",40,200); auto f1 = new TF1("fPb1","expo",40,200); auto f2 = new TF1("fPb2","expo",40,200); auto f3 = new TF1("fPb3","expo",40,200); seth(18,40,200); auto ntpp = (TTree *)config.getfile_inc("mcppqcd")->Get("nt"); auto hd = geth("hd"); auto hn = geth("hn",";p_{T} [GeV];mistag probability"); ntpp->Project("hd","jtpt","weight*(pthat>50 && refpt>20 && abs(refparton_flavorForB)!=5)"); ntpp->Project("hn","jtpt","weight*(pthat>50 && refpt>20 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)"); hn->Divide(hn,hd,1,1,"B"); // hn->Scale(1/hn->Integral()); hn->Fit(fpp); auto nt = (TTree *)config.getfile_inc("mcPbqcd")->Get("nt"); auto hd1 = geth("hd1"); auto hn1 = geth("hn1",";p_{T} [GeV];mistag probability"); nt->Project("hd1","jtpt","weight*(pthat>50 && refpt>20 && bin < 20 && abs(refparton_flavorForB)!=5)"); nt->Project("hn1","jtpt","weight*(pthat>50 && refpt>20 && bin < 20 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)"); hn1->Divide(hn1,hd1,1,1,"B"); // hn1->Scale(1/hn1->Integral()); hn1->Fit(f1); auto hd2 = geth("hd2"); auto hn2 = geth("hn2",";p_{T} [GeV];mistag probability"); nt->Project("hd2","jtpt","weight*(pthat>50 && refpt>20 && bin>=20 && bin<60 && abs(refparton_flavorForB)!=5)"); nt->Project("hn2","jtpt","weight*(pthat>50 && refpt>20 && bin>=20 && bin<60 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)"); hn2->Divide(hn2,hd2,1,1,"B"); // hn2->Scale(1/hn2->Integral()); hn2->Fit(f2); auto hd3 = geth("hd3"); auto hn3 = geth("hn3",";p_{T} [GeV];mistag probability"); nt->Project("hd3","jtpt","weight*(pthat>50 && refpt>20 && bin>=60 && abs(refparton_flavorForB)!=5)"); nt->Project("hn3","jtpt","weight*(pthat>50 && refpt>20 && bin>=60 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)"); hn3->Divide(hn3,hd3,1,1,"B"); // hn3->Scale(1/hn3->Integral()); hn3->Fit(f3); // because of backward imcompatibility with root version on polui cout<<"auto fpp = new TF1(\"fpp\",\"expo\","<<fpp->GetXmin()<<","<<fpp->GetXmax()<<");"<<endl; cout<<"auto fPb1 = new TF1(\"fPb1\",\"expo\","<<f1->GetXmin()<<","<<f1->GetXmax()<<");"<<endl; cout<<"auto fPb2 = new TF1(\"fPb2\",\"expo\","<<f2->GetXmin()<<","<<f2->GetXmax()<<");"<<endl; cout<<"auto fPb3 = new TF1(\"fPb3\",\"expo\","<<f3->GetXmin()<<","<<f3->GetXmax()<<");"<<endl; cout<<"fpp->SetParameters("<<fpp->GetParameter(0)<<","<<fpp->GetParameter(1)<<");"<<endl; cout<<"fPb1->SetParameters("<<f1->GetParameter(0)<<","<<f1->GetParameter(1)<<");"<<endl; cout<<"fPb2->SetParameters("<<f2->GetParameter(0)<<","<<f2->GetParameter(1)<<");"<<endl; cout<<"fPb3->SetParameters("<<f3->GetParameter(0)<<","<<f3->GetParameter(1)<<");"<<endl; // hn->SetMinimum(0); // hn1->SetMinimum(0); // hn2->SetMinimum(0); // hn3->SetMinimum(0); auto fout = new TFile("../correctionfiles/BXmistagfunc.root","recreate"); fout->cd(); fpp->Write(); f1->Write(); f2->Write(); f3->Write(); hn->Write(); hn1->Write(); hn2->Write(); hn3->Write(); auto c = getc(); f1->SetLineColor(kRed); f2->SetLineColor(kGreen); f3->SetLineColor(kOrange); fpp->SetLineColor(kBlue); auto l = getLegend(); l->AddEntry(fpp,"pp","L"); l->AddEntry(f1,"bin<20","L"); l->AddEntry(f2,"20<bin<60","L"); l->AddEntry(f3,"bin>60","L"); f1->GetXaxis()->SetTitle("p_{T} [GeV]"); f1->GetYaxis()->SetTitle("mistag probability"); f1->Draw(); f2->Draw("same"); f3->Draw("same"); fpp->Draw("same"); l->Draw(); SavePlot(c,"func"); float x = 0.55; float y = 0.75; auto t= new TLatex(); auto cpp = getc(); hn->Draw(); fpp->Draw("same"); t->DrawLatexNDC(x,y,"pp"); SavePlot(cpp,"pp"); auto c1 = getc(); hn1->Draw(); f1->Draw("same"); t->DrawLatexNDC(x,y,"PbPb 0-10%"); SavePlot(c1,"bin_0_20"); auto c2 = getc(); hn2->Draw(); f2->Draw("same"); t->DrawLatexNDC(x,y,"PbPb 10-30%"); SavePlot(c2,"bin_20_60"); auto c3 = getc(); hn3->Draw(); f3->Draw("same"); t->DrawLatexNDC(x,y,"PbPb 30-100%"); SavePlot(c3,"bin_60"); fout->Close(); }
inline short geth(short u) { if (h[u] == -1) h[u] = p[u] == -1 ? 0 : geth(p[u]) + 1; return h[u]; }
void deriveNSfractions(bool data, int mode, bool bjet = false) { if (mode==0) { for (unsigned i=0;i<binbounds.size()-1;i++) NSfrac.push_back(1); return; } if (mode==2) { for (unsigned i=0;i<binbounds.size()-1;i++) NSfrac.push_back(0.7); return; } if (mode==4) { for (unsigned i=0;i<binbounds.size()-1;i++) NSfrac.push_back(1.3); return; } TString fnpp; if (bjet) fnpp = data ? "dtppjpf" : "mcppbfa"; else fnpp = data ? "dtppjpf" : "mcppqcd"; auto filepp = config.getfile_djt(fnpp); seth(1,0,PI); auto hppNS = geth("hppNS"); auto hppAS = geth("hppAS"); Fill(filepp,[&] (dict &d) { if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return; if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hppNS->Fill(d["dphi21"],d["weight"]); if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hppAS->Fill(d["dphi21"],d["weight"]); }); float a_pp = hppNS->Integral()/hppAS->Integral(); cout<<"a_pp "<<a_pp<<endl; TString fnPbPb; if (bjet) fnPbPb = data ? "dtPbbjt" : "mcPbbfa"; else fnPbPb = data ? "dtPbjcl" : "mcPbqcd"; auto file = config.getfile_djt(fnPbPb); vector<TString> histn; for (unsigned i=0;i<binbounds.size()-1;i++) histn.push_back(Form("PbPb%d%d",binbounds[i],binbounds[i+1])); setv(histn); auto hPbPbNS = getv("hPbPbNS"); auto hPbPbAS = getv("hPbPbAS"); auto hPbPbNSsig = getv("hPbPbNSsig"); Fill(file,[&] (dict &d) { int b = getbin(d["bin"]); float w = d["weight"]; if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return; if (bjet && d["pairCode21"]==0) w*=processweight((int)d["bProdCode"]); if (!data && d["pthat"]<50) return; if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hPbPbNS[b]->Fill(d["dphi21"],d["weight"]); if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hPbPbAS[b]->Fill(d["dphi21"],d["weight"]); if (!data && d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13 && (d["subid2"]==0 && d["refpt2"]>20)) hPbPbNSsig[b]->Fill(d["dphi21"],d["weight"]); }); vector<double> binmean; vector<double> nsfractrue; vector<double> nsfracest; for (unsigned i=0;i<binbounds.size()-1;i++) { float a_PbPb = hPbPbNS[i]->Integral()/hPbPbAS[i]->Integral(); float x = (1-a_pp/a_PbPb)/(1-a_pp); NSfrac.push_back(mode==1 ? x : -1);// = old stupid adding of the signal : 2-x); // cout<<binbounds[i]<<" - "<<binbounds[i+1]<<" = "<<NSfrac[i]<<endl; nsfractrue.push_back(1-hPbPbNSsig[i]->Integral()/hPbPbNS[i]->Integral()); nsfracest.push_back(NSfrac[NSfrac.size()-1]); binmean.push_back((binbounds[i]+binbounds[i+1])/2); } auto c = getc(); TGraph *g = new TGraph(binbounds.size()-1,&binmean[0],&nsfractrue[0]); g->Draw(); SavePlot(c,bjet ? "bjetfractionofNS" : "incfractionofNS"); auto c2 = getc(); TGraph *g2 = new TGraph(binbounds.size()-1,&binmean[0],&nsfracest[0]); g2->Draw(); SavePlot(c2,bjet ? "bjetfractionofNSdata" : "incfractionofNSdata"); ///////////////////////////// DATA: // bin<20 : 0.93 // bin>=20 && bin<60 : 0.84 // bin>=60 : 0.39 //////////////////////////// }
void derivefromNS(bool data = false) { // float shift = mode == 2 ? -2 : mode*2; //mode = 0,1,2 shift = 0,2,-2 // cout<<"shift = "<<shift<<endl; auto file = config.getfile_djt(data ? "dtPbjcl" : "mcPbqcd"); auto nt = (TTree *)file->Get("nt"); for (unsigned i=1;i<binbounds.size();i++) { int b1 = binbounds[i-1]; int b2 = binbounds[i]; seth(71,38,180); //71,38 auto h = geth(Form("h%d%d",b1,b2)); //allowing one more bin for overflow seth(b2-b1,b1,b2); auto hb = geth(Form("hb%d%d",b1,b2)); TString mcappendix = data ? "" : "&& pthat>50";//"&& subid2!=0 && pthat>50"; //"&& pthat>50";//"&& !(subid2==0 && refpt2>20) && pthat>50"; //"&& pthat>80";// //Form("jtpt2+%f",shift) nt->Project(h->GetName(),"jtpt2", Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphi21<1.05 %s)",b1,b2,mcappendix.Data())); nt->Project(hb->GetName(),"bin", Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphi21<1.05 %s)",b1,b2,mcappendix.Data())); ScaleVisibleBins(h,NSfrac[i-1]); h->SetBinContent(1,h->GetBinContent(0)+h->GetBinContent(1)); // auto p = new TProfile(Form("p%d%d",b1,b2),Form("prof"),71,38,180); // nt->Project(p->GetName(),"(subid2 == 0 && refpt2 > 20):jtptSignal2",Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphiSignal21<1.05 && !(subid2==0 && refpt2>20) && pthat>80)",b1,b2)); auto g = getCDFgraph(h); g->GetXaxis()->SetTitle("p_{T,2} threshold [GeV]"); g->GetYaxis()->SetTitle("found fraction"); auto gtemp = getCDFgraph(h); meanb.push_back(hb->GetMean()); prob.push_back(gtemp->Eval(pt)); float c0=g->Eval(50); cout<<"prob at 50: "<<c0<<endl; auto gf = new TFile("graph.root","recreate"); gtemp->Write(); gf->Close(); // auto f = new TF1(Form("f%d%d",b1,b2),"1-[0]*exp(-[1]*(x-40))",40,180); // f->SetParameters(0.1,0.1); // // f->FixParameter(1,0.08); // auto f = new TF1(Form("f%d%d",b1,b2),"TMath::Erf((x-[0])/[1])",40,180); // f->SetParameters(40,10); // f->FixParameter(1,25); auto f = new TF1(Form("f%d%d",b1,b2),"exp(-[0]*exp(-[1]*x))",40,180); f->SetParameters(100,0.1); // f->FixParameter(1,0.11); //!!!!!!!!!! f->SetLineColor(kRed); f->SetLineWidth(2); g->Fit(f,"RM"); fs.push_back(f); binmean.push_back(hb->GetMean()); float median = -1/f->GetParameter(1)*log(-1/f->GetParameter(0)*log(0.5)); Draw({h}); // h->Rebin(2); auto gcoarse = getCDFgraph(h); auto c = getc(); TLatex *Tl = new TLatex(); gcoarse->SetMinimum(0);g->SetMaximum(1); gcoarse->Draw("AP"); f->Draw("same"); Tl->DrawLatexNDC(0.6,0.55,"y=e^{-a e^{-b x} }"); Tl->DrawLatexNDC(0.6,0.50,Form("a = %.1f",f->GetParameter(0))); Tl->DrawLatexNDC(0.6,0.45,Form("b = %.2f",f->GetParameter(1))); Tl->DrawLatexNDC(0.6,0.4,Form("PbPb bin %d-%d",b1,b2)); Tl->DrawLatexNDC(0.6,0.35,Form("median = %.2f",median)); TLine *l1 = new TLine(median,0,median, f->Eval(median)); l1->Draw(); TLine *l2 = new TLine(0,0.5,median, f->Eval(median)); l2->Draw(); // p->SetMarkerColor(kRed); // p->SetMarkerSize(1); // p->Draw("same"); SavePlot(c,Form("fit%d%d",b1,b2));//return; } }
void findtruthpp() { seth(10,0,1); auto hmcppxJTrue = geth("hmcppxJTrue","true;x_{J};Event fractions"); auto hmcppxJTrueTag = geth("hmcppxJTrueTag","true tagged;x_{J};Event fractions"); auto hmcppxJTrueTagCorr = geth("hmcppxJTrueTagCorr","true tagged corrected;x_{J};Event fractions"); TFile *fmcpp = new TFile(config.getFileName_djt("mcppbfa")); Fill(fmcpp,[&] (dict &m) { if (m["pthat"]<pthatcut) return; if (m[pairCodeSB1]!=0) return; // if (m["pthat"]<80) return; // if (m["bProdCode"]!=1) return; float w = m["weight"]*processweight((int)m["bProdCode"]); // float w = m["weight"]; // if (m["bProdCode"]==2) return; float corr = tageffcorrectionpp(m["jtpt1"],m["jteta1"],m[jtptSB],m[jtetaSB]); float wb = w*corr; if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[dphiSB1]>PI23) hmcppxJTrue->Fill(m[jtptSB]/m["jtpt1"],w); if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[dphiSB1]>PI23 && m["discr_csvV1_1"]>0.9 && m[discr_csvV1_SB]>0.9) { hmcppxJTrueTag->Fill(m[jtptSB]/m["jtpt1"],w); hmcppxJTrueTagCorr->Fill(m[jtptSB]/m["jtpt1"],wb); } }); NormalizeAllHists(); plotputmean = true; plotytitle = "Event fractions"; plotdivide = false; // aktstring += "R=0.4 |#eta|<2.0"; // plotsecondline = Form("p_{T,1}>%d GeV, p_{T,2}>%d GeV", (int)pt1cut, (int)pt2cut); // plotthirdline = "#Delta#phi>2/3#pi"; plottextposy = 0.8; plottextposx = 0.2; plotmeanposy = 0.43; plotymax = 0.2; plotymin = 0; plotlegendpos = BottomRight;//TopLeft; aktstring = "pp"; SetMC({hmcppxJTrue,hmcppxJTrueTag,hmcppxJTrueTagCorr}); SetData({hmcppxJTrue}); Draw({hmcppxJTrue,hmcppxJTrueTag,hmcppxJTrueTagCorr}); hmcppxJTrue->SetMinimum(0); hmcppxJTrue->SetMaximum(0.3); hmcppxJTrue->SetLineWidth(2); hmcppxJTrue->SetMarkerStyle(kNone); hmcppxJTrue->SetFillStyle(0); hmcppxJTrueTag->SetMarkerStyle(kOpenCircle); hmcppxJTrueTagCorr->SetMarkerStyle(kOpenSquare); plotymax = 0.3; SetB({hmcppxJTrue,hmcppxJTrueTag,hmcppxJTrueTagCorr}); float xjtrue = hmcppxJTrue->GetMean(); float xjtruetag = hmcppxJTrueTag->GetMean(); float xjtruetagcorr = hmcppxJTrueTagCorr->GetMean(); float exjtrue = hmcppxJTrue->GetMeanError(); float exjtruetag = hmcppxJTrueTag->GetMeanError(); float exjtruetagcorr = hmcppxJTrueTagCorr->GetMeanError(); auto c = getc(); hmcppxJTrue->Draw("hist"); hmcppxJTrueTag->Draw("E1,same"); hmcppxJTrueTagCorr->Draw("E1,same"); plotlegendpos = TopLeft; auto l = getLegend(); l->AddEntry(hmcppxJTrue,Form("b-dijets, #LTx_{J}#GT=%.3f#pm%.3f",xjtrue,exjtrue),"L"); l->AddEntry(hmcppxJTrueTag,Form("uncorrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetag,exjtruetag),"P"); l->AddEntry(hmcppxJTrueTagCorr,Form("corrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetagcorr,exjtruetagcorr),"P"); l->Draw(); TLatex *Tl = new TLatex(); Tl->DrawLatexNDC(0.2, 0.8, aktstring); SavePlot(c,"closurepp"); }
void findtruthPbPb(int binMin, int binMax) { TFile *fmc = new TFile(config.getFileName_djt("mcPbbfa")); buildNamesuffix = TString::Format("_bin_%d_%d",binMin, binMax); // buildTitlesuffix = TString::Format("%d-%d %%",binMin/2, binMax/2); seth(10,0,1); auto hmcPbPbxJTrue = geth("hmcPbPbxJTrue","PbPb true;x_{J};Event fractions"); auto hmcPbPbxJTrueTag = geth("hmcPbPbxJTrueTag","PbPb true tagged;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorr = geth("hmcPbPbxJTrueTagCorr","PbPb true tagged corrected;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorrPt = geth("hmcPbPbxJTrueTagCorrPt","PbPb true tagged corrected pt;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorrEta = geth("hmcPbPbxJTrueTagCorrEta","PbPb true tagged corrected eta;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorrBin = geth("hmcPbPbxJTrueTagCorrBin","PbPb true tagged corrected bin;x_{J};Event fractions"); seth(12,20,140);//10,40,100); auto hpt2true = geth("hpt2true","true;p_{T,2} GeV"); auto hpt2truetag = geth("hpt2truetag","true tagged;p_{T,2} GeV"); auto hpt2truetagovertrue = geth("hpt2truetagovertrue","true tagged/true;p_{T,2} GeV"); auto hpt2truetagcorr = geth("hpt2truetagcorr","true tagged corrected;p_{T,2} GeV"); auto hpt2truetagcorrovertrue = geth("hpt2truetagcorrovertrue","true tagged corrected/true;p_{T,2} GeV"); seth(10,100,200); auto hpt1true = geth("hpt1true","true;p_{T,1} GeV"); auto hpt1truetag = geth("hpt1truetag","true tagged;p_{T,1} GeV"); auto hpt1truetagovertrue = geth("hpt1truetagovertrue","true tagged/true;p_{T,1} GeV"); auto hpt1truetagcorr = geth("hpt1truetagcorr","true tagged corrected;p_{T,1} GeV"); auto hpt1truetagcorrovertrue = geth("hpt1truetagcorrovertrue","true tagged corrected/true;p_{T,1} GeV"); seth(10,0,200); auto hbintrue = geth("hbintrue","true;bin"); auto hbintruetag = geth("hbintruetag","true tagged;bin"); auto hbintruetagovertrue = geth("hbintruetagovertrue","true tagged/true;bin"); auto hbintruetagcorr = geth("hbintruetagcorr","true tagged corrected;bin"); auto hbintruetagcorrovertrue = geth("hbintruetagcorrovertrue","true tagged corrected/true;bin"); seth(20,-2,2); auto heta2true = geth("heta2true","true;#eta_{2}"); auto heta2truetag = geth("heta2truetag","true tagged;#eta_{2}"); auto heta2truetagovertrue = geth("heta2truetagovertrue","true tagged/true;#eta_{2}"); auto heta2truetagcorr = geth("heta2truetagcorr","true tagged corrected;#eta_{2}"); auto heta2truetagcorrovertrue = geth("heta2truetagcorrovertrue","true tagged corrected/true;#eta_{2}"); auto heta1true = geth("heta1true","true;#eta_{1}"); auto heta1truetag = geth("heta1truetag","true tagged;#eta_{1}"); auto heta1truetagovertrue = geth("heta1truetagovertrue","true tagged/true;#eta_{1}"); auto heta1truetagcorr = geth("heta1truetagcorr","true tagged corrected;#eta_{1}"); auto heta1truetagcorrovertrue = geth("heta1truetagcorrovertrue","true tagged corrected/true;#eta_{1}"); unordered_set<int> eventstodiscard = {1805770,1116573,1084397};//, // 5755734,1599758,395810, // 1363321,211625,3195128}; // Fill(fmc,[&] (dict &m) { if (m["bin"]<binMin || m["bin"]>=binMax) return; if (m["pthat"]<pthatcut) return; if (m[pairCodeSB1]!=0) return; // if (m["bProdCode"]>1) return; if (eventstodiscard.find(m["event"])!=eventstodiscard.end()) return; //kill large-weight GSP event float w = m["weight"]*processweight((int)m["bProdCode"]); //because we have only b-dijets float corr = tageffcorrectionPbPb(m["jtpt1"],m["jteta1"],m[jtptSB],m[jtetaSB],m["bin"]); // float corrpt = getPbPbcorrectionPt(m["jtpt1"],m[jtptSB]); // float correta = getPbPbcorrectionEta(m["jteta1"],m[jtetaSB]); // float corrbin = getPbPbcorrectionBin(m["bin"]); float wb = w*corr; if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[refptSB]>20 && m[dphiSB1]>PI23) { hmcPbPbxJTrue->Fill(m[jtptSB]/m["jtpt1"],w); hpt2true->Fill(m[jtptSB],w); hpt1true->Fill(m["jtpt1"],w); heta2true->Fill(m[jtetaSB],w); heta1true->Fill(m["jteta1"],w); hbintrue->Fill(m["bin"],w); } if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[refptSB]>20 && m[dphiSB1]>PI23 && m["discr_csvV1_1"]>0.9 && m[discr_csvV1_SB]>0.9) { // //corrpt *= m[jtptSB] < 60 ? 1./0.7 : 1; //wb *= m[jtptSB] < 60 ? 1./0.7 : 1; hmcPbPbxJTrueTag->Fill(m[jtptSB]/m["jtpt1"],w); hmcPbPbxJTrueTagCorr->Fill(m[jtptSB]/m["jtpt1"],wb); // hmcPbPbxJTrueTagCorrPt->Fill(m[jtptSB]/m["jtpt1"],w*corrpt); // hmcPbPbxJTrueTagCorrEta->Fill(m[jtptSB]/m["jtpt1"],w*corrpt*correta); // hmcPbPbxJTrueTagCorrBin->Fill(m[jtptSB]/m["jtpt1"],w*corrpt*correta*corrbin); hpt2truetag->Fill(m[jtptSB],w); hpt1truetag->Fill(m["jtpt1"],w); heta2truetag->Fill(m[jtetaSB],w); heta1truetag->Fill(m["jteta1"],w); hbintruetag->Fill(m["bin"],w); hpt2truetagcorr->Fill(m[jtptSB],wb); hpt1truetagcorr->Fill(m["jtpt1"],wb); heta2truetagcorr->Fill(m[jtetaSB],wb); heta1truetagcorr->Fill(m["jteta1"],wb); hbintruetagcorr->Fill(m["bin"],wb); } }); NormalizeAllHists(); //plotymax = 9999; aktstring = TString::Format("PbPb %d-%d %%",binMin/2, binMax/2);//TString::Format("PbPb#Delta#phi>2/3#pi %d-%d %%",binMin/2, binMax/2); SetMC({hmcPbPbxJTrue,hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorr}); SetData({hmcPbPbxJTrue}); hmcPbPbxJTrue->SetMinimum(0); hmcPbPbxJTrue->SetMaximum(0.3); hmcPbPbxJTrue->SetLineWidth(2); hmcPbPbxJTrue->SetMarkerStyle(kNone); hmcPbPbxJTrue->SetFillStyle(0); hmcPbPbxJTrueTag->SetMarkerStyle(kOpenCircle); hmcPbPbxJTrueTagCorr->SetMarkerStyle(kOpenSquare); plotymax = 0.3; Draw({hmcPbPbxJTrue,hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorr}); SetB({hmcPbPbxJTrue,hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorr}); float xjtrue = hmcPbPbxJTrue->GetMean(); float xjtruetag = hmcPbPbxJTrueTag->GetMean(); float xjtruetagcorr = hmcPbPbxJTrueTagCorr->GetMean(); float exjtrue = hmcPbPbxJTrue->GetMeanError(); float exjtruetag = hmcPbPbxJTrueTag->GetMeanError(); float exjtruetagcorr = hmcPbPbxJTrueTagCorr->GetMeanError(); auto c = getc(); hmcPbPbxJTrue->Draw("hist"); hmcPbPbxJTrueTag->Draw("E1,same"); hmcPbPbxJTrueTagCorr->Draw("E1,same"); plotlegendpos = TopLeft; auto l = getLegend(); l->AddEntry(hmcPbPbxJTrue,Form("b-dijets, #LTx_{J}#GT=%.3f#pm%.3f",xjtrue,exjtrue),"L"); l->AddEntry(hmcPbPbxJTrueTag,Form("uncorrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetag,exjtruetag),"P"); l->AddEntry(hmcPbPbxJTrueTagCorr,Form("corrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetagcorr,exjtruetagcorr),"P"); l->Draw(); TLatex *Tl = new TLatex(); Tl->DrawLatexNDC(0.2, 0.8, aktstring); SavePlot(c,Form("closure%d%d",binMin,binMax)); // //if (binMin==0 && binMax==200) { // Draw({hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorrPt,hmcPbPbxJTrueTagCorrEta,hmcPbPbxJTrueTagCorrBin}); // SetMC({hpt2truetag,hpt1truetag,heta2truetag,heta1truetag,hbintruetag}); // plotputmean = false; // plotymax = 0.2; // Draw({hpt2true,hpt2truetag,hpt2truetagcorr}); // plotymax = 0.3; // Draw({hpt1true,hpt1truetag,hpt1truetagcorr}); // plotymax = 0.2; // Draw({heta2true,heta2truetag,heta2truetagcorr}); // Draw({heta1true,heta1truetag,heta1truetagcorr}); // plotymax = 1; // Draw({hbintrue,hbintruetag,hbintruetagcorr}); plotymin = 0; plotymax = 0.2; Draw({hpt2truetag,hpt2true}); Draw({hpt2truetagcorr,hpt2true}); hpt2truetagovertrue->Divide(hpt2truetag,hpt2true,1,1); //"B" hpt1truetagovertrue->Divide(hpt1truetag,hpt1true,1,1); //"B" heta2truetagovertrue->Divide(heta2truetag,heta2true,1,1); //"B" heta1truetagovertrue->Divide(heta1truetag,heta1true,1,1); //"B" hbintruetagovertrue->Divide(hbintruetag,hbintrue,1,1); //"B" hpt2truetagcorrovertrue->Divide(hpt2truetagcorr,hpt2true,1,1); //"B" hpt1truetagcorrovertrue->Divide(hpt1truetagcorr,hpt1true,1,1); //"B" heta2truetagcorrovertrue->Divide(heta2truetagcorr,heta2true,1,1); //"B" heta1truetagcorrovertrue->Divide(heta1truetagcorr,heta1true,1,1); //"B" hbintruetagcorrovertrue->Divide(hbintruetagcorr,hbintrue,1,1); //"B" NormalizeAllHists(); Draw({hpt2truetagovertrue,hpt2truetagcorrovertrue}); Draw({hpt1truetagovertrue,hpt1truetagcorrovertrue}); Draw({heta2truetagovertrue,heta2truetagcorrovertrue}); Draw({heta1truetagovertrue,heta1truetagcorrovertrue}); Draw({hbintruetagovertrue,hbintruetagcorrovertrue}); // } }
/** * Place a char at a column and row location on the canvas * @param c, column where the char will be placed * @param r, row where the char will be placed * @param ch, the character that will be placed on the canvas */ void Canvas::put(int c, int r, char ch) { if (r < geth() && c < getw()) grid.at(r).at(c) = ch; }