-
Notifications
You must be signed in to change notification settings - Fork 0
/
compare_test.cpp
225 lines (186 loc) · 6.67 KB
/
compare_test.cpp
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/types.h>
#include <getopt.h>
#include <iostream>
#include <set>
#include <assert.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <iomanip> // std::setw
#include <TROOT.h>
#include <TSystem.h>
#include <TStyle.h>
#include <TSpectrum.h>
#include <TF1.h>
#include <TCanvas.h>
#include <TH2F.h>
#include <TFile.h>
#include <TH1F.h>
#include <TGraph.h>
#include <TGraphErrors.h>
#include <TTree.h>
#include "TError.h"
int main(int argc, char * argv[])
{
TFile *f = new TFile("compare.root", "RECREATE");
Int_t N = 3;
std::string *fileNames = new std::string[N];
std::string *date = new std::string[N];
// for(int n = 0 ; n < N ; n++)
// {
fileNames[0] = "/data/acqmanager/calibration/resumes/2015-02-20_04:24:50.root";
fileNames[1] = "/data/acqmanager/calibration/resumes/2015-07-17_02:04:06.root";
fileNames[2] = "/data/acqmanager/calibration/resumes/2015-09-15_05:19:05.root";
// }
for (int n = 0 ; n < N ; n++)
{
std::size_t found = fileNames[n].find_last_of("/\\");
date[n] = fileNames[n].substr(found+1,fileNames[n].substr(found+1).size()-5);
std::cout << " date: " << fileNames[n].substr(found+1,fileNames[n].substr(found+1).size()-5) << std::endl;
}
gSystem->Load("libCalibration.so");
gStyle->SetPalette(1);
gStyle->SetOptFit(1);
gStyle->SetOptStat(0);
Int_t crystalX [6144];
Int_t crystalY [6144];
ifstream cmap ("crystal_map.txt");
while(!cmap.eof()) {
int cid, x, y;
cmap >> cid >> x >> y;
if(cid >= 6144/2)
y += 48;
crystalX[cid] = x;
crystalY[cid] = y;
}
char *smPrefix = "K";
TH2F **hTop = new TH2F*[N];
TH2F **hBottom = new TH2F*[N];;
TH2F **hDifference = new TH2F*[N-1];
TH2F **hRatioTop = new TH2F*[N-1];
TH2F **hRatioBottom = new TH2F*[N-1];
TCanvas **cComparisons = new TCanvas*[N-1];
TCanvas **cCoefficients = new TCanvas*[N];
for(Int_t n = 0; n < N; n++) {
char hName[128];
char hTitle[128];
//kTop
sprintf(hName, "hTop _ %s", date[n].c_str());
sprintf(hTitle, "%s, Top APD %s", smPrefix, date[n].c_str());
hTop[n] = new TH2F(hName, hTitle, 64, 0, 64, 48+48, 0, 48+48);
//kBottom
sprintf(hName, "hBottom_%s", date[n].c_str());
sprintf(hTitle, "%s, Bottom APD %s", smPrefix, date[n].c_str());
hBottom[n] = new TH2F(hName, hTitle, 64, 0, 64, 48+48, 0, 48+48);
// sprintf(hName, "hDifference_%s", date[n]);
// sprintf(hTitle, "%s Difference Top - Bottom (comparison %s)", smPrefix, date[n]);
// hDifference[n] = new TH2F(hName, hTitle, 64, 0, 64, 48+48, 0, 48+48);
TFile * calibrationFile = new TFile(fileNames[n].c_str(), "READ");
TTree * calibrationTree = (TTree *)calibrationFile->Get("T2");
CalibrationSummaryData *csd;
calibrationTree->SetBranchAddress("event", &csd);
for(int i = 0; i < calibrationTree->GetEntries(); i++) {
calibrationTree->GetEntry(i);
if(csd == NULL)
continue;
Int_t crystalID = csd->GetCrystalID();
Int_t cx = crystalX[crystalID]+1;
Int_t cy = crystalY[crystalID]+1;
Int_t asic = (crystalID / 192) % 2;
hTop[n]->SetBinContent(cx, cy, csd->Get22NaKAbsolute());
hBottom[n]->SetBinContent(cx, cy, csd->Get22NaKAbsolute() * csd->Get176LuKrel());
hTop[n]->GetZaxis()->SetRangeUser(0, 10);
hBottom[n]->GetZaxis()->SetRangeUser(0, 10);
}
}
//
for(Int_t n = N-1; n > 0; n--) {
//comparisons
//ktop
char hName[128];
char hTitle[128];
sprintf(hName, "ratio hTop_ %s - %s", date[n].c_str(),date[n-1].c_str());
sprintf(hTitle, "(%s2 - %s1)/%s1, Top APD. %s1 = %s , %s2 %s",smPrefix,smPrefix,smPrefix,smPrefix,date[n-1].c_str(),smPrefix,date[n].c_str());
hRatioTop[n-1] = new TH2F(hName, hTitle, 64, 0, 64, 48+48, 0, 48+48);
//kbottom
sprintf(hName, "ratio hBottom_ %s - %s", date[n].c_str(),date[n-1].c_str());
sprintf(hTitle, "(%s2 - %s1)/%s1, Bottom APD. %s1 = %s , %s2 %s",smPrefix,smPrefix,smPrefix,smPrefix,date[n-1].c_str(),smPrefix,date[n].c_str());
hRatioBottom[n-1] = new TH2F(hName, hTitle, 64, 0, 64, 48+48, 0, 48+48);
for(Int_t cx = 0; cx < 64; cx++) {
for(Int_t cy = 0; cy < 2*48; cy++) {
Float_t v1 = hTop[n-1]->GetBinContent(cx+1, cy+1);
Float_t v2 = hTop[n]->GetBinContent(cx+1, cy+1);
Float_t d = 0;
if(v1 != 0 && v2 != 0)
d = (v2 - v1)/v1;
hRatioTop[n-1]->SetBinContent(cx+1, cy+1, d );
}
}
hRatioTop[n-1]->GetZaxis()->SetRangeUser(-0.2, 0.2);
for(Int_t cx = 0; cx < 64; cx++) {
for(Int_t cy = 0; cy < 2*48; cy++) {
Float_t v1 = hBottom[n-1]->GetBinContent(cx+1, cy+1);
Float_t v2 = hBottom[n]->GetBinContent(cx+1, cy+1);
Float_t d = 0;
if(v1 != 0 && v2 != 0)
d = (v2 - v1)/v1;
hRatioBottom[n-1]->SetBinContent(cx+1, cy+1, d );
}
}
hRatioBottom[n-1]->GetZaxis()->SetRangeUser(-0.2, 0.2);
// h1 = hBottom[n-1];
// h2 = hBottom[n];
//
//
// for(Int_t cx = 0; cx < 64; cx++) {
// for(Int_t cy = 0; cy < 2*48; cy++) {
// Float_t v1 = h1->GetBinContent(cx+1, cy+1);
// Float_t v2 = h2->GetBinContent(cx+1, cy+1);
// Float_t d = 0;
// if(v1 != 0 && v2 != 0)
// d = (v2 - v1)/v1;
// h2->SetBinContent(cx+1, cy+1, d );
// }
// }
// h2->GetZaxis()->SetRangeUser(-0.2, 0.2);
}
for(Int_t n = 0; n < N; n++)
{
char cName[128];
char cTitle[128];
sprintf(cName, "canvas_%s", date[n].c_str());
sprintf(cTitle, "%s Coefficients - Calibration %s", smPrefix, date[n].c_str());
cCoefficients[n] = new TCanvas(cName,cTitle,1200,800);
cCoefficients[n]->Divide(2,1);
cCoefficients[n]->cd(1);
hTop[n]->Draw("COLZ");
cCoefficients[n]->cd(2);
hBottom[n]->Draw("COLZ");
f->cd();
cCoefficients[n]->Write();
}
for(Int_t n = 0; n < N-1; n++)
{
char cName[128];
char cTitle[128];
sprintf(cName, "canvas %s %s", date[n].c_str(),date[n+1].c_str());
sprintf(cTitle, "%s canvas comparison %s %s", smPrefix, date[n].c_str(),date[n+1].c_str());
cComparisons[n] = new TCanvas(cName,cTitle,1200,800);
cComparisons[n]->Divide(3,1);
cComparisons[n]->cd(1);
hRatioTop[n]->Draw("COLZ");
cComparisons[n]->cd(2);
hRatioBottom[n]->Draw("COLZ");
cComparisons[n]->cd(3);
f->cd();
cComparisons[n]->Write();
// hDifference[n-1]->Draw("COLZ");
}
f->Close();
return 0;
}