]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Adding statistical function (Marian)
authormarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 3 Apr 2007 08:52:07 +0000 (08:52 +0000)
committermarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 3 Apr 2007 08:52:07 +0000 (08:52 +0000)
TPC/AliTPCCalPad.cxx
TPC/AliTPCCalPad.h
TPC/AliTPCCalROC.cxx
TPC/AliTPCCalROC.h

index 1c4ce236315dc55203e520781af9b8314fe46b20..e0cf8567d949422b0756c58f9d0fda2fa91ac34d 100644 (file)
@@ -23,7 +23,9 @@
 
 #include "AliTPCCalPad.h"
 #include "AliTPCCalROC.h"
-
+#include <TObjArray.h>
+#include <TAxis.h>
+#include <TGraph.h>
 ClassImp(AliTPCCalPad)
 
 //_____________________________________________________________________________
@@ -63,6 +65,20 @@ AliTPCCalPad::AliTPCCalPad(const AliTPCCalPad &c):TNamed(c)
 
 }
 
+//_____________________________________________________________________________
+AliTPCCalPad::AliTPCCalPad(TObjArray * array):TNamed()
+{
+  //
+  // AliTPCCalPad default constructor
+  //
+
+  for (Int_t isec = 0; isec < kNsec; isec++) {
+    fROC[isec] = (AliTPCCalROC *)array->At(isec);
+  }
+
+}
+
+
 ///_____________________________________________________________________________
 AliTPCCalPad::~AliTPCCalPad()
 {
@@ -105,3 +121,37 @@ void AliTPCCalPad::Copy(TObject &c) const
   }
   TObject::Copy(c);
 }
+
+TGraph  *  AliTPCCalPad::MakeGraph(Int_t type, Float_t ratio){
+  //
+  //   type=1 - mean
+  //        2 - median
+  //        3 - LTM
+  Int_t npoints = 0;
+  for (Int_t i=0;i<72;i++) if (fROC[i]) npoints++;
+  TGraph * graph = new TGraph(npoints);
+  npoints=0;   
+  for (Int_t isec=0;isec<72;isec++){
+    if (!fROC[isec]) continue;
+    if (type==0)  graph->SetPoint(npoints,isec,fROC[isec]->GetMean());      
+    if (type==1)  graph->SetPoint(npoints,isec,fROC[isec]->GetMedian());
+    if (type==2)  graph->SetPoint(npoints,isec,fROC[isec]->GetLTM(0,ratio));    
+    npoints++;
+  }
+
+  graph->GetXaxis()->SetTitle("Sector"); 
+  if (type==0) {
+    graph->GetYaxis()->SetTitle("Mean");   
+    graph->SetMarkerStyle(22);    
+  }
+  if (type==1) {
+    graph->GetYaxis()->SetTitle("Median");   
+    graph->SetMarkerStyle(22);    
+  }
+  if (type==2) {
+      graph->GetYaxis()->SetTitle(Form("Mean%f",ratio));      
+      graph->SetMarkerStyle(24);
+  }
+
+  return graph;
+}
index a94e11b4f625b6e0981b36fc5ed22e69e63c6a28..7ef09c82679097d3b9fc76c26d7f861e0a8924b4 100644 (file)
@@ -15,6 +15,8 @@
 
 class AliTPCCalROC;
 class AliTPCCalDet;
