LCOV - code coverage report
Current view: top level - TPC/TPCbase - AliTPCCalPad.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 589 3.1 %
Date: 2016-06-14 17:26:59 Functions: 8 49 16.3 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       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             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : /// \class AliTPCCalPad
      19             : ///
      20             : ///  TPC calibration class for parameters which are saved per pad
      21             : ///  Each AliTPCCalPad consists of 72 AliTPCCalROC-objects
      22             : 
      23             : #include "AliTPCCalPad.h"
      24             : #include "AliTPCCalROC.h"
      25             : #include <TObjArray.h>
      26             : #include <TAxis.h>
      27             : #include <TGraph.h>
      28             : #include <TGraph2D.h>
      29             : #include <TH2F.h>
      30             : #include "TTreeStream.h"
      31             : #include "TLinearFitter.h"
      32             : #include "TFile.h"
      33             : #include "TKey.h"
      34             : #include <TFormula.h>
      35             : #include <TString.h>
      36             : #include <TObjString.h>
      37             : #include <iostream>
      38             : #include <AliLog.h>
      39             : 
      40             : //graphic includes
      41             : #include <TTree.h>
      42             : #include <TH1.h>
      43             : #include <TCanvas.h>
      44             : #include <TLegend.h>
      45             : #include <TCut.h>
      46             : #include <TVirtualPad.h>
      47             : #include "AliTPCPreprocessorOnline.h"
      48             : #include "AliTPCCalibViewer.h"
      49             : #include "TVectorD.h"
      50             : 
      51             : /// \cond CLASSIMP
      52          24 : ClassImp(AliTPCCalPad)
      53             : /// \endcond
      54             : 
      55             : //_____________________________________________________________________________
      56          68 : AliTPCCalPad::AliTPCCalPad():TNamed()
      57         340 : {
      58             :   //
      59             :   // AliTPCCalPad default constructor
      60             :   //
      61             : 
      62        9928 :   for (Int_t isec = 0; isec < kNsec; isec++) {
      63        4896 :     fROC[isec] = 0;
      64             :   }
      65             : 
      66         136 : }
      67             : 
      68             : //_____________________________________________________________________________
      69             : AliTPCCalPad::AliTPCCalPad(const Text_t *name, const Text_t *title)
      70           9 :                 :TNamed(name,title)
      71          45 : {
      72             :   /// AliTPCCalPad constructor
      73             : 
      74        1314 :   for (Int_t isec = 0; isec < kNsec; isec++) {
      75        1944 :     fROC[isec] = new AliTPCCalROC(isec);
      76             :   }
      77          18 : }
      78             : 
      79             : 
      80             : //_____________________________________________________________________________
      81           0 : AliTPCCalPad::AliTPCCalPad(const AliTPCCalPad &c):TNamed(c)
      82           0 : {
      83             :   /// AliTPCCalPad copy constructor
      84             : 
      85           0 :   for (Int_t isec = 0; isec < kNsec; isec++) {
      86           0 :          fROC[isec] = 0;
      87           0 :      if (c.fROC[isec])
      88           0 :        fROC[isec] = new AliTPCCalROC(*(c.fROC[isec]));
      89             :   }
      90           0 : }
      91             : 
      92             : //_____________________________________________________________________________
      93           0 : AliTPCCalPad::AliTPCCalPad(TObjArray * array):TNamed(array->GetName(),array->GetName())
      94           0 : {
      95             :   /// AliTPCCalPad default constructor
      96             : 
      97           0 :   for (Int_t isec = 0; isec < kNsec; isec++) {
      98           0 :     fROC[isec] = (AliTPCCalROC *)array->At(isec);
      99             :   }
     100             : 
     101           0 : }
     102             : 
     103             : 
     104             : ///_____________________________________________________________________________
     105             : AliTPCCalPad::~AliTPCCalPad()
     106         102 : {
     107             :   /// AliTPCCalPad destructor
     108             : 
     109        2482 :   for (Int_t isec = 0; isec < kNsec; isec++) {
     110        1224 :     if (fROC[isec]) {
     111        2448 :       delete fROC[isec];
     112        1224 :       fROC[isec] = 0;
     113        1224 :     }
     114             :   }
     115             : 
     116          51 : }
     117             : 
     118             : //_____________________________________________________________________________
     119             : AliTPCCalPad &AliTPCCalPad::operator=(const AliTPCCalPad &c)
     120             : {
     121             :   /// Assignment operator
     122             : 
     123           0 :   if (this != &c) ((AliTPCCalPad &) c).Copy(*this);
     124           0 :   return *this;
     125             : 
     126             : }
     127             : 
     128             : //_____________________________________________________________________________
     129             : void AliTPCCalPad::Copy(TObject &c) const
     130             : {
     131             :   /// Copy function
     132             : 
     133           0 :   for (Int_t isec = 0; isec < kNsec; isec++) {
     134           0 :     if (fROC[isec]) {
     135           0 :       fROC[isec]->Copy(*((AliTPCCalPad &) c).fROC[isec]);
     136           0 :     }
     137             :   }
     138           0 :   TObject::Copy(c);
     139           0 : }
     140             : 
     141             : 
     142             : void AliTPCCalPad::Print(Option_t* option) const{
     143             :   //
     144             :   // Print summary content
     145             :   //
     146           0 :   printf("TPC %s\t%s\n",GetName(),GetTitle());
     147             :   //
     148           0 :   printf("|\t|%s|\t%s|\t%s|\n", "Mean","Median","RMS");
     149           0 :   printf("|ALL\t|%f|\t%f|\t%f|\n", GetMean(),GetMedian(),GetRMS());
     150           0 :   if (TString(option).Contains("list")){
     151           0 :     for (Int_t isec=0; isec<72; isec++){
     152           0 :       if (fROC[isec]) fROC[isec]->Print(option);
     153             :     }
     154           0 :   }
     155           0 : }
     156             : 
     157             : 
     158             : 
     159             : 
     160             : void AliTPCCalPad::SetCalROC(AliTPCCalROC* roc, Int_t sector){
     161             :    /// Set AliTPCCalROC copies values from 'roc'
     162             :    /// if sector == -1 the sector specified in 'roc' is used
     163             :    /// else sector specified in 'roc' is ignored and specified sector is filled
     164             : 
     165           0 :    if (sector == -1) sector = roc->GetSector();
     166           0 :    if (!fROC[sector]) fROC[sector] = new AliTPCCalROC(sector);
     167           0 :    for (UInt_t ichannel = 0; ichannel < roc->GetNchannels(); ichannel++)
     168           0 :       fROC[sector]->SetValue(ichannel, roc->GetValue(ichannel));
     169           0 : }
     170             : 
     171             : Bool_t  AliTPCCalPad::MedianFilter(Int_t deltaRow, Int_t deltaPad, AliTPCCalPad*outlierPad,  Bool_t doEdge){
     172             :   /// replace constent with median in the neigborhood
     173             : 
     174             :   Bool_t isOK=kTRUE;
     175           0 :   for (Int_t isec = 0; isec < kNsec; isec++) {
     176           0 :     AliTPCCalROC *outlierROC=(outlierPad==NULL)?NULL:outlierPad->GetCalROC(isec);
     177           0 :     if (fROC[isec]){
     178           0 :       isOK&=fROC[isec]->MedianFilter(deltaRow,deltaPad,outlierROC,doEdge);
     179           0 :     }
     180             :   }
     181           0 :   return isOK;
     182             : }
     183             : 
     184             : Bool_t  AliTPCCalPad::LTMFilter(Int_t deltaRow, Int_t deltaPad, Float_t fraction, Int_t type, AliTPCCalPad*outlierPad,  Bool_t doEdge){
     185             :   /// replace constent with LTM statistic  in  neigborhood
     186             : 
     187             :   Bool_t isOK=kTRUE;
     188           0 :   for (Int_t isec = 0; isec < kNsec; isec++) {
     189           0 :     AliTPCCalROC *outlierROC=(outlierPad==NULL)?NULL:outlierPad->GetCalROC(isec);
     190           0 :     if (fROC[isec]){
     191           0 :       isOK&=fROC[isec]->LTMFilter(deltaRow, deltaPad,fraction,type,outlierROC,doEdge);
     192           0 :     }
     193             :   }
     194           0 :   return isOK;
     195             : }
     196             : 
     197             : Bool_t  AliTPCCalPad::Convolute(Double_t sigmaPad, Double_t sigmaRow,  AliTPCCalPad*outlierPad, TF1 *fpad, TF1 *frow){
     198             :   /// replace constent with median in the neigborhood
     199             : 
     200             :   Bool_t isOK=kTRUE;
     201           0 :   for (Int_t isec = 0; isec < kNsec; isec++) {
     202           0 :     AliTPCCalROC *outlierROC=(outlierPad==NULL)?NULL:outlierPad->GetCalROC(isec);
     203           0 :     if (fROC[isec]){
     204           0 :       isOK&=fROC[isec]->Convolute(sigmaPad,sigmaRow,outlierROC,fpad,frow);
     205           0 :     }
     206             :   }
     207           0 :   return isOK;
     208             : }
     209             : 
     210             : 
     211             : //_____________________________________________________________________________
     212             : void AliTPCCalPad::Add(Float_t c1)
     213             : {
     214             :     /// add constant c1 to all channels of all ROCs
     215             : 
     216           0 :     for (Int_t isec = 0; isec < kNsec; isec++) {
     217           0 :         if (fROC[isec]){
     218           0 :             fROC[isec]->Add(c1);
     219           0 :         }
     220             :     }
     221           0 : }
     222             : 
     223             : //_____________________________________________________________________________
     224             : void AliTPCCalPad::Multiply(Float_t c1)
     225             : {
     226             :   /// multiply each channel of all ROCs with c1
     227             : 
     228           0 :     for (Int_t isec = 0; isec < kNsec; isec++) {
     229           0 :         if (fROC[isec]){
     230           0 :             fROC[isec]->Multiply(c1);
     231           0 :         }
     232             :     }
     233           0 : }
     234             : 
     235             : //_____________________________________________________________________________
     236             : void AliTPCCalPad::Add(const AliTPCCalPad * pad, Double_t c1)
     237             : {
     238             :   /// multiply AliTPCCalPad 'pad' by c1 and add each channel to the coresponing channel in all ROCs
     239             :   ///  - pad by pad -
     240             : 
     241           0 :     for (Int_t isec = 0; isec < kNsec; isec++) {
     242           0 :         if (fROC[isec] && pad->GetCalROC(isec)){
     243           0 :             fROC[isec]->Add(pad->GetCalROC(isec),c1);
     244           0 :         }
     245             :     }
     246           0 : }
     247             : 
     248             : //_____________________________________________________________________________
     249             : void AliTPCCalPad::Multiply(const AliTPCCalPad * pad)
     250             : {
     251             :   /// multiply each channel of all ROCs with the coresponding channel of 'pad'
     252             :   ///     - pad by pad -
     253             : 
     254           0 :    for (Int_t isec = 0; isec < kNsec; isec++) {
     255           0 :         if (fROC[isec]){
     256           0 :             fROC[isec]->Multiply(pad->GetCalROC(isec));
     257           0 :         }
     258             :     }
     259           0 : }
     260             : 
     261             : //_____________________________________________________________________________
     262             : void AliTPCCalPad::Divide(const AliTPCCalPad * pad)
     263             : {
     264             :   /// divide each channel of all ROCs by the coresponding channel of 'pad'
     265             :   ///     - pad by pad -
     266             : 
     267           0 :     for (Int_t isec = 0; isec < kNsec; isec++) {
     268           0 :         if (fROC[isec]){
     269           0 :             fROC[isec]->Divide(pad->GetCalROC(isec));
     270           0 :         }
     271             :     }
     272           0 : }
     273             : 
     274             : //_____________________________________________________________________________
     275             : void AliTPCCalPad::Reset()
     276             : {
     277             :   /// Reset all cal Rocs
     278             : 
     279           0 :   for (Int_t isec = 0; isec < kNsec; isec++) {
     280           0 :     if (fROC[isec]){
     281           0 :       fROC[isec]->Reset();
     282           0 :     }
     283             :   }
     284           0 : }
     285             : 
     286             : //_____________________________________________________________________________
     287             : TGraph  *  AliTPCCalPad::MakeGraph(Int_t type, Float_t ratio, AliTPCCalROC::EPadType padType){
     288             :   ///   type=1 - mean
     289             :   ///        2 - median
     290             :   ///        3 - LTM
     291             :   ///   padType = AliTPCCalROC::kAll full oroc sectors
     292             :   ///             kOROCmedium,kOROClong split oroc sector
     293             : 
     294             :   Int_t npoints = 0;
     295           0 :   for (Int_t i=0;i<36;i++) if (fROC[i]) npoints++;//iroc
     296           0 :   if(padType==AliTPCCalROC::kAll) {
     297           0 :     for (Int_t i=36;i<72;i++) if (fROC[i]) npoints++;//oroc full
     298           0 :   } else {
     299           0 :     for (Int_t i=36;i<72;i++) if (fROC[i]) npoints+=2;//oroc split
     300             :   }
     301           0 :   TGraph * graph = new TGraph(npoints);
     302             :   npoints=0;
     303           0 :   for (Int_t isec=0;isec<36;isec++){//iroc
     304           0 :     if (!fROC[isec]) continue;
     305           0 :     if (type==0)  graph->SetPoint(npoints,isec,fROC[isec]->GetMean());
     306           0 :     if (type==1)  graph->SetPoint(npoints,isec,fROC[isec]->GetMedian());
     307           0 :     if (type==2)  graph->SetPoint(npoints,isec,fROC[isec]->GetLTM(0,ratio));
     308           0 :     npoints++;
     309           0 :   }
     310           0 :   if(padType==AliTPCCalROC::kAll) {
     311           0 :     for (Int_t isec=36;isec<72;isec++){//oroc full
     312           0 :       if (!fROC[isec]) continue;
     313           0 :       if (type==0)  graph->SetPoint(npoints,isec,fROC[isec]->GetMean());
     314           0 :       if (type==1)  graph->SetPoint(npoints,isec,fROC[isec]->GetMedian());
     315           0 :       if (type==2)  graph->SetPoint(npoints,isec,fROC[isec]->GetLTM(0,ratio));
     316           0 :       npoints++;
     317           0 :     }
     318           0 :   }else{
     319           0 :     for (Int_t isec=36;isec<72;isec++){//oroc split
     320           0 :       if (!fROC[isec]) continue;
     321           0 :       if (type==0)  graph->SetPoint(npoints,isec,fROC[isec]->GetMean(0,AliTPCCalROC::kOROCmedium));
     322           0 :       if (type==1)  graph->SetPoint(npoints,isec,fROC[isec]->GetMedian(0,AliTPCCalROC::kOROCmedium));
     323           0 :       if (type==2)  graph->SetPoint(npoints,isec,fROC[isec]->GetLTM(0,ratio,0,AliTPCCalROC::kOROCmedium));
     324           0 :       npoints++;
     325           0 :       if (type==0)  graph->SetPoint(npoints,isec+36,fROC[isec]->GetMean(0,AliTPCCalROC::kOROClong));
     326           0 :       if (type==1)  graph->SetPoint(npoints,isec+36,fROC[isec]->GetMedian(0,AliTPCCalROC::kOROClong));
     327           0 :       if (type==2)  graph->SetPoint(npoints,isec+36,fROC[isec]->GetLTM(0,ratio,0,AliTPCCalROC::kOROClong));
     328           0 :       npoints++;
     329           0 :     }
     330             :   }
     331             : 
     332           0 :   graph->GetXaxis()->SetTitle("Sector"); 
     333           0 :   if (type==0) {
     334           0 :     graph->GetYaxis()->SetTitle("Mean");   
     335           0 :     graph->SetMarkerStyle(22);    
     336           0 :   }
     337           0 :   if (type==1) {
     338           0 :     graph->GetYaxis()->SetTitle("Median");   
     339           0 :     graph->SetMarkerStyle(22);    
     340           0 :   }
     341           0 :   if (type==2) {
     342           0 :       graph->GetYaxis()->SetTitle(Form("Mean%f",ratio));      
     343           0 :       graph->SetMarkerStyle(24);
     344           0 :   }
     345             : 
     346           0 :   return graph;
     347           0 : }
     348             : 
     349             : //_____________________________________________________________________________
     350             : Double_t AliTPCCalPad::GetMeanRMS(Double_t &rms) const
     351             : {
     352             :     /// Calculates mean and RMS of all ROCs
     353             : 
     354             :     Double_t sum = 0, sum2 = 0, n=0, val=0;
     355           0 :     for (Int_t isec = 0; isec < kNsec; isec++) {
     356           0 :         AliTPCCalROC *calRoc = fROC[isec];
     357           0 :         if ( calRoc ){
     358           0 :             for (UInt_t irow=0; irow<calRoc->GetNrows(); irow++){
     359           0 :                 for (UInt_t ipad=0; ipad<calRoc->GetNPads(irow); ipad++){
     360           0 :                     val = calRoc->GetValue(irow,ipad);
     361           0 :                     sum+=val;
     362           0 :                     sum2+=val*val;
     363           0 :                     n++;
     364             :                 }
     365             :             }
     366             : 
     367           0 :         }
     368             :     }
     369           0 :     Double_t n1 = 1./n;
     370           0 :     Double_t mean = sum*n1;
     371           0 :     rms  = TMath::Sqrt(TMath::Abs(sum2*n1-mean*mean));
     372           0 :     return mean;
     373             : }
     374             : 
     375             : //_____________________________________________________________________________
     376             : Double_t AliTPCCalPad::GetStats(AliTPCCalROC::EStatType statType, AliTPCCalPad *const outlierPad, AliTPCCalROC::EPadType padType) const
     377             : {
     378             :   /// return mean of statType(kMean,kMedian,kRMS) 
     379             :   /// for padType(kAll,kOROCmedium,kOROClong)
     380             : 
     381           0 :   Double_t arr[kNsecSplit];
     382             :   Int_t n=0;
     383           0 :   for (Int_t isec = 0; isec < kNsec; isec++) {
     384           0 :     AliTPCCalROC *calRoc = fROC[isec];
     385           0 :     if ( calRoc ){
     386             :       AliTPCCalROC* outlierROC = 0;
     387           0 :       if (outlierPad) outlierROC = outlierPad->GetCalROC(isec);
     388           0 :       if(isec>=36 && padType!=AliTPCCalROC::kAll){
     389           0 :         arr[n] = calRoc->GetStats(statType,outlierROC,AliTPCCalROC::kOROCmedium);
     390           0 :         n++;
     391           0 :         arr[n] = calRoc->GetStats(statType,outlierROC,AliTPCCalROC::kOROClong);
     392           0 :         n++;
     393           0 :       } else {
     394           0 :         arr[n] = calRoc->GetStats(statType,outlierROC,AliTPCCalROC::kAll);
     395           0 :         n++;
     396             :       }
     397             : 
     398           0 :     }
     399             :   }
     400             : 
     401             :   Double_t val=0.;
     402           0 :   if      (statType==AliTPCCalROC::kMinElement) val=TMath::MinElement(n,arr);
     403           0 :   else if (statType==AliTPCCalROC::kMaxElement) val=TMath::MaxElement(n,arr);
     404           0 :   else                                          val=TMath::Mean      (n,arr);
     405           0 :   return val;
     406           0 : }
     407             : 
     408             : //_____________________________________________________________________________
     409             : Double_t AliTPCCalPad::GetMean(AliTPCCalPad* outlierPad, AliTPCCalROC::EPadType padType) const
     410             : {
     411             :   /// return mean of the mean of all ROCs
     412             : 
     413           0 :   return GetStats(AliTPCCalROC::kMean, outlierPad, padType);
     414             : }
     415             : 
     416             : //_____________________________________________________________________________
     417             : Double_t AliTPCCalPad::GetRMS(AliTPCCalPad* outlierPad, AliTPCCalROC::EPadType padType) const
     418             : {
     419             :   /// return mean of the RMS of all ROCs
     420             : 
     421           0 :   return GetStats(AliTPCCalROC::kRMS, outlierPad, padType);
     422             : }
     423             : 
     424             : //_____________________________________________________________________________
     425             : Double_t AliTPCCalPad::GetMedian(AliTPCCalPad* outlierPad, AliTPCCalROC::EPadType padType) const
     426             : {
     427             :   /// return mean of the median of all ROCs
     428             : 
     429           0 :   return GetStats(AliTPCCalROC::kMedian, outlierPad, padType);
     430             : }
     431             : 
     432             : //_____________________________________________________________________________
     433             : Double_t AliTPCCalPad::GetMinElement(AliTPCCalPad* outlierPad, AliTPCCalROC::EPadType padType) const
     434             : {
     435             :   /// return MinElement all ROCs
     436             : 
     437           0 :   return GetStats(AliTPCCalROC::kMinElement, outlierPad, padType);
     438             : }
     439             : 
     440             : //_____________________________________________________________________________
     441             : Double_t AliTPCCalPad::GetMaxElement(AliTPCCalPad* outlierPad, AliTPCCalROC::EPadType padType) const
     442             : {
     443             :   /// return MaxElement of all ROCs
     444             : 
     445           0 :   return GetStats(AliTPCCalROC::kMaxElement, outlierPad, padType);
     446             : }
     447             : 
     448             : //_____________________________________________________________________________
     449             : Double_t AliTPCCalPad::GetLTM(Double_t *sigma, Double_t fraction, AliTPCCalPad* outlierPad, AliTPCCalROC::EPadType padType) const
     450             : {
     451             :   /// return mean of the LTM and sigma of all ROCs
     452             : 
     453           0 :   Double_t arrm[kNsecSplit];
     454           0 :   Double_t arrs[kNsecSplit];
     455             :   Double_t *sTemp=0x0;
     456             :   Int_t n=0;
     457             : 
     458           0 :   for (Int_t isec = 0; isec < kNsec; isec++) {
     459           0 :     AliTPCCalROC *calRoc = fROC[isec];
     460           0 :     if ( calRoc ){
     461           0 :       if ( sigma ) sTemp=arrs+n;
     462             :       AliTPCCalROC* outlierROC = 0;
     463           0 :       if (outlierPad) outlierROC = outlierPad->GetCalROC(isec);
     464           0 :       if(isec>=36 && padType!=AliTPCCalROC::kAll){
     465           0 :         arrm[n] = calRoc->GetLTM(sTemp,fraction, outlierROC,AliTPCCalROC::kOROCmedium);
     466           0 :         n++;
     467           0 :         if ( sigma ) sTemp=arrs+n;
     468           0 :         arrm[n] = calRoc->GetLTM(sTemp,fraction, outlierROC,AliTPCCalROC::kOROClong);
     469           0 :         n++;
     470           0 :       } else {
     471           0 :         arrm[n] = calRoc->GetLTM(sTemp,fraction, outlierROC,AliTPCCalROC::kAll);
     472           0 :         n++;
     473             :       }
     474             : 
     475           0 :     }
     476             :   }
     477           0 :   if ( sigma ) *sigma = TMath::Mean(n,arrs);
     478           0 :   return TMath::Mean(n,arrm);
     479           0 : }
     480             : 
     481             : //_____________________________________________________________________________
     482             : TH1F * AliTPCCalPad::MakeHisto1D(Float_t min, Float_t max,Int_t type, Int_t side){
     483             :   /// make 1D histo
     484             :   /// type -1 = user defined range
     485             :   ///       0 = nsigma cut nsigma=min
     486             : 
     487           0 :   if (type>=0){
     488           0 :     if (type==0){
     489             :       // nsigma range
     490           0 :       Float_t mean  = GetMean();
     491           0 :       Float_t sigma = GetRMS();
     492           0 :       Float_t nsigma = TMath::Abs(min);
     493           0 :       min = mean-nsigma*sigma;
     494           0 :       max = mean+nsigma*sigma;
     495           0 :     }
     496           0 :     if (type==1){
     497             :       // fixed range
     498           0 :       Float_t mean   = GetMedian();
     499             :       Float_t  delta = min;
     500           0 :       min = mean-delta;
     501           0 :       max = mean+delta;
     502           0 :     }
     503           0 :     if (type==2){
     504             :       //
     505             :       // LTM mean +- nsigma
     506             :       //
     507           0 :       Double_t sigma;
     508           0 :       Float_t mean  = GetLTM(&sigma,max);
     509           0 :       sigma*=min;
     510           0 :       min = mean-sigma;
     511           0 :       max = mean+sigma;
     512           0 :     }
     513             :   }
     514           0 :   TString name=Form("%s Pad 1D",GetTitle());
     515           0 :   TH1F * his = new TH1F(name.Data(),name.Data(),100, min,max);
     516           0 :     for (Int_t isec = 0; isec < kNsec; isec++) {
     517           0 :       if (side==1 && isec%36>18) continue;
     518           0 :       if (side==-1 && isec%36<18) continue;
     519           0 :         if (fROC[isec]){
     520           0 :             for (UInt_t irow=0; irow<fROC[isec]->GetNrows(); irow++){
     521           0 :                 UInt_t npads = (Int_t)fROC[isec]->GetNPads(irow);
     522           0 :                 for (UInt_t ipad=0; ipad<npads; ipad++){
     523           0 :                     his->Fill(fROC[isec]->GetValue(irow,ipad));
     524             :                 }
     525             :             }
     526           0 :         }
     527             :     }
     528             :   return his;
     529           0 : }
     530             : 
     531             : //_____________________________________________________________________________
     532             : TH2F *AliTPCCalPad::MakeHisto2D(Int_t side){
     533             :   /// Make 2D graph
     534             :   /// side  -  specify the side A = 0 C = 1
     535             :   /// type  -  used types of determination of boundaries in z
     536             : 
     537             :   Float_t kEpsilon = 0.000000000001;
     538           0 :   TH2F * his = new TH2F(GetName(), GetName(), 250,-250,250,250,-250,250);
     539           0 :   AliTPCROC * roc  = AliTPCROC::Instance();
     540           0 :   for (Int_t isec=0; isec<72; isec++){
     541           0 :     if (side==0 && isec%36>=18) continue;
     542           0 :     if (side>0 && isec%36<18) continue;
     543           0 :     if (fROC[isec]){
     544             :       AliTPCCalROC * calRoc = fROC[isec];
     545           0 :       for (UInt_t irow=0; irow<calRoc->GetNrows(); irow++)
     546           0 :         for (UInt_t ipad=0; ipad<calRoc->GetNPads(irow); ipad++)
     547           0 :           if (TMath::Abs(calRoc->GetValue(irow,ipad))>kEpsilon){
     548           0 :             Float_t xyz[3];
     549           0 :             roc->GetPositionGlobal(isec,irow,ipad,xyz);
     550           0 :             Int_t binx = 1+TMath::Nint((xyz[0]+250.)*0.5);
     551           0 :             Int_t biny = 1+TMath::Nint((xyz[1]+250.)*0.5);
     552           0 :             Float_t value = calRoc->GetValue(irow,ipad);
     553           0 :             his->SetBinContent(binx,biny,value);
     554           0 :           }
     555           0 :     }
     556             :   }
     557           0 :   his->SetXTitle("x (cm)");
     558           0 :   his->SetYTitle("y (cm)");
     559           0 :   return his;
     560           0 : }
     561             : 
     562             : 
     563             : AliTPCCalPad* AliTPCCalPad::LocalFit(const char* padName, Int_t rowRadius, Int_t padRadius, AliTPCCalPad* PadOutliers, Bool_t robust, Double_t chi2Threshold, Double_t robustFraction, Bool_t printCurrentSector) const {
     564             :    /// Loops over all AliTPCCalROCs and performs a localFit in each ROC
     565             :    /// AliTPCCalPad with fit-data is returned
     566             :    /// rowRadius and padRadius specifies a window around a given pad in one sector.
     567             :    /// The data of this window are fitted with a parabolic function.
     568             :    /// This function is evaluated at the pad's position.
     569             :    /// At the edges the window is shifted, so that the specified pad is not anymore in the center of the window.
     570             :    /// rowRadius  -  radius - rows to be used for smoothing
     571             :    /// padradius  -  radius - pads to be used for smoothing
     572             :    /// ROCoutlier -  map of outliers - pads not to be used for local smoothing
     573             :    /// robust     -  robust method of fitting  - (much slower)
     574             :    /// chi2Threshold: Threshold for chi2 when EvalRobust is called
     575             :    /// robustFraction: Fraction of data that will be used in EvalRobust
     576             : 
     577           0 :    AliTPCCalPad* pad = new AliTPCCalPad(padName, padName);
     578           0 :    for (Int_t isec = 0; isec < 72; isec++){
     579           0 :       if (printCurrentSector) std::cout << "LocalFit in sector " << isec << "\r" << std::flush;
     580           0 :       if (PadOutliers)
     581           0 :          pad->SetCalROC(GetCalROC(isec)->LocalFit(rowRadius, padRadius, PadOutliers->GetCalROC(isec), robust, chi2Threshold, robustFraction));
     582             :       else 
     583           0 :          pad->SetCalROC(GetCalROC(isec)->LocalFit(rowRadius, padRadius, 0, robust, chi2Threshold, robustFraction));
     584             :    }
     585           0 :    return pad;
     586           0 : }
     587             : 
     588             : 
     589             : AliTPCCalPad* AliTPCCalPad::GlobalFit(const char* padName, AliTPCCalPad* PadOutliers, Bool_t robust, Int_t fitType, Double_t chi2Threshold, Double_t robustFraction, Double_t err, TObjArray *fitParArr, TObjArray *fitCovArr, AliTPCCalROC::EPadType padType){
     590             :    /// Loops over all AliTPCCalROCs and performs a globalFit in each ROC
     591             :    /// AliTPCCalPad with fit-data is returned
     592             :    /// chi2Threshold: Threshold for chi2 when EvalRobust is called
     593             :    /// robustFraction: Fraction of data that will be used in EvalRobust
     594             :    /// chi2Threshold: Threshold for chi2 when EvalRobust is called
     595             :    /// robustFraction: Fraction of data that will be used in EvalRobust
     596             :    /// err: error of the data points
     597             :    /// if fitParArr and/or fitCovArr is given, write fitParameters and/or covariance Matrices into the array
     598             :    /// padType shows whether full oroc or splited oroc is taken into account
     599             : 
     600           0 :    AliTPCCalPad* pad = new AliTPCCalPad(padName, padName);
     601           0 :    TVectorD fitParam(0);
     602           0 :    TMatrixD covMatrix(0,0);
     603           0 :    Float_t chi2 = 0;
     604           0 :    for (Int_t isec = 0; isec < 72; isec++){
     605           0 :      if(isec>=36 && padType!=AliTPCCalROC::kAll){
     606             :        //part for medium pads
     607           0 :        if (PadOutliers)
     608           0 :          GetCalROC(isec)->GlobalFit(PadOutliers->GetCalROC(isec), robust, fitParam, covMatrix, chi2, fitType, chi2Threshold, robustFraction, err, AliTPCCalROC::kOROCmedium);
     609             :        else 
     610           0 :          GetCalROC(isec)->GlobalFit(0, robust, fitParam, covMatrix, chi2, fitType, chi2Threshold, robustFraction, err, AliTPCCalROC::kOROCmedium);
     611             :        
     612           0 :        AliTPCCalROC *roc=AliTPCCalROC::CreateGlobalFitCalROC(fitParam, isec, AliTPCCalROC::kOROCmedium);
     613           0 :        if ( fitParArr ) fitParArr->AddAtAndExpand(new TVectorD(fitParam), isec);
     614           0 :        if ( fitCovArr ) fitCovArr->AddAtAndExpand(new TMatrixD(covMatrix), isec);
     615             :        //part for long pads
     616           0 :        if (PadOutliers)
     617           0 :          GetCalROC(isec)->GlobalFit(PadOutliers->GetCalROC(isec), robust, fitParam, covMatrix, chi2, fitType, chi2Threshold, robustFraction, err, AliTPCCalROC::kOROClong);
     618             :        else 
     619           0 :          GetCalROC(isec)->GlobalFit(0, robust, fitParam, covMatrix, chi2, fitType, chi2Threshold, robustFraction, err, AliTPCCalROC::kOROClong);
     620             :        
     621           0 :        roc=AliTPCCalROC::CreateGlobalFitCalROC(fitParam, isec, AliTPCCalROC::kOROClong,roc);
     622           0 :        if ( fitParArr ) fitParArr->AddAtAndExpand(new TVectorD(fitParam), isec+36);
     623           0 :        if ( fitCovArr ) fitCovArr->AddAtAndExpand(new TMatrixD(covMatrix), isec+36);
     624             : 
     625           0 :        pad->SetCalROC(roc);
     626           0 :        delete roc;
     627           0 :      } else {
     628           0 :        if (PadOutliers)
     629           0 :          GetCalROC(isec)->GlobalFit(PadOutliers->GetCalROC(isec), robust, fitParam, covMatrix, chi2, fitType, chi2Threshold, robustFraction, err);
     630             :        else 
     631           0 :          GetCalROC(isec)->GlobalFit(0, robust, fitParam, covMatrix, chi2, fitType, chi2Threshold, robustFraction, err);
     632             :        
     633           0 :        AliTPCCalROC *roc=AliTPCCalROC::CreateGlobalFitCalROC(fitParam, isec);
     634           0 :        pad->SetCalROC(roc);
     635           0 :        delete roc;
     636           0 :        if ( fitParArr ) fitParArr->AddAtAndExpand(new TVectorD(fitParam), isec);
     637           0 :        if ( fitCovArr ) fitCovArr->AddAtAndExpand(new TMatrixD(covMatrix), isec);
     638             :      }
     639             :    }//end of loop over sectors
     640             : 
     641             :    return pad;
     642           0 : }
     643             : //_____________________________________________________________________________
     644             : TObjArray* AliTPCCalPad::CreateFormulaArray(const char *fitFormula)
     645             : {
     646             :   /// create an array of TFormulas for the each parameter of the fit function
     647             : 
     648             :   // split fit string in single parameters
     649             :   // find dimension of the fit:
     650           0 :   TString fitString(fitFormula);
     651           0 :   fitString.ReplaceAll("++","#");
     652           0 :   fitString.ReplaceAll(" ","");
     653           0 :   TObjArray *arrFitParams = fitString.Tokenize("#");
     654           0 :   Int_t ndim = arrFitParams->GetEntries();
     655             :   //create array of TFormulas to evaluate the parameters
     656           0 :   TObjArray *arrFitFormulas = new TObjArray(ndim);
     657           0 :   arrFitFormulas->SetOwner(kTRUE);
     658           0 :   for (Int_t idim=0;idim<ndim;++idim){
     659           0 :     TString s=((TObjString*)arrFitParams->At(idim))->GetString();
     660           0 :     s.ReplaceAll("gx","[0]");
     661           0 :     s.ReplaceAll("gy","[1]");
     662           0 :     s.ReplaceAll("lx","[2]");
     663           0 :     s.ReplaceAll("ly","[3]");
     664           0 :     s.ReplaceAll("sector","[4]");
     665           0 :     arrFitFormulas->AddAt(new TFormula(Form("param%02d",idim),s.Data()),idim);
     666           0 :   }
     667           0 :   delete arrFitParams;
     668             :   
     669             :   return arrFitFormulas;
     670           0 : }
     671             : //_____________________________________________________________________________
     672             : void AliTPCCalPad::EvalFormulaArray(const TObjArray &arrFitFormulas, TVectorD &results,
     673             :                                     const Int_t sec, const Int_t row, const Int_t pad)
     674             : {
     675             :   /// evaluate the fit formulas
     676             : 
     677           0 :   Int_t ndim=arrFitFormulas.GetEntries();
     678           0 :   results.ResizeTo(ndim);
     679             :   
     680           0 :   AliTPCROC* tpcROCinstance = AliTPCROC::Instance();  // to calculate the pad's position
     681           0 :   Float_t localXYZ[3];
     682           0 :   Float_t globalXYZ[3];
     683           0 :   tpcROCinstance->GetPositionLocal(sec, row, pad, localXYZ);
     684           0 :   tpcROCinstance->GetPositionGlobal(sec, row, pad, globalXYZ);
     685             :   //calculate parameter values
     686           0 :   for (Int_t idim=0;idim<ndim;++idim){
     687           0 :     TFormula *f=(TFormula*)arrFitFormulas.At(idim);
     688           0 :     f->SetParameters(globalXYZ[0],globalXYZ[1],localXYZ[0],localXYZ[1],sec);
     689           0 :     results[idim]=f->Eval(0);
     690             :   }
     691           0 : }
     692             : //_____________________________________________________________________________
     693             : void AliTPCCalPad::GlobalSidesFit(const AliTPCCalPad* PadOutliers, const char* fitFormula, TVectorD &fitParamSideA, TVectorD &fitParamSideC,TMatrixD &covMatrixSideA, TMatrixD &covMatrixSideC, Float_t & chi2SideA, Float_t & chi2SideC, AliTPCCalPad *pointError, Bool_t robust, Double_t robustFraction){
     694             :   /// Performs a fit on both sides.
     695             :   /// Valid information for the fitFormula are the variables
     696             :   /// - gx, gy, lx ,ly: meaning global x, global y, local x, local y value of the padName
     697             :   /// - sector:         the sector number.
     698             :   ///  eg. a formula might look 'gy' or '(sector<36) ++ gy' or 'gx ++ gy' or 'gx ++ gy ++ lx ++ lx^2' and so on
     699             :   ///
     700             :   /// PadOutliers - pads with value !=0 are not used in fitting procedure
     701             :   /// chi2Threshold: Threshold for chi2 when EvalRobust is called
     702             :   /// robustFraction: Fraction of data that will be used in EvalRobust
     703             : 
     704           0 :   TObjArray* arrFitFormulas=CreateFormulaArray(fitFormula);
     705           0 :   Int_t ndim = arrFitFormulas->GetEntries();
     706             :   //resize output data arrays
     707           0 :   fitParamSideA.ResizeTo(ndim+1);
     708           0 :   fitParamSideC.ResizeTo(ndim+1);
     709           0 :   covMatrixSideA.ResizeTo(ndim+1,ndim+1);
     710           0 :   covMatrixSideC.ResizeTo(ndim+1,ndim+1);
     711             :   // create linear fitter for A- and C- Side
     712           0 :   TLinearFitter* fitterGA = new TLinearFitter(ndim+1,Form("hyp%d",ndim));
     713           0 :   TLinearFitter* fitterGC = new TLinearFitter(ndim+1,Form("hyp%d",ndim));
     714           0 :   fitterGA->StoreData(kTRUE);
     715           0 :   fitterGC->StoreData(kTRUE);
     716             :   //parameter values
     717           0 :   TVectorD parValues(ndim);
     718             : 
     719             :   AliTPCCalROC *rocErr=0x0;
     720             :   
     721           0 :   for (UInt_t isec = 0; isec<kNsec; ++isec){
     722           0 :     AliTPCCalROC *rocOut=PadOutliers->GetCalROC(isec);
     723           0 :     AliTPCCalROC *rocData=GetCalROC(isec);
     724           0 :     if (pointError) rocErr=pointError->GetCalROC(isec);
     725           0 :     if (!rocData) continue;
     726           0 :     for (UInt_t irow = 0; irow < GetCalROC(isec)->GetNrows(); irow++) {
     727           0 :       for (UInt_t ipad = 0; ipad < GetCalROC(isec)->GetNPads(irow); ipad++) {
     728             :         //check for outliers
     729           0 :         if (rocOut && rocOut->GetValue(irow,ipad)) continue;
     730             :         //calculate parameter values
     731           0 :         EvalFormulaArray(*arrFitFormulas,parValues,isec,irow,ipad);
     732             :         //get value
     733           0 :         Float_t value=rocData->GetValue(irow,ipad);
     734             :         //point error
     735             :         Int_t err=1;
     736           0 :         if (rocErr) {
     737           0 :           err=TMath::Nint(rocErr->GetValue(irow,ipad));
     738           0 :           if (err==0) err=1;
     739             :         }
     740             :         //add points to the fitters
     741           0 :         if (isec/18%2==0){
     742           0 :           fitterGA->AddPoint(parValues.GetMatrixArray(),value,err);
     743             :         }else{
     744           0 :           fitterGC->AddPoint(parValues.GetMatrixArray(),value,err);
     745             :         }
     746           0 :       }
     747             :     }
     748           0 :   }
     749           0 :   if (robust){
     750           0 :     fitterGA->EvalRobust(robustFraction);
     751           0 :     fitterGC->EvalRobust(robustFraction);
     752             :   } else {
     753           0 :     fitterGA->Eval();
     754           0 :     fitterGC->Eval();
     755             :   }
     756           0 :   chi2SideA=fitterGA->GetChisquare()/(fitterGA->GetNpoints()-(ndim+1));
     757           0 :   chi2SideC=fitterGC->GetChisquare()/(fitterGC->GetNpoints()-(ndim+1));
     758           0 :   fitterGA->GetParameters(fitParamSideA);
     759           0 :   fitterGC->GetParameters(fitParamSideC);
     760           0 :   fitterGA->GetCovarianceMatrix(covMatrixSideA);
     761           0 :   fitterGC->GetCovarianceMatrix(covMatrixSideC);
     762             :   
     763           0 :   delete arrFitFormulas;
     764           0 :   delete fitterGA;
     765           0 :   delete fitterGC;
     766             :   
     767           0 : }
     768             : //
     769             : AliTPCCalPad *AliTPCCalPad::CreateCalPadFit(const char* fitFormula, const TVectorD &fitParamSideA, const TVectorD &fitParamSideC)
     770             : {
     771             :   ///
     772             : 
     773           0 :   TObjArray *arrFitFormulas=CreateFormulaArray(fitFormula);
     774           0 :   Int_t ndim = arrFitFormulas->GetEntries();
     775             :   //check if dimension of fit formula and fit parameters agree
     776           0 :   if (ndim!=fitParamSideA.GetNrows()||ndim!=fitParamSideC.GetNrows()){
     777           0 :     printf("AliTPCCalPad::CreateCalPadFit: Dimensions of fit formula and fit Parameters does not match!");
     778           0 :     return 0;
     779             :   }
     780             :   //create cal pad
     781           0 :   AliTPCCalPad *pad=new AliTPCCalPad("fitResultPad",Form("Fit result: %s",fitFormula));
     782             :   //fill cal pad with fit results if requested
     783           0 :   for (UInt_t isec = 0; isec<kNsec; ++isec){
     784           0 :     AliTPCCalROC *roc=pad->GetCalROC(isec);
     785           0 :     for (UInt_t irow = 0; irow < roc->GetNrows(); irow++) {
     786           0 :       for (UInt_t ipad = 0; ipad < roc->GetNPads(irow); ipad++) {
     787             :         const TVectorD *fitPar=0;
     788           0 :         TVectorD fitResArray;
     789           0 :         if (isec/18%2==0){
     790             :           fitPar=&fitParamSideA;
     791           0 :         }else{
     792             :           fitPar=&fitParamSideC;
     793             :         }
     794           0 :         EvalFormulaArray(*arrFitFormulas,fitResArray, isec, irow, ipad);
     795           0 :         for (Int_t idim=0;idim<ndim;++idim)
     796           0 :           fitResArray(idim)*=(*fitPar)(idim);
     797           0 :         roc->SetValue(irow,ipad,fitResArray.Sum());
     798           0 :       }
     799             :     }
     800             :   }
     801           0 :   delete arrFitFormulas;
     802             :   return pad;
     803           0 : }
     804             : 
     805             : 
     806             : 
     807             : TCanvas * AliTPCCalPad::MakeReportPadSector(TTree *chain, const char* varName, const char*varTitle, const char *axisTitle, Float_t min, Float_t max, const char *cutUser){
     808             :   /// Make a report - cal pads per sector
     809             :   /// mean valeus per sector and local X
     810             : 
     811             :   TH1* his=0;
     812             :   TLegend *legend = 0;
     813           0 :   TCanvas *canvas = new TCanvas(Form("Sector: %s",varTitle),Form("Sector: %s",varTitle),1500,1100);
     814             : 
     815           0 :   canvas->Divide(2);
     816           0 :   chain->SetAlias("lX","lx.fElements"); 
     817             :   //
     818           0 :   canvas->cd(1);
     819           0 :   TString strDraw=varName;
     820           0 :   strDraw+=":lX";
     821           0 :   legend = new TLegend(0.5,0.50,0.9,0.9, Form("%s TPC A side", varTitle));
     822           0 :   for (Int_t isec=-1; isec<18; isec+=1){
     823           0 :     TCut cutSec=Form("sector%%36==%d",isec);
     824           0 :     cutSec+=cutUser;
     825           0 :     if (isec==-1) cutSec="sector%36<18";
     826           0 :     chain->SetMarkerColor(1+(isec+2)%5);
     827           0 :     chain->SetLineColor(1+(isec+2)%5);
     828           0 :     chain->SetMarkerStyle(25+(isec+2)%4);
     829             :     //
     830           0 :     chain->Draw(strDraw.Data(),cutSec,"profgoff");
     831           0 :     his=(TH1*)chain->GetHistogram()->Clone();
     832           0 :     delete chain->GetHistogram();
     833           0 :     his->SetMaximum(max);
     834           0 :     his->SetMinimum(min);
     835           0 :     his->GetXaxis()->SetTitle("R (cm)");
     836           0 :     his->GetYaxis()->SetTitle(axisTitle);
     837           0 :     his->SetTitle(Form("%s- sector %d",varTitle, isec));
     838           0 :     his->SetName(Form("%s- sector %d",varTitle, isec));
     839           0 :     if (isec==-1) his->SetTitle(Form("%s A side",varTitle));
     840           0 :     if (isec==-1) his->Draw();
     841           0 :     his->Draw("same");
     842           0 :     legend->AddEntry(his);
     843           0 :   }
     844           0 :   legend->Draw();
     845           0 :   canvas->cd(2);
     846             :   //
     847           0 :   legend = new TLegend(0.5,0.50,0.9,0.9, Form("%s TPC C side", varTitle));
     848           0 :   for (Int_t isec=-1; isec<18; isec+=1){
     849           0 :     TCut cutSec=Form("(sector+18)%%36==%d",isec);
     850           0 :     cutSec+=cutUser;
     851           0 :     if (isec==-1) cutSec="sector%36>18";
     852           0 :     chain->SetMarkerColor(1+(isec+2)%5);
     853           0 :     chain->SetLineColor(1+(isec+2)%5);
     854           0 :     chain->SetMarkerStyle(25+isec%4);
     855             :     //
     856           0 :     chain->Draw(strDraw.Data(),cutSec,"profgoff");
     857           0 :     his=(TH1*)chain->GetHistogram()->Clone();
     858           0 :     delete chain->GetHistogram();
     859           0 :     his->SetMaximum(max);
     860           0 :     his->SetMinimum(min);
     861           0 :     his->GetXaxis()->SetTitle("R (cm)");
     862           0 :     his->GetYaxis()->SetTitle(axisTitle);
     863           0 :     his->SetTitle(Form("%s- sector %d",varTitle,isec));
     864           0 :     his->SetName(Form("%s- sector %d",varTitle,isec));
     865           0 :     if (isec==-1) his->SetTitle(Form("%s C side",varTitle));
     866           0 :     if (isec==-1) his->Draw();
     867           0 :     his->Draw("same");
     868           0 :     legend->AddEntry(his);
     869           0 :   }
     870           0 :   legend->Draw();
     871             :   //
     872             :   //
     873             :   return canvas;
     874           0 : }
     875             : 
     876             : 
     877             : TCanvas * AliTPCCalPad::MakeReportPadSector2D(TTree *chain, const char* varName, const char*varTitle, const char *axisTitle, Float_t min, Float_t max, const char *cutUser){
     878             :   /// Make a report - cal pads per sector
     879             :   /// 2D view
     880             :   /// Input tree should be created using AliPreprocesorOnline before
     881             : 
     882             :   TH1* his=0;
     883           0 :   TCanvas *canvas = new TCanvas(Form("%s2D",varTitle),Form("%s2D",varTitle),1500,1100);
     884           0 :   canvas->Divide(2);
     885             :   //
     886           0 :   TString strDraw=varName;
     887           0 :   strDraw+=":gy.fElements:gx.fElements>>his(250,-250,250,250,-250,250)";
     888             :   //
     889             :   TVirtualPad * pad=0;
     890           0 :   pad=canvas->cd(1);
     891           0 :   pad->SetMargin(0.15,0.15,0.15,0.15);
     892           0 :   TCut cut=cutUser;
     893           0 :   chain->Draw(strDraw.Data(),"sector%36<18"+cut,"profgoffcolz2");
     894           0 :   his=(TH1*)chain->GetHistogram()->Clone();
     895           0 :   delete chain->GetHistogram();
     896           0 :   his->SetMaximum(max);
     897           0 :   his->SetMinimum(min);
     898           0 :   his->GetXaxis()->SetTitle("x (cm)");
     899           0 :   his->GetYaxis()->SetTitle("y (cm)");
     900           0 :   his->GetZaxis()->SetTitle(axisTitle);
     901           0 :   his->SetTitle(Form("%s A side",varTitle));
     902           0 :   his->SetName(Form("%s A side",varTitle));
     903           0 :   his->Draw("colz2");
     904             :   //
     905           0 :   pad=canvas->cd(2);
     906           0 :   pad->SetMargin(0.15,0.15,0.15,0.15);
     907             : 
     908           0 :   chain->Draw(strDraw.Data(),"sector%36>=18"+cut,"profgoffcolz2");
     909           0 :   his=(TH1*)chain->GetHistogram()->Clone();
     910           0 :   delete chain->GetHistogram();
     911           0 :   his->SetMaximum(max);
     912           0 :   his->SetMinimum(min);
     913           0 :   his->GetXaxis()->SetTitle("x (cm)");
     914           0 :   his->GetYaxis()->SetTitle("y (cm)");
     915           0 :   his->GetZaxis()->SetTitle(axisTitle);
     916           0 :   his->SetTitle(Form("%s C side",varTitle));
     917           0 :   his->SetName(Form("%s C side",varTitle));
     918           0 :   his->Draw("colz2");
     919             :   //
     920             :   //
     921             :   return canvas;
     922           0 : }
     923             : 
     924             : void  AliTPCCalPad::Draw(Option_t* option){
     925             :   /// Draw function - standard 2D view
     926             : 
     927             :   TH1* his=0;
     928           0 :   TCanvas *canvas = new TCanvas(Form("%s2D",GetTitle()),Form("%s2D",GetTitle()),900,900);
     929           0 :   canvas->Divide(2,2);
     930             :   //
     931             :   //
     932             :   TVirtualPad * pad=0;
     933           0 :   pad=canvas->cd(1);
     934           0 :   pad->SetMargin(0.15,0.15,0.15,0.15);
     935           0 :   his=MakeHisto2D(0);
     936           0 :   his->GetXaxis()->SetTitle("x (cm)");
     937           0 :   his->GetYaxis()->SetTitle("y (cm)");
     938           0 :   his->GetZaxis()->SetTitle(GetTitle());
     939           0 :   his->SetTitle(Form("%s A side",GetTitle()));
     940           0 :   his->SetName(Form("%s A side",GetTitle()));
     941           0 :   his->Draw(option);
     942             :   //
     943           0 :   pad=canvas->cd(2);
     944           0 :   pad->SetMargin(0.15,0.15,0.15,0.15);
     945           0 :   his=MakeHisto2D(1);
     946           0 :   his->GetXaxis()->SetTitle("x (cm)");
     947           0 :   his->GetYaxis()->SetTitle("y (cm)");
     948           0 :   his->GetZaxis()->SetTitle(GetTitle());
     949           0 :   his->SetTitle(Form("%s C side",GetTitle()));
     950           0 :   his->SetName(Form("%s C side",GetTitle()));
     951           0 :   his->Draw(option);
     952             :   //
     953           0 :   pad=canvas->cd(3);
     954           0 :   pad->SetMargin(0.15,0.15,0.15,0.15);
     955           0 :   his=MakeHisto1D(-8,8,0,1);
     956           0 :   his->GetXaxis()->SetTitle(GetTitle());
     957           0 :   his->SetTitle(Form("%s A side",GetTitle()));
     958           0 :   his->SetName(Form("%s A side",GetTitle()));
     959           0 :   his->Draw("err");
     960             :   //
     961           0 :   pad=canvas->cd(4);
     962           0 :   pad->SetMargin(0.15,0.15,0.15,0.15);
     963           0 :   his=MakeHisto1D(-8,8,0,-1);
     964           0 :   his->GetXaxis()->SetTitle(GetTitle());
     965           0 :   his->SetTitle(Form("%s C side",GetTitle()));
     966           0 :   his->SetName(Form("%s C side",GetTitle()));
     967           0 :   his->Draw("err");
     968             : 
     969             : 
     970           0 : }
     971             : 
     972             : 
     973             : AliTPCCalPad * AliTPCCalPad::MakeCalPadFromHistoRPHI(TH2 * hisA, TH2* hisC){
     974             :   /// Make cal pad from r-phi histograms
     975             : 
     976           0 :   AliTPCROC *proc= AliTPCROC::Instance();
     977           0 :   AliTPCCalPad *calPad = new AliTPCCalPad("his","his");
     978           0 :   Float_t globalPos[3];
     979           0 :   for (Int_t isec=0; isec<72; isec++){
     980           0 :     AliTPCCalROC* calRoc  = calPad->GetCalROC(isec);
     981           0 :     TH2 * his = ((isec%36<18) ? hisA:hisC);
     982           0 :     for (UInt_t irow=0; irow<calRoc->GetNrows(); irow+=1){
     983             :       Int_t jrow=irow;
     984           0 :       if (isec>=36) jrow+=63;
     985           0 :       for (UInt_t ipad=0;ipad<proc->GetNPads(isec,irow);ipad+=1){
     986           0 :         proc->GetPositionGlobal(isec,irow,ipad, globalPos);
     987           0 :         Double_t phi=TMath::ATan2(globalPos[1],globalPos[0]);
     988             :         //if (phi<0) phi+=TMath::Pi()*2;
     989           0 :         Int_t bin=his->FindBin(phi,jrow);
     990           0 :         Float_t value= his->GetBinContent(bin);
     991           0 :         calRoc->SetValue(irow,ipad,value);
     992             :       }
     993             :     }
     994             :   }
     995           0 :   return calPad;
     996           0 : }
     997             : 
     998             : AliTPCCalPad *AliTPCCalPad::MakePadFromTree(TTree * treePad, const char *query, const char* name, Bool_t doFast){
     999             :   /// make cal pad from the tree
    1000             : 
    1001           0 :   if (!treePad){
    1002           0 :     ::Error("AliTPCCalPad::MakePadFromTree(TTree * treePad, const char *query, const char* name)","Input tree is missing");
    1003           0 :     return 0;
    1004             :   }
    1005           0 :   if (treePad->GetEntries()!=kNsec) return 0;
    1006           0 :   AliTPCCalPad * calPad= new AliTPCCalPad(name,name);
    1007           0 :   if (name) calPad->SetName(name);
    1008           0 :   if (!doFast){
    1009           0 :     for (Int_t iSec=0; iSec<72; iSec++){
    1010           0 :       AliTPCCalROC* calROC  = calPad->GetCalROC(iSec);
    1011           0 :       UInt_t nchannels = (UInt_t)treePad->Draw(query,"1","goff",1,iSec);
    1012           0 :       if (nchannels!=calROC->GetNchannels()) {
    1013           0 :         ::Error("AliTPCCalPad::MakePad","%s\t:Wrong query sector\t%d\t%d",treePad->GetName(),iSec,nchannels);
    1014           0 :         break;
    1015             :       }
    1016           0 :       for (UInt_t index=0; index<nchannels; index++) calROC->SetValue(index,treePad->GetV1()[index]);
    1017           0 :     }
    1018           0 :   }else{    
    1019           0 :     UInt_t nchannelsTree = (UInt_t)treePad->Draw(query,"1","goff");
    1020             :     UInt_t nchannelsAll=0;
    1021           0 :     for (Int_t iSec=0; iSec<72; iSec++){
    1022           0 :       AliTPCCalROC* calROC  = calPad->GetCalROC(iSec);
    1023           0 :       UInt_t nchannels=calROC->GetNchannels();
    1024           0 :       for (UInt_t index=0; index<nchannels; index++) {
    1025           0 :         if (nchannelsAll<=nchannelsTree)calROC->SetValue(index,treePad->GetV1()[nchannelsAll]);
    1026           0 :         nchannelsAll++;
    1027             :       }
    1028             :     }
    1029           0 :     if (nchannelsAll>nchannelsTree){
    1030           0 :       ::Error("AliTPCCalPad::MakePad","%s\t:Wrong query: cout mismatch\t%d\t%d",query, nchannelsAll,nchannelsTree);
    1031           0 :     }
    1032             :   }
    1033             :   return calPad;
    1034           0 : }
    1035             : 
    1036             : void AliTPCCalPad::AddFriend(TTree * treePad, const char *friendName, const char *fname){
    1037             :   ///
    1038             : 
    1039           0 :   TObjArray *fArray = new TObjArray(1);
    1040           0 :   fArray->AddLast(this);
    1041           0 :   this->SetName(friendName);
    1042           0 :   AliTPCCalibViewer::MakeTree(fname, fArray,0);
    1043           0 :   TFile * f = TFile::Open(fname);
    1044           0 :   TTree * tree = (TTree*)f->Get("calPads");
    1045           0 :   treePad->AddFriend(tree,friendName);
    1046             :   //  tree->AddFriend(TString::Format("%s = calPads",friendName).Data(),fname);
    1047           0 : }
    1048             : 
    1049             : //_____________________________________________________________________________
    1050             : void AliTPCCalPad::DumpUnitTestTrees(TString fileName/*=""*/)
    1051             : {
    1052             :   /// Dump a unit test tree with most derived variables
    1053             :   /// If filename is empty, then the "<ClassName>_UnitTest.root" is used
    1054             : 
    1055           0 :   if (fileName.IsNull()) fileName=TString::Format("%s_UnitTest.root",IsA()->GetName());
    1056             : 
    1057             :   //===========================================================================
    1058             :   // ===| CalPad fits |========================================================
    1059             :   // --- create fit cal pads
    1060           0 :   AliTPCCalPad *localFit         = LocalFit ("localFit",5,5);
    1061           0 :   AliTPCCalPad *globalFit        = GlobalFit("globalFit");
    1062           0 :   AliTPCCalPad *globalFitRegions = GlobalFit("globalFitRegions",0,kFALSE,1,5,0.7,1,0x0,0x0,AliTPCCalROC::kOROCmedium);
    1063             : 
    1064           0 :   TObjArray arrFits(3);
    1065           0 :   arrFits.Add(localFit);
    1066           0 :   arrFits.Add(globalFit);
    1067           0 :   arrFits.Add(globalFitRegions);
    1068           0 :   arrFits.SetOwner();
    1069             : 
    1070             :   // --- dump to tree
    1071           0 :   AliTPCCalibViewer::MakeTree(fileName, &arrFits);
    1072             : 
    1073             :   //===========================================================================
    1074             :   // ===| single variables     |===============================================
    1075             : 
    1076           0 :   TTreeSRedirector stream(fileName,"UPDATE");
    1077             : 
    1078             :   // ---| set up all variables |-----------------------------------------------
    1079           0 :   Double_t mean       = GetMean();
    1080           0 :   Double_t rms        = GetRMS();
    1081           0 :   Double_t median     = GetMedian();
    1082           0 :   Double_t minElement = GetMinElement();
    1083           0 :   Double_t maxElement = GetMaxElement();
    1084           0 :   Double_t ltmSigma   = 0.;
    1085           0 :   Double_t ltm        = GetLTM(&ltmSigma);
    1086             : 
    1087             :   // ---| Dump to Tree |-------------------------------------------------------
    1088           0 :   stream << "vars" <<
    1089           0 :   "mean="       << mean        <<
    1090           0 :   "rms="        << rms         <<
    1091           0 :   "median="     << median      <<
    1092           0 :   "minElement=" << minElement  <<
    1093           0 :   "maxElement=" << maxElement  <<
    1094           0 :   "ltmSigma="   << ltmSigma    <<
    1095           0 :   "ltm="        << ltm         <<
    1096             :   "\n";
    1097             : 
    1098             : 
    1099           0 : }

Generated by: LCOV version 1.11