]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCdataQA.cxx
macros for reconstruction for both cases: cosmic and PDC08
[u/mrichter/AliRoot.git] / TPC / AliTPCdataQA.cxx
CommitLineData
0ffacf98 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
17/* $Id$ */
18
19
f11b3071 20// stl includes
21#include <iostream>
22
23using namespace std;
24
0ffacf98 25//Root includes
26#include <TH1F.h>
27#include <TH2F.h>
28#include <TString.h>
29#include <TMath.h>
30#include <TF1.h>
31#include <TRandom.h>
32#include <TDirectory.h>
33#include <TFile.h>
34//AliRoot includes
35#include "AliRawReader.h"
36#include "AliRawReaderRoot.h"
37#include "AliRawReaderDate.h"
38#include "AliTPCRawStream.h"
39#include "AliTPCCalROC.h"
40#include "AliTPCROC.h"
41#include "AliMathBase.h"
42#include "TTreeStream.h"
43#include "AliTPCRawStreamFast.h"
44
45//date
46#include "event.h"
47#include "AliTPCCalPad.h"
258cd111 48#include "AliTPCPreprocessorOnline.h"
0ffacf98 49
50//header file
51#include "AliTPCdataQA.h"
52
0ffacf98 53ClassImp(AliTPCdataQA)
54
336156cc 55AliTPCdataQA::AliTPCdataQA() : /*FOLD00*/
56 TH1F("TPCRAW","TPCRAW",100,0,100),
0ffacf98 57 fFirstTimeBin(60),
58 fLastTimeBin(1000),
59 fAdcMin(1),
60 fAdcMax(100),
61 fOldRCUformat(kTRUE),
62 fROC(AliTPCROC::Instance()),
63 fMapping(NULL),
f11b3071 64 fPedestal(0),
65 fNoise(0),
0ffacf98 66 fMaxCharge(0),
f11b3071 67 fMeanCharge(0),
68 fNoThreshold(0),
0ffacf98 69 fOverThreshold0(0),
70 fOverThreshold5(0),
71 fOverThreshold10(0),
72 fOverThreshold20(0),
73 fOverThreshold30(0),
74 fEventCounter(0)
75{
76 //
77 // default constructor
78 //
f11b3071 79
80 fSectorLast = -1;
81 fRowLast = 0;
82 fPadLast = 0;
83 fTimeBinLast = 0;
84 fSignalLast = 0;
85 fNAboveThreshold = 0;
0ffacf98 86}
87
88
89//_____________________________________________________________________
90AliTPCdataQA::AliTPCdataQA(const AliTPCdataQA &ped) : /*FOLD00*/
336156cc 91 TH1F(ped),
0ffacf98 92 fFirstTimeBin(ped.GetFirstTimeBin()),
93 fLastTimeBin(ped.GetLastTimeBin()),
94 fAdcMin(ped.GetAdcMin()),
95 fAdcMax(ped.GetAdcMax()),
96 fOldRCUformat(ped.fOldRCUformat),
97 fROC(AliTPCROC::Instance()),
98 fMapping(NULL)
99{
100 //
101 // copy constructor
102 //
103
104}
105
106
107//_____________________________________________________________________
108AliTPCdataQA& AliTPCdataQA::operator = (const AliTPCdataQA &source)
109{
110 //
111 // assignment operator
112 //
113 if (&source == this) return *this;
114 new (this) AliTPCdataQA(source);
115
116 return *this;
117}
118
119
120//_____________________________________________________________________
121AliTPCdataQA::~AliTPCdataQA() /*FOLD00*/
122{
123 //
124 // destructor
125 //
126
127 // do not delete fMapping, because we do not own it.
128
129}
130
131
132
133
134//_____________________________________________________________________
135Bool_t AliTPCdataQA::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
136{
137 //
138 // Event Processing loop - AliTPCRawStream
139 //
140 Bool_t withInput = kFALSE;
141
142 while ( rawStreamFast->NextDDL() ){
143 while ( rawStreamFast->NextChannel() ){
144 Int_t isector = rawStreamFast->GetSector(); // current sector
145 Int_t iRow = rawStreamFast->GetRow(); // current row
146 Int_t iPad = rawStreamFast->GetPad(); // current pad
0ffacf98 147
148 while ( rawStreamFast->NextBunch() ){
f11b3071 149 Int_t startTbin = (Int_t)rawStreamFast->GetStartTimeBin();
150 Int_t endTbin = (Int_t)rawStreamFast->GetEndTimeBin();
151
0ffacf98 152 for (Int_t iTimeBin = startTbin; iTimeBin < endTbin; iTimeBin++){
153 Float_t signal=(Float_t)rawStreamFast->GetSignals()[iTimeBin-startTbin];
154 Update(isector,iRow,iPad,iTimeBin+1,signal);
155 withInput = kTRUE;
156 }
157 }
158 }
159 }
160
161 return withInput;
162}
163//_____________________________________________________________________
164Bool_t AliTPCdataQA::ProcessEventFast(AliRawReader *rawReader)
165{
166 //
167 // Event processing loop - AliRawReader
168 //
f11b3071 169 fSectorLast = -1;
0ffacf98 170 AliTPCRawStreamFast *rawStreamFast = new AliTPCRawStreamFast(rawReader, (AliAltroMapping**)fMapping);
171 Bool_t res=ProcessEventFast(rawStreamFast);
c75bf2f1 172 if(res)
173 fEventCounter++; // only increment event counter if there is TPC data
174 // otherwise Analyse (called in QA) fails
175
0ffacf98 176 delete rawStreamFast;
177 return res;
178}
179
180//_____________________________________________________________________
181Bool_t AliTPCdataQA::ProcessEvent(AliTPCRawStream *rawStream)
182{
183 //
184 // Event Processing loop - AliTPCRawStream
185 //
186
187 rawStream->SetOldRCUFormat(fOldRCUformat);
188
189 Bool_t withInput = kFALSE;
190
191 while (rawStream->Next()) {
192
193 Int_t iSector = rawStream->GetSector(); // current ROC
194 Int_t iRow = rawStream->GetRow(); // current row
195 Int_t iPad = rawStream->GetPad(); // current pad
196 Int_t iTimeBin = rawStream->GetTime(); // current time bin
197 Float_t signal = rawStream->GetSignal(); // current ADC signal
198
199 Update(iSector,iRow,iPad,iTimeBin,signal);
200 withInput = kTRUE;
201 }
202
203 return withInput;
204}
205
206
207//_____________________________________________________________________
208Bool_t AliTPCdataQA::ProcessEvent(AliRawReader *rawReader)
209{
210 //
211 // Event processing loop - AliRawReader
212 //
213
214 // if fMapping is NULL the rawstream will crate its own mapping
f11b3071 215 fSectorLast = -1;
0ffacf98 216 AliTPCRawStream rawStream(rawReader, (AliAltroMapping**)fMapping);
217 rawReader->Select("TPC");
c75bf2f1 218 Bool_t res = ProcessEvent(&rawStream);
219
220 if(res)
221 fEventCounter++; // only increment event counter if there is TPC data
222 // otherwise Analyse (called in QA) fails
223 return res;
0ffacf98 224}
225
226
227//_____________________________________________________________________
228Bool_t AliTPCdataQA::ProcessEvent(eventHeaderStruct *event)
229{
230 //
231 // process date event
232 //
233
234 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
235 Bool_t result=ProcessEvent(rawReader);
236 delete rawReader;
237 return result;
238}
239
240
241
242//_____________________________________________________________________
243void AliTPCdataQA::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
244{
245 //
246 // Write class to file
247 //
248
249 TString sDir(dir);
250 TString option;
251
252 if ( append )
253 option = "update";
254 else
255 option = "recreate";
256
257 TDirectory *backup = gDirectory;
258 TFile f(filename,option.Data());
259 f.cd();
260 if ( !sDir.IsNull() ){
261 f.mkdir(sDir.Data());
262 f.cd(sDir);
263 }
264 this->Write();
265 f.Close();
266
267 if ( backup ) backup->cd();
268}
269
270
271//_____________________________________________________________________
272Int_t AliTPCdataQA::Update(const Int_t icsector, /*FOLD00*/
273 const Int_t icRow,
274 const Int_t icPad,
275 const Int_t icTimeBin,
276 const Float_t csignal)
277{
278 //
279 // Signal filling method
280 //
281 if (icTimeBin<fFirstTimeBin) return 0;
282 if (icTimeBin>fLastTimeBin) return 0;
f11b3071 283
0ffacf98 284 if (!fMaxCharge) fMaxCharge = new AliTPCCalPad("MaxCharge","MaxCharge");
f11b3071 285 if (!fMeanCharge) fMeanCharge = new AliTPCCalPad("MeanCharge","MeanCharge");
286 if (!fNoThreshold) fNoThreshold = new AliTPCCalPad("NoThreshold","NoThreshold");
0ffacf98 287 if (!fOverThreshold0) fOverThreshold0 = new AliTPCCalPad("OverThreshold0","OverThreshold0");
288 if (!fOverThreshold5) fOverThreshold5 = new AliTPCCalPad("OverThreshold5","OverThreshold5");
289 if (!fOverThreshold10) fOverThreshold10 = new AliTPCCalPad("OverThreshold10","OverThreshold10");
290 if (!fOverThreshold20) fOverThreshold20 = new AliTPCCalPad("OverThreshold20","OverThreshold20");
291 if (!fOverThreshold30) fOverThreshold30 = new AliTPCCalPad("OverThreshold30","OverThreshold30");
292 //
f11b3071 293
294 Int_t signal = Int_t(csignal);
295
296 // if pedestal calibrations are loaded subtract pedestals
297 if(fPedestal) {
298
299 Int_t pedestal = Int_t(fPedestal->GetCalROC(icsector)->GetValue(icRow, icPad));
300 if(pedestal<10 || pedestal>90)
301 return 0;
302 signal -= pedestal;
0ffacf98 303 }
f11b3071 304
305
306 if (signal >= 0) {
307
308 Float_t count = fNoThreshold->GetCalROC(icsector)->GetValue(icRow, icPad);
309 fNoThreshold->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
310 }
311
312 // Require at least 3 ADC channels
313 if (signal < 3)
314 return 0;
315
316 // if noise calibrations are loaded require at least 3*sigmaNoise
317 if(fNoise) {
0ffacf98 318
f11b3071 319 Float_t noise = fNoise->GetCalROC(icsector)->GetValue(icRow, icPad);
320
321 if(signal<noise*3)
322 return 0;
323 }
324 //
325 // this signal is ok - now see if the previous signal was connected
326 // this is a bit ugly since the standard decoder goes down in time bins
327 // (10, 9, 8..) while the fast HLT decoder goes up in time bins (1, 2, 3..)
0ffacf98 328 //
f11b3071 329 if(fSectorLast==icsector && fRowLast==icRow && fPadLast==icPad &&
330 fTimeBinLast==icTimeBin+1 || fTimeBinLast==icTimeBin-1)
331 fNAboveThreshold++;
332 else
333 fNAboveThreshold = 1;
334
335 if(fNAboveThreshold==2) {
336
337 //
338 // This is the only special case, because before we did not know if we
339 // should store the information
340 //
341 UpdateSignalHistograms(fSectorLast, fRowLast, fPadLast, fTimeBinLast,
342 fSignalLast);
343 }
344
345 // keep the information for the next signal
346 fSectorLast = icsector;
347 fRowLast = icRow;
348 fPadLast = icPad;
349 fTimeBinLast = icTimeBin;
350 fSignalLast = signal;
351
352 if(fNAboveThreshold==1) // we don't know if this information should be stored
353 return 1;
354
355 UpdateSignalHistograms(fSectorLast, fRowLast, fPadLast, fTimeBinLast,
356 fSignalLast);
357
358 return 1;
359}
360//_____________________________________________________________________
361void AliTPCdataQA::UpdateSignalHistograms(const Int_t icsector, /*FOLD00*/
362 const Int_t icRow,
363 const Int_t icPad,
364 const Int_t icTimeBin,
365 const Float_t signal)
366{
367 //
368 // Signal filling method
369 //
370
371 {
372 Float_t charge = fMeanCharge->GetCalROC(icsector)->GetValue(icRow, icPad);
373 fMeanCharge->GetCalROC(icsector)->SetValue(icRow, icPad, charge + signal);
374 }
375
376 if (signal>fMaxCharge->GetCalROC(icsector)->GetValue(icRow, icPad)){
377 fMaxCharge->GetCalROC(icsector)->SetValue(icRow, icPad,signal);
378 }
379
380 if (signal>0){
381 Float_t count = fOverThreshold0->GetCalROC(icsector)->GetValue(icRow, icPad);
0ffacf98 382 fOverThreshold0->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
383 };
384 //
f11b3071 385 if (signal>5){
386 Float_t count = fOverThreshold5->GetCalROC(icsector)->GetValue(icRow, icPad);
0ffacf98 387 fOverThreshold5->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
388 };
f11b3071 389 if (signal>10){
390 Float_t count = fOverThreshold10->GetCalROC(icsector)->GetValue(icRow, icPad);
0ffacf98 391 fOverThreshold10->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
392 };
f11b3071 393 if (signal>20){
394 Float_t count = fOverThreshold20->GetCalROC(icsector)->GetValue(icRow, icPad);
0ffacf98 395 fOverThreshold20->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
396 };
f11b3071 397 if (signal>30){
398 Float_t count = fOverThreshold30->GetCalROC(icsector)->GetValue(icRow, icPad);
0ffacf98 399 fOverThreshold30->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
f11b3071 400 };
0ffacf98 401}
11ccf1c1 402
f11b3071 403//_____________________________________________________________________
404void AliTPCdataQA::Analyse()
405{
11ccf1c1 406 //
f11b3071 407 // Calculate calibration constants
11ccf1c1 408 //
f11b3071 409
410 cout << "Analyse called" << endl;
411
412 if(fEventCounter==0) {
413
414 cout << "EventCounter == 0, Cannot analyse" << endl;
415 return;
416 }
417
418 Int_t nTimeBins = fLastTimeBin - fFirstTimeBin +1;
419
c75bf2f1 420 cout << "EventCounter: " << fEventCounter << endl
f11b3071 421 << "TimeBins: " << nTimeBins << endl;
422
238eb338 423 if (fMeanCharge && fNoThreshold) fMeanCharge->Divide(fNoThreshold);
f11b3071 424
425 Float_t normalization = 1.0 / Float_t(fEventCounter * nTimeBins);
238eb338 426 if (fNoThreshold) fNoThreshold->Multiply(normalization);
427 if (fOverThreshold0) fOverThreshold0->Multiply(normalization);
428 if (fOverThreshold5) fOverThreshold5->Multiply(normalization);
429 if (fOverThreshold10) fOverThreshold10->Multiply(normalization);
430 if (fOverThreshold20) fOverThreshold20->Multiply(normalization);
431 if (fOverThreshold30) fOverThreshold30->Multiply(normalization);
11ccf1c1 432}
258cd111 433
434
435void AliTPCdataQA::MakeTree(const char *fname){
436 //
437 // Export result to the tree -located in the file
438 // This file can be analyzed using AliTPCCalibViewer
439 //
440 AliTPCdataQA *ped = this;
441 AliTPCPreprocessorOnline preprocesor;
442 if (ped->GetMaxCharge()) preprocesor.AddComponent(ped->GetMaxCharge());
443 if (ped->GetMeanCharge()) preprocesor.AddComponent(ped->GetMeanCharge());
444 if (ped->GetOverThreshold0()) preprocesor.AddComponent(ped->GetOverThreshold0());
445 if (ped->GetOverThreshold5()) preprocesor.AddComponent(ped->GetOverThreshold5());
446 if (ped->GetOverThreshold10()) preprocesor.AddComponent(ped->GetOverThreshold10());
447 if (ped->GetOverThreshold20()) preprocesor.AddComponent(ped->GetOverThreshold20());
448 if (ped->GetOverThreshold30()) preprocesor.AddComponent(ped->GetOverThreshold30());
449 preprocesor.DumpToFile(fname);
450}