]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSBaselineAnalyzer.cxx
blabalbal
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSBaselineAnalyzer.cxx
CommitLineData
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
40using namespace PhosHLTConst;
41
ab38011b 42ClassImp(AliHLTPHOSBaselineAnalyzer);
5c6503dc 43
44AliHLTPHOSBaselineAnalyzer::AliHLTPHOSBaselineAnalyzer() :
45 AliHLTPHOSBase(),
46 fSampleStart(5),
1804b020 47 fMaxCrazyDifference(0),
48 fMaxSignal(0),
5c6503dc 49 fTreePtr(0),
50 fSanityInspector(0)
51{
2374af72 52 //see headerfile for documentation
5c6503dc 53 fSanityInspector = new AliHLTPHOSSanityInspector();
54
55 char histName[128];
56 char histTitle[128];
1804b020 57 for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 58 {
1804b020 59 for(UInt_t z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 60 {
1804b020 61 for(UInt_t gain = 0; gain < N_GAINS; gain++)
5c6503dc 62 {
63 sprintf(histName, "sample_value_channel_x_col_%d_z_row_%d_gain_%d", x, z, gain);
64 sprintf(histTitle, "Distribution of Sample Values for Channel X: %d - Z: %d - Gain: %d", x, z, gain);
65 fChannelHistogramsPtr[x][z][gain] = new TH1F(histName, histTitle, 1024, 0, 1023);
66 sprintf(histName, "fixed_sample_value_channel_x_col_%d_z_row_%d_gain_%d", x, z, gain);
67 sprintf(histTitle, "Distribution of Corrected Sample Values for Channel X: %d - Z: %d - Gain: %d", x, z, gain);
68 fFixedChannelHistogramsPtr[x][z][gain] = new TH1F(histName, histTitle, 1024, 0, 1023);
69 }
70 }
71 }
72
73 fRMSHistogramPtr = new TH1F("RMSHist", "RMS Values for All Channels", 1023, 0, 1023);
74 fRMSMapHighGainHistogramPtr = new TH2F("RMSHGMapHist", "Map of RMS Values for High Gain Channels", 64, 0, 63, 56, 0, 55);
75 fRMSMapLowGainHistogramPtr = new TH2F("RMSLGMapHist", "Map of RMS Values for Low Gain Channels", 64, 0, 63, 56, 0, 55);
76
77 fFixedRMSHistogramPtr = new TH1F("fixedRMSHist", "Corrected RMS Values for All Channels", 1023, 0, 1023);
78 fFixedRMSMapHighGainHistogramPtr = new TH2F("fixedRMSHGMapHist", "Map of Corrected RMS Values for High Gain Channels", 64, 0, 63, 56, 0, 55);
79 fFixedRMSMapLowGainHistogramPtr = new TH2F("fixedRMSLGMapHist", "Map of Corrected RMS Values for Low Gain Channels", 64, 0, 63, 56, 0, 55);
80
81 ResetBaselines();
82 ResetAccumulatedBaselines();
83}
84
85AliHLTPHOSBaselineAnalyzer::~AliHLTPHOSBaselineAnalyzer()
86{
2374af72 87 //see headerfile for documentation
5c6503dc 88}
89
90
91void
92AliHLTPHOSBaselineAnalyzer::CalculateRcuBaselines(AliHLTPHOSRcuCellEnergyDataStruct* rcuData)
93{
2374af72 94 //see headerfile for documentation
5c6503dc 95 Int_t xOff = rcuData->fRcuX * N_XCOLUMNS_RCU;
96 Int_t zOff = rcuData->fRcuZ * N_ZROWS_RCU;
97 Float_t baseline = 0;
98
d949e02e 99 //TODO: fix this to comply with new format
100 /*
5c6503dc 101 AliHLTPHOSValidCellDataStruct *data = rcuData->fValidData;
102
103 for(Int_t i = 0; i < rcuData->fCnt; i++)
104 {
105 baseline = CalculateChannelBaseline(&(data[i]), xOff, zOff);
106 if(!(baseline < 0))
107 {
108 CalculateAccumulatedChannelBaseline(data[i].fX + xOff, data[i].fZ + zOff, data[i].fGain, baseline);
109 }
d949e02e 110 }*/
5c6503dc 111}
112
113
114
115Float_t
116AliHLTPHOSBaselineAnalyzer::CalculateChannelBaseline(AliHLTPHOSValidCellDataStruct *cellData, Int_t xOff, Int_t zOff)
117{
2374af72 118 //see headerfile for documentation
5c6503dc 119 Int_t crazyness = 0;
120 Int_t total = 0;
121 Int_t *data = cellData->fData;
122 for(Int_t i = fSampleStart; i < fNSamples; i++)
123 {
124 /*
125 if(cellData->fGain == 0)
126 {
127 fChannelLowGainHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff]->Fill(data[i]);
128 }
129 else
130 {
131 fChannelHighGainHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff]->Fill(data[i]);
132 }
133 */
134 fChannelHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain]->Fill(data[i]);
135 }
136
137 if(cellData->fCrazyness == 0)
138 {
139 crazyness = fSanityInspector->CheckAndHealInsanity(data, fNSamples);
140 }
141 if(crazyness < 0)
142 return crazyness;
143
144 for(Int_t j = fSampleStart; j < fNSamples; j++)
145 {
146 if(data[j] > fMaxSignal)
147 return -data[j];
148
149 fFixedChannelHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain]->Fill(data[j]);
150 total += data[j];
151 }
152 fBaselines[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain] = (float)total / (fNSamples - fSampleStart);
153
154 return (float)total/(fNSamples - fSampleStart);
155}
ab38011b 156
5c6503dc 157void
158AliHLTPHOSBaselineAnalyzer::CalculateAccumulatedChannelBaseline(Int_t x, Int_t z, Int_t gain, Float_t baseline)
159{
2374af72 160 //see headerfile for documentation
5c6503dc 161 Float_t oldBaseline = fAccumulatedBaselines[x][z][gain][0];
162 Float_t nEntries = fAccumulatedBaselines[x][z][gain][1];
163
164 Float_t total = nEntries * oldBaseline + baseline;
165 nEntries++;
166 fAccumulatedBaselines[x][z][gain][0] = total / nEntries;
167 fAccumulatedBaselines[x][z][gain][1] = nEntries;
168}
169
170void
171AliHLTPHOSBaselineAnalyzer::CalculateChannelsBaselineRMS()
172{
2374af72 173
174 //see headerfile for documentation
1804b020 175 for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 176 {
1804b020 177 for(UInt_t z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 178 {
1804b020 179 for(UInt_t gain = 0; gain < N_GAINS; gain++)
5c6503dc 180 {
181 fRMSHistogramPtr->Fill(fChannelHistogramsPtr[x][z][gain]->GetRMS());
182 if(gain == 1)
183 fRMSMapHighGainHistogramPtr->SetBinContent(x, z, fChannelHistogramsPtr[x][z][gain]->GetRMS());
184 else
185 fRMSMapLowGainHistogramPtr->SetBinContent(x, z, fChannelHistogramsPtr[x][z][gain]->GetRMS());
186
187 fFixedRMSHistogramPtr->Fill(fFixedChannelHistogramsPtr[x][z][gain]->GetRMS());
188 if(gain == 1)
189 fFixedRMSMapHighGainHistogramPtr->SetBinContent(x, z, fFixedChannelHistogramsPtr[x][z][gain]->GetRMS());
190 else
191 fFixedRMSMapLowGainHistogramPtr->SetBinContent(x, z, fFixedChannelHistogramsPtr[x][z][gain]->GetRMS());
192 }
193 }
194 }
195}
196
197
198void
199AliHLTPHOSBaselineAnalyzer::SetRootObjects(TTree *tree, TClonesArray *baselineArray)
200{
2374af72 201 //see headerfile for documentation
5c6503dc 202 fTreePtr = tree;
203 fBaselineArrayPtr = baselineArray;
204 tree->Branch("Baselines", &fBaselineArrayPtr);
205}
206
207
208void
209AliHLTPHOSBaselineAnalyzer::FillTree()
210{
2374af72 211 //see headerfile for documentation
5c6503dc 212 AliHLTPHOSBaseline *baseline;
213 Int_t n = 0;
214
1804b020 215 for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 216 {
1804b020 217 for(UInt_t z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 218 {
1804b020 219 for(UInt_t gain = 0; gain < N_GAINS; gain++)
5c6503dc 220 {
221 baseline = (AliHLTPHOSBaseline*)fBaselineArrayPtr->New(n);
222 baseline->SetX(x);
223 baseline->SetZ(z);
224 baseline->SetGain(gain);
225 baseline->SetBaseline(fAccumulatedBaselines[x][z][gain][0]);
226 baseline->SetEntries((Int_t)fAccumulatedBaselines[x][z][gain][1]);
227 n++;
228 }
229 }
230 }
231 fTreePtr->Fill();
232 fBaselineArrayPtr->Clear();
233}
234
235void
236AliHLTPHOSBaselineAnalyzer::WriteAccumulatedBaselines(const Char_t* filename)
237{
2374af72 238 //see headerfile for documentation
5c6503dc 239 TFile *baselineFile = TFile::Open(filename, "recreate");
240 fTreePtr->Write();
241 baselineFile->Close();
242}
243
244void
245AliHLTPHOSBaselineAnalyzer::WriteChannelHistograms(const Char_t* filename)
246{
2374af72 247 //see headerfile for documentation
5c6503dc 248 TFile *file = TFile::Open(filename, "recreate");
249
1804b020 250 for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 251 {
1804b020 252 for(UInt_t z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 253 {
1804b020 254 for(UInt_t gain = 0; gain < N_GAINS; gain++)
5c6503dc 255 {
256 fChannelHistogramsPtr[x][z][gain]->Write();
257 }
258 }
259 }
260 file->Close();
261}
262
263
264void
265AliHLTPHOSBaselineAnalyzer::WriteRMSHistogram(const Char_t* filename)
266{
2374af72 267 //see headerfile for documentation
5c6503dc 268 TFile *file = TFile::Open(filename, "recreate");
269 fRMSHistogramPtr->Write();
270 fRMSMapHighGainHistogramPtr->Write();
271 fRMSMapLowGainHistogramPtr->Write();
272
273 fFixedRMSHistogramPtr->Write();
274 fFixedRMSMapHighGainHistogramPtr->Write();
275 fFixedRMSMapLowGainHistogramPtr->Write();
276
277 file->Close();
278}
279
280void
281AliHLTPHOSBaselineAnalyzer::ResetBaselines()
282{
2374af72 283 //see headerfile for documentation
1804b020 284 for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 285 {
1804b020 286 for(UInt_t z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 287 {
1804b020 288 for(UInt_t gain = 0; gain < N_GAINS; gain++)
5c6503dc 289 {
290 fBaselines[x][z][gain] = 0;
291 }
292 }
293 }
294}
295
296void
297AliHLTPHOSBaselineAnalyzer::ResetChannelCount()
298{
2374af72 299 //see headerfile for documentation
5c6503dc 300 fChannelCount = 0;
301}
302
303void
304AliHLTPHOSBaselineAnalyzer::ResetAccumulatedBaselines()
305{
1804b020 306 for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 307 {
1804b020 308 for(UInt_t z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 309 {
1804b020 310 for(UInt_t gain = 0; gain < N_GAINS; gain++)
5c6503dc 311 {
312 fAccumulatedBaselines[x][z][gain][0] = 0;
313 fAccumulatedBaselines[x][z][gain][1] = 0;
314 }
315 }
316 }
317}
318
319void
320AliHLTPHOSBaselineAnalyzer::SetMaxCrazyDifference(Int_t diff)
321{
2374af72 322 //see headerfile for documentation
5c6503dc 323 fMaxCrazyDifference = diff;
324 fSanityInspector->SetMaxDifference(diff);
325}
326
327
328
329/*
330void
331AliHLTPHOSBaselineAnalyzer::SetChannelsHistograms(TH1F *channelLowGainHistArray[N_XCOLUMNS_MOD][N_ZROWS_MOD], TH1F *channelHighGainHistArray[N_XCOLUMNS_MOD][N_ZROWS_MOD])
332{
1804b020 333 for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 334 {
1804b020 335 for(UInt_t z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 336 {
1804b020 337 for(UInt_t gain = 0; gain < N_GAINS; gain++)
5c6503dc 338 {
339 fChannelLowGainHistogramsPtr[x][z][gain] = channelLowGainHistArray[x][z][gain];
340 fChannelHighGainHistogramsPtr[x][z][gain] = channelHighGainHistArray[x][z][gain];
341 }
342 }
343 }
344}
345*/