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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // TRD calibration class for parameters which saved per detector //
22 ///////////////////////////////////////////////////////////////////////////////
29 #include "AliTRDCalDet.h"
30 #include "AliTRDgeometry.h"
31 #include "AliMathBase.h"
32 #include "AliTRDpadPlane.h"
34 ClassImp(AliTRDCalDet)
36 //_____________________________________________________________________________
37 AliTRDCalDet::AliTRDCalDet():TNamed()
40 // AliTRDCalDet default constructor
43 for (Int_t idet = 0; idet < kNdet; idet++) {
49 //_____________________________________________________________________________
50 AliTRDCalDet::AliTRDCalDet(const Text_t *name, const Text_t *title)
54 // AliTRDCalDet constructor
57 for (Int_t idet = 0; idet < kNdet; idet++) {
63 //_____________________________________________________________________________
64 AliTRDCalDet::AliTRDCalDet(const AliTRDCalDet &c):TNamed(c)
67 // AliTRDCalDet copy constructor
70 ((AliTRDCalDet &) c).Copy(*this);
74 ///_____________________________________________________________________________
75 AliTRDCalDet::~AliTRDCalDet()
78 // AliTRDCalDet destructor
83 //_____________________________________________________________________________
84 AliTRDCalDet &AliTRDCalDet::operator=(const AliTRDCalDet &c)
87 // Assignment operator
90 if (this != &c) ((AliTRDCalDet &) c).Copy(*this);
95 //_____________________________________________________________________________
96 void AliTRDCalDet::Copy(TObject &c) const
102 for (Int_t idet = 0; idet < kNdet; idet++) {
103 ((AliTRDCalDet &) c).fData[idet] = fData[idet];
110 //___________________________________________________________________________________
111 Double_t AliTRDCalDet::GetMean(AliTRDCalDet * const outlierDet) const
114 // Calculate the mean
117 if (!outlierDet) return TMath::Mean(kNdet,fData);
118 Double_t *ddata = new Double_t[kNdet];
120 for (Int_t i=0;i<kNdet;i++) {
121 if (!(outlierDet->GetValue(i))) {
122 ddata[nPoints]= fData[nPoints];
126 Double_t mean = TMath::Mean(nPoints,ddata);
131 //_______________________________________________________________________________________
132 Double_t AliTRDCalDet::GetMedian(AliTRDCalDet * const outlierDet) const
135 // Calculate the median
138 if (!outlierDet) return (Double_t) TMath::Median(kNdet,fData);
139 Double_t *ddata = new Double_t[kNdet];
141 for (Int_t i=0;i<kNdet;i++) {
142 if (!(outlierDet->GetValue(i))) {
143 ddata[nPoints]= fData[nPoints];
147 Double_t mean = TMath::Median(nPoints,ddata);
153 //____________________________________________________________________________________________
154 Double_t AliTRDCalDet::GetRMS(AliTRDCalDet * const outlierDet) const
160 if (!outlierDet) return TMath::RMS(kNdet,fData);
161 Double_t *ddata = new Double_t[kNdet];
163 for (Int_t i=0;i<kNdet;i++) {
164 if (!(outlierDet->GetValue(i))) {
165 ddata[nPoints]= fData[nPoints];
169 Double_t mean = TMath::RMS(nPoints,ddata);
174 //____________________________________________________________________________________________
175 Double_t AliTRDCalDet::GetRMSRobust(Double_t robust) const
178 // Calculate the robust RMS
182 Int_t *index = new Int_t[kNdet];
183 TMath::Sort((Int_t)kNdet,fData,index);
186 Double_t reject = (Int_t) (kNdet*(1-robust)/2.0);
187 if(reject <= 0.0) reject = 0.0;
188 if(reject >= kNdet) reject = 0.0;
189 //printf("Rejecter %f\n",reject);
191 Double_t *ddata = new Double_t[kNdet];
193 for (Int_t i=0;i<kNdet;i++) {
195 for(Int_t k = 0; k < reject; k++){
196 if(i==index[k]) rej = kTRUE;
197 if(i==index[kNdet-(k+1)]) rej = kTRUE;
200 ddata[nPoints]= fData[i];
204 //printf("Number of points %d\n",nPoints);
205 Double_t mean = TMath::RMS(nPoints,ddata);
211 //______________________________________________________________________________________________
212 Double_t AliTRDCalDet::GetLTM(Double_t *sigma
214 , AliTRDCalDet * const outlierDet)
217 // Calculate LTM mean and sigma
220 Double_t *ddata = new Double_t[kNdet];
221 Double_t mean=0, lsigma=0;
223 for (Int_t i=0;i<kNdet;i++) {
224 if (!outlierDet || !(outlierDet->GetValue(i))) {
225 ddata[nPoints]= fData[nPoints];
229 Int_t hh = TMath::Min(TMath::Nint(fraction *nPoints), Int_t(nPoints));
230 AliMathBase::EvaluateUni(nPoints,ddata, mean, lsigma, hh);
231 if (sigma) *sigma=lsigma;
236 //_________________________________________________________________________
237 TH1F * AliTRDCalDet::MakeHisto1Distribution(Float_t min, Float_t max,Int_t type)
241 // type -1 = user defined range
242 // 0 = nsigma cut nsigma=min
243 // 1 = delta cut around median delta=min
249 Float_t mean = GetMean();
250 Float_t sigma = GetRMS();
251 Float_t nsigma = TMath::Abs(min);
252 min = mean-nsigma*sigma;
253 max = mean+nsigma*sigma;
257 Float_t mean = GetMedian();
264 // LTM mean +- nsigma
267 Float_t mean = GetLTM(&sigma,max);
274 snprintf(name,1000,"%s CalDet 1Distribution",GetTitle());
275 TH1F * his = new TH1F(name,name,100, min,max);
276 for (Int_t idet=0; idet<kNdet; idet++){
277 his->Fill(GetValue(idet));
282 //________________________________________________________________________________
283 TH1F * AliTRDCalDet::MakeHisto1DAsFunctionOfDet(Float_t min, Float_t max,Int_t type)
287 // type -1 = user defined range
288 // 0 = nsigma cut nsigma=min
289 // 1 = delta cut around median delta=min
295 Float_t mean = GetMean();
296 Float_t sigma = GetRMS();
297 Float_t nsigma = TMath::Abs(min);
298 min = mean-nsigma*sigma;
299 max = mean+nsigma*sigma;
303 Float_t mean = GetMedian();
310 Float_t mean = GetLTM(&sigma,max);
319 snprintf(name,1000,"%s CalDet as function of det",GetTitle());
320 TH1F * his = new TH1F(name,name,kNdet, 0, kNdet);
321 for(Int_t det = 0; det< kNdet; det++){
322 his->Fill(det+0.5,GetValue(det));
325 his->SetMaximum(max);
326 his->SetMinimum(min);
330 //_____________________________________________________________________________
331 TH2F *AliTRDCalDet::MakeHisto2DCh(Int_t ch, Float_t min, Float_t max, Int_t type)
336 // type -1 = user defined range
337 // 0 = nsigma cut nsigma=min
338 // 1 = delta cut around median delta=min
341 gStyle->SetPalette(1);
345 Float_t mean = GetMean();
346 Float_t sigma = GetRMS();
347 Float_t nsigma = TMath::Abs(min);
348 min = mean-nsigma*sigma;
349 max = mean+nsigma*sigma;
353 Float_t mean = GetMedian();
360 Float_t mean = GetLTM(&sigma,max);
368 AliTRDgeometry *trdGeo = new AliTRDgeometry();
370 Double_t poslocal[3] = {0.0,0.0,0.0};
371 Double_t posglobal[3] = {0.0,0.0,0.0};
374 snprintf(name,1000,"%s CalDet 2D ch %d",GetTitle(),ch);
375 TH2F * his = new TH2F(name, name, 400,-400.0,400.0,400,-400.0,400.0);
378 Int_t offsetch = 6*ch;
381 for (Int_t isec = 0; isec < kNsect; isec++){
382 for(Int_t ipl = 0; ipl < kNplan; ipl++){
383 Int_t det = offsetch+isec*30+ipl;
384 AliTRDpadPlane *padPlane = trdGeo->GetPadPlane(ipl,ch);
385 for (Int_t icol=0; icol<padPlane->GetNcols(); icol++){
386 poslocal[0] = trdGeo->GetTime0(ipl);
387 poslocal[2] = padPlane->GetRowPos(0);
388 poslocal[1] = padPlane->GetColPos(icol);
389 trdGeo->RotateBack(det,poslocal,posglobal);
390 Int_t binx = 1+TMath::Nint((posglobal[0]+400.0)*0.5);
391 Int_t biny = 1+TMath::Nint((posglobal[1]+400.0)*0.5);
392 his->SetBinContent(binx,biny,fData[det]);
396 his->SetXTitle("x (cm)");
397 his->SetYTitle("y (cm)");
399 his->SetMaximum(max);
400 his->SetMinimum(min);
405 //_____________________________________________________________________________
406 TH2F *AliTRDCalDet::MakeHisto2DSmPl(Int_t sm, Int_t pl, Float_t min, Float_t max, Int_t type)
410 // sm - supermodule number
412 // type -1 = user defined range
413 // 0 = nsigma cut nsigma=min
414 // 1 = delta cut around median delta=min
417 gStyle->SetPalette(1);
421 Float_t mean = GetMean();
422 Float_t sigma = GetRMS();
423 Float_t nsigma = TMath::Abs(min);
424 min = mean-nsigma*sigma;
425 max = mean+nsigma*sigma;
429 Float_t mean = GetMedian();
436 Float_t mean = GetLTM(&sigma,max);
444 AliTRDgeometry *trdGeo = new AliTRDgeometry();
445 AliTRDpadPlane *padPlane0 = trdGeo->GetPadPlane(pl,0);
446 Double_t row0 = padPlane0->GetRow0();
447 Double_t col0 = padPlane0->GetCol0();
450 snprintf(name,1000,"%s CalDet 2D sm %d and pl %d",GetTitle(),sm,pl);
451 TH2F * his = new TH2F( name, name, 5, -TMath::Abs(row0), TMath::Abs(row0)
452 , 4,-2*TMath::Abs(col0),2*TMath::Abs(col0));
455 Int_t offsetsmpl = 30*sm+pl;
458 for (Int_t k = 0; k < kNcham; k++){
459 Int_t det = offsetsmpl+k*6;
460 Int_t kb = kNcham-1-k;
461 his->SetBinContent(kb+1,2,fData[det]);
462 his->SetBinContent(kb+1,3,fData[det]);
464 his->SetXTitle("z (cm)");
465 his->SetYTitle("y (cm)");
467 his->SetMaximum(max);
468 his->SetMinimum(min);
473 //_____________________________________________________________________________
474 void AliTRDCalDet::Add(Float_t c1)
477 // Add constant for all detectors
480 for (Int_t idet = 0; idet < kNdet; idet++) {
485 //_____________________________________________________________________________
486 void AliTRDCalDet::Multiply(Float_t c1)
489 // multiply constant for all detectors
491 for (Int_t idet = 0; idet < kNdet; idet++) {
496 //_____________________________________________________________________________
497 void AliTRDCalDet::Add(const AliTRDCalDet * calDet, Double_t c1)
500 // add caldet channel by channel multiplied by c1
502 for (Int_t idet = 0; idet < kNdet; idet++) {
503 fData[idet] += calDet->GetValue(idet)*c1;
507 //_____________________________________________________________________________
508 void AliTRDCalDet::Multiply(const AliTRDCalDet * calDet)
511 // multiply caldet channel by channel
513 for (Int_t idet = 0; idet < kNdet; idet++) {
514 fData[idet] *= calDet->GetValue(idet);
518 //_____________________________________________________________________________
519 void AliTRDCalDet::Divide(const AliTRDCalDet * calDet)
522 // divide caldet channel by channel
524 Float_t kEpsilon=0.00000000000000001;
525 for (Int_t idet = 0; idet < kNdet; idet++) {
526 if (TMath::Abs(calDet->GetValue(idet))>kEpsilon){
527 fData[idet] /= calDet->GetValue(idet);
531 //_____________________________________________________________________________
532 Double_t AliTRDCalDet::CalcMean(Bool_t wghtPads, Int_t &calib)
534 // Calculate the mean value after rejection of the chambers not calibrated
535 // wghPads = kTRUE weighted with the number of pads in case of a AliTRDCalPad created (t0)
536 // calib = number of used chambers for the mean calculation
541 Double_t meanALL = 0.0;
542 Double_t meanWP = 0.0;
544 Double_t padsALL=(144*16*24+144*12*6)*18;
545 Double_t *meanSM = new Double_t[18];
546 Double_t *meanSMWP = new Double_t[18];
548 for (Int_t i = 0; i < 18; i++) {
555 Float_t val= fData[det];
556 iSM = (Int_t)(det / (6*5));
557 pads=(((Int_t) (det % (6 * 5)) / 6) == 2) ? 144*12 : 144*16;
559 meanSM[iSM]+=val/30.;
560 meanWP+=val*(pads/padsALL);
561 meanSMWP[iSM]+=val*(pads/(padsALL/18.));
564 printf(" det %d val %.3f meanALL %.5f meanWP %.5f meanSM[%d] %.5f meanSMWP[%d] %.5f \n",
580 printf(" ALL %.5f \n",meanALL);
581 printf(" WP %.5f \n",meanWP);
582 for(Int_t i=0; i<18; i++) printf(" SM %02d %.5f \n",i,meanSM[i]);
583 for(Int_t i=0; i<18; i++) printf(" SM %02d %.5f \n",i,meanSMWP[i]);
588 Float_t val= fData[det];
590 (TMath::Abs(val - meanALL) > 0.0001) &&
591 (TMath::Abs(val - meanSM[(Int_t)(det / (6*5))]) > 0.0001) ) ||
593 (TMath::Abs(val - meanWP) > 0.0001) &&
594 (TMath::Abs(val - meanSMWP[(Int_t)(det / (6*5) )]) > 0.0001) )
606 return (sum!=0.0 ? sum/ndet : -1);
608 //_____________________________________________________________________________
609 Double_t AliTRDCalDet::CalcMean(Bool_t wghtPads)
611 // Calculate the mean value after rejection of the chambers not calibrated
612 // wghPads = kTRUE weighted with the number of pads in case of a AliTRDCalPad created (t0)
613 // calib = number of used chambers for the mean calculation
618 Double_t meanALL = 0.0;
619 Double_t meanWP = 0.0;
621 Double_t padsALL=(144*16*24+144*12*6)*18;
622 Double_t *meanSM = new Double_t[18];
623 Double_t *meanSMWP = new Double_t[18];
625 for (Int_t i = 0; i < 18; i++) {
632 Float_t val= fData[det];
633 iSM = (Int_t)(det / (6*5));
634 pads=(((Int_t) (det % (6 * 5)) / 6) == 2) ? 144*12 : 144*16;
636 meanSM[iSM]+=val/30.;
637 meanWP+=val*(pads/padsALL);
638 meanSMWP[iSM]+=val*(pads/(padsALL/18.));
641 printf(" det %d val %.3f meanALL %.5f meanWP %.5f meanSM[%d] %.5f meanSMWP[%d] %.5f \n",
657 printf(" ALL %.5f \n",meanALL);
658 printf(" WP %.5f \n",meanWP);
659 for(Int_t i=0; i<18; i++) printf(" SM %02d %.5f \n",i,meanSM[i]);
660 for(Int_t i=0; i<18; i++) printf(" SM %02d %.5f \n",i,meanSMWP[i]);
665 Float_t val= fData[det];
667 (TMath::Abs(val - meanALL) > 0.0001) &&
668 (TMath::Abs(val - meanSM[(Int_t)(det / (6*5))]) > 0.0001) ) ||
670 (TMath::Abs(val - meanWP) > 0.0001) &&
671 (TMath::Abs(val - meanSMWP[(Int_t)(det / (6*5) )]) > 0.0001) )
682 return (sum!=0.0 ? sum/ndet : -1);
684 //_____________________________________________________________________________
685 Double_t AliTRDCalDet::CalcRMS(Bool_t wghtPads, Int_t &calib)
687 // Calculate the RMS value after rejection of the chambers not calibrated
688 // wghPads = kTRUE weighted with the number of pads in case of a AliTRDCalPad created (t0)
689 // calib = number of used chambers for the mean calculation
694 Double_t meanALL = 0.0;
695 Double_t meanWP = 0.0;
697 Double_t padsALL=(144*16*24+144*12*6)*18;
698 Double_t *meanSM = new Double_t[18];
699 Double_t *meanSMWP = new Double_t[18];
701 for (Int_t i = 0; i < 18; i++) {
708 Float_t val= fData[det];
709 iSM = (Int_t)(det / (6*5));
710 pads=(((Int_t) (det % (6 * 5)) / 6) == 2) ? 144*12 : 144*16;
712 meanSM[iSM]+=val/30.;
713 meanWP+=val*(pads/padsALL);
714 meanSMWP[iSM]+=val*(pads/(padsALL/18.));
719 if(!wghtPads) mean= meanALL;
720 if(wghtPads) mean= meanWP;
724 Float_t val= fData[det];
726 (TMath::Abs(val - meanALL) > 0.0001) &&
727 (TMath::Abs(val - meanSM[(Int_t)(det / (6*5))]) > 0.0001) ) ||
729 (TMath::Abs(val - meanWP) > 0.0001) &&
730 (TMath::Abs(val - meanSMWP[(Int_t)(det / (6*5) )]) > 0.0001) )
732 sum+=(val-mean)*(val-mean);
742 return (sum!=0.0 ? TMath::Sqrt(sum/ndet) : -1);
744 //_____________________________________________________________________________
745 Double_t AliTRDCalDet::CalcRMS(Bool_t wghtPads)
747 // Calculate the RMS value after rejection of the chambers not calibrated
748 // wghPads = kTRUE weighted with the number of pads in case of a AliTRDCalPad created (t0)
749 // calib = number of used chambers for the mean calculation
754 Double_t meanALL = 0.0;
755 Double_t meanWP = 0.0;
757 Double_t padsALL=(144*16*24+144*12*6)*18;
758 Double_t *meanSM = new Double_t[18];
759 Double_t *meanSMWP = new Double_t[18];
761 for (Int_t i = 0; i < 18; i++) {
768 Float_t val= fData[det];
769 iSM = (Int_t)(det / (6*5));
770 pads=(((Int_t) (det % (6 * 5)) / 6) == 2) ? 144*12 : 144*16;
772 meanSM[iSM]+=val/30.;
773 meanWP+=val*(pads/padsALL);
774 meanSMWP[iSM]+=val*(pads/(padsALL/18.));
779 if(!wghtPads) mean= meanALL;
780 if(wghtPads) mean= meanWP;
784 Float_t val= fData[det];
786 (TMath::Abs(val - meanALL) > 0.0001) &&
787 (TMath::Abs(val - meanSM[(Int_t)(det / (6*5))]) > 0.0001) ) ||
789 (TMath::Abs(val - meanWP) > 0.0001) &&
790 (TMath::Abs(val - meanSMWP[(Int_t)(det / (6*5) )]) > 0.0001) )
792 sum+=(val-mean)*(val-mean);
801 return (sum!=0.0 ? TMath::Sqrt(sum/ndet) : -1);