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 **************************************************************************/
19 example: fill pedestal with Gaussian noise
20 AliTRDCalibPadStatus ped;
21 ped.TestEvent(numberofevent);
22 // Method without histo
23 //////////////////////////
25 //Create the histo of the AliTRDCalROC
26 TH2F * histo2dm = ped.GetCalRocMean(0,kFALSE)->MakeHisto2D();
27 histo2dm->Scale(10.0);
28 TH1F * histo1dm = ped.GetCalRocMean(0,kFALSE)->MakeHisto1D();
29 histo1dm->Scale(10.0);
30 TH2F * histo2ds = ped.GetCalRocSquares(0,kFALSE)->MakeHisto2D();
31 histo2ds->Scale(10.0);
32 TH1F * histo1ds = ped.GetCalRocSquares(0,kFALSE)->MakeHisto1D();
35 TCanvas* c1 = new TCanvas;
38 histo2dm->Draw("colz");
42 histo2ds->Draw("colz");
46 /////////////////////////
49 TH1F * histo = ped.GetHisto(31);
56 #include <TObjArray.h>
63 #include <TDirectory.h>
65 #include <TTreeStream.h>
68 #include <AliMathBase.h>
69 #include "AliRawReader.h"
70 #include "AliRawReaderRoot.h"
71 #include "AliRawReaderDate.h"
74 #include "AliTRDCalibPadStatus.h"
75 #include "AliTRDRawStreamV2.h"
76 #include "AliTRDarrayF.h"
77 #include "AliTRDgeometry.h"
78 #include "AliTRDCommonParam.h"
79 #include "./Cal/AliTRDCalROC.h"
80 #include "./Cal/AliTRDCalPadStatus.h"
81 #include "./Cal/AliTRDCalDet.h"
82 #include "./Cal/AliTRDCalPad.h"
83 #include "./Cal/AliTRDCalSingleChamberStatus.h"
89 ClassImp(AliTRDCalibPadStatus) /*FOLD00*/
91 //_____________________________________________________________________
92 AliTRDCalibPadStatus::AliTRDCalibPadStatus() : /*FOLD00*/
99 fCalArrayEntries(540),
101 fCalArraySquares(540),
102 fCalRocArrayMean(540),
103 fCalRocArrayRMS(540),
110 // default constructor
113 fGeo = new AliTRDgeometry();
117 //_____________________________________________________________________
118 AliTRDCalibPadStatus::AliTRDCalibPadStatus(const AliTRDCalibPadStatus &ped) : /*FOLD00*/
121 fAdcMin(ped.GetAdcMin()),
122 fAdcMax(ped.GetAdcMax()),
123 fDetector(ped.fDetector),
124 fNumberOfTimeBins(ped.fNumberOfTimeBins),
125 fCalArrayEntries(540),
127 fCalArraySquares(540),
128 fCalRocArrayMean(540),
129 fCalRocArrayRMS(540),
138 for (Int_t idet = 0; idet < 540; idet++){
139 const AliTRDarrayF *calEntries = (AliTRDarrayF*)ped.fCalArrayEntries.UncheckedAt(idet);
140 const AliTRDarrayF *calMean = (AliTRDarrayF*)ped.fCalArrayMean.UncheckedAt(idet);
141 const AliTRDarrayF *calSquares = (AliTRDarrayF*)ped.fCalArraySquares.UncheckedAt(idet);
142 const AliTRDCalROC *calRocMean = (AliTRDCalROC*)ped.fCalRocArrayMean.UncheckedAt(idet);
143 const AliTRDCalROC *calRocRMS = (AliTRDCalROC*)ped.fCalRocArrayRMS.UncheckedAt(idet);
144 const TH2F *hped = (TH2F*)ped.fHistoArray.UncheckedAt(idet);
146 if ( calEntries != 0x0 ) fCalArrayEntries.AddAt(new AliTRDarrayF(*calEntries), idet);
147 if ( calMean != 0x0 ) fCalArrayMean.AddAt(new AliTRDarrayF(*calMean), idet);
148 if ( calSquares != 0x0 ) fCalArraySquares.AddAt(new AliTRDarrayF(*calSquares), idet);
149 if ( calRocMean != 0x0 ) fCalRocArrayMean.AddAt(new AliTRDCalROC(*calRocMean), idet);
150 if ( calRocRMS != 0x0 ) fCalRocArrayRMS.AddAt(new AliTRDCalROC(*calRocRMS), idet);
153 TH2F *hNew = new TH2F(*hped);
154 hNew->SetDirectory(0);
155 fHistoArray.AddAt(hNew,idet);
162 fGeo = new AliTRDgeometry();
165 //_____________________________________________________________________
166 AliTRDCalibPadStatus& AliTRDCalibPadStatus::operator = (const AliTRDCalibPadStatus &source)
169 // assignment operator
171 if (&source == this) return *this;
172 new (this) AliTRDCalibPadStatus(source);
177 //_____________________________________________________________________
178 AliTRDCalibPadStatus::~AliTRDCalibPadStatus() /*FOLD00*/
188 //_____________________________________________________________________
189 Int_t AliTRDCalibPadStatus::Update(const Int_t icdet, /*FOLD00*/
196 // Signal filling methode
198 if ( (csignal>fAdcMax) || (csignal<fAdcMin) ) return 0;
200 if(fDetector != icdet){
201 fCalEntries = ((AliTRDarrayF *)GetCalEntries(icdet,kTRUE));
202 fCalMean = ((AliTRDarrayF *)GetCalMean(icdet,kTRUE));
203 fCalSquares = ((AliTRDarrayF *)GetCalSquares(icdet,kTRUE));
206 Float_t entries = fCalEntries->At(icRow+icCol*crowMax);
207 Float_t mean = fCalMean->At(icRow+icCol*crowMax);
208 Float_t squares = fCalSquares->At(icRow+icCol*crowMax);
210 Float_t entriesn = entries+1.0;
211 fCalEntries->AddAt(entriesn,(icRow+icCol*crowMax));
212 Float_t meann = (mean*entries+((Float_t)(csignal+0.5)))/entriesn;
213 fCalMean->AddAt(meann,icRow+icCol*crowMax);
214 Float_t squaresn = ((squares*entries)+(((Float_t)(csignal+0.5))*((Float_t)(csignal+0.5))))/entriesn;
215 fCalSquares->AddAt(squaresn,icRow+icCol*crowMax);
217 //printf("icdet %d, icRow %d, icCol %d, csignal %d, crowMax %d\n",icdet,icRow,icCol,csignal,crowMax);
218 //printf("entries %f, mean %f, squares %f\n",entriesn,meann,squaresn);
225 //_____________________________________________________________________
226 Int_t AliTRDCalibPadStatus::UpdateHisto(const Int_t icdet, /*FOLD00*/
233 // Signal filling methode
235 Int_t nbchannel = icRow+icCol*crowMax;
237 // fast filling methode.
238 // Attention: the entry counter of the histogram is not increased
239 // this means that e.g. the colz draw option gives an empty plot
241 if ( !(((Int_t)csignal>fAdcMax ) || ((Int_t)csignal<fAdcMin)) )
242 bin = (nbchannel+1)*(fAdcMax-fAdcMin+2)+((Int_t)csignal-fAdcMin+1);
244 GetHisto(icdet,kTRUE)->GetArray()[bin]++;
249 //_____________________________________________________________________
250 Int_t AliTRDCalibPadStatus::ProcessEvent(AliTRDRawStreamV2 *rawStream, Bool_t nocheck)
253 // Event Processing loop - AliTRDRawStreamV2
254 // 0 time bin problem or zero suppression
262 while (rawStream->Next()) {
263 Int_t rawversion = rawStream->GetRawVersion(); // current raw version
264 if(rawversion != 2) return 0;
265 Int_t idetector = rawStream->GetDet(); // current detector
266 Int_t iRow = rawStream->GetRow(); // current row
267 Int_t iRowMax = rawStream->GetMaxRow(); // current rowmax
268 Int_t iCol = rawStream->GetCol(); // current col
269 Int_t iTimeBin = rawStream->GetTimeBin(); // current time bin
270 Int_t *signal = rawStream->GetSignals(); // current ADC signal
271 Int_t nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
273 if((fDetector != -1) && (nbtimebin != fNumberOfTimeBins)) return 0;
274 fNumberOfTimeBins = nbtimebin;
276 Int_t fin = TMath::Min(nbtimebin,(iTimeBin+3));
279 for(Int_t k = iTimeBin; k < fin; k++){
280 if(signal[n]>0) UpdateHisto(idetector,iRow,iCol,signal[n],iRowMax);
288 while (rawStream->Next()) {
289 Int_t idetector = rawStream->GetDet(); // current detector
290 Int_t iRow = rawStream->GetRow(); // current row
291 Int_t iRowMax = rawStream->GetMaxRow(); // current rowmax
292 Int_t iCol = rawStream->GetCol(); // current col
293 Int_t iTimeBin = rawStream->GetTimeBin(); // current time bin
294 Int_t *signal = rawStream->GetSignals(); // current ADC signal
295 Int_t nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
297 Int_t fin = TMath::Min(nbtimebin,(iTimeBin+3));
300 for(Int_t k = iTimeBin; k < fin; k++){
301 if(signal[n]>0) UpdateHisto(idetector,iRow,iCol,signal[n],iRowMax);
312 //_____________________________________________________________________
313 Int_t AliTRDCalibPadStatus::ProcessEvent(AliRawReader *rawReader, Bool_t nocheck)
316 // Event processing loop - AliRawReader
320 AliTRDRawStreamV2 rawStream(rawReader);
322 rawReader->Select("TRD");
324 return ProcessEvent(&rawStream, nocheck);
327 //_________________________________________________________________________
328 Int_t AliTRDCalibPadStatus::ProcessEvent(
330 eventHeaderStruct *event,
333 eventHeaderStruct* /*event*/,
340 // process date event
343 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
344 Bool_t result=ProcessEvent(rawReader, nocheck);
348 Fatal("AliTRDCalibPadStatus", "this class was compiled without DATE");
354 //_____________________________________________________________________
355 Bool_t AliTRDCalibPadStatus::TestEvent(Int_t nevent, Int_t sm) /*FOLD00*/
359 // fill one oroc and one iroc with random gaus
364 for (Int_t ism=sm; ism<sm+1; ism++){
365 for (Int_t ich=0; ich < 5; ich++){
366 for (Int_t ipl=0; ipl < 6; ipl++){
367 for(Int_t irow = 0; irow < fGeo->GetRowMax(ipl,ich,ism); irow++){
368 for(Int_t icol = 0; icol < fGeo->GetColMax(ipl); icol++){
369 for (Int_t iTimeBin=0; iTimeBin<(30*nevent); iTimeBin++){
370 Int_t signal=(Int_t)(gRandom->Gaus(10.0,1.2));
371 if ( signal>0 )Update((ipl+ich*6+ism*6*5),irow,icol,signal,fGeo->GetRowMax(ipl,ich,ism));
381 //_____________________________________________________________________
382 Bool_t AliTRDCalibPadStatus::TestEventHisto(Int_t nevent, Int_t sm) /*FOLD00*/
386 // fill one oroc and one iroc with random gaus
391 for (Int_t ism=sm; ism<sm+1; ism++){
392 for (Int_t ich=0; ich < 5; ich++){
393 for (Int_t ipl=0; ipl < 6; ipl++){
394 for(Int_t irow = 0; irow < fGeo->GetRowMax(ipl,ich,ism); irow++){
395 for(Int_t icol = 0; icol < fGeo->GetColMax(ipl); icol++){
396 for (Int_t iTimeBin=0; iTimeBin<(30*nevent); iTimeBin++){
397 Int_t signal=(Int_t)(gRandom->Gaus(10.0,1.2));
398 if ( signal>0 )UpdateHisto((ipl+ich*6+ism*6*5),irow,icol,signal,fGeo->GetRowMax(ipl,ich,ism));
408 //_____________________________________________________________________
409 TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, TObjArray *arr, /*FOLD00*/
410 Int_t nbinsY, Float_t ymin, Float_t ymax,
411 Char_t *type, Bool_t force)
414 // return pointer to histogram
415 // if force is true create a new histogram if it doesn't exist allready
417 if ( !force || arr->UncheckedAt(det) )
418 return (TH2F*)arr->UncheckedAt(det);
420 // if we are forced and histogram doesn't yes exist create it
421 Char_t name[255], title[255];
423 sprintf(name,"hCalib%s%.2d",type,det);
424 sprintf(title,"%s calibration histogram detector %.2d;ADC channel;Channel (pad)",type,det);
427 Int_t nbchannels = fGeo->GetRowMax(GetPlane(det),GetChamber(det),GetSector(det))*fGeo->GetColMax(GetPlane(det));
429 // new histogram with calib information. One value for each pad!
430 TH2F* hist = new TH2F(name,title,
432 nbchannels,0,nbchannels
434 hist->SetDirectory(0);
435 arr->AddAt(hist,det);
439 //_____________________________________________________________________
440 TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, Bool_t force) /*FOLD00*/
443 // return pointer to histogram
444 // if force is true create a new histogram if it doesn't exist allready
446 TObjArray *arr = &fHistoArray;
447 return GetHisto(det, arr, fAdcMax-fAdcMin, fAdcMin, fAdcMax, "Pedestal", force);
450 //_____________________________________________________________________
451 AliTRDarrayF* AliTRDCalibPadStatus::GetCal(Int_t det, TObjArray* arr, Bool_t force) /*FOLD00*/
454 // return pointer to ROC Calibration
455 // if force is true create a new AliTRDarrayF if it doesn't exist allready
457 if ( !force || arr->UncheckedAt(det) )
458 return (AliTRDarrayF*)arr->UncheckedAt(det);
460 // if we are forced and histogram doesn't yes exist create it
461 AliTRDarrayF *croc = new AliTRDarrayF();
463 Int_t nbpad = fGeo->GetRowMax(GetPlane(det),GetChamber(det),GetSector(det))*fGeo->GetColMax(GetPlane(det));
465 // new AliTRDCalROC. One value for each pad!
467 for(Int_t k = 0; k < nbpad; k++){
470 arr->AddAt(croc,det);
474 //_____________________________________________________________________
475 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRoc(Int_t det, TObjArray* arr, Bool_t force) /*FOLD00*/
478 // return pointer to ROC Calibration
479 // if force is true create a new AliTRDCalROC if it doesn't exist allready
481 if ( !force || arr->UncheckedAt(det) )
482 return (AliTRDCalROC*)arr->UncheckedAt(det);
484 // if we are forced and histogram doesn't yes exist create it
486 // new AliTRDCalROC. One value for each pad!
487 AliTRDCalROC *croc = new AliTRDCalROC(GetPlane(det),GetChamber(det));
488 arr->AddAt(croc,det);
492 //_____________________________________________________________________
493 AliTRDarrayF* AliTRDCalibPadStatus::GetCalEntries(Int_t det, Bool_t force) /*FOLD00*/
496 // return pointer to Carge ROC Calibration
497 // if force is true create a new histogram if it doesn't exist allready
499 TObjArray *arr = &fCalArrayEntries;
500 return GetCal(det, arr, force);
503 //_____________________________________________________________________
504 AliTRDarrayF* AliTRDCalibPadStatus::GetCalMean(Int_t det, Bool_t force) /*FOLD00*/
507 // return pointer to Carge ROC Calibration
508 // if force is true create a new histogram if it doesn't exist allready
510 TObjArray *arr = &fCalArrayMean;
511 return GetCal(det, arr, force);
514 //_____________________________________________________________________
515 AliTRDarrayF* AliTRDCalibPadStatus::GetCalSquares(Int_t det, Bool_t force) /*FOLD00*/
518 // return pointer to Carge ROC Calibration
519 // if force is true create a new histogram if it doesn't exist allready
521 TObjArray *arr = &fCalArraySquares;
522 return GetCal(det, arr, force);
525 //_____________________________________________________________________
526 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocMean(Int_t det, Bool_t force) /*FOLD00*/
529 // return pointer to Carge ROC Calibration
530 // if force is true create a new histogram if it doesn't exist allready
532 TObjArray *arr = &fCalRocArrayMean;
533 return GetCalRoc(det, arr, force);
536 //_____________________________________________________________________
537 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocRMS(Int_t det, Bool_t force) /*FOLD00*/
540 // return pointer to Carge ROC Calibration
541 // if force is true create a new histogram if it doesn't exist allready
543 TObjArray *arr = &fCalRocArrayRMS;
544 return GetCalRoc(det, arr, force);
547 //_________________________________________________________________________
548 void AliTRDCalibPadStatus::Analyse() /*FOLD00*/
551 // Calcul the rms properly
554 for(Int_t idet = 0; idet < 540; idet++){
557 fCalEntries = ((AliTRDarrayF *)GetCalEntries(idet));
558 fCalMean = ((AliTRDarrayF *)GetCalMean(idet));
559 fCalSquares = ((AliTRDarrayF *)GetCalSquares(idet));
561 if(!fCalEntries) continue;
563 AliTRDCalROC *calRocMean = ((AliTRDCalROC *)GetCalRocMean(idet,kTRUE));
564 AliTRDCalROC *calRocRMS = ((AliTRDCalROC *)GetCalRocRMS(idet,kTRUE));
567 Int_t channels = calRocMean->GetNchannels();
569 for(Int_t ichannels = 0 ; ichannels < channels; ichannels++){
571 Float_t entries = fCalEntries->At(ichannels);
572 Float_t mean = fCalMean->At(ichannels);
573 Float_t squares = fCalSquares->At(ichannels);
577 Double_t rm = TMath::Abs(squares-(mean*mean));
578 rms = TMath::Sqrt(rm);
579 calRocRMS->SetValue(ichannels,rms/10.0);
580 calRocMean->SetValue(ichannels,mean/10.0);
586 //_____________________________________________________________________
587 void AliTRDCalibPadStatus::AnalyseHisto() /*FOLD00*/
590 // Calculate calibration constants
593 Int_t nbinsAdc = fAdcMax-fAdcMin;
601 for (Int_t idet=0; idet<540; idet++){
602 TH2F *hP = GetHisto(idet);
607 AliTRDCalROC *rocMean = GetCalRocMean(idet,kTRUE);
608 AliTRDCalROC *rocRMS = GetCalRocRMS(idet,kTRUE);
610 array_hP = hP->GetArray();
611 Int_t nChannels = rocMean->GetNchannels();
613 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
614 Int_t offset = (nbinsAdc+2)*(iChannel+1)+1;
615 Double_t ret = AliMathBase::FitGaus(array_hP+offset,nbinsAdc,fAdcMin,fAdcMax,¶m,&dummy);
616 // if the fitting failed set noise and pedestal to 0
617 if ((ret==-4) || (ret==-1) || (ret==-2)) {
621 if((param[1]/10.0) > 65534.0) param[1] = 0.0;
622 if((param[2]/10.0) > 65534.0) param[2] = 0.0;
623 rocMean->SetValue(iChannel,param[1]/10.0);
624 rocRMS->SetValue(iChannel,param[2]/10.0);
630 //_______________________________________________________________________________________
631 AliTRDCalPadStatus* AliTRDCalibPadStatus::CreateCalPadStatus()
634 // Create Pad Status out of Mean and RMS values
637 AliTRDCalPadStatus* obj = new AliTRDCalPadStatus("padstatus", "padstatus");
639 for (Int_t idet=0; idet<540; ++idet)
641 AliTRDCalSingleChamberStatus *calROC = obj->GetCalROC(idet);
644 AliTRDCalROC *calRocMean = ((AliTRDCalROC *)GetCalRocMean(idet));
645 AliTRDCalROC *calRocRMS = ((AliTRDCalROC *)GetCalRocRMS(idet));
648 for(Int_t k = 0; k < calROC->GetNchannels(); k++){
649 calROC->SetStatus(k,AliTRDCalPadStatus::kMasked);
655 Int_t channels = calROC->GetNchannels();
657 Double_t rmsmean = calRocMean->GetRMS()*10.0;
658 Double_t meanmean = calRocMean->GetMean()*10.0;
659 Double_t meansquares = calRocRMS->GetMean()*10.0;
662 for(Int_t ich = 0; ich < channels; ich++){
664 Float_t mean = calRocMean->GetValue(ich)*10.0;
665 Float_t rms = calRocRMS->GetValue(ich)*10.0;
667 if((rms <= 0.0001) || (TMath::Abs(mean-meanmean)>(5*rmsmean)) || (TMath::Abs(rms)>(5.0*TMath::Abs(meansquares)))) calROC->SetStatus(ich, AliTRDCalPadStatus::kMasked);
676 //_______________________________________________________________________________________
677 AliTRDCalPad* AliTRDCalibPadStatus::CreateCalPad()
680 // Create Pad Noise out of RMS values
683 AliTRDCalPad* obj = new AliTRDCalPad("PadNoise", "PadNoise");
686 for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det) {
688 AliTRDCalROC *calROC22 = obj->GetCalROC(det);
690 AliTRDCalROC *calRocRMS = ((AliTRDCalROC *)GetCalRocRMS(det,kTRUE));
692 for(Int_t k = 0; k < calROC22->GetNchannels(); k++){
693 calROC22->SetValue(k,calRocRMS->GetValue(k));
702 //_______________________________________________________________________________________
703 AliTRDCalDet* AliTRDCalibPadStatus::CreateCalDet()
706 // Create Det Noise correction factor
709 AliTRDCalDet* obj = new AliTRDCalDet("DetNoise", "DetNoise (correction factor)");
711 for(Int_t l = 0; l < 540; l++){
712 obj->SetValue(l,10.0);
719 //_____________________________________________________________________
720 void AliTRDCalibPadStatus::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
723 // Write class to file
734 TDirectory *backup = gDirectory;
735 TFile f(filename,option.Data());
737 if ( !sDir.IsNull() ){
738 f.mkdir(sDir.Data());
744 if ( backup ) backup->cd();
747 //_____________________________________________________________________
748 void AliTRDCalibPadStatus::SetCalRocMean(AliTRDCalROC *mean, Int_t det) /*FOLD00*/
751 // Put the AliTRDCalROC in the array fCalRocArrayMean
755 AliTRDCalROC *rocMean = GetCalRocMean(det,kTRUE);
757 Int_t nChannels = rocMean->GetNchannels();
759 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
761 rocMean->SetValue(iChannel,mean->GetValue(iChannel));
767 //_____________________________________________________________________
768 void AliTRDCalibPadStatus::SetCalRocRMS(AliTRDCalROC *rms, Int_t det) /*FOLD00*/
771 // Put the AliTRDCalROC in the array fCalRocArrayRMS
775 AliTRDCalROC *rocRms = GetCalRocRMS(det,kTRUE);
777 Int_t nChannels = rocRms->GetNchannels();
779 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
781 rocRms->SetValue(iChannel,rms->GetValue(iChannel));
787 //_____________________________________________________________________________
788 Int_t AliTRDCalibPadStatus::GetPlane(Int_t d) const
791 // Reconstruct the plane number from the detector number
794 return ((Int_t) (d % 6));
798 //_____________________________________________________________________________
799 Int_t AliTRDCalibPadStatus::GetChamber(Int_t d) const
802 // Reconstruct the chamber number from the detector number
805 return ((Int_t) (d % 30) / 6);
809 //_____________________________________________________________________________
810 Int_t AliTRDCalibPadStatus::GetSector(Int_t d) const
813 // Reconstruct the sector number from the detector number
816 return ((Int_t) (d / 30));