Changes needed for cuts optimisation task (Francesco)
authordainese <dainese@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 16 Jul 2009 01:23:34 +0000 (01:23 +0000)
committerdainese <dainese@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 16 Jul 2009 01:23:34 +0000 (01:23 +0000)
PWG3/vertexingHF/AliMultiDimVector.cxx
PWG3/vertexingHF/AliMultiDimVector.h
PWG3/vertexingHF/TestMultiVector.C

index b6d61be..bfa7132 100644 (file)
@@ -29,7 +29,6 @@
 #include "TH2.h"
 #include "AliMultiDimVector.h"
 #include "AliLog.h"
-#include "TMath.h"
 #include "TString.h"
 
 ClassImp(AliMultiDimVector)
@@ -44,7 +43,7 @@ fIsIntegrated(0)
   // default constructor
 }
 //___________________________________________________________________________
-AliMultiDimVector::AliMultiDimVector(const char *name,const char *title, const Int_t npars, Int_t nptbins, Int_t *nofcells, Float_t *loosecuts, Float_t *tightcuts, TString *axisTitles):TNamed(name,title),
+AliMultiDimVector::AliMultiDimVector(const char *name,const char *title, const Int_t nptbins, Float_t* ptlimits, const Int_t npars,  Int_t *nofcells, Float_t *loosecuts, Float_t *tightcuts, TString *axisTitles):TNamed(name,title),
 fNVariables(npars),
 fNPtBins(nptbins),
 fVett(0),
@@ -66,8 +65,10 @@ fIsIntegrated(0){
     }
     fAxisTitles[i]=axisTitles[i].Data();
   }
-  fNTotCells=ntot*fNPtBins;
+  fNTotCells=ntot*fNPtBins;  
   fVett.Set(fNTotCells); 
+  for(Int_t ipt=0;ipt<fNPtBins+1;ipt++) fPtLimits[ipt]=ptlimits[ipt];
+  for(Int_t ipt=fNPtBins+1;ipt<fgkMaxNPtBins+1;ipt++) fPtLimits[ipt]=999.;
   for (ULong64_t j=0;j<fNTotCells;j++) fVett.AddAt(0,j);
 }
 //___________________________________________________________________________
@@ -87,6 +88,8 @@ fIsIntegrated(mv.fIsIntegrated)
     fAxisTitles[i]=mv.GetAxisTitle(i);
   }
   fVett.Set(fNTotCells); 
+  
+  for(Int_t ipt=0;ipt<fNPtBins+1;ipt++) fPtLimits[ipt]=mv.GetPtLimit(ipt);
   for(ULong64_t i=0;i<fNTotCells;i++) fVett[i]=mv.GetElement(i);
 }
 //___________________________________________________________________________
@@ -103,8 +106,8 @@ void AliMultiDimVector::CopyStructure(const AliMultiDimVector* mv){
     fGreaterThan[i]=mv->GetGreaterThan(i);
     fAxisTitles[i]=mv->GetAxisTitle(i);
   }
