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>
61 #include <TDirectory.h>
65 #include <AliMathBase.h>
66 #include "AliRawReader.h"
67 #include "AliRawReaderRoot.h"
68 #include "AliRawReaderDate.h"
72 #include "AliTRDCalibPadStatus.h"
73 #include "AliTRDRawStreamV2.h"
74 #include "AliTRDgeometry.h"
75 #include "AliTRDCommonParam.h"
76 #include "./Cal/AliTRDCalROC.h"
77 #include "./Cal/AliTRDCalPadStatus.h"
78 #include "./Cal/AliTRDCalDet.h"
79 #include "./Cal/AliTRDCalPad.h"
80 #include "./Cal/AliTRDCalSingleChamberStatus.h"
86 ClassImp(AliTRDCalibPadStatus) /*FOLD00*/
88 //_____________________________________________________________________
89 AliTRDCalibPadStatus::AliTRDCalibPadStatus() : /*FOLD00*/
96 fCalRocArrayMean(540),
98 fCalRocArrayMeand(540),
99 fCalRocArrayRMSd(540),
103 // default constructor
106 fGeo = new AliTRDgeometry();
110 //_____________________________________________________________________
111 AliTRDCalibPadStatus::AliTRDCalibPadStatus(const AliTRDCalibPadStatus &ped) : /*FOLD00*/
114 fAdcMin(ped.GetAdcMin()),
115 fAdcMax(ped.GetAdcMax()),
116 fDetector(ped.fDetector),
117 fNumberOfTimeBins(ped.fNumberOfTimeBins),
118 fCalRocArrayMean(540),
119 fCalRocArrayRMS(540),
120 fCalRocArrayMeand(540),
121 fCalRocArrayRMSd(540),
127 for (Int_t idet = 0; idet < 540; idet++){
128 const AliTRDCalROC *calRocMean = (AliTRDCalROC*)ped.fCalRocArrayMean.UncheckedAt(idet);
129 const AliTRDCalROC *calRocRMS = (AliTRDCalROC*)ped.fCalRocArrayRMS.UncheckedAt(idet);
130 const AliTRDCalROC *calRocMeand = (AliTRDCalROC*)ped.fCalRocArrayMeand.UncheckedAt(idet);
131 const AliTRDCalROC *calRocRMSd = (AliTRDCalROC*)ped.fCalRocArrayRMSd.UncheckedAt(idet);
132 const TH2F *hped = (TH2F*)ped.fHistoArray.UncheckedAt(idet);
134 if ( calRocMean != 0x0 ) fCalRocArrayMean.AddAt(new AliTRDCalROC(*calRocMean), idet);
135 if ( calRocRMS != 0x0 ) fCalRocArrayRMS.AddAt(new AliTRDCalROC(*calRocRMS), idet);
137 if ( calRocMeand != 0x0 ) fCalRocArrayMeand.AddAt(new AliTRDCalROC(*calRocMeand), idet);
138 if ( calRocRMSd != 0x0 ) fCalRocArrayRMSd.AddAt(new AliTRDCalROC(*calRocRMSd), idet);
141 TH2F *hNew = new TH2F(*hped);
142 hNew->SetDirectory(0);
143 fHistoArray.AddAt(hNew,idet);
150 fGeo = new AliTRDgeometry();
153 //_____________________________________________________________________
154 AliTRDCalibPadStatus& AliTRDCalibPadStatus::operator = (const AliTRDCalibPadStatus &source)
157 // assignment operator
159 if (&source == this) return *this;
160 new (this) AliTRDCalibPadStatus(source);
165 //_____________________________________________________________________
166 AliTRDCalibPadStatus::~AliTRDCalibPadStatus() /*FOLD00*/
176 //_____________________________________________________________________
177 Int_t AliTRDCalibPadStatus::UpdateHisto(const Int_t icdet, /*FOLD00*/
186 // Signal filling methode
188 Int_t nbchannel = icRow+icCol*crowMax;
190 // now the case of double read channel
192 nbchannel = (((ccold-1)*8+ icMcm)*crowMax+icRow)+144*crowMax;
193 //printf("nbchannel %d, ccold %d, icMcm %d, crowMax %d, icRow %d\n",nbchannel,ccold,icMcm,crowMax,icRow);
196 // fast filling methode.
197 // Attention: the entry counter of the histogram is not increased
198 // this means that e.g. the colz draw option gives an empty plot
200 if ( !(((Int_t)csignal>fAdcMax ) || ((Int_t)csignal<fAdcMin)) )
201 bin = (nbchannel+1)*(fAdcMax-fAdcMin+2)+((Int_t)csignal-fAdcMin+1);
203 GetHisto(icdet,kTRUE)->GetArray()[bin]++;
207 //_____________________________________________________________________
208 Int_t AliTRDCalibPadStatus::ProcessEvent(AliTRDRawStreamV2 *rawStream, Bool_t nocheck)
211 // Event Processing loop - AliTRDRawStreamCosmic
212 // 0 time bin problem or zero suppression
219 //rawStream->SetSharedPadReadout(kTRUE);
222 while (rawStream->Next()) {
223 Int_t rawversion = rawStream->GetRawVersion(); // current raw version
224 //if(!rawStream->IsDataZeroSuppressed()) {
226 AliInfo(Form("this is not no-zero-suppressed data, the version is %d",rawversion));
229 Int_t idetector = rawStream->GetDet(); // current detector
230 Int_t iRow = rawStream->GetRow(); // current row
231 Int_t iRowMax = rawStream->GetMaxRow(); // current rowmax
232 Int_t iCol = rawStream->GetCol(); // current col
235 Int_t iADC = 21-rawStream->GetADC(); // current ADC
237 if(iADC == 1) col = 1;
239 col = TMath::Max(0,(Int_t)(iADC-19));
242 Int_t mcm = (Int_t)(iCol/18); // current group of 18 col pads
243 if(col > 1) mcm -= 1;
244 if(col ==1) mcm += 1;
246 //Bool_t shared = rawStream->IsCurrentPadShared();
247 //printf("ADC %d, iCol %d, col %d, mcm %d, shared %d\n",iADC,iCol,col,mcm,(Int_t)shared);
249 Int_t iTimeBin = rawStream->GetTimeBin(); // current time bin
250 Int_t *signal = rawStream->GetSignals(); // current ADC signal
251 Int_t nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
253 if((fDetector != -1) && (nbtimebin != fNumberOfTimeBins)) {
254 AliInfo(Form("the number of time bins is %d, is different from the previous one %d",nbtimebin,fNumberOfTimeBins));
257 fNumberOfTimeBins = nbtimebin;
259 Int_t fin = TMath::Min(nbtimebin,(iTimeBin+3));
262 for(Int_t k = iTimeBin; k < fin; k++){
263 if(signal[n]>0) UpdateHisto(idetector,iRow,iCol,signal[n],iRowMax,col,mcm);
271 while (rawStream->Next()) {
272 Int_t idetector = rawStream->GetDet(); // current detector
273 Int_t iRow = rawStream->GetRow(); // current row
274 Int_t iRowMax = rawStream->GetMaxRow(); // current rowmax
275 Int_t iCol = rawStream->GetCol(); // current col
278 Int_t iADC = 21-rawStream->GetADC(); // current ADC
280 if(iADC == 1) col = 1;
282 col = TMath::Max(0,(Int_t)(iADC-19));
285 Int_t mcm = (Int_t)(iCol/18); // current group of 18 col pads
286 if(col > 1) mcm -= 1;
287 if(col ==1) mcm += 1;
289 Int_t iTimeBin = rawStream->GetTimeBin(); // current time bin
290 Int_t *signal = rawStream->GetSignals(); // current ADC signal
291 Int_t nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
293 Int_t fin = TMath::Min(nbtimebin,(iTimeBin+3));
296 for(Int_t k = iTimeBin; k < fin; k++){
297 if(signal[n]>0) UpdateHisto(idetector,iRow,iCol,signal[n],iRowMax,col,mcm);
308 //_____________________________________________________________________
309 Int_t AliTRDCalibPadStatus::ProcessEvent(AliRawReader *rawReader, Bool_t nocheck)
312 // Event processing loop - AliRawReader
316 AliTRDRawStreamV2 rawStream(rawReader);
318 rawReader->Select("TRD");
320 return ProcessEvent(&rawStream, nocheck);
323 //_________________________________________________________________________
324 Int_t AliTRDCalibPadStatus::ProcessEvent(
326 eventHeaderStruct *event,
329 eventHeaderStruct* /*event*/,
336 // process date event
339 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
340 Bool_t result=ProcessEvent(rawReader, nocheck);
344 Fatal("AliTRDCalibPadStatus", "this class was compiled without DATE");
350 //_____________________________________________________________________
351 Bool_t AliTRDCalibPadStatus::TestEventHisto(Int_t nevent, Int_t sm) /*FOLD00*/
355 // fill one oroc and one iroc with random gaus
360 for (Int_t ism=sm; ism<sm+1; ism++){
361 for (Int_t ich=0; ich < 5; ich++){
362 for (Int_t ipl=0; ipl < 6; ipl++){
363 for(Int_t irow = 0; irow < fGeo->GetRowMax(ipl,ich,ism); irow++){
364 for(Int_t icol = 0; icol < fGeo->GetColMax(ipl); icol++){
365 for (Int_t iTimeBin=0; iTimeBin<(30*nevent); iTimeBin++){
366 Int_t signal=(Int_t)(gRandom->Gaus(10.0,1.2));
367 if ( signal>0 )UpdateHisto((ipl+ich*6+ism*6*5),irow,icol,signal,fGeo->GetRowMax(ipl,ich,ism),0,0);
377 //_____________________________________________________________________
378 TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, TObjArray *arr, /*FOLD00*/
379 Int_t nbinsY, Float_t ymin, Float_t ymax,
380 Char_t *type, Bool_t force)
383 // return pointer to histogram
384 // if force is true create a new histogram if it doesn't exist allready
386 if ( !force || arr->UncheckedAt(det) )
387 return (TH2F*)arr->UncheckedAt(det);
389 // if we are forced and histogram doesn't yes exist create it
390 Char_t name[255], title[255];
392 sprintf(name,"hCalib%s%.2d",type,det);
393 sprintf(title,"%s calibration histogram detector %.2d;ADC channel;Channel (pad)",type,det);
396 Int_t nbchannels = fGeo->GetRowMax(GetPlane(det),GetChamber(det),GetSector(det))*fGeo->GetColMax(GetPlane(det));
398 // we will add 3*8*rowMax channels at the end for the double counted
399 nbchannels += 3*8*(fGeo->GetRowMax(GetPlane(det),GetChamber(det),GetSector(det)));
402 // new histogram with calib information. One value for each pad!
403 TH2F* hist = new TH2F(name,title,
405 nbchannels,0,nbchannels
407 hist->SetDirectory(0);
408 arr->AddAt(hist,det);
412 //_____________________________________________________________________
413 TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, Bool_t force) /*FOLD00*/
416 // return pointer to histogram
417 // if force is true create a new histogram if it doesn't exist allready
419 TObjArray *arr = &fHistoArray;
420 return GetHisto(det, arr, fAdcMax-fAdcMin, fAdcMin, fAdcMax, "Pedestal", force);
423 //_____________________________________________________________________
424 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRoc(Int_t det, TObjArray* arr, Bool_t force) /*FOLD00*/
427 // return pointer to ROC Calibration
428 // if force is true create a new AliTRDCalROC if it doesn't exist allready
430 if ( !force || arr->UncheckedAt(det) )
431 return (AliTRDCalROC*)arr->UncheckedAt(det);
433 // if we are forced and histogram doesn't yes exist create it
435 // new AliTRDCalROC. One value for each pad!
436 AliTRDCalROC *croc = new AliTRDCalROC(GetPlane(det),GetChamber(det));
437 arr->AddAt(croc,det);
440 //_____________________________________________________________________
441 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocMean(Int_t det, Bool_t force) /*FOLD00*/
444 // return pointer to Carge ROC Calibration
445 // if force is true create a new histogram if it doesn't exist allready
447 TObjArray *arr = &fCalRocArrayMean;
448 return GetCalRoc(det, arr, force);
451 //_____________________________________________________________________
452 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocRMS(Int_t det, Bool_t force) /*FOLD00*/
455 // return pointer to Carge ROC Calibration
456 // if force is true create a new histogram if it doesn't exist allready
458 TObjArray *arr = &fCalRocArrayRMS;
459 return GetCalRoc(det, arr, force);
461 //_____________________________________________________________________
462 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocMeand(Int_t det, Bool_t force) /*FOLD00*/
465 // return pointer to Carge ROC Calibration
466 // if force is true create a new histogram if it doesn't exist allready
468 TObjArray *arr = &fCalRocArrayMeand;
469 return GetCalRoc(det, arr, force);
472 //_____________________________________________________________________
473 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocRMSd(Int_t det, Bool_t force) /*FOLD00*/
476 // return pointer to Carge ROC Calibration
477 // if force is true create a new histogram if it doesn't exist allready
479 TObjArray *arr = &fCalRocArrayRMSd;
480 return GetCalRoc(det, arr, force);
483 //_____________________________________________________________________
484 void AliTRDCalibPadStatus::AnalyseHisto() /*FOLD00*/
487 // Calculate calibration constants
490 Int_t nbinsAdc = fAdcMax-fAdcMin;
498 for (Int_t idet=0; idet<540; idet++){
499 TH2F *hP = GetHisto(idet);
504 AliTRDCalROC *rocMean = GetCalRocMean(idet,kTRUE);
505 AliTRDCalROC *rocRMS = GetCalRocRMS(idet,kTRUE);
507 array_hP = hP->GetArray();
508 Int_t nChannels = rocMean->GetNchannels();
510 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
511 Int_t offset = (nbinsAdc+2)*(iChannel+1)+1;
512 Double_t ret = AliMathBase::FitGaus(array_hP+offset,nbinsAdc,fAdcMin,fAdcMax,¶m,&dummy);
513 // if the fitting failed set noise and pedestal to 0
514 if ((ret==-4) || (ret==-1) || (ret==-2)) {
518 if((param[1]/10.0) > 65534.0) param[1] = 0.0;
519 if((param[2]/10.0) > 65534.0) param[2] = 0.0;
520 rocMean->SetValue(iChannel,param[1]/10.0);
521 rocRMS->SetValue(iChannel,param[2]/10.0);
524 // here we analyse doubled read channels
526 AliTRDCalROC *rocMeand = GetCalRocMeand(idet,kTRUE);
527 AliTRDCalROC *rocRMSd = GetCalRocRMSd(idet,kTRUE);
529 Int_t nrows = rocMeand->GetNrows();
530 Int_t shift = 144*nrows;
531 Int_t total = shift+3*8*nrows;
533 for (Int_t iChannel=shift; iChannel<total; iChannel++){
534 Int_t offset = (nbinsAdc+2)*(iChannel+1)+1;
535 Double_t ret = AliMathBase::FitGaus(array_hP+offset,nbinsAdc,fAdcMin,fAdcMax,¶m,&dummy);
536 // if the fitting failed set noise and pedestal to 0
537 if ((ret==-4) || (ret==-1) || (ret==-2)) {
541 if((param[1]/10.0) > 65534.0) param[1] = 0.0;
542 if((param[2]/10.0) > 65534.0) param[2] = 0.0;
544 // here we have to recalculate backward
545 Int_t nb = iChannel-shift;
546 Int_t row = nb%nrows;
547 Int_t j = (Int_t)(nb/nrows);
549 Int_t icol = (Int_t)(j/8);
551 Int_t finalcol = 18*imcm;
552 if(icol > 0) icol += 17;
556 Int_t channel = row+finalcol*nrows;
558 //printf("iChannel %d, nrows %d, finalcol %d, row %d, channel %d\n",iChannel,nrows,finalcol,row,channel);
559 if((finalcol < 0) || (finalcol >= 144)) continue;
561 rocMeand->SetValue(channel,param[1]/10.0);
562 rocRMSd->SetValue(channel,param[2]/10.0);
569 //_______________________________________________________________________________________
570 AliTRDCalPadStatus* AliTRDCalibPadStatus::CreateCalPadStatus()
573 // Create Pad Status out of Mean and RMS values
576 AliTRDCalPadStatus* obj = new AliTRDCalPadStatus("padstatus", "padstatus");
578 for (Int_t idet=0; idet<540; ++idet)
580 AliTRDCalSingleChamberStatus *calROC = obj->GetCalROC(idet);
583 AliTRDCalROC *calRocMean = ((AliTRDCalROC *)GetCalRocMean(idet));
584 AliTRDCalROC *calRocRMS = ((AliTRDCalROC *)GetCalRocRMS(idet));
586 //Take the stuff second chance
587 AliTRDCalROC *calRocMeand = ((AliTRDCalROC *)GetCalRocMeand(idet));
588 AliTRDCalROC *calRocRMSd = ((AliTRDCalROC *)GetCalRocRMSd(idet));
591 for(Int_t k = 0; k < calROC->GetNchannels(); k++){
592 calROC->SetStatus(k,AliTRDCalPadStatus::kMasked);
598 Int_t channels = calROC->GetNchannels();
600 Double_t rmsmean = calRocMean->GetRMS()*10.0;
601 Double_t meanmean = calRocMean->GetMean()*10.0;
602 Double_t meansquares = calRocRMS->GetMean()*10.0;
604 for(Int_t ich = 0; ich < channels; ich++){
606 Float_t mean = calRocMean->GetValue(ich)*10.0;
607 Float_t rms = calRocRMS->GetValue(ich)*10.0;
609 if((rms <= 0.0001) || (TMath::Abs(mean-meanmean)>(5*rmsmean)) || (TMath::Abs(rms)>(5.0*TMath::Abs(meansquares)))) {
610 // look at second chance
611 Float_t meand = calRocMeand->GetValue(ich)*10.0;
612 Float_t rmsd = calRocRMSd->GetValue(ich)*10.0;
614 if((rmsd <= 0.0001) || (TMath::Abs(meand-meanmean)>(5*rmsmean)) || (TMath::Abs(rmsd)>(5.0*TMath::Abs(meansquares)))) {
615 calROC->SetStatus(ich, AliTRDCalPadStatus::kMasked);
617 else calROC->SetStatus(ich, AliTRDCalPadStatus::kReadSecond);
626 //_______________________________________________________________________________________
627 AliTRDCalPad* AliTRDCalibPadStatus::CreateCalPad()
630 // Create Pad Noise out of RMS values
633 AliTRDCalPad* obj = new AliTRDCalPad("PadNoise", "PadNoise");
636 for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det) {
638 AliTRDCalROC *calROC22 = obj->GetCalROC(det);
640 AliTRDCalROC *calRocRMS = ((AliTRDCalROC *)GetCalRocRMS(det,kTRUE));
642 for(Int_t k = 0; k < calROC22->GetNchannels(); k++){
643 calROC22->SetValue(k,calRocRMS->GetValue(k));
652 //_______________________________________________________________________________________
653 AliTRDCalDet* AliTRDCalibPadStatus::CreateCalDet()
656 // Create Det Noise correction factor
659 AliTRDCalDet* obj = new AliTRDCalDet("DetNoise", "DetNoise (correction factor)");
661 for(Int_t l = 0; l < 540; l++){
662 obj->SetValue(l,10.0);
669 //_____________________________________________________________________
670 void AliTRDCalibPadStatus::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
673 // Write class to file
684 TDirectory *backup = gDirectory;
685 TFile f(filename,option.Data());
687 if ( !sDir.IsNull() ){
688 f.mkdir(sDir.Data());
694 if ( backup ) backup->cd();
697 //_____________________________________________________________________
698 void AliTRDCalibPadStatus::SetCalRocMean(AliTRDCalROC *mean, Int_t det) /*FOLD00*/
701 // Put the AliTRDCalROC in the array fCalRocArrayMean
705 AliTRDCalROC *rocMean = GetCalRocMean(det,kTRUE);
707 Int_t nChannels = rocMean->GetNchannels();
709 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
711 rocMean->SetValue(iChannel,mean->GetValue(iChannel));
717 //_____________________________________________________________________
718 void AliTRDCalibPadStatus::SetCalRocRMS(AliTRDCalROC *rms, Int_t det) /*FOLD00*/
721 // Put the AliTRDCalROC in the array fCalRocArrayRMS
725 AliTRDCalROC *rocRms = GetCalRocRMS(det,kTRUE);
727 Int_t nChannels = rocRms->GetNchannels();
729 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
731 rocRms->SetValue(iChannel,rms->GetValue(iChannel));
736 //_____________________________________________________________________
737 void AliTRDCalibPadStatus::SetCalRocMeand(AliTRDCalROC *mean, Int_t det) /*FOLD00*/
740 // Put the AliTRDCalROC in the array fCalRocArrayMean
744 AliTRDCalROC *rocMean = GetCalRocMeand(det,kTRUE);
746 Int_t nChannels = rocMean->GetNchannels();
748 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
750 rocMean->SetValue(iChannel,mean->GetValue(iChannel));
756 //_____________________________________________________________________
757 void AliTRDCalibPadStatus::SetCalRocRMSd(AliTRDCalROC *rms, Int_t det) /*FOLD00*/
760 // Put the AliTRDCalROC in the array fCalRocArrayRMS
764 AliTRDCalROC *rocRms = GetCalRocRMSd(det,kTRUE);
766 Int_t nChannels = rocRms->GetNchannels();
768 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
770 rocRms->SetValue(iChannel,rms->GetValue(iChannel));
775 //_____________________________________________________________________________
776 Int_t AliTRDCalibPadStatus::GetPlane(Int_t d) const
779 // Reconstruct the plane number from the detector number
782 return ((Int_t) (d % 6));
786 //_____________________________________________________________________________
787 Int_t AliTRDCalibPadStatus::GetChamber(Int_t d) const
790 // Reconstruct the chamber number from the detector number
793 return ((Int_t) (d % 30) / 6);
797 //_____________________________________________________________________________
798 Int_t AliTRDCalibPadStatus::GetSector(Int_t d) const
801 // Reconstruct the sector number from the detector number
804 return ((Int_t) (d / 30));