]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSBaselineAnalyzer.cxx
New monitoring componenet for the online display (Oystein)
[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 */
94594220 25#include <fstream>
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"
94594220 32#include "AliHLTPHOSMapper.h"
5c6503dc 33
34#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
94594220 35#include "AliHLTPHOSSharedMemoryInterface.h"
36#include "AliHLTPHOSValidCellDataStruct.h"
5c6503dc 37#include "TTree.h"
38#include "TClonesArray.h"
39#include "TFile.h"
94594220 40#include "TF1.h"
5c6503dc 41#include "TH1F.h"
42#include "TH2F.h"
43
44using namespace PhosHLTConst;
45
ab38011b 46ClassImp(AliHLTPHOSBaselineAnalyzer);
5c6503dc 47
48AliHLTPHOSBaselineAnalyzer::AliHLTPHOSBaselineAnalyzer() :
49 AliHLTPHOSBase(),
50 fSampleStart(5),
1804b020 51 fMaxCrazyDifference(0),
25b7f84c 52 fMaxSignal(0),
53 fChannelCount(0),
5c6503dc 54 fTreePtr(0),
25b7f84c 55 fBaselineArrayPtr(0),
56 fRMSHistogramPtr(0),
57 fRMSMapHighGainHistogramPtr(0),
58 fRMSMapLowGainHistogramPtr(0),
59 fFixedRMSHistogramPtr(0),
60 fFixedRMSMapHighGainHistogramPtr(0),
61 fFixedRMSMapLowGainHistogramPtr(0),
5c6503dc 62 fSanityInspector(0)
63{
2374af72 64 //see headerfile for documentation
5c6503dc 65 fSanityInspector = new AliHLTPHOSSanityInspector();
66
67 char histName[128];
68 char histTitle[128];
b444d727 69 for(int x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 70 {
b444d727 71 for(int z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 72 {
b444d727 73 for(int gain = 0; gain < N_GAINS; gain++)
5c6503dc 74 {
75 sprintf(histName, "sample_value_channel_x_col_%d_z_row_%d_gain_%d", x, z, gain);
76 sprintf(histTitle, "Distribution of Sample Values for Channel X: %d - Z: %d - Gain: %d", x, z, gain);
77 fChannelHistogramsPtr[x][z][gain] = new TH1F(histName, histTitle, 1024, 0, 1023);
78 sprintf(histName, "fixed_sample_value_channel_x_col_%d_z_row_%d_gain_%d", x, z, gain);
79 sprintf(histTitle, "Distribution of Corrected Sample Values for Channel X: %d - Z: %d - Gain: %d", x, z, gain);
80 fFixedChannelHistogramsPtr[x][z][gain] = new TH1F(histName, histTitle, 1024, 0, 1023);
81 }
82 }
83 }
84
85 fRMSHistogramPtr = new TH1F("RMSHist", "RMS Values for All Channels", 1023, 0, 1023);
86 fRMSMapHighGainHistogramPtr = new TH2F("RMSHGMapHist", "Map of RMS Values for High Gain Channels", 64, 0, 63, 56, 0, 55);
87 fRMSMapLowGainHistogramPtr = new TH2F("RMSLGMapHist", "Map of RMS Values for Low Gain Channels", 64, 0, 63, 56, 0, 55);
88
89 fFixedRMSHistogramPtr = new TH1F("fixedRMSHist", "Corrected RMS Values for All Channels", 1023, 0, 1023);
90 fFixedRMSMapHighGainHistogramPtr = new TH2F("fixedRMSHGMapHist", "Map of Corrected RMS Values for High Gain Channels", 64, 0, 63, 56, 0, 55);
91 fFixedRMSMapLowGainHistogramPtr = new TH2F("fixedRMSLGMapHist", "Map of Corrected RMS Values for Low Gain Channels", 64, 0, 63, 56, 0, 55);
92
93 ResetBaselines();
94 ResetAccumulatedBaselines();
95}
96
97AliHLTPHOSBaselineAnalyzer::~AliHLTPHOSBaselineAnalyzer()
98{
2374af72 99 //see headerfile for documentation
5c6503dc 100}
101
102
103void
104AliHLTPHOSBaselineAnalyzer::CalculateRcuBaselines(AliHLTPHOSRcuCellEnergyDataStruct* rcuData)
105{
5c6503dc 106
94594220 107 //see headerfile for documentation
108 Int_t xOff = rcuData->fRcuX * N_XCOLUMNS_RCU;
109 Int_t zOff = rcuData->fRcuZ * N_ZROWS_RCU;
110 Float_t baseline = 0;
111 AliHLTPHOSValidCellDataStruct *currentChannel =0;
5c6503dc 112
94594220 113 AliHLTPHOSSharedMemoryInterface* shmPtr = new AliHLTPHOSSharedMemoryInterface();
114 shmPtr->SetMemory(rcuData);
115 currentChannel = shmPtr->NextChannel();
116
117 while(currentChannel != 0)
5c6503dc 118 {
94594220 119 if(rcuData->fHasRawData == true)
120 {
121 Int_t* rawPtr = 0;
122 Int_t dummysamples = 0;
123 rawPtr = shmPtr->GetRawData(dummysamples);
124 baseline = CalculateChannelBaseline(currentChannel, rawPtr, xOff, zOff);
125 if(!(baseline < 0))
126 {
127 CalculateAccumulatedChannelBaseline(currentChannel->fX + xOff, currentChannel->fZ + zOff, currentChannel->fGain, baseline);
128 }
129 }
130 currentChannel = shmPtr->NextChannel();
131 }
132
133// AliHLTPHOSValidCellDataStruct *data = rcuData->fValidData;
134
135// for(Int_t i = 0; i < rcuData->fCnt; i++)
136// {
137// baseline = CalculateChannelBaseline(&(data[i]), xOff, zOff);
138// if(!(baseline < 0))
139// {
140// CalculateAccumulatedChannelBaseline(data[i].fX + xOff, data[i].fZ + zOff, data[i].fGain, baseline);
141// }
5c6503dc 142}
143
144
145
146Float_t
7ce40e5c 147AliHLTPHOSBaselineAnalyzer::CalculateChannelBaseline(AliHLTPHOSValidCellDataStruct *cellData, Int_t* rawDataPtr, Int_t xOff, Int_t zOff)
5c6503dc 148{
2374af72 149 //see headerfile for documentation
5c6503dc 150 Int_t crazyness = 0;
151 Int_t total = 0;
7ce40e5c 152 Int_t *data = rawDataPtr;
5c6503dc 153 for(Int_t i = fSampleStart; i < fNSamples; i++)
154 {
155 /*
156 if(cellData->fGain == 0)
157 {
158 fChannelLowGainHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff]->Fill(data[i]);
159 }
160 else
161 {
162 fChannelHighGainHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff]->Fill(data[i]);
163 }
164 */
165 fChannelHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain]->Fill(data[i]);
94594220 166 total += data[i];
5c6503dc 167 }
94594220 168 fBaselines[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain] = (float)total / (fNSamples - fSampleStart);
169
170 //if(cellData->fCrazyness == 0)
171 // {
172 // crazyness = fSanityInspector->CheckAndHealInsanity(data, fNSamples);
173 // }
5c6503dc 174 if(crazyness < 0)
175 return crazyness;
94594220 176
177 total = 0;
178
5c6503dc 179 for(Int_t j = fSampleStart; j < fNSamples; j++)
180 {
181 if(data[j] > fMaxSignal)
182 return -data[j];
183
184 fFixedChannelHistogramsPtr[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain]->Fill(data[j]);
185 total += data[j];
186 }
94594220 187 // fBaselines[cellData->fX + xOff][cellData->fZ + zOff][cellData->fGain] = (float)total / (fNSamples - fSampleStart);
5c6503dc 188
189 return (float)total/(fNSamples - fSampleStart);
190}
ab38011b 191
5c6503dc 192void
193AliHLTPHOSBaselineAnalyzer::CalculateAccumulatedChannelBaseline(Int_t x, Int_t z, Int_t gain, Float_t baseline)
194{
2374af72 195 //see headerfile for documentation
5c6503dc 196 Float_t oldBaseline = fAccumulatedBaselines[x][z][gain][0];
197 Float_t nEntries = fAccumulatedBaselines[x][z][gain][1];
198
199 Float_t total = nEntries * oldBaseline + baseline;
200 nEntries++;
201 fAccumulatedBaselines[x][z][gain][0] = total / nEntries;
202 fAccumulatedBaselines[x][z][gain][1] = nEntries;
203}
204
205void
206AliHLTPHOSBaselineAnalyzer::CalculateChannelsBaselineRMS()
207{
2374af72 208
209 //see headerfile for documentation
b444d727 210 for(int x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 211 {
b444d727 212 for(int z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 213 {
b444d727 214 for(int gain = 0; gain < N_GAINS; gain++)
5c6503dc 215 {
216 fRMSHistogramPtr->Fill(fChannelHistogramsPtr[x][z][gain]->GetRMS());
217 if(gain == 1)
218 fRMSMapHighGainHistogramPtr->SetBinContent(x, z, fChannelHistogramsPtr[x][z][gain]->GetRMS());
219 else
220 fRMSMapLowGainHistogramPtr->SetBinContent(x, z, fChannelHistogramsPtr[x][z][gain]->GetRMS());
221
222 fFixedRMSHistogramPtr->Fill(fFixedChannelHistogramsPtr[x][z][gain]->GetRMS());
223 if(gain == 1)
224 fFixedRMSMapHighGainHistogramPtr->SetBinContent(x, z, fFixedChannelHistogramsPtr[x][z][gain]->GetRMS());
225 else
226 fFixedRMSMapLowGainHistogramPtr->SetBinContent(x, z, fFixedChannelHistogramsPtr[x][z][gain]->GetRMS());
227 }
228 }
229 }
230}
231
232
8efbf5fe 233
5c6503dc 234void
235AliHLTPHOSBaselineAnalyzer::SetRootObjects(TTree *tree, TClonesArray *baselineArray)
236{
2374af72 237 //see headerfile for documentation
5c6503dc 238 fTreePtr = tree;
239 fBaselineArrayPtr = baselineArray;
240 tree->Branch("Baselines", &fBaselineArrayPtr);
241}
242
243
244void
245AliHLTPHOSBaselineAnalyzer::FillTree()
246{
2374af72 247 //see headerfile for documentation
5c6503dc 248 AliHLTPHOSBaseline *baseline;
249 Int_t n = 0;
250
b444d727 251 for(int x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 252 {
b444d727 253 for(int z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 254 {
b444d727 255 for(int gain = 0; gain < N_GAINS; gain++)
5c6503dc 256 {
257 baseline = (AliHLTPHOSBaseline*)fBaselineArrayPtr->New(n);
258 baseline->SetX(x);
259 baseline->SetZ(z);
260 baseline->SetGain(gain);
261 baseline->SetBaseline(fAccumulatedBaselines[x][z][gain][0]);
262 baseline->SetEntries((Int_t)fAccumulatedBaselines[x][z][gain][1]);
263 n++;
264 }
265 }
266 }
267 fTreePtr->Fill();
268 fBaselineArrayPtr->Clear();
269}
270
271void
272AliHLTPHOSBaselineAnalyzer::WriteAccumulatedBaselines(const Char_t* filename)
273{
2374af72 274 //see headerfile for documentation
5c6503dc 275 TFile *baselineFile = TFile::Open(filename, "recreate");
276 fTreePtr->Write();
277 baselineFile->Close();
278}
279
280void
281AliHLTPHOSBaselineAnalyzer::WriteChannelHistograms(const Char_t* filename)
282{
2374af72 283 //see headerfile for documentation
94594220 284 TH1F* tmpRMSHistPtr = new TH1F("tmp", "tmp", 100, 0, 20);
285 char fullfilename[128];
286 sprintf(fullfilename, "%s.root", filename);
287 TFile *file = TFile::Open(fullfilename, "recreate");
5c6503dc 288
b444d727 289 for(int x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 290 {
b444d727 291 for(int z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 292 {
b444d727 293 for(int gain = 0; gain < N_GAINS; gain++)
5c6503dc 294 {
295 fChannelHistogramsPtr[x][z][gain]->Write();
296 }
297 }
298 }
299 file->Close();
94594220 300
301 // char fullfilename[128];
302 char header[128];
303 int x = -1;
304 int z = -1;
305 int gain = -1;
306 float maxSigma = 0;
307 sprintf(fullfilename, "%s.txt", filename);
308 ofstream asciifile(fullfilename);
309 AliHLTPHOSMapper* fMapperPtr = new AliHLTPHOSMapper();
310 //CRAP need to find module number
311 for(int module = 0; module < N_MODULES; module++)
312 {
313 for(int rcu = 0; rcu < N_RCUS; rcu++)
314 {
315 for(int branch = 0; branch < N_BRANCHES; branch++)
316 {
317 for(int card = 0; card < N_FEECS; card++)
318 {
319 for(int chip = 0; chip < N_ALTROS+1; chip++)
320 {
321 if(chip==1)continue;
322 // sprintf(header, "Module:%d RCU:%d Branch:%d Card:%d Chip:%d", module-1, rcu, branch, card, chip);
323 if(module == 2)
324 {
325 sprintf(header, "Module:%d RCU:%d Branch:%d Card:%d Chip:%d", module-1, rcu, branch, card+1, chip);
326 asciifile << header << endl;
327 for(int channel = 0; channel < N_ALTROCHANNELS; channel++)
328 {
329
330 int hwAddress = ((branch << 11) | (card << 7) | (chip << 4) | channel);
331 int xoff = 0;
332 int zoff = 0;
9bf87c6f 333 if(rcu == 0 || rcu == 2) xoff = 1;
94594220 334 if(rcu == 2 || rcu == 3) zoff = 1;
335 z = fMapperPtr->fHw2geomapPtr[hwAddress].fZRow + zoff*N_ZROWS_RCU;
336 x = fMapperPtr->fHw2geomapPtr[hwAddress].fXCol + xoff*N_XCOLUMNS_RCU;
337 gain = fMapperPtr->fHw2geomapPtr[hwAddress].fGain;
338 if(x >63 || x < 0 || z > 55 || z < 0 || gain < 0 || gain >1)
339 {
340 // cout << "index out of range!" << " x = " << x << " z = " << z << " gain = " << gain << " xoff = " << xoff << " zoff = " << zoff << endl;
d8122453 341 continue;
94594220 342 }
343 //fChannelHistogramsPtr[x][z][gain]->Fit("gaus", "0");
344 // asciifile << (fChannelHistogramsPtr[x][z][gain]->GetFunction("gaus"))->GetParameter(1) << endl;
345 asciifile << (int)fChannelHistogramsPtr[x][z][gain]->GetMean()<< endl;
346 //asciifile << (int)(fAccumulatedBaselines[x][z][gain][0]) << endl;
347 if(fChannelHistogramsPtr[x][z][gain]->GetRMS() > maxSigma) maxSigma = fChannelHistogramsPtr[x][z][gain]->GetRMS();
348 tmpRMSHistPtr->Fill(fChannelHistogramsPtr[x][z][gain]->GetRMS());
349 }
350 }
351 else
352 {
353 // asciifile << 0 << endl;
354 maxSigma = 0;
355 }
356 }
357 }
358 }
359 }
360 }
361 asciifile << tmpRMSHistPtr->GetMean()*3;
5c6503dc 362}
363
364
365void
366AliHLTPHOSBaselineAnalyzer::WriteRMSHistogram(const Char_t* filename)
367{
2374af72 368 //see headerfile for documentation
5c6503dc 369 TFile *file = TFile::Open(filename, "recreate");
370 fRMSHistogramPtr->Write();
371 fRMSMapHighGainHistogramPtr->Write();
372 fRMSMapLowGainHistogramPtr->Write();
5c6503dc 373 fFixedRMSHistogramPtr->Write();
374 fFixedRMSMapHighGainHistogramPtr->Write();
375 fFixedRMSMapLowGainHistogramPtr->Write();
5c6503dc 376 file->Close();
377}
378
8efbf5fe 379
5c6503dc 380void
381AliHLTPHOSBaselineAnalyzer::ResetBaselines()
382{
2374af72 383 //see headerfile for documentation
b444d727 384 for(int x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 385 {
b444d727 386 for(int z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 387 {
b444d727 388 for(int gain = 0; gain < N_GAINS; gain++)
5c6503dc 389 {
390 fBaselines[x][z][gain] = 0;
391 }
392 }
393 }
394}
395
8efbf5fe 396
5c6503dc 397void
398AliHLTPHOSBaselineAnalyzer::ResetChannelCount()
399{
2374af72 400 //see headerfile for documentation
5c6503dc 401 fChannelCount = 0;
402}
403
404void
405AliHLTPHOSBaselineAnalyzer::ResetAccumulatedBaselines()
406{
b444d727 407 for(int x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 408 {
b444d727 409 for(int z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 410 {
b444d727 411 for(int gain = 0; gain < N_GAINS; gain++)
5c6503dc 412 {
413 fAccumulatedBaselines[x][z][gain][0] = 0;
414 fAccumulatedBaselines[x][z][gain][1] = 0;
415 }
416 }
417 }
418}
419
420void
421AliHLTPHOSBaselineAnalyzer::SetMaxCrazyDifference(Int_t diff)
422{
2374af72 423 //see headerfile for documentation
5c6503dc 424 fMaxCrazyDifference = diff;
425 fSanityInspector->SetMaxDifference(diff);
426}
427
428
429
430/*
431void
432AliHLTPHOSBaselineAnalyzer::SetChannelsHistograms(TH1F *channelLowGainHistArray[N_XCOLUMNS_MOD][N_ZROWS_MOD], TH1F *channelHighGainHistArray[N_XCOLUMNS_MOD][N_ZROWS_MOD])
433{
b444d727 434 for(int x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 435 {
b444d727 436 for(int z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 437 {
b444d727 438 for(int gain = 0; gain < N_GAINS; gain++)
5c6503dc 439 {
440 fChannelLowGainHistogramsPtr[x][z][gain] = channelLowGainHistArray[x][z][gain];
441 fChannelHighGainHistogramsPtr[x][z][gain] = channelHighGainHistArray[x][z][gain];
442 }
443 }
444 }
445}
446*/