+class TObjArray;
+class TGraph;
 
 class AliTPCCalPad : public TNamed {
  public:
@@ -22,10 +24,14 @@ class AliTPCCalPad : public TNamed {
   AliTPCCalPad();
   AliTPCCalPad(const Text_t* name, const Text_t* title);
   AliTPCCalPad(const AliTPCCalPad &c);   
+  AliTPCCalPad(TObjArray *arrayROC);
   virtual ~AliTPCCalPad();
   AliTPCCalPad &operator=(const AliTPCCalPad &c);
   virtual void     Copy(TObject &c) const;
   AliTPCCalROC *GetCalROC(Int_t sector) const { return fROC[sector]; };  
+  //
+  //
+  TGraph       *MakeGraph(Int_t type=0, Float_t ratio=0.7);
  protected:
   AliTPCCalROC *fROC[kNsec];                    //  Array of ROC objects which contain the values per pad
   ClassDef(AliTPCCalPad,1)                      //  TPC calibration class for parameters which are saved per pad
index 81d43923963ff668d11ee168f7ba3e4a9ebf0b72..5a6f527f6a1b67704a1c2e60943f34049b9c75fb 100644 (file)
@@ -26,7 +26,9 @@
 #include "TMath.h"
 #include "TClass.h"
 #include "TFile.h"
+#include "TH1F.h"
 #include "TH2F.h"
+#include "AliMathBase.h"
 ClassImp(AliTPCCalROC)
 
 
@@ -122,11 +124,98 @@ void AliTPCCalROC::Streamer(TBuffer &R__b)
 }
 
 
+Double_t AliTPCCalROC::GetLTM(Double_t *sigma, Double_t fraction){
+  //
+  //  Calculate LTM mean and sigma
+  //
+  Double_t *ddata = new Double_t[fNChannels];
+  Double_t mean=0, lsigma=0;
+  Int_t hh = TMath::Min(TMath::Nint(fraction *fNChannels), Int_t(fNChannels));
+  for (UInt_t i=0;i<fNChannels;i++) ddata[i]= fData[i];
+  AliMathBase::EvaluateUni(UInt_t(fNChannels),ddata, mean, lsigma, hh);
+  if (sigma) *sigma=lsigma;
+  delete [] ddata;
+  return mean;
+}
 
-void AliTPCCalROC::Draw(Option_t* option){
+TH1F * AliTPCCalROC::MakeHisto1D(Float_t min, Float_t max,Int_t type){
   //
-  // create histogram with values and draw it
+  // make 1D histo
+  // type -1 = user defined range
+  //       0 = nsigma cut nsigma=min
+  //       1 = delta cut around median delta=min
+  if (type>=0){
+    if (type==0){
+      // nsigma range
+      Float_t mean  = GetMean();
+      Float_t sigma = GetRMS();
+      Float_t nsigma = TMath::Abs(min);
+      min = mean-nsigma*sigma;
+      max = mean+nsigma*sigma;
+    }
+    if (type==1){
+      // fixed range
+      Float_t mean   = GetMedian();
+      Float_t  delta = min;
+      min = mean-delta;
+      max = mean+delta;
+    }
+    if (type==2){
+      //
+      // LTM mean +- nsigma
+      //
+      Double_t sigma;
+      Float_t mean  = GetLTM(&sigma,max);
+      sigma*=min;
+      min = mean-sigma;
+      max = mean+sigma;
+    }
+  }
+  char  name[1000];
+  sprintf(name,"%s ROC 1D%d",GetTitle(),fSector);
+  TH1F * his = new TH1F(name,name,100, min,max);
+  for (UInt_t irow=0; irow<fNRows; irow++){
+    UInt_t npads = (Int_t)GetNPads(irow);
+    for (UInt_t ipad=0; ipad<=npads; ipad++){
+      his->Fill(GetValue(irow,ipad));
+    }
+  }
+  return his;
+}
+
+
+
+TH2F * AliTPCCalROC::MakeHisto2D(Float_t min, Float_t max,Int_t type){
   //
+  // make 2D histo
+  // type -1 = user defined range
+  //       0 = nsigma cut nsigma=min
+  //       1 = delta cut around median delta=min
+  if (type>=0){
+    if (type==0){
+      // nsigma range
+      Float_t mean  = GetMean();
+      Float_t sigma = GetRMS();
+      Float_t nsigma = TMath::Abs(min);
+      min = mean-nsigma*sigma;
+      max = mean+nsigma*sigma;
+    }
+    if (type==1){
+      // fixed range
+      Float_t mean   = GetMedian();
+      Float_t  delta = min;
+      min = mean-delta;
+      max = mean+delta;
+    }
+    if (type==2){
+      Double_t sigma;
+      Float_t mean  = GetLTM(&sigma,max);
+      sigma*=min;
+      min = mean-sigma;
+      max = mean+sigma;
+
+    }
+  }
   UInt_t maxPad = 0;
   for (UInt_t irow=0; irow<fNRows; irow++){
     if (GetNPads(irow)>maxPad) maxPad = GetNPads(irow);
@@ -140,10 +229,62 @@ void AliTPCCalROC::Draw(Option_t* option){
       his->Fill(irow+0.5,Int_t(ipad)-Int_t(npads/2)+0.5,GetValue(irow,ipad));
     }
   }
+  his->SetMaximum(max);
+  his->SetMinimum(min);
+  return his;
+}
+
+TH2F * AliTPCCalROC::MakeHistoOutliers(Float_t delta, Float_t fraction, Int_t type){
+  //
+  // Make Histogram with outliers
+  // mode = 0 - sigma cut used
+  // mode = 1 - absolute cut used
+  // fraction - fraction of values used to define sigma
+  // delta - in mode 0 - nsigma cut
+  //            mode 1 - delta cut
+  Double_t sigma;
+  Float_t mean  = GetLTM(&sigma,fraction);  
+  if (type==0) delta*=sigma; 
+  UInt_t maxPad = 0;
+  for (UInt_t irow=0; irow<fNRows; irow++){
+    if (GetNPads(irow)>maxPad) maxPad = GetNPads(irow);
+  }
+
+  char  name[1000];
+  sprintf(name,"%s ROC Outliers%d",GetTitle(),fSector);
+  TH2F * his = new TH2F(name,name,fNRows+10,-5, fNRows+5, maxPad+10, -(Int_t(maxPad/2))-5, maxPad/2+5);
+  for (UInt_t irow=0; irow<fNRows; irow++){
+    UInt_t npads = (Int_t)GetNPads(irow);
+    for (UInt_t ipad=0; ipad<=npads; ipad++){
+      if (TMath::Abs(GetValue(irow,ipad)-mean)>delta)
+       his->Fill(irow+0.5,Int_t(ipad)-Int_t(npads/2)+0.5,1);
+    }
+  }
+  return his;
+}
+
+
+
+void AliTPCCalROC::Draw(Option_t* opt){
+  //
+  // create histogram with values and draw it
+  //
+  TH1 * his=0; 
+  TString option=opt;
+  option.ToUpper();
+  if (option.Contains("1D")){
+    his = MakeHisto1D();
+  }
+  else{
+    his = MakeHisto2D();
+  }
   his->Draw(option);
 }
 
 
+
+
+
 void AliTPCCalROC::Test(){
   //
   // example function to show functionality and tes AliTPCCalROC
index 2f38dcd69bff72bb58878a1be59354ad6b091485..ddceadceee516827a88217694b5d5bf16f7b7476 100644 (file)
 //////////////////////////////////////////////////
 
 #include <TObject.h>
+#include <TMath.h>
 #include <AliTPCROC.h>
-
+class TH1F;
+class TH2F;
 //_____________________________________________________________________________
 class AliTPCCalROC : public TObject {
 
@@ -32,6 +34,14 @@ class AliTPCCalROC : public TObject {
   void         SetValue(UInt_t row, UInt_t pad, Float_t vd) { if ( row<fNRows && (fIndexes[row]+pad)<fNChannels)fData[fIndexes[row]+pad]= vd; };
   void         SetValue(UInt_t channel, Float_t vd) {fData[channel]= vd; };
   virtual void Draw(Option_t* option = "");
+  //
+  Double_t GetMean(){return TMath::Mean(fNChannels, fData);}
+  Double_t GetRMS() {return TMath::RMS(fNChannels, fData);}
+  Double_t GetMedian() {return TMath::Median(fNChannels, fData);}
+  Double_t GetLTM(Double_t *sigma=0, Double_t fraction=0.9);
+  TH1F * MakeHisto1D(Float_t min=4, Float_t max=-4, Int_t type=0);     
+  TH2F * MakeHisto2D(Float_t min=4, Float_t max=-4, Int_t type=0);   
+  TH2F * MakeHistoOutliers(Float_t delta=4, Float_t fraction=0.7, Int_t mode=0);
   static void Test();
  protected:
   UInt_t     fSector;          // sector number