]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCCalibPedestal.cxx
Forgotten commit - removing obsolete class
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibPedestal.cxx
CommitLineData
8bc7e885 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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
16
8bc7e885 17/* $Id$ */
18
8bc7e885 19
20//Root includes
8bc7e885 21#include <TH1F.h>
8bc7e885 22#include <TH2F.h>
8bc7e885 23#include <TString.h>
8bc7e885 24#include <TMath.h>
25#include <TF1.h>
26#include <TRandom.h>
8bc7e885 27#include <TDirectory.h>
8bc7e885 28#include <TFile.h>
ac940b58 29#include <TMap.h>
8bc7e885 30//AliRoot includes
31#include "AliRawReader.h"
32#include "AliRawReaderRoot.h"
bc331d5b 33#include "AliRawReaderDate.h"
8bc7e885 34#include "AliTPCRawStream.h"
35#include "AliTPCCalROC.h"
8bc7e885 36#include "AliTPCROC.h"
8bc7e885 37#include "AliMathBase.h"
8bc7e885 38#include "TTreeStream.h"
4958b652 39#include "AliTPCRawStreamFast.h"
8bc7e885 40
bc331d5b 41//date
42#include "event.h"
43
44//header file
45#include "AliTPCCalibPedestal.h"
8bc7e885 46
47
aa983e4f 48///////////////////////////////////////////////////////////////////////////////////////
49// Implementation of the TPC pedestal and noise calibration
50//
51// Origin: Jens Wiechula, Marian Ivanov J.Wiechula@gsi.de, Marian.Ivanov@cern.ch
52//
53//
54// *************************************************************************************
55// * Class Description *
56// *************************************************************************************
57//
58// Working principle:
59// ------------------
60// Raw pedestal data is processed by calling one of the ProcessEvent(...) functions
61// (see below). These in the end call the Update(...) function, where the data is filled
62// into histograms.
63//
64// For each ROC one TH2F histo (ROC channel vs. ADC channel) is created when
65// it is filled for the first time (GetHistoPedestal(ROC,kTRUE)). All histos are stored in the
66// TObjArray fHistoPedestalArray.
67//
68// For a fast filling of the histogram the corresponding bin number of the channel and ADC channel
69// is computed by hand and the histogram array is accessed directly via its pointer.
70// ATTENTION: Doing so the the entry counter of the histogram is not increased
71// this means that e.g. the colz draw option gives an empty plot unless
72// calling 'histo->SetEntries(1)' before drawing.
73//
74// After accumulating the desired statistics the Analyse() function has to be called.
75// Whithin this function the pedestal and noise values are calculated for each pad, using
76// the fast gaus fit function AliMathBase::FitGaus(...), and the calibration
77// storage classes (AliTPCCalROC) are filled for each ROC.
78// The calibration information is stored in the TObjArrays fCalRocArrayPedestal and fCalRocArrayRMS;
79//
80//
81//
82// User interface for filling data:
83// --------------------------------
84//
85// To Fill information one of the following functions can be used:
86//
87// Bool_t ProcessEvent(eventHeaderStruct *event);
88// - process Date event
89// - use AliTPCRawReaderDate and call ProcessEvent(AliRawReader *rawReader)
90//
91// Bool_t ProcessEvent(AliRawReader *rawReader);
92// - process AliRawReader event
93// - use AliTPCRawStream to loop over data and call ProcessEvent(AliTPCRawStream *rawStream)
94//
95// Bool_t ProcessEvent(AliTPCRawStream *rawStream);
96// - process event from AliTPCRawStream
97// - call Update function for signal filling
98//
99// Int_t Update(const Int_t isector, const Int_t iRow, const Int_t
100// iPad, const Int_t iTimeBin, const Float_t signal);
101// - directly fill signal information (sector, row, pad, time bin, pad)
102// to the reference histograms
103//
104// It is also possible to merge two independently taken calibrations using the function
105//
106// void Merge(AliTPCCalibPedestal *ped)
107// - copy histograms in 'ped' if the do not exist in this instance
108// - Add histograms in 'ped' to the histograms in this instance if the allready exist
109// - After merging call Analyse again!
110//
111//
112//
113// -- example: filling data using root raw data:
114// void fillPedestal(Char_t *filename)
115// {
116// rawReader = new AliRawReaderRoot(fileName);
117// if ( !rawReader ) return;
118// AliTPCCalibPedestal *calib = new AliTPCCalibPedestal;
119// while (rawReader->NextEvent()){
120// calib->ProcessEvent(rawReader);
121// }
122// calib->Analyse();
123// calib->DumpToFile("PedestalData.root");
124// delete rawReader;
125// delete calib;
126// }
127//
128//
129// What kind of information is stored and how to retrieve them:
130// ------------------------------------------------------------
131//
132// - Accessing the 'Reference Histograms' (pedestal distribution histograms):
133//
134// TH2F *GetHistoPedestal(Int_t sector);
135//
136// - Accessing the calibration storage objects:
137//
1542c62d 138// AliTPCCalROC *GetCalRocPedestal(Int_t sector); - for the pedestal values, mean from gaus fit
139// AliTPCCalROC *GetCalRocSigma(Int_t sector); - for the Noise values, sigma from guas fit
140// AliTPCCalROC *GetCalRocMean(Int_t sector); - for the pedestal values, truncated mean
141// AliTPCCalROC *GetCalRocRMS(Int_t sector); - for the Noise values, rms from truncated mean
aa983e4f 142//
143// example for visualisation:
144// if the file "PedestalData.root" was created using the above example one could do the following:
145//
146// TFile filePedestal("PedestalData.root")
147// AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)filePedestal->Get("AliTPCCalibPedestal");
148// ped->GetCalRocPedestal(0)->Draw("colz");
149// ped->GetCalRocRMS(0)->Draw("colz");
150//
151// or use the AliTPCCalPad functionality:
152// AliTPCCalPad padPedestal(ped->GetCalPadPedestal());
153// AliTPCCalPad padNoise(ped->GetCalPadRMS());
154// padPedestal->MakeHisto2D()->Draw("colz"); //Draw A-Side Pedestal Information
155// padNoise->MakeHisto2D()->Draw("colz"); //Draw A-Side Noise Information
156//
157/*
158 example: fill pedestal with gausschen noise
159 AliTPCCalibPedestal ped;
160 ped.TestEvent();
161 ped.Analyse();
162 //Draw output;
163 TCanvas* c1 = new TCanvas;
164 c1->Divide(1,2);
165 c1->cd(1);
166 ped.GetHistoPedestal(0)->SetEntries(1); //needed in order for colz to work, reason: fast filling does not increase the entries counter
167 ped.GetHistoPedestal(0)->Draw("colz");
168 c1->cd(2);
169 ped.GetHistoPedestal(36)->SetEntries(1); //needed in order for colz to work, reason: fast filling does not increase the entries counter
170 ped.GetHistoPedestal(36)->Draw("colz");
171 TCanvas* c2 = new TCanvas;
172 c2->Divide(2,2);
173 c2->cd(1);
174 ped.GetCalRocPedestal(0)->Draw("colz");
175 c2->cd(2);
176 ped.GetCalRocRMS(0)->Draw("colz");
177 c2->cd(3);
178 ped.GetCalRocPedestal(36)->Draw("colz");
179 c2->cd(4);
180 ped.GetCalRocRMS(36)->Draw("colz");
aa983e4f 181*/
bdf99a93 182//
183// Time dependent pedestals:
184//
185// If wished there is the possibility to calculate for each channel and time bin
186// the mean pedestal [pedestals(t)]. This is done by
187//
188// 1) setting SetTimeAnalysis(kTRUE),
189// 2) processing the data by looping over the events using ProcessEvent(..)
190// 3) calling the Analyse() and AnalyseTime(nevents) functions (providing nevents)
191// 4) getting the pedestals(t) using TArrayF **timePed = calibPedestal.GetTimePedestals();
192// 5) looking at values using timePed[row][pad].At(timebin)
193//
194// This functionality is intended to be used on an LDC bu the detector algorithm
195// (TPCPEDESTALda) to generate a data set used for configuration of the pattern
196// memory for baseline subtraction in the ALTROs. Later the information should also
197// be stored as reference data.
198//
8bc7e885 199
200
aa983e4f 201ClassImp(AliTPCCalibPedestal)
8bc7e885 202
1542c62d 203AliTPCCalibPedestal::AliTPCCalibPedestal() :
880c3382 204 AliTPCCalibRawBase(),
8bc7e885 205 fAdcMin(1),
206 fAdcMax(100),
1542c62d 207 fAnaMeanDown(0.),
208 fAnaMeanUp(1.),
bdf99a93 209 fTimeAnalysis(kFALSE),
8bc7e885 210 fCalRocArrayPedestal(72),
1542c62d 211 fCalRocArraySigma(72),
bdf99a93 212 fHistoPedestalArray(72),
1542c62d 213 fTimeSignal(NULL),
214 fCalRocArrayMean(72),
215 fCalRocArrayRMS(72)
8bc7e885 216{
bdf99a93 217 //
218 // default constructor
219 //
880c3382 220 SetNameTitle("AliTPCCalibPedestal","AliTPCCalibPedestal");
221 fFirstTimeBin=60;
222 fLastTimeBin=1000;
8bc7e885 223}
bdf99a93 224
225
bc331d5b 226//_____________________________________________________________________
1542c62d 227AliTPCCalibPedestal::AliTPCCalibPedestal(const AliTPCCalibPedestal &ped) :
880c3382 228 AliTPCCalibRawBase(ped),
bc331d5b 229 fAdcMin(ped.GetAdcMin()),
230 fAdcMax(ped.GetAdcMax()),
1542c62d 231 fAnaMeanDown(ped.fAnaMeanDown),
232 fAnaMeanUp(ped.fAnaMeanUp),
bdf99a93 233 fTimeAnalysis(ped.fTimeAnalysis),
bc331d5b 234 fCalRocArrayPedestal(72),
1542c62d 235 fCalRocArraySigma(72),
bdf99a93 236 fHistoPedestalArray(72),
1542c62d 237 fTimeSignal(ped.fTimeSignal),
238 fCalRocArrayMean(72),
239 fCalRocArrayRMS(72)
bc331d5b 240{
bdf99a93 241 //
242 // copy constructor
243 //
244 for (Int_t iSec = 0; iSec < 72; ++iSec){
245 const AliTPCCalROC *calPed = (AliTPCCalROC*)ped.fCalRocArrayPedestal.UncheckedAt(iSec);
246 const AliTPCCalROC *calRMS = (AliTPCCalROC*)ped.fCalRocArrayRMS.UncheckedAt(iSec);
247 const TH2F *hPed = (TH2F*)ped.fHistoPedestalArray.UncheckedAt(iSec);
248
249 if ( calPed != 0x0 ) fCalRocArrayPedestal.AddAt(new AliTPCCalROC(*calPed), iSec);
250 if ( calRMS != 0x0 ) fCalRocArrayRMS.AddAt(new AliTPCCalROC(*calRMS), iSec);
251
252 if ( hPed != 0x0 ){
253 TH2F *hNew = new TH2F(*hPed);
254 hNew->SetDirectory(0);
255 fHistoPedestalArray.AddAt(hNew,iSec);
bc331d5b 256 }
bdf99a93 257 }
bc331d5b 258}
ac940b58 259AliTPCCalibPedestal::AliTPCCalibPedestal(const TMap *config):
880c3382 260 AliTPCCalibRawBase(),
ac940b58 261 fAdcMin(1),
262 fAdcMax(100),
263 fAnaMeanDown(0.),
264 fAnaMeanUp(1.),
265 fTimeAnalysis(kFALSE),
ac940b58 266 fCalRocArrayPedestal(72),
267 fCalRocArraySigma(72),
268 fHistoPedestalArray(72),
269 fTimeSignal(NULL),
270 fCalRocArrayMean(72),
271 fCalRocArrayRMS(72)
272{
273 //
274 // This constructor uses a TMap for setting some parametes
275 //
880c3382 276 SetNameTitle("AliTPCCalibPedestal","AliTPCCalibPedestal");
277 fFirstTimeBin=60;
278 fLastTimeBin=1000;
ac940b58 279 if (config->GetValue("FirstTimeBin")) fFirstTimeBin = ((TObjString*)config->GetValue("FirstTimeBin"))->GetString().Atoi();
280 if (config->GetValue("LastTimeBin")) fLastTimeBin = ((TObjString*)config->GetValue("LastTimeBin"))->GetString().Atoi();
281 if (config->GetValue("AdcMin")) fAdcMin = ((TObjString*)config->GetValue("AdcMin"))->GetString().Atoi();
282 if (config->GetValue("AdcMax")) fAdcMax = ((TObjString*)config->GetValue("AdcMax"))->GetString().Atoi();
283 if (config->GetValue("TimeAnalysis")) SetTimeAnalysis(((TObjString*)config->GetValue("TimeAnalysis"))->GetString().Atoi());
ac940b58 284}
bdf99a93 285
286
bc331d5b 287//_____________________________________________________________________
288AliTPCCalibPedestal& AliTPCCalibPedestal::operator = (const AliTPCCalibPedestal &source)
289{
290 //
291 // assignment operator
292 //
293 if (&source == this) return *this;
294 new (this) AliTPCCalibPedestal(source);
8bc7e885 295
bc331d5b 296 return *this;
297}
bdf99a93 298
299
8bc7e885 300//_____________________________________________________________________
1542c62d 301AliTPCCalibPedestal::~AliTPCCalibPedestal()
8bc7e885 302{
303 //
304 // destructor
305 //
8bc7e885 306
bdf99a93 307 fCalRocArrayPedestal.Delete();
308 fCalRocArrayRMS.Delete();
a480de15 309 fCalRocArraySigma.Delete();
bdf99a93 310 fHistoPedestalArray.Delete();
311
312 if ( fTimeSignal ) {
313 for (Int_t i = 0; i < 159; i++) {
314 delete [] fTimeSignal[i];
315 fTimeSignal[i] = 0;
316 }
317 delete [] fTimeSignal;
318 fTimeSignal = 0;
319 }
4958b652 320
321 // do not delete fMapping, because we do not own it.
322
bdf99a93 323}
324
325
326//_____________________________________________________________________
327void AliTPCCalibPedestal::SetTimeAnalysis(Bool_t time)
328{
329 //
330 // Use time dependent analysis: Pedestals are analysed as a function
331 // of the drift time. There is one mean value generated for each time
332 // bin and each channel. It can be used as reference data and for
333 // configuration of the ALTRO pattern memory for baseline subtraction.
334 //
335 // ATTENTION: Use only on LDC in TPCPEDESTALda! On a LDC we get data
336 // only from one sector. For the full TPC we would need a lot of
337 // memory (36*159*140*1024*4bytes = 3.3GB)!
338 //
339
340 fTimeAnalysis = time;
341
342 if ( !fTimeAnalysis ) return;
343
344 // prepare array for one sector (159*140*1024*4bytes = 92MB):
345 fTimeSignal = new TArrayF*[159];
346 for (Int_t i = 0; i < 159; i++) { // padrows
347 fTimeSignal[i] = new TArrayF[140];
348 for (Int_t j = 0; j < 140; j++) { // pads per row
349 fTimeSignal[i][j].Set(1024);
350 for (Int_t k = 0; k < 1024; k++) { // time bins per pad
351 fTimeSignal[i][j].AddAt(0., k);
352 }
353 }
354 }
aa983e4f 355}
bdf99a93 356
357
8bc7e885 358//_____________________________________________________________________
1542c62d 359Int_t AliTPCCalibPedestal::Update(const Int_t icsector,
bdf99a93 360 const Int_t icRow,
361 const Int_t icPad,
362 const Int_t icTimeBin,
363 const Float_t csignal)
8bc7e885 364{
bdf99a93 365 //
366 // Signal filling method
367 //
b401648b 368 if (icRow<0) return 0;
369 if (icPad<0) return 0;
370 if (icTimeBin<0) return 0;
371
bdf99a93 372 // Time dependent pedestals
373 if ( fTimeAnalysis ) {
374 if ( icsector < 36 ) // IROC
375 fTimeSignal[icRow][icPad].AddAt(fTimeSignal[icRow][icPad].At(icTimeBin)+csignal, icTimeBin);
376 else
377 fTimeSignal[icRow+63][icPad].AddAt(fTimeSignal[icRow+63][icPad].At(icTimeBin)+csignal, icTimeBin);
378 }
379 //return if we are out of the specified time bin or adc range
380 if ( (icTimeBin>fLastTimeBin) || (icTimeBin<fFirstTimeBin) ) return 0;
381 if ( ((Int_t)csignal>fAdcMax) || ((Int_t)csignal<fAdcMin) ) return 0;
8bc7e885 382
bdf99a93 383 Int_t iChannel = fROC->GetRowIndexes(icsector)[icRow]+icPad; // global pad position in sector
8bc7e885 384
4958b652 385 // fast filling method
bdf99a93 386 // Attention: the entry counter of the histogram is not increased
387 // this means that e.g. the colz draw option gives an empty plot
388 Int_t bin = (iChannel+1)*(fAdcMax-fAdcMin+2)+((Int_t)csignal-fAdcMin+1);
8bc7e885 389
bdf99a93 390 GetHistoPedestal(icsector,kTRUE)->GetArray()[bin]++;
8bc7e885 391
bdf99a93 392 return 0;
8bc7e885 393}
4958b652 394
395
bc331d5b 396//_____________________________________________________________________
1542c62d 397Bool_t AliTPCCalibPedestal::TestEvent()
8bc7e885 398{
399 //
400 // Test event loop
bc331d5b 401 // fill one oroc and one iroc with random gaus
8bc7e885 402 //
403
880c3382 404 gRandom->SetSeed(0);
405
406 for (UInt_t iSec=0; iSec<72; ++iSec){
407 if (iSec%36>0) continue;
408 for (UInt_t iRow=0; iRow < fROC->GetNRows(iSec); ++iRow){
409 for (UInt_t iPad=0; iPad < fROC->GetNPads(iSec,iRow); ++iPad){
410 for (UInt_t iTimeBin=0; iTimeBin<1024; ++iTimeBin){
411 Float_t signal=(Int_t)(iRow+3+gRandom->Gaus(0,.7));
412 if ( signal>0 )Update(iSec,iRow,iPad,iTimeBin,signal);
413 }
414 }
8bc7e885 415 }
880c3382 416 }
417 return kTRUE;
8bc7e885 418}
bdf99a93 419
420
8bc7e885 421//_____________________________________________________________________
1542c62d 422TH2F* AliTPCCalibPedestal::GetHisto(Int_t sector, TObjArray *arr,
4958b652 423 Int_t nbinsY, Float_t ymin, Float_t ymax,
a6e0ebfe 424 const Char_t *type, Bool_t force)
8bc7e885 425{
426 //
427 // return pointer to Q histogram
428 // if force is true create a new histogram if it doesn't exist allready
429 //
430 if ( !force || arr->UncheckedAt(sector) )
a3b590cf 431 return (TH2F*)arr->UncheckedAt(sector);
8bc7e885 432
433 // if we are forced and histogram doesn't yes exist create it
8bc7e885 434 // new histogram with Q calib information. One value for each pad!
a3b590cf 435 TH2F* hist = new TH2F(Form("hCalib%s%.2d",type,sector),
436 Form("%s calibration histogram sector %.2d;ADC channel;Channel (pad)",type,sector),
437 nbinsY, ymin, ymax,
438 fROC->GetNChannels(sector),0,fROC->GetNChannels(sector)
439 );
8bc7e885 440 hist->SetDirectory(0);
441 arr->AddAt(hist,sector);
442 return hist;
443}
bdf99a93 444
445
8bc7e885 446//_____________________________________________________________________
1542c62d 447TH2F* AliTPCCalibPedestal::GetHistoPedestal(Int_t sector, Bool_t force)
8bc7e885 448{
449 //
450 // return pointer to T0 histogram
451 // if force is true create a new histogram if it doesn't exist allready
452 //
453 TObjArray *arr = &fHistoPedestalArray;
454 return GetHisto(sector, arr, fAdcMax-fAdcMin, fAdcMin, fAdcMax, "Pedestal", force);
455}
bdf99a93 456
457
8bc7e885 458//_____________________________________________________________________
1542c62d 459AliTPCCalROC* AliTPCCalibPedestal::GetCalRoc(Int_t sector, TObjArray* arr, Bool_t force)
8bc7e885 460{
461 //
462 // return pointer to ROC Calibration
463 // if force is true create a new histogram if it doesn't exist allready
464 //
465 if ( !force || arr->UncheckedAt(sector) )
466 return (AliTPCCalROC*)arr->UncheckedAt(sector);
467
aa983e4f 468 // if we are forced and the histogram doesn't yet exist create it
8bc7e885 469
470 // new AliTPCCalROC for T0 information. One value for each pad!
471 AliTPCCalROC *croc = new AliTPCCalROC(sector);
8bc7e885 472 arr->AddAt(croc,sector);
473 return croc;
474}
bdf99a93 475
476
8bc7e885 477//_____________________________________________________________________
1542c62d 478AliTPCCalROC* AliTPCCalibPedestal::GetCalRocPedestal(Int_t sector, Bool_t force)
8bc7e885 479{
480 //
1542c62d 481 // return pointer to ROC with Pedestal data
8bc7e885 482 // if force is true create a new histogram if it doesn't exist allready
483 //
484 TObjArray *arr = &fCalRocArrayPedestal;
485 return GetCalRoc(sector, arr, force);
486}
bdf99a93 487
488
8bc7e885 489//_____________________________________________________________________
1542c62d 490AliTPCCalROC* AliTPCCalibPedestal::GetCalRocSigma(Int_t sector, Bool_t force)
8bc7e885 491{
492 //
1542c62d 493 // return pointer to ROC with signal witdth in sigma
8bc7e885 494 // if force is true create a new histogram if it doesn't exist allready
495 //
1542c62d 496 TObjArray *arr = &fCalRocArraySigma;
8bc7e885 497 return GetCalRoc(sector, arr, force);
498}
1542c62d 499//_____________________________________________________________________
500AliTPCCalROC* AliTPCCalibPedestal::GetCalRocMean(Int_t sector, Bool_t force)
501{
502 //
503 // return pointer to ROC with signal mean information
504 // if force is true create a new histogram if it doesn't exist allready
505 //
506 TObjArray *arr = &fCalRocArrayMean;
507 return GetCalRoc(sector, arr, force);
508}
509
510//_____________________________________________________________________
511AliTPCCalROC* AliTPCCalibPedestal::GetCalRocRMS(Int_t sector, Bool_t force)
512{
513 //
514 // return pointer to signal width ROC Calibration
515 // if force is true create a new histogram if it doesn't exist allready
516 //
517 TObjArray *arr = &fCalRocArrayRMS;
518 return GetCalRoc(sector, arr, force);
519}
bdf99a93 520
521
8bc7e885 522//_____________________________________________________________________
7442bceb 523void AliTPCCalibPedestal::Merge(AliTPCCalibPedestal * const ped)
aa983e4f 524{
bdf99a93 525 //
526 // Merge reference histograms of sig to the current AliTPCCalibSignal
527 //
78f17711 528 MergeBase(ped);
bdf99a93 529 // merge histograms
530 for (Int_t iSec=0; iSec<72; ++iSec){
531 TH2F *hRefPedMerge = ped->GetHistoPedestal(iSec);
7442bceb 532
bdf99a93 533 if ( hRefPedMerge ){
534 TDirectory *dir = hRefPedMerge->GetDirectory(); hRefPedMerge->SetDirectory(0);
535 TH2F *hRefPed = GetHistoPedestal(iSec);
536 if ( hRefPed ) hRefPed->Add(hRefPedMerge);
537 else {
7442bceb 538 TH2F *hist = new TH2F(*hRefPedMerge);
539 hist->SetDirectory(0);
540 fHistoPedestalArray.AddAt(hist, iSec);
bdf99a93 541 }
542 hRefPedMerge->SetDirectory(dir);
543 }
544 }
7442bceb 545
bdf99a93 546 // merge array
547 // ...
7442bceb 548
aa983e4f 549}
bdf99a93 550
7442bceb 551//_____________________________________________________________________
552Long64_t AliTPCCalibPedestal::Merge(TCollection * const list)
553{
554 //
555 // Merge all objects of this type in list
556 //
557
558 Long64_t nmerged=1;
559
560 TIter next(list);
561 AliTPCCalibPedestal *ce=0;
562 TObject *o=0;
563
564 while ( (o=next()) ){
565 ce=dynamic_cast<AliTPCCalibPedestal*>(o);
566 if (ce){
567 Merge(ce);
568 ++nmerged;
569 }
570 }
571
572 return nmerged;
573}
bdf99a93 574
aa983e4f 575//_____________________________________________________________________
1542c62d 576void AliTPCCalibPedestal::Analyse()
8bc7e885 577{
bdf99a93 578 //
579 // Calculate calibration constants
580 //
8bc7e885 581
bdf99a93 582 Int_t nbinsAdc = fAdcMax-fAdcMin;
8bc7e885 583
1542c62d 584 TVectorD param(4);
bdf99a93 585 TMatrixD dummy(3,3);
8bc7e885 586
1542c62d 587 TH1F *hChannel=new TH1F("hChannel","hChannel",nbinsAdc,fAdcMin,fAdcMax);
588
7442bceb 589 Float_t *arrayhP=0;
8bc7e885 590
bdf99a93 591 for (Int_t iSec=0; iSec<72; ++iSec){
592 TH2F *hP = GetHistoPedestal(iSec);
593 if ( !hP ) continue;
8bc7e885 594
bdf99a93 595 AliTPCCalROC *rocPedestal = GetCalRocPedestal(iSec,kTRUE);
1542c62d 596 AliTPCCalROC *rocSigma = GetCalRocSigma(iSec,kTRUE);
597 AliTPCCalROC *rocMean = GetCalRocMean(iSec,kTRUE);
bdf99a93 598 AliTPCCalROC *rocRMS = GetCalRocRMS(iSec,kTRUE);
8bc7e885 599
7442bceb 600 arrayhP = hP->GetArray();
bdf99a93 601 UInt_t nChannels = fROC->GetNChannels(iSec);
8bc7e885 602
bdf99a93 603 for (UInt_t iChannel=0; iChannel<nChannels; ++iChannel){
604 Int_t offset = (nbinsAdc+2)*(iChannel+1)+1;
1542c62d 605 //calculate mean and sigma using a gaus fit
9e359afd 606 //Double_t ret =
7442bceb 607 AliMathBase::FitGaus(arrayhP+offset,nbinsAdc,fAdcMin,fAdcMax,&param,&dummy);
bdf99a93 608 // if the fitting failed set noise and pedestal to 0
1542c62d 609 // is now done in AliMathBase::FitGaus !
610// if ( ret == -4 ) {
611// param[1]=0;
612// param[2]=0;
613// }
ac940b58 614 if ( param[1]<fAdcMin || param[1]>fAdcMax ){
615 param[1]=0;
616 param[2]=0;
617 }
bdf99a93 618 rocPedestal->SetValue(iChannel,param[1]);
1542c62d 619 rocSigma->SetValue(iChannel,param[2]);
620 //calculate mean and RMS using a truncated means
7442bceb 621 hChannel->Set(nbinsAdc+2,arrayhP+offset-1);
1542c62d 622 hChannel->SetEntries(param[3]);
623 param[1]=0;
624 param[2]=0;
625 if ( param[3]>0 ) AliMathBase::TruncatedMean(hChannel,&param,fAnaMeanDown,fAnaMeanUp);
626 rocMean->SetValue(iChannel,param[1]);
bdf99a93 627 rocRMS->SetValue(iChannel,param[2]);
628 }
629 }
1542c62d 630 delete hChannel;
bdf99a93 631}
8bc7e885 632
bdf99a93 633
634//_____________________________________________________________________
635void AliTPCCalibPedestal::AnalyseTime(Int_t nevents)
636{
637 //
638 // Calculate for each channel and time bin the mean pedestal. This
639 // is used on LDC by TPCPEDESTALda to generate data used for configuration
640 // of the pattern memory for baseline subtraction in the ALTROs.
641 //
642
643 if ( nevents <= 0 ) return;
644 if ( fTimeAnalysis ) {
645 for (Int_t i = 0; i < 159; i++) { // padrows
646 for (Int_t j = 0; j < 140; j++) { // pads per row
647 for (Int_t k = 0; k < 1024; k++) { // time bins per pad
648 fTimeSignal[i][j].AddAt(fTimeSignal[i][j].At(k)/(Float_t)nevents, k);
8bc7e885 649 }
bdf99a93 650 }
8bc7e885 651 }
bdf99a93 652 }
8bc7e885 653}