I am trying to sum over a column of 1s and 0s in a TTree, and this seems like a trivial task, but I have no clue what function lets me pull these values. I am attempting to do this in a .C file, where I am able to pull statistics from other TTrees from the same TFile Here is what I have so far:

Thanks for posting. I propose to solve your enquiry with RDataFrame, the modern way to deal with columnar (and not only) datasets. Below you find a complete example. I had to create a fake dataset in the first function to delivere a copy & paste recipe. Let us know how it goes!

Cheers,
D

void produceFakeInput()
{
// This function is there just to produce some fake data
auto df = ROOT::RDataFrame(128).Define("YourBranch", []{return (int) gRandom->Gaus() > 0 ? 1 : 0;});
df.Snapshot("Incident", "TestCAL_Cs137_d5z6_MoreStats.root");
}
void example()
{
produceFakeInput();
// Open a Data Frame built on your columnar dataset
auto df = ROOT::RDataFrame("Incident", "TestCAL_Cs137_d5z6_MoreStats.root");
auto sumRes = df.Sum("YourBranch");
auto statsRes = df.Stats("YourBranch");
std::cout << "The sum is " << sumRes.GetValue() << std::endl;
std::cout << "A more complete statistics: " << std::endl;
statsRes->Print();
}