Skip to content

Instantly share code, notes, and snippets.

@marty1885
Created September 3, 2019 09:22
Show Gist options
  • Save marty1885/029d9e817811b0241c7b844dfcaf95e1 to your computer and use it in GitHub Desktop.
Save marty1885/029d9e817811b0241c7b844dfcaf95e1 to your computer and use it in GitHub Desktop.
void missing_creator_pct()
{
// Now we can use the new and improved RDataFrame interface
auto rdf = ROOT::RDataFrame("library", "library.root");
auto rdf_with_year = rdf.Filter("publication_year != 0x7fffffff");
auto rdf_missing = rdf_with_year.Filter("creator != \"\"");
std::map<std::string, int> books;
std::map<std::string, int> all_books;
rdf_with_year.Foreach([&](std::string title, int year) {all_books[title] = year;}, {"title", "publication_year"});
rdf_missing.Foreach([&](std::string title, int year) {books[title] = year;}, {"title", "publication_year"});
auto h1 = new TH1F("h1", "% of books with missing creator", 100, 1850, 2019);
for(auto [title, year] : books)
h1->Fill(year);
auto h2 = new TH1F("h2", "books with missing year", 100, 1850, 2019);
for(auto [title, year] : all_books)
h2->Fill(year);
for(int i=0;i<101;i++) {
if(h2->GetBinContent(i) == 0)
continue;
h1->SetBinContent(i, h1->GetBinContent(i)/h2->GetBinContent(i));
}
h1->Draw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment