Graduation-Project/integral.cpp

40 lines
925 B
C++

#include <TFile.h>
#include <TTree.h>
#include <stdio.h>
void integral(TString file) {
double e[24];
int id[24], N[1];
int sum1, sum2;
TFile f(file);
if (f.IsZombie()) {
printf("cannot open root file\n");
return;
}
TTree* t = (TTree*)f.Get("SimData1");
if (!t) {
printf("cannot find tree!\n");
return;
}
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("%d,%d,%d,%f\n", sum1 + sum2, sum1, sum2, 1.0 * sum1 / sum2);
}