]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/dielectron/AliDielectronHelper.cxx
Implemented NxM cluster finder
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliDielectronHelper.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2009, 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 //
17 // Dielectron helper functions wrapped in a namespace
18 // 
19 //
20 // Authors: 
21 //   Jens Wiechula <Jens.Wiechula@cern.ch> 
22 // 
23
24
25
26
27 #include <TError.h>
28 #include <TMath.h>
29 #include <TObjString.h>
30 #include <TObjArray.h>
31 #include <TVectorD.h>
32
33 #include "AliDielectronHelper.h"
34
35 //_____________________________________________________________________________
36 TVectorD* AliDielectronHelper::MakeLogBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
37 {
38   //
39   // Make logarithmic binning
40   // the user has to delete the array afterwards!!!
41   //
42   
43   //check limits
44   if (xmin<1e-20 || xmax<1e-20){
45     Error("AliDielectronHelper::MakeLogBinning","For Log binning xmin and xmax must be > 1e-20. Using linear binning instead!");
46     return AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
47   }
48   if (xmax<xmin){
49     Double_t tmp=xmin;
50     xmin=xmax;
51     xmax=tmp;
52   }
53   TVectorD *binLim=new TVectorD(nbinsX+1);
54   Double_t first=xmin;
55   Double_t last=xmax;
56   Double_t expMax=TMath::Log(last/first);
57   for (Int_t i=0; i<nbinsX+1; ++i){
58     (*binLim)[i]=first*TMath::Exp(expMax/nbinsX*(Double_t)i);
59   }
60   return binLim;
61 }
62
63 //_____________________________________________________________________________
64 TVectorD* AliDielectronHelper::MakeLinBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
65 {
66   //
67   // Make linear binning
68   // the user has to delete the array afterwards!!!
69   //
70   if (xmax<xmin){
71     Double_t tmp=xmin;
72     xmin=xmax;
73     xmax=tmp;
74   }
75   TVectorD *binLim=new TVectorD(nbinsX+1);
76   Double_t first=xmin;
77   Double_t last=xmax;
78   Double_t binWidth=(last-first)/nbinsX;
79   for (Int_t i=0; i<nbinsX+1; ++i){
80     (*binLim)[i]=first+binWidth*(Double_t)i;
81   }
82   return binLim;
83 }
84
85 //_____________________________________________________________________________
86 TVectorD* AliDielectronHelper::MakeArbitraryBinning(const char* bins)
87 {
88   //
89   // Make arbitrary binning, bins separated by a ','
90   //
91   TString limits(bins);
92   if (limits.IsNull()){
93     Error("AliDielectronHelper::MakeArbitraryBinning","Bin Limit string is empty, cannot add the variable");
94     return 0x0;
95   }
96   
97   TObjArray *arr=limits.Tokenize(",");
98   Int_t nLimits=arr->GetEntries();
99   if (nLimits<2){
100     Error("AliDielectronHelper::MakeArbitraryBinning","Need at leas 2 bin limits, cannot add the variable");
101     delete arr;
102     return 0x0;
103   }
104   
105   TVectorD *binLimits=new TVectorD(nLimits);
106   for (Int_t iLim=0; iLim<nLimits; ++iLim){
107     (*binLimits)[iLim]=(static_cast<TObjString*>(arr->At(iLim)))->GetString().Atof();
108   }
109   
110   delete arr;
111   return binLimits;
112 }
113