]>
Commit | Line | Data |
---|---|---|
5c6503dc | 1 | /************************************************************************** |
2 | * This file is property of and copyright by the ALICE HLT Project * | |
3 | * All rights reserved. * | |
4 | * * | |
5 | * Primary Authors: Oystein Djuvsland * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
2374af72 | 16 | |
17 | /** | |
18 | * Measures the baselines and calculates relevant values | |
19 | * | |
20 | * @file AliHLTPHOSBaselineAnalyzer.cxx | |
21 | * @author Oystein Djuvsland | |
22 | * @date | |
23 | * @brief Baseline analyzer for PHOS HLT | |
24 | */ | |
25 | ||
5c6503dc | 26 | #include "AliHLTPHOSBaselineAnalyzer.h" |
27 | #include "AliHLTPHOSBase.h" | |
28 | #include "AliHLTPHOSBaseline.h" | |
29 | #include "AliHLTPHOSValidCellDataStruct.h" | |
30 | #include "AliHLTPHOSSanityInspector.h" | |
31 | #include "AliHLTPHOSConstants.h" | |
32 | ||
33 | #include "AliHLTPHOSRcuCellEnergyDataStruct.h" | |
34 | #include "TTree.h" | |
35 | #include "TClonesArray.h" | |
36 | #include "TFile.h" | |
37 | #include "TH1F.h" | |
38 | #include "TH2F.h" | |
39 | ||
40 | using namespace PhosHLTConst; | |
41 | ||
ab38011b | 42 | ClassImp(AliHLTPHOSBaselineAnalyzer); |
5c6503dc | 43 | |
44 | AliHLTPHOSBaselineAnalyzer::AliHLTPHOSBaselineAnalyzer() : | |
45 | AliHLTPHOSBase(), | |
46 | fSampleStart(5), | |
1804b020 | 47 | fMaxCrazyDifference(0), |
25b7f84c | 48 | fMaxSignal(0), |
49 | fChannelCount(0), | |
5c6503dc | 50 | fTreePtr(0), |
25b7f84c | 51 | fBaselineArrayPtr(0), |
52 | fRMSHistogramPtr(0), | |
53 | fRMSMapHighGainHistogramPtr(0), | |
54 | fRMSMapLowGainHistogramPtr(0), | |
55 | fFixedRMSHistogramPtr(0), | |
56 | fFixedRMSMapHighGainHistogramPtr(0), | |
57 | fFixedRMSMapLowGainHistogramPtr(0), | |
5c6503dc | 58 | fSanityInspector(0) |
59 | { | |
2374af72 | 60 | //see headerfile for documentation |
5c6503dc | 61 | fSanityInspector = new AliHLTPHOSSanityInspector(); |
62 | ||
63 | char histName[128]; | |
64 | char histTitle[128]; | |
1804b020 | 65 | for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++) |
5c6503dc | 66 | { |
1804b020 | 67 | for(UInt_t z = 0; z < N_ZROWS_MOD; z++) |
5c6503dc | 68 | { |
1804b020 | 69 | for(UInt_t gain = 0; gain < N_GAINS; gain++) |
5c6503dc | 70 | { |
71 | sprintf(histName, "sample_value_channel_x_col_%d_z_row_%d_gain_%d", x, z, gain); | |
72 | sprintf(histTitle, "Distribution of Sample Values for Channel X: %d - Z: %d - Gain: %d", x, z, gain); | |
73 | fChannelHistogramsPtr[x][z][gain] = new TH1F(histName, histTitle, 1024, 0, 1023); | |
74 | sprintf(histName, "fixed_sample_value_channel_x_col_%d_z_row_%d_gain_%d", x, z, gain); | |
75 | sprintf(histTitle, "Distribution of Corrected Sample Values for Channel X: %d - Z: %d - Gain: %d", x, z, gain); | |
76 | fFixedChannelHistogramsPtr[x][z][gain] = new TH1F(histName, histTitle, 1024, 0, 1023); | |
77 | } | |
78 | } | |
79 | } | |
80 | ||
81 | fRMSHistogramPtr = new TH1F("RMSHist", "RMS Values for All Channels", 1023, 0, 1023); | |
82 | fRMSMapHighGainHistogramPtr = new TH2F("RMSHGMapHist", "Map of RMS Values for High Gain Channels", 64, 0, 63, 56, 0, 55); | |
83 | fRMSMapLowGainHistogramPtr = new TH2F("RMSLGMapHist", "Map of RMS Values for Low Gain Channels", 64, 0, 63, 56, 0, 55); | |
84 | ||
85 | fFixedRMSHistogramPtr = new TH1F("fixedRMSHist", "Corrected RMS Values for All Channels", 1023, 0, 1023); | |
86 | fFixedRMSMapHighGainHistogramPtr = new TH2F("fixedRMSHGMapHist", "Map of Corrected RMS Values for High Gain Channels", 64, 0, 63, 56, 0, 55); | |
87 | fFixedRMSMapLowGainHistogramPtr = new TH2F("fixedRMSLGMapHist", "Map of Corrected RMS Values for Low Gain Channels", 64, 0, 63, 56, 0, 55); | |
88 | ||
89 | ResetBaselines(); | |
90 | ResetAccumulatedBaselines(); | |
91 | } | |
92 | ||
93 | AliHLTPHOSBaselineAnalyzer::~AliHLTPHOSBaselineAnalyzer() | |
94 | { | |
2374af72 | 95 | //see headerfile for documentation |
5c6503dc | 96 | } |
97 | ||
98 | ||
99 | void | |
100 | AliHLTPHOSBaselineAnalyzer::CalculateRcuBaselines(AliHLTPHOSRcuCellEnergyDataStruct* rcuData) | |
101 | { | |
2374af72 | 102 | //see headerfile for documentation |
25b7f84c | 103 | //Int_t xOff = rcuData->fRcuX * N_XCOLUMNS_RCU; |
104 | //Int_t zOff = rcuData->fRcuZ * N_ZROWS_RCU; | |
105 | //Float_t baseline = 0; | |
5c6503dc | 106 | |
d949e02e | 107 | //TODO: fix this to comply with new format |
108 | /* | |
5c6503dc | 109 | AliHLTPHOSValidCellDataStruct *data = rcuData->fValidData; |
110 | ||
111 | for(Int_t i = 0; i < rcuData->fCnt; i++) | |
112 | { | |
113 | baseline = CalculateChannelBaseline(&(data[i]), xOff, zOff); | |
114 | if(!(baseline < 0)) | |
115 | { | |
116 | CalculateAccumulatedChannelBaseline(data[i].fX + xOff, data[i].fZ + zOff, data[i].fGain, baseline); | |
117 | } | |
d949e02e | 118 | }*/ |
5c6503dc | 119 | } |
120 | ||
121 | ||
122 | ||
123 | Float_t | |
124 | AliHLTPHOSBaselineAnalyzer::CalculateChannelBaseline(AliHLTPHOSValidCellDataStruct *cellData, Int_t xOff, Int_t zOff) | |
125 | { | |
2374af72 | 126 | //see headerfile for documentation |
5c6503dc | 127 | Int_t crazyness = 0; |
128 | Int_t total = 0; | |
129 | Int_t *data = cellData->fData; | |
130 | for(Int_t i = fSampleStart; i < fNSamples; i++) | |
131 | { | |
132 | /* | |
133 | if(cellData->fGain == 0) | |
134 | { | |
135 | fChannelLowGainHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff]->Fill(data[i]); | |
136 | } | |
137 | else | |
138 | { | |
139 | fChannelHighGainHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff]->Fill(data[i]); | |
140 | } | |
141 | */ | |
142 | fChannelHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain]->Fill(data[i]); | |
143 | } | |
144 | ||
145 | if(cellData->fCrazyness == 0) | |
146 | { | |
147 | crazyness = fSanityInspector->CheckAndHealInsanity(data, fNSamples); | |
148 | } | |
149 | if(crazyness < 0) | |
150 | return crazyness; | |
151 | ||
152 | for(Int_t j = fSampleStart; j < fNSamples; j++) | |
153 | { | |
154 | if(data[j] > fMaxSignal) | |
155 | return -data[j]; | |
156 | ||
157 | fFixedChannelHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain]->Fill(data[j]); | |
158 | total += data[j]; | |
159 | } | |
160 | fBaselines[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain] = (float)total / (fNSamples - fSampleStart); | |
161 | ||
162 | return (float)total/(fNSamples - fSampleStart); | |
163 | } | |
ab38011b | 164 | |
5c6503dc | 165 | void |
166 | AliHLTPHOSBaselineAnalyzer::CalculateAccumulatedChannelBaseline(Int_t x, Int_t z, Int_t gain, Float_t baseline) | |
167 | { | |
2374af72 | 168 | //see headerfile for documentation |
5c6503dc | 169 | Float_t oldBaseline = fAccumulatedBaselines[x][z][gain][0]; |
170 | Float_t nEntries = fAccumulatedBaselines[x][z][gain][1]; | |
171 | ||
172 | Float_t total = nEntries * oldBaseline + baseline; | |
173 | nEntries++; | |
174 | fAccumulatedBaselines[x][z][gain][0] = total / nEntries; | |
175 | fAccumulatedBaselines[x][z][gain][1] = nEntries; | |
176 | } | |
177 | ||
178 | void | |
179 | AliHLTPHOSBaselineAnalyzer::CalculateChannelsBaselineRMS() | |
180 | { | |
2374af72 | 181 | |
182 | //see headerfile for documentation | |
1804b020 | 183 | for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++) |
5c6503dc | 184 | { |
1804b020 | 185 | for(UInt_t z = 0; z < N_ZROWS_MOD; z++) |
5c6503dc | 186 | { |
1804b020 | 187 | for(UInt_t gain = 0; gain < N_GAINS; gain++) |
5c6503dc | 188 | { |
189 | fRMSHistogramPtr->Fill(fChannelHistogramsPtr[x][z][gain]->GetRMS()); | |
190 | if(gain == 1) | |
191 | fRMSMapHighGainHistogramPtr->SetBinContent(x, z, fChannelHistogramsPtr[x][z][gain]->GetRMS()); | |
192 | else | |
193 | fRMSMapLowGainHistogramPtr->SetBinContent(x, z, fChannelHistogramsPtr[x][z][gain]->GetRMS()); | |
194 | ||
195 | fFixedRMSHistogramPtr->Fill(fFixedChannelHistogramsPtr[x][z][gain]->GetRMS()); | |
196 | if(gain == 1) | |
197 | fFixedRMSMapHighGainHistogramPtr->SetBinContent(x, z, fFixedChannelHistogramsPtr[x][z][gain]->GetRMS()); | |
198 | else | |
199 | fFixedRMSMapLowGainHistogramPtr->SetBinContent(x, z, fFixedChannelHistogramsPtr[x][z][gain]->GetRMS()); | |
200 | } | |
201 | } | |
202 | } | |
203 | } | |
204 | ||
205 | ||
206 | void | |
207 | AliHLTPHOSBaselineAnalyzer::SetRootObjects(TTree *tree, TClonesArray *baselineArray) | |
208 | { | |
2374af72 | 209 | //see headerfile for documentation |
5c6503dc | 210 | fTreePtr = tree; |
211 | fBaselineArrayPtr = baselineArray; | |
212 | tree->Branch("Baselines", &fBaselineArrayPtr); | |
213 | } | |
214 | ||
215 | ||
216 | void | |
217 | AliHLTPHOSBaselineAnalyzer::FillTree() | |
218 | { | |
2374af72 | 219 | //see headerfile for documentation |
5c6503dc | 220 | AliHLTPHOSBaseline *baseline; |
221 | Int_t n = 0; | |
222 | ||
1804b020 | 223 | for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++) |
5c6503dc | 224 | { |
1804b020 | 225 | for(UInt_t z = 0; z < N_ZROWS_MOD; z++) |
5c6503dc | 226 | { |
1804b020 | 227 | for(UInt_t gain = 0; gain < N_GAINS; gain++) |
5c6503dc | 228 | { |
229 | baseline = (AliHLTPHOSBaseline*)fBaselineArrayPtr->New(n); | |
230 | baseline->SetX(x); | |
231 | baseline->SetZ(z); | |
232 | baseline->SetGain(gain); | |
233 | baseline->SetBaseline(fAccumulatedBaselines[x][z][gain][0]); | |
234 | baseline->SetEntries((Int_t)fAccumulatedBaselines[x][z][gain][1]); | |
235 | n++; | |
236 | } | |
237 | } | |
238 | } | |
239 | fTreePtr->Fill(); | |
240 | fBaselineArrayPtr->Clear(); | |
241 | } | |
242 | ||
243 | void | |
244 | AliHLTPHOSBaselineAnalyzer::WriteAccumulatedBaselines(const Char_t* filename) | |
245 | { | |
2374af72 | 246 | //see headerfile for documentation |
5c6503dc | 247 | TFile *baselineFile = TFile::Open(filename, "recreate"); |
248 | fTreePtr->Write(); | |
249 | baselineFile->Close(); | |
250 | } | |
251 | ||
252 | void | |
253 | AliHLTPHOSBaselineAnalyzer::WriteChannelHistograms(const Char_t* filename) | |
254 | { | |
2374af72 | 255 | //see headerfile for documentation |
5c6503dc | 256 | TFile *file = TFile::Open(filename, "recreate"); |
257 | ||
1804b020 | 258 | for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++) |
5c6503dc | 259 | { |
1804b020 | 260 | for(UInt_t z = 0; z < N_ZROWS_MOD; z++) |
5c6503dc | 261 | { |
1804b020 | 262 | for(UInt_t gain = 0; gain < N_GAINS; gain++) |
5c6503dc | 263 | { |
264 | fChannelHistogramsPtr[x][z][gain]->Write(); | |
265 | } | |
266 | } | |
267 | } | |
268 | file->Close(); | |
269 | } | |
270 | ||
271 | ||
272 | void | |
273 | AliHLTPHOSBaselineAnalyzer::WriteRMSHistogram(const Char_t* filename) | |
274 | { | |
2374af72 | 275 | //see headerfile for documentation |
5c6503dc | 276 | TFile *file = TFile::Open(filename, "recreate"); |
277 | fRMSHistogramPtr->Write(); | |
278 | fRMSMapHighGainHistogramPtr->Write(); | |
279 | fRMSMapLowGainHistogramPtr->Write(); | |
280 | ||
281 | fFixedRMSHistogramPtr->Write(); | |
282 | fFixedRMSMapHighGainHistogramPtr->Write(); | |
283 | fFixedRMSMapLowGainHistogramPtr->Write(); | |
284 | ||
285 | file->Close(); | |
286 | } | |
287 | ||
288 | void | |
289 | AliHLTPHOSBaselineAnalyzer::ResetBaselines() | |
290 | { | |
2374af72 | 291 | //see headerfile for documentation |
1804b020 | 292 | for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++) |
5c6503dc | 293 | { |
1804b020 | 294 | for(UInt_t z = 0; z < N_ZROWS_MOD; z++) |
5c6503dc | 295 | { |
1804b020 | 296 | for(UInt_t gain = 0; gain < N_GAINS; gain++) |
5c6503dc | 297 | { |
298 | fBaselines[x][z][gain] = 0; | |
299 | } | |
300 | } | |
301 | } | |
302 | } | |
303 | ||
304 | void | |
305 | AliHLTPHOSBaselineAnalyzer::ResetChannelCount() | |
306 | { | |
2374af72 | 307 | //see headerfile for documentation |
5c6503dc | 308 | fChannelCount = 0; |
309 | } | |
310 | ||
311 | void | |
312 | AliHLTPHOSBaselineAnalyzer::ResetAccumulatedBaselines() | |
313 | { | |
1804b020 | 314 | for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++) |
5c6503dc | 315 | { |
1804b020 | 316 | for(UInt_t z = 0; z < N_ZROWS_MOD; z++) |
5c6503dc | 317 | { |
1804b020 | 318 | for(UInt_t gain = 0; gain < N_GAINS; gain++) |
5c6503dc | 319 | { |
320 | fAccumulatedBaselines[x][z][gain][0] = 0; | |
321 | fAccumulatedBaselines[x][z][gain][1] = 0; | |
322 | } | |
323 | } | |
324 | } | |
325 | } | |
326 | ||
327 | void | |
328 | AliHLTPHOSBaselineAnalyzer::SetMaxCrazyDifference(Int_t diff) | |
329 | { | |
2374af72 | 330 | //see headerfile for documentation |
5c6503dc | 331 | fMaxCrazyDifference = diff; |
332 | fSanityInspector->SetMaxDifference(diff); | |
333 | } | |
334 | ||
335 | ||
336 | ||
337 | /* | |
338 | void | |
339 | AliHLTPHOSBaselineAnalyzer::SetChannelsHistograms(TH1F *channelLowGainHistArray[N_XCOLUMNS_MOD][N_ZROWS_MOD], TH1F *channelHighGainHistArray[N_XCOLUMNS_MOD][N_ZROWS_MOD]) | |
340 | { | |
1804b020 | 341 | for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++) |
5c6503dc | 342 | { |
1804b020 | 343 | for(UInt_t z = 0; z < N_ZROWS_MOD; z++) |
5c6503dc | 344 | { |
1804b020 | 345 | for(UInt_t gain = 0; gain < N_GAINS; gain++) |
5c6503dc | 346 | { |
347 | fChannelLowGainHistogramsPtr[x][z][gain] = channelLowGainHistArray[x][z][gain]; | |
348 | fChannelHighGainHistogramsPtr[x][z][gain] = channelHighGainHistArray[x][z][gain]; | |
349 | } | |
350 | } | |
351 | } | |
352 | } | |
353 | */ |