///////////////////////// // Put entries into the entry list SEXP putIntoEntryList(SEXP entryList, SEXP entryNums) { TEntryList* el = checkForEntryListWrapper(entryList); for ( unsigned int i = 0; i < GET_LENGTH(entryNums); ++i ) { el->Enter( INTEGER(entryNums)[i] ); } return R_NilValue; }
///**** LL **** void doMC_LL(){ TTree* MyTreeMC = (TTree*) fileInMC->Get(treeNameMC.c_str()); for (nIter = 0; nIter<maxIter; nIter++){ if (!(nIter%1)) std::cerr << ">>> nIter = " << nIter << " : " << maxIter << std::endl; vET_data.clear(); outFile->cd(); TString nameDATA = Form("hDATA_%d_%d_%.5f",Data_or_MC,nIter,ScaleTrue); TH1F hDATA(nameDATA,nameDATA,numBINS,minBINS,maxBINS); MyTreeMC->Draw(">> myListMC",(AdditionalCut+Form("&& (ET * (1+(%f)))>%f",ScaleTrue,minET)).Data(),"entrylist"); TEntryList *myListMC = (TEntryList*)gDirectory->Get("myListMC"); MyTreeMC->SetEntryList(0); TEntryList *listMCHere = new TEntryList("listMCHere","listMCHere"); for (int iEvt = 0; iEvt < numSelectedData; iEvt ++){ listMCHere->Enter(myListMC->GetEntry(gRandom->Uniform(0,myListMC->GetN()))); } MyTreeMC->SetEntryList(listMCHere); MyTreeMC->Draw(Form("(1+%f) * %s >> %s",ScaleTrue,variableName.c_str(),nameDATA.Data())); ConvertStdVectDouble(vET_data,MyTreeMC->GetV1(),numSelectedData); ///==== likelihood ==== std::cerr << " === LL === " << std::endl; std::cerr << " === pseudo vET_data.size() = " << vET_data.size() << std::endl; minuit->SetFunction(functorLL); TGraph * grLL_temp = new TGraph(iNoSteps); minuit->Scan(iPar_NoBG,iNoSteps,grLL_temp->GetX(),grLL_temp->GetY(),MinScan,MaxScan); TGraph * grLL = new TGraph(); int nPointLL = 0; for (unsigned int iStep = 0; iStep < iNoSteps; iStep++){ double x = MinScan + (MaxScan - MinScan) / iNoSteps * (iStep+0.5); double y = LLFunc(&x); if (y != numberDATA * numEvents) { grLL->SetPoint(nPointLL,x,y); nPointLL++; } } grLL->Draw("AL"); outFile->cd(); minuit->PrintResults(); const double *outParametersTemp2 = minuit->X(); const double *errParametersTemp2 = minuit->Errors(); double *outParametersLL = new double; double *errParametersLL = new double; outParametersLL[0] = outParametersTemp2[0]; errParametersLL[0] = errParametersTemp2[0]; std::cerr << " nPointLL = " << nPointLL << std::endl; double minLL = grLL->Eval(outParametersLL[0]); ///==== end likelihood ==== ///==== Save the whole shape of LL/Chi2 ==== for (unsigned int ii=0; ii < iNoSteps; ii++){ double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan; Alpha = X_ii; Chi2 = 0; LL = grLL->Eval(X_ii); NewChi2 = 0; myTreeChi2->Fill(); } ///===== Look for minima ===== double a; double b; double c; double errX_low = -9999; double errX_up = 9999; int err_low = 0; int err_up = 0; for (unsigned int ii=0; ii < iNoSteps; ii++){ double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan; double here = grLL->Eval(X_ii); if (err_low == 0){ if (here < (minLL + DELTA_LL)){ errX_low = X_ii; err_low = 1; } } else if (err_up == 0 && here > (minLL + DELTA_LL) && X_ii > outParametersLL[0]){ errX_up = X_ii; err_up = 1; } } AlphaMean = outParametersLL[0]; AlphaMinus = errX_low; AlphaPlus = errX_up; grLL->Fit("fitMin","RMQ"); c = fitMin->GetParameter(0); b = fitMin->GetParameter(1); a = fitMin->GetParameter(2); AlphaMean_Fit = -b / (2*a); AlphaMinus_Fit = (-b + sqrt(2*a)) / (2*a); ///==== delta LL = 0.5 AlphaPlus_Fit = (-b - sqrt(2*a)) / (2*a); ///==== delta LL = 0.5 myTreeLL_Result->Fill(); grLL->Write(); //delete listMCHere; } }
///**** NewChi2 **** void doMC_NewChi2(){ TTree* MyTreeMC = (TTree*) fileInMC->Get(treeNameMC.c_str()); for (nIter = 0; nIter<maxIter; nIter++){ if (!(nIter%1)) std::cerr << ">>> nIter = " << nIter << " : " << maxIter << std::endl; vET_data.clear(); outFile->cd(); TString nameDATA = Form("hDATA_%d_%d_%.5f",Data_or_MC,nIter,ScaleTrue); TH1F hDATA(nameDATA,nameDATA,numBINS,minBINS,maxBINS); MyTreeMC->Draw(">> myListMC",(AdditionalCut+Form("&& (ET * (1+(%f)))>%f",ScaleTrue,minET)).Data(),"entrylist"); TEntryList *myListMC = (TEntryList*)gDirectory->Get("myListMC"); MyTreeMC->SetEntryList(0); TEntryList *listMCHere = new TEntryList("listMCHere","listMCHere"); for (int iEvt = 0; iEvt < numSelectedData; iEvt ++){ listMCHere->Enter(myListMC->GetEntry(gRandom->Uniform(0,myListMC->GetN()))); } MyTreeMC->SetEntryList(listMCHere); MyTreeMC->Draw(Form("(1+%f) * %s >> %s",ScaleTrue,variableName.c_str(),nameDATA.Data())); ConvertStdVectDouble(vET_data,MyTreeMC->GetV1(),numSelectedData); ///==== newChi2 ==== minuit->SetFunction(functorNewChi2); TGraph * grNewChi2 = new TGraph(iNoSteps); minuit->Scan(iPar_NoBG,iNoSteps,grNewChi2->GetX(),grNewChi2->GetY(),MinScan,MaxScan); grNewChi2->Draw("AL"); outFile->cd(); minuit->PrintResults(); const double *outParametersNewChi2 = minuit->X(); const double *errParametersNewChi2 = minuit->Errors(); double minNewChi2 = grNewChi2->Eval(outParametersNewChi2[0]); ///==== end newChi2 ==== ///==== Save the whole shape of LL/Chi2 ==== for (unsigned int ii=0; ii < iNoSteps; ii++){ double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan; Alpha = X_ii; Chi2 = 0; LL = 0; NewChi2 = grNewChi2->Eval(X_ii); myTreeChi2->Fill(); } ///===== Look for minima ===== double a; double b; double c; double errX_low = -9999; double errX_up = 9999; int err_low = 0; int err_up = 0; for (unsigned int ii=0; ii < iNoSteps; ii++){ double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan; double here = grNewChi2->Eval(X_ii); if (err_low == 0){ if (here < (minNewChi2 + DELTA_CHI2)){ errX_low = X_ii; err_low = 1; } } else if (err_up == 0 && here > (minNewChi2 + DELTA_CHI2) && X_ii > outParametersNewChi2[0]){ errX_up = X_ii; err_up = 1; } } AlphaMean = outParametersNewChi2[0]; AlphaMinus = errX_low; AlphaPlus = errX_up; grNewChi2->Fit("fitMin","RMQ"); c = fitMin->GetParameter(0); b = fitMin->GetParameter(1); a = fitMin->GetParameter(2); AlphaMean_Fit = -b / (2*a); AlphaMinus_Fit = (-b + 2 * sqrt(a)) / (2*a); ///==== delta Chi2 = 1 AlphaPlus_Fit = (-b - 2 * sqrt(a)) / (2*a); ///==== delta Chi2 = 1 myTreeNewChi2_Result->Fill(); // delete listMCHere; } }
void plotL1Digis(Long64_t entryNum=1) { TH1::SetDefaultSumw2(); TString inputFile = "L1UpgradeAnalyzer.root"; TString inputFileunp = "L1UnpackedUnpacker.root"; TFile *inFile = TFile::Open(inputFile); TFile *inFileunp = TFile::Open(inputFileunp); TTree *emulatorResults = (TTree*)inFile->Get("L1UpgradeAnalyzer/L1UpgradeTree"); TTree *unpackerResults = (TTree*)inFileunp->Get("UnpackerResults/L1UpgradeTree"); //TCut entryCut = Form("Entry$ == %i", entryNum); //TCut entryCutUnpacker = Form("Entry$ == %i",entryNum+179); TEntryList* elist = new TEntryList(unpackerResults); for ( int bx(0); bx<100; bx++) { if ( !unpackerResults->Draw("Entry$",Form("FEDBXID == %i", bx), "nodraw" ) ) continue; elist->Enter(unpackerResults->GetV1()[0], unpackerResults); } unpackerResults->SetEntryList(elist); elist->Print(); const int nHISTS = 30; TString labels[nHISTS] = {"region_et", "region_eta", "region_phi", "egcand_rank", "egcand_eta", "egcand_phi", "central_jet_hwPt", "central_jet_hwEta", "central_jet_hwPhi", "forward_jet_hwPt", "forward_jet_hwEta", "forward_jet_hwPhi", "ETT", "HTT", "MET_Rank", "MET_Phi", "MHT_Rank", "MHT_Phi", "iso_egamma_hwPt", "iso_egamma_hwEta", "iso_egamma_hwPhi", "noniso_egamma_hwPt", "noniso_egamma_hwEta", "noniso_egamma_hwPhi", "tau_hwPt", "tau_hwEta", "tau_hwPhi", "isotau_hwPt", "isotau_hwEta", "isotau_hwPhi"}; TString projectionnames[nHISTS] = {"legacyregion_et", "legacyregion_gctEta", "legacyregion_gctPhi", "legacyemcand_rank", "legacyemcand_regionEta", "legacyemcand_regionPhi", "jet_hwPt", "jet_hwEta", "jet_hwPhi", "jet_hwPt", "jet_hwEta", "jet_hwPhi", "etsum_hwPt", "etsum_hwPt", "etsum_hwPt","etsum_hwPhi","etsum_hwPt","etsum_hwPhi", "egamma_hwPt", "egamma_hwEta", "egamma_hwPhi", "egamma_hwPt", "egamma_hwEta", "egamma_hwPhi", "tau_hwPt", "tau_hwEta", "tau_hwPhi", "isotau_hwPt", "isotau_hwEta", "isotau_hwPhi"}; TCut projectioncuts[nHISTS] = {"", "", "", "", "", "", "(jet_hwQual&0x2)!=0x2&&jet_bx==0","(jet_hwQual&0x2)!=0x2&&jet_bx==0","(jet_hwQual&0x2)!=0x2&&jet_bx==0", "(jet_hwQual&0x2)==0x2&&jet_bx==0","(jet_hwQual&0x2)==0x2&&jet_bx==0","(jet_hwQual&0x2)==0x2&&jet_bx==0", "etsum_type==0&&etsum_bx==0","etsum_type==1&&etsum_bx==0", "etsum_type==2&&etsum_bx==0","etsum_type==2&&etsum_bx==0","etsum_type==3&&etsum_bx==0","etsum_type==3&&etsum_bx==0", "egamma_hwIso==1&&egamma_bx==0", "egamma_hwIso==1&&egamma_bx==0", "egamma_hwIso==1&&egamma_bx==0", "egamma_hwIso==0&&egamma_bx==0", "egamma_hwIso==0&&egamma_bx==0", "egamma_hwIso==0&&egamma_bx==0", "tau_bx==0", "tau_bx==0", "tau_bx==0", "isotau_bx==0", "isotau_bx==0", "isotau_bx==0"}; Int_t minBin[nHISTS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Int_t maxBin[nHISTS] = {40, 22, 25, 64, 22, 25, 64,22,25, 64,22,25, 600, 300, 200, 70, 200, 30, 64, 22, 25, 64, 22, 25, 64, 22, 25, 64, 25, 25}; TH1I *hists[nHISTS][2]; TH1D *divs[nHISTS]; TCanvas *c[nHISTS]; for(int i = 0; i < nHISTS; ++i) { hists[i][0] = new TH1I(labels[i], ";"+labels[i], maxBin[i]-minBin[i], minBin[i], maxBin[i]); hists[i][1] = (TH1I*)hists[i][0]->Clone(labels[i]+"unpacked"); divs[i] = new TH1D(labels[i]+"div", ";"+labels[i], maxBin[i]-minBin[i], minBin[i], maxBin[i]); //emulatorResults->Project(hists[i][0]->GetName(), projectionnames[i], projectioncuts[i]&&entryCut); //unpackerResults->Project(hists[i][1]->GetName(), projectionnames[i], projectioncuts[i]&&entryCutUnpacker); emulatorResults->Project(hists[i][0]->GetName(), projectionnames[i], projectioncuts[i]); unpackerResults->Project(hists[i][1]->GetName(), projectionnames[i], projectioncuts[i]); divs[i]->Divide(hists[i][1], hists[i][0]); for (int m=1;m<=hists[i][1]->GetNbinsX();m++){ if(hists[i][1]->GetBinContent(m)==hists[i][0]->GetBinContent(m)) divs[i]->SetBinContent(m,1); } hists[i][0]->SetLineWidth(5); hists[i][0]->SetMarkerColor(kRed); hists[i][0]->SetLineColor(kRed); hists[i][1]->SetLineWidth(2); c[i] = new TCanvas(); c[i]->Divide(1,2); c[i]->cd(1); hists[i][0]->Draw("hist"); hists[i][1]->Draw("hist same"); TLegend* legend= new TLegend(0.72578,0.7917988,0.9002463,0.9371476); legend->SetFillColor(0); legend->SetLineColor(kGray+2); legend->SetTextFont(42); ent=legend->AddEntry(hists[i][0],"Emulator","F"); ent=legend->AddEntry(hists[i][1],"Unpacked","F"); legend->Draw(); c[i]->cd(2); divs[i]->SetLineWidth(3); divs[i]->GetYaxis()->SetTitle("Ratio unpacked/emulated"); divs[i]->Draw("hist"); c[i]->SaveAs(Form("figs/%s.pdf",labels[i].Data())); } }