-  fVett.Set(fNTotCells);
-  
+  for(Int_t ipt=0;ipt<fNPtBins+1;ipt++) fPtLimits[ipt]=mv->GetPtLimit(ipt);
+  fVett.Set(fNTotCells);  
 }
 //______________________________________________________________________
 Bool_t AliMultiDimVector::GetIndicesFromGlobalAddress(ULong64_t globadd, Int_t *ind, Int_t &ptbin) const {
@@ -375,6 +378,49 @@ void AliMultiDimVector::Integrate(){
   for(ULong64_t i=0;i<fNTotCells;i++) integral[i]=CountsAboveCell(i);
   for(ULong64_t i=0;i<fNTotCells;i++) fVett[i]= integral[i];
   fIsIntegrated=kTRUE;
+}//_____________________________________________________________________________ 
+ULong64_t* AliMultiDimVector::GetGlobalAddressesAboveCuts(Float_t *values, Int_t ptbin, Int_t& nVals) const{
+  // fills an array with global addresses of cells passing the cuts
+
+  Int_t ind[fgkMaxNVariables];
+  Bool_t retcode=GetIndicesFromValues(values,ind);
+  if(!retcode){ 
+    nVals=0;
+    return 0x0;
+  }
+  for(Int_t i=fNVariables; i<fgkMaxNVariables; i++) ind[i]=0;
+  Int_t mink[fgkMaxNVariables];
+  Int_t maxk[fgkMaxNVariables];
+  Int_t size=1;
+  for(Int_t i=0;i<fgkMaxNVariables;i++){
+    GetFillRange(i,ind[i],mink[i],maxk[i]);
+    size*=(maxk[i]-mink[i]+1);
+  }
+  ULong64_t* indexes=new ULong64_t[size];
+  nVals=0;
+  for(Int_t k0=mink[0]; k0<=maxk[0]; k0++){
+    for(Int_t k1=mink[1]; k1<=maxk[1]; k1++){
+      for(Int_t k2=mink[2]; k2<=maxk[2]; k2++){
+       for(Int_t k3=mink[3]; k3<=maxk[3]; k3++){
+         for(Int_t k4=mink[4]; k4<=maxk[4]; k4++){
+           for(Int_t k5=mink[5]; k5<=maxk[5]; k5++){
+             for(Int_t k6=mink[6]; k6<=maxk[6]; k6++){
+               for(Int_t k7=mink[7]; k7<=maxk[7]; k7++){
+                 for(Int_t k8=mink[8]; k8<=maxk[8]; k8++){
+                   for(Int_t k9=mink[9]; k9<=maxk[9]; k9++){
+                     Int_t currentBin[fgkMaxNVariables]={k0,k1,k2,k3,k4,k5,k6,k7,k8,k9};
+                     indexes[nVals++]=GetGlobalAddressFromIndices(currentBin,ptbin);
+                   }
+                 }
+               }
+             }
+           }
+         }
+       }
+      }
+    }
+  }
+  return indexes;
 }
 //_____________________________________________________________________________ 
 Float_t AliMultiDimVector::CountsAboveCell(ULong64_t globadd) const{
@@ -492,7 +538,10 @@ AliMultiDimVector* AliMultiDimVector:: ShrinkPtBins(Int_t firstBin, Int_t lastBi
     axisTitles[i]=fAxisTitles[i];
   }
   Int_t newNptbins=fNPtBins-(lastBin-firstBin);
-  AliMultiDimVector* shrinkedMV=new AliMultiDimVector(GetName(),GetTitle(),fNVariables,newNptbins,nofcells,loosecuts,tightcuts,axisTitles);
+  Float_t ptlimits[fgkMaxNPtBins+1];
+  for(Int_t ipt=0; ipt<=firstBin;ipt++) ptlimits[ipt]=fPtLimits[ipt];
+  for(Int_t ipt=firstBin+1; ipt<newNptbins+1;ipt++) ptlimits[ipt]=fPtLimits[ipt+(lastBin-firstBin)];
+  AliMultiDimVector* shrinkedMV=new AliMultiDimVector(GetName(),GetTitle(),newNptbins,ptlimits,fNVariables,nofcells,loosecuts,tightcuts,axisTitles);
   
   ULong64_t nOfPointsPerPtbin=fNTotCells/fNPtBins;
   ULong64_t addressOld,addressNew;
@@ -525,3 +574,17 @@ AliMultiDimVector* AliMultiDimVector:: ShrinkPtBins(Int_t firstBin, Int_t lastBi
   }
   return shrinkedMV;
 }
+//_____________________________________________________________________________ 
+void AliMultiDimVector::PrintStatus(){
+  //
+  printf("Number of Pt bins       = %d\n",fNPtBins);
+  printf("Limits of Pt bins       = ");
+  for(Int_t ib=0;ib<fNPtBins+1;ib++) printf("%6.2f ",fPtLimits[ib]);
+  printf("\n");
+  printf("Number of cut variables = %d\n",fNVariables);
+  for(Int_t iv=0;iv<fNVariables;iv++){
+    printf("- Variable %d: %s\n",iv,fAxisTitles[iv].Data());
+    printf("    Nsteps= %d Rage = %6.2f %6.2f\n",
+          fNCutSteps[iv],fMinLimits[iv],fMaxLimits[iv]);
+  }
+}
index ae4570f..2496ecf 100644 (file)
@@ -20,6 +20,7 @@
 #include "TArrayI.h"
 #include "TNamed.h"
 #include "TH2.h"
+#include "TMath.h"
 #include "TString.h"
 
 class AliMultiDimVector :  public TNamed{
@@ -27,7 +28,7 @@ class AliMultiDimVector :  public TNamed{
  public:
   AliMultiDimVector();
   AliMultiDimVector(const AliMultiDimVector &mv);
-  AliMultiDimVector(const char *name, const char *title, const Int_t npars, Int_t nptbins, Int_t *nofcells, Float_t *loosecuts, Float_t *tightcuts, TString *axisTitles);
+  AliMultiDimVector(const char *name, const char *title, const Int_t nptbins, Float_t* ptlimits, const Int_t npars, Int_t *nofcells, Float_t *loosecuts, Float_t *tightcuts, TString *axisTitles);
   virtual ~AliMultiDimVector(){};
 
   ULong64_t GetNTotCells()            const {return fNTotCells;}
@@ -51,6 +52,12 @@ class AliMultiDimVector :  public TNamed{
     ULong64_t elem=GetGlobalAddressFromIndices(ind,ptbin);
     return fVett[elem];
   }
+  Float_t   GetPtLimit(Int_t i) const{return fPtLimits[i];}
+  Int_t     GetPtBin(const Float_t pt) const{
+    Int_t theBin=TMath::BinarySearch(fNPtBins+1,fPtLimits,pt);
+    if(theBin>=fNPtBins) theBin=-1;
+    return theBin;
+  }
   void      GetEntireMultiDimVector(Float_t *vett) const {
     for(ULong64_t i=0; i<fNTotCells; i++) vett[i]=fVett[i];
   }
@@ -60,6 +67,13 @@ class AliMultiDimVector :  public TNamed{
   Bool_t    GetIndicesFromValues(Float_t *values, Int_t *ind) const;
   ULong64_t GetGlobalAddressFromValues(Float_t *values, Int_t ptbin) const;
   Bool_t    GetCutValuesFromGlobalAddress(ULong64_t globadd, Float_t *cuts, Int_t &ptbin) const;
+  
+  ULong64_t* GetGlobalAddressesAboveCuts(Float_t *values, Float_t pt, Int_t& nVals) const{
+    Int_t theBin=GetPtBin(pt);
+    if(theBin>=0) return GetGlobalAddressesAboveCuts(values,theBin,nVals);
+    else return 0x0;
+  }
+  ULong64_t* GetGlobalAddressesAboveCuts(Float_t *values, Int_t ptbin, Int_t& nVals) const;
 
   void SetElement(ULong64_t globadd,Float_t val) {fVett[globadd]=val;}
   void SetElement(Int_t *ind, Int_t ptbin, Float_t val){
@@ -96,7 +110,8 @@ class AliMultiDimVector :  public TNamed{
   TH2F*  Project(Int_t firstVar, Int_t secondVar, Int_t* fixedVars, Int_t ptbin, Float_t norm=1.);
 
   void SuppressZeroBKGEffect(AliMultiDimVector* BKG);
-   AliMultiDimVector* ShrinkPtBins(Int_t firstBin, Int_t lastBin);
+  AliMultiDimVector* ShrinkPtBins(Int_t firstBin, Int_t lastBin);
+  void PrintStatus();
 
  protected:
   void GetIntegrationLimits(Int_t iVar, Int_t iCell, Int_t& minbin, Int_t& maxbin) const;
@@ -106,9 +121,11 @@ class AliMultiDimVector :  public TNamed{
 
  private:
   static const Int_t fgkMaxNVariables=10;  // max. n. of selection variables
+  static const Int_t fgkMaxNPtBins=10;     // max. n. of Pt bins
 
   Int_t     fNVariables;                   // n. of selection variables
   Int_t     fNPtBins;                      // n. of pt bins
+  Float_t   fPtLimits[fgkMaxNPtBins+1];    // limits of pt bins
   Int_t     fNCutSteps[fgkMaxNVariables];  // n. of cut step for each variable
   Float_t   fMinLimits[fgkMaxNVariables];  // lower cut value for each variable
   Float_t   fMaxLimits[fgkMaxNVariables];  // higher cut value for each variable
@@ -118,7 +135,7 @@ class AliMultiDimVector :  public TNamed{
   ULong64_t fNTotCells;              // total number of matrix elements
   Bool_t    fIsIntegrated;           // flag for integrated matrix 
 
-  ClassDef(AliMultiDimVector,1); // a multi-dimensional vector class
+  ClassDef(AliMultiDimVector,2); // a multi-dimensional vector class
 
 };
 
index c6910f2..368a54a 100644 (file)
@@ -9,7 +9,8 @@ void TestMultiVector(){
   gSystem->Load("libPWG3");
   gSystem->Load("libPWG3vertexingHF");
 
-  Int_t nptbins=4;
+  const Int_t nptbins=4;
+  Float_t ptlimits[5]={1.,2.,3.,5.,10.};
   const Int_t npars=3;
   Int_t nofcells[npars]={20,20,20};
   Float_t looses[npars]={0.,700.,0.8};
@@ -19,9 +20,9 @@ void TestMultiVector(){
   AxisTitle[1]="TrackDispersion";
   AxisTitle[2]="CosPoint";
 
-  AliMultiDimVector* mvsig=new AliMultiDimVector("Signal","Signal",npars,nptbins,nofcells,looses,tights,AxisTitle);
-  AliMultiDimVector* mvsig2=new AliMultiDimVector("Signal","Signal",npars,nptbins,nofcells,looses,tights,AxisTitle);
-  AliMultiDimVector* mvbkg=new AliMultiDimVector("Background","Background",npars,nptbins,nofcells,looses,tights,AxisTitle);
+  AliMultiDimVector* mvsig=new AliMultiDimVector("Signal","Signal",nptbins,ptlimits,npars,nofcells,looses,tights,AxisTitle);
+  AliMultiDimVector* mvsig2=new AliMultiDimVector("Signal","Signal",nptbins,ptlimits,npars,nofcells,looses,tights,AxisTitle);
+  AliMultiDimVector* mvbkg=new AliMultiDimVector("Background","Background",nptbins,ptlimits,npars,nofcells,looses,tights,AxisTitle);
 
 
   TF1* dsig=new TF1("dsig","exp(-x/310.)",0.,5000.);