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 gausschen 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 <AliMathBase.h>
66 #include "TTreeStream.h"
69 #include "AliRawReader.h"
70 #include "AliRawReaderRoot.h"
71 #include "AliRawReaderDate.h"
73 #include "AliTRDRawStream.h"
74 #include "AliTRDarrayF.h"
75 #include "AliTRDgeometry.h"
76 #include "./Cal/AliTRDCalROC.h"
77 #include "./Cal/AliTRDCalPadStatus.h"
78 #include "./Cal/AliTRDCalSingleChamberStatus.h"
85 #include "AliTRDCalibPadStatus.h"
87 ClassImp(AliTRDCalibPadStatus) /*FOLD00*/
89 //_____________________________________________________________________
90 AliTRDCalibPadStatus::AliTRDCalibPadStatus() : /*FOLD00*/
97 fCalArrayEntries(540),
99 fCalArraySquares(540),
100 fCalRocArrayMean(540),
101 fCalRocArrayRMS(540),
108 // default constructor
111 fGeo = new AliTRDgeometry();
115 //_____________________________________________________________________
116 AliTRDCalibPadStatus::AliTRDCalibPadStatus(const AliTRDCalibPadStatus &ped) : /*FOLD00*/
119 fAdcMin(ped.GetAdcMin()),
120 fAdcMax(ped.GetAdcMax()),
121 fDetector(ped.fDetector),
122 fNumberOfTimeBins(ped.fNumberOfTimeBins),
123 fCalArrayEntries(540),
125 fCalArraySquares(540),
126 fCalRocArrayMean(540),
127 fCalRocArrayRMS(540),
136 for (Int_t idet = 0; idet < 540; idet++){
137 const AliTRDarrayF *calEntries = (AliTRDarrayF*)ped.fCalArrayEntries.UncheckedAt(idet);
138 const AliTRDarrayF *calMean = (AliTRDarrayF*)ped.fCalArrayMean.UncheckedAt(idet);
139 const AliTRDarrayF *calSquares = (AliTRDarrayF*)ped.fCalArraySquares.UncheckedAt(idet);
140 const AliTRDCalROC *calRocMean = (AliTRDCalROC*)ped.fCalRocArrayMean.UncheckedAt(idet);
141 const AliTRDCalROC *calRocRMS = (AliTRDCalROC*)ped.fCalRocArrayRMS.UncheckedAt(idet);
142 const TH2F *hped = (TH2F*)ped.fHistoArray.UncheckedAt(idet);
144 if ( calEntries != 0x0 ) fCalArrayEntries.AddAt(new AliTRDarrayF(*calEntries), idet);
145 if ( calMean != 0x0 ) fCalArrayMean.AddAt(new AliTRDarrayF(*calMean), idet);
146 if ( calSquares != 0x0 ) fCalArraySquares.AddAt(new AliTRDarrayF(*calSquares), idet);
147 if ( calRocMean != 0x0 ) fCalRocArrayMean.AddAt(new AliTRDCalROC(*calRocMean), idet);
148 if ( calRocRMS != 0x0 ) fCalRocArrayRMS.AddAt(new AliTRDCalROC(*calRocRMS), idet);
151 TH2F *hNew = new TH2F(*hped);
152 hNew->SetDirectory(0);
153 fHistoArray.AddAt(hNew,idet);
161 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*/
190 //_____________________________________________________________________
191 Int_t AliTRDCalibPadStatus::Update(const Int_t icdet, /*FOLD00*/
198 // Signal filling methode
200 if ( (csignal>fAdcMax) || (csignal<fAdcMin) ) return 0;
202 if(fDetector != icdet){
203 fCalEntries = ((AliTRDarrayF *)GetCalEntries(icdet,kTRUE));
204 fCalMean = ((AliTRDarrayF *)GetCalMean(icdet,kTRUE));
205 fCalSquares = ((AliTRDarrayF *)GetCalSquares(icdet,kTRUE));
208 Float_t entries = fCalEntries->At(icRow+icCol*crowMax);
209 Float_t mean = fCalMean->At(icRow+icCol*crowMax);
210 Float_t squares = fCalSquares->At(icRow+icCol*crowMax);
212 Float_t entriesn = entries+1.0;
213 fCalEntries->AddAt(entriesn,(icRow+icCol*crowMax));
214 Float_t meann = (mean*entries+((Float_t)(csignal+0.5)))/entriesn;
215 fCalMean->AddAt(meann,icRow+icCol*crowMax);
216 Float_t squaresn = ((squares*entries)+(((Float_t)(csignal+0.5))*((Float_t)(csignal+0.5))))/entriesn;
217 fCalSquares->AddAt(squaresn,icRow+icCol*crowMax);
219 //printf("icdet %d, icRow %d, icCol %d, csignal %d, crowMax %d\n",icdet,icRow,icCol,csignal,crowMax);
220 //printf("entries %f, mean %f, squares %f\n",entriesn,meann,squaresn);
226 //_____________________________________________________________________
227 Int_t AliTRDCalibPadStatus::UpdateHisto(const Int_t icdet, /*FOLD00*/
234 // Signal filling methode
236 Int_t nbchannel = icRow+icCol*crowMax;
238 // fast filling methode.
239 // Attention: the entry counter of the histogram is not increased
240 // this means that e.g. the colz draw option gives an empty plot
242 if ( !(((Int_t)csignal>fAdcMax ) || ((Int_t)csignal<fAdcMin)) )
243 bin = (nbchannel+1)*(fAdcMax-fAdcMin+2)+((Int_t)csignal-fAdcMin+1);
245 GetHisto(icdet,kTRUE)->GetArray()[bin]++;
249 //_____________________________________________________________________
250 Bool_t AliTRDCalibPadStatus::ProcessEvent(AliTRDRawStream *rawStream, Bool_t nocheck)
253 // Event Processing loop - AliTRDRawStream
257 Bool_t withInput = kFALSE;
260 while (rawStream->Next()) {
261 Int_t rawversion = rawStream->GetRawVersion(); // current raw version
262 if(rawversion != 2) return kFALSE;
263 Int_t idetector = rawStream->GetDet(); // current detector
264 Int_t iRow = rawStream->GetRow(); // current row
265 Int_t iRowMax = rawStream->GetMaxRow(); // current rowmax
266 Int_t iCol = rawStream->GetCol(); // current col
267 Int_t iTimeBin = rawStream->GetTimeBin(); // current time bin
268 Int_t *signal = rawStream->GetSignals(); // current ADC signal
269 Int_t nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
271 if((fDetector != -1) && (nbtimebin != fNumberOfTimeBins)) return kFALSE;
272 fNumberOfTimeBins = nbtimebin;
274 Int_t fin = TMath::Min(nbtimebin,(iTimeBin+3));
277 for(Int_t k = iTimeBin; k < fin; k++){
278 if(signal[n]>0) UpdateHisto(idetector,iRow,iCol,signal[n],iRowMax);
286 while (rawStream->Next()) {
287 Int_t idetector = rawStream->GetDet(); // current detector
288 Int_t iRow = rawStream->GetRow(); // current row
289 Int_t iRowMax = rawStream->GetMaxRow(); // current rowmax
290 Int_t iCol = rawStream->GetCol(); // current col
291 Int_t iTimeBin = rawStream->GetTimeBin(); // current time bin
292 Int_t *signal = rawStream->GetSignals(); // current ADC signal
293 Int_t nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
295 Int_t fin = TMath::Min(nbtimebin,(iTimeBin+3));
298 for(Int_t k = iTimeBin; k < fin; k++){
299 if(signal[n]>0) UpdateHisto(idetector,iRow,iCol,signal[n],iRowMax);
309 //_____________________________________________________________________
310 Bool_t AliTRDCalibPadStatus::ProcessEvent(AliRawReader *rawReader, Bool_t nocheck)
313 // Event processing loop - AliRawReader
317 AliTRDRawStream rawStream(rawReader);
319 rawReader->Select("TRD");
321 return ProcessEvent(&rawStream, nocheck);
323 //_________________________________________________________________________
324 Bool_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");
349 //_____________________________________________________________________
350 Bool_t AliTRDCalibPadStatus::TestEvent(Int_t nevent) /*FOLD00*/
354 // fill one oroc and one iroc with random gaus
359 for (Int_t ism=0; ism<18; ism++){
360 for (Int_t ich=0; ich < 5; ich++){
361 for (Int_t ipl=0; ipl < 6; ipl++){
362 for(Int_t irow = 0; irow < fGeo->GetRowMax(ipl,ich,ism); irow++){
363 for(Int_t icol = 0; icol < fGeo->GetColMax(ipl); icol++){
364 for (Int_t iTimeBin=0; iTimeBin<(30*nevent); iTimeBin++){
365 Int_t signal=(Int_t)(ich+8+gRandom->Gaus(0,1.2));
366 if ( signal>0 )Update((ipl+ich*6+ism*6*5),irow,icol,signal,fGeo->GetRowMax(ipl,ich,ism));
375 //_____________________________________________________________________
376 Bool_t AliTRDCalibPadStatus::TestEventHisto(Int_t nevent) /*FOLD00*/
380 // fill one oroc and one iroc with random gaus
385 for (Int_t ism=0; ism<18; ism++){
386 for (Int_t ich=0; ich < 5; ich++){
387 for (Int_t ipl=0; ipl < 6; ipl++){
388 for(Int_t irow = 0; irow < fGeo->GetRowMax(ipl,ich,ism); irow++){
389 for(Int_t icol = 0; icol < fGeo->GetColMax(ipl); icol++){
390 for (Int_t iTimeBin=0; iTimeBin<(30*nevent); iTimeBin++){
391 Int_t signal=(Int_t)(ich+8+gRandom->Gaus(0,1.2));
392 if ( signal>0 )UpdateHisto((ipl+ich*6+ism*6*5),irow,icol,signal,fGeo->GetRowMax(ipl,ich,ism));
401 //_____________________________________________________________________
402 TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, TObjArray *arr, /*FOLD00*/
403 Int_t nbinsY, Float_t ymin, Float_t ymax,
404 Char_t *type, Bool_t force)
407 // return pointer to histogram
408 // if force is true create a new histogram if it doesn't exist allready
410 if ( !force || arr->UncheckedAt(det) )
411 return (TH2F*)arr->UncheckedAt(det);
413 // if we are forced and histogram doesn't yes exist create it
414 Char_t name[255], title[255];
416 sprintf(name,"hCalib%s%.2d",type,det);
417 sprintf(title,"%s calibration histogram detector %.2d;ADC channel;Channel (pad)",type,det);
419 Int_t nbchannels = fGeo->GetRowMax(GetPlane(det),GetChamber(det),GetSector(det))
420 * fGeo->GetColMax(GetPlane(det));
422 // new histogram with calib information. One value for each pad!
423 TH2F* hist = new TH2F(name,title,
425 nbchannels,0,nbchannels
427 hist->SetDirectory(0);
428 arr->AddAt(hist,det);
431 //_____________________________________________________________________
432 TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, Bool_t force) /*FOLD00*/
435 // return pointer to histogram
436 // if force is true create a new histogram if it doesn't exist allready
438 TObjArray *arr = &fHistoArray;
439 return GetHisto(det, arr, fAdcMax-fAdcMin, fAdcMin, fAdcMax, "Pedestal", force);
441 //_____________________________________________________________________
442 AliTRDarrayF* AliTRDCalibPadStatus::GetCal(Int_t det, TObjArray* arr, Bool_t force) /*FOLD00*/
445 // return pointer to ROC Calibration
446 // if force is true create a new AliTRDarrayF if it doesn't exist allready
448 if ( !force || arr->UncheckedAt(det) )
449 return (AliTRDarrayF*)arr->UncheckedAt(det);
451 // if we are forced and histogram doesn't yes exist create it
452 AliTRDarrayF *croc = new AliTRDarrayF();
453 Int_t nbpad = fGeo->GetRowMax(GetPlane(det),GetChamber(det),GetSector(det))
454 * fGeo->GetColMax(GetPlane(det));
456 // new AliTRDCalROC. One value for each pad!
458 for(Int_t k = 0; k < nbpad; k++){
461 arr->AddAt(croc,det);
464 //_____________________________________________________________________
465 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRoc(Int_t det, TObjArray* arr, Bool_t force) /*FOLD00*/
468 // return pointer to ROC Calibration
469 // if force is true create a new AliTRDCalROC if it doesn't exist allready
471 if ( !force || arr->UncheckedAt(det) )
472 return (AliTRDCalROC*)arr->UncheckedAt(det);
474 // if we are forced and histogram doesn't yes exist create it
476 // new AliTRDCalROC. One value for each pad!
477 AliTRDCalROC *croc = new AliTRDCalROC(GetPlane(det),GetChamber(det));
478 arr->AddAt(croc,det);
481 //_____________________________________________________________________
482 AliTRDarrayF* AliTRDCalibPadStatus::GetCalEntries(Int_t det, Bool_t force) /*FOLD00*/
485 // return pointer to Carge ROC Calibration
486 // if force is true create a new histogram if it doesn't exist allready
488 TObjArray *arr = &fCalArrayEntries;
489 return GetCal(det, arr, force);
491 //_____________________________________________________________________
492 AliTRDarrayF* AliTRDCalibPadStatus::GetCalMean(Int_t det, Bool_t force) /*FOLD00*/
495 // return pointer to Carge ROC Calibration
496 // if force is true create a new histogram if it doesn't exist allready
498 TObjArray *arr = &fCalArrayMean;
499 return GetCal(det, arr, force);
501 //_____________________________________________________________________
502 AliTRDarrayF* AliTRDCalibPadStatus::GetCalSquares(Int_t det, Bool_t force) /*FOLD00*/
505 // return pointer to Carge ROC Calibration
506 // if force is true create a new histogram if it doesn't exist allready
508 TObjArray *arr = &fCalArraySquares;
509 return GetCal(det, arr, force);
511 //_____________________________________________________________________
512 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocMean(Int_t det, Bool_t force) /*FOLD00*/
515 // return pointer to Carge ROC Calibration
516 // if force is true create a new histogram if it doesn't exist allready
518 TObjArray *arr = &fCalRocArrayMean;
519 return GetCalRoc(det, arr, force);
521 //_____________________________________________________________________
522 AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocRMS(Int_t det, Bool_t force) /*FOLD00*/
525 // return pointer to Carge ROC Calibration
526 // if force is true create a new histogram if it doesn't exist allready
528 TObjArray *arr = &fCalRocArrayRMS;
529 return GetCalRoc(det, arr, force);
531 //_________________________________________________________________________
532 void AliTRDCalibPadStatus::Analyse() /*FOLD00*/
535 // Calcul the rms properly
538 for(Int_t idet = 0; idet < 540; idet++){
541 fCalEntries = ((AliTRDarrayF *)GetCalEntries(idet));
542 fCalMean = ((AliTRDarrayF *)GetCalMean(idet));
543 fCalSquares = ((AliTRDarrayF *)GetCalSquares(idet));
545 if(!fCalEntries) continue;
547 AliTRDCalROC *calRocMean = ((AliTRDCalROC *)GetCalRocMean(idet,kTRUE));
548 AliTRDCalROC *calRocRMS = ((AliTRDCalROC *)GetCalRocRMS(idet,kTRUE));
551 Int_t channels = calRocMean->GetNchannels();
553 for(Int_t ichannels = 0 ; ichannels < channels; ichannels++){
555 Float_t entries = fCalEntries->At(ichannels);
556 Float_t mean = fCalMean->At(ichannels);
557 Float_t squares = fCalSquares->At(ichannels);
561 Double_t rm = TMath::Abs(squares-(mean*mean));
562 rms = TMath::Sqrt(rm);
563 calRocRMS->SetValue(ichannels,rms/10.0);
564 calRocMean->SetValue(ichannels,mean/10.0);
569 //_____________________________________________________________________
570 void AliTRDCalibPadStatus::AnalyseHisto() /*FOLD00*/
573 // Calculate calibration constants
576 Int_t nbinsAdc = fAdcMax-fAdcMin;
584 for (Int_t idet=0; idet<540; idet++){
585 TH2F *hP = GetHisto(idet);
590 AliTRDCalROC *rocMean = GetCalRocMean(idet,kTRUE);
591 AliTRDCalROC *rocRMS = GetCalRocRMS(idet,kTRUE);
593 array_hP = hP->GetArray();
594 Int_t nChannels = rocMean->GetNchannels();
596 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
597 Int_t offset = (nbinsAdc+2)*(iChannel+1)+1;
598 Double_t ret = AliMathBase::FitGaus(array_hP+offset,nbinsAdc,fAdcMin,fAdcMax,¶m,&dummy);
599 // if the fitting failed set noise and pedestal to 0
600 if ((ret == -4) || (ret == -1)) {
604 if((param[1]/10.0) > 65534.0) param[1] = 0.0;
605 if((param[2]/10.0) > 65534.0) param[2] = 0.0;
606 rocMean->SetValue(iChannel,param[1]/10.0);
607 rocRMS->SetValue(iChannel,param[2]/10.0);
612 //_______________________________________________________________________________________
613 AliTRDCalPadStatus* AliTRDCalibPadStatus::CreateCalPadStatus()
619 AliTRDCalPadStatus* obj = new AliTRDCalPadStatus("padstatus", "padstatus");
621 for (Int_t idet=0; idet<540; ++idet)
623 AliTRDCalSingleChamberStatus *calROC = obj->GetCalROC(idet);
626 fCalEntries = ((AliTRDarrayF *)GetCalEntries(idet));
627 AliTRDCalROC *calRocMean = ((AliTRDCalROC *)GetCalRocMean(idet));
628 AliTRDCalROC *calRocRMS = ((AliTRDCalROC *)GetCalRocRMS(idet));
631 for(Int_t k = 0; k < calROC->GetNchannels(); k++){
632 calROC->SetStatus(k,AliTRDCalPadStatus::kMasked);
634 //printf("no fCalRocMean for %d\n",idet);
639 Int_t channels = calROC->GetNchannels();
643 Float_t meanentries = 0.0;
646 meanentries = GetHisto(idet)->GetEntries()/(channels);
649 else meanentries = TMath::Mean(channels,((TArrayF *)fCalEntries)->GetArray());
650 //Double_t meanmean = calRocMean->GetMean()*10.0;
651 //Double_t meansquares = calRocRMS->GetMean()*10.0;
654 for(Int_t ich = 0; ich < channels; ich++){
656 Float_t entries = 0.0;
659 for(Int_t bin = 0; bin < (fAdcMax-fAdcMin); bin++){
660 entries += GetHisto(idet)->GetArray()[(ich+1)*(fAdcMax-fAdcMin+2)+(bin+1)];
664 else entries = fCalEntries->At(ich);
665 //Float_t mean = calRocMean->GetValue(ich)*10.0;
666 Float_t rms = calRocRMS->GetValue(ich)*10.0;
667 if(ich > 1720) printf("rms %f\n",rms);
669 //if((entries < 0.3*meanentries) || (TMath::Abs(rms-meansquares) > ((Float_t)(fAdcMax-fAdcMin)/2.0)) || (rms == 0.0)) calROC->SetStatus(ich, AliTRDCalPadStatus::kMasked);
670 if(rms <= 0.01) calROC->SetStatus(ich, AliTRDCalPadStatus::kMasked);
677 //_____________________________________________________________________
678 void AliTRDCalibPadStatus::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
681 // Write class to file
692 TDirectory *backup = gDirectory;
693 TFile f(filename,option.Data());
695 if ( !sDir.IsNull() ){
696 f.mkdir(sDir.Data());
702 if ( backup ) backup->cd();
703 }//_____________________________________________________________________________
704 Int_t AliTRDCalibPadStatus::GetPlane(Int_t d) const
707 // Reconstruct the plane number from the detector number
710 return ((Int_t) (d % 6));
714 //_____________________________________________________________________________
715 Int_t AliTRDCalibPadStatus::GetChamber(Int_t d) const
718 // Reconstruct the chamber number from the detector number
721 return ((Int_t) (d % 30) / 6);
724 //_____________________________________________________________________________
725 Int_t AliTRDCalibPadStatus::GetSector(Int_t d) const
728 // Reconstruct the sector number from the detector number
731 return ((Int_t) (d / 30));