]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added the possibility to define variable bins in output histograms.
authorpulvir <pulvir@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 12 Aug 2010 17:17:16 +0000 (17:17 +0000)
committerpulvir <pulvir@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 12 Aug 2010 17:17:16 +0000 (17:17 +0000)
Added an initial template for a histogram fitting class.

12 files changed:
PWG2/PWG2resonancesLinkDef.h
PWG2/RESONANCES/AliRsnAnalysisEffSE.cxx
PWG2/RESONANCES/AliRsnAnalysisEffSE.h
PWG2/RESONANCES/AliRsnFitResult.cxx
PWG2/RESONANCES/AliRsnFitResult.h
PWG2/RESONANCES/AliRsnFunction.cxx
PWG2/RESONANCES/AliRsnValue.cxx
PWG2/RESONANCES/AliRsnValue.h
PWG2/RESONANCES/macros/test/AddAnalysisTaskRsnTest.C
PWG2/RESONANCES/macros/test/ConfigTaskRsnTest.C
PWG2/RESONANCES/macros/test/runLocal.C
PWG2/libPWG2resonances.pkg

index 9a43d8d7d14392caa0c124bfb61cb9caf3a8c3a8..3248077911374910e237f4953c03d3300a55cd34 100644 (file)
@@ -43,6 +43,6 @@
 
 #pragma link C++ class AliRsnMonitorTrack+;
 #pragma link C++ class AliRsnAnalysisMonitorTask+;
-//#pragma link C++ class AliRsnFitResult+;
+#pragma link C++ class AliRsnFitResult+;
 
 #endif
index 3e06fdac0b4b0e94f4e38957e286fef07cf95fcd..ad6680a63eba97c4cfa33a285548efc909ab9acb 100644 (file)
@@ -93,7 +93,8 @@ void AliRsnAnalysisEffSE::RsnUserCreateOutputObjects()
   // retrieve number of bins for each axis
   Int_t   *nBins     = new Int_t[nAxes];
   TArrayD *binLimits = new TArrayD[nAxes];
-  for (iaxis = 0; iaxis < nAxes; iaxis++) {
+  for (iaxis = 0; iaxis < nAxes; iaxis++) 
+  {
     AliRsnValue *fcnAxis = (AliRsnValue*)fAxisList.At(iaxis);
     binLimits[iaxis] = fcnAxis->GetArray();
     nBins[iaxis] = binLimits[iaxis].GetSize() - 1;
index 7d730f7e634e5aa8988f30da2b75911891ebf74d..1eb2b8959f61c63dbfe8eed582f58b78720b6e50 100644 (file)
@@ -15,7 +15,6 @@
 #include "AliRsnVAnalysisTaskSE.h"
 #include "AliRsnEvent.h"
 #include "AliRsnMother.h"
-#include "AliRsnPIDIndex.h"
 
 class AliPID;
 
@@ -45,7 +44,7 @@ class AliRsnAnalysisEffSE : public AliRsnVAnalysisTaskSE
     // settings
     void            SetEventCuts(AliRsnCutSet *const cuts) {fEventCuts = cuts;}
     void            AddPairDef(AliRsnPairDef *pairDef);
-    void            AddStepMC(AliRsnCutManager *mgr) {fStepListMC.AddLast(mgr);}
+    void            AddStepMC(AliRsnCutManager *mgr)  {fStepListMC.AddLast(mgr);}
     void            AddStepESD(AliRsnCutManager *mgr) {fStepListESD.AddLast(mgr);}
     void            AddAxis(AliRsnValue *axis) {fAxisList.AddLast(axis);}
 
index 6bcffbeebc36d5cd06b1bab70facf4e9b81c824b..1d0cce6a1bb4f24f19eab28dc41aceaaf43a6fb5 100644 (file)
@@ -219,7 +219,7 @@ void AliRsnFitResult::SetHistogram(TH1F *histogram)
 
   if (fHistogram) delete fHistogram;
   
-  fHistogram = (TH1F*)histogram->Clone();
+  fHistogram = (TH1D*)histogram->Clone();
   fHistogram->SetName(Form("h_%s_%s", GetName(), histogram->GetName()));
   fHistogram->SetTitle(histogram->GetTitle());
 }
index bcf7f8790075c57cea1710db0839c5d093af61d8..e5a917a63006cfd65b22a774f3102c39f14374eb 100644 (file)
@@ -52,6 +52,7 @@ class AliRsnFitResult : public TNamed
     Double_t NormLinear(Double_t *x, Double_t *par);
     Double_t NormBreitWigner(Double_t *x, Double_t *par);
     Double_t NormGaus(Double_t *x, Double_t *par);
+    
     Double_t Signal(Double_t *x, Double_t *par);
     Double_t Background(Double_t *x, Double_t *par);
     Double_t Sum(Double_t *x, Double_t *par);
@@ -73,7 +74,7 @@ class AliRsnFitResult : public TNamed
     Double_t         fPeakRange[2];        // peak fit range
     Double_t         fFitResult[kValues];  // array of fit results
     
-    TH1F            *fHistogram;           // histogram to be fitted
+    TH1D            *fHistogram;           // histogram to be fitted
     TF1             *fSignalFcn;           // function for signal
     TF1             *fBackgroundFcn;       // function for background
     TF1             *fSumFcn;              // total function
index 3a2a322c8f02e5c38094a3506cab0903c85df402..73b835882402e5d048131cc1227b7891df23a67a 100644 (file)
@@ -20,6 +20,7 @@
 //
 
 #include <TString.h>
+#include <TAxis.h>
 
 #include "AliLog.h"
 
@@ -152,37 +153,37 @@ TH1* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTit
     return 0x0;
   }
 
