Rev 146 | Rev 172 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 146 | Rev 167 | ||
---|---|---|---|
1 | #include "../include/sipmscan.h" |
1 | #include "../include/sipmscan.h" |
2 | #include "../include/workstation.h" |
2 | #include "../include/workstation.h" |
3 | 3 | ||
4 | #include <stdio.h> |
4 | #include <stdio.h> |
5 | #include <stdlib.h> |
5 | #include <stdlib.h> |
6 | 6 | ||
7 | // Peak detection function |
7 | // Peak detection function |
8 | int npeaks = 20; |
8 | int npeaks = 20; |
9 | double FindPeaks(double *x, double *par) |
9 | double FindPeaks(double *x, double *par) |
10 | { |
10 | { |
11 | double result = 0; |
11 | double result = 0; |
12 | for(int i = 0; i < npeaks; i++) |
12 | for(int i = 0; i < npeaks; i++) |
13 | { |
13 | { |
14 | double norm = par[3*i]; |
14 | double norm = par[3*i]; |
15 | double mean = par[3*i+1]; |
15 | double mean = par[3*i+1]; |
16 | double sigma = par[3*i+2]; |
16 | double sigma = par[3*i+2]; |
17 | result += norm*TMath::Gaus(x[0], mean, sigma); |
17 | result += norm*TMath::Gaus(x[0], mean, sigma); |
18 | } |
18 | } |
19 | return result; |
19 | return result; |
20 | } |
20 | } |
21 | 21 | ||
22 | // File browser for selecting the dark run histogram |
22 | // File browser for selecting the dark run histogram |
23 | void TGAppMainFrame::SelectDarkHist() |
23 | void TGAppMainFrame::SelectDarkHist() |
24 | { |
24 | { |
25 | TGFileInfo file_info; |
25 | TGFileInfo file_info; |
26 | const char *filetypes[] = {"Histograms",histextall,0,0}; |
26 | const char *filetypes[] = {"Histograms",histextall,0,0}; |
27 | char *cTemp; |
27 | char *cTemp; |
28 | file_info.fFileTypes = filetypes; |
28 | file_info.fFileTypes = filetypes; |
29 |
|
29 | // cTemp = new char[1024]; |
30 |
|
30 | // sprintf(cTemp, "%s/results", rootdir); |
31 |
|
31 | // file_info.fIniDir = StrDup(cTemp); |
- | 32 | file_info.fIniDir = StrDup(currentOpenDir); |
|
32 | file_info.fMultipleSelection = kFALSE; |
33 | file_info.fMultipleSelection = kFALSE; |
33 | new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDOpen, &file_info); |
34 | new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDOpen, &file_info); |
34 |
|
35 | // delete[] cTemp; |
35 | 36 | ||
36 | if(file_info.fFilename != NULL) |
37 | if(file_info.fFilename != NULL) |
37 | { |
38 | { |
38 | darkRun->widgetTE->SetText(file_info.fFilename); |
39 | darkRun->widgetTE->SetText(file_info.fFilename); |
39 | fileList->AddEntry(file_info.fFilename, fileList->GetNumberOfEntries()); |
40 | fileList->AddEntry(file_info.fFilename, fileList->GetNumberOfEntries()); |
40 | fileList->Layout(); |
41 | fileList->Layout(); |
41 | } |
42 | } |
42 | else |
43 | else |
43 | darkRun->widgetTE->SetText(""); |
44 | darkRun->widgetTE->SetText(""); |
44 | } |
45 | } |
45 | 46 | ||
46 | // Reset analysis defaults for the current analysis type (0 = Integrate spectrum, 1 = Relative PDE, 2 = Breakdown voltage, 3 = Surface scan, 4 = Timing analysis) |
47 | // Reset analysis defaults for the current analysis type (0 = Integrate spectrum, 1 = Relative PDE, 2 = Breakdown voltage, 3 = Surface scan, 4 = Timing analysis) |
47 | void TGAppMainFrame::AnalysisDefaults() |
48 | void TGAppMainFrame::AnalysisDefaults() |
48 | { |
49 | { |
49 | printf("AnalysisDefaults(): Current analysis tab = %d\n", analTab->GetCurrent()); |
50 | printf("AnalysisDefaults(): Current analysis tab = %d\n", analTab->GetCurrent()); |
50 | if(analTab->GetCurrent() == 0) // Integrate spectrum |
51 | if(analTab->GetCurrent() == 0) // Integrate spectrum |
51 | { |
52 | { |
52 | intSpect->widgetChBox[0]->SetState(kButtonUp); |
53 | intSpect->widgetChBox[0]->SetState(kButtonUp); |
53 | intSpect->widgetChBox[1]->SetState(kButtonUp); |
54 | intSpect->widgetChBox[1]->SetState(kButtonUp); |
54 | intSpect->widgetChBox[2]->SetState(kButtonDown); |
55 | intSpect->widgetChBox[2]->SetState(kButtonDown); |
55 | resol2d->widgetNE[0]->SetNumber(40); |
56 | resol2d->widgetNE[0]->SetNumber(40); |
56 | resol2d->widgetNE[1]->SetNumber(40); |
57 | resol2d->widgetNE[1]->SetNumber(40); |
57 | } |
58 | } |
58 | else if(analTab->GetCurrent() == 1) // Relative PDE |
59 | else if(analTab->GetCurrent() == 1) // Relative PDE |
59 | { |
60 | { |
60 | relPde->widgetChBox[1]->SetState(kButtonDown); |
61 | relPde->widgetChBox[1]->SetState(kButtonDown); |
61 | midPeak->widgetChBox[0]->SetState(kButtonUp); |
62 | midPeak->widgetChBox[0]->SetState(kButtonUp); |
62 | zeroAngle->widgetNE[0]->SetNumber(0.00); |
63 | zeroAngle->widgetNE[0]->SetNumber(0.00); |
63 | } |
64 | } |
64 | else if(analTab->GetCurrent() == 2) // Breakdown voltage |
65 | else if(analTab->GetCurrent() == 2) // Breakdown voltage |
65 | { |
66 | { |
66 | minPeak->widgetNE[0]->SetNumber(2); |
67 | minPeak->widgetNE[0]->SetNumber(2); |
67 | minPeak->widgetNE[0]->SetNumber(1); |
68 | minPeak->widgetNE[0]->SetNumber(1); |
68 | } |
69 | } |
69 | else if(analTab->GetCurrent() == 3) // Surface scan |
70 | else if(analTab->GetCurrent() == 3) // Surface scan |
70 | { |
71 | { |
71 | surfScanOpt->widgetChBox[0]->SetState(kButtonDown); |
72 | surfScanOpt->widgetChBox[0]->SetState(kButtonDown); |
72 | surfScanOpt->widgetChBox[1]->SetState(kButtonUp); |
73 | surfScanOpt->widgetChBox[1]->SetState(kButtonUp); |
73 | resolSurf->widgetNE[0]->SetNumber(40); |
74 | resolSurf->widgetNE[0]->SetNumber(40); |
74 | resolSurf->widgetNE[1]->SetNumber(40); |
75 | resolSurf->widgetNE[1]->SetNumber(40); |
75 | } |
76 | } |
76 | } |
77 | } |
77 | 78 | ||
78 | // Analysis handle function |
79 | // Analysis handle function |
79 | void TGAppMainFrame::AnalysisHandle(int type) |
80 | void TGAppMainFrame::AnalysisHandle(int type) |
80 | { |
81 | { |
81 | TList *files; |
82 | TList *files; |
82 | bool createTab = true; |
83 | bool createTab = true; |
83 | int tabid = -1; |
84 | int tabid = -1; |
84 | int analtab = analTab->GetCurrent(); |
85 | int analtab = analTab->GetCurrent(); |
85 | 86 | ||
86 | int analtype; |
87 | int analtype; |
87 | if( (analtab == 0) && (!intSpect->widgetChBox[0]->IsDown() && !intSpect->widgetChBox[1]->IsDown()) ) |
88 | if( (analtab == 0) && (!intSpect->widgetChBox[0]->IsDown() && !intSpect->widgetChBox[1]->IsDown()) ) |
88 | analtype = 0; |
89 | analtype = 0; |
89 | else if( (analtab == 0) && (intSpect->widgetChBox[0]->IsDown() || intSpect->widgetChBox[1]->IsDown()) ) |
90 | else if( (analtab == 0) && (intSpect->widgetChBox[0]->IsDown() || intSpect->widgetChBox[1]->IsDown()) ) |
90 | analtype = 1; |
91 | analtype = 1; |
91 | else if( analtab == 1 ) |
92 | else if( analtab == 1 ) |
92 | analtype = 2; |
93 | analtype = 2; |
93 | else if( analtab == 2 ) |
94 | else if( analtab == 2 ) |
94 | analtype = 3; |
95 | analtype = 3; |
95 | else if( analtab == 3 ) |
96 | else if( analtab == 3 ) |
96 | analtype = 4; |
97 | analtype = 4; |
97 | 98 | ||
98 | // Only integrate spectrum or make relative PDE |
99 | // Only integrate spectrum or make relative PDE |
99 | if(type == 0) |
100 | if(type == 0) |
100 | { |
101 | { |
101 | files = new TList(); |
102 | files = new TList(); |
102 | fileList->GetSelectedEntries(files); |
103 | fileList->GetSelectedEntries(files); |
103 | 104 | ||
104 | if( analtype == 0 ) |
105 | if( analtype == 0 ) |
105 | IntegSpectrum(files, 0, 0); |
106 | IntegSpectrum(files, 0, 0); |
106 | 107 | ||
107 | if( intSpect->widgetChBox[0]->IsDown() ) |
108 | if( intSpect->widgetChBox[0]->IsDown() ) |
108 | IntegSpectrum(files, 1, 0); |
109 | IntegSpectrum(files, 1, 0); |
109 | 110 | ||
110 | if( intSpect->widgetChBox[1]->IsDown() ) |
111 | if( intSpect->widgetChBox[1]->IsDown() ) |
111 | IntegSpectrum(files, 2, 0); |
112 | IntegSpectrum(files, 2, 0); |
112 | 113 | ||
113 | if( analtype == 2 ) |
114 | if( analtype == 2 ) |
114 | PhotonMu(files, 0); |
115 | PhotonMu(files, 0); |
115 | 116 | ||
116 | if( analtype == 3 ) |
117 | if( analtype == 3 ) |
117 | BreakdownVolt(files, 0); |
118 | BreakdownVolt(files, 0); |
118 | 119 | ||
119 | if( analtype == 4 ) |
120 | if( analtype == 4 ) |
120 | SurfaceScan(files, 0); |
121 | SurfaceScan(files, 0); |
121 | } |
122 | } |
122 | // Integrate spectrum or make relative PDE and open edit window |
123 | // Integrate spectrum or make relative PDE and open edit window |
123 | else if(type == 1) |
124 | else if(type == 1) |
124 | { |
125 | { |
125 | files = new TList(); |
126 | files = new TList(); |
126 | fileList->GetSelectedEntries(files); |
127 | fileList->GetSelectedEntries(files); |
127 | 128 | ||
128 | // Prepare a new analysis edit tab, if we want to edit plots |
129 | // Prepare a new analysis edit tab, if we want to edit plots |
129 | for(int i = 0; i < fTab->GetNumberOfTabs(); i++) |
130 | for(int i = 0; i < fTab->GetNumberOfTabs(); i++) |
130 | { |
131 | { |
131 | if(strcmp("Analysis edit", fTab->GetTabTab(i)->GetString() ) == 0) |
132 | if(strcmp("Analysis edit", fTab->GetTabTab(i)->GetString() ) == 0) |
132 | { |
133 | { |
133 | createTab = false; |
134 | createTab = false; |
134 | tabid = i; |
135 | tabid = i; |
135 | } |
136 | } |
136 | 137 | ||
137 | if(DBGSIG) printf("AnalysisHandle(): Name of tab = %s\n", fTab->GetTabTab(i)->GetString() ); |
138 | if(DBGSIG) printf("AnalysisHandle(): Name of tab = %s\n", fTab->GetTabTab(i)->GetString() ); |
138 | } |
139 | } |
139 | 140 | ||
140 | if(files->GetSize() > 0) |
141 | if(files->GetSize() > 0) |
141 | { |
142 | { |
142 | TempAnalysisTab(fTab, createTab, &tabid, analtype); |
143 | TempAnalysisTab(fTab, createTab, &tabid, analtype); |
143 | 144 | ||
144 | // Integrate spectra |
145 | // Integrate spectra |
145 | if( analtype == 0 ) |
146 | if( analtype == 0 ) |
146 | IntegSpectrum(files, 0, 1); |
147 | IntegSpectrum(files, 0, 1); |
147 | 148 | ||
148 | if( intSpect->widgetChBox[0]->IsDown() ) |
149 | if( intSpect->widgetChBox[0]->IsDown() ) |
149 | IntegSpectrum(files, 1, 1); |
150 | IntegSpectrum(files, 1, 1); |
150 | 151 | ||
151 | if( intSpect->widgetChBox[1]->IsDown() ) |
152 | if( intSpect->widgetChBox[1]->IsDown() ) |
152 | IntegSpectrum(files, 2, 1); |
153 | IntegSpectrum(files, 2, 1); |
153 | 154 | ||
154 | if( analtype == 2 ) |
155 | if( analtype == 2 ) |
155 | PhotonMu(files, 1); |
156 | PhotonMu(files, 1); |
156 | 157 | ||
157 | if( analtype == 3 ) |
158 | if( analtype == 3 ) |
158 | BreakdownVolt(files, 1); |
159 | BreakdownVolt(files, 1); |
159 | 160 | ||
160 | if( analtype == 4 ) |
161 | if( analtype == 4 ) |
161 | SurfaceScan(files, 1); |
162 | SurfaceScan(files, 1); |
162 | 163 | ||
163 | fTab->SetTab(tabid); |
164 | fTab->SetTab(tabid); |
164 | } |
165 | } |
165 | } |
166 | } |
166 | 167 | ||
167 | delete files; |
168 | delete files; |
168 | } |
169 | } |
169 | 170 | ||
170 | // Analysis functions ---------------------------------- |
171 | // Analysis functions ---------------------------------- |
171 | void TGAppMainFrame::IntegSpectrum(TList *files, int direction, int edit) |
172 | void TGAppMainFrame::IntegSpectrum(TList *files, int direction, int edit) |
172 | { |
173 | { |
173 | unsigned int nrfiles = files->GetSize(); |
174 | unsigned int nrfiles = files->GetSize(); |
174 | char ctemp[1024]; |
175 | char ctemp[1024]; |
175 | char exportname[1024]; |
176 | char exportname[1024]; |
176 | int j, k = 0, m = 0; |
177 | int j, k = 0, m = 0; |
177 | 178 | ||
178 | TTree *header_data, *meas_data; |
179 | TTree *header_data, *meas_data; |
179 | double *integralCount, *integralAcc; |
180 | double *integralCount, *integralAcc; |
180 | integralCount = new double[nrfiles]; |
181 | integralCount = new double[nrfiles]; |
181 | integralAcc = new double[nrfiles]; |
182 | integralAcc = new double[nrfiles]; |
182 | double *surfxy, *surfz; |
183 | double *surfxy, *surfz; |
183 | surfxy = new double[nrfiles]; |
184 | surfxy = new double[nrfiles]; |
184 | surfz = new double[nrfiles]; |
185 | surfz = new double[nrfiles]; |
185 | double minInteg, maxInteg; |
186 | double minInteg, maxInteg; |
186 | bool norm = intSpect->widgetChBox[2]->IsDown(); |
187 | bool norm = intSpect->widgetChBox[2]->IsDown(); |
187 | double curzval; |
188 | double curzval; |
188 | bool edge2d = false; |
189 | bool edge2d = false; |
189 | TCanvas *gCanvas; |
190 | TCanvas *gCanvas; |
190 | 191 | ||
191 | float progVal = 0; |
192 | float progVal = 0; |
192 | analysisProgress->widgetPB->SetPosition(progVal); |
193 | analysisProgress->widgetPB->SetPosition(progVal); |
193 | gVirtualX->Update(1); |
194 | gVirtualX->Update(1); |
194 | 195 | ||
195 | // Zero the integral count and accumulated vaules |
196 | // Zero the integral count and accumulated vaules |
196 | for(int i = 0; i < (int)nrfiles; i++) {integralCount[i] = 0; integralAcc[i] = 0; } |
197 | for(int i = 0; i < (int)nrfiles; i++) {integralCount[i] = 0; integralAcc[i] = 0; } |
197 | 198 | ||
198 | // Start if we select at least one file |
199 | // Start if we select at least one file |
199 | if(nrfiles > 0) |
200 | if(nrfiles > 0) |
200 | { |
201 | { |
201 | for(int i = 0; i < (int)nrfiles; i++) |
202 | for(int i = 0; i < (int)nrfiles; i++) |
202 | { |
203 | { |
203 | if(files->At(i)) |
204 | if(files->At(i)) |
204 | { |
205 | { |
205 | // Read the X,Y and Z positions from header and ADC and TDC values from the measurements |
206 | // Read the X,Y and Z positions from header and ADC and TDC values from the measurements |
206 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
207 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
207 | inroot = new TFile(ctemp, "READ"); |
208 | inroot = new TFile(ctemp, "READ"); |
208 | 209 | ||
209 | inroot->GetObject("header_data", header_data); |
210 | inroot->GetObject("header_data", header_data); |
210 | inroot->GetObject("meas_data", meas_data); |
211 | inroot->GetObject("meas_data", meas_data); |
211 | 212 | ||
212 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
213 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
213 | header_data->GetEntry(0); |
214 | header_data->GetEntry(0); |
214 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
215 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
215 | header_data->GetEntry(0); |
216 | header_data->GetEntry(0); |
216 | header_data->SetBranchAddress("zpos", &evtheader.zpos); |
217 | header_data->SetBranchAddress("zpos", &evtheader.zpos); |
217 | header_data->GetEntry(0); |
218 | header_data->GetEntry(0); |
218 | 219 | ||
219 | char rdc[256]; |
220 | char rdc[256]; |
220 | j = selectCh->widgetNE[0]->GetNumber(); |
221 | j = selectCh->widgetNE[0]->GetNumber(); |
221 | double rangetdc[2]; |
222 | double rangetdc[2]; |
222 | rangetdc[0] = tdcRange->widgetNE[0]->GetNumber(); |
223 | rangetdc[0] = tdcRange->widgetNE[0]->GetNumber(); |
223 | rangetdc[1] = tdcRange->widgetNE[1]->GetNumber(); |
224 | rangetdc[1] = tdcRange->widgetNE[1]->GetNumber(); |
224 | 225 | ||
225 | k = 0; |
226 | k = 0; |
226 | m = 0; |
227 | m = 0; |
227 | 228 | ||
228 | // Reading the data |
229 | // Reading the data |
229 | for(int e = 0; e < meas_data->GetEntries(); e++) |
230 | for(int e = 0; e < meas_data->GetEntries(); e++) |
230 | { |
231 | { |
231 | sprintf(rdc, "ADC%d", j); |
232 | sprintf(rdc, "ADC%d", j); |
232 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
233 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
233 | meas_data->GetEntry(e); |
234 | meas_data->GetEntry(e); |
234 | 235 | ||
235 | sprintf(rdc, "TDC%d", j); |
236 | sprintf(rdc, "TDC%d", j); |
236 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
237 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
237 | meas_data->GetEntry(e); |
238 | meas_data->GetEntry(e); |
238 | 239 | ||
239 | // Use data point only if it is inside the TDC window |
240 | // Use data point only if it is inside the TDC window |
240 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
241 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
241 | { |
242 | { |
242 | k++; |
243 | k++; |
243 | m += evtdata.adcdata[j]; |
244 | m += evtdata.adcdata[j]; |
244 | } |
245 | } |
245 | } |
246 | } |
246 | 247 | ||
247 | // X, Y and Z values from each file (table units or microns) |
248 | // X, Y and Z values from each file (table units or microns) |
248 | if( |
249 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
249 | { |
250 | { |
250 | if(direction == 1) |
251 | if(direction == 1) |
251 | surfxy[i] = (double)(evtheader.xpos); |
252 | surfxy[i] = (double)(evtheader.xpos); |
252 | else if(direction == 2) |
253 | else if(direction == 2) |
253 | surfxy[i] = (double)(evtheader.ypos); |
254 | surfxy[i] = (double)(evtheader.ypos); |
254 | surfz[i] = (double)(evtheader.zpos); |
255 | surfz[i] = (double)(evtheader.zpos); |
255 | } |
256 | } |
256 | else if( |
257 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
257 | { |
258 | { |
258 | if(direction == 1) |
259 | if(direction == 1) |
259 | surfxy[i] = (double)(evtheader.xpos*lenconversion); |
260 | surfxy[i] = (double)(evtheader.xpos*lenconversion); |
260 | else if(direction == 2) |
261 | else if(direction == 2) |
261 | surfxy[i] = (double)(evtheader.ypos*lenconversion); |
262 | surfxy[i] = (double)(evtheader.ypos*lenconversion); |
262 | surfz[i] = (double)(evtheader.zpos*lenconversion); |
263 | surfz[i] = (double)(evtheader.zpos*lenconversion); |
263 | } |
264 | } |
264 | 265 | ||
265 | // Check if we have different Z values: if no, just make the edge plots; if yes, save edge plots and make a 2d edge plot |
266 | // Check if we have different Z values: if no, just make the edge plots; if yes, save edge plots and make a 2d edge plot |
266 | if(i == 0) curzval = surfz[i]; |
267 | if(i == 0) curzval = surfz[i]; |
267 | else |
268 | else |
268 | { |
269 | { |
269 | if(surfz[i] != curzval) |
270 | if(surfz[i] != curzval) |
270 | edge2d = true; |
271 | edge2d = true; |
271 | } |
272 | } |
272 | 273 | ||
273 | // Print the calculated integral, if no X or Y direction edge plots are enabled; otherwise, just save for later plotting |
274 | // Print the calculated integral, if no X or Y direction edge plots are enabled; otherwise, just save for later plotting |
274 | if(direction == 0) |
275 | if(direction == 0) |
275 | { |
276 | { |
276 | if(norm) |
277 | if(norm) |
277 | { |
278 | { |
278 | integralCount[i] += ((double)m)/((double)k); |
279 | integralCount[i] += ((double)m)/((double)k); |
279 | printf("IntegSpectrum(): %s: The integral is: %lf\n", ctemp, integralCount[i]); |
280 | printf("IntegSpectrum(): %s: The integral is: %lf\n", ctemp, integralCount[i]); |
280 | } |
281 | } |
281 | else |
282 | else |
282 | { |
283 | { |
283 | integralCount[i] += m; |
284 | integralCount[i] += m; |
284 | printf("IntegSpectrum(): %s: The integral is: %d\n", ctemp, (int)integralCount[i]); |
285 | printf("IntegSpectrum(): %s: The integral is: %d\n", ctemp, (int)integralCount[i]); |
285 | } |
286 | } |
286 | } |
287 | } |
287 | else |
288 | else |
288 | { |
289 | { |
289 | if(norm) |
290 | if(norm) |
290 | integralCount[i] += ((double)m)/((double)k); |
291 | integralCount[i] += ((double)m)/((double)k); |
291 | else |
292 | else |
292 | integralCount[i] += m; |
293 | integralCount[i] += m; |
293 | } |
294 | } |
294 | 295 | ||
295 | inroot->Close(); |
296 | inroot->Close(); |
296 | delete inroot; |
297 | delete inroot; |
297 | } |
298 | } |
298 | 299 | ||
299 | // Update the progress bar |
300 | // Update the progress bar |
300 | progVal = (float)(75.00/nrfiles)*i; |
301 | progVal = (float)(75.00/nrfiles)*i; |
301 | analysisProgress->widgetPB->SetPosition(progVal); |
302 | analysisProgress->widgetPB->SetPosition(progVal); |
302 | gVirtualX->Update(1); |
303 | gVirtualX->Update(1); |
303 | } |
304 | } |
304 | 305 | ||
305 | printf("IntegSpectrum(): %d files were selected.\n", nrfiles); |
306 | printf("IntegSpectrum(): %d files were selected.\n", nrfiles); |
306 | 307 | ||
307 | // If only an integral is needed, do not plot and exit here |
308 | // If only an integral is needed, do not plot and exit here |
308 | if( direction == 0 ) |
309 | if( direction == 0 ) |
309 | { |
310 | { |
310 | delete[] integralCount; |
311 | delete[] integralCount; |
311 | delete[] surfxy; |
312 | delete[] surfxy; |
312 | delete[] surfz; |
313 | delete[] surfz; |
313 | return; |
314 | return; |
314 | } |
315 | } |
315 | 316 | ||
316 | // Current z value and the accumulated counter |
317 | // Current z value and the accumulated counter |
317 | curzval = surfz[0]; |
318 | curzval = surfz[0]; |
318 | j = 0; |
319 | j = 0; |
319 | int acc = 0; |
320 | int acc = 0; |
320 | int zb; |
321 | int zb; |
321 | for(int i = 0; i <= (int)nrfiles; i++) |
322 | for(int i = 0; i <= (int)nrfiles; i++) |
322 | { |
323 | { |
323 | // Collect the accumulated integral in order to produce a PDF from a CDF |
324 | // Collect the accumulated integral in order to produce a PDF from a CDF |
324 | // While we are at the same Z value, save under one set |
325 | // While we are at the same Z value, save under one set |
325 | if( (surfz[i] == curzval) && (acc != nrfiles) ) |
326 | if( (surfz[i] == curzval) && (acc != nrfiles) ) |
326 | { |
327 | { |
327 | integralAcc[j] = integralCount[i]; |
328 | integralAcc[j] = integralCount[i]; |
328 | if(DBGSIG) printf("IntegSpectrum(): Integral check 1 (i=%d,j=%d,z=%.2lf): %lf\t%lf\n", i, j, surfz[i], integralCount[i], integralAcc[j]); |
329 | if(DBGSIG) printf("IntegSpectrum(): Integral check 1 (i=%d,j=%d,z=%.2lf): %lf\t%lf\n", i, j, surfz[i], integralCount[i], integralAcc[j]); |
329 | j++; |
330 | j++; |
330 | acc++; |
331 | acc++; |
331 | } |
332 | } |
332 | // When we switch to a new set of Z values and at the end, we must save the previous ones to make 1D edge plots |
333 | // When we switch to a new set of Z values and at the end, we must save the previous ones to make 1D edge plots |
333 | else |
334 | else |
334 | { |
335 | { |
335 | // Find minimal and maximal integral values to subtract the offset and normate PDF to 1 |
336 | // Find minimal and maximal integral values to subtract the offset and normate PDF to 1 |
336 | NormateSet(i, j, &minInteg, &maxInteg, integralCount, integralAcc); |
337 | NormateSet(i, j, &minInteg, &maxInteg, integralCount, integralAcc); |
337 | 338 | ||
338 | if(acc != nrfiles) |
339 | if(acc != nrfiles) |
339 | { |
340 | { |
340 | curzval = surfz[i]; |
341 | curzval = surfz[i]; |
341 | // PDF and CDF plot |
342 | // PDF and CDF plot |
342 | PlotEdgeDistribution(files, i, j, &minInteg, &maxInteg, surfxy, integralAcc, direction, edge2d, edit); |
343 | PlotEdgeDistribution(files, i, j, &minInteg, &maxInteg, surfxy, integralAcc, direction, edge2d, edit); |
343 | i--; |
344 | i--; |
344 | j = 0; |
345 | j = 0; |
345 | } |
346 | } |
346 | else |
347 | else |
347 | { |
348 | { |
348 | // PDF and CDF plot |
349 | // PDF and CDF plot |
349 | PlotEdgeDistribution(files, i, j, &minInteg, &maxInteg, surfxy, integralAcc, direction, edge2d, edit); |
350 | PlotEdgeDistribution(files, i, j, &minInteg, &maxInteg, surfxy, integralAcc, direction, edge2d, edit); |
350 | i--; |
351 | i--; |
351 | break; |
352 | break; |
352 | } |
353 | } |
353 | } |
354 | } |
354 | 355 | ||
355 | // Update the progress bar |
356 | // Update the progress bar |
356 | progVal = (float)(15.00/nrfiles)*i+75.00; |
357 | progVal = (float)(15.00/nrfiles)*i+75.00; |
357 | analysisProgress->widgetPB->SetPosition(progVal); |
358 | analysisProgress->widgetPB->SetPosition(progVal); |
358 | gVirtualX->Update(1); |
359 | gVirtualX->Update(1); |
359 | } |
360 | } |
360 | 361 | ||
361 | // Make the 2D edge plot |
362 | // Make the 2D edge plot |
362 | if(edge2d) |
363 | if(edge2d) |
363 | { |
364 | { |
364 | if(edit == 0) |
365 | if(edit == 0) |
365 | gCanvas = new TCanvas("canv","canv",900,900); |
366 | gCanvas = new TCanvas("canv","canv",900,900); |
366 | else |
367 | else |
367 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
368 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
368 | 369 | ||
369 | double range[4]; |
370 | double range[4]; |
370 | TGraph2D *gScan2D; |
371 | TGraph2D *gScan2D; |
371 | gScan2D = new TGraph2D(); |
372 | gScan2D = new TGraph2D(); |
372 | range[0] = TMath::MinElement(nrfiles, surfxy); |
373 | range[0] = TMath::MinElement(nrfiles, surfxy); |
373 | range[1] = TMath::MaxElement(nrfiles, surfxy); |
374 | range[1] = TMath::MaxElement(nrfiles, surfxy); |
374 | range[2] = TMath::MinElement(nrfiles, surfz); |
375 | range[2] = TMath::MinElement(nrfiles, surfz); |
375 | range[3] = TMath::MaxElement(nrfiles, surfz); |
376 | range[3] = TMath::MaxElement(nrfiles, surfz); |
376 | 377 | ||
377 | for(int i = 0; i < nrfiles; i++) |
378 | for(int i = 0; i < nrfiles; i++) |
378 | { |
379 | { |
379 | if(DBGSIG) |
380 | if(DBGSIG) |
380 | printf("IntegSpectrum(): %.2lf\t%.2lf\t%lf\n", surfxy[i], surfz[i], integralCount[i]); |
381 | printf("IntegSpectrum(): %.2lf\t%.2lf\t%lf\n", surfxy[i], surfz[i], integralCount[i]); |
381 | gScan2D->SetPoint(i, surfxy[i], surfz[i], integralCount[i]); |
382 | gScan2D->SetPoint(i, surfxy[i], surfz[i], integralCount[i]); |
382 | 383 | ||
383 | // Update the progress bar |
384 | // Update the progress bar |
384 | progVal = (float)(9.00/nrfiles)*i+90.00; |
385 | progVal = (float)(9.00/nrfiles)*i+90.00; |
385 | analysisProgress->widgetPB->SetPosition(progVal); |
386 | analysisProgress->widgetPB->SetPosition(progVal); |
386 | gVirtualX->Update(1); |
387 | gVirtualX->Update(1); |
387 | } |
388 | } |
388 | 389 | ||
389 | gCanvas->cd(); |
390 | gCanvas->cd(); |
390 | gStyle->SetPalette(1); |
391 | gStyle->SetPalette(1); |
391 | gCanvas->SetLeftMargin(0.15); |
392 | gCanvas->SetLeftMargin(0.15); |
392 | gCanvas->SetRightMargin(0.126); |
393 | gCanvas->SetRightMargin(0.126); |
393 | gCanvas->SetTopMargin(0.077); |
394 | gCanvas->SetTopMargin(0.077); |
394 | gScan2D->Draw("COLZ"); |
395 | gScan2D->Draw("COLZ"); |
395 | 396 | ||
396 | gCanvas->Modified(); |
397 | gCanvas->Modified(); |
397 | gCanvas->Update(); |
398 | gCanvas->Update(); |
398 | 399 | ||
399 | gScan2D->SetNpx((int)resol2d->widgetNE[0]->GetNumber()); |
400 | gScan2D->SetNpx((int)resol2d->widgetNE[0]->GetNumber()); |
400 | gScan2D->SetNpy((int)resol2d->widgetNE[1]->GetNumber()); |
401 | gScan2D->SetNpy((int)resol2d->widgetNE[1]->GetNumber()); |
401 | 402 | ||
402 | gCanvas->Modified(); |
403 | gCanvas->Modified(); |
403 | gCanvas->Update(); |
404 | gCanvas->Update(); |
404 | 405 | ||
405 | if(direction == 1) |
406 | if(direction == 1) |
406 | gScan2D->GetXaxis()->SetTitle("X [#mum]"); |
407 | gScan2D->GetXaxis()->SetTitle("X [#mum]"); |
407 | else if(direction == 2) |
408 | else if(direction == 2) |
408 | gScan2D->GetXaxis()->SetTitle("Y [#mum]"); |
409 | gScan2D->GetXaxis()->SetTitle("Y [#mum]"); |
409 | 410 | ||
410 | 411 | ||
411 | gScan2D->GetXaxis()->SetTitleOffset(1.3); |
412 | gScan2D->GetXaxis()->SetTitleOffset(1.3); |
412 | gScan2D->GetXaxis()->CenterTitle(kTRUE); |
413 | gScan2D->GetXaxis()->CenterTitle(kTRUE); |
413 | gScan2D->GetXaxis()->SetLabelSize(0.027); |
414 | gScan2D->GetXaxis()->SetLabelSize(0.027); |
414 | gScan2D->GetXaxis()->SetLabelOffset(0.02); |
415 | gScan2D->GetXaxis()->SetLabelOffset(0.02); |
415 | gScan2D->GetXaxis()->SetRangeUser(range[0], range[1]); |
416 | gScan2D->GetXaxis()->SetRangeUser(range[0], range[1]); |
416 | gScan2D->GetXaxis()->SetNoExponent(kTRUE); |
417 | gScan2D->GetXaxis()->SetNoExponent(kTRUE); |
417 | gScan2D->GetYaxis()->SetTitleOffset(1.9); |
418 | gScan2D->GetYaxis()->SetTitleOffset(1.9); |
418 | gScan2D->GetYaxis()->CenterTitle(kTRUE); |
419 | gScan2D->GetYaxis()->CenterTitle(kTRUE); |
419 | gScan2D->GetYaxis()->SetLabelSize(0.027); |
420 | gScan2D->GetYaxis()->SetLabelSize(0.027); |
420 | gScan2D-> |
421 | gScan2D->GetYaxis()->SetLabelOffset(0.02); |
421 | gScan2D->GetYaxis()->SetRangeUser(range[2], range[3]); |
422 | gScan2D->GetYaxis()->SetRangeUser(range[2], range[3]); |
422 | gScan2D->GetYaxis()->SetNoExponent(kTRUE); |
423 | gScan2D->GetYaxis()->SetNoExponent(kTRUE); |
423 | 424 | ||
424 | /* TGaxis *yax = (TGaxis*)gScan2D->GetYaxis(); |
425 | /* TGaxis *yax = (TGaxis*)gScan2D->GetYaxis(); |
425 | yax->SetMaxDigits(4);*/ |
426 | yax->SetMaxDigits(4);*/ |
426 | 427 | ||
427 | if(!cleanPlots) |
428 | if(!cleanPlots) |
428 | { |
429 | { |
429 | if(direction == 1) |
430 | if(direction == 1) |
430 | { |
431 | { |
431 | if( |
432 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
432 | gScan2D->SetTitle("Laser focal point;X [table units];Z [table units]"); |
433 | gScan2D->SetTitle("Laser focal point;X [table units];Z [table units]"); |
433 | else if( |
434 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
434 | gScan2D->SetTitle("Laser focal point;X [#mum];Z [#mum]"); |
435 | gScan2D->SetTitle("Laser focal point;X [#mum];Z [#mum]"); |
435 | } |
436 | } |
436 | else if(direction == 2) |
437 | else if(direction == 2) |
437 | { |
438 | { |
438 | if( |
439 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
439 | gScan2D->SetTitle("Laser focal point;Y [table units];Z [table units]"); |
440 | gScan2D->SetTitle("Laser focal point;Y [table units];Z [table units]"); |
440 | else if( |
441 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
441 | gScan2D->SetTitle("Laser focal point;Y [#mum];Z [#mum]"); |
442 | gScan2D->SetTitle("Laser focal point;Y [#mum];Z [#mum]"); |
442 | } |
443 | } |
443 | } |
444 | } |
444 | else |
445 | else |
445 | { |
446 | { |
446 | if(direction == 1) |
447 | if(direction == 1) |
447 | { |
448 | { |
448 | if( |
449 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
449 | gScan2D->SetTitle(";X [table units];Z [table units]"); |
450 | gScan2D->SetTitle(";X [table units];Z [table units]"); |
450 | else if( |
451 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
451 | gScan2D->SetTitle(";X [#mum];Z [#mum]"); |
452 | gScan2D->SetTitle(";X [#mum];Z [#mum]"); |
452 | } |
453 | } |
453 | else if(direction == 2) |
454 | else if(direction == 2) |
454 | { |
455 | { |
455 | if( |
456 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
456 | gScan2D->SetTitle(";Y [table units];Z [table units]"); |
457 | gScan2D->SetTitle(";Y [table units];Z [table units]"); |
457 | else if( |
458 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
458 | gScan2D->SetTitle(";Y [#mum];Z [#mum]"); |
459 | gScan2D->SetTitle(";Y [#mum];Z [#mum]"); |
459 | } |
460 | } |
460 | } |
461 | } |
461 | 462 | ||
462 | gCanvas->Modified(); |
463 | gCanvas->Modified(); |
463 | gCanvas->Update(); |
464 | gCanvas->Update(); |
464 | 465 | ||
465 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
466 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
466 | sprintf(exportname, "%s", ctemp); |
467 | sprintf(exportname, "%s", ctemp); |
467 | remove_from_last(exportname, '_', ctemp); |
468 | remove_from_last(exportname, '_', ctemp); |
468 | if(direction == 1) |
469 | if(direction == 1) |
469 | sprintf(exportname, "%s_xdir_focalpoint.pdf", ctemp); |
470 | sprintf(exportname, "%s_xdir_focalpoint.pdf", ctemp); |
470 | else if(direction == 2) |
471 | else if(direction == 2) |
471 | sprintf(exportname, "%s_ydir_focalpoint.pdf", ctemp); |
472 | sprintf(exportname, "%s_ydir_focalpoint.pdf", ctemp); |
472 | gCanvas->SaveAs(exportname); |
473 | gCanvas->SaveAs(exportname); |
473 | 474 | ||
474 | // Update the progress bar |
475 | // Update the progress bar |
475 | analysisProgress->widgetPB->SetPosition(100.0); |
476 | analysisProgress->widgetPB->SetPosition(100.0); |
476 | gVirtualX->Update(1); |
477 | gVirtualX->Update(1); |
477 | 478 | ||
478 | if(edit == 0) |
479 | if(edit == 0) |
479 | { |
480 | { |
480 | delete gScan2D; |
481 | delete gScan2D; |
481 | delete gCanvas; |
482 | delete gCanvas; |
482 | } |
483 | } |
483 | } |
484 | } |
484 | else |
485 | else |
485 | { |
486 | { |
486 | // Update the progress bar |
487 | // Update the progress bar |
487 | analysisProgress->widgetPB->SetPosition(100.0); |
488 | analysisProgress->widgetPB->SetPosition(100.0); |
488 | gVirtualX->Update(1); |
489 | gVirtualX->Update(1); |
489 | } |
490 | } |
490 | } |
491 | } |
491 | } |
492 | } |
492 | 493 | ||
493 | void TGAppMainFrame::PlotEdgeDistribution(TList *files, int filenr, int points, double *min, double *max, double *xy, double *integAcc, int axis, bool edge2d, int edit) |
494 | void TGAppMainFrame::PlotEdgeDistribution(TList *files, int filenr, int points, double *min, double *max, double *xy, double *integAcc, int axis, bool edge2d, int edit) |
494 | { |
495 | { |
495 | TGraph *gScan[2]; |
496 | TGraph *gScan[2]; |
496 | int pdfmax = -1; |
497 | int pdfmax = -1; |
497 | int count = 0; |
498 | int count = 0; |
498 | char ctemp[1024]; |
499 | char ctemp[1024]; |
499 | char exportname[1024]; |
500 | char exportname[1024]; |
500 | TCanvas *gCanvas; |
501 | TCanvas *gCanvas; |
501 | 502 | ||
502 | // Prepare the CDF plot |
503 | // Prepare the CDF plot |
503 | gScan[1] = new TGraph(); |
504 | gScan[1] = new TGraph(); |
504 | for(int i = 0; i < points; i++) |
505 | for(int i = 0; i < points; i++) |
505 | { |
506 | { |
506 | count = filenr - points + i; |
507 | count = filenr - points + i; |
507 | gScan[1]->SetPoint(i, (double)xy[count], (double)integAcc[i]/(*max)); |
508 | gScan[1]->SetPoint(i, (double)xy[count], (double)integAcc[i]/(*max)); |
508 | if(DBGSIG) printf("PlotEdgeDistribution(): CDF %d: %lf, %lf\n", i, (double)xy[count], (double)integAcc[i]/(*max)); |
509 | if(DBGSIG) printf("PlotEdgeDistribution(): CDF %d: %lf, %lf\n", i, (double)xy[count], (double)integAcc[i]/(*max)); |
509 | 510 | ||
510 | if( ((integAcc[i+1]-integAcc[i])/(*max) > pdfmax) && (i < points-1) ) |
511 | if( ((integAcc[i+1]-integAcc[i])/(*max) > pdfmax) && (i < points-1) ) |
511 | pdfmax = (integAcc[i+1]-integAcc[i])/(*max); |
512 | pdfmax = (integAcc[i+1]-integAcc[i])/(*max); |
512 | } |
513 | } |
513 | 514 | ||
514 | pdfmax = (TMath::Ceil(pdfmax*10))/10.; |
515 | pdfmax = (TMath::Ceil(pdfmax*10))/10.; |
515 | 516 | ||
516 | // Prepare the PDF plot |
517 | // Prepare the PDF plot |
517 | gScan[0] = new TGraph(); |
518 | gScan[0] = new TGraph(); |
518 | for(int i = points-1; i >= 0; i--) |
519 | for(int i = points-1; i >= 0; i--) |
519 | { |
520 | { |
520 | count = (filenr-1) - (points-1) + i; |
521 | count = (filenr-1) - (points-1) + i; |
521 | // Set any negative values of the PDF to 0 |
522 | // Set any negative values of the PDF to 0 |
522 | if( (integAcc[i]-integAcc[i-1])/(*max) < 0 ) |
523 | if( (integAcc[i]-integAcc[i-1])/(*max) < 0 ) |
523 | gScan[0]->SetPoint(i, (double)xy[count], 0); |
524 | gScan[0]->SetPoint(i, (double)xy[count], 0); |
524 | else |
525 | else |
525 | gScan[0]->SetPoint(i, (double)xy[count], (integAcc[i]-integAcc[i-1])/(*max)); |
526 | gScan[0]->SetPoint(i, (double)xy[count], (integAcc[i]-integAcc[i-1])/(*max)); |
526 | if(DBGSIG) printf("PlotEdgeDistribution(): PDF %d: %lf, %lf\n", i, (double)xy[count], (integAcc[i+1]-integAcc[i])/(*max)); |
527 | if(DBGSIG) printf("PlotEdgeDistribution(): PDF %d: %lf, %lf\n", i, (double)xy[count], (integAcc[i+1]-integAcc[i])/(*max)); |
527 | } |
528 | } |
528 | 529 | ||
529 | remove_from_last((char*)files->At(filenr-1)->GetTitle(), '_', ctemp); |
530 | remove_from_last((char*)files->At(filenr-1)->GetTitle(), '_', ctemp); |
530 | sprintf(exportname, "%s_edge.pdf", ctemp); |
531 | sprintf(exportname, "%s_edge.pdf", ctemp); |
531 | 532 | ||
532 | if(edit == 0) |
533 | if(edit == 0) |
533 | gCanvas = new TCanvas("canv1d","canv1d",1200,900); |
534 | gCanvas = new TCanvas("canv1d","canv1d",1200,900); |
534 | else |
535 | else |
535 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
536 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
536 | 537 | ||
537 | // Fit the PDF with a gaussian |
538 | // Fit the PDF with a gaussian |
538 | gScan[0]->Fit("gaus","Q"); |
539 | gScan[0]->Fit("gaus","Q"); |
539 | gScan[0]->GetFunction("gaus")->SetNpx(400); |
540 | gScan[0]->GetFunction("gaus")->SetNpx(400); |
540 | 541 | ||
541 | gStyle->SetOptFit(1); |
542 | gStyle->SetOptFit(1); |
542 | 543 | ||
543 | gScan[1]->Draw("AL"); |
544 | gScan[1]->Draw("AL"); |
544 | gPad->Update(); |
545 | gPad->Update(); |
545 | gScan[0]->Draw("LP"); |
546 | gScan[0]->Draw("LP"); |
546 | 547 | ||
547 | gCanvas->Modified(); |
548 | gCanvas->Modified(); |
548 | gCanvas->Update(); |
549 | gCanvas->Update(); |
549 | 550 | ||
550 | TPaveStats *stats = (TPaveStats*)gScan[0]->FindObject("stats"); |
551 | TPaveStats *stats = (TPaveStats*)gScan[0]->FindObject("stats"); |
551 | if(!cleanPlots) |
552 | if(!cleanPlots) |
552 | { |
553 | { |
553 | stats->SetX1NDC(0.86); stats->SetX2NDC(1.0); |
554 | stats->SetX1NDC(0.86); stats->SetX2NDC(1.0); |
554 | stats->SetY1NDC(0.87); stats->SetY2NDC(1.0); |
555 | stats->SetY1NDC(0.87); stats->SetY2NDC(1.0); |
555 | } |
556 | } |
556 | else |
557 | else |
557 | { |
558 | { |
558 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
559 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
559 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
560 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
560 | } |
561 | } |
561 | 562 | ||
562 | gCanvas->SetGridx(1); |
563 | gCanvas->SetGridx(1); |
563 | gCanvas->SetGridy(1); |
564 | gCanvas->SetGridy(1); |
564 | if(axis == 1) |
565 | if(axis == 1) |
565 | gScan[1]->GetXaxis()->SetTitle("X [#mum]"); |
566 | gScan[1]->GetXaxis()->SetTitle("X [#mum]"); |
566 | else if(axis == 2) |
567 | else if(axis == 2) |
567 | gScan[1]->GetXaxis()->SetTitle("Y [#mum]"); |
568 | gScan[1]->GetXaxis()->SetTitle("Y [#mum]"); |
568 | gScan[1]->GetXaxis()->SetTitleOffset(1.3); |
569 | gScan[1]->GetXaxis()->SetTitleOffset(1.3); |
569 | gScan[1]->GetXaxis()->CenterTitle(kTRUE); |
570 | gScan[1]->GetXaxis()->CenterTitle(kTRUE); |
570 | gScan[1]->GetXaxis()->SetLabelSize(0.027); |
571 | gScan[1]->GetXaxis()->SetLabelSize(0.027); |
571 | gScan[1]->GetXaxis()->SetLabelOffset(0.02); |
572 | gScan[1]->GetXaxis()->SetLabelOffset(0.02); |
572 | gScan[1]->GetXaxis()->SetNoExponent(kTRUE); |
573 | gScan[1]->GetXaxis()->SetNoExponent(kTRUE); |
573 | gScan[1]->GetYaxis()->SetTitle("Normalized ADC integral"); |
574 | gScan[1]->GetYaxis()->SetTitle("Normalized ADC integral"); |
574 | 575 | ||
575 | gScan[1]->GetYaxis()->CenterTitle(kTRUE); |
576 | gScan[1]->GetYaxis()->CenterTitle(kTRUE); |
576 | gScan[1]->GetYaxis()->SetLabelSize(0.027); |
577 | gScan[1]->GetYaxis()->SetLabelSize(0.027); |
577 | gScan[1]->GetYaxis()->SetLabelOffset(0.02); |
578 | gScan[1]->GetYaxis()->SetLabelOffset(0.02); |
578 | gScan[1]->GetYaxis()->SetRangeUser(0,1); |
579 | gScan[1]->GetYaxis()->SetRangeUser(0,1); |
579 | gScan[1]->GetYaxis()->SetTitleOffset(1.4); |
580 | gScan[1]->GetYaxis()->SetTitleOffset(1.4); |
580 | gScan[1]->GetYaxis()->SetTitleSize(0.030); |
581 | gScan[1]->GetYaxis()->SetTitleSize(0.030); |
581 | 582 | ||
582 | if(!cleanPlots) |
583 | if(!cleanPlots) |
583 | { |
584 | { |
584 | if(axis == 1) |
585 | if(axis == 1) |
585 | { |
586 | { |
586 | if( |
587 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
587 | gScan[1]->SetTitle("SiPM edge detection;X [table units];Normalized ADC integral"); |
588 | gScan[1]->SetTitle("SiPM edge detection;X [table units];Normalized ADC integral"); |
588 | else if( |
589 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
589 | gScan[1]->SetTitle("SiPM edge detection;X [#mum];Normalized ADC integral"); |
590 | gScan[1]->SetTitle("SiPM edge detection;X [#mum];Normalized ADC integral"); |
590 | } |
591 | } |
591 | else if(axis == 2) |
592 | else if(axis == 2) |
592 | { |
593 | { |
593 | if( |
594 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
594 | gScan[1]->SetTitle("SiPM edge detection;Y [table units];Normalized ADC integral"); |
595 | gScan[1]->SetTitle("SiPM edge detection;Y [table units];Normalized ADC integral"); |
595 | else if( |
596 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
596 | gScan[1]->SetTitle("SiPM edge detection;Y [#mum];Normalized ADC integral"); |
597 | gScan[1]->SetTitle("SiPM edge detection;Y [#mum];Normalized ADC integral"); |
597 | } |
598 | } |
598 | } |
599 | } |
599 | else |
600 | else |
600 | { |
601 | { |
601 | if(axis == 1) |
602 | if(axis == 1) |
602 | { |
603 | { |
603 | if( |
604 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
604 | gScan[1]->SetTitle(";X [table units];Normalized ADC integral"); |
605 | gScan[1]->SetTitle(";X [table units];Normalized ADC integral"); |
605 | else if( |
606 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
606 | gScan[1]->SetTitle(";X [#mum];Normalized ADC integral"); |
607 | gScan[1]->SetTitle(";X [#mum];Normalized ADC integral"); |
607 | } |
608 | } |
608 | else if(axis == 2) |
609 | else if(axis == 2) |
609 | { |
610 | { |
610 | if( |
611 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
611 | gScan[1]->SetTitle(";Y [table units];Normalized ADC integral"); |
612 | gScan[1]->SetTitle(";Y [table units];Normalized ADC integral"); |
612 | else if( |
613 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
613 | gScan[1]->SetTitle(";Y [#mum];Normalized ADC integral"); |
614 | gScan[1]->SetTitle(";Y [#mum];Normalized ADC integral"); |
614 | } |
615 | } |
615 | } |
616 | } |
616 | gScan[1]->SetLineColor(kBlue); |
617 | gScan[1]->SetLineColor(kBlue); |
617 | gScan[0]->SetLineWidth(2); |
618 | gScan[0]->SetLineWidth(2); |
618 | gScan[1]->SetLineWidth(2); |
619 | gScan[1]->SetLineWidth(2); |
619 | 620 | ||
620 | gCanvas->Modified(); |
621 | gCanvas->Modified(); |
621 | gCanvas->Update(); |
622 | gCanvas->Update(); |
622 | 623 | ||
623 | gCanvas->SaveAs(exportname); |
624 | gCanvas->SaveAs(exportname); |
624 | 625 | ||
625 | // If 2D edge plot, delete the 1D edge plots as we go |
626 | // If 2D edge plot, delete the 1D edge plots as we go |
626 | if(edge2d) |
627 | if(edge2d) |
627 | { |
628 | { |
628 | delete gScan[0]; |
629 | delete gScan[0]; |
629 | delete gScan[1]; |
630 | delete gScan[1]; |
630 | if(edit == 0) |
631 | if(edit == 0) |
631 | delete gCanvas; |
632 | delete gCanvas; |
632 | } |
633 | } |
633 | else |
634 | else |
634 | { |
635 | { |
635 | if(edit == 0) |
636 | if(edit == 0) |
636 | { |
637 | { |
637 | delete gScan[0]; |
638 | delete gScan[0]; |
638 | delete gScan[1]; |
639 | delete gScan[1]; |
639 | delete gCanvas; |
640 | delete gCanvas; |
640 | } |
641 | } |
641 | } |
642 | } |
642 | } |
643 | } |
643 | 644 | ||
644 | void TGAppMainFrame::PhotonMu(TList *files, int edit) |
645 | void TGAppMainFrame::PhotonMu(TList *files, int edit) |
645 | { |
646 | { |
646 | unsigned int nrfiles = files->GetSize(); |
647 | unsigned int nrfiles = files->GetSize(); |
647 | char ctemp[1024]; |
648 | char ctemp[1024]; |
648 | char exportname[1024]; |
649 | char exportname[1024]; |
649 | int j, k = 0, m = 0, n = 0, k2 = 0, m2 = 0; |
650 | int j, k = 0, m = 0, n = 0, k2 = 0, m2 = 0; |
650 | 651 | ||
651 | TCanvas *gCanvas; |
652 | TCanvas *gCanvas; |
652 | TTree *header_data, *meas_data; |
653 | TTree *header_data, *meas_data; |
653 | double *integralCount, *integralPedestal; |
654 | double *integralCount, *integralPedestal; |
654 | integralCount = new double[nrfiles]; |
655 | integralCount = new double[nrfiles]; |
655 | integralPedestal = new double[nrfiles]; |
656 | integralPedestal = new double[nrfiles]; |
656 | double *angle, *pdeval, *muval; |
657 | double *angle, *pdeval, *muval; |
657 | angle = new double[nrfiles]; |
658 | angle = new double[nrfiles]; |
658 | pdeval = new double[nrfiles]; |
659 | pdeval = new double[nrfiles]; |
659 | muval = new double[nrfiles]; |
660 | muval = new double[nrfiles]; |
660 | 661 | ||
661 | // Zero the integral count and accumulated vaules |
662 | // Zero the integral count and accumulated vaules |
662 | for(int i = 0; i < (int)nrfiles; i++) {integralCount[i] = 0; integralPedestal[i] = 0; } |
663 | for(int i = 0; i < (int)nrfiles; i++) {integralCount[i] = 0; integralPedestal[i] = 0; } |
663 | 664 | ||
664 | // Fitting variables |
665 | // Fitting variables |
665 | TSpectrum *spec; |
666 | TSpectrum *spec; |
666 | TH1F *histtemp; |
667 | TH1F *histtemp; |
667 | TH1 *histback; |
668 | TH1 *histback; |
668 | TH1F *h2; |
669 | TH1F *h2; |
669 | float *xpeaks; |
670 | float *xpeaks; |
670 | TF1 *fit; |
671 | TF1 *fit; |
671 | TF1 *fittingfunc; |
672 | TF1 *fittingfunc; |
672 | double *fparam, *fparamerr; |
673 | double *fparam, *fparamerr; |
673 | double meansel[20]; |
674 | double meansel[20]; |
674 | double sigmasel[20]; |
675 | double sigmasel[20]; |
675 | double meanparam, paramsigma; |
676 | double meanparam, paramsigma; |
676 | int sortindex[20]; |
677 | int sortindex[20]; |
677 | int adcpedestal[2]; |
678 | int adcpedestal[2]; |
678 | int zeromu = 0; |
679 | int zeromu = 0; |
679 | int darkhist = -1; |
680 | int darkhist = -1; |
680 | 681 | ||
681 | double pointest[12]; |
682 | double pointest[12]; |
682 | bool exclude = false; |
683 | bool exclude = false; |
683 | 684 | ||
684 | // Zero the parameter values |
685 | // Zero the parameter values |
685 | for(int i = 0; i < 20; i++) {meansel[i] = 0; sigmasel[i] = 0; } |
686 | for(int i = 0; i < 20; i++) {meansel[i] = 0; sigmasel[i] = 0; } |
686 | 687 | ||
687 | float progVal = 0; |
688 | float progVal = 0; |
688 | analysisProgress->widgetPB->SetPosition(progVal); |
689 | analysisProgress->widgetPB->SetPosition(progVal); |
689 | gVirtualX->Update(1); |
690 | gVirtualX->Update(1); |
690 | 691 | ||
691 | // Start if we select at least one file |
692 | // Start if we select at least one file |
692 | if(nrfiles > 0) |
693 | if(nrfiles > 0) |
693 | { |
694 | { |
694 | for(int i = 0; i < (int)nrfiles; i++) |
695 | for(int i = 0; i < (int)nrfiles; i++) |
695 | { |
696 | { |
696 | if(files->At(i)) |
- | |
697 | { |
- | |
698 |
|
697 | if( (nrfiles == 1) || (!multiSelect->widgetChBox[0]->IsDown()) ) |
699 | { |
698 | { |
- | 699 | printf("PhotonMu(): Only one file selected. Not running analysis, just showing the fit.\n"); |
|
- | 700 | ||
- | 701 | // Replot the spectrum on analysisCanvas and do not close the input file |
|
- | 702 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, 1); |
|
- | 703 | analysisCanvas->GetCanvas()->Modified(); |
|
- | 704 | analysisCanvas->GetCanvas()->Update(); |
|
- | 705 | ||
- | 706 | // Get the spectrum |
|
- | 707 | histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname); |
|
- | 708 | npeaks = 15; |
|
- | 709 | double par[300]; |
|
- | 710 | spec = new TSpectrum(npeaks); |
|
- | 711 | // Find spectrum background |
|
- | 712 | histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same"); |
|
- | 713 | // Clone histogram and subtract background from it if we select that option |
|
- | 714 | h2 = (TH1F*)histtemp->Clone("h2"); |
|
- | 715 | if(fitChecks->widgetChBox[0]->IsDown()) |
|
- | 716 | h2->Add(histback, -1); |
|
- | 717 | // Search for the peaks |
|
- | 718 | int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() ); |
|
- | 719 | printf("PhotonMu(): Found %d candidates to fit.\n",found); |
|
- | 720 | npeaks = found; |
|
- | 721 | ||
- | 722 | // Set initial peak parameters |
|
- | 723 | xpeaks = spec->GetPositionX(); |
|
- | 724 | for(j = 0; j < found; j++) |
|
- | 725 | { |
|
- | 726 | float xp = xpeaks[j]; |
|
- | 727 | int bin = h2->GetXaxis()->FindBin(xp); |
|
- | 728 | float yp = h2->GetBinContent(bin); |
|
- | 729 | par[3*j] = yp; |
|
- | 730 | par[3*j+1] = xp; |
|
- | 731 | par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber(); |
|
- | 732 | } |
|
- | 733 | ||
- | 734 | // Fit the histogram |
|
- | 735 | fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks); |
|
- | 736 | TVirtualFitter::Fitter(histtemp, 3*npeaks); |
|
- | 737 | fit->SetParameters(par); |
|
- | 738 | fit->SetNpx(300); |
|
- | 739 | h2->Fit("fit","Q"); |
|
- | 740 | // Get the fitted parameters |
|
- | 741 | fittingfunc = h2->GetFunction("fit"); |
|
- | 742 | fparam = fittingfunc->GetParameters(); |
|
- | 743 | fparamerr = fittingfunc->GetParErrors(); |
|
- | 744 | ||
- | 745 | // Gather the parameters (mean peak value for now) |
|
- | 746 | int j = 1; |
|
- | 747 | int nrfit = 0; |
|
- | 748 | while(1) |
|
- | 749 | { |
|
- | 750 | if( (fparam[j] < 1.E-30) || (nrfit > 8) ) |
|
- | 751 | break; |
|
- | 752 | else |
|
- | 753 | { |
|
- | 754 | // Check if pedestal is above the lower limit and sigma is smaller than the mean |
|
- | 755 | if( (fparam[j] > pedesLow->widgetNE[0]->GetNumber()) && ((double)fparamerr[j]/fparam[j] < accError->widgetNE[0]->GetNumber()) ) |
|
- | 756 | { |
|
- | 757 | // With the additional ADC offset, we can shift the mean values slightly, so they are not close to the X.5, but to the X.0 values |
|
- | 758 | meansel[nrfit] = fparam[j]+(adcOffset->widgetNE[0]->GetNumber()); |
|
- | 759 | sigmasel[nrfit] = fparam[j+1]; |
|
- | 760 | nrfit++; |
|
- | 761 | } |
|
- | 762 | } |
|
- | 763 | ||
- | 764 | j+=3; |
|
- | 765 | } |
|
- | 766 | TMath::Sort(nrfit, meansel, sortindex, kFALSE); |
|
- | 767 | ||
- | 768 | fittingfunc->Draw("SAME"); |
|
- | 769 | analysisCanvas->GetCanvas()->Modified(); |
|
- | 770 | analysisCanvas->GetCanvas()->Update(); |
|
- | 771 | ||
- | 772 | meanparam = meansel[sortindex[0]]; |
|
- | 773 | paramsigma = sigmasel[sortindex[0]]; |
|
- | 774 | ||
- | 775 | for(j = 0; j < nrfit; j++) |
|
- | 776 | printf("PhotonMu(): %d: peak mean = %lf\n", j, meansel[sortindex[j]]); |
|
- | 777 | ||
- | 778 | ||
- | 779 | ||
- | 780 | return; |
|
- | 781 | } |
|
- | 782 | if(files->At(i)) |
|
- | 783 | { |
|
- | 784 | if(strcmp(files->At(i)->GetTitle(),darkRun->widgetTE->GetText()) == 0) |
|
- | 785 | { |
|
700 | printf("PhotonMu(): %s is the dark histogram file.\n", files->At(i)->GetTitle()); |
786 | printf("PhotonMu(): %s is the dark histogram file.\n", files->At(i)->GetTitle()); |
701 | darkhist = i; |
787 | darkhist = i; |
702 | } |
788 | } |
703 | 789 | ||
704 | // Replot the spectrum on analysisCanvas and do not close the input file |
790 | // Replot the spectrum on analysisCanvas and do not close the input file |
705 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, 1); |
791 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, 1); |
706 | analysisCanvas->GetCanvas()->Modified(); |
792 | analysisCanvas->GetCanvas()->Modified(); |
707 | analysisCanvas->GetCanvas()->Update(); |
793 | analysisCanvas->GetCanvas()->Update(); |
708 | 794 | ||
709 | // Get the spectrum |
795 | // Get the spectrum |
710 | histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname); |
796 | histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname); |
711 | npeaks = 15; |
797 | npeaks = 15; |
712 | double par[300]; |
798 | double par[300]; |
713 | spec = new TSpectrum(npeaks); |
799 | spec = new TSpectrum(npeaks); |
714 | // Find spectrum background |
800 | // Find spectrum background |
715 | histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same"); |
801 | histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same"); |
716 | // Clone histogram and subtract background from it if we select that option |
802 | // Clone histogram and subtract background from it if we select that option |
717 | h2 = (TH1F*)histtemp->Clone("h2"); |
803 | h2 = (TH1F*)histtemp->Clone("h2"); |
718 | if(fitChecks->widgetChBox[0]->IsDown()) |
804 | if(fitChecks->widgetChBox[0]->IsDown()) |
719 | h2->Add(histback, -1); |
805 | h2->Add(histback, -1); |
720 | // Search for the peaks |
806 | // Search for the peaks |
721 | int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() ); |
807 | int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() ); |
722 | printf("PhotonMu(): Found %d candidates to fit.\n",found); |
808 | printf("PhotonMu(): Found %d candidates to fit.\n",found); |
723 | npeaks = found; |
809 | npeaks = found; |
724 | 810 | ||
725 | // Set initial peak parameters |
811 | // Set initial peak parameters |
726 | xpeaks = spec->GetPositionX(); |
812 | xpeaks = spec->GetPositionX(); |
727 | for(j = 0; j < found; j++) |
813 | for(j = 0; j < found; j++) |
728 | { |
814 | { |
729 | float xp = xpeaks[j]; |
815 | float xp = xpeaks[j]; |
730 | int bin = h2->GetXaxis()->FindBin(xp); |
816 | int bin = h2->GetXaxis()->FindBin(xp); |
731 | float yp = h2->GetBinContent(bin); |
817 | float yp = h2->GetBinContent(bin); |
732 | par[3*j] = yp; |
818 | par[3*j] = yp; |
733 | par[3*j+1] = xp; |
819 | par[3*j+1] = xp; |
734 | par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber(); |
820 | par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber(); |
735 | } |
821 | } |
736 | 822 | ||
737 | // Fit the histogram |
823 | // Fit the histogram |
738 | fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks); |
824 | fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks); |
739 | TVirtualFitter::Fitter(histtemp, 3*npeaks); |
825 | TVirtualFitter::Fitter(histtemp, 3*npeaks); |
740 | fit->SetParameters(par); |
826 | fit->SetParameters(par); |
741 | fit->SetNpx(300); |
827 | fit->SetNpx(300); |
742 | h2->Fit("fit","Q"); |
828 | h2->Fit("fit","Q"); |
743 | // Get the fitted parameters |
829 | // Get the fitted parameters |
744 | fittingfunc = h2->GetFunction("fit"); |
830 | fittingfunc = h2->GetFunction("fit"); |
745 | fparam = fittingfunc->GetParameters(); |
831 | fparam = fittingfunc->GetParameters(); |
746 | fparamerr = fittingfunc->GetParErrors(); |
832 | fparamerr = fittingfunc->GetParErrors(); |
747 | 833 | ||
748 | // Gather the parameters (mean peak value for now) |
834 | // Gather the parameters (mean peak value for now) |
749 | int j = 1; |
835 | int j = 1; |
750 | int nrfit = 0; |
836 | int nrfit = 0; |
751 | while(1) |
837 | while(1) |
752 | { |
838 | { |
753 | if( (fparam[j] < 1.E-30) || (nrfit > 8) ) |
839 | if( (fparam[j] < 1.E-30) || (nrfit > 8) ) |
754 | break; |
840 | break; |
755 | else |
841 | else |
756 | { |
842 | { |
757 | // Check if pedestal is above the lower limit and sigma is smaller than the mean |
843 | // Check if pedestal is above the lower limit and sigma is smaller than the mean |
758 | if( (fparam[j] > pedesLow->widgetNE[0]->GetNumber()) && ((double)fparamerr[j]/fparam[j] < accError->widgetNE[0]->GetNumber()) ) |
844 | if( (fparam[j] > pedesLow->widgetNE[0]->GetNumber()) && ((double)fparamerr[j]/fparam[j] < accError->widgetNE[0]->GetNumber()) ) |
759 | { |
845 | { |
760 | // With the additional ADC offset, we can shift the mean values slightly, so they are not close to the X.5, but to the X.0 values |
846 | // With the additional ADC offset, we can shift the mean values slightly, so they are not close to the X.5, but to the X.0 values |
761 | meansel[nrfit] = fparam[j]+(adcOffset->widgetNE[0]->GetNumber()); |
847 | meansel[nrfit] = fparam[j]+(adcOffset->widgetNE[0]->GetNumber()); |
762 | sigmasel[nrfit] = fparam[j+1]; |
848 | sigmasel[nrfit] = fparam[j+1]; |
763 | nrfit++; |
849 | nrfit++; |
764 | } |
850 | } |
765 | } |
851 | } |
766 | 852 | ||
767 | j+=3; |
853 | j+=3; |
768 | } |
854 | } |
769 | TMath::Sort(nrfit, meansel, sortindex, kFALSE); |
855 | TMath::Sort(nrfit, meansel, sortindex, kFALSE); |
770 | 856 | ||
771 | meanparam = meansel[sortindex[0]]; |
857 | meanparam = meansel[sortindex[0]]; |
772 | paramsigma = sigmasel[sortindex[0]]; |
858 | paramsigma = sigmasel[sortindex[0]]; |
773 | 859 | ||
774 | for(j = 0; j < nrfit; j++) |
860 | for(j = 0; j < nrfit; j++) |
775 | if(DBGSIG) |
861 | if(DBGSIG) |
776 | printf("PhotonMu(): %d: peak mean = %lf\n", j, meansel[sortindex[j]]); |
862 | printf("PhotonMu(): %d: peak mean = %lf\n", j, meansel[sortindex[j]]); |
777 | 863 | ||
778 | j = 0; |
864 | j = 0; |
779 | adcpedestal[0] = 0; |
865 | adcpedestal[0] = 0; |
780 | adcpedestal[1] = -1; |
866 | adcpedestal[1] = -1; |
781 | 867 | ||
782 | while(1) |
868 | while(1) |
783 | { |
869 | { |
784 | int bin = histtemp->GetXaxis()->FindBin((int)(j+meanparam+paramsigma)); |
870 | int bin = histtemp->GetXaxis()->FindBin((int)(j+meanparam+paramsigma)); |
785 | int yp = histtemp->GetBinContent(bin); |
871 | int yp = histtemp->GetBinContent(bin); |
786 | 872 | ||
787 | // Check where we get to first minimum after pedestal peak or where we get to the half maximum of the pedestal peak (in case there is only a pedestal peak) |
873 | // Check where we get to first minimum after pedestal peak or where we get to the half maximum of the pedestal peak (in case there is only a pedestal peak) |
788 | if(adcpedestal[1] == -1) |
874 | if(adcpedestal[1] == -1) |
789 | { |
875 | { |
790 | adcpedestal[0] = j+meanparam+paramsigma; |
876 | adcpedestal[0] = j+meanparam+paramsigma; |
791 | adcpedestal[1] = yp; |
877 | adcpedestal[1] = yp; |
792 | } |
878 | } |
793 | else |
879 | else |
794 | { |
880 | { |
795 | if( (npeaks > 1) && (adcpedestal[1] >= yp) ) |
881 | if( (npeaks > 1) && (adcpedestal[1] >= yp) ) |
796 | { |
882 | { |
797 | adcpedestal[0] = j+meanparam+paramsigma; |
883 | adcpedestal[0] = j+meanparam+paramsigma; |
798 | adcpedestal[1] = yp; |
884 | adcpedestal[1] = yp; |
799 | } |
885 | } |
800 | else if( (npeaks == 1) && (adcpedestal[0] < meanparam+5*paramsigma) ) // TODO -> Determining the pedestal when only one peak |
886 | else if( (npeaks == 1) && (adcpedestal[0] < meanparam+5*paramsigma) ) // TODO -> Determining the pedestal when only one peak |
801 | { |
887 | { |
802 | adcpedestal[0] = j+meanparam+paramsigma; |
888 | adcpedestal[0] = j+meanparam+paramsigma; |
803 | adcpedestal[1] = yp; |
889 | adcpedestal[1] = yp; |
804 | } |
890 | } |
805 | else |
891 | else |
806 | break; |
892 | break; |
807 | } |
893 | } |
808 | 894 | ||
809 | j++; |
895 | j++; |
810 | if(j > 50) break; |
896 | if(j > 50) break; |
811 | } |
897 | } |
812 | 898 | ||
813 | if(npeaks > 1) |
899 | if(npeaks > 1) |
814 | { |
900 | { |
815 | int bin = histtemp->GetXaxis()->FindBin((int)(meanparam+meansel[sortindex[1]])/2); |
901 | int bin = histtemp->GetXaxis()->FindBin((int)(meanparam+meansel[sortindex[1]])/2); |
816 | adcpedestal[0] = (meanparam+meansel[sortindex[1]])/2; |
902 | adcpedestal[0] = (meanparam+meansel[sortindex[1]])/2; |
817 | printf("PhotonMu(): multipeak x = %d, ", adcpedestal[0]); |
903 | printf("PhotonMu(): multipeak x = %d, ", adcpedestal[0]); |
818 | adcpedestal[1] = histtemp->GetBinContent(bin); |
904 | adcpedestal[1] = histtemp->GetBinContent(bin); |
819 | } |
905 | } |
820 | 906 | ||
821 | if(midPeak->widgetChBox[0]->IsDown()) |
907 | if(midPeak->widgetChBox[0]->IsDown()) |
822 | { |
908 | { |
823 | if( (meanparam - (int)meanparam >= 0.) && (meanparam - (int)meanparam < 0.5) ) |
909 | if( (meanparam - (int)meanparam >= 0.) && (meanparam - (int)meanparam < 0.5) ) |
824 | m = TMath::Floor(meanparam); |
910 | m = TMath::Floor(meanparam); |
825 | else if( (meanparam - (int)meanparam >= 0.5) && (meanparam - (int)meanparam < 1.) ) |
911 | else if( (meanparam - (int)meanparam >= 0.5) && (meanparam - (int)meanparam < 1.) ) |
826 | m = TMath::Ceil(meanparam); |
912 | m = TMath::Ceil(meanparam); |
827 | int bin = histtemp->GetXaxis()->FindBin(m); |
913 | int bin = histtemp->GetXaxis()->FindBin(m); |
828 | adcpedestal[0] = m; |
914 | adcpedestal[0] = m; |
829 | printf("midpeak x = %d, ", adcpedestal[0]); |
915 | printf("midpeak x = %d, ", adcpedestal[0]); |
830 | adcpedestal[1] = histtemp->GetBinContent(bin); |
916 | adcpedestal[1] = histtemp->GetBinContent(bin); |
831 | } |
917 | } |
832 | 918 | ||
833 | /* // Option to show the fit |
919 | /* // Option to show the fit |
834 | fittingfunc->Draw("L SAME"); |
920 | fittingfunc->Draw("L SAME"); |
835 | analysisCanvas->GetCanvas()->Modified(); |
921 | analysisCanvas->GetCanvas()->Modified(); |
836 | analysisCanvas->GetCanvas()->Update();*/ |
922 | analysisCanvas->GetCanvas()->Update();*/ |
837 | 923 | ||
838 | printf("Pedestal ends = %d and nr. of counts = %d\n", adcpedestal[0], adcpedestal[1]); |
924 | printf("Pedestal ends = %d and nr. of counts = %d\n", adcpedestal[0], adcpedestal[1]); |
839 | 925 | ||
840 | // Delete the opened histogram and spectrum |
926 | // Delete the opened histogram and spectrum |
841 | delete spec; |
927 | delete spec; |
842 | delete inroot; |
928 | delete inroot; |
843 | 929 | ||
844 | // Open the input file and read header, ADC and TDC values |
930 | // Open the input file and read header, ADC and TDC values |
845 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
931 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
846 | inroot = new TFile(ctemp, "READ"); |
932 | inroot = new TFile(ctemp, "READ"); |
847 | 933 | ||
848 | inroot->GetObject("header_data", header_data); |
934 | inroot->GetObject("header_data", header_data); |
849 | inroot->GetObject("meas_data", meas_data); |
935 | inroot->GetObject("meas_data", meas_data); |
850 | 936 | ||
851 | // Reading the header |
937 | // Reading the header |
852 | if( header_data->FindBranch("angle") ) |
938 | if( header_data->FindBranch("angle") ) |
853 | { |
939 | { |
854 | header_data->SetBranchAddress("angle", &evtheader.angle); |
940 | header_data->SetBranchAddress("angle", &evtheader.angle); |
855 | header_data->GetEntry(0); |
941 | header_data->GetEntry(0); |
856 | } |
942 | } |
857 | else |
943 | else |
858 | { |
944 | { |
859 | printf("PhotonMu(): Error! Selected file has no angle header value. Please edit header to add the angle header value.\n"); |
945 | printf("PhotonMu(): Error! Selected file has no angle header value. Please edit header to add the angle header value.\n"); |
860 | break; |
946 | break; |
861 | } |
947 | } |
862 | 948 | ||
863 | char rdc[256]; |
949 | char rdc[256]; |
864 | j = selectCh->widgetNE[0]->GetNumber(); |
950 | j = selectCh->widgetNE[0]->GetNumber(); |
865 | double rangetdc[2]; |
951 | double rangetdc[2]; |
866 | rangetdc[0] = tdcRange->widgetNE[0]->GetNumber(); |
952 | rangetdc[0] = tdcRange->widgetNE[0]->GetNumber(); |
867 | rangetdc[1] = tdcRange->widgetNE[1]->GetNumber(); |
953 | rangetdc[1] = tdcRange->widgetNE[1]->GetNumber(); |
868 | 954 | ||
869 | k = 0; |
955 | k = 0; |
870 | k2 = 0; |
956 | k2 = 0; |
871 | m = 0; |
957 | m = 0; |
872 | m2 = 0; |
958 | m2 = 0; |
873 | 959 | ||
874 | // Reading the data |
960 | // Reading the data |
875 | for(int e = 0; e < meas_data->GetEntries(); e++) |
961 | for(int e = 0; e < meas_data->GetEntries(); e++) |
876 | { |
962 | { |
877 | sprintf(rdc, "ADC%d", j); |
963 | sprintf(rdc, "ADC%d", j); |
878 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
964 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
879 | meas_data->GetEntry(e); |
965 | meas_data->GetEntry(e); |
880 | 966 | ||
881 | sprintf(rdc, "TDC%d", j); |
967 | sprintf(rdc, "TDC%d", j); |
882 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
968 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
883 | meas_data->GetEntry(e); |
969 | meas_data->GetEntry(e); |
884 | 970 | ||
885 | // If our data point is inside the TDC window |
971 | // If our data point is inside the TDC window |
886 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
972 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
887 | { |
973 | { |
888 | // Gather only the integral of the pedestal |
974 | // Gather only the integral of the pedestal |
889 | if((double)evtdata.adcdata[j] < (double)adcpedestal[0]+0.5 ) |
975 | if((double)evtdata.adcdata[j] < (double)adcpedestal[0]+0.5 ) |
890 | { |
976 | { |
891 | k2++; |
977 | k2++; |
892 | m2 += evtdata.adcdata[j]; |
978 | m2 += evtdata.adcdata[j]; |
893 | } |
979 | } |
894 | 980 | ||
895 | // Gather the complete integral |
981 | // Gather the complete integral |
896 | k++; |
982 | k++; |
897 | m += evtdata.adcdata[j]; |
983 | m += evtdata.adcdata[j]; |
898 | } |
984 | } |
899 | } |
985 | } |
900 | 986 | ||
901 | // Determine the angle, mu and relative PDE |
987 | // Determine the angle, mu and relative PDE |
902 | angle[i] = (double)(evtheader.angle); |
988 | angle[i] = (double)(evtheader.angle); |
903 | integralCount[i] += (double)m; |
989 | integralCount[i] += (double)m; |
904 | printf("PhotonMu(): %lf: Complete integral (%d evts) = %lf\n", angle[i], k, integralCount[i]); |
990 | printf("PhotonMu(): %lf: Complete integral (%d evts) = %lf\n", angle[i], k, integralCount[i]); |
905 | integralPedestal[i] += (double)m2; |
991 | integralPedestal[i] += (double)m2; |
906 | printf("PhotonMu(): %lf: Pedestal integral (%d evts) = %lf\n", angle[i], k2, integralPedestal[i]); |
992 | printf("PhotonMu(): %lf: Pedestal integral (%d evts) = %lf\n", angle[i], k2, integralPedestal[i]); |
907 | if( (angle[i] == zeroAngle->widgetNE[0]->GetNumber()) && (darkhist != i) ) |
993 | if( (angle[i] == zeroAngle->widgetNE[0]->GetNumber()) && (darkhist != i) ) |
908 | zeromu = i; |
994 | zeromu = i; |
909 | 995 | ||
910 | muval[i] = -TMath::Log((double)k2/(double)k); |
996 | muval[i] = -TMath::Log((double)k2/(double)k); |
911 | printf("PhotonMu(): %lf: muval = %lf\n", angle[i], muval[i]); |
997 | printf("PhotonMu(): %lf: muval = %lf\n", angle[i], muval[i]); |
912 | 998 | ||
913 | inroot->Close(); |
999 | inroot->Close(); |
914 | delete inroot; |
1000 | delete inroot; |
915 | } |
1001 | } |
916 | 1002 | ||
917 | // Update the progress bar |
1003 | // Update the progress bar |
918 | progVal = (float)(90.00/nrfiles)*i; |
1004 | progVal = (float)(90.00/nrfiles)*i; |
919 | analysisProgress->widgetPB->SetPosition(progVal); |
1005 | analysisProgress->widgetPB->SetPosition(progVal); |
920 | gVirtualX->Update(1); |
1006 | gVirtualX->Update(1); |
921 | } |
1007 | } |
922 | 1008 | ||
923 | printf("PhotonMu(): %d files were selected.\n", nrfiles); |
1009 | printf("PhotonMu(): %d files were selected.\n", nrfiles); |
924 | 1010 | ||
925 | printf("PhotonMu(): angle\tmu\trelative PDE\n"); |
1011 | printf("PhotonMu(): angle\tmu\trelative PDE\n"); |
926 | m = 0; |
1012 | m = 0; |
927 | 1013 | ||
928 | // Set the 0 degree muval, reuse meansel[1] |
1014 | // Set the 0 degree muval, reuse meansel[1] |
929 | meansel[1] = muval[zeromu]; |
1015 | meansel[1] = muval[zeromu]; |
930 | printf("Zero value (id=%d, angle=%lf) = %lf\n", zeromu, angle[zeromu], meansel[1]); |
1016 | printf("Zero value (id=%d, angle=%lf) = %lf\n", zeromu, angle[zeromu], meansel[1]); |
931 | 1017 | ||
932 | // TODO - point estimation still not working correctly! |
1018 | // TODO - point estimation still not working correctly! |
933 | for(int i = 0; i < (int)nrfiles; i++) |
1019 | for(int i = 0; i < (int)nrfiles; i++) |
934 | { |
1020 | { |
935 | // Estimate next point and check error (5 point least square fit estimation) |
1021 | // Estimate next point and check error (5 point least square fit estimation) |
936 | if( ((i > 4) && (m == i)) || ((i > 5) && (m < i)) ) |
1022 | if( ((i > 4) && (m == i)) || ((i > 5) && (m < i)) ) |
937 | { |
1023 | { |
938 | // Set exclude signal to false |
1024 | // Set exclude signal to false |
939 | exclude = false; |
1025 | exclude = false; |
940 | 1026 | ||
941 | // Get next point values (if zero value -> need to add the dark hist value again) |
1027 | // Get next point values (if zero value -> need to add the dark hist value again) |
942 | pointest[10] = angle[i]; |
1028 | pointest[10] = angle[i]; |
943 | pointest[11] = muval[i]; |
1029 | pointest[11] = muval[i]; |
944 | 1030 | ||
945 | // Check if next point has larger error than acceptable (if yes, set exclude signal to true), reuse meansel[0] |
1031 | // Check if next point has larger error than acceptable (if yes, set exclude signal to true), reuse meansel[0] |
946 | meansel[0] = PointEstimate(5, pointest); // PointEstimate only works with very small step size |
1032 | meansel[0] = PointEstimate(5, pointest); // PointEstimate only works with very small step size |
947 | if(meansel[0] > accError->widgetNE[0]->GetNumber()) |
1033 | if(meansel[0] > accError->widgetNE[0]->GetNumber()) |
948 | { |
1034 | { |
949 | printf("PhotonMu(): Point (%lf, %lf) excluded due to error: %lf\n", pointest[10], pointest[11], meansel[0]); |
1035 | printf("PhotonMu(): Point (%lf, %lf) excluded due to error: %lf\n", pointest[10], pointest[11], meansel[0]); |
950 | exclude = true; |
1036 | exclude = true; |
951 | } |
1037 | } |
952 | 1038 | ||
953 | // Value with 0 angle and dark histogram are always needed, so should not be excluded |
1039 | // Value with 0 angle and dark histogram are always needed, so should not be excluded |
954 | if(i == darkhist) |
1040 | if(i == darkhist) |
955 | exclude = false; |
1041 | exclude = false; |
956 | 1042 | ||
957 | // If nothing excluded, pass the points in pointest variable like in a FIFO |
1043 | // If nothing excluded, pass the points in pointest variable like in a FIFO |
958 | if(!exclude) |
1044 | if(!exclude) |
959 | { |
1045 | { |
960 | for(int j = 0; j < 10; j++) |
1046 | for(int j = 0; j < 10; j++) |
961 | { |
1047 | { |
962 | if(DBGSIG) printf("PhotonMu(): j = %d: Old X value = %lf\n", j, pointest[j]); |
1048 | if(DBGSIG) printf("PhotonMu(): j = %d: Old X value = %lf\n", j, pointest[j]); |
963 | pointest[j] = pointest[j+2]; |
1049 | pointest[j] = pointest[j+2]; |
964 | } |
1050 | } |
965 | } |
1051 | } |
966 | else |
1052 | else |
967 | { |
1053 | { |
968 | for(int j = 0; j < 10; j++) |
1054 | for(int j = 0; j < 10; j++) |
969 | if(DBGSIG) printf("PhotonMu(): No j = %d: Old X value = %lf\n", j, pointest[j]); |
1055 | if(DBGSIG) printf("PhotonMu(): No j = %d: Old X value = %lf\n", j, pointest[j]); |
970 | } |
1056 | } |
971 | } |
1057 | } |
972 | else |
1058 | else |
973 | { |
1059 | { |
974 | // First 5 points act as estimator points for next one |
1060 | // First 5 points act as estimator points for next one |
975 | pointest[2*m] = angle[i]; |
1061 | pointest[2*m] = angle[i]; |
976 | pointest[2*m+1] = muval[i]; |
1062 | pointest[2*m+1] = muval[i]; |
977 | } |
1063 | } |
978 | 1064 | ||
979 | // Run only if we have a dark run histogram and middle pedestal peak estimation |
1065 | // Run only if we have a dark run histogram and middle pedestal peak estimation |
980 | if( (darkhist != -1) && midPeak->widgetChBox[0]->IsDown() ) |
1066 | if( (darkhist != -1) && midPeak->widgetChBox[0]->IsDown() ) |
981 | { |
1067 | { |
982 | if(DBGSIG) printf("PhotonMu(): m = %d, i = %d: muval = %lf, ", m, i, muval[i]); |
1068 | if(DBGSIG) printf("PhotonMu(): m = %d, i = %d: muval = %lf, ", m, i, muval[i]); |
983 | 1069 | ||
984 | // Subtract the dark value from all values |
1070 | // Subtract the dark value from all values |
985 | angle[m] = angle[i]; |
1071 | angle[m] = angle[i]; |
986 | muval[m] = muval[i] - muval[darkhist]; |
1072 | muval[m] = muval[i] - muval[darkhist]; |
987 | 1073 | ||
988 | if(DBGSIG) printf("angle = %lf, newmuval = %lf, darkmuval = %lf, ", angle[m], muval[m], muval[darkhist]); |
1074 | if(DBGSIG) printf("angle = %lf, newmuval = %lf, darkmuval = %lf, ", angle[m], muval[m], muval[darkhist]); |
989 | 1075 | ||
990 | // Calculate relative PDE |
1076 | // Calculate relative PDE |
991 | // pdeval[m] = muval[m]/(muval[zeromu]*TMath::Cos(angle[m]*TMath::ACos(-1.)/180.)); |
1077 | // pdeval[m] = muval[m]/(muval[zeromu]*TMath::Cos(angle[m]*TMath::ACos(-1.)/180.)); |
992 | pdeval[m] = muval[m]/((meansel[1]-muval[darkhist])*TMath::Cos(angle[m]*TMath::ACos(-1.)/180.)); |
1078 | pdeval[m] = muval[m]/((meansel[1]-muval[darkhist])*TMath::Cos(angle[m]*TMath::ACos(-1.)/180.)); |
993 | if(DBGSIG) printf("pdeval = %lf\n", pdeval[m]); |
1079 | if(DBGSIG) printf("pdeval = %lf\n", pdeval[m]); |
994 | 1080 | ||
995 | // Only increase counter if error is not too big |
1081 | // Only increase counter if error is not too big |
996 | if( (darkhist != i) && (!exclude) ) |
1082 | if( (darkhist != i) && (!exclude) ) |
997 | m++; |
1083 | m++; |
998 | } |
1084 | } |
999 | else |
1085 | else |
1000 | { |
1086 | { |
1001 | // Relative PDE calculation |
1087 | // Relative PDE calculation |
1002 | angle[m] = angle[i]; |
1088 | angle[m] = angle[i]; |
1003 | muval[m] = muval[i]; |
1089 | muval[m] = muval[i]; |
1004 | // pdeval[m] = muval[m]/(muval[zeromu]*TMath::Cos(angle[m]*TMath::ACos(-1.)/180.)); |
1090 | // pdeval[m] = muval[m]/(muval[zeromu]*TMath::Cos(angle[m]*TMath::ACos(-1.)/180.)); |
1005 | pdeval[m] = muval[m]/(meansel[1]*TMath::Cos(angle[m]*TMath::ACos(-1.)/180.)); |
1091 | pdeval[m] = muval[m]/(meansel[1]*TMath::Cos(angle[m]*TMath::ACos(-1.)/180.)); |
1006 | 1092 | ||
1007 | // Only increase counter if error is not too big |
1093 | // Only increase counter if error is not too big |
1008 | if(!exclude) |
1094 | if(!exclude) |
1009 | m++; |
1095 | m++; |
1010 | } |
1096 | } |
1011 | printf("PhotonMu(): %lf\t%lf\t%lf\n", angle[i], muval[i], pdeval[i]); |
1097 | printf("PhotonMu(): %lf\t%lf\t%lf\n", angle[i], muval[i], pdeval[i]); |
1012 | } |
1098 | } |
- | 1099 | ||
- | 1100 | // Check for range of values to plot |
|
- | 1101 | double plotMax = 0.; |
|
- | 1102 | for(int i = 0; i < (int)nrfiles; i++) |
|
- | 1103 | { |
|
- | 1104 | plotMax = TMath::Max(plotMax, muval[i]); |
|
- | 1105 | plotMax = TMath::Max(plotMax, pdeval[i]); |
|
- | 1106 | } |
|
- | 1107 | if(plotMax <= 0.) |
|
- | 1108 | plotMax = 1.1; |
|
- | 1109 | printf("PhotonMu(): Maximum value: %lf\n", plotMax); |
|
1013 | 1110 | ||
1014 | if(DBGSIG) printf("\n"); |
1111 | if(DBGSIG) printf("\n"); |
1015 | if(darkhist != -1) |
1112 | if(darkhist != -1) |
1016 | printf("PhotonMu(): Number of excluded points: %d\n", (nrfiles-1-m)); |
1113 | printf("PhotonMu(): Number of excluded points: %d\n", (nrfiles-1-m)); |
1017 | else |
1114 | else |
1018 | printf("PhotonMu(): Number of excluded points: %d\n", (nrfiles-m)); |
1115 | printf("PhotonMu(): Number of excluded points: %d\n", (nrfiles-m)); |
1019 | 1116 | ||
1020 | // Plot mu and PDE angle dependance plots |
1117 | // Plot mu and PDE angle dependance plots |
1021 | if(edit == 0) |
1118 | if(edit == 0) |
1022 | gCanvas = new TCanvas("canv","canv",1200,900); |
1119 | gCanvas = new TCanvas("canv","canv",1200,900); |
1023 | else if(edit == 1) |
1120 | else if(edit == 1) |
1024 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
1121 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
1025 | gCanvas->cd(); |
1122 | gCanvas->cd(); |
1026 | gCanvas->SetGrid(); |
1123 | gCanvas->SetGrid(); |
1027 | 1124 | ||
1028 | TGraph *pde = new TGraph(m, angle, pdeval); |
1125 | TGraph *pde = new TGraph(m, angle, pdeval); |
1029 | pde->SetMarkerStyle(21); |
1126 | pde->SetMarkerStyle(21); |
1030 | pde->SetMarkerSize(0.7); |
1127 | pde->SetMarkerSize(0.7); |
1031 | pde->SetMarkerColor(2); |
1128 | pde->SetMarkerColor(2); |
1032 | pde->SetLineWidth(1); |
1129 | pde->SetLineWidth(1); |
1033 | pde->SetLineColor(2); |
1130 | pde->SetLineColor(2); |
1034 | pde->GetXaxis()->SetLabelSize(0.030); |
1131 | pde->GetXaxis()->SetLabelSize(0.030); |
1035 | pde->GetXaxis()->CenterTitle(); |
1132 | pde->GetXaxis()->CenterTitle(); |
1036 | // pde->GetXaxis()->SetRange(angle[0],angle[nrfiles-1]); |
1133 | // pde->GetXaxis()->SetRange(angle[0],angle[nrfiles-1]); |
1037 | // pde->GetXaxis()->SetRangeUser(angle[0],angle[nrfiles-1]); |
1134 | // pde->GetXaxis()->SetRangeUser(angle[0],angle[nrfiles-1]); |
1038 | pde->GetXaxis()->SetRange(- |
1135 | pde->GetXaxis()->SetRange(-90.0,90.0); |
1039 | pde->GetXaxis()->SetRangeUser(- |
1136 | pde->GetXaxis()->SetRangeUser(-90.0,90.0); |
1040 | pde->GetXaxis()->SetLimits(- |
1137 | pde->GetXaxis()->SetLimits(-90.0,90.0); |
1041 | pde->GetYaxis()->SetTitleOffset(1.2); |
1138 | pde->GetYaxis()->SetTitleOffset(1.2); |
1042 | pde->GetYaxis()->SetLabelSize(0.030); |
1139 | pde->GetYaxis()->SetLabelSize(0.030); |
1043 | pde->GetYaxis()->CenterTitle(); |
1140 | pde->GetYaxis()->CenterTitle(); |
- | 1141 | pde->GetYaxis()->SetRange(0., 1.1*plotMax); |
|
1044 | pde->GetYaxis()->SetRangeUser(0., 1. |
1142 | pde->GetYaxis()->SetRangeUser(0., 1.1*plotMax); |
- | 1143 | pde->GetYaxis()->SetLimits(0., 1.1*plotMax); |
|
1045 | pde->SetName("pde"); |
1144 | pde->SetName("pde"); |
1046 | pde->Draw("ALP"); |
1145 | pde->Draw("ALP"); |
1047 | 1146 | ||
1048 | pde->SetTitle(";Incidence angle (#circ);Relative PDE(#theta) / #mu(#theta)"); |
1147 | pde->SetTitle(";Incidence angle (#circ);Relative PDE(#theta) / #mu(#theta)"); |
1049 | 1148 | ||
1050 | TGraph *mugr = new TGraph(m, angle, muval); |
1149 | TGraph *mugr = new TGraph(m, angle, muval); |
1051 | mugr->SetMarkerStyle(20); |
1150 | mugr->SetMarkerStyle(20); |
1052 | mugr->SetMarkerSize(0.7); |
1151 | mugr->SetMarkerSize(0.7); |
1053 | mugr->SetMarkerColor(4); |
1152 | mugr->SetMarkerColor(4); |
1054 | mugr->SetLineWidth(1); |
1153 | mugr->SetLineWidth(1); |
1055 | mugr->SetLineColor(4); |
1154 | mugr->SetLineColor(4); |
1056 | mugr->SetName("muval"); |
1155 | mugr->SetName("muval"); |
1057 | mugr->Draw("SAME;LP"); |
1156 | mugr->Draw("SAME;LP"); |
1058 | 1157 | ||
1059 | gCanvas->Modified(); |
1158 | gCanvas->Modified(); |
1060 | gCanvas->Update(); |
1159 | gCanvas->Update(); |
1061 | 1160 | ||
1062 | if(edit == 0) |
1161 | if(edit == 0) |
1063 | { |
1162 | { |
1064 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
1163 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
1065 | sprintf(exportname, "%s_pde.pdf", ctemp); |
1164 | sprintf(exportname, "%s_pde.pdf", ctemp); |
1066 | gCanvas->SaveAs(exportname); |
1165 | gCanvas->SaveAs(exportname); |
1067 | 1166 | ||
1068 | delete mugr; |
1167 | delete mugr; |
1069 | delete pde; |
1168 | delete pde; |
1070 | delete gCanvas; |
1169 | delete gCanvas; |
1071 | } |
1170 | } |
1072 | else if(edit == 1) |
1171 | else if(edit == 1) |
1073 | { |
1172 | { |
1074 | gCanvas->Modified(); |
1173 | gCanvas->Modified(); |
1075 | gCanvas->Update(); |
1174 | gCanvas->Update(); |
1076 | } |
1175 | } |
1077 | 1176 | ||
1078 | // Update the progress bar |
1177 | // Update the progress bar |
1079 | analysisProgress->widgetPB->SetPosition(100.); |
1178 | analysisProgress->widgetPB->SetPosition(100.); |
1080 | gVirtualX->Update(1); |
1179 | gVirtualX->Update(1); |
1081 | } |
1180 | } |
1082 | } |
1181 | } |
1083 | 1182 | ||
1084 | void TGAppMainFrame::BreakdownVolt(TList *files, int edit) |
1183 | void TGAppMainFrame::BreakdownVolt(TList *files, int edit) |
1085 | { |
1184 | { |
1086 | unsigned int nrfiles = files->GetSize(); |
1185 | unsigned int nrfiles = files->GetSize(); |
1087 | char ctemp[1024]; |
1186 | char ctemp[1024]; |
1088 | char exportname[1024]; |
1187 | char exportname[1024]; |
1089 | char paramname[1024]; |
1188 | char paramname[1024]; |
1090 | int j, k = 0; |
1189 | int j, k = 0; |
1091 | 1190 | ||
1092 | TCanvas *gCanvas; |
1191 | TCanvas *gCanvas; |
1093 | TTree *header_data, *meas_data; |
1192 | TTree *header_data, *meas_data; |
1094 | 1193 | ||
1095 | // Fitting variables |
1194 | // Fitting variables |
1096 | TSpectrum *spec; |
1195 | TSpectrum *spec; |
1097 | TH1F *histtemp; |
1196 | TH1F *histtemp; |
1098 | TH1 *histback; |
1197 | TH1 *histback; |
1099 | TH1F *h2; |
1198 | TH1F *h2; |
1100 | float *xpeaks; |
1199 | float *xpeaks; |
1101 | TF1 *fit; |
1200 | TF1 *fit; |
1102 | TF1 *fittingfunc; |
1201 | TF1 *fittingfunc; |
1103 | TLatex *latex; |
1202 | TLatex *latex; |
1104 | double *fparam, *fparamerr; |
1203 | double *fparam, *fparamerr; |
1105 | double meansel[20]; |
1204 | double meansel[20]; |
1106 | double meanselerr[20]; |
1205 | double meanselerr[20]; |
1107 | double sigmasel[20]; |
1206 | double sigmasel[20]; |
1108 | double meanparam, meanparamerr, paramsigma; |
1207 | double meanparam, meanparamerr, paramsigma; |
1109 | int sortindex[20]; |
1208 | int sortindex[20]; |
1110 | bool exclude = false; |
1209 | bool exclude = false; |
1111 | 1210 | ||
1112 | int p = 0; |
1211 | int p = 0; |
1113 | double volt[nrfiles], volterr[nrfiles], sep[3][nrfiles], seperr[3][nrfiles]; |
1212 | double volt[nrfiles], volterr[nrfiles], sep[3][nrfiles], seperr[3][nrfiles]; |
1114 | int first = 1; |
1213 | int first = 1; |
1115 | 1214 | ||
1116 | FILE *fp; |
1215 | FILE *fp; |
1117 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
1216 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
1118 | sprintf(paramname, "%s_fitresult.txt", ctemp); |
1217 | sprintf(paramname, "%s_fitresult.txt", ctemp); |
1119 | fp = fopen(paramname, "w"); |
1218 | fp = fopen(paramname, "w"); |
1120 | fclose(fp); |
1219 | fclose(fp); |
1121 | 1220 | ||
1122 | int peaklimit = minPeak->widgetNE[0]->GetNumber()+1; // +1 to account for the pedestal peak |
1221 | int peaklimit = minPeak->widgetNE[0]->GetNumber()+1; // +1 to account for the pedestal peak |
1123 | 1222 | ||
1124 | // Zero the parameter values |
1223 | // Zero the parameter values |
1125 | for(int i = 0; i < nrfiles; i++) |
1224 | for(int i = 0; i < nrfiles; i++) |
1126 | { |
1225 | { |
1127 | volt[i] = 0; volterr[i] = 0; |
1226 | volt[i] = 0; volterr[i] = 0; |
1128 | sep[0][i] = 0; sep[1][i] = 0; sep[2][i] = 0; |
1227 | sep[0][i] = 0; sep[1][i] = 0; sep[2][i] = 0; |
1129 | seperr[0][i] = 0; seperr[1][i] = 0; seperr[2][i] = 0; |
1228 | seperr[0][i] = 0; seperr[1][i] = 0; seperr[2][i] = 0; |
1130 | if(i < 20) { meansel[i] = 0; meanselerr[i] = 0; sigmasel[i] = 0; } |
1229 | if(i < 20) { meansel[i] = 0; meanselerr[i] = 0; sigmasel[i] = 0; } |
1131 | } |
1230 | } |
1132 | 1231 | ||
1133 | float progVal = 0; |
1232 | float progVal = 0; |
1134 | analysisProgress->widgetPB->SetPosition(progVal); |
1233 | analysisProgress->widgetPB->SetPosition(progVal); |
1135 | gVirtualX->Update(1); |
1234 | gVirtualX->Update(1); |
1136 | 1235 | ||
1137 | // Start if we select at least one file |
1236 | // Start if we select at least one file |
1138 | if(nrfiles > 0) |
1237 | if(nrfiles > 0) |
1139 | { |
1238 | { |
1140 | for(int i = 0; i < (int)nrfiles; i++) |
1239 | for(int i = 0; i < (int)nrfiles; i++) |
1141 | { |
1240 | { |
- | 1241 | if( (nrfiles == 1) || (!multiSelect->widgetChBox[0]->IsDown()) ) |
|
- | 1242 | { |
|
- | 1243 | printf("BreakdownVolt(): Only one file selected. Not running analysis, just showing the fit.\n"); |
|
- | 1244 | ||
- | 1245 | // Replot the spectrum on analysisCanvas and do not close the input file |
|
- | 1246 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, 1); |
|
- | 1247 | analysisCanvas->GetCanvas()->Modified(); |
|
- | 1248 | analysisCanvas->GetCanvas()->Update(); |
|
- | 1249 | ||
- | 1250 | // Get the spectrum |
|
- | 1251 | histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname); |
|
- | 1252 | npeaks = 15; |
|
- | 1253 | double par[300]; |
|
- | 1254 | spec = new TSpectrum(npeaks); |
|
- | 1255 | // Find spectrum background |
|
- | 1256 | histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same"); |
|
- | 1257 | // Clone histogram and subtract background from it if we select that option |
|
- | 1258 | h2 = (TH1F*)histtemp->Clone("h2"); |
|
- | 1259 | if(fitChecks->widgetChBox[0]->IsDown()) |
|
- | 1260 | h2->Add(histback, -1); |
|
- | 1261 | // Search for the peaks |
|
- | 1262 | int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() ); |
|
- | 1263 | printf("PhotonMu(): Found %d candidates to fit.\n",found); |
|
- | 1264 | npeaks = found; |
|
- | 1265 | ||
- | 1266 | // Set initial peak parameters |
|
- | 1267 | xpeaks = spec->GetPositionX(); |
|
- | 1268 | for(j = 0; j < found; j++) |
|
- | 1269 | { |
|
- | 1270 | float xp = xpeaks[j]; |
|
- | 1271 | int bin = h2->GetXaxis()->FindBin(xp); |
|
- | 1272 | float yp = h2->GetBinContent(bin); |
|
- | 1273 | par[3*j] = yp; |
|
- | 1274 | par[3*j+1] = xp; |
|
- | 1275 | par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber(); |
|
- | 1276 | } |
|
- | 1277 | ||
- | 1278 | // Fit the histogram |
|
- | 1279 | fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks); |
|
- | 1280 | TVirtualFitter::Fitter(histtemp, 3*npeaks); |
|
- | 1281 | fit->SetParameters(par); |
|
- | 1282 | fit->SetNpx(300); |
|
- | 1283 | h2->Fit("fit","Q"); |
|
- | 1284 | // Get the fitted parameters |
|
- | 1285 | fittingfunc = h2->GetFunction("fit"); |
|
- | 1286 | fparam = fittingfunc->GetParameters(); |
|
- | 1287 | fparamerr = fittingfunc->GetParErrors(); |
|
- | 1288 | ||
- | 1289 | // Gather the parameters (mean peak value for now) |
|
- | 1290 | int j = 1; |
|
- | 1291 | int nrfit = 0; |
|
- | 1292 | while(1) |
|
- | 1293 | { |
|
- | 1294 | if( (fparam[j] < 1.E-30) || (nrfit > 8) ) |
|
- | 1295 | break; |
|
- | 1296 | else |
|
- | 1297 | { |
|
- | 1298 | // Check if pedestal is above the lower limit and sigma is smaller than the mean |
|
- | 1299 | if( (fparam[j] > pedesLow->widgetNE[0]->GetNumber()) && ((double)fparamerr[j]/fparam[j] < accError->widgetNE[0]->GetNumber()) ) |
|
- | 1300 | { |
|
- | 1301 | // With the additional ADC offset, we can shift the mean values slightly, so they are not close to the X.5, but to the X.0 values |
|
- | 1302 | meansel[nrfit] = fparam[j]+(adcOffset->widgetNE[0]->GetNumber()); |
|
- | 1303 | sigmasel[nrfit] = fparam[j+1]; |
|
- | 1304 | nrfit++; |
|
- | 1305 | } |
|
- | 1306 | } |
|
- | 1307 | ||
- | 1308 | j+=3; |
|
- | 1309 | } |
|
- | 1310 | TMath::Sort(nrfit, meansel, sortindex, kFALSE); |
|
- | 1311 | ||
- | 1312 | fittingfunc->Draw("SAME"); |
|
- | 1313 | analysisCanvas->GetCanvas()->Modified(); |
|
- | 1314 | analysisCanvas->GetCanvas()->Update(); |
|
- | 1315 | ||
- | 1316 | meanparam = meansel[sortindex[0]]; |
|
- | 1317 | meanparamerr = meanselerr[sortindex[0]]; |
|
- | 1318 | paramsigma = sigmasel[sortindex[0]]; |
|
- | 1319 | ||
- | 1320 | for(j = 0; j < nrfit; j++) |
|
- | 1321 | printf("BreakdownVolt(): %d: peak mean = %lf, peak err = %lf\n", j, meansel[sortindex[j]], meanselerr[sortindex[j]]); |
|
- | 1322 | ||
- | 1323 | return; |
|
- | 1324 | } |
|
1142 | if(files->At(i)) |
1325 | if(files->At(i)) |
1143 | { |
1326 | { |
1144 | // Replot the spectrum on analysisCanvas and do not close the input file |
1327 | // Replot the spectrum on analysisCanvas and do not close the input file |
1145 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, 1); |
1328 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, 1); |
1146 | analysisCanvas->GetCanvas()->Modified(); |
1329 | analysisCanvas->GetCanvas()->Modified(); |
1147 | analysisCanvas->GetCanvas()->Update(); |
1330 | analysisCanvas->GetCanvas()->Update(); |
1148 | 1331 | ||
1149 | // Get the spectrum |
1332 | // Get the spectrum |
1150 | histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname); |
1333 | histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname); |
1151 | npeaks = 15; |
1334 | npeaks = 15; |
1152 | double par[300]; |
1335 | double par[300]; |
1153 | spec = new TSpectrum(npeaks); |
1336 | spec = new TSpectrum(npeaks); |
1154 | // Find spectrum background |
1337 | // Find spectrum background |
1155 | histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same"); |
1338 | histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same"); |
1156 | // Clone histogram and subtract background from it if we select that option |
1339 | // Clone histogram and subtract background from it if we select that option |
1157 | h2 = (TH1F*)histtemp->Clone("h2"); |
1340 | h2 = (TH1F*)histtemp->Clone("h2"); |
1158 | if(fitChecks->widgetChBox[0]->IsDown()) |
1341 | if(fitChecks->widgetChBox[0]->IsDown()) |
1159 | h2->Add(histback, -1); |
1342 | h2->Add(histback, -1); |
1160 | // Search for the peaks |
1343 | // Search for the peaks |
1161 | int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() ); |
1344 | int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() ); |
1162 | printf("BreakdownVolt(): Found %d candidates to fit.\n",found); |
1345 | printf("BreakdownVolt(): Found %d candidates to fit.\n",found); |
1163 | npeaks = found; |
1346 | npeaks = found; |
1164 | 1347 | ||
1165 | // Set initial peak parameters |
1348 | // Set initial peak parameters |
1166 | xpeaks = spec->GetPositionX(); |
1349 | xpeaks = spec->GetPositionX(); |
1167 | for(j = 0; j < found; j++) |
1350 | for(j = 0; j < found; j++) |
1168 | { |
1351 | { |
1169 | float xp = xpeaks[j]; |
1352 | float xp = xpeaks[j]; |
1170 | int bin = h2->GetXaxis()->FindBin(xp); |
1353 | int bin = h2->GetXaxis()->FindBin(xp); |
1171 | float yp = h2->GetBinContent(bin); |
1354 | float yp = h2->GetBinContent(bin); |
1172 | par[3*j] = yp; |
1355 | par[3*j] = yp; |
1173 | par[3*j+1] = xp; |
1356 | par[3*j+1] = xp; |
1174 | par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber(); |
1357 | par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber(); |
1175 | } |
1358 | } |
1176 | 1359 | ||
1177 | // Fit the histogram |
1360 | // Fit the histogram |
1178 | fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks); |
1361 | fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks); |
1179 | TVirtualFitter::Fitter(histtemp, 3*npeaks); |
1362 | TVirtualFitter::Fitter(histtemp, 3*npeaks); |
1180 | fit->SetParameters(par); |
1363 | fit->SetParameters(par); |
1181 | fit->SetNpx(300); |
1364 | fit->SetNpx(300); |
1182 | h2->Fit("fit","Q"); |
1365 | h2->Fit("fit","Q"); |
1183 | // Get the fitted parameters |
1366 | // Get the fitted parameters |
1184 | fittingfunc = h2->GetFunction("fit"); |
1367 | fittingfunc = h2->GetFunction("fit"); |
1185 | if(nrfiles == 1) // TODO: Show the fit if only one file is selected |
1368 | if(nrfiles == 1) // TODO: Show the fit if only one file is selected |
1186 | fittingfunc->Draw("SAME"); |
1369 | fittingfunc->Draw("SAME"); |
1187 | fparam = fittingfunc->GetParameters(); |
1370 | fparam = fittingfunc->GetParameters(); |
1188 | fparamerr = fittingfunc->GetParErrors(); |
1371 | fparamerr = fittingfunc->GetParErrors(); |
1189 | 1372 | ||
1190 | // Gather the parameters (mean peak value for now) |
1373 | // Gather the parameters (mean peak value for now) |
1191 | int j = 1; |
1374 | int j = 1; |
1192 | int nrfit = 0; |
1375 | int nrfit = 0; |
1193 | while(1) |
1376 | while(1) |
1194 | { |
1377 | { |
1195 | if( (fparam[j] < 1.E-30) || (fparamerr[j] < 1.E-10) )// TODO: Maybe not correct for the error |
1378 | if( (fparam[j] < 1.E-30) || (fparamerr[j] < 1.E-10) )// TODO: Maybe not correct for the error |
1196 | break; |
1379 | break; |
1197 | else |
1380 | else |
1198 | { |
1381 | { |
1199 | // Check if pedestal is above the lower limit and sigma is smaller than the mean |
1382 | // Check if pedestal is above the lower limit and sigma is smaller than the mean |
1200 | if( (fparam[j] > pedesLow->widgetNE[0]->GetNumber()) && ((double)fparamerr[j]/fparam[j] < accError->widgetNE[0]->GetNumber()) ) |
1383 | if( (fparam[j] > pedesLow->widgetNE[0]->GetNumber()) && ((double)fparamerr[j]/fparam[j] < accError->widgetNE[0]->GetNumber()) ) |
1201 | { |
1384 | { |
1202 | meansel[nrfit] = fparam[j]; |
1385 | meansel[nrfit] = fparam[j]; |
1203 | meanselerr[nrfit] = fparamerr[j]; |
1386 | meanselerr[nrfit] = fparamerr[j]; |
1204 | sigmasel[nrfit] = fparam[j+1]; |
1387 | sigmasel[nrfit] = fparam[j+1]; |
1205 | nrfit++; |
1388 | nrfit++; |
1206 | } |
1389 | } |
1207 | } |
1390 | } |
1208 | 1391 | ||
1209 | j+=3; |
1392 | j+=3; |
1210 | } |
1393 | } |
1211 | TMath::Sort(nrfit, meansel, sortindex, kFALSE); |
1394 | TMath::Sort(nrfit, meansel, sortindex, kFALSE); |
1212 | 1395 | ||
1213 | meanparam = meansel[sortindex[0]]; |
1396 | meanparam = meansel[sortindex[0]]; |
1214 | meanparamerr = meanselerr[sortindex[0]]; |
1397 | meanparamerr = meanselerr[sortindex[0]]; |
1215 | paramsigma = sigmasel[sortindex[0]]; |
1398 | paramsigma = sigmasel[sortindex[0]]; |
1216 | 1399 | ||
1217 | for(j = 0; j < nrfit; j++) |
1400 | for(j = 0; j < nrfit; j++) |
1218 | { |
1401 | { |
1219 | if(DBGSIG) |
1402 | if(DBGSIG) |
1220 | printf("BreakdownVolt(): %d: peak mean = %lf, peak err = %lf\n", j, meansel[sortindex[j]], meanselerr[sortindex[j]]); |
1403 | printf("BreakdownVolt(): %d: peak mean = %lf, peak err = %lf\n", j, meansel[sortindex[j]], meanselerr[sortindex[j]]); |
1221 | } |
1404 | } |
1222 | 1405 | ||
1223 | // Delete the opened histogram and spectrum |
1406 | // Delete the opened histogram and spectrum |
1224 | delete spec; |
1407 | delete spec; |
1225 | delete inroot; |
1408 | delete inroot; |
1226 | 1409 | ||
1227 | // Open the input file and read header, ADC and TDC values |
1410 | // Open the input file and read header, ADC and TDC values |
1228 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
1411 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
1229 | inroot = new TFile(ctemp, "READ"); |
1412 | inroot = new TFile(ctemp, "READ"); |
1230 | 1413 | ||
1231 | inroot->GetObject("header_data", header_data); |
1414 | inroot->GetObject("header_data", header_data); |
1232 | inroot->GetObject("meas_data", meas_data); |
1415 | inroot->GetObject("meas_data", meas_data); |
1233 | 1416 | ||
1234 | // Reading the header |
1417 | // Reading the header |
1235 | if( header_data->FindBranch("biasvolt") ) |
1418 | if( header_data->FindBranch("biasvolt") ) |
1236 | { |
1419 | { |
1237 | header_data->SetBranchAddress("biasvolt", &evtheader.biasvolt); |
1420 | header_data->SetBranchAddress("biasvolt", &evtheader.biasvolt); |
1238 | header_data->GetEntry(0); |
1421 | header_data->GetEntry(0); |
1239 | } |
1422 | } |
1240 | else |
1423 | else |
1241 | { |
1424 | { |
1242 | printf("BreakdownVolt(): Error! Selected file has no bias voltage header value. Please edit header to add the bias voltage header value.\n"); |
1425 | printf("BreakdownVolt(): Error! Selected file has no bias voltage header value. Please edit header to add the bias voltage header value.\n"); |
1243 | break; |
1426 | break; |
1244 | } |
1427 | } |
1245 | 1428 | ||
1246 | // h2->SetStats(0); |
1429 | // h2->SetStats(0); |
1247 | 1430 | ||
1248 | analysisCanvas->GetCanvas()->Modified(); |
1431 | analysisCanvas->GetCanvas()->Modified(); |
1249 | analysisCanvas->GetCanvas()->Update(); |
1432 | analysisCanvas->GetCanvas()->Update(); |
1250 | 1433 | ||
1251 | // Save each fitting plot |
1434 | // Save each fitting plot |
1252 | if(fitChecks->widgetChBox[1]->IsDown()) // TODO: Check if this works |
1435 | if(fitChecks->widgetChBox[1]->IsDown()) // TODO: Check if this works |
1253 | { |
1436 | { |
1254 | remove_ext((char*)files->At(i)->GetTitle(), ctemp); |
1437 | remove_ext((char*)files->At(i)->GetTitle(), ctemp); |
1255 | sprintf(exportname, "%s_fit.pdf", ctemp); |
1438 | sprintf(exportname, "%s_fit.pdf", ctemp); |
1256 | analysisCanvas->GetCanvas()->SaveAs(exportname); |
1439 | analysisCanvas->GetCanvas()->SaveAs(exportname); |
1257 | } |
1440 | } |
1258 | 1441 | ||
1259 | // Calculate the separation between peaks |
1442 | // Calculate the separation between peaks |
1260 | volt[p] = evtheader.biasvolt; |
1443 | volt[p] = evtheader.biasvolt; |
1261 | volterr[p] = 1.e-5; |
1444 | volterr[p] = 1.e-5; |
1262 | 1445 | ||
1263 | if(nrfit == 3) |
1446 | if(nrfit == 3) |
1264 | { |
1447 | { |
1265 | sep[0][p] = meansel[sortindex[2]] - meansel[sortindex[1]]; |
1448 | sep[0][p] = meansel[sortindex[2]] - meansel[sortindex[1]]; |
1266 | seperr[0][p] = TMath::Abs(meanselerr[sortindex[2]]) + TMath::Abs(meanselerr[sortindex[1]]); |
1449 | seperr[0][p] = TMath::Abs(meanselerr[sortindex[2]]) + TMath::Abs(meanselerr[sortindex[1]]); |
1267 | 1450 | ||
1268 | exclude = (seperr[0][p]/sep[0][p] < accError->widgetNE[0]->GetNumber()); |
1451 | exclude = (seperr[0][p]/sep[0][p] < accError->widgetNE[0]->GetNumber()); |
1269 | } |
1452 | } |
1270 | else if(nrfit == 4) |
1453 | else if(nrfit == 4) |
1271 | { |
1454 | { |
1272 | sep[0][p] = meansel[sortindex[2]] - meansel[sortindex[1]]; |
1455 | sep[0][p] = meansel[sortindex[2]] - meansel[sortindex[1]]; |
1273 | sep[1][p] = meansel[sortindex[3]] - meansel[sortindex[2]]; |
1456 | sep[1][p] = meansel[sortindex[3]] - meansel[sortindex[2]]; |
1274 | seperr[0][p] = TMath::Abs(meanselerr[sortindex[2]]) + TMath::Abs(meanselerr[sortindex[1]]); |
1457 | seperr[0][p] = TMath::Abs(meanselerr[sortindex[2]]) + TMath::Abs(meanselerr[sortindex[1]]); |
1275 | seperr[1][p] = TMath::Abs(meanselerr[sortindex[3]]) + TMath::Abs(meanselerr[sortindex[2]]); |
1458 | seperr[1][p] = TMath::Abs(meanselerr[sortindex[3]]) + TMath::Abs(meanselerr[sortindex[2]]); |
1276 | 1459 | ||
1277 | exclude = ((seperr[0][p]/sep[0][p] < accError->widgetNE[0]->GetNumber()) && (seperr[1][p]/sep[1][p] < accError->widgetNE[0]->GetNumber())); |
1460 | exclude = ((seperr[0][p]/sep[0][p] < accError->widgetNE[0]->GetNumber()) && (seperr[1][p]/sep[1][p] < accError->widgetNE[0]->GetNumber())); |
1278 | } |
1461 | } |
1279 | else if(nrfit > 4) |
1462 | else if(nrfit > 4) |
1280 | { |
1463 | { |
1281 | sep[0][p] = meansel[sortindex[2]] - meansel[sortindex[1]]; |
1464 | sep[0][p] = meansel[sortindex[2]] - meansel[sortindex[1]]; |
1282 | sep[1][p] = meansel[sortindex[3]] - meansel[sortindex[2]]; |
1465 | sep[1][p] = meansel[sortindex[3]] - meansel[sortindex[2]]; |
1283 | sep[2][p] = meansel[sortindex[4]] - meansel[sortindex[3]]; |
1466 | sep[2][p] = meansel[sortindex[4]] - meansel[sortindex[3]]; |
1284 | seperr[0][p] = TMath::Abs(meanselerr[sortindex[2]]) + TMath::Abs(meanselerr[sortindex[1]]); |
1467 | seperr[0][p] = TMath::Abs(meanselerr[sortindex[2]]) + TMath::Abs(meanselerr[sortindex[1]]); |
1285 | seperr[1][p] = TMath::Abs(meanselerr[sortindex[3]]) + TMath::Abs(meanselerr[sortindex[2]]); |
1468 | seperr[1][p] = TMath::Abs(meanselerr[sortindex[3]]) + TMath::Abs(meanselerr[sortindex[2]]); |
1286 | seperr[2][p] = TMath::Abs(meanselerr[sortindex[4]]) + TMath::Abs(meanselerr[sortindex[3]]); |
1469 | seperr[2][p] = TMath::Abs(meanselerr[sortindex[4]]) + TMath::Abs(meanselerr[sortindex[3]]); |
1287 | 1470 | ||
1288 | exclude = ((seperr[0][p]/sep[0][p] < accError->widgetNE[0]->GetNumber()) && (seperr[1][p]/sep[1][p] < accError->widgetNE[0]->GetNumber()) && (seperr[2][p]/sep[2][p] < accError->widgetNE[0]->GetNumber())); |
1471 | exclude = ((seperr[0][p]/sep[0][p] < accError->widgetNE[0]->GetNumber()) && (seperr[1][p]/sep[1][p] < accError->widgetNE[0]->GetNumber()) && (seperr[2][p]/sep[2][p] < accError->widgetNE[0]->GetNumber())); |
1289 | } |
1472 | } |
1290 | else |
1473 | else |
1291 | { |
1474 | { |
1292 | printf("BreakdownVolt(): The current separation measurements does not fall within acceptable errors.\n"); |
1475 | printf("BreakdownVolt(): The current separation measurements does not fall within acceptable errors.\n"); |
1293 | exclude = false; |
1476 | exclude = false; |
1294 | } |
1477 | } |
1295 | 1478 | ||
1296 | // Write out parameters to a file |
1479 | // Write out parameters to a file |
1297 | fp = fopen(paramname, "a"); |
1480 | fp = fopen(paramname, "a"); |
1298 | if(exclude) |
1481 | if(exclude) |
1299 | { |
1482 | { |
1300 | if(first == 1) |
1483 | if(first == 1) |
1301 | { |
1484 | { |
1302 | fprintf(fp, "%le\t%d\t", evtheader.biasvolt, nrfit); |
1485 | fprintf(fp, "%le\t%d\t", evtheader.biasvolt, nrfit); |
1303 | for(j = 0; j < nrfit; j++) |
1486 | for(j = 0; j < nrfit; j++) |
1304 | fprintf(fp, "%le\t%le\t", meansel[sortindex[j]], meanselerr[sortindex[j]]); |
1487 | fprintf(fp, "%le\t%le\t", meansel[sortindex[j]], meanselerr[sortindex[j]]); |
1305 | fprintf(fp,"\n"); |
1488 | fprintf(fp,"\n"); |
1306 | first = 0; |
1489 | first = 0; |
1307 | } |
1490 | } |
1308 | p++; |
1491 | p++; |
1309 | } |
1492 | } |
1310 | else |
1493 | else |
1311 | { |
1494 | { |
1312 | if(nrfit == 3) |
1495 | if(nrfit == 3) |
1313 | printf("Point (at %.2lfV) rejected due to too large errors: %lf\n", volt[p], seperr[0][p]/sep[0][p]); |
1496 | printf("Point (at %.2lfV) rejected due to too large errors: %lf\n", volt[p], seperr[0][p]/sep[0][p]); |
1314 | else if(nrfit == 4) |
1497 | else if(nrfit == 4) |
1315 | printf("Point (at %.2lfV) rejected due to too large errors: %lf, %lf\n", volt[p], seperr[0][p]/sep[0][p], seperr[1][p]/sep[1][p]); |
1498 | printf("Point (at %.2lfV) rejected due to too large errors: %lf, %lf\n", volt[p], seperr[0][p]/sep[0][p], seperr[1][p]/sep[1][p]); |
1316 | else if(nrfit > 4) |
1499 | else if(nrfit > 4) |
1317 | printf("Point (at %.2lfV) rejected due to too large errors: %lf, %lf, %lf\n", volt[p], seperr[0][p]/sep[0][p], seperr[1][p]/sep[1][p], seperr[2][p]/sep[2][p]); |
1500 | printf("Point (at %.2lfV) rejected due to too large errors: %lf, %lf, %lf\n", volt[p], seperr[0][p]/sep[0][p], seperr[1][p]/sep[1][p], seperr[2][p]/sep[2][p]); |
1318 | } |
1501 | } |
1319 | fclose(fp); |
1502 | fclose(fp); |
1320 | } |
1503 | } |
1321 | 1504 | ||
1322 | if(nrfiles == 1) break; |
1505 | if(nrfiles == 1) break; |
1323 | first = 1; |
1506 | first = 1; |
1324 | 1507 | ||
1325 | // Update the progress bar |
1508 | // Update the progress bar |
1326 | progVal = (float)(90.00/nrfiles)*i; |
1509 | progVal = (float)(90.00/nrfiles)*i; |
1327 | analysisProgress->widgetPB->SetPosition(progVal); |
1510 | analysisProgress->widgetPB->SetPosition(progVal); |
1328 | gVirtualX->Update(1); |
1511 | gVirtualX->Update(1); |
1329 | } |
1512 | } |
1330 | 1513 | ||
1331 | printf("BreakdownVolt(): %d files were selected.\n", nrfiles); |
1514 | printf("BreakdownVolt(): %d files were selected.\n", nrfiles); |
1332 | printf("BreakdownVolt(): Number of points to plot is %d\n", p); |
1515 | printf("BreakdownVolt(): Number of points to plot is %d\n", p); |
1333 | 1516 | ||
1334 | // Plot and fit breakdown voltage plot |
1517 | // Plot and fit breakdown voltage plot |
1335 | if(edit == 0) |
1518 | if(edit == 0) |
1336 | gCanvas = new TCanvas("canv","canv",1200,900); |
1519 | gCanvas = new TCanvas("canv","canv",1200,900); |
1337 | else if(edit == 1) |
1520 | else if(edit == 1) |
1338 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
1521 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
1339 | gCanvas->cd(); |
1522 | gCanvas->cd(); |
1340 | gCanvas->SetGrid(); |
1523 | gCanvas->SetGrid(); |
1341 | 1524 | ||
1342 | TGraphErrors* bdplot; |
1525 | TGraphErrors* bdplot; |
1343 | k = peakSepCalc->widgetNE[0]->GetNumber(); |
1526 | k = peakSepCalc->widgetNE[0]->GetNumber(); |
1344 | if(k < 4) |
1527 | if(k < 4) |
1345 | bdplot = new TGraphErrors(p, volt, sep[k-1], volterr, seperr[k-1]); |
1528 | bdplot = new TGraphErrors(p, volt, sep[k-1], volterr, seperr[k-1]); |
1346 | else |
1529 | else |
1347 | { |
1530 | { |
1348 | printf("BreakdownVold(): Unsupported peak separation selected (%d).\n", k); |
1531 | printf("BreakdownVold(): Unsupported peak separation selected (%d).\n", k); |
1349 | return; |
1532 | return; |
1350 | } |
1533 | } |
1351 | 1534 | ||
1352 | bdplot->SetMarkerStyle(20); |
1535 | bdplot->SetMarkerStyle(20); |
1353 | bdplot->SetMarkerSize(0.4); |
1536 | bdplot->SetMarkerSize(0.4); |
1354 | bdplot->SetMarkerColor(kBlue); |
1537 | bdplot->SetMarkerColor(kBlue); |
1355 | bdplot->SetLineWidth(1); |
1538 | bdplot->SetLineWidth(1); |
1356 | bdplot->SetLineColor(kBlue); |
1539 | bdplot->SetLineColor(kBlue); |
1357 | bdplot->GetXaxis()->SetLabelSize(0.030); |
1540 | bdplot->GetXaxis()->SetLabelSize(0.030); |
1358 | bdplot->GetXaxis()->CenterTitle(); |
1541 | bdplot->GetXaxis()->CenterTitle(); |
1359 | // bdplot->GetXaxis()->SetRange(-90,90); |
1542 | // bdplot->GetXaxis()->SetRange(-90,90); |
1360 | // bdplot->GetXaxis()->SetRangeUser(-90,90); |
1543 | // bdplot->GetXaxis()->SetRangeUser(-90,90); |
1361 | // bdplot->GetXaxis()->SetLimits(-90,90); |
1544 | // bdplot->GetXaxis()->SetLimits(-90,90); |
1362 | bdplot->GetYaxis()->SetTitleOffset(1.2); |
1545 | bdplot->GetYaxis()->SetTitleOffset(1.2); |
1363 | bdplot->GetYaxis()->SetLabelSize(0.030); |
1546 | bdplot->GetYaxis()->SetLabelSize(0.030); |
1364 | bdplot->GetYaxis()->CenterTitle(); |
1547 | bdplot->GetYaxis()->CenterTitle(); |
1365 | // bdplot->GetYaxis()->SetRangeUser(0., 1.2); |
1548 | // bdplot->GetYaxis()->SetRangeUser(0., 1.2); |
1366 | bdplot->SetName("bdplot"); |
1549 | bdplot->SetName("bdplot"); |
1367 | bdplot->Draw("AP"); |
1550 | bdplot->Draw("AP"); |
1368 | bdplot->SetTitle(";Bias voltage (V);Peak separation"); |
1551 | bdplot->SetTitle(";Bias voltage (V);Peak separation"); |
1369 | 1552 | ||
1370 | // Fit the breakdown voltage plot with a line |
1553 | // Fit the breakdown voltage plot with a line |
1371 | bdplot->Fit("pol1","Q"); |
1554 | bdplot->Fit("pol1","Q"); |
1372 | 1555 | ||
1373 | TF1 *fit1 = bdplot->GetFunction("pol1"); |
1556 | TF1 *fit1 = bdplot->GetFunction("pol1"); |
1374 | meansel[0] = fit1->GetParameter(0); |
1557 | meansel[0] = fit1->GetParameter(0); |
1375 | meanselerr[0] = fit1->GetParError(0); |
1558 | meanselerr[0] = fit1->GetParError(0); |
1376 | meansel[1] = fit1->GetParameter(1); |
1559 | meansel[1] = fit1->GetParameter(1); |
1377 | meanselerr[1] = fit1->GetParError(1); |
1560 | meanselerr[1] = fit1->GetParError(1); |
1378 | 1561 | ||
1379 | meansel[2] = -meansel[0]/meansel[1]; |
1562 | meansel[2] = -meansel[0]/meansel[1]; |
1380 | if(!cleanPlots) |
1563 | if(!cleanPlots) |
1381 | { |
1564 | { |
1382 | sprintf(ctemp, "#splitline{#Delta_{p}(U) = (%.2lf #pm %.2lf)#timesU + (%.2lf #pm %.3lf)}{U_{0} = %.2lf #pm %.3lf}", meansel[0], meanselerr[0], meansel[1], meanselerr[1], meansel[2], meansel[2]*(TMath::Abs(meanselerr[0]/meansel[0]) + TMath::Abs(meanselerr[1]/meansel[1])) ); |
1565 | sprintf(ctemp, "#splitline{#Delta_{p}(U) = (%.2lf #pm %.2lf)#timesU + (%.2lf #pm %.3lf)}{U_{0} = %.2lf #pm %.3lf}", meansel[0], meanselerr[0], meansel[1], meanselerr[1], meansel[2], meansel[2]*(TMath::Abs(meanselerr[0]/meansel[0]) + TMath::Abs(meanselerr[1]/meansel[1])) ); |
1383 | latex = new TLatex(); |
1566 | latex = new TLatex(); |
1384 | latex->SetTextSize(0.039); |
1567 | latex->SetTextSize(0.039); |
1385 | latex->DrawLatex(volt[0], 0.97*sep[0][sortindex[p-1]], ctemp); |
1568 | latex->DrawLatex(volt[0], 0.97*sep[0][sortindex[p-1]], ctemp); |
- | 1569 | printf("#Delta_{p}(U) = (%.6lf #pm %.8lf)#timesU + (%.6lf #pm %.8lf)}{U_{0} = %.6lf #pm %.8lf\n", meansel[0], meanselerr[0], meansel[1], meanselerr[1], meansel[2], meansel[2]*(TMath::Abs(meanselerr[0]/meansel[0]) + TMath::Abs(meanselerr[1]/meansel[1])) ); |
|
1386 | } |
1570 | } |
1387 | else |
1571 | else |
1388 | printf("#Delta_{p}(U) = (%.2lf #pm %.2lf)#timesU + (%.2lf #pm %.3lf)}{U_{0} = %.2lf #pm %.3lf", meansel[0], meanselerr[0], meansel[1], meanselerr[1], meansel[2], meansel[2]*(TMath::Abs(meanselerr[0]/meansel[0]) + TMath::Abs(meanselerr[1]/meansel[1])) ); |
1572 | printf("#Delta_{p}(U) = (%.2lf #pm %.2lf)#timesU + (%.2lf #pm %.3lf)}{U_{0} = %.2lf #pm %.3lf\n", meansel[0], meanselerr[0], meansel[1], meanselerr[1], meansel[2], meansel[2]*(TMath::Abs(meanselerr[0]/meansel[0]) + TMath::Abs(meanselerr[1]/meansel[1])) ); |
1389 | 1573 | ||
1390 | if(edit == 0) |
1574 | if(edit == 0) |
1391 | { |
1575 | { |
1392 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
1576 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
1393 | sprintf(exportname, "%s_breakdown.pdf", ctemp); |
1577 | sprintf(exportname, "%s_breakdown.pdf", ctemp); |
1394 | gCanvas->SaveAs(exportname); |
1578 | gCanvas->SaveAs(exportname); |
1395 | 1579 | ||
1396 | delete bdplot; |
1580 | delete bdplot; |
1397 | delete gCanvas; |
1581 | delete gCanvas; |
1398 | } |
1582 | } |
1399 | else if(edit == 1) |
1583 | else if(edit == 1) |
1400 | { |
1584 | { |
1401 | gCanvas->Modified(); |
1585 | gCanvas->Modified(); |
1402 | gCanvas->Update(); |
1586 | gCanvas->Update(); |
1403 | } |
1587 | } |
1404 | 1588 | ||
1405 | // Update the progress bar |
1589 | // Update the progress bar |
1406 | analysisProgress->widgetPB->SetPosition(100.); |
1590 | analysisProgress->widgetPB->SetPosition(100.); |
1407 | gVirtualX->Update(1); |
1591 | gVirtualX->Update(1); |
1408 | } |
1592 | } |
1409 | } |
1593 | } |
1410 | 1594 | ||
1411 | void TGAppMainFrame::SurfaceScan(TList *files, int edit) |
1595 | void TGAppMainFrame::SurfaceScan(TList *files, int edit) |
1412 | { |
1596 | { |
1413 | unsigned int nrfiles = files->GetSize(); |
1597 | unsigned int nrfiles = files->GetSize(); |
1414 | char ctemp[1024]; |
1598 | char ctemp[1024]; |
1415 | char exportname[1024]; |
1599 | char exportname[1024]; |
1416 | int j, k = 0, m = 0, n = 0; |
1600 | int j, k = 0, m = 0, n = 0; |
1417 | 1601 | ||
1418 | TTree *header_data, *meas_data; |
1602 | TTree *header_data, *meas_data; |
1419 | double *integralCount; |
1603 | double *integralCount; |
1420 | integralCount = new double[nrfiles]; |
1604 | integralCount = new double[nrfiles]; |
1421 | double *surfx, *surfy; |
1605 | double *surfx, *surfy; |
1422 | surfx = new double[nrfiles]; |
1606 | surfx = new double[nrfiles]; |
1423 | surfy = new double[nrfiles]; |
1607 | surfy = new double[nrfiles]; |
1424 | double xsurfmin = 0, ysurfmin = 0; |
1608 | double xsurfmin = 0, ysurfmin = 0; |
1425 | int nrentries; |
1609 | int nrentries; |
1426 |
|
1610 | double minInteg, maxInteg; |
1427 | bool norm = surfScanOpt->widgetChBox[0]->IsDown(); |
1611 | bool norm = surfScanOpt->widgetChBox[0]->IsDown(); |
1428 |
|
1612 | double curyval; |
1429 | // bool edge2d = false; |
1613 | // bool edge2d = false; |
1430 | 1614 | ||
1431 | TCanvas *gCanvas; |
1615 | TCanvas *gCanvas; |
1432 | 1616 | ||
1433 | float progVal = 0; |
1617 | float progVal = 0; |
1434 | analysisProgress->widgetPB->SetPosition(progVal); |
1618 | analysisProgress->widgetPB->SetPosition(progVal); |
1435 | gVirtualX->Update(1); |
1619 | gVirtualX->Update(1); |
1436 | 1620 | ||
1437 | // Zero the integral count and accumulated vaules |
1621 | // Zero the integral count and accumulated vaules |
1438 | for(int i = 0; i < (int)nrfiles; i++) integralCount[i] = 0; |
1622 | for(int i = 0; i < (int)nrfiles; i++) integralCount[i] = 0; |
1439 | 1623 | ||
1440 | // Start if we select at more than one file |
1624 | // Start if we select at more than one file |
1441 | if( (nrfiles > 1) && (multiSelect->widgetChBox[0]->IsOn()) ) |
1625 | if( (nrfiles > 1) && (multiSelect->widgetChBox[0]->IsOn()) ) |
1442 | { |
1626 | { |
1443 | printf("SurfaceScan(): Creating a surface plot. Please wait...\n"); |
1627 | printf("SurfaceScan(): Creating a surface plot. Please wait...\n"); |
1444 | for(int i = 0; i < (int)nrfiles; i++) |
1628 | for(int i = 0; i < (int)nrfiles; i++) |
1445 | { |
1629 | { |
1446 | if(files->At(i)) |
1630 | if(files->At(i)) |
1447 | { |
1631 | { |
1448 | n++; |
1632 | n++; |
1449 | // Read the X and Y positions from header and ADC and TDC values from the measurements |
1633 | // Read the X and Y positions from header and ADC and TDC values from the measurements |
1450 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
1634 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
1451 | inroot = new TFile(ctemp, "READ"); |
1635 | inroot = new TFile(ctemp, "READ"); |
1452 | 1636 | ||
1453 | inroot->GetObject("header_data", header_data); |
1637 | inroot->GetObject("header_data", header_data); |
1454 | inroot->GetObject("meas_data", meas_data); |
1638 | inroot->GetObject("meas_data", meas_data); |
1455 | 1639 | ||
1456 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
1640 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
1457 | header_data->GetEntry(0); |
1641 | header_data->GetEntry(0); |
1458 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
1642 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
1459 | header_data->GetEntry(0); |
1643 | header_data->GetEntry(0); |
1460 | 1644 | ||
1461 | char rdc[256]; |
1645 | char rdc[256]; |
1462 | j = selectCh->widgetNE[0]->GetNumber(); |
1646 | j = selectCh->widgetNE[0]->GetNumber(); |
1463 | double rangetdc[2]; |
1647 | double rangetdc[2]; |
1464 | rangetdc[0] = tdcRange->widgetNE[0]->GetNumber(); |
1648 | rangetdc[0] = tdcRange->widgetNE[0]->GetNumber(); |
1465 | rangetdc[1] = tdcRange->widgetNE[1]->GetNumber(); |
1649 | rangetdc[1] = tdcRange->widgetNE[1]->GetNumber(); |
1466 | 1650 | ||
1467 | k = 0; |
1651 | k = 0; |
1468 | m = 0; |
1652 | m = 0; |
1469 | 1653 | ||
1470 | // Reading the data |
1654 | // Reading the data |
1471 | for(int e = 0; e < meas_data->GetEntries(); e++) |
1655 | for(int e = 0; e < meas_data->GetEntries(); e++) |
1472 | { |
1656 | { |
1473 | sprintf(rdc, "ADC%d", j); |
1657 | sprintf(rdc, "ADC%d", j); |
1474 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
1658 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
1475 | meas_data->GetEntry(e); |
1659 | meas_data->GetEntry(e); |
1476 | 1660 | ||
1477 | sprintf(rdc, "TDC%d", j); |
1661 | sprintf(rdc, "TDC%d", j); |
1478 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
1662 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
1479 | meas_data->GetEntry(e); |
1663 | meas_data->GetEntry(e); |
1480 | 1664 | ||
1481 | // Use data point only if it is inside the TDC window |
1665 | // Use data point only if it is inside the TDC window |
1482 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
1666 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
1483 | { |
1667 | { |
1484 | k++; |
1668 | k++; |
1485 | m += evtdata.adcdata[j]; |
1669 | m += evtdata.adcdata[j]; |
1486 | } |
1670 | } |
1487 | } |
1671 | } |
1488 | 1672 | ||
1489 | // X, Y and Z values from each file (table units or microns) |
1673 | // X, Y and Z values from each file (table units or microns) |
1490 | if( |
1674 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
1491 | { |
1675 | { |
1492 | if(n == 1) |
1676 | if(n == 1) |
1493 | { |
1677 | { |
1494 | xsurfmin = (double)(evtheader.xpos); |
1678 | xsurfmin = (double)(evtheader.xpos); |
1495 | ysurfmin = (double)(evtheader.ypos); |
1679 | ysurfmin = (double)(evtheader.ypos); |
1496 | } |
1680 | } |
1497 | 1681 | ||
1498 | surfx[i] = (double)(evtheader.xpos); |
1682 | surfx[i] = (double)(evtheader.xpos); |
1499 | surfy[i] = (double)(evtheader.ypos); |
1683 | surfy[i] = (double)(evtheader.ypos); |
1500 | } |
1684 | } |
1501 | else if( |
1685 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
1502 | { |
1686 | { |
1503 | if(n == 1) |
1687 | if(n == 1) |
1504 | { |
1688 | { |
1505 | xsurfmin = (double)(evtheader.xpos*lenconversion); |
1689 | xsurfmin = (double)(evtheader.xpos*lenconversion); |
1506 | ysurfmin = (double)(evtheader.ypos*lenconversion); |
1690 | ysurfmin = (double)(evtheader.ypos*lenconversion); |
1507 | } |
1691 | } |
1508 | 1692 | ||
1509 | surfx[i] = (double)(evtheader.xpos*lenconversion); |
1693 | surfx[i] = (double)(evtheader.xpos*lenconversion); |
1510 | surfy[i] = (double)(evtheader.ypos*lenconversion); |
1694 | surfy[i] = (double)(evtheader.ypos*lenconversion); |
1511 | } |
1695 | } |
1512 | 1696 | ||
1513 | // Save result for later plotting |
1697 | // Save result for later plotting |
1514 | if(norm) |
1698 | if(norm) |
1515 | integralCount[i] += ((double)m)/((double)k); |
1699 | integralCount[i] += ((double)m)/((double)k); |
1516 | else |
1700 | else |
1517 | integralCount[i] += m; |
1701 | integralCount[i] += m; |
1518 | 1702 | ||
1519 | inroot->Close(); |
1703 | inroot->Close(); |
1520 | delete inroot; |
1704 | delete inroot; |
1521 | } |
1705 | } |
1522 | 1706 | ||
1523 | // Update the progress bar |
1707 | // Update the progress bar |
1524 | progVal = (float)(75.00/nrfiles)*i; |
1708 | progVal = (float)(75.00/nrfiles)*i; |
1525 | analysisProgress->widgetPB->SetPosition(progVal); |
1709 | analysisProgress->widgetPB->SetPosition(progVal); |
1526 | gVirtualX->Update(1); |
1710 | gVirtualX->Update(1); |
1527 | } |
1711 | } |
1528 | 1712 | ||
1529 | nrentries = n; |
1713 | nrentries = n; |
1530 | printf("SurfaceScan(): %d files were selected.\n", nrfiles); |
1714 | printf("SurfaceScan(): %d files were selected.\n", nrfiles); |
1531 | 1715 | ||
1532 | / |
1716 | // Check for Minimum and Maximum values and normalize to 1, if normalization is selected |
1533 |
|
1717 | if(norm) |
1534 |
|
1718 | { |
1535 |
|
1719 | minInteg = TMath::MinElement(nrfiles, integralCount); |
1536 |
|
1720 | for(int i = 0; i < nrfiles; i++) |
- | 1721 | { |
|
1537 |
|
1722 | integralCount[i] -= minInteg; |
1538 |
|
1723 | if(DBGSIG) printf("Subtraction: %lf\n", integralCount[i]); |
1539 |
|
1724 | } |
1540 | // |
1725 | |
1541 |
|
1726 | maxInteg = TMath::MaxElement(nrfiles, integralCount); |
1542 | // curzval = surfz[0]; |
- | |
1543 | // j = 0; |
- | |
1544 | // int acc = 0; |
- | |
1545 | // int zb; |
- | |
1546 |
|
1727 | for(int i = 0; i < nrfiles; i++) |
1547 |
|
1728 | { |
1548 | // // Collect the accumulated integral in order to produce a PDF from a CDF |
- | |
1549 | // // While we are at the same Z value, save under one set |
- | |
1550 | // if( (surfz[i] == curzval) && (acc != nrfiles) ) |
- | |
1551 | // { |
- | |
1552 |
|
1729 | integralCount[i] = integralCount[i]/maxInteg; |
1553 | // if(DBGSIG) printf("IntegSpectrum(): Integral check 1 (i=%d,j=%d,z=%.2lf): %lf\t%lf\n", i, j, surfz[i], integralCount[i], integralAcc[j]); |
- | |
1554 | // j++; |
- | |
1555 | // acc++; |
- | |
1556 | // } |
- | |
1557 | // // When we switch to a new set of Z values and at the end, we must save the previous ones to make 1D edge plots |
- | |
1558 | // else |
- | |
1559 | // { |
- | |
1560 | // // Find minimal and maximal integral values to subtract the offset and normate PDF to 1 |
- | |
1561 |
|
1730 | if(DBGSIG) printf("Normalization: %lf\n", integralCount[i]); |
1562 | // |
- | |
1563 | // if(acc != nrfiles) |
- | |
1564 | // { |
- | |
1565 | // curzval = surfz[i]; |
- | |
1566 | // // PDF and CDF plot |
- | |
1567 | // PlotEdgeDistribution(files, i, j, &minInteg, &maxInteg, surfxy, integralAcc, direction, edge2d, edit); |
- | |
1568 | // i--; |
- | |
1569 | // j = 0; |
- | |
1570 | // } |
- | |
1571 | // else |
- | |
1572 | // { |
- | |
1573 | // // PDF and CDF plot |
- | |
1574 | // PlotEdgeDistribution(files, i, j, &minInteg, &maxInteg, surfxy, integralAcc, direction, edge2d, edit); |
- | |
1575 | // i--; |
- | |
1576 | // break; |
- | |
1577 | // } |
- | |
1578 | // } |
- | |
1579 |
|
1731 | } |
1580 | // // Update the progress bar |
- | |
1581 | // progVal = (float)(15.00/nrfiles)*i+75.00; |
- | |
1582 | // analysisProgress->widgetPB->SetPosition(progVal); |
- | |
1583 | // gVirtualX->Update(1); |
- | |
1584 |
|
1732 | } |
1585 | 1733 | ||
1586 | // Make the 2D surface plot |
1734 | // Make the 2D surface plot |
1587 | if(edit == 0) |
1735 | if(edit == 0) |
1588 | gCanvas = new TCanvas("canv","canv",1100,900); |
1736 | gCanvas = new TCanvas("canv","canv",1100,900); |
1589 | else |
1737 | else |
1590 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
1738 | gCanvas = tempAnalysisCanvas->GetCanvas(); |
1591 | 1739 | ||
1592 | double range[4]; |
1740 | double range[4]; |
1593 | TGraph2D *gScan2D; |
1741 | TGraph2D *gScan2D; |
1594 | gScan2D = new TGraph2D(); |
1742 | gScan2D = new TGraph2D(); |
1595 | range[0] = TMath::MinElement(nrfiles, surfx); |
1743 | range[0] = TMath::MinElement(nrfiles, surfx); |
1596 | range[1] = TMath::MaxElement(nrfiles, surfx); |
1744 | range[1] = TMath::MaxElement(nrfiles, surfx); |
1597 | range[2] = TMath::MinElement(nrfiles, surfy); |
1745 | range[2] = TMath::MinElement(nrfiles, surfy); |
1598 | range[3] = TMath::MaxElement(nrfiles, surfy); |
1746 | range[3] = TMath::MaxElement(nrfiles, surfy); |
1599 | 1747 | ||
1600 | for(int i = 0; i < nrfiles; i++) |
1748 | for(int i = 0; i < nrfiles; i++) |
1601 | { |
1749 | { |
1602 | if(DBGSIG) |
1750 | if(DBGSIG) |
1603 | { |
1751 | { |
1604 | if(surfScanOpt->widgetChBox[1]->IsDown()) |
1752 | if(surfScanOpt->widgetChBox[1]->IsDown()) |
1605 | printf("SurfaceScan(): %.2lf\t%.2lf\t%lf\n", surfx[i]-range[0], surfy[i]-range[2], integralCount[i]); |
1753 | printf("SurfaceScan(): %.2lf\t%.2lf\t%lf\n", surfx[i]-range[0], surfy[i]-range[2], integralCount[i]); |
1606 | else |
1754 | else |
1607 | printf("SurfaceScan(): %.2lf\t%.2lf\t%lf\n", surfx[i], surfy[i], integralCount[i]); |
1755 | printf("SurfaceScan(): %.2lf\t%.2lf\t%lf\n", surfx[i], surfy[i], integralCount[i]); |
1608 | } |
1756 | } |
1609 | 1757 | ||
1610 | if(surfScanOpt->widgetChBox[1]->IsDown()) |
1758 | if(surfScanOpt->widgetChBox[1]->IsDown()) |
1611 | gScan2D->SetPoint(i, surfx[i]-range[0], surfy[i]-range[2], integralCount[i]); |
1759 | gScan2D->SetPoint(i, surfx[i]-range[0], surfy[i]-range[2], integralCount[i]); |
1612 | else |
1760 | else |
1613 | gScan2D->SetPoint(i, surfx[i], surfy[i], integralCount[i]); |
1761 | gScan2D->SetPoint(i, surfx[i], surfy[i], integralCount[i]); |
1614 | 1762 | ||
1615 | // Update the progress bar |
1763 | // Update the progress bar |
1616 | progVal = (float)(9.00/nrfiles)*i+90.00; |
1764 | progVal = (float)(9.00/nrfiles)*i+90.00; |
1617 | analysisProgress->widgetPB->SetPosition(progVal); |
1765 | analysisProgress->widgetPB->SetPosition(progVal); |
1618 | gVirtualX->Update(1); |
1766 | gVirtualX->Update(1); |
1619 | } |
1767 | } |
1620 | 1768 | ||
1621 | if(surfScanOpt->widgetChBox[1]->IsDown()) |
1769 | if(surfScanOpt->widgetChBox[1]->IsDown()) |
1622 | { |
1770 | { |
1623 | range[1] -= range[0]; |
1771 | range[1] -= range[0]; |
1624 | range[3] -= range[2]; |
1772 | range[3] -= range[2]; |
1625 | range[0] -= range[0]; |
1773 | range[0] -= range[0]; |
1626 | range[2] -= range[2]; |
1774 | range[2] -= range[2]; |
1627 | } |
1775 | } |
1628 | 1776 | ||
1629 | gCanvas->cd(); |
1777 | gCanvas->cd(); |
1630 | gStyle->SetPalette(1); |
1778 | gStyle->SetPalette(1); |
1631 | gCanvas->SetLeftMargin(0.15); |
1779 | gCanvas->SetLeftMargin(0.15); |
1632 | gCanvas->SetRightMargin(0.126); |
1780 | gCanvas->SetRightMargin(0.126); |
1633 | gCanvas->SetTopMargin(0.077); |
1781 | gCanvas->SetTopMargin(0.077); |
1634 | gScan2D->Draw("COLZ"); |
1782 | gScan2D->Draw("COLZ"); |
1635 | 1783 | ||
1636 | gCanvas->Modified(); |
1784 | gCanvas->Modified(); |
1637 | gCanvas->Update(); |
1785 | gCanvas->Update(); |
1638 | 1786 | ||
1639 | if(!cleanPlots) |
1787 | if(!cleanPlots) |
1640 | { |
1788 | { |
1641 | if( |
1789 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
1642 | gScan2D->SetTitle("Surface scan;X [table units];Y [table units]"); |
1790 | gScan2D->SetTitle("Surface scan;X [table units];Y [table units]"); |
1643 | else if( |
1791 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
1644 | gScan2D->SetTitle("Surface scan;X [#mum];Y [#mum]"); |
1792 | gScan2D->SetTitle("Surface scan;X [#mum];Y [#mum]"); |
1645 | } |
1793 | } |
1646 | else |
1794 | else |
1647 | { |
1795 | { |
1648 | if( |
1796 | if(posUnitsPlot->widgetCB->GetSelected() == 0) |
1649 | gScan2D->SetTitle(";X [table units];Y [table units]"); |
1797 | gScan2D->SetTitle(";X [table units];Y [table units]"); |
1650 | else if( |
1798 | else if(posUnitsPlot->widgetCB->GetSelected() == 1) |
1651 | gScan2D->SetTitle(";X [#mum];Y [#mum]"); |
1799 | gScan2D->SetTitle(";X [#mum];Y [#mum]"); |
1652 | } |
1800 | } |
1653 | /* TGaxis *xax = (TGaxis*)gScan2D->GetXaxis(); |
1801 | /* TGaxis *xax = (TGaxis*)gScan2D->GetXaxis(); |
1654 | xax->SetMaxDigits(4); |
1802 | xax->SetMaxDigits(4); |
1655 | TGaxis *yax = (TGaxis*)gScan2D->GetYaxis(); |
1803 | TGaxis *yax = (TGaxis*)gScan2D->GetYaxis(); |
1656 | yax->SetMaxDigits(4);*/ |
1804 | yax->SetMaxDigits(4);*/ |
1657 | 1805 | ||
1658 | gScan2D->SetNpx((int)resolSurf->widgetNE[0]->GetNumber()); |
1806 | gScan2D->SetNpx((int)resolSurf->widgetNE[0]->GetNumber()); |
1659 | gScan2D->SetNpy((int)resolSurf->widgetNE[1]->GetNumber()); |
1807 | gScan2D->SetNpy((int)resolSurf->widgetNE[1]->GetNumber()); |
1660 | 1808 | ||
1661 | gCanvas->Modified(); |
1809 | gCanvas->Modified(); |
1662 | gCanvas->Update(); |
1810 | gCanvas->Update(); |
1663 | 1811 | ||
1664 | gScan2D->GetXaxis()->SetTitleOffset(1.3); |
1812 | gScan2D->GetXaxis()->SetTitleOffset(1.3); |
1665 | gScan2D->GetXaxis()->CenterTitle(kTRUE); |
1813 | gScan2D->GetXaxis()->CenterTitle(kTRUE); |
1666 | gScan2D->GetXaxis()->SetLabelSize(0.027); |
1814 | gScan2D->GetXaxis()->SetLabelSize(0.027); |
1667 | gScan2D->GetXaxis()->SetLabelOffset(0.02); |
1815 | gScan2D->GetXaxis()->SetLabelOffset(0.02); |
1668 | gScan2D->GetXaxis()->SetRangeUser(range[0], range[1]); |
1816 | gScan2D->GetXaxis()->SetRangeUser(range[0], range[1]); |
1669 | gScan2D->GetXaxis()->SetNoExponent(kTRUE); |
1817 | gScan2D->GetXaxis()->SetNoExponent(kTRUE); |
1670 | gScan2D->GetYaxis()->SetTitleOffset(1.9); |
1818 | gScan2D->GetYaxis()->SetTitleOffset(1.9); |
1671 | gScan2D->GetYaxis()->CenterTitle(kTRUE); |
1819 | gScan2D->GetYaxis()->CenterTitle(kTRUE); |
1672 | gScan2D->GetYaxis()->SetLabelSize(0.027); |
1820 | gScan2D->GetYaxis()->SetLabelSize(0.027); |
1673 | gScan2D-> |
1821 | gScan2D->GetYaxis()->SetLabelOffset(0.02); |
1674 | gScan2D->GetYaxis()->SetRangeUser(range[2], range[3]); |
1822 | gScan2D->GetYaxis()->SetRangeUser(range[2], range[3]); |
1675 | gScan2D->GetYaxis()->SetNoExponent(kTRUE); |
1823 | gScan2D->GetYaxis()->SetNoExponent(kTRUE); |
1676 | 1824 | ||
1677 | gCanvas->Modified(); |
1825 | gCanvas->Modified(); |
1678 | gCanvas->Update(); |
1826 | gCanvas->Update(); |
1679 | 1827 | ||
1680 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
1828 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
1681 | sprintf(exportname, "%s_surfscan.pdf", ctemp); |
1829 | sprintf(exportname, "%s_surfscan.pdf", ctemp); |
1682 | gCanvas->SaveAs(exportname); |
1830 | gCanvas->SaveAs(exportname); |
1683 | 1831 | ||
1684 | // Update the progress bar |
1832 | // Update the progress bar |
1685 | analysisProgress->widgetPB->SetPosition(100.0); |
1833 | analysisProgress->widgetPB->SetPosition(100.0); |
1686 | gVirtualX->Update(1); |
1834 | gVirtualX->Update(1); |
1687 | 1835 | ||
1688 | if(edit == 0) |
1836 | if(edit == 0) |
1689 | { |
1837 | { |
1690 | delete gScan2D; |
1838 | delete gScan2D; |
1691 | delete gCanvas; |
1839 | delete gCanvas; |
1692 | } |
1840 | } |
1693 | else if(edit == 1) |
1841 | else if(edit == 1) |
1694 | { |
1842 | { |
1695 | gCanvas->Modified(); |
1843 | gCanvas->Modified(); |
1696 | gCanvas->Update(); |
1844 | gCanvas->Update(); |
1697 | } |
1845 | } |
1698 | } |
1846 | } |
1699 | } |
1847 | } |
1700 | 1848 |