-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqconvert_to_txt.cpp
More file actions
125 lines (118 loc) · 4.45 KB
/
Copy pathqconvert_to_txt.cpp
File metadata and controls
125 lines (118 loc) · 4.45 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
std::string dbl_to_str (double val, int precision)
{
std::stringstream ss;
ss<<std::fixed<<std::setprecision(precision)<<val;
return ss.str();
}
void read_hist (TH1D *hist, std::string fname) {
std::ifstream str;
str.open(fname, std::ios_base::binary);
if (!str.is_open()) {
std::cerr<<"Failed to open file '"<<fname<<"'"<<std::endl;
return;
}
std::size_t real_size = 0;
str.read((char*)&real_size, sizeof(std::size_t));
std::cout<<"File '"<<fname<<"': "<<real_size<<" events"<<std::endl;
double val;
while (!str.eof()) {
str.read((char*)&val, sizeof(double));
hist->Fill(val);
}
str.close();
}
void read_hist_w (TH1D *hist, std::string fname) {
std::ifstream str;
str.open(fname, std::ios_base::binary);
if (!str.is_open()) {
std::cerr<<"Failed to open file '"<<fname<<"'"<<std::endl;
return;
}
std::size_t real_size = 0;
str.read((char*)&real_size, sizeof(std::size_t));
std::cout<<"File '"<<fname<<"': "<<real_size<<" events"<<std::endl;
double val1;
double val2;
while (!str.eof()) {
str.read((char*)&val1, sizeof(double));
if (str.eof())
break;
str.read((char*)&val2, sizeof(double));
hist->Fill(val1, val2);
}
str.close();
}
void write_hist(TH1D *hist, std::string fname) {
std::ofstream str;
str.open(fname, std::ios_base::trunc);
if (!str.is_open()) {
std::cerr<<"Failed to open file '"<<fname<<"'"<<std::endl;
return;
}
for (int bin = 1, bin_end = hist->GetNbinsX()+1; bin!=bin_end; ++bin)
str<<hist->GetBinCenter(bin)<<"\t"<< hist->GetBinContent(bin)<<std::endl;
str.close();
}
int qconvert_to_txt (void) {
gStyle->SetStatY(0.9);
gStyle->SetStatX(0.9);
int DEF_W = 1300, DEF_H = 700;
int Nbins = 1800;
double time_left = 0, time_right = 160;//us
TF1 *unity_f = new TF1("f1", "1", time_left, time_right);
TH1D* hist_1 = new TH1D ("hist1", "hist1", Nbins, time_left, time_right);
TH1D* hist_2 = new TH1D ("hist2", "hist2", Nbins, time_left, time_right);
TH1D* hist_3 = new TH1D ("hist3", "hist3", Nbins, time_left, time_right);
TH1D* hist_4 = new TH1D ("hist4", "hist4", Nbins, time_left, time_right);
TH1D* hist_5 = new TH1D ("hist5", "hist5", Nbins, time_left, time_right);
TH1D* hist_6 = new TH1D ("hist6", "hist6", Nbins, time_left, time_right);
TH1D* hist_7 = new TH1D ("hist6", "hist6", Nbins, time_left, time_right);
std::vector<TH1D*> hists;
hists.push_back(hist_1);
//hists.push_back(hist_2);
//hists.push_back(hist_3);
//hists.push_back(hist_4);
//hists.push_back(hist_5);
//hists.push_back(hist_6);
//hists.push_back(hist_7);
std::vector<Color_t> palette_major = {kBlack, kRed, kBlue, kGreen, kYellow + 2, kMagenta, kOrange + 7};
std::vector<Color_t> palette_minor = {kGray + 2, kMagenta, kAzure + 10, kGreen -2, kMagenta+3, kOrange - 7, kOrange + 6};
double max_val = 0;
bool linear = true;
std::string prefix = "210128/results_v6/Pu_46V_19kV_850V/forms_Alpha_peak/";
std::string output = "210128/results_v6/v1_hists_for_origin/fPMTs_19kV_Pu_peak.txt";
//read_hist_w (hist_1, prefix + "SiPMs_form_by_Npe.hdata");
read_hist_w (hist_1, prefix + "6_form_by_Npe.hdata");
read_hist_w (hist_1, prefix + "7_form_by_Npe.hdata");
read_hist_w (hist_1, prefix + "8_form_by_Npe.hdata");
write_hist(hist_1, output);
std::string framename = "framename";
for (int hh = 0, hh_end_ = hists.size(); hh!=hh_end_; ++hh)
max_val = std::max(max_val, hists[hh]->GetBinContent(hists[hh]->GetMaximumBin()));
max_val*= linear ? 1.2 : 2;
gStyle->SetGridStyle(3);
gStyle->SetGridColor(14);
gStyle->SetGridWidth(1);
gStyle->SetOptStat("");
TCanvas *c_ = new TCanvas ((std::string(" ") + framename).c_str(), (std::string(" ") + framename).c_str(), DEF_W, DEF_H);
c_->SetGrid(); c_->SetTicks(); c_->ToggleEventStatus(); c_->ToggleToolBar();
if (!linear)
c_->SetLogy();
TLegend *legend = new TLegend(0.55, 0.65, 0.9, 0.9);
//legend->SetHeader("");
legend->SetMargin(0.25);
TH2F* frame = new TH2F("frame", framename.c_str(), 500, time_left, time_right, 500, linear ? 0 : 1e-4, max_val);
frame->GetXaxis()->SetTitle("t [#mus]");
frame->GetYaxis()->SetTitle("");
frame->Draw();
for (int hh = 0, hh_end_ = hists.size(); hh!=hh_end_; ++hh) {
hists[hh]->SetLineWidth(2);
hists[hh]->SetLineColor(palette_major[hh]);
hists[hh]->Draw("hist Lsame");
}
legend->AddEntry(hist_1, (std::string("? Td fPMTs Cd peak")).c_str(), "l");
frame->Draw("sameaxis");
legend->Draw("same");
c_->Update();
return 0;
}