bool PlotManager::saveBayesEfficiency(const string& graphName, const string& graphTitle, const string& numeHistName, const string& denoHistName) { if ( ! isSetup_ ) return false; TH1F* numeHist = (TH1F*)(theSrcFile_->Get(numeHistName.c_str())); TH1F* denoHist = (TH1F*)(theSrcFile_->Get(denoHistName.c_str())); // Check validity of objects if ( numeHist == 0 || denoHist == 0 ) { cerr << "Cannot get object : " << graphName << endl; return false; } if ( ! numeHist->IsA()->InheritsFrom("TH1") || ! denoHist->IsA()->InheritsFrom("TH1") || numeHist->IsA()->InheritsFrom("TH2") || denoHist->IsA()->InheritsFrom("TH2") ) { return false; } // Check bin size if ( numeHist->GetNbinsX() != denoHist->GetNbinsX() ) { cerr << "Bin size of two histograms are not same" << endl; return false; } // Push to base directory string pwd(gDirectory->GetPath()); string newGraphPath = dirname(graphName); string newGraphName = basename(graphName); if ( newGraphPath.empty() ) { theOutFile_->cd(); } else if ( theOutFile_->cd(newGraphPath.c_str()) == kFALSE ) { cout << "Cannot find directory, do mkdirs" << endl; mkdirs(theOutFile_, newGraphPath)->cd(); } // Create new TGraphAsymmErrors TGraphAsymmErrors* effGraph = new TGraphAsymmErrors(numeHist, denoHist); // Cosmetics effGraph->SetName(newGraphName.c_str()); effGraph->SetTitle(graphTitle.c_str()); effGraph->SetMinimum(0.8); effGraph->SetMaximum(1.0); effGraph->GetXaxis()->SetTitle(numeHist->GetXaxis()->GetTitle()); effGraph->GetYaxis()->SetTitle("Efficiency"); // Save histogram effGraph->Write(); // Pop directory gDirectory->cd(pwd.c_str()); return true; }
void customContextMenu() { TH1F *h; TH1F *h2; TClassMenuItem *n; TList *l; // Create test histograms h = new TH1F("h","Schtroumpf",100,-4,4); h->FillRandom("gaus"); h->Draw(); h2 = new TH1F("h2","h2",1000,-4,4); h2->FillRandom("gaus",30000); // Retrieve menu list from TClass TClass *cl = h->IsA(); l = cl->GetMenuList(); // Add some items to the popup menus n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Test object, draw a second h","Draw",h2,"Option_t*"); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 4","poptest4",0,"const char*"); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 3","poptest3",0,""); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 2 bis","poptest2bis",0,"TObject*",2); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 2","poptest2",0,"int,int,TObject*",2); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 1","poptest1",0,"int,int"); l->AddFirst(n); }
bool PlotManager::saveFakeRate(const string& histName, const string& histTitle, const string& numeHistName, const string& denoHistName) { if ( ! isSetup_ ) return false; TH1F* numeHist = (TH1F*)(theSrcFile_->Get(numeHistName.c_str())); TH1F* denoHist = (TH1F*)(theSrcFile_->Get(denoHistName.c_str())); // Check validity of objects if ( numeHist == 0 || denoHist == 0 ) { cerr << "Cannot get object : " << histName << endl; return false; } if ( ! numeHist->IsA()->InheritsFrom("TH1") || ! denoHist->IsA()->InheritsFrom("TH1") || numeHist->IsA()->InheritsFrom("TH2") || denoHist->IsA()->InheritsFrom("TH2") ) { return false; } // Check bin size if ( numeHist->GetNbinsX() != denoHist->GetNbinsX() ) { cerr << "Bin size of two histograms are not same" << endl; return false; } // Push to base directory string pwd(gDirectory->GetPath()); string newHistPath = dirname(histName); string newHistName = basename(histName); if ( newHistPath.empty() ) { theOutFile_->cd(); } else if ( theOutFile_->cd(newHistPath.c_str()) == kFALSE ) { cout << "Cannot find directory, do mkdirs" << endl; mkdirs(theOutFile_, newHistPath)->cd(); } // Create new histogram TH1F* fakeHist = dynamic_cast<TH1F*>(numeHist->Clone()); // effHist->Divide(denoHist); // Set the error to binomial statistics int nBinsX = fakeHist->GetNbinsX(); for(int bin = 1; bin <= nBinsX; bin++) { float nNume = numeHist->GetBinContent(bin); float nDeno = denoHist->GetBinContent(bin); float fakeRate = nDeno==0 ? 0 : 1.0 - nNume/nDeno; float err = 0; if ( nDeno != 0 && fakeRate <= 1 ) { err = sqrt(fakeRate*(1-fakeRate)/nDeno); } fakeHist->SetBinContent(bin, fakeRate); fakeHist->SetBinError(bin, err); } // Cosmetics fakeHist->SetName(newHistName.c_str()); fakeHist->SetTitle(histTitle.c_str()); fakeHist->SetMinimum(0.8); fakeHist->SetMaximum(1.0); fakeHist->GetXaxis()->SetTitle(numeHist->GetXaxis()->GetTitle()); fakeHist->GetYaxis()->SetTitle("Efficiency"); // Save histogram fakeHist->Write(); // Pop directory gDirectory->cd(pwd.c_str()); return true; }