TProfile* getPlot(TProfile *h1, char *var, TCut cut, char *filename, char* treeName) { TFile *inf = new TFile(filename); TTree *t = (TTree*)inf->FindObjectAny(treeName); TProfile * tmp = (TProfile*)h1->Clone(); tmp->SetName("tmp"); t->Draw(Form("%s>>tmp",var),cut); return tmp; }
void plotQApid(Int_t ic,Float_t pt,Int_t addbin){ char name[100]; char stringa[200]; LoadLib(); snprintf(name,100,"AnalysisResults.root"); if(!fo) fo = new TFile(name); snprintf(name,100,"contVZEROv2"); TList *cont = (TList *) fo->Get(name); AliFlowVZEROResults *pidqa = cont->FindObject("qaPID"); Float_t xval[2] = {2.,pt+0.00001}; Float_t xval2[2] = {2.+addbin,pt+0.00001}; TProfile *proTPCpi = pidqa->GetV2(0,xval,xval2); TProfile *proTOFpi = pidqa->GetV2(1,xval,xval2); TProfile *proTPCka = pidqa->GetV2(2,xval,xval2); TProfile *proTOFka = pidqa->GetV2(3,xval,xval2); TProfile *proTPCpr = pidqa->GetV2(4,xval,xval2); TProfile *proTOFpr = pidqa->GetV2(5,xval,xval2); proTPCpi->SetName("hPiTPC"); proTOFpi->SetName("hPiTOF"); proTPCka->SetName("hKaTPC"); proTOFka->SetName("hKaTOF"); proTPCpr->SetName("hPrTPC"); proTOFpr->SetName("hPrTOF"); proTPCpi->GetXaxis()->SetTitle("dE/dx - dE/dx_{calc}^{#pi} (a.u)"); proTOFpi->GetXaxis()->SetTitle("t_{tof} - t_{calc}^{#pi} (ps)"); proTPCka->GetXaxis()->SetTitle("dE/dx - dE/dx_{calc}^{K} (a.u)"); proTOFka->GetXaxis()->SetTitle("t_{tof} - t_{calc}^{K} (ps)"); proTPCpr->GetXaxis()->SetTitle("dE/dx - dE/dx_{calc}^{p} (a.u)"); proTOFpr->GetXaxis()->SetTitle("t_{tof} - t_{calc}^{p} (ps)"); TCanvas *c = new TCanvas("cVproj","cVproj"); c->Divide(2,3); c->cd(1); proTPCpi->Draw(); c->cd(2); proTOFpi->Draw(); c->cd(3); proTPCka->Draw(); c->cd(4); proTOFka->Draw(); c->cd(5); proTPCpr->Draw(); c->cd(6); proTOFpr->Draw(); }
TProfile *extractFlowVZEROsingle(Int_t icentr,Int_t spec,Int_t arm,Bool_t isMC,Float_t pTh,Int_t addbin,const char *nameSp,Float_t detMin,Float_t detMax,Int_t chMin,Int_t chMax){ LoadLib(); pTh += 0.00001; // NUA correction currently are missing char name[100]; char stringa[200]; snprintf(name,100,"AnalysisResults.root"); if(!fo) fo = new TFile(name); snprintf(name,100,"contVZEROv%i",arm); TList *cont = (TList *) fo->Get(name); cont->ls(); Float_t xMin[5] = {icentr/*centrality bin*/,chMin/*charge*/,pTh/*prob*/,-TMath::Pi()/arm/*Psi*/,detMin/*PID mask*/}; Float_t xMax[5] = {icentr+addbin,chMax,1.0,TMath::Pi()/arm,detMax}; cont->ls(); TProfile *p1 = cont->At(2); TProfile *p2 = cont->At(3); TProfile *p3 = cont->At(4); TH2F *hPsi2DA = cont->At(5); TH2F *hPsi2DC = cont->At(6); TH1D *hPsiA = hPsi2DA->ProjectionY("PsiA",icentr+1,icentr+addbin+1); TH1D *hPsiC = hPsi2DC->ProjectionY("PsiC",icentr+1,icentr+addbin+1); if(!fPsi) fPsi = new TF1("fPsi","pol0",-TMath::Pi()/arm,TMath::Pi()/arm); hPsiA->Fit(fPsi,"0"); Float_t offsetA = fPsi->GetParameter(0); hPsiC->Fit(fPsi,"0"); Float_t offsetC = fPsi->GetParameter(0); Int_t nbinPsi = hPsiA->GetNbinsX(); Float_t *NUAcorrA = new Float_t[nbinPsi]; Float_t *NUAcorrC = new Float_t[nbinPsi]; for(Int_t i=0;i < nbinPsi;i++){ NUAcorrA[i] = offsetA/(hPsiA->GetBinContent(i+1)); NUAcorrC[i] = offsetC/(hPsiC->GetBinContent(i+1)); } Float_t res1=0,res2=0,res3=0; Float_t eres1=0,eres2=0,eres3=0; for(Int_t i = icentr; i <= icentr+addbin;i++){ if(p1->GetBinError(i+1)){ eres1 += 1./p1->GetBinError(i+1)/p1->GetBinError(i+1); res1 += p1->GetBinContent(i+1)/p1->GetBinError(i+1)/p1->GetBinError(i+1); } if(p2->GetBinError(i+1)){ eres2 += 1./p2->GetBinError(i+1)/p2->GetBinError(i+1); res2 += p2->GetBinContent(i+1)/p2->GetBinError(i+1)/p2->GetBinError(i+1); } if(p3->GetBinError(i+1)){ eres3 += 1./p3->GetBinError(i+1)/p3->GetBinError(i+1); res3 += p3->GetBinContent(i+1)/p3->GetBinError(i+1)/p3->GetBinError(i+1); } } res1 /= eres1; res2 /= eres2; res3 /= eres3; eres1 = sqrt(1./eres1); eres2 = sqrt(1./eres2); eres3 = sqrt(1./eres3); AliFlowVZEROResults *a = (AliFlowVZEROResults *) cont->At(0); AliFlowVZEROResults *b = (AliFlowVZEROResults *) cont->At(1); TProfile *pp,*pp2; if(kNUAcorr){ // with NUA corrections pp = a->GetV2reweight(spec,xMin,xMax,3,NUAcorrA); pp2 = b->GetV2reweight(spec,xMin,xMax,3,NUAcorrC); } else{ pp = a->GetV2(spec,xMin,xMax); pp2 = b->GetV2(spec,xMin,xMax); } Float_t scaling = sqrt(res1*res3/res2); if(kVZEROrescorr){ pp->Scale(1./scaling); } Float_t err1_2 = eres1*eres1/res1/res1/4 + eres2*eres2/res2/res2/4 + eres3*eres3/res3/res3/4; Float_t err2_2 = err1_2; err1_2 /= scaling*scaling; printf("resolution V0A = %f +/- %f\n",scaling,err1_2); scaling = sqrt(res2*res3/res1); err2_2 /= scaling*scaling; if(kVZEROrescorr){ pp2->Scale(1./scaling); } printf("resolution V0C =%f +/- %f\n",scaling,err2_2); pp->SetName("V0A"); pp2->SetName("V0C"); if(! kCleanMemory){ new TCanvas(); pp->Draw(); pp2->Draw("SAME"); } TProfile *pData = new TProfile(*pp); pData->Add(pp2); snprintf(stringa,100,"%sData",nameSp); pData->SetName(stringa); TProfile *pMc = NULL; TProfile *ppMC; TProfile *ppMC2; if(isMC){ snprintf(name,100,"contVZEROmc"); cont = (TList *) fo->Get(name); cont->ls(); if(arm == 2){ AliFlowVZEROResults *c = (AliFlowVZEROResults *) cont->At(0); if(! kCleanMemory) c->GetV2(spec,xMin,xMax)->Draw("SAME"); } AliFlowVZEROResults *cA; if(fo->Get("contVZEROv2")) cA = (AliFlowVZEROResults *) cont->At(1+2*(arm==3)); else cA = (AliFlowVZEROResults *) cont->At(0); AliFlowVZEROResults *cC; if(fo->Get("contVZEROv2")) cC = (AliFlowVZEROResults *) cont->At(2+2*(arm==3)); else cC = (AliFlowVZEROResults *) cont->At(1); TProfile *p1mc = cont->At(5+3*(arm==3)); TProfile *p2mc = cont->At(6+3*(arm==3)); TProfile *p3mc = cont->At(7+3*(arm==3)); Float_t resMC1=0,resMC2=0,resMC3=0; Float_t eresMC1=0,eresMC2=0,eresMC3=0; for(Int_t i = icentr; i <= icentr+addbin;i++){ if(p1mc->GetBinError(i+1)){ eresMC1 += 1./p1mc->GetBinError(i+1)/p1mc->GetBinError(i+1); resMC1 += p1mc->GetBinContent(i+1)/p1mc->GetBinError(i+1)/p1mc->GetBinError(i+1); } if(p2mc->GetBinError(i+1)){ eresMC2 += 1./p2mc->GetBinError(i+1)/p2mc->GetBinError(i+1); resMC2 += p2mc->GetBinContent(i+1)/p2mc->GetBinError(i+1)/p2mc->GetBinError(i+1); } if(p3mc->GetBinError(i+1)){ eresMC3 += 1./p3mc->GetBinError(i+1)/p3mc->GetBinError(i+1); resMC3 += p3mc->GetBinContent(i+1)/p3mc->GetBinError(i+1)/p3mc->GetBinError(i+1); } } resMC1 /= eresMC1; resMC2 /= eresMC2; resMC3 /= eresMC3; eresMC1 = sqrt(1./eresMC1); eresMC2 = sqrt(1./eresMC2); eresMC3 = sqrt(1./eresMC3); ppMC = cA->GetV2(spec,xMin,xMax); ppMC2 = cC->GetV2(spec,xMin,xMax); scaling = sqrt(resMC1*resMC3/resMC2); ppMC->Scale(1./scaling); err1_2 = eresMC1*eresMC1/resMC1/resMC1/4 + eresMC2*eresMC2/resMC2/resMC2/4 + eresMC3*eresMC3/resMC3/resMC3/4; err2_2 = err1_2; err1_2 /= scaling*scaling; printf("resolution V0A (MC) = %f +/- %f\n",scaling,err1_2); scaling = sqrt(resMC2*resMC3/resMC1); err2_2 /= scaling*scaling; ppMC2->Scale(1./scaling); printf("resolution V0C (MC) =%f +/- %f\n",scaling,err2_2); ppMC->SetName("V0Amc"); ppMC2->SetName("V0Cmc"); if(! kCleanMemory){ ppMC->Draw("SAME"); ppMC2->Draw("SAME"); } pMc = new TProfile(*ppMC); pMc->Add(ppMC2); snprintf(stringa,100,"%sMC",nameSp); pMc->SetName(stringa); pMc->SetLineColor(2); } if(! kCleanMemory){ new TCanvas(); pData->Draw(); } if(pMc && !kCleanMemory){ pMc->Draw("SAME"); TH1D *hData = pData->ProjectionX(); TH1D *hMc = pMc->ProjectionX(); hData->Divide(hMc); new TCanvas(); hData->Draw(); } delete[] NUAcorrA; delete[] NUAcorrC; if(kCleanMemory){ if(pp) delete pp; if(pp2) delete pp2; if(ppMC) delete ppMC; if(ppMC2) delete ppMC2; } delete cont; if(isMC) return pMc; return pData; }
int main(int argc, char* argv[]) { TApplication theApp(srcName.Data(), &argc, argv); //============================================================================= for (int i=0; i<argc; i++) cout << i << ", " << argv[i] << endl; //============================================================================= if (argc<5) return -1; TString sPath = argv[1]; if (sPath.IsNull()) return -1; TString sFile = argv[2]; if (sFile.IsNull()) return -1; TString sJetR = argv[3]; if (sJetR.IsNull()) return -1; TString sSjeR = argv[4]; if (sSjeR.IsNull()) return -1; //============================================================================= sPath.ReplaceAll("#", "/"); //============================================================================= double dJetR = -1.; if (sJetR=="JetR02") dJetR = 0.2; if (sJetR=="JetR03") dJetR = 0.3; if (sJetR=="JetR04") dJetR = 0.4; if (sJetR=="JetR05") dJetR = 0.5; if (dJetR<0.) return -1; cout << "Jet R = " << dJetR << endl; //============================================================================= double dSjeR = -1.; if (sSjeR=="SjeR01") dSjeR = 0.1; if (sSjeR=="SjeR02") dSjeR = 0.2; if (sSjeR=="SjeR03") dSjeR = 0.3; if (sSjeR=="SjeR04") dSjeR = 0.4; if (dSjeR<0.) return -1; cout << "Sub-jet R = " << dSjeR << endl; //============================================================================= const double dJetsPtMin = 0.001; const double dCutEtaMax = 1.6; const double dJetEtaMax = 1.; const double dJetAreaRef = TMath::Pi() * dJetR * dJetR; fastjet::GhostedAreaSpec areaSpc(dCutEtaMax); fastjet::JetDefinition jetsDef(fastjet::antikt_algorithm, dJetR, fastjet::BIpt_scheme, fastjet::Best); //fastjet::AreaDefinition areaDef(fastjet::active_area,areaSpc); fastjet::AreaDefinition areaDef(fastjet::active_area_explicit_ghosts,areaSpc); //fastjet::JetDefinition bkgsDef(fastjet::kt_algorithm, 0.2, fastjet::BIpt_scheme, fastjet::Best); //fastjet::AreaDefinition aBkgDef(fastjet::active_area_explicit_ghosts, areaSpc); fastjet::Selector selectJet = fastjet::SelectorAbsEtaMax(dJetEtaMax); //fastjet::Selector selectRho = fastjet::SelectorAbsEtaMax(dCutEtaMax-0.2); //fastjet::Selector selecHard = fastjet::SelectorNHardest(2); //fastjet::Selector selectBkg = selectRho * (!(selecHard)); //fastjet::JetMedianBackgroundEstimator bkgsEstimator(selectBkg, bkgsDef, aBkgDef); //fastjet::Subtractor bkgSubtractor(&bkgsEstimator); fastjet::JetDefinition subjDef(fastjet::antikt_algorithm, dSjeR, fastjet::BIpt_scheme, fastjet::Best); //============================================================================= std::vector<fastjet::PseudoJet> fjInput; //============================================================================= TList *list = new TList(); TH1D *hPtHat = new TH1D("hPtHat", "", 1000, 0., 1000.); TH1D *hJet = new TH1D("hJet", "", 1000, 0., 1000.); hJet->Sumw2(); list->Add(hJet); TH2D *hJetNsj = new TH2D("hJetNsj", "", 1000, 0., 1000., 101, -0.5, 100.5); hJetNsj->Sumw2(); list->Add(hJetNsj); TH2D *hJetIsj = new TH2D("hJetIsj", "", 1000, 0., 1000., 1000, 0., 1000.); hJetIsj->Sumw2(); list->Add(hJetIsj); TH2D *hJet1sj = new TH2D("hJet1sj", "", 1000, 0., 1000., 1000, 0., 1000.); hJet1sj->Sumw2(); list->Add(hJet1sj); TH2D *hJet2sj = new TH2D("hJet2sj", "", 1000, 0., 1000., 1000, 0., 1000.); hJet2sj->Sumw2(); list->Add(hJet2sj); TH2D *hJetDsj = new TH2D("hJetDsj", "", 1000, 0., 1000., 1000, 0., 1000.); hJetDsj->Sumw2(); list->Add(hJetDsj); TH2D *hJetIsz = new TH2D("hJetIsz", "", 1000, 0., 1000., 120, 0., 1.2); hJetIsz->Sumw2(); list->Add(hJetIsz); TH2D *hJet1sz = new TH2D("hJet1sz", "", 1000, 0., 1000., 120, 0., 1.2); hJet1sz->Sumw2(); list->Add(hJet1sz); TH2D *hJet2sz = new TH2D("hJet2sz", "", 1000, 0., 1000., 120, 0., 1.2); hJet2sz->Sumw2(); list->Add(hJet2sz); TH2D *hJetDsz = new TH2D("hJetDsz", "", 1000, 0., 1000., 120, 0., 1.2); hJetDsz->Sumw2(); list->Add(hJetDsz); //============================================================================= AliRunLoader *rl = AliRunLoader::Open(Form("%s/galice.root",sPath.Data())); if (!rl) return -1; if (rl->LoadHeader()) return -1; if (rl->LoadKinematics("READ")) return -1; //============================================================================= for (Int_t iEvent=0; iEvent<rl->GetNumberOfEvents(); iEvent++) { fjInput.resize(0); if (rl->GetEvent(iEvent)) continue; //============================================================================= AliStack *pStack = rl->Stack(); if (!pStack) continue; AliHeader *pHeader = rl->GetHeader(); if (!pHeader) continue; //============================================================================= AliGenPythiaEventHeader *pHeadPy = (AliGenPythiaEventHeader*)pHeader->GenEventHeader(); if (!pHeadPy) continue; hPtHat->Fill(pHeadPy->GetPtHard()); //============================================================================= for (Int_t i=0; i<pStack->GetNtrack(); i++) if (pStack->IsPhysicalPrimary(i)) { TParticle *pTrk = pStack->Particle(i); if (!pTrk) continue; if (TMath::Abs(pTrk->Eta())>dCutEtaMax) { pTrk = 0; continue; } // TParticlePDG *pPDG = pTrk->GetPDG(); if (!pPDG) { pTrk = 0; continue; } fjInput.push_back(fastjet::PseudoJet(pTrk->Px(), pTrk->Py(), pTrk->Pz(), pTrk->P())); // pPDG = 0; pTrk = 0; } //============================================================================= fastjet::ClusterSequenceArea clustSeq(fjInput, jetsDef, areaDef); std::vector<fastjet::PseudoJet> includJets = clustSeq.inclusive_jets(dJetsPtMin); // std::vector<fastjet::PseudoJet> subtedJets = bkgSubtractor(includJets); std::vector<fastjet::PseudoJet> selectJets = selectJet(includJets); // std::vector<fastjet::PseudoJet> sortedJets = fastjet::sorted_by_pt(selectJets); for (int j=0; j<selectJets.size(); j++) { double dJet = selectJets[j].pt(); hJet->Fill(dJet); //============================================================================= fastjet::Filter trimmer(subjDef, fastjet::SelectorPtFractionMin(0.)); fastjet::PseudoJet trimmdJet = trimmer(selectJets[j]); std::vector<fastjet::PseudoJet> trimmdSj = trimmdJet.pieces(); double nIsj = 0.; double d1sj = -1.; int k1sj = -1; double d2sj = -1.; int k2sj = -1; for (int i=0; i<trimmdSj.size(); i++) { double dIsj = trimmdSj[i].pt(); if (dIsj<0.001) continue; hJetIsj->Fill(dJet, dIsj); hJetIsz->Fill(dJet, dIsj/dJet); if (dIsj>d1sj) { d2sj = d1sj; k2sj = k1sj; d1sj = dIsj; k1sj = i; } else if (dIsj>d2sj) { d2sj = dIsj; k2sj = i; } nIsj += 1.; } hJetNsj->Fill(dJet, nIsj); if (d1sj>0.) { hJet1sj->Fill(dJet, d1sj); hJet1sz->Fill(dJet, d1sj/dJet); } if (d2sj>0.) { hJet2sj->Fill(dJet, d2sj); hJet2sz->Fill(dJet, d2sj/dJet); } if ((d1sj>0.) && (d2sj>0.)) { double dsj = d1sj - d2sj; double dsz = dsj / dJet; hJetDsj->Fill(dJet, dsj); hJetDsz->Fill(dJet, dsz); } } //============================================================================= pStack = 0; pHeadPy = 0; pHeader = 0; } //============================================================================= rl->UnloadgAlice(); rl->UnloadHeader(); rl->UnloadKinematics(); rl->RemoveEventFolder(); //============================================================================= TFile *file = TFile::Open(Form("%s/pyxsec_hists.root",sPath.Data()), "READ"); TList *lXsc = (TList*)file->Get("cFilterList"); file->Close(); TH1D *hWeightSum = (TH1D*)lXsc->FindObject("h1Trials"); hWeightSum->SetName("hWeightSum"); TProfile *hSigmaGen = (TProfile*)lXsc->FindObject("h1Xsec"); hSigmaGen->SetName("hSigmaGen"); //============================================================================= file = TFile::Open(Form("%s.root",sFile.Data()), "NEW"); hPtHat->Write(); hWeightSum->Write(); hSigmaGen->Write(); list->Write(); file->Close(); //============================================================================= cout << "DONE" << endl; //============================================================================= return 0; }
void plotPhotonType(char* var="(ecalRecHitSumEtConeDR04+hcalTowerSumEtConeDR04):genCalIsoDR04") { TCut allCut = simpleCut + hardScatterCut; TProfile *hTemplate; TProfile *htmp= new TProfile("htmp","",100,0,20); htmp->SetXTitle("genCalIso [GeV]"); htmp->SetYTitle("recCalIso [GeV]"); hTemplate= getPlot(htmp,var,allCut,"MPA_PhotonJetPt15_31X.root","Analysis"); hTemplate->SetName("hTemplate"); hTemplate->Draw(); gStyle->SetOptFit(11111); hTemplate->Fit("pol1","",""); TF1* f1 = hTemplate->GetFunction("pol1"); float p0 = f1->GetParameter(0); float p1 = f1->GetParameter(1); char tempName[1000]; sprintf(tempName, "((ecalRecHitSumEtConeDR04+hcalTowerSumEtConeDR04)-genCalIsoDR04*%f):((ecalRecHitSumEtConeDR04+hcalTowerSumEtConeDR04)-genCalIsoDR04*(%f))",p1,-1.0/p1); cout << tempName << endl; TProfile *hTemplate_decompos; const int nbin=50; const float min = 0.0; const float max = 10.0; TProfile *htmp2= new TProfile("htmp2","",nbin,min,max); hTemplate_decompos= getPlot(htmp2,tempName,allCut,"MPA_PhotonJetPt15_31X.root","Analysis"); hTemplate_decompos->SetName("hTemplate_decompos"); hTemplate_decompos->Draw(); hTemplate_decompos->SetYTitle(Form("recCalIso-genCalIso*%.2f",p1)); hTemplate_decompos->SetXTitle(Form("recCalIso+genCalIso*%.2f",1.0/p1)); gStyle->SetOptFit(11111); // hTemplate_decompos->Fit("pol1"); TCanvas* c1 = new TCanvas("c1","",500,1000); c1->Divide(1,2); c1->cd(1); hTemplate->Draw(""); c1->cd(2); hTemplate_decompos->SetErrorOption("S"); hTemplate_decompos->Draw(""); c1->Print("bestGenCalIsoDR04.eps"); c1->Print("bestGenCalIsoDR04.gif"); TCanvas* c2 = new TCanvas("c2","",500,1000); c2->Divide(1,2); c2->cd(1); TH1F* hMean = new TH1F("hMean","",nbin,min,max); hMean->SetXTitle(Form("recCalIso+genCalIso*%.2f",1.0/p1)); hMean->SetTitleSize(0.06,"Y"); hMean->SetTitleOffset(1.2,"Y"); hMean->SetYTitle(Form("Mean of recCalIso-genCalIso*%.2f",p1)); for(int i=1; i <= nbin; i++) hMean->SetBinContent(i,hTemplate_decompos->GetBinContent(i)); hMean->Draw(); c2->cd(2); TH1F* hRMS = new TH1F("hRMS","",nbin,min,max); hRMS->SetXTitle(Form("recCalIso+genCalIso*%.2f",1.0/p1)); hRMS->SetTitleSize(0.06,"Y"); hRMS->SetTitleOffset(1.2,"Y"); hRMS->SetYTitle(Form("RMS of recCalIso-genCalIso*%.2f",p1)); for(int i=1; i <= nbin; i++) hRMS->SetBinContent(i,hTemplate_decompos->GetBinError(i)); hRMS->Draw(); c2->Print("bestGenCalIsoDR04_sup.eps"); c2->Print("bestGenCalIsoDR04_sup.gif"); int bestDeComposXBin = 11; float bestDeComposX = hMean->GetBinCenter(bestDeComposXBin); float bestDeComposY = hMean->GetBinContent(bestDeComposXBin); cout << "bestDeComposX = " << bestDeComposX << endl; cout << "bestDeComposY = " << bestDeComposY << endl; float bestGenIso = (bestDeComposX - bestDeComposY)/((1.0)/p1 + p1); float bestRecIso = bestDeComposX - (1.0/p1) * bestGenIso; cout << "bestGenIso = " << bestGenIso << endl; cout << "bestRecIso = " << bestRecIso << endl; }
void drawFracs(string mc_type = "MC", string dt_type="DT", string stp = "tp") { setTDRStyle(); // The mode of operation can be overridden to compare only MC or only DT. // The MC mode names are evaluated strictly; DT type can be anything. { bool all_DT = false, all_MC = false; if (mc_type!="MC" && mc_type!="HW") all_DT = true; if (dt_type=="MC" || dt_type=="HW") all_MC = true; assert(!(all_MC && all_DT)); // } assert(stp=="tp" || stp==""); bool tp = (stp=="tp"); string smethod = (tp ? "Tag-and-probe method" : "Direct match method"); const char *cmethod = smethod.c_str(); TDirectory *curdir = gDirectory; setTDRStyle(); // Opening the requested files { string dt_file = all_MC ? dt_type : "DATA"; dt_file = "output-" + dt_file + (_vspu ? "-1" : "-2b") + ".root"; TFile *fdt = new TFile(Form("%s%s",dt_path.c_str(),dt_file.c_str()),"READ"); assert(fdt && !fdt->IsZombie()); assert(fdt->cd("Standard")); TDirectory *ddt = gDirectory; cout << "Opened the data file: "; cout << Form("%s%s",dt_path.c_str(),dt_file.c_str()) << endl; string mc_file = all_DT ? "DATA" : mc_type; mc_file = "output-" + mc_file + (_vspu ? "-1" : "-2b") + ".root"; TFile *fmc = new TFile(Form("%s%s",mc_path.c_str(),mc_file.c_str()),"READ"); assert(fmc && !fdt->IsZombie()); assert(fmc->cd("Standard")); TDirectory *dmc = gDirectory; cout << "Opened the mc file: "; cout << Form("%s%s",mc_path.c_str(),mc_file.c_str()) << endl; // } vector<pair<double,double> > etas; etas.push_back(make_pair<double, double>(0., 1.3)); //etas.push_back(make_pair<double, double>(0.0, 0.5)); //etas.push_back(make_pair<double, double>(0.5, 1.0)); //etas.push_back(make_pair<double, double>(1.0, 1.5)); //etas.push_back(make_pair<double, double>(1.5, 2.0)); //etas.push_back(make_pair<double, double>(2.0, 2.5)); //etas.push_back(make_pair<double, double>(2.5, 3.0)); //etas.push_back(make_pair<double, double>(3.0, 3.2)); //etas.push_back(make_pair<double, double>(3.2, 4.7)); //string fracs[] = {"betastar","chf", "beta", "nef", "nhf", "cef"}; bool dobeta=true; string fracs[] = {"betastar","chf", "nef", "nhf", "cef"}; bool dobeta=false; const int nfrac = sizeof(fracs)/sizeof(fracs[0]); map<string, pair<int, int> > style; style["betastar"] = make_pair<int, int>(kRed+2, kOpenCircle); style["chf"] = make_pair<int, int>(dobeta ? kRed+1 : kRed, dobeta ? kOpenDiamond : kFullCircle); style["beta"] = make_pair<int, int>(kRed, kFullCircle); // style["nef"] = make_pair<int, int>(kBlue, kFullSquare); style["nhf"] = make_pair<int, int>(kGreen+1, kFullDiamond); style["cef"] = make_pair<int, int>(kCyan+1, kOpenTriangleUp); style["muf"] = make_pair<int, int>(kMagenta+1, kOpenTriangleDown); map<string, string> name; name["betastar"] = "Charged pile-up"; name["chf"] = (dobeta ? "Charged unassoc." : "Charged hadrons"); name["beta"] = "Charged hadrons"; name["nef"] = "Photons"; name["nhf"] = "Neutral hadrons"; //name["cef"] = "Electrons"; name["muf"] = "Muons"; name["cef"] = "Electrons+muons"; // Wide binning for cleaner graphs and less jitter const int neta = 6; double xw[] = //{1, 15, 18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, //97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468, //507, 548, 592, 638, 686, 737, 790, 846, 905, 967, //1032, 1101, 1172, 1248, 1327, 1410, 1497, 1588, 1684, 1784, 1890, 2000}; //2116, 2238, 2366, 2500, 2640, 2787, 2941, 3103, 3273, 3450, 3637, 3832, //4037, 4252, 4477, 4713, 4961, 5220, 5492, 5777, 6076, 6389, 6717, 7000}; {1, 15, 21, 28, 37, 49, 64, 84, 114, 153, 196, 245, 300, 395, 468, 548, 686, 846, 1032, 1248, 1588, 2000, 2500, 3103, 3450, 3637, 3832, 4037, 4252, 4477, 4713, 4961, 5220, 5492, 5777, 6076, 6389, 6717, 7000}; const int nbins = sizeof(xw)/sizeof(xw[0]); for (unsigned int ieta = 0; ieta != etas.size(); ++ieta) { double y1 = etas[ieta].first; double y2 = etas[ieta].second; int iy = int(0.5*(y1+y2)/0.5); assert(iy<neta); cout << "iy = " << iy << endl; // List of differences map<string, TH1D*> mdf; // Build appropriate wide binning vector<double> x; if (_vspu) { for (int i = 0; i < 24; ++i) { x.push_back(0.5+2*i); } // for i } else { for (int i = 0; i != nbins && xw[i]!=0; ++i) { x.push_back(xw[i]); } // for i } const int nx = x.size()-1; THStack *hsdt = new THStack(Form("hsdt%d",ieta),"stacked histograms"); THStack *hsmc = new THStack(Form("hsmc%d",ieta),"stacked histograms"); THStack *hsdf = new THStack(Form("hsdf%d",ieta),"differences"); const double ptmin = 37; const double ptmax = 3450;//3832; const double pvmin = 0.5; const double pvmax = 32.5; TH1D *h = new TH1D("h",";p_{T} (GeV);PF energy fractions",nx,&x[0]); if (_vspu) { h->SetXTitle("N_{PV,good}"); h->GetXaxis()->SetRangeUser(pvmin,pvmax); } else { h->GetXaxis()->SetMoreLogLabels(); h->GetXaxis()->SetNoExponent(); h->GetXaxis()->SetRangeUser(ptmin,ptmax); } h->SetMaximum(1-1e-5); h->SetMinimum(0+1e-5); //TH1D *h2 = new TH1D("h2",";p_{T} (GeV);Data-MC (%)",nx,&x[0]); TH1D *h2 = new TH1D("h2",Form(";p_{T} (GeV);%s-%s (%%)",dt_type.c_str(),mc_type.c_str()),nx,&x[0]); if (_vspu) { h2->SetXTitle("N_{PV,good}"); h2->GetXaxis()->SetRangeUser(pvmin,pvmax); } else { h2->GetXaxis()->SetMoreLogLabels(); h2->GetXaxis()->SetNoExponent(); h2->GetXaxis()->SetRangeUser(37,3832); } h2->SetMaximum(_vspu ? +6+10-1e-5 : +4-1e-5 +6); h2->SetMinimum(_vspu ? -6+1e-5 : -4+1e-5 -6); //lumi_13TeV = "2.1 fb^{-1}"; lumi_13TeV = plot_title.c_str(); TCanvas *c1 = tdrDiCanvas("c1",h,h2,4,0); c1->cd(1); TLegend *leg = tdrLeg(0.20,0.23-0.05,0.50,0.53-0.05); for (int jfrac = 0; jfrac != nfrac; ++jfrac) { string sf = fracs[jfrac]; const char *cf = fracs[jfrac].c_str(); const char *ctp = stp.c_str(); string spu = (_vspu ? "_vsnpv" : ""); const char *cpu = spu.c_str(); string spudt = (_vspu ? (all_MC ? "mc/" : "jt40/") : ""); const char *cpudt = spudt.c_str(); string spumc = (_vspu ? (all_DT ? "jt40/" : "mc/") : ""); const char *cpumc = spumc.c_str(); assert(ddt->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); const char *hname1 = Form("%sp%s%s%s",cpudt,cf,ctp,cpu); TProfile *pdt = (TProfile*)gDirectory->Get(hname1); if (!pdt) cout << hname1 << " not found in " << gDirectory->GetName() << endl << flush; assert(pdt); pdt->SetName(Form("%s_dt",pdt->GetName())); assert(dmc->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); const char *hname2 = Form("%sp%s%s%s",cpumc,cf,ctp,cpu); TProfile *pmc = (TProfile*)gDirectory->Get(hname2); if (!pmc) cout << hname2 << " not found in " << gDirectory->GetName() << endl << flush; assert(pmc); pmc->SetName(Form("%s_mc",pmc->GetName())); // Rebin histogram TH1D *href = new TH1D("href","", nx, &x[0]); //TH1D *hmc = (_vspu ? pmc->ProjectionX() : tools::Rebin(pmc, href)); //TH1D *hdt = (_vspu ? pdt->ProjectionX() : tools::Rebin(pdt, href)); TH1D *hmc = tools::Rebin(pmc, href); TH1D *hdt = tools::Rebin(pdt, href); // Scale data by response to MC-equivalent energy fractions if (_shiftJES) { for (int i = 1; i != hdt->GetNbinsX()+1; ++i) { //double jec = 1.02; double jec = jesShift(hdt->GetBinCenter(i)); hdt->SetBinContent(i, hdt->GetBinContent(i)/jec); } // for i } // _shiftJES // For cef, add muf if (sf=="cef") { assert(ddt->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); TProfile *pdt2 = (TProfile*)gDirectory->Get(Form("%spmuf%s%s", cpudt,ctp,cpu)); assert(pdt2); //TH1D *hdt2 = (_vspu ? pdt2->ProjectionX() : tools::Rebin(pdt2, href)); TH1D *hdt2 = tools::Rebin(pdt2, href); for (int i = 1; i != hdt2->GetNbinsX()+1; ++i) { hdt->SetBinContent(i, hdt->GetBinContent(i)+hdt2->GetBinContent(i)); } delete hdt2; assert(dmc->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); TProfile *pmc2 = (TProfile*)gDirectory->Get(Form("%spmuf%s%s", cpumc,ctp,cpu)); assert(pmc2); //TH1D *hmc2 = (_vspu ? pmc2->ProjectionX() : tools::Rebin(pmc2, href)); TH1D *hmc2 = tools::Rebin(pmc2, href); for (int i = 1; i != hmc2->GetNbinsX()+1; ++i) { hmc->SetBinContent(i, hmc->GetBinContent(i)+hmc2->GetBinContent(i)); } delete hmc2; } // sf="cef" // For betastar, multiply by chf if (sf=="betastar") { assert(ddt->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); TProfile *pdt2 = (TProfile*)gDirectory->Get(Form("%spchf%s%s", cpudt,ctp,cpu)); assert(pdt2); //TH1D *hdt2 = (_vspu ? pdt2->ProjectionX() : tools::Rebin(pdt2, href)); TH1D *hdt2 = tools::Rebin(pdt2, href); for (int i = 1; i != hdt2->GetNbinsX()+1; ++i) { hdt->SetBinContent(i, hdt->GetBinContent(i)*hdt2->GetBinContent(i)); } delete hdt2; assert(dmc->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); TProfile *pmc2 = (TProfile*)gDirectory->Get(Form("%spchf%s%s", cpumc,ctp,cpu)); assert(pmc2); //TH1D *hmc2 = (_vspu ? pmc2->ProjectionX() : tools::Rebin(pmc2, href)); TH1D *hmc2 = tools::Rebin(pmc2, href); for (int i = 1; i != hmc2->GetNbinsX()+1; ++i) { hmc->SetBinContent(i, hmc->GetBinContent(i)*hmc2->GetBinContent(i)); } delete hmc2; } // betastar -> chf * betastar // For beta, multiply by chf if (sf=="beta") { assert(ddt->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); TProfile *pdt2 = (TProfile*)gDirectory->Get(Form("%spchf%s%s", cpudt,ctp,cpu)); assert(pdt2); //TH1D *hdt2 = (_vspu ? pdt2->ProjectionX() : tools::Rebin(pdt2, href)); TH1D *hdt2 = tools::Rebin(pdt2, href); for (int i = 1; i != hdt2->GetNbinsX()+1; ++i) { hdt->SetBinContent(i, hdt->GetBinContent(i)*hdt2->GetBinContent(i)); } delete hdt2; assert(dmc->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); TProfile *pmc2 = (TProfile*)gDirectory->Get(Form("%spchf%s%s", cpumc,ctp,cpu)); assert(pmc2); //TH1D *hmc2 = (_vspu ? pmc2->ProjectionX() : tools::Rebin(pmc2, href)); TH1D *hmc2 = tools::Rebin(pmc2, href); for (int i = 1; i != hmc2->GetNbinsX()+1; ++i) { hmc->SetBinContent(i, hmc->GetBinContent(i)*hmc2->GetBinContent(i)); } delete hmc2; } // beta -> chf * beta // For chf, multiply by (1-beta-betastar) if (sf=="chf") { assert(ddt->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); TProfile *pdt2 = (TProfile*)gDirectory->Get(Form("%spbeta%s%s", cpudt,ctp,cpu)); assert(pdt2); //TH1D *hdt2 = (_vspu ? pdt2->ProjectionX() : tools::Rebin(pdt2, href)); TH1D *hdt2 = tools::Rebin(pdt2, href); TProfile *pdt3 = (TProfile*)gDirectory->Get(Form("%spbetastar%s%s", cpudt,ctp,cpu)); assert(pdt3); //TH1D *hdt3 = (_vspu ? pdt3->ProjectionX() : tools::Rebin(pdt3, href)); TH1D *hdt3 = tools::Rebin(pdt3, href); for (int i = 1; i != hdt2->GetNbinsX()+1; ++i) { hdt->SetBinContent(i, hdt->GetBinContent(i) * (1 - (dobeta ? hdt2->GetBinContent(i) : 0) - hdt3->GetBinContent(i))); } delete hdt2; delete hdt3; assert(dmc->cd(Form("Eta_%1.1f-%1.1f",y1,y2))); TProfile *pmc2 = (TProfile*)gDirectory->Get(Form("%spbeta%s%s", cpumc,ctp,cpu)); assert(pmc2); //TH1D *hmc2 = (_vspu ? pmc2->ProjectionX() : tools::Rebin(pmc2, href)); TH1D *hmc2 = tools::Rebin(pmc2, href); TProfile *pmc3 = (TProfile*)gDirectory->Get(Form("%spbetastar%s%s", cpumc,ctp,cpu)); assert(pmc3); //TH1D *hmc3 = (_vspu ? pmc3->ProjectionX() : tools::Rebin(pmc3, href)); TH1D *hmc3 = tools::Rebin(pmc3, href); for (int i = 1; i != hmc2->GetNbinsX()+1; ++i) { hmc->SetBinContent(i, hmc->GetBinContent(i) * (1 - (dobeta ? hmc2->GetBinContent(i) : 0) - hmc3->GetBinContent(i))); } delete hmc2; delete hmc3; } // chf -> chf*(1-beta-betastar) delete href; hmc->SetMarkerStyle(kNone); hmc->SetFillStyle(1001); hmc->SetFillColor(style[cf].first - 7); hmc->SetLineColor(style[cf].first + 1); hmc->GetXaxis()->SetRangeUser(_vspu ? pvmin : ptmin, _vspu ? pvmin : ptmax); hsmc->Add(hmc, "SAME H"); hdt->SetFillStyle(1001); // for legend hdt->SetFillColor(style[cf].first - 7); // for legend hdt->SetLineColor(style[cf].first + 1); hdt->SetMarkerStyle(style[cf].second); hdt->SetMarkerSize(sf=="nhf"||(sf=="chf"&&dobeta) ? 1.3 : 1.0); if (!_vspu) hdt->GetXaxis()->SetRangeUser(_vspu ? pvmin : ptmin, _vspu ? pvmin : ptmax); hsdt->Add(hdt, "SAME P"); // Then, do the difference TH1D *hdf = (TH1D*)hdt->Clone(Form("hdf%d",ieta)); hdf->Add(hdt, hmc, 100, -100); hdf->SetLineColor(style[cf].first + 1); hdf->SetMarkerColor(style[cf].first + 1); hdf->SetMarkerStyle(style[cf].second); hdf->SetLineWidth(ieta==0 ? 2 : 0); hdf->SetMarkerSize(ieta==0 ? (sf=="nhf"||(sf=="chf"&&dobeta) ? 1.8 : 1.3) : 0.7); hsdf->Add(hdf, "SAME P"); c1->cd(2); if (jfrac==0) { TLine *l = new TLine(); l->DrawLine(_vspu ? pvmin : ptmin, 0, _vspu ? pvmax : ptmax, 0); TLatex *tex = new TLatex(); tex->SetNDC(); tex->SetTextSize(h2->GetYaxis()->GetLabelSize()); tex->DrawLatex(0.17,0.80,Form("Anti-k_{T} R=0.4%s", _shiftJES ? ", shifted by JES" : "")); } hdf->Draw("SAME"); leg->AddEntry(hdt,name[cf].c_str(),"PF"); mdf[sf] = hdf; } // for jfrac c1->cd(1); if (!_vspu) gPad->SetLogx(); hsmc->Draw("SAME"); hsdt->Draw("SAME"); leg->Draw("SAME"); // redraw gPad->RedrawAxis(); c1->cd(2); if (!_vspu) gPad->SetLogx(); //hsdf->Draw("SAME"); gPad->RedrawAxis(); c1->SaveAs(Form("pdf/drawFracs_%1.1f-%1.1f%s%s.pdf", y1, y2, _shiftJES ? "_shiftJES" : "", _vspu ? "_vsNPV" : "")); // Estimate jet response slope by analyzing composition TLatex *tex = new TLatex(); tex->SetNDC(); tex->SetTextSize(h2->GetYaxis()->GetLabelSize()*0.7); if (dobeta) { //TF1 *fchf = new TF1("fchf","[0]+[1]*pow(x,[2])",40,2000);//ptmin,ptmax); //fchf->SetParameters(0,-2, -0.05); TF1 *fchf = new TF1("fchf",jesFit,40,3000,2); fchf->SetParameters( 0.9881-1, 0.2440 ); // Fall15_25nsV2 //mdf["beta"]->Fit(fchf,"QRN"); TH1D *hchfa = (TH1D*)mdf["beta"]->Clone("hcfha"); hchfa->Add(mdf["chf"]); hchfa->Add(mdf["betastar"]); hchfa->Fit(fchf,"QRN"); fchf->SetLineColor(kRed+3); fchf->Draw("SAME"); hchfa->SetMarkerStyle(kFullStar); hchfa->SetMarkerColor(kRed+3); hchfa->SetLineColor(kRed+3); hchfa->Draw("SAMEP"); } else { //TF1 *fchf = new TF1("fchf","[0]+[1]*pow(x,[2])",40,2000);//ptmin,ptmax); //fchf->SetParameters(0,-2, -0.05); TF1 *fchf = new TF1("fchf",jesFit,40,3000,2); fchf->SetParameters( 0.9881-1, 0.2440 ); // Fall15_25nsV2 mdf["chf"]->Fit(fchf,"QRN"); fchf->SetLineColor(kRed+2); fchf->Draw("SAME"); tex->SetTextColor(kRed); tex->DrawLatex(0.17,0.40,Form("%1.2f#pm%1.2f%%, #chi^2/NDF=%1.1f/%d", fchf->GetParameter(0), fchf->GetParError(0), fchf->GetChisquare(), fchf->GetNDF())); } //TF1 *fnhf = new TF1("fnhf","[0]+[1]*pow(x,[2])",40,2000);//ptmin,ptmax); //fnhf->SetParameters(0,-2, -0.05); TF1 *fnhf = new TF1("fnhf",jesFit,40,3000,2); fnhf->SetParameters( 0.9881-1, 0.2440 ); // Fall15_25nsV2 mdf["nhf"]->Fit(fnhf,"QRN"); fnhf->SetLineColor(kGreen+2); fnhf->Draw("SAME"); //TF1 *fnef = new TF1("fnef","[0]+[1]*pow(x,[2])",40,2000);//ptmin,ptmax); //fnef->SetParameters(0,-2, -0.05); TF1 *fnef = new TF1("fnef",jesFit,40,3000,2); fnef->SetParameters( 0.9881-1, 0.2440 ); // Fall15_25nsV2 mdf["nef"]->Fit(fnef,"QRN"); fnef->SetLineColor(kBlue+1); fnef->Draw("SAME"); //TH1D *hall = (TH1D*)hchfa->Clone("hall"); TH1D *hall = (TH1D*)mdf["chf"]->Clone("hall"); if (dobeta) hall->Add(mdf["beta"]); hall->Add(mdf["betastar"]); hall->Add(mdf["nef"]); hall->Add(mdf["nhf"]); hall->Add(mdf["cef"]); hall->SetMarkerStyle(kFullCross); hall->SetMarkerColor(kBlack); //hall->Draw("SAMEL"); h2->SetMaximum(+5);//+3.0); h2->SetMinimum(-5);//-1.5); if (ieta==0) c1->SaveAs(Form("pdf/drawFracs_WithFit%s%s.pdf", _shiftJES ? "_shiftJES" : "", _vspu ? "_vsNPV" : "")); } // For ieta } // drawFracs