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 pad //
22 ///////////////////////////////////////////////////////////////////////////////
29 #include "AliTRDCalPad.h"
30 #include "AliTRDCalROC.h"
31 #include "AliTRDCalDet.h"
32 #include "AliTRDpadPlane.h"
33 #include "AliMathBase.h"
34 #include "AliTRDgeometry.h"
36 ClassImp(AliTRDCalPad)
38 //_____________________________________________________________________________
39 AliTRDCalPad::AliTRDCalPad():TNamed()
42 // AliTRDCalPad default constructor
45 for (Int_t idet = 0; idet < kNdet; idet++) {
51 //_____________________________________________________________________________
52 AliTRDCalPad::AliTRDCalPad(const Text_t *name, const Text_t *title)
56 // AliTRDCalPad constructor
59 for (Int_t isec = 0; isec < kNsect; isec++) {
60 for (Int_t ipla = 0; ipla < kNplan; ipla++) {
61 for (Int_t icha = 0; icha < kNcham; icha++) {
62 Int_t idet = GetDet(ipla,icha,isec);
63 fROC[idet] = new AliTRDCalROC(ipla,icha);
70 //_____________________________________________________________________________
71 AliTRDCalPad::AliTRDCalPad(const AliTRDCalPad &c)
75 // AliTRDCalPad copy constructor
78 for (Int_t idet = 0; idet < kNdet; idet++) {
79 fROC[idet] = new AliTRDCalROC(*((AliTRDCalPad &) c).fROC[idet]);
84 //_____________________________________________________________________________
85 AliTRDCalPad::~AliTRDCalPad()
88 // AliTRDCalPad destructor
91 for (Int_t idet = 0; idet < kNdet; idet++) {
100 //_____________________________________________________________________________
101 AliTRDCalPad &AliTRDCalPad::operator=(const AliTRDCalPad &c)
104 // Assignment operator
107 if (this != &c) ((AliTRDCalPad &) c).Copy(*this);
112 //_____________________________________________________________________________
113 void AliTRDCalPad::Copy(TObject &c) const
119 for (Int_t idet = 0; idet < kNdet; idet++) {
120 if (((AliTRDCalPad &) c).fROC[idet]) {
121 delete ((AliTRDCalPad &) c).fROC[idet];
123 ((AliTRDCalPad &) c).fROC[idet] = new AliTRDCalROC();
125 fROC[idet]->Copy(*((AliTRDCalPad &) c).fROC[idet]);
133 //_____________________________________________________________________________
134 Bool_t AliTRDCalPad::ScaleROCs(const AliTRDCalDet* values)
137 // Scales ROCs of this class with the values from the class <values>
138 // Is used if an AliTRDCalPad object defines local variations of a parameter
139 // defined per detector using a AliTRDCalDet class
144 Bool_t result = kTRUE;
145 for (Int_t idet = 0; idet < kNdet; idet++) {
147 if(!fROC[idet]->Multiply(values->GetValue(idet))) result = kFALSE;
153 //_____________________________________________________________________________
154 Double_t AliTRDCalPad::GetMeanRMS(Double_t &rms, const AliTRDCalDet *calDet, Int_t type)
157 // Calculate mean an RMS of all rocs
158 // If calDet correct the CalROC from the detector coefficient
159 // type == 0 for gain and vdrift
162 Double_t factor = 0.0;
163 if(type == 0) factor = 1.0;
164 Double_t sum = 0, sum2 = 0, n=0, val=0;
165 for (Int_t idet = 0; idet < kNdet; idet++) {
166 if(calDet) factor = calDet->GetValue(idet);
167 AliTRDCalROC *calRoc = fROC[idet];
169 for (Int_t irow=0; irow<calRoc->GetNrows(); irow++){
170 for (Int_t icol=0; icol<calRoc->GetNcols(); icol++){
171 if(type == 0) val = calRoc->GetValue(icol,irow)*factor;
172 else val = calRoc->GetValue(icol,irow)+factor;
181 Double_t mean = sum*n1;
182 rms = TMath::Sqrt(TMath::Abs(sum2*n1-mean*mean));
186 //_____________________________________________________________________________
187 Double_t AliTRDCalPad::GetMean(const AliTRDCalDet *calDet, Int_t type, AliTRDCalPad* outlierPad)
190 // return mean of the mean of all ROCs
191 // If calDet correct the CalROC from the detector coefficient
192 // type == 0 for gain and vdrift
195 Double_t factor = 0.0;
196 if(type == 0) factor = 1.0;
199 for (Int_t idet = 0; idet < kNdet; idet++) {
200 if(calDet) factor = calDet->GetValue(idet);
201 AliTRDCalROC *calRoc = fROC[idet];
203 AliTRDCalROC* outlierROC = 0;
204 if (outlierPad) outlierROC = outlierPad->GetCalROC(idet);
205 if(type == 0) arr[n] = calRoc->GetMean(outlierROC)*factor;
206 else arr[n] = calRoc->GetMean(outlierROC)+factor;
210 return TMath::Mean(n,arr);
213 //_____________________________________________________________________________
214 Double_t AliTRDCalPad::GetRMS(const AliTRDCalDet *calDet, Int_t type, AliTRDCalPad* outlierPad)
217 // return mean of the RMS of all ROCs
218 // If calDet correct the CalROC from the detector coefficient
219 // type == 0 for gain and vdrift
222 Double_t factor = 0.0;
223 if(type == 0) factor = 1.0;
226 for (Int_t idet = 0; idet < kNdet; idet++) {
227 if(calDet) factor = calDet->GetValue(idet);
228 AliTRDCalROC *calRoc = fROC[idet];
230 AliTRDCalROC* outlierROC = 0;
231 if (outlierPad) outlierROC = outlierPad->GetCalROC(idet);
232 if(type == 0) arr[n] = calRoc->GetRMS(outlierROC)*factor;
233 else arr[n] = calRoc->GetRMS(outlierROC);
237 return TMath::Mean(n,arr);
240 //_____________________________________________________________________________
241 Double_t AliTRDCalPad::GetMedian(const AliTRDCalDet *calDet, Int_t type
242 , AliTRDCalPad* outlierPad)
245 // return mean of the median of all ROCs
246 // If AliTRDCalDet, the correct the CalROC from the detector coefficient
247 // type == 0 for gain and vdrift
250 Double_t factor = 0.0;
251 if(type == 0) factor = 1.0;
254 for (Int_t idet = 0; idet < kNdet; idet++) {
255 if(calDet) factor = calDet->GetValue(idet);
256 AliTRDCalROC *calRoc = fROC[idet];
258 AliTRDCalROC* outlierROC = 0;
259 if (outlierPad) outlierROC = outlierPad->GetCalROC(idet);
260 if(type == 0) arr[n] = calRoc->GetMedian(outlierROC)*factor;
261 else arr[n] = calRoc->GetMedian(outlierROC)+factor;
265 return TMath::Mean(n,arr);
268 //_____________________________________________________________________________
269 Double_t AliTRDCalPad::GetLTM(Double_t *sigma, Double_t fraction
270 , const AliTRDCalDet *calDet, Int_t type
271 , AliTRDCalPad* outlierPad)
274 // return mean of the LTM and sigma of all ROCs
275 // If calDet correct the CalROC from the detector coefficient
276 // type == 0 for gain and vdrift
279 Double_t factor = 0.0;
280 if(type == 0) factor = 1.0;
281 Double_t arrm[kNdet];
282 Double_t arrs[kNdet];
286 for (Int_t idet = 0; idet < kNdet; idet++) {
287 if(calDet) factor = calDet->GetValue(idet);
288 AliTRDCalROC *calRoc = fROC[idet];
290 if ( sigma ) sTemp=arrs+n;
291 AliTRDCalROC* outlierROC = 0;
292 if (outlierPad) outlierROC = outlierPad->GetCalROC(idet);
293 if(type == 0) arrm[n] = calRoc->GetLTM(sTemp,fraction, outlierROC)*factor;
294 else arrm[n] = calRoc->GetLTM(sTemp,fraction, outlierROC)+factor;
298 if ( sigma ) *sigma = TMath::Mean(n,arrs);
299 return TMath::Mean(n,arrm);
302 //_____________________________________________________________________________
303 TH1F * AliTRDCalPad::MakeHisto1D(const AliTRDCalDet *calDet, Int_t typedet
304 , Float_t min, Float_t max,Int_t type)
308 // type -1 = user defined range
309 // 0 = nsigma cut nsigma=min
310 // If calDet correct the CalROC from the detector coefficient
311 // typedet == 0 for gain and vdrift
312 // typedet == 1 for t0
314 Float_t kEpsilonr = 0.005;
316 Double_t factor = 0.0;
317 if(typedet == 0) factor = 1.0;
322 Float_t mean = GetMean(calDet,typedet);
324 if(GetRMS(calDet,typedet) > kEpsilonr) sigma = GetRMS(calDet,typedet);
327 sigma = GetMeanRMS(rms,calDet,typedet);
329 Float_t nsigma = TMath::Abs(min);
331 if(sigma < kEpsilonr) sigma = kEpsilonr;
337 Float_t mean = GetMedian(calDet,typedet);
344 // LTM mean +- nsigma
347 Float_t mean = GetLTM(&sigma,max,calDet,typedet);
349 if(sigma < kEpsilonr) sigma = kEpsilonr;
355 sprintf(name,"%s Pad 1D",GetTitle());
356 TH1F * his = new TH1F(name,name,100, min,max);
357 for (Int_t idet = 0; idet < kNdet; idet++) {
358 if(calDet) factor = calDet->GetValue(idet);
360 for (Int_t irow=0; irow<fROC[idet]->GetNrows(); irow++){
361 for (Int_t icol=0; icol<fROC[idet]->GetNcols(); icol++){
362 if(typedet == 0) his->Fill(fROC[idet]->GetValue(irow,icol)*factor);
363 else his->Fill(fROC[idet]->GetValue(irow,icol)+factor);
371 //_____________________________________________________________________________
372 TH2F *AliTRDCalPad::MakeHisto2DSmPl(Int_t sm, Int_t pl, const AliTRDCalDet *calDet
373 , Int_t typedet, Float_t min, Float_t max,Int_t type)
377 // sm - supermodule number
379 // If calDet correct the CalROC from the detector coefficient
380 // typedet == 0 for gain and vdrift
381 // typedet == 1 for t0
383 gStyle->SetPalette(1);
384 Double_t factor = 0.0;
385 if(typedet == 0) factor = 1.0;
387 Float_t kEpsilon = 0.000000000001;
388 Float_t kEpsilonr = 0.005;
390 AliTRDgeometry *trdGeo = new AliTRDgeometry();
395 Float_t mean = GetMean(calDet,typedet);
397 if(GetRMS(calDet,typedet) > kEpsilonr) sigma = GetRMS(calDet,typedet);
400 sigma = GetMeanRMS(rms,calDet,typedet);
402 Float_t nsigma = TMath::Abs(min);
404 if(sigma < kEpsilonr) sigma = kEpsilonr;
410 Float_t mean = GetMedian(calDet,typedet);
417 // LTM mean +- nsigma
420 Float_t mean = GetLTM(&sigma,max,calDet,typedet);
422 if(sigma < kEpsilonr) sigma = kEpsilonr;
428 AliTRDpadPlane *padPlane0 = trdGeo->GetPadPlane(pl,0);
429 Double_t row0 = padPlane0->GetRow0();
430 Double_t col0 = padPlane0->GetCol0();
433 sprintf(name,"%s Pad 2D sm %d pl %d",GetTitle(),sm,pl);
434 TH2F * his = new TH2F( name, name, 76,-TMath::Abs(row0),TMath::Abs(row0),144,-TMath::Abs(col0),TMath::Abs(col0));
437 Int_t offsetsmpl = 30*sm+pl;
440 for (Int_t k = 0; k < kNcham; k++){
441 Int_t det = offsetsmpl+k*6;
442 if(calDet) factor = calDet->GetValue(det);
444 AliTRDCalROC * calRoc = fROC[det];
445 for (Int_t irow=0; irow<calRoc->GetNrows(); irow++){
446 for (Int_t icol=0; icol<calRoc->GetNcols(); icol++){
447 if (TMath::Abs(calRoc->GetValue(icol,irow))>kEpsilon){
449 Int_t kb = kNcham-1-k;
450 Int_t krow = calRoc->GetNrows()-1-irow;
451 Int_t kcol = calRoc->GetNcols()-1-icol;
452 if(kb > 2) binz = 16*(kb-1)+12+krow+1;
453 else binz = 16*kb+krow+1;
455 Float_t value = calRoc->GetValue(icol,irow);
456 if(typedet == 0) his->SetBinContent(binz,biny,value*factor);
457 else his->SetBinContent(binz,biny,value+factor);
463 his->SetXTitle("z (cm)");
464 his->SetYTitle("y (cm)");
466 his->SetMaximum(max);
467 his->SetMinimum(min);
472 //_____________________________________________________________________________
473 TH2F *AliTRDCalPad::MakeHisto2DCh(Int_t ch, const AliTRDCalDet *calDet, Int_t typedet
474 , Float_t min, Float_t max,Int_t type)
477 // Make 2D graph mean value in z direction
479 // If calDet correct the CalROC from the detector coefficient
480 // typedet == 0 for gain and vdrift
481 // typedet == 1 for t0
483 gStyle->SetPalette(1);
484 Double_t factor = 0.0;
485 if(typedet == 0) factor = 1.0;
487 Float_t kEpsilonr = 0.005;
492 Float_t mean = GetMean(calDet,typedet);
494 if(GetRMS(calDet,typedet) > kEpsilonr) sigma = GetRMS(calDet,typedet);
497 sigma = GetMeanRMS(rms,calDet,typedet);
499 Float_t nsigma = TMath::Abs(min);
501 if(sigma < kEpsilonr) sigma = kEpsilonr;
507 Float_t mean = GetMedian(calDet,typedet);
514 // LTM mean +- nsigma
517 Float_t mean = GetLTM(&sigma,max,calDet,typedet);
519 if(sigma < kEpsilonr) sigma = kEpsilonr;
525 AliTRDgeometry *trdGeo = new AliTRDgeometry();
527 Float_t kEpsilon = 0.000000000001;
529 Double_t poslocal[3] = {0.0,0.0,0.0};
530 Double_t posglobal[3] = {0.0,0.0,0.0};
533 sprintf(name,"%s Pad 2D ch %d",GetTitle(),ch);
534 TH2F * his = new TH2F( name, name, 400,-400.0,400.0,400,-400.0,400.0);
537 Int_t offsetch = 6*ch;
540 for (Int_t isec = 0; isec < kNsect; isec++){
541 for(Int_t ipl = 0; ipl < kNplan; ipl++){
542 Int_t det = offsetch+isec*30+ipl;
543 if(calDet) factor = calDet->GetValue(det);
545 AliTRDCalROC * calRoc = fROC[det];
546 AliTRDpadPlane *padPlane = trdGeo->GetPadPlane(ipl,ch);
547 for (Int_t icol=0; icol<calRoc->GetNcols(); icol++){
548 poslocal[0] = trdGeo->GetTime0(ipl);
549 poslocal[2] = padPlane->GetRowPos(0);
550 poslocal[1] = padPlane->GetColPos(icol);
551 trdGeo->RotateBack(det,poslocal,posglobal);
552 Int_t binx = 1+TMath::Nint((posglobal[0]+400.0)*0.5);
553 Int_t biny = 1+TMath::Nint((posglobal[1]+400.0)*0.5);
556 for (Int_t irow=0; irow<calRoc->GetNrows(); irow++){
557 if (TMath::Abs(calRoc->GetValue(icol,irow))>kEpsilon){
558 value += calRoc->GetValue(icol,irow);
563 if(typedet == 0) his->SetBinContent(binx,biny,value*factor);
564 else his->SetBinContent(binx,biny,value+factor);
569 his->SetXTitle("x (cm)");
570 his->SetYTitle("y (cm)");
572 his->SetMaximum(max);
573 his->SetMinimum(min);
578 //_____________________________________________________________________________
579 Bool_t AliTRDCalPad::Add(Float_t c1)
582 // add constant for all channels of all ROCs
585 Bool_t result = kTRUE;
586 for (Int_t idet = 0; idet < kNdet; idet++) {
588 if(!fROC[idet]->Add(c1)) result = kFALSE;
594 //_____________________________________________________________________________
595 Bool_t AliTRDCalPad::Multiply(Float_t c1)
598 // multiply constant for all channels of all ROCs
600 Bool_t result = kTRUE;
601 for (Int_t idet = 0; idet < kNdet; idet++) {
603 if(!fROC[idet]->Multiply(c1)) result = kFALSE;
609 //_____________________________________________________________________________
610 Bool_t AliTRDCalPad::Add(const AliTRDCalPad * pad, Double_t c1
611 , const AliTRDCalDet * calDet1, const AliTRDCalDet *calDet2
615 // add calpad channel by channel multiplied by c1 - all ROCs
616 // If calDet1 and calDet2, the correct the CalROC from the detector coefficient
617 // then you have calDet1 and the calPad together
618 // calDet2 and pad together
619 // typedet == 0 for gain and vdrift
620 // typedet == 1 for t0
622 Float_t kEpsilon = 0.000000000001;
624 Double_t factor1 = 0.0;
625 Double_t factor2 = 0.0;
630 Bool_t result = kTRUE;
631 for (Int_t idet = 0; idet < kNdet; idet++) {
632 if(calDet1) factor1 = calDet1->GetValue(idet);
633 if(calDet2) factor2 = calDet2->GetValue(idet);
636 if(TMath::Abs(factor1) > kEpsilon){
637 if(!fROC[idet]->Add(pad->GetCalROC(idet),c1*factor2/factor1)) result = kFALSE;
639 else result = kFALSE;
642 AliTRDCalROC *croc = new AliTRDCalROC((const AliTRDCalROC) *pad->GetCalROC(idet));
643 if(!croc->Add(factor2)) result = kFALSE;
644 if(!fROC[idet]->Add(croc,c1)) result = kFALSE;
651 //_____________________________________________________________________________
652 Bool_t AliTRDCalPad::Multiply(const AliTRDCalPad * pad, const AliTRDCalDet * calDet1
653 , const AliTRDCalDet *calDet2, Int_t type)
656 // multiply calpad channel by channel - all ROCs
657 // If calDet1 and calDet2, the correct the CalROC from the detector coefficient
658 // then you have calDet1 and the calPad together
659 // calDet2 and pad together
660 // typedet == 0 for gain and vdrift
661 // typedet == 1 for t0
663 Float_t kEpsilon = 0.000000000001;
664 Bool_t result = kTRUE;
665 Double_t factor1 = 0.0;
666 Double_t factor2 = 0.0;
671 for (Int_t idet = 0; idet < kNdet; idet++) {
672 if(calDet1) factor1 = calDet1->GetValue(idet);
673 if(calDet2) factor2 = calDet2->GetValue(idet);
676 if(TMath::Abs(factor1) > kEpsilon){
677 AliTRDCalROC *croc = new AliTRDCalROC((const AliTRDCalROC) *pad->GetCalROC(idet));
678 if(!croc->Multiply(factor2)) result = kFALSE;
679 if(!fROC[idet]->Multiply(croc)) result = kFALSE;
681 else result = kFALSE;
684 AliTRDCalROC *croc2 = new AliTRDCalROC((const AliTRDCalROC) *pad->GetCalROC(idet));
685 if(!croc2->Add(factor2)) result = kFALSE;
686 if(!fROC[idet]->Add(factor1)) result = kFALSE;
687 if(!fROC[idet]->Multiply(croc2)) result = kFALSE;
688 if(!fROC[idet]->Add(-factor1)) result = kFALSE;
695 //_____________________________________________________________________________
696 Bool_t AliTRDCalPad::Divide(const AliTRDCalPad * pad, const AliTRDCalDet * calDet1
697 , const AliTRDCalDet *calDet2, Int_t type)
700 // divide calpad channel by channel - all ROCs
701 // If calDet1 and calDet2, the correct the CalROC from the detector coefficient
702 // then you have calDet1 and the calPad together
703 // calDet2 and pad together
704 // typedet == 0 for gain and vdrift
705 // typedet == 1 for t0
707 Float_t kEpsilon = 0.000000000001;
708 Bool_t result = kTRUE;
709 Double_t factor1 = 0.0;
710 Double_t factor2 = 0.0;
715 for (Int_t idet = 0; idet < kNdet; idet++) {
716 if(calDet1) factor1 = calDet1->GetValue(idet);
717 if(calDet2) factor2 = calDet2->GetValue(idet);
720 if(TMath::Abs(factor1) > kEpsilon){
721 AliTRDCalROC *croc = new AliTRDCalROC((const AliTRDCalROC) *pad->GetCalROC(idet));
722 if(!croc->Multiply(factor2)) result = kFALSE;
723 if(!fROC[idet]->Divide(croc)) result = kFALSE;
725 else result = kFALSE;
728 AliTRDCalROC *croc2 = new AliTRDCalROC((const AliTRDCalROC) *pad->GetCalROC(idet));
729 if(!croc2->Add(factor2)) result = kFALSE;
730 if(!fROC[idet]->Add(factor1)) result = kFALSE;
731 if(!fROC[idet]->Divide(croc2)) result = kFALSE;
732 if(!fROC[idet]->Add(-factor1)) result = kFALSE;