-  Int_t    *nbins = new Int_t   [fSize];
-  Double_t *min   = new Double_t[fSize];
-  Double_t *max   = new Double_t[fSize];
-
   // retrieve binnings for main and secondary axes
-  AliRsnValue *fcnAxis = 0;
-  for (Int_t i = 0; i < fSize; i++) {
+  AliRsnValue *fcnAxis;
+  TArrayD      array[3];
+  for (Int_t i = 0; i < fSize; i++) 
+  {
     fcnAxis = (AliRsnValue*)fAxisList.At(i);
-    if (!fcnAxis) {
-      nbins[i] = 0;
-      min[i]   = 0.0;
-      max[i]   = 0.0;
+    if (!fcnAxis) 
+    {
       AliError("Empty axis");
+      array[i].Set(2);
+      array[i][0] = -1E5;
+      array[i][1] = -1E5;
       continue;
     }
-    nbins[i] = fcnAxis->GetNBins();
-    min[i]   = fcnAxis->GetMin();
-    max[i]   = fcnAxis->GetMax();
+    else
+    {
+      array[i] = fcnAxis->GetArray();
+    }
   }
 
   // create histogram depending on the number of axes
   switch (fSize)
   {
     case 1:
-      fH1 = new TH1F(histoName, histoTitle, nbins[0], min[0], max[0]);
+      fH1 = new TH1F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray());
       break;
     case 2:
-      fH1 = new TH2F(histoName, histoTitle, nbins[0], min[0], max[0], nbins[1], min[1], max[1]);
+      fH1 = new TH2F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray());
       break;
     case 3:
-      fH1 = new TH3F(histoName, histoTitle, nbins[0], min[0], max[0], nbins[1], min[1], max[1], nbins[2], min[2], max[2]);
+      fH1 = new TH3F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray(), array[2].GetSize() - 1, array[2].GetArray());
       break;
   }
   fH1->Sumw2();
@@ -208,42 +209,30 @@ THnSparseF* AliRsnFunction::CreateHistogramSparse(const char *histoName, const c
     AliError("No axes defined");
     return 0x0;
   }
