ANASEN_analysis/Armory/aarootscript.C
2026-04-20 13:37:31 -04:00

75 lines
1.9 KiB
C

#include "TFile.h"
#include "TTree.h"
#include "TGraph.h"
#include "TLegend.h"
#include "TCanvas.h"
#include "TH1D.h"
#include "TObjArray.h"
#include "TBranch.h"
#include <iostream>
void aarootscript(int argument = 0) {
std::cout << "\n\n\n";
std::cout << "=========================================\n";
std::cout << "========= ANASEN Root Script =========\n";
std::cout << "=========================================\n";
TFile *f = new TFile("SimAnasen1.root");
TTree *tree1 = (TTree*)f->Get("tree");
if (!tree1) {
std::cerr << "Error: tree1 not found in the file!" << std::endl;
return;
}
TTree *tree2 = (TTree*)f->Get("tree2");
TTreeReader reader("tree");
TTreeReaderValue<double> branchValue(reader, "Tb");
double totalSum = 0;
while (reader.Next()) {
totalSum += *branchValue;
}
std::cout << "Total Sum: " << totalSum << std::endl;
TTreeReader reader2("tree2");
TTreeReaderValue<double> branchValue2(reader2, "Tb");
double totalSum2 = 0;
int zeroCount = 0;
while (reader2.Next()) {
totalSum2 += *branchValue2;
if (*branchValue2 == 0) {
zeroCount++;
}
}
std::cout << "Total Sum: " << totalSum2 << std::endl;
std::cout << "Difference: " << totalSum - totalSum2 << std::endl;
std::cout << "Zero Count: " << zeroCount << std::endl;
std::cout << "Making histograms..." << std::endl;
gErrorIgnoreLevel = 2001;
gROOT->ProcessLine(".x histcomp.C");
std::cout << "=========================================\n";
if (argument == 1) {
if (tree1) {
gROOT->ProcessLine("tree->Print();");
} else {
std::cout << "Tree1 not found!" << std::endl;
}
}
if (argument == 2) {
if (tree2) {
gROOT->ProcessLine("tree2->Print();");
} else {
std::cout << "Tree2 not found!" << std::endl;
}
}
std::cout << "\n\n\n";
}