-
Notifications
You must be signed in to change notification settings - Fork 0
/
first.c
80 lines (69 loc) · 1.96 KB
/
first.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
void first(const char *fname = "flat_x1.5_z1.5mm_3000evt.root", const char *fOutName = "out_x1.5_z1.5.root") {
//
// Some common variables
//
const char *treeName = "DRTile";
const int nBins = 50;
const float binLo = 0.0;
const float binHi = 5.0;
// const float gMean = 3.0;
// const float gSigma = 2.0;
// const double eff = 0.15;
// std::cout << " gSigma == " << gSigma << std::endl;
//
// Create an output file
//
std::cout << "[SiPM macro]: Trying to create output file... ";
TFile *fOut = new TFile(fOutName, "RECREATE");
if (!fOut) {
file->Close();
std::cout << "[FAIL]" << std::endl;
return;
}
std::cout << "[OK]" << std::endl;
//
// Open file
//
std::cout << "[SiPM macro]: Trying to open file... ";
TFile *file = new TFile(fname, "READ");
if (!file) { // if error occure then exit
std::cout << "[FAIL]" << std::endl;
return;
}
std::cout << "[OK]" << std::endl;
//
// Setup a TTree
//
std::cout << "[SiPM macro]: Setup a tree... ";
TTree *tree = (TTree *)file->Get(treeName);
TH1F *hist = (TH1F *)file->Get("fcountE");
if (!tree) {
std::cout << "[FAIL]" << std::endl;
file->Close();
return;
}
std::cout << "[OK]" << std::endl;
unsigned int nEvents = tree->GetEntries();
//
// Setup a branch
//
Double_t E_first_particle = 0;
tree->SetBranchAddress("E_first_particle", &E_first_particle);
//
// Create a histogram and random generator
//
TH1F *E_first_particle_hist = new TH1F("E_first_particle", "E_first_particle", nBins, binLo, binHi);
for (unsigned int i = 0; i < nEvents; i++) {
tree->GetEntry(i);
E_first_particle_hist->Fill(E_first_particle);
}
TH1F *copy_from_in_file=(TH1F*)hist->Clone();
copy_from_in_file->GetXaxis()->SetRangeUser(1.25, 2.5);
E_first_particle_hist->GetXaxis()->SetRangeUser(1.25, 2.5);
fOut->cd();
E_first_particle_hist->Write();
copy_from_in_file->Write();
fOut->Write();
fOut->Close();
file->Close();
}