+  
+  // create dummy variables to initialize the histogram
+  Int_t    dummyI;
+  Double_t dummyD;
 
-  Int_t    *nbins = new Int_t   [fSize];
-  Double_t *min   = new Double_t[fSize];
-  Double_t *max   = new Double_t[fSize];
-
-  // retrieve binnings for main and secondary axes
+  // create histogram
+  fHSparse = new THnSparseF(histoName, histoTitle, fSize, &dummyI, &dummyD, &dummyD);
+  fHSparse->Sumw2();
+  
+  // update the various axes using the definitions given in the array of axes here
   AliRsnValue *fcnAxis = 0;
-  for (Int_t i = 0; i < fSize; i++) {
+  TAxis       *axis = 0;
+  for (Int_t i = 0; i < fSize; i++) 
+  {
     fcnAxis = (AliRsnValue*)fAxisList.At(i);
+    axis    = fHSparse->GetAxis(i);
     if (!fcnAxis) {
-      nbins[i] = 0;
-      min[i]   = 0.0;
-      max[i]   = 0.0;
-      AliError("Empty axis");
+      axis->Set(1, -1E5, 1E5);
+      AliError("Empty axis: doing unique bin betweeen -100000 and 100000");
       continue;
     }
-    nbins[i] = fcnAxis->GetNBins();
-    min[i]   = fcnAxis->GetMin();
-    max[i]   = fcnAxis->GetMax();
-  }
-
-  Int_t size = fAxisList.GetEntries();
-  if (!size) {
-    AliError("No axes defined");
-    return 0x0;
+    axis->Set(fcnAxis->GetArray().GetSize() - 1, fcnAxis->GetArray().GetArray());
   }
 
-  // create histogram
-  fHSparse = new THnSparseF(histoName, histoTitle, size, nbins, min, max);
-  fHSparse->Sumw2();
-  
-  // clean heap
-  delete [] nbins;
-  delete [] min;
-  delete [] max;
-
   return fHSparse;
 }
 
index 7ba27107b037a8722247a6f7becd3752b8c8a289..6f6114c8e837a870870b570592f279ec0dcef96d 100644 (file)
@@ -20,10 +20,8 @@ ClassImp(AliRsnValue)
 AliRsnValue::AliRsnValue() :
   TNamed(),
   fType(kValueTypes),
