1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
32 #include <TDirectory.h>
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"
47 #include "AliTPCCalPad.h"
48 #include "AliTPCPreprocessorOnline.h"
51 #include "AliTPCdataQA.h"
53 ClassImp(AliTPCdataQA)
55 AliTPCdataQA::AliTPCdataQA() : /*FOLD00*/
56 TH1F("TPCRAW","TPCRAW",100,0,100),
63 fROC(AliTPCROC::Instance()),
78 // default constructor
90 //_____________________________________________________________________
91 AliTPCdataQA::AliTPCdataQA(const AliTPCdataQA &ped) : /*FOLD00*/
93 fFirstTimeBin(ped.GetFirstTimeBin()),
94 fLastTimeBin(ped.GetLastTimeBin()),
95 fMaxTime(ped.fMaxTime),
96 fAdcMin(ped.GetAdcMin()),
97 fAdcMax(ped.GetAdcMax()),
98 fOldRCUformat(ped.fOldRCUformat),
99 fROC(AliTPCROC::Instance()),
109 //_____________________________________________________________________
110 AliTPCdataQA& AliTPCdataQA::operator = (const AliTPCdataQA &source)
113 // assignment operator
115 if (&source == this) return *this;
116 new (this) AliTPCdataQA(source);
122 //_____________________________________________________________________
123 AliTPCdataQA::~AliTPCdataQA() /*FOLD00*/
129 // do not delete fMapping, because we do not own it.
136 //_____________________________________________________________________
137 Bool_t AliTPCdataQA::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
140 // Event Processing loop - AliTPCRawStream
142 Bool_t withInput = kFALSE;
144 while ( rawStreamFast->NextDDL() ){
145 while ( rawStreamFast->NextChannel() ){
146 Int_t isector = rawStreamFast->GetSector(); // current sector
147 Int_t iRow = rawStreamFast->GetRow(); // current row
148 Int_t iPad = rawStreamFast->GetPad(); // current pad
150 while ( rawStreamFast->NextBunch() ){
151 Int_t startTbin = (Int_t)rawStreamFast->GetStartTimeBin();
152 Int_t endTbin = (Int_t)rawStreamFast->GetEndTimeBin();
154 for (Int_t iTimeBin = startTbin; iTimeBin < endTbin; iTimeBin++){
155 Float_t signal=(Float_t)rawStreamFast->GetSignals()[iTimeBin-startTbin];
156 Update(isector,iRow,iPad,iTimeBin+1,signal);
165 //_____________________________________________________________________
166 Bool_t AliTPCdataQA::ProcessEventFast(AliRawReader *rawReader)
169 // Event processing loop - AliRawReader
172 AliTPCRawStreamFast *rawStreamFast = new AliTPCRawStreamFast(rawReader, (AliAltroMapping**)fMapping);
173 Bool_t res=ProcessEventFast(rawStreamFast);
175 fEventCounter++; // only increment event counter if there is TPC data
176 // otherwise Analyse (called in QA) fails
178 delete rawStreamFast;
182 //_____________________________________________________________________
183 Bool_t AliTPCdataQA::ProcessEvent(AliTPCRawStream *rawStream)
186 // Event Processing loop - AliTPCRawStream
189 rawStream->SetOldRCUFormat(fOldRCUformat);
191 Bool_t withInput = kFALSE;
193 while (rawStream->Next()) {
195 Int_t iSector = rawStream->GetSector(); // current ROC
196 Int_t iRow = rawStream->GetRow(); // current row
197 Int_t iPad = rawStream->GetPad(); // current pad
198 Int_t iTimeBin = rawStream->GetTime(); // current time bin
199 Float_t signal = rawStream->GetSignal(); // current ADC signal
201 Update(iSector,iRow,iPad,iTimeBin,signal);
209 //_____________________________________________________________________
210 Bool_t AliTPCdataQA::ProcessEvent(AliRawReader *rawReader)
213 // Event processing loop - AliRawReader
216 // if fMapping is NULL the rawstream will crate its own mapping
218 AliTPCRawStream rawStream(rawReader, (AliAltroMapping**)fMapping);
219 rawReader->Select("TPC");
220 Bool_t res = ProcessEvent(&rawStream);
223 fEventCounter++; // only increment event counter if there is TPC data
224 // otherwise Analyse (called in QA) fails
229 //_____________________________________________________________________
230 Bool_t AliTPCdataQA::ProcessEvent(eventHeaderStruct *event)
233 // process date event
236 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
237 Bool_t result=ProcessEvent(rawReader);
244 //_____________________________________________________________________
245 void AliTPCdataQA::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
248 // Write class to file
259 TDirectory *backup = gDirectory;
260 TFile f(filename,option.Data());
262 if ( !sDir.IsNull() ){
263 f.mkdir(sDir.Data());
269 if ( backup ) backup->cd();
273 //_____________________________________________________________________
274 Int_t AliTPCdataQA::Update(const Int_t icsector, /*FOLD00*/
277 const Int_t icTimeBin,
278 const Float_t csignal)
281 // Signal filling method
283 if (icTimeBin<fFirstTimeBin) return 0;
284 if (icTimeBin>fLastTimeBin) return 0;
286 if (!fMaxCharge) fMaxCharge = new AliTPCCalPad("MaxCharge","MaxCharge");
287 if (!fMeanCharge) fMeanCharge = new AliTPCCalPad("MeanCharge","MeanCharge");
288 if (!fNoThreshold) fNoThreshold = new AliTPCCalPad("NoThreshold","NoThreshold");
289 if (!fOverThreshold0) fOverThreshold0 = new AliTPCCalPad("OverThreshold0","OverThreshold0");
290 if (!fOverThreshold5) fOverThreshold5 = new AliTPCCalPad("OverThreshold5","OverThreshold5");
291 if (!fOverThreshold10) fOverThreshold10 = new AliTPCCalPad("OverThreshold10","OverThreshold10");
292 if (!fOverThreshold20) fOverThreshold20 = new AliTPCCalPad("OverThreshold20","OverThreshold20");
293 if (!fOverThreshold30) fOverThreshold30 = new AliTPCCalPad("OverThreshold30","OverThreshold30");
296 Int_t signal = Int_t(csignal);
298 // if pedestal calibrations are loaded subtract pedestals
301 Int_t pedestal = Int_t(fPedestal->GetCalROC(icsector)->GetValue(icRow, icPad));
302 if(pedestal<10 || pedestal>90)
310 Float_t count = fNoThreshold->GetCalROC(icsector)->GetValue(icRow, icPad);
311 fNoThreshold->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
314 // Require at least 3 ADC channels
318 // if noise calibrations are loaded require at least 3*sigmaNoise
321 Float_t noise = fNoise->GetCalROC(icsector)->GetValue(icRow, icPad);
327 // this signal is ok - now see if the previous signal was connected
328 // this is a bit ugly since the standard decoder goes down in time bins
329 // (10, 9, 8..) while the fast HLT decoder goes up in time bins (1, 2, 3..)
331 if(fSectorLast==icsector && fRowLast==icRow && fPadLast==icPad &&
332 fTimeBinLast==icTimeBin+1 || fTimeBinLast==icTimeBin-1)
335 fNAboveThreshold = 1;
337 if(fNAboveThreshold==2) {
340 // This is the only special case, because before we did not know if we
341 // should store the information
343 UpdateSignalHistograms(fSectorLast, fRowLast, fPadLast, fTimeBinLast,
347 // keep the information for the next signal
348 fSectorLast = icsector;
351 fTimeBinLast = icTimeBin;
352 fSignalLast = signal;
354 if(fNAboveThreshold==1) // we don't know if this information should be stored
357 UpdateSignalHistograms(fSectorLast, fRowLast, fPadLast, fTimeBinLast,
362 //_____________________________________________________________________
363 void AliTPCdataQA::UpdateSignalHistograms(const Int_t icsector, /*FOLD00*/
366 const Int_t icTimeBin,
367 const Float_t signal)
370 // Signal filling method
374 Float_t charge = fMeanCharge->GetCalROC(icsector)->GetValue(icRow, icPad);
375 fMeanCharge->GetCalROC(icsector)->SetValue(icRow, icPad, charge + signal);
378 if (signal>fMaxCharge->GetCalROC(icsector)->GetValue(icRow, icPad)){
379 fMaxCharge->GetCalROC(icsector)->SetValue(icRow, icPad,signal);
383 Float_t count = fOverThreshold0->GetCalROC(icsector)->GetValue(icRow, icPad);
384 fOverThreshold0->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
388 Float_t count = fOverThreshold5->GetCalROC(icsector)->GetValue(icRow, icPad);
389 fOverThreshold5->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
392 Float_t count = fOverThreshold10->GetCalROC(icsector)->GetValue(icRow, icPad);
393 fOverThreshold10->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
396 Float_t count = fOverThreshold20->GetCalROC(icsector)->GetValue(icRow, icPad);
397 fOverThreshold20->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
400 Float_t count = fOverThreshold30->GetCalROC(icsector)->GetValue(icRow, icPad);
401 fOverThreshold30->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
405 //_____________________________________________________________________
406 void AliTPCdataQA::Analyse()
409 // Calculate calibration constants
412 cout << "Analyse called" << endl;
414 if(fEventCounter==0) {
416 cout << "EventCounter == 0, Cannot analyse" << endl;
420 Int_t nTimeBins = fLastTimeBin - fFirstTimeBin +1;
421 cout << "EventCounter: " << fEventCounter << endl
422 << "TimeBins: " << nTimeBins << endl;
424 if (fMeanCharge && fNoThreshold) fMeanCharge->Divide(fNoThreshold);
426 Float_t normalization = 1.0 / Float_t(fEventCounter * nTimeBins);
427 if (fNoThreshold) fNoThreshold->Multiply(normalization);
428 if (fOverThreshold0) fOverThreshold0->Multiply(normalization);
429 if (fOverThreshold5) fOverThreshold5->Multiply(normalization);
430 if (fOverThreshold10) fOverThreshold10->Multiply(normalization);
431 if (fOverThreshold20) fOverThreshold20->Multiply(normalization);
432 if (fOverThreshold30) fOverThreshold30->Multiply(normalization);
436 void AliTPCdataQA::MakeTree(const char *fname){
438 // Export result to the tree -located in the file
439 // This file can be analyzed using AliTPCCalibViewer
441 AliTPCdataQA *ped = this;
442 AliTPCPreprocessorOnline preprocesor;
443 if (ped->GetMaxCharge()) preprocesor.AddComponent(ped->GetMaxCharge());
444 if (ped->GetMeanCharge()) preprocesor.AddComponent(ped->GetMeanCharge());
445 if (ped->GetOverThreshold0()) preprocesor.AddComponent(ped->GetOverThreshold0());
446 if (ped->GetOverThreshold5()) preprocesor.AddComponent(ped->GetOverThreshold5());
447 if (ped->GetOverThreshold10()) preprocesor.AddComponent(ped->GetOverThreshold10());
448 if (ped->GetOverThreshold20()) preprocesor.AddComponent(ped->GetOverThreshold20());
449 if (ped->GetOverThreshold30()) preprocesor.AddComponent(ped->GetOverThreshold30());
450 preprocesor.DumpToFile(fname);
455 void AliTPCdataQA::MakeArrays(){
459 AliTPCROC * roc = AliTPCROC::Instance();
461 Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
462 Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
464 fAllBins = new Float_t*[nRowsMax];
465 fAllSigBins = new Int_t*[nRowsMax];
466 fAllNSigBins = new Int_t[nRowsMax];
467 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
469 Int_t maxBin = fMaxTime*(nPadsMax+6); // add 3 virtual pads before and 3 after
470 fAllBins[iRow] = new Float_t[maxBin];
471 memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
472 fAllSigBins[iRow] = new Int_t[maxBin];
473 fAllNSigBins[iRow]=0;
478 void AliTPCdataQA::CleanArrays(){
482 AliTPCROC * roc = AliTPCROC::Instance();
484 Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
485 Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
486 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
488 Int_t maxBin = fMaxTime*(nPadsMax+6); // add 3 virtual pads before and 3 after
489 memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
490 fAllNSigBins[iRow]=0;
494 Float_t* AliTPCdataQA::GetExpandDigit(Int_t row, Int_t pad, Int_t time){
498 AliTPCROC * roc = AliTPCROC::Instance();
499 Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
500 if (row<0 || row>nRowsMax) return 0;
501 Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);