Graduation-Project/integral.cpp

44 lines
1.0 KiB
C++
Raw Normal View History

2023-02-13 14:50:36 +08:00
#include <TFile.h>
#include <TTree.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
double e[24];
int id[24], N[1];
int sum1, sum2;
if (argc != 2) {
printf("usage: ./xxx <input root file>\n");
return 0;
}
TFile f(argv[1]);
if (f.IsZombie()) {
printf("cannot open root file\n");
return 0;
}
TTree* t = (TTree*)f.Get("SimData1");
if (!t) {
printf("cannot find tree!\n");
return 0;
}
t->SetBranchAddress("detE", e);
t->SetBranchAddress("detId", id);
t->SetBranchAddress("Ndets", N);
int n = t->GetEntries();
// printf("n=%d\n", n);
int i, j;
sum1 = sum2 = 0;
for (i = 0; i < n; i++) {
t->GetEntry(i);
for (j = 0; j < N[0]; j++) {
if (e[j] > 0.18 && id[j] < 12) {
sum1++;
}
if (e[j] > 0.18 && id[j] > 11) {
sum2++;
}
}
}
printf(" %s,%d,%d,%d,%f\n", argv[1], sum1 + sum2, sum1, sum2, 1.0 * sum1 / sum2);
return 0;
}