-  fNBins(0),
-  fMin(0.0),
-  fMax(0.0),
-  fValue(0.0)
+  fValue(0.0),
+  fArray(0)
 {
 //
 // Main constructor (version 1)
@@ -36,10 +34,8 @@ AliRsnValue::AliRsnValue
 (const char *name, EValueType type, Int_t nbins, Double_t min, Double_t max) :
   TNamed(name, ""),
   fType(type),
-  fNBins(0),
-  fMin(0.0),
-  fMax(0.0),
-  fValue(0.0)
+  fValue(0.0),
+  fArray(0)
 {
 //
 // Main constructor (version 1)
@@ -54,10 +50,8 @@ AliRsnValue::AliRsnValue
 (const char *name, EValueType type, Double_t min, Double_t max, Double_t step) :
   TNamed(name, ""),
   fType(type),
-  fNBins(0),
-  fMin(0.0),
-  fMax(0.0),
-  fValue(0.0)
+  fValue(0.0),
+  fArray(0)
 {
 //
 // Main constructor (version 2)
@@ -66,90 +60,66 @@ AliRsnValue::AliRsnValue
   SetBins(min, max, step);
 }
 
-/*
 //_____________________________________________________________________________
-const char* AliRsnValue::GetName() const
+AliRsnValue::AliRsnValue
+(const char *name, EValueType type, Int_t nbins, Double_t *array) :
+  TNamed(name, ""),
+  fType(type),
+  fValue(0.0),
+  fArray(0)
 {
 //
-// Return the name of this object defined by the type
+// Main constructor (version 2)
 //
 
-  switch (fType)
-  {
-    case kTrack1P:        return "P1";
-    case kTrack2P:        return "P2";
-    case kTrack1Pt:       return "PT1";
-    case kTrack2Pt:       return "PT2";
-    case kPairInvMass:    return "IM";
-    case kPairInvMassMC:  return "IMMC";
-    case kPairInvMassRes: return "IMRES";
-    case kPairPt:         return "PT";
-    case kPairEta:        return "ETA";
-    case kPairMt:         return "MT";
-    case kPairY:          return "Y";
-    case kEventMult:      return "MULT";
-    default:              return "UNDEF";
-  }
+  SetBins(nbins, array);
 }
-*/
 
 //_____________________________________________________________________________
-TArrayD AliRsnValue::GetArray() const
+void AliRsnValue::SetBins(Int_t nbins, Double_t min, Double_t max)
 {
 //
-// Creates an array with all bin edges
+// Set binning for the axis in equally spaced bins
+// where the number of bins, minimum and maximum are given.
 //
 
-  TArrayD out(fNBins + 1);
-
-  Int_t i;
-  Double_t step = (fMax - fMin) / (Double_t)fNBins;
-
-  for (i = 0; i <= fNBins; i++) out[i] = fMin + step * (Double_t)i;
-
-  return out;
+  fArray.Set(nbins + 1);
+  
+  Double_t mymax = TMath::Max(min, max);
+  Double_t mymin = TMath::Min(min, max);
+  
+  Int_t    k = 0;
+  Double_t binSize = (mymax - mymin) / ((Double_t)nbins);
+  
+  fArray[0] = mymin;
+  for (k = 1; k <= nbins; k++) fArray[k] = fArray[k-1] + binSize;
+  for (k = 0; k < fArray.GetSize() - 1; k++) AliDebug(AliLog::kDebug + 3, Form("Bin #%d: %f - %f", k, fArray[k], fArray[k+1]));
 }
 
 //_____________________________________________________________________________
-void AliRsnValue::SetBins(Int_t n, Double_t min, Double_t max)
+void AliRsnValue::SetBins(Double_t min, Double_t max, Double_t step)
 {
 //
-// Set binning for histogram.
+// Set binning for the axis in equally spaced bins
+// where the bin size, minimum and maximum are given.
 //
 
-  fNBins = n;
-
-  if (min < max) 
-  {
-    fMin = min;
-    fMax = max;
-  } 
-  else 
-  {
-    fMin = max;
-    fMax = min;
-  }
+  Double_t dblNbins = TMath::Abs(max - min) / step;
+  Int_t    intNbins = ((Int_t)dblNbins) + 1;
+  
+  SetBins(intNbins, min, max);
 }
 
 //_____________________________________________________________________________
-void AliRsnValue::SetBins(Double_t min, Double_t max, Double_t step)
+void AliRsnValue::SetBins(Int_t nbins, Double_t *array)
 {
 //
-// Binning for histogram.
+// Set binning for the axis in unequally spaced bins
+// using the same way it is done in TAxis
 //
 
-  if (min < max) 
-  {
-    fMin = min;
-    fMax = max;
-  } 
-  else 
-  {
-    fMin = max;
-    fMax = min;
-  }
-
-  fNBins = (Int_t)((fMax - fMin) / (step)) + 1;
+  fArray.Adopt(nbins, array);
+  for (Int_t k = 0; k < fArray.GetSize() - 1; k++) AliDebug(AliLog::kDebug + 3, Form("Bin #%d: %f - %f", k, fArray[k], fArray[k+1]));
 }
 
 //_____________________________________________________________________________
index 2342878ce06ad7363664673dfc5e44b750319a6a..ad8d5977d786c0b74bddb08ac5b7af013a2de3bc 100644 (file)
@@ -42,33 +42,29 @@ class AliRsnValue : public TNamed
     };
 
     AliRsnValue();
-    AliRsnValue(const char *name, EValueType type, Int_t n, Double_t min, Double_t max);
+    AliRsnValue(const char *name, EValueType type, Int_t n = 0, Double_t min = 0.0, Double_t max = 0.0);
     AliRsnValue(const char *name, EValueType type, Double_t min, Double_t max, Double_t step);
-    AliRsnValue(const AliRsnValue& copy) : TNamed(copy),fType(copy.fType),fNBins(copy.fNBins),fMin(copy.fMin),fMax(copy.fMax),fValue(copy.fValue) {}
-    AliRsnValue& operator=(const AliRsnValue& copy) {SetName(copy.GetName());fType=copy.fType;fNBins=copy.fNBins;fMin=copy.fMin;fMax=copy.fMax;fValue=copy.fValue;return (*this);}
+    AliRsnValue(const char *name, EValueType type, Int_t n, Double_t *array);
+    AliRsnValue(const AliRsnValue& copy) : TNamed(copy),fType(copy.fType),fValue(copy.fValue),fArray(copy.fArray) {}
+    AliRsnValue& operator=(const AliRsnValue& copy) {SetName(copy.GetName());fType=copy.fType;fValue=copy.fValue;fArray=copy.fArray;return (*this);}
     virtual ~AliRsnValue() { }
     
-    //const char* GetName() const;
-    Int_t       GetNBins() const {return fNBins;}
-    Double_t    GetMin() const {return fMin;}
-    Double_t    GetMax() const {return fMax;}
-    TArrayD     GetArray() const;
+    TArrayD     GetArray() const {return fArray;}
     Double_t    GetValue() const {return fValue;}
     EValueType  GetValueType() {return fType;}
 
     void        SetValueType(EValueType type) {fType = type;}
     void        SetBins(Int_t n, Double_t min, Double_t max);
     void        SetBins(Double_t min, Double_t max, Double_t step);
+    void        SetBins(Int_t n, Double_t *array);
     
     Bool_t      Eval(AliRsnMother * const mother, AliRsnPairDef * const pairDef, AliRsnEvent * const event);
 
   private:
 
     EValueType fType;    // value type
-    Int_t      fNBins;   // number of bins (when applicable)
-    Double_t   fMin;     // lower edge
-    Double_t   fMax;     // upper edge
     Double_t   fValue;   // computed value
+    TArrayD    fArray;   // array of bins (when necessary)
     
     // ROOT dictionary
     ClassDef(AliRsnValue, 1)
index 692e358384b9773dcf57f41a8531dd68815b719b..6a320897c1371b2866a352a1adf2d1905e7f90d3 100644 (file)
@@ -11,7 +11,7 @@
 //                   arguments must have to be the task and the 'dataLabel' argument.
 // 
 Bool_t AddAnalysisTaskRsnTest
-(const char *dataLabel, const char *configMacro = "ConfigTaskRsnTest2010.C")
+(const char *dataLabel, const char *configMacro = "ConfigTaskRsnTest.C")
 {
   // retrieve analysis manager
   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
@@ -23,6 +23,8 @@ Bool_t AddAnalysisTaskRsnTest
 
   // load and execute configuration macro
   gROOT->LoadMacro(configMacro);
+  if (!RsnConfigTask(task, dataLabel)) return kFALSE;
+  /*
   //                                  perf    its     expPID
   if (!RsnConfigTask(task, dataLabel, kTRUE , kTRUE , kFALSE)) return kFALSE;
   if (!RsnConfigTask(task, dataLabel, kTRUE , kFALSE, kFALSE)) return kFALSE;
@@ -30,6 +32,7 @@ Bool_t AddAnalysisTaskRsnTest
   if (!RsnConfigTask(task, dataLabel, kFALSE, kFALSE, kFALSE)) return kFALSE;
   if (!RsnConfigTask(task, dataLabel, kFALSE, kTRUE , kTRUE )) return kFALSE;
   if (!RsnConfigTask(task, dataLabel, kFALSE, kFALSE, kTRUE )) return kFALSE;
+  */
 
   // add the task to manager
   mgr->AddTask(task);
index d11c8599b8191bce64e1c479366876a8ce20a767..407b7cd526bf3a1df9c3c158b15fc7b54e9c5e6b 100644 (file)
@@ -132,14 +132,17 @@ Bool_t RsnConfigTask(AliRsnAnalysisSE* &task, const char *dataLabel)
   pairPMntp ->GetCutManager()->SetCommonDaughterCuts(cutSetDaughterCommon);
 
   // function axes
-  AliRsnValue *axisIM = new AliRsnValue("IM", AliRsnValue::kPairInvMass,        50,  0.9,  1.4);
-  AliRsnValue *axisPt = new AliRsnValue("PT", AliRsnValue::kPairPt,             50,  0.0, 20.0);
+  Double_t ybins[] = {-0.8, -0.7, -0.6, -0.5, 0.5, 0.6, 0.7, 0.8};
+  AliRsnValue *axisIM = new AliRsnValue("IM", AliRsnValue::kPairInvMass, 50,  0.9,  1.4);
+  AliRsnValue *axisPt = new AliRsnValue("PT", AliRsnValue::kPairPt,      0.0, 20.0, 0.1);
+  AliRsnValue *axisY  = new AliRsnValue("Y" , AliRsnValue::kPairY,       sizeof(ybins)/sizeof(ybins[0]), ybins);
 
   // functions for TH1-like output
   AliRsnFunction *fcnPt    = new AliRsnFunction;
   // --> add axes
   fcnPt   ->AddAxis(axisIM);
   fcnPt   ->AddAxis(axisPt);
+  fcnPt   ->AddAxis(axisY);
   
   // add functions to TH1-like output
   pairPMhist->AddFunction(fcnPt);
index 4f616908e7c205fbfda891a862fa62bec7595cde..e8cd58230c55e92acec6bc71e2efcb6e0bcb47be 100644 (file)
@@ -26,7 +26,7 @@
 //
 void runLocal
 (
-  Int_t       nReadFiles  = 1,
+  Int_t       nReadFiles  = 10,
   Int_t       nSkipFiles  = 0,
   const char *addTaskName = "AddAnalysisTaskRsnTest.C",
   const char *inputSource = "/home/pulvir/analysis/resonances/LHC2010-7TeV-phi/rsn-package/sim.txt",
@@ -45,6 +45,7 @@ void runLocal
   //AliLog::SetClassDebugLevel("AliRsnCutPID", AliLog::kDebug+2);
   //AliLog::SetClassDebugLevel("AliRsnPair", AliLog::kDebug+2);
   //AliLog::SetClassDebugLevel("AliRsnPairFunctions", AliLog::kDebug+2);
+  //AliLog::SetClassDebugLevel("AliRsnValue", AliLog::kDebug+4);
 
   // check extension of input to distinguish between XML and TXT
   TString sInput(inputSource);
index 7feab1fb8195f472236914b087e324de4b23ced0..fdf6e900df62efc05b33b6af40edb561abc0f7ec 100644 (file)
@@ -33,8 +33,8 @@ SRCS= RESONANCES/AliRsnDaughter.cxx \
       RESONANCES/AliRsnAnalysisPhi7TeVNoPID.cxx \
       RESONANCES/AliRsnMonitorTrack.cxx \
       RESONANCES/AliRsnAnalysisMonitorTask.cxx \
-#     RESONANCES/AliRsnFitResult.cxx \
-#     RESONANCES/AliRsnAnalysisEffSE.cxx \
+      RESONANCES/AliRsnFitResult.cxx \
+#      RESONANCES/AliRsnAnalysisEffSE.cxx \
 
 HDRS= $(SRCS:.cxx=.h)