-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdet_reader1.C
executable file
·70 lines (65 loc) · 2.27 KB
/
det_reader1.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
/// macro_code
///
/// \author Sebastian Sarasti Zambonino - 2022
/// DCN
#include "Riostream.h"
#include "TFile.h"
#include "TH1F.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"
#include <vector>
void det_reader1() {
// Create a histogram for the values we read.
auto myHist1 = new TH1F("h1","ntuple",300,0,2);
auto myHist2 = new TH1F("h2","ntuple",300,0,2);
auto myHist3 = new TH1F("h3","ntuple",300,0,2);
auto myHist4 = new TH1F("h4","ntuple",300,0,2);
// Load the file which contains the trees.
auto myFile = TFile::Open("output0.root");
if (!myFile || myFile->IsZombie()) {
return;
}
// call interested trees
TTreeReader myReader1("Detector_1", myFile);
TTreeReader myReader2("Detector_2", myFile);
TTreeReader myReader3("Detector_3", myFile);
TTreeReader myReader4("Detector_4", myFile);
// call the branch needed
TTreeReaderValue<Double_t> mDet1(myReader1, "fedep1");
TTreeReaderValue<Double_t> mDet2(myReader2, "fedep2");
TTreeReaderValue<Double_t> mDet3(myReader3, "fedep3");
TTreeReaderValue<Double_t> mDet4(myReader4, "fedep4");
// create a file to save the results
ofstream out;
out.open("NaIDetector_matrix.dat");
// add loaded trees into histograms
while (myReader1.Next()) {
// fill histograms with data
myHist1->Fill(*mDet1);
}
while (myReader2.Next()) {
// fill histograms with data
myHist2->Fill(*mDet2);
}
while (myReader3.Next()) {
// fill histograms with data
myHist3->Fill(*mDet3);
}
while (myReader4.Next()) {
// fill histograms with data
myHist4->Fill(*mDet4);
}
// get the number of the bins
int nbins= myHist1->GetXaxis()->GetNbins();
// iterate to save each bin and the value
for (int bin=1; bin<=nbins; bin++){
// to print the results
// printf("%4d %6.1f %4.11f %4.11f\n",bin, myHist1->GetXaxis()->GetBinCenter(bin), myHist1->GetBinContent(bin), myHist2->GetBinContent(bin));
// to save the results in a matrix
out<< myHist1->GetXaxis()->GetBinCenter(bin)<<" "<<myHist1->GetBinContent(bin)<<" "<<myHist2->GetBinContent(bin) << " "<<myHist3->GetBinContent(bin)<<" "<<myHist4->GetBinContent(bin) << endl;
}
// This lines draw the results
//myHist1->Draw();
//myHist2->Draw();
out.close();
}