void makeEfficiency_74X_setBr(bool isPrompt=false, bool isPair=true, bool isEmbedded=true, bool isPtCut = false, bool doWeight = false) { gROOT->Macro("./JpsiStyle.C"); gStyle->SetPaintTextFormat(".3f"); // for text colz //string strDir = "eff_74X_setBr"; // directory name //string strDir = "eff_74X_setBr_wDetached"; // directory name string strDir = "eff_74X_noRegitMuDetached"; // directory name int initev =0; int nevt = -1; //all //int nevt = 1000; int ptbin = 11.; double ptmin = 0.; double ptmax = 11.; if (isEmbedded && !isPrompt) { ptbin = 22.; ptmax = 22.; } int rapbin = 12; double rapmin = -2.4; double rapmax = 2.4; int lxybin = 10; double lxymin = 0.; double lxymax = 1.; string strPrompt; string strEmbd; string strPair; if(isPrompt){ strPrompt = "prompt"; } else { strPrompt = "nonprompt"; } if(isEmbedded){ strEmbd = "embd"; } else { strEmbd = "nonembd"; } if(isPair){ strPair = "Pair"; } else { strPair = "Trk"; } cout << "strPrompt = " << strPrompt.c_str() << endl; cout << "strEmbd = " << strEmbd.c_str() << endl; cout << "strPair = " << strPair.c_str() << endl; ////// read-in file & tree TFile * refFile; if (isEmbedded){ ////// 740pre3 -embd //if (isPrompt){ refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_PromptJpsi_step2nMatch_KYO_regit_embd_20150211.root");} //else { refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_B2JpsiMuMu_step2nMatch_KYO_regit_embd_20150211.root");} ////// 740pre3 -embd with HiDetachedTripletStep //if (isPrompt){ refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_PromptJpsi_step2nMatch_KYO_regit_wDetached_embd_20150224.root");} //else { refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_B2JpsiMuMu_step2nMatch_KYO_regit_wDetached_embd_20150224.root");} ////// 740pre3 - remove some regit : noRegitMuDetached if (isPrompt){ refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_PromptJpsi_step2nMatch_KYO_regit_noRegitMuDetached_embd_20150310.root");} else { refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_B2JpsiMuMu_step2nMatch_KYO_regit_noRegitMuDetached_embd_20150310.root");} } else { //730pre2 -nonembd if (isPrompt){ refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_PromptJpsi_step2nMatch_KYO_regit_20141121.root");} else { refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_B2Jpsi_step2nMatch_KYO_regit_20141203_no9_32_90.root");} } TTree *tr = new TTree(); if(isPair) { tr = (TTree*)refFile->Get("mcmatchanalysis/pnSimRecoPairType1");} else { tr = (TTree*)refFile->Get("mcmatchanalysis/pnSimRecoTrkType1"); } /* //for pT-|y| weight TFile *fWeight; if (isPrompt){ fWeight = new TFile("./pTdist_diffY/pTdist_diffY_prompt.root");} else {fWeight = new TFile("./pTdist_diffY/pTdist_diffY_nonprompt.root");} const int nYBin = 4; TH1D* hWeight[nYBin]; for (int i=0; i< nYBin; i++){ if (isPair) { hWeight[i] = (TH1D*)fWeight->Get(Form("hPairRatio_%d",i)); } else { hWeight[i] = (TH1D*)fWeight->Get(Form("hTrkRatio_%d",i)); }; //cout << i << "th hWeight = " << hWeight[i] << endl; cout << i << "th hWeight Name= " << hWeight[i]->GetName() << endl; } */ /////////////////////////////////////// ////// Pair ////// //gen Float_t pt; Float_t y; Float_t pt1; Float_t eta1; Float_t npixelhits1; Float_t nmuonhits1; Float_t pt2; Float_t eta2; Float_t npixelhits2; Float_t nmuonhits2; //reco Float_t ptreco; Float_t yreco; Float_t minvreco; Float_t ptreco1; Float_t etareco1; Float_t nvalidpixelhitsreco1; Float_t nvalidmuonhitsreco1; Float_t nmatch1; Float_t chi2ndofreco1; Float_t ptreco2; Float_t etareco2; Float_t nvalidpixelhitsreco2; Float_t nvalidmuonhitsreco2; Float_t nmatch2; Float_t chi2ndofreco2; // for lxy Float_t vtxz1; Float_t vtxy1; Float_t bx; Float_t by; ////// Trk (additional)////// //gen Float_t eta; Float_t idparent; Float_t npixelhits; Float_t nmuonhits; //reco Float_t etareco; Float_t nvalidpixelhitsreco; Float_t nvalidmuonhitsreco; Float_t nmatch; Float_t chi2ndofreco; // for lxy Float_t vtxz; Float_t vtxy; /////////////////////////////////////// //Branches /////////////////////////////////////// TBranch *b_pt; TBranch *b_y; TBranch *b_pt1; TBranch *b_eta1; TBranch *b_npixelhits1; TBranch *b_nmuonhits1; TBranch *b_pt2; TBranch *b_eta2; TBranch *b_npixelhits2; TBranch *b_nmuonhits2; //reco TBranch *b_ptreco; TBranch *b_yreco; TBranch *b_minvreco; TBranch *b_ptreco1; TBranch *b_etareco1; TBranch *b_nvalidpixelhitsreco1; TBranch *b_nvalidmuonhitsreco1; TBranch *b_nmatch1; TBranch *b_chi2ndofreco1; TBranch *b_ptreco2; TBranch *b_etareco2; TBranch *b_nvalidpixelhitsreco2; TBranch *b_nvalidmuonhitsreco2; TBranch *b_nmatch2; TBranch *b_chi2ndofreco2; // for lxy TBranch *b_vtxz1; TBranch *b_vtxy1; TBranch *b_bx; TBranch *b_by; ////// Trk (additional)////// //gen TBranch *b_eta; TBranch *b_idparent; TBranch *b_npixelhits; TBranch *b_nmuonhits; //reco TBranch *b_etareco; TBranch *b_nvalidpixelhitsreco; TBranch *b_nvalidmuonhitsreco; TBranch *b_nmatch; TBranch *b_chi2ndofreco; // for lxy TBranch *b_vtxz; TBranch *b_vtxy; /////////////////////////////////////// //BranchAddress /////////////////////////////////////// tr->SetBranchAddress("pt",&pt,&b_pt); tr->SetBranchAddress("ptreco",&ptreco,&b_ptreco); tr->SetBranchAddress("bx",&bx,&b_bx); tr->SetBranchAddress("by",&by,&b_by); if (isPair) { tr->SetBranchAddress("y",&y,&b_y); tr->SetBranchAddress("pt1",&pt1,&b_pt1); tr->SetBranchAddress("eta1",&eta1,&b_eta1); tr->SetBranchAddress("npixelhits1",&npixelhits1,&b_npixelhits1); tr->SetBranchAddress("nmuonhits1",&nmuonhits1,&b_nmuonhits1); tr->SetBranchAddress("pt2",&pt2,&b_pt2); tr->SetBranchAddress("eta2",&eta2,&b_eta2); tr->SetBranchAddress("npixelhits2",&npixelhits2,&b_npixelhits2); tr->SetBranchAddress("nmuonhits2",&nmuonhits2,&b_nmuonhits2); tr->SetBranchAddress("yreco",&yreco,&b_yreco); tr->SetBranchAddress("minvreco",&minvreco,&b_minvreco); tr->SetBranchAddress("ptreco1",&ptreco1,&b_ptreco1); tr->SetBranchAddress("etareco1",&etareco1,&b_etareco1); tr->SetBranchAddress("nvalidpixelhitsreco1",&nvalidpixelhitsreco1,&b_nvalidpixelhitsreco1); tr->SetBranchAddress("nvalidmuonhitsreco1",&nvalidmuonhitsreco1,&b_nvalidmuonhitsreco1); tr->SetBranchAddress("nmatch1",&nmatch1,&b_nmatch1); tr->SetBranchAddress("chi2ndofreco1",&chi2ndofreco1,&b_chi2ndofreco1); tr->SetBranchAddress("ptreco2",&ptreco2,&b_ptreco2); tr->SetBranchAddress("etareco2",&etareco2,&b_etareco2); tr->SetBranchAddress("nvalidpixelhitsreco2",&nvalidpixelhitsreco2,&b_nvalidpixelhitsreco2); tr->SetBranchAddress("nvalidmuonhitsreco2",&nvalidmuonhitsreco2,&b_nvalidmuonhitsreco2); tr->SetBranchAddress("nmatch2",&nmatch2,&b_nmatch2); tr->SetBranchAddress("chi2ndofreco2",&chi2ndofreco2,&b_chi2ndofreco2); tr->SetBranchAddress("vtxz1",&vtxz1,&b_vtxz1); tr->SetBranchAddress("vtxy1",&vtxy1,&b_vtxy1); } else { tr->SetBranchAddress("eta",&eta,&b_eta); tr->SetBranchAddress("etareco",&etareco,&b_etareco); tr->SetBranchAddress("idparent",&idparent,&b_idparent); tr->SetBranchAddress("npixelhits",&npixelhits,&b_npixelhits); tr->SetBranchAddress("nmuonhits",&nmuonhits,&b_nmuonhits); tr->SetBranchAddress("nvalidpixelhitsreco",&nvalidpixelhitsreco,&b_nvalidpixelhitsreco); tr->SetBranchAddress("nvalidmuonhitsreco",&nvalidmuonhitsreco,&b_nvalidmuonhitsreco); tr->SetBranchAddress("nmatch",&nmatch,&b_nmatch); tr->SetBranchAddress("chi2ndofreco",&chi2ndofreco,&b_chi2ndofreco); tr->SetBranchAddress("vtxz",&vtxz,&b_vtxz); tr->SetBranchAddress("vtxy",&vtxy,&b_vtxy); } //2D hist. just check TH2D* hGenPtY = new TH2D("hGenPtY","hGenPtY",50,rapmin,rapmax,50,ptmin,ptmax); TH2D* hRecoPtY = new TH2D("hRecoPtY","hRecoPtY",50,rapmin,rapmax,50,ptmin,ptmax); TH2D* hEffPtY = new TH2D("hEffPtY","hEffPtY",50,rapmin,rapmax,50,ptmin,ptmax); TH1D* hGenPt = new TH1D("hGenPt","hGenPt",ptbin,ptmin,ptmax); TH1D* hRecoPt = new TH1D("hRecoPt","hRecoPt",ptbin,ptmin,ptmax); TH1D* hEffPt = new TH1D("hEffPt","hEffPt",ptbin,ptmin,ptmax); TH1D* hGenRap = new TH1D("hGenRap","hGenRap",rapbin,rapmin,rapmax); TH1D* hRecoRap = new TH1D("hRecoRap","hRecoRap",rapbin,rapmin,rapmax); TH1D* hEffRap = new TH1D("hEffRap","hEffRap",rapbin,rapmin,rapmax); TH1D* hGenLxy = new TH1D("hGenLxy","hGenLxy",lxybin,lxymin,lxymax); TH1D* hRecoLxy = new TH1D("hRecoLxy","hRecoLxy",lxybin,lxymin,lxymax); TH1D* hEffLxy = new TH1D("hEffLxy","hEffLxy",lxybin,lxymin,lxymax); hGenPtY->Sumw2(); hRecoPtY->Sumw2(); hEffPtY->Sumw2(); hGenPt->Sumw2(); hRecoPt->Sumw2(); hEffPt->Sumw2(); hGenRap->Sumw2(); hRecoRap->Sumw2(); hEffRap->Sumw2(); hGenLxy->Sumw2(); hRecoLxy->Sumw2(); hEffLxy->Sumw2(); //event loop start if(nevt == -1) nevt = tr->GetEntries(); for (int iev=initev; iev<nevt; iev++){ tr->GetEntry(iev); bool yngen = false; bool ynreco = false; float weightF = 1.; float lxy = -531.; /// give a cut to Gen and Reco separately if (isPair) { if (isPtCut) { if ( !(pt<15.) ) continue; } /// define IP lxy = TMath::Sqrt((vtxz1-bx)*(vtxz1-bx)+(vtxy1-by)*(vtxy1-by)); if (kineCut(pt1,eta1) && kineCut(pt2,eta2) && idCut(npixelhits1,nmuonhits1) && idCut(npixelhits2,nmuonhits2) ) { yngen=true; } if (kineCut(ptreco1,etareco1) && kineCut(ptreco2,etareco2) && idCut(nvalidpixelhitsreco1,nvalidmuonhitsreco1) && idCut(nvalidpixelhitsreco2,nvalidmuonhitsreco2) //&& idRecoCut(nmatch1, chi2ndofreco1) //&& idRecoCut(nmatch2, chi2ndofreco2) && chi2ndofreco1 < 4. && chi2ndofreco2 < 4. && massCut(minvreco) ) { ynreco=true;} } else { if (isPtCut) { if (!(pt >1. && pt<15. ) ) continue; } /// define IP lxy = TMath::Sqrt((vtxz-bx)*(vtxz-bx)+(vtxy-by)*(vtxy-by)); if ( (!isEmbedded) && TMath::Abs(eta) < 2.4 && TMath::Abs(idparent)>442 && TMath::Abs(idparent)<550 && idCut(npixelhits,nmuonhits) ) { yngen=true; } else if ( isEmbedded && TMath::Abs(eta) < 2.4 //&& TMath::Abs(idparent)>442 //&& TMath::Abs(idparent)<550 && idCut(npixelhits,nmuonhits) ) { yngen=true; } if ( (!isEmbedded) //TMath::Abs(etareco) < 2.4 && TMath::Abs(eta) < 2.4 && TMath::Abs(idparent)>442 && TMath::Abs(idparent)<550 && idCut(nvalidpixelhitsreco,nvalidmuonhitsreco) && idRecoCut(nmatch, chi2ndofreco) ) { ynreco=true;} else if ( isEmbedded //TMath::Abs(etareco) < 2.4 && TMath::Abs(eta) < 2.4 //&& TMath::Abs(idparent)>442 //&& TMath::Abs(idparent)<550 && idCut(nvalidpixelhitsreco,nvalidmuonhitsreco) && idRecoCut(nmatch, chi2ndofreco) ) { ynreco=true;} } /// weight if "doWeight" && fill the histogram if (isPair){ if (doWeight) {weightF = getWeight(isPrompt, isPair, pt,y);} // cout << "weightF = " <<weightF << endl; if (yngen) { hGenPtY->Fill(y,pt,weightF); hGenPt->Fill(pt,weightF); hGenRap->Fill(y,weightF); hGenLxy->Fill(lxy,weightF); } if (ynreco) { hRecoPtY->Fill(yreco,ptreco,weightF); hRecoPt->Fill(ptreco, weightF); hRecoRap->Fill(yreco, weightF); hRecoLxy->Fill(lxy, weightF); } }else { if (doWeight) {weightF = getWeight(isPrompt, isPair, pt,eta);} // cout << "weightF = " <<weightF << endl; if (yngen) { hGenPtY->Fill(eta,pt,weightF); hGenPt->Fill(pt,weightF); hGenRap->Fill(eta,weightF); hGenLxy->Fill(lxy,weightF); } if (ynreco) { hRecoPtY->Fill(etareco,ptreco,weightF); hRecoPt->Fill(ptreco,weightF); hRecoRap->Fill(etareco,weightF); hRecoLxy->Fill(lxy, weightF); } } }// end of event loop cout << "hGenPt integral = " << hGenPt->Integral() << endl; cout << "hRecoPt integral = " << hRecoPt->Integral() << endl; cout << "hGenRap integral = " << hGenRap->Integral() << endl; cout << "hRecoRap integral = " << hRecoRap->Integral() << endl; cout << "hGenLxy integral = " << hGenLxy->Integral() << endl; cout << "hRecoLxy integral = " << hRecoLxy->Integral() << endl; //calculate efficiency hEffPtY->Divide(hRecoPtY,hGenPtY,1,1,"b"); hEffPt->Divide(hRecoPt,hGenPt,1,1,"b"); hEffRap->Divide(hRecoRap,hGenRap,1,1,"b"); hEffLxy->Divide(hRecoLxy,hGenLxy,1,1,"b"); //Legend TLegend *legUR = new TLegend(0.56,0.68,0.90,0.90,NULL,"brNDC"); TLegend *legUL = new TLegend(0.17,0.68,0.51,0.90,NULL,"brNDC"); TLegend *legBM = new TLegend(0.40,0.20,0.75,0.35,NULL,"brNDC"); TLegend *legBR = new TLegend(0.56,0.20,0.90,0.42,NULL,"brNDC"); SetLegendStyle(legUR); SetLegendStyle(legUL); SetLegendStyle(legBM); SetLegendStyle(legBR); TCanvas *c1 = new TCanvas("c1","c1",600,600); //draw 2D Pt-y TPaletteAxis* pal; hEffPtY->SetMinimum(0.0); hEffPtY->SetMaximum(1.0); if (isPair) hEffPtY->GetXaxis()->SetTitle("y"); else hEffPtY->GetXaxis()->SetTitle("#eta"); hEffPtY->GetXaxis()->CenterTitle(); hEffPtY->GetYaxis()->SetTitle("p_{T} (GeV)"); hEffPtY->Draw("colz"); c1->Update(); pal = (TPaletteAxis*)hEffPtY->GetListOfFunctions()->FindObject("palette"); pal->SetX2NDC(0.92); c1->Modified(); c1->Update(); c1->SaveAs(Form("%s/EffPtY_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.pdf",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str())); c1->Clear(); //draw EffPt SetHistStyle(hEffPt,3,0); hEffPt->SetMinimum(0.0); hEffPt->SetMaximum(1.0); if (isPair) hEffPt->GetXaxis()->SetTitle("Pair p_{T} (GeV)"); else hEffPt->GetXaxis()->SetTitle("Trk p_{T} (GeV)"); hEffPt->GetYaxis()->SetTitle("Efficiency"); hEffPt->Draw("pe"); c1->SaveAs(Form("%s/EffPt_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.pdf",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str())); c1->Clear(); //draw EffRap SetHistStyle(hEffRap,3,0); hEffRap->SetMinimum(0.0); hEffRap->SetMaximum(1.0); if (isPair) hEffRap->GetXaxis()->SetTitle("y"); else hEffRap->GetXaxis()->SetTitle("#eta"); hEffRap->GetXaxis()->CenterTitle(); hEffRap->GetYaxis()->SetTitle("Efficiency"); hEffRap->Draw("pe"); c1->SaveAs(Form("%s/EffRap_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.pdf",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str())); c1->Clear(); //draw EffLxy SetHistStyle(hEffLxy,3,0); hEffLxy->SetMinimum(0.0); hEffLxy->SetMaximum(1.0); hEffLxy->GetXaxis()->SetTitle("Lxy"); hEffLxy->GetYaxis()->SetTitle("Efficiency"); hEffLxy->Draw("pe"); c1->SaveAs(Form("%s/EffLxy_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.pdf",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str())); c1->Clear(); //save as a root file TFile* outFile = new TFile(Form("%s/Eff_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.root",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str()),"RECREATE"); outFile->cd(); hGenPtY->Write(); hRecoPtY->Write(); hEffPtY->Write(); hGenPt->Write(); hGenRap->Write(); hGenLxy->Write(); hRecoPt->Write(); hRecoRap->Write(); hRecoLxy->Write(); hEffPt->Write(); hEffRap->Write(); hEffLxy->Write(); outFile->Close(); return; }
void printEff(TTree* HltTree,const char *cut,const char *title, char *projectTitle) { cout <<" * "<<title<<":"<<endl; cout <<" * Efficiencies:"<<endl; double nEvt = HltTree->GetEntries(cut); cout <<" | "<<setw(20)<<"HLT Path"; cout <<" | "<<setw(25)<<"Efficiency"; cout <<" | "<<endl; triggers->clear(); triggerCuts->clear(); vector <double*> effs; // calculate the efficiency // effs.push_back(calcEff(HltTree,"L1Tech_BSC_OR",nEvt,Form("(%s)&&L1Tech_BSC_minBias_OR.v0==1",cut))); effs.push_back(calcEff(HltTree,"L1Tech_BSC_thr1",nEvt,Form("(%s)&&L1Tech_BSC_minBias_threshold1.v0==1",cut))); effs.push_back(calcEff(HltTree,"L1Tech_BSC_thr2",nEvt,Form("(%s)&&L1Tech_BSC_minBias_threshold2.v0==1",cut))); effs.push_back(calcEff(HltTree,"L1Tech_BSC_inner_thr1",nEvt,Form("(%s)&&L1Tech_BSC_minBias_inner_threshold1.v0==1",cut))); effs.push_back(calcEff(HltTree,"L1Tech_BSC_inner_thr2",nEvt,Form("(%s)&&L1Tech_BSC_minBias_inner_threshold2.v0==1",cut))); effs.push_back(calcEff(HltTree,"L1Tech_HF_coinc_PM",nEvt,Form("(%s)&&L1Tech_HCAL_HF_coincidence_PM.v0==1",cut))); effs.push_back(calcEff(HltTree,"HLT_MBPixel_1Track",nEvt,Form("(%s)&&HLT_MinBiasPixel_SingleTrack==1",cut))); //effs.push_back(calcEff(HltTree,"L1Tech_BSC_splash_beam1.v0",nEvt,Form("(%s)&&L1Tech_BSC_splash_beam1.v0==1",cut))); //effs.push_back(calcEff(HltTree,"L1Tech_BSC_splash_beam2.v0",nEvt,Form("(%s)&&L1Tech_BSC_splash_beam2.v0==1",cut))); //effs.push_back(calcEff(HltTree,"All",nEvt,Form("(%s)&&(L1Tech_BSC_minBias_threshold1.v0||L1Tech_BSC_minBias_threshold2.v0||L1Tech_BSC_minBias_OR.v0||L1Tech_BSC_minBias_inner_threshold1.v0||L1Tech_BSC_minBias_inner_threshold2.v0||L1Tech_BSC_splash_beam1.v0||L1Tech_BSC_splash_beam2.v0)",cut))); results->push_back(effs); cout <<" * Correlation Matrix:"<<endl; int tsize = (int)triggers->size(); TH2D *h = new TH2D(Form("h%s",title),"",tsize,0,tsize,tsize,0,tsize); TH2D *hct = new TH2D(Form("h%s_ct",title),"",tsize,0,tsize,tsize,0,tsize); for (int i=tsize-1;i>=0;i--){ int nEvtAfterCut = HltTree->GetEntries((*triggerCuts)[i].c_str()); h->GetXaxis()->SetBinLabel(i+1,(*triggers)[i].c_str()); h->GetYaxis()->SetBinLabel(i+1,(*triggers)[i].c_str()); hct->GetXaxis()->SetBinLabel(i+1,(*triggers)[i].c_str()); hct->GetYaxis()->SetBinLabel(i+1,(*triggers)[i].c_str()); for (int j=0;j<tsize;j++){ string cut ="("+(*triggerCuts)[i]+")&&("+(*triggerCuts)[j]+")"; double* eff = calcEff(HltTree,"",nEvtAfterCut,Form("%s",cut.c_str()),0); if (nEvtAfterCut==0) eff[0]=0; h->SetBinContent(i+1,j+1,int(eff[0]*100000)/1000.); hct->SetBinContent(i+1,j+1,HltTree->GetEntries(cut.c_str())); } } h->GetXaxis()->LabelsOption("v"); hct->GetXaxis()->LabelsOption("v"); TCanvas *c1 = new TCanvas(Form("c%s",title), Form("c_%s",title),800,600); c1->Range(-3.609756,-1.910995,12.7561,10.60209); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetBorderSize(0); c1->SetTickx(); c1->SetTicky(); c1->SetLeftMargin(0.25); c1->SetRightMargin(0.1684054); c1->SetTopMargin(0.02); c1->SetBottomMargin(0.3); c1->SetFrameLineColor(0); c1->SetFrameBorderMode(0); c1->SetFrameLineColor(0); c1->SetFrameBorderMode(0); h->Draw("col text"); TPaletteAxis *palette = new TPaletteAxis(tsize*1.02,0,tsize*1.1,tsize,h); palette->SetLabelColor(1); palette->SetLabelFont(42); palette->SetLabelOffset(0.005); palette->SetLabelSize(0.045); palette->SetTitleOffset(1); palette->SetTitleSize(0.04); palette->SetFillColor(100); palette->SetFillStyle(1001); h->GetListOfFunctions()->Add(palette,"br"); h->Draw("col text z"); string fname(Form("plot_%s_%s.gif",projectTitle,title)); c1->SaveAs(fname.c_str()); c1->SaveAs(Form("plot_%s_%s.C",projectTitle,title)); cout <<"<img src=\"%ATTACHURLPATH%/"<<fname<<"\" alt=\""<<fname<<"\" width='671' height='478' />"<<endl; }
void MakeBioluminescencePlots(){ gStyle->SetOptStat(0); gStyle->SetCanvasColor(0); gStyle->SetPadColor(0); gStyle->SetPadBorderMode(0); gStyle->SetCanvasBorderMode(0); gStyle->SetFrameBorderMode(0); gStyle->SetLabelSize(0.03,"x"); gStyle->SetLabelSize(0.03,"y"); gStyle->SetLabelFont(42,"x"); gStyle->SetLabelFont(42,"y"); gStyle->SetOptStat(1111); ////////////// DECLARES HISTOGRAMS ///////////////////////////////////////////////////////////// TH2D * histXY = new TH2D("histXY","",200,-15,15,200,-15,15); ///////////////////// DECLARES CHAINS //////////////////////////////////////////////////////////// TChain *chain1 = new TChain("OpticalData",""); ///////////////////////////// ADDS NTUPLES TO CHAINS //////////////////////////////////////////// chain1->Add("./Bioluminescence_skin.root/OpticalData"); //////////////////////////////////// MAKES SELECTIONS IN EACH CHAIN //////////////////////////////////////////////////////////// chain1->Draw("CrystalLastHitPos_Y:CrystalLastHitPos_X>>histXY","CrystalLastHitPos_Z == 30.0 && CrystalLastHitEnergy > 0.0","goff"); TCanvas *XY = new TCanvas("XY", " ",0,22,800,802); XY->Range(-125,-125,125,125); XY->SetGridx(); XY->SetGridy(); XY->SetTickx(1); XY->SetTicky(1); XY->SetFrameBorderMode(0); XY->SetFrameBorderMode(0); XY->SetFillColor(kWhite); TPaletteAxis *palette = new TPaletteAxis(13.23807,-14.97093,14.93405,15.01938,histXY); palette->SetLabelColor(1); palette->SetLabelFont(62); palette->SetLabelOffset(0.005); palette->SetLabelSize(0.02); palette->SetTitleOffset(1); palette->SetTitleSize(0.04); palette->SetFillColor(0); palette->SetFillStyle(1001); histXY->GetListOfFunctions()->Add(palette,"br"); histXY->GetXaxis()->SetTitle("x-position(mm)"); histXY->GetXaxis()->SetLabelFont(42); histXY->GetXaxis()->SetTitleFont(42); histXY->GetYaxis()->SetTitle("y-position(mm)"); histXY->GetYaxis()->SetLabelFont(42); histXY->GetYaxis()->SetTitleOffset(1.43); histXY->GetYaxis()->SetTitleFont(42); histXY->Draw("colz"); histXY->GetXaxis()->SetTitleSize(0.03); histXY->GetYaxis()->SetTitleSize(0.03); histXY->GetXaxis()->SetLabelSize(0.03); histXY->GetYaxis()->SetLabelSize(0.03); XY->Modified(); XY->cd(); XY->SetSelected(XY); }
// ----------------------------------------------------------------------------- // Create plots void plot( std::string& path, std::string& type, std::string& sample, std::string& dir, std::string& histo, double lumi, bool scale ) { std::string canvas_name = histo + "_" + dir + "_" + type + "_" + sample; // Create canvas TCanvas* canvas = new TCanvas(canvas_name.c_str(),""); canvas->SetFillColor(0); canvas->SetFrameBorderMode(0); canvas->SetFrameFillColor(0); canvas->SetTopMargin(0.10); canvas->SetBottomMargin(0.12); canvas->SetLeftMargin(0.12); canvas->SetRightMargin(0.15); // Retrieve histogram std::string file_name = path + type + "_" + sample + ".root"; TFile* f = new TFile(file_name.c_str(),"READ"); TDirectory* d = (TDirectory*)f->Get(dir.c_str()); TH2D* his = (TH1*)d->Get(histo.c_str()); if ( !his ) return; //his->Rebin2D(2,2); if ( true ) { gPad->SetLogz(); } if ( scale ) his->Scale( lumi / 100. ); his->SetMaximum(1.e4); his->SetMinimum(1.e-5); //his->SetMinimum( his->GetMinimum(1.e-12) ); // his->SetMaximum( 20000. ); // his->SetMinimum( 2.e-4 ); // his->SetMaximum( 20000. ); // his->SetMinimum( 20. ); double xmin = his->GetXaxis()->GetXmin(); double xmax = his->GetXaxis()->GetXmax(); double ymin = his->GetYaxis()->GetXmin(); double ymax = his->GetYaxis()->GetXmax(); // Reset title std::string title = ";" + std::string(his->GetXaxis()->GetTitle()) + ";" + std::string(his->GetYaxis()->GetTitle()); his->SetTitle(title.c_str()); his->GetXaxis()->SetTitle("x_{2}"); his->GetXaxis()->SetTitleOffset(1.2); his->GetYaxis()->SetTitle("x_{1}"); his->GetYaxis()->SetTitleOffset(1.4); his->Draw("COLZ"); gPad->Update(); // Lumi if (1) { std::stringstream ss; ss << "#int L dt = " << lumi << " pb^{-1}"; double xpos = 0.05 * (xmax-xmin)+xmin; double ypos = 0.25 * (ymax-ymin)+ymin; TLatex* text1 = new TLatex(xpos,ypos,ss.str().c_str()); text1->SetTextAlign(12); text1->SetTextSize(0.035); text1->Draw(); } // Jet type if (1) { double xpos = 0.05 * (xmax-xmin)+xmin; double ypos = 0.15 * (ymax-ymin)+ymin; TText* text2 = new TText(xpos,ypos,type.c_str()); text2->SetTextAlign(12); text2->SetTextSize(0.035); text2->Draw(); } // Sample if (1) { double xpos = 0.05 * (xmax-xmin)+xmin; double ypos = 0.10 * (ymax-ymin)+ymin; TText* text3 = new TText(xpos,ypos,sample.c_str()); text3->SetTextAlign(12); text3->SetTextSize(0.035); text3->Draw(); } // Stats gStyle->SetOptStat("i"); his->SetStats(1); TPaveStats* stats = (TPaveStats*)his->GetListOfFunctions()->FindObject("stats"); std::string stats_pos = "br"; if ( stats ) { stats->SetFillColor(0); stats->SetLineColor(0); stats->SetShadowColor(0); if ( stats_pos == "tr" ) { stats->SetX1NDC(0.60); stats->SetY1NDC(0.68); stats->SetX2NDC(0.83); stats->SetY2NDC(0.88); } else if ( stats_pos == "br" ) { stats->SetX1NDC(0.60); stats->SetY1NDC(0.18); stats->SetX2NDC(0.83); stats->SetY2NDC(0.28); } else { stats->SetX1NDC(0.60); stats->SetY1NDC(0.68); stats->SetX2NDC(0.83); stats->SetY2NDC(0.88); } } // Scale gStyle->SetPalette(1); TPaletteAxis* palette = (TPaletteAxis*)his->GetListOfFunctions()->FindObject("palette"); if ( palette ) { palette->SetY1NDC(0.2); palette->SetY2NDC(0.8); } canvas->Modified(); canvas->cd(); canvas->SetSelected(canvas); canvas->SaveAs(std::string(canvas_name+".png").c_str()); //canvas->Write(); }