]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG3/dielectron/AliDielectronSignalFunc.h
Signal extraction and error calc. updates (Ionut), updated configs (Jens)
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliDielectronSignalFunc.h
index b3da5537c6151defe365c71a7c92bcf9aa9d3110..22b8690542fc609012e521e6f1782c3828f8a3b5 100644 (file)
 //#                                                           #
 //#############################################################
 
+/*
+  Class used for extracting the signal from an invariant mass spectrum.
+  It implements the AliDielectronSignalBase class and it uses user provided
+  functions to fit the unlike-sign spectrum (and the like-sign one).
+  
+  Example usage:
+
+  AliDielectronSignalFunc *signalProcess = new AliDielectronSignalFunc();
+  TObjArray *histoArray = new TObjArray();
+  histoArray->Add(signalPP);            // add the spectrum histograms to the array
+  histoArray->Add(signalPM);            // the order is important !!!
+  histoArray->Add(signalMM);
+  // set the extraction method 
+  // AliDielectronSignalBase::kFitted       -->  fit only the unlike-sign spectrum and extract everything from that
+  // AliDielectronSignalBase::kLikeSign     -->  fit both the unlike- and like-sign spectra
+  // AliDielectronSignalBase::kEventMixing  -->  fit both the unlike- and like-sign spectra from event mixing
+  signalProcess->SetMethod(AliDielectronSignalBase::kLikeSign); 
+  // Initialize the functions to be used and pass them to the signal object
+  // External preparation of the functions can(should) be done as this can be a 5 or more parameter fit
+  TF1* gaus = new TF1("gaus", "gaus", 0., 4.);
+  TF1* expo = new TF1("expo", "[0]*exp([1]*x)", 0., 4.);
+  TF1* combined = new TF1("combined", "gaus + [3]*exp([4]*x)", 0.,4.);
+  combined->SetParameter(1, 3.1);
+  combined->SetParameter(1, 0.1);
+  signalPP->Fit(expo, "SME", "", 2.4, 4.0);
+  signalPM->Fit(gaus, "SME", "", 3.0, 3.15);
+  Double_t pars[5];
+  gaus->GetParameters(&pars[0]);
+  expo->GetParameters(&pars[3]);
+  combined->SetParameters(pars);
+  combined->SetParLimits(1, 3.05, 3.15);
+  combined->SetParLimits(2, 0.03, 0.1);
+  signalProcess->SetFunctions(combined, gaus, expo, 1, 2);
+
+  signalProcess->SetFitRange(2.4,4.0);
+  // Use the integral of the fit function to estimate the signal or not
+  // The background will always be estimated from the fit
+  //  signalProcess->SetUseIntegral(kTRUE);  
+  signalProcess->SetFitOption("SME");
+  // Give the range where the signal is calculated
+  signalProcess->SetIntegralRange(3.0,3.15);
+  signalProcess->SetRebin(2);
+  signalProcess->Process(histoArray);
+  signalProcess->Draw("stat");
+  signalProcess->Print();
+*/
+
+
 #include <TVectorT.h>
 #include <TString.h>
+#include <TH1F.h>
 
 #include "AliDielectronSignalBase.h"
 
@@ -28,52 +77,43 @@ class AliDielectronSignalFunc : public AliDielectronSignalBase {
 public:
   AliDielectronSignalFunc();
   AliDielectronSignalFunc(const char*name, const char* title);
+  AliDielectronSignalFunc(const AliDielectronSignalFunc &c);
+  AliDielectronSignalFunc &operator=(const AliDielectronSignalFunc &c);
 
   virtual ~AliDielectronSignalFunc();
 
-  void Process(TH1 * const hist);
   virtual void Process(TObjArray * const arrhist);
+  void ProcessFit(TObjArray * const arrhist);      // fit the SE +- distribution
+  void ProcessLS(TObjArray * const arrhist);       // substract the fitted SE like-sign background
+  //void ProcessEM(TObjArray * const arrhist);       // substract the fitted SE+ME like-sign background ...not yet implemented
   
-  void SetFunctions(TF1 * const sig, TF1 * const back, TF1 * const combined, Int_t parM=-1, Int_t parMres=-1);
-  void InitParams();
-  void SetFitOption(const char* opt) {fFitOpt=opt;}
+  void SetUseIntegral(Bool_t flag=kTRUE) {fUseIntegral = flag;};
+  void SetFunctions(TF1 * const combined, TF1 * const sig=0, TF1 * const back=0, Int_t parM=1, Int_t parMres=2);
+  void SetFitOption(const char* opt) {
+    fFitOpt=opt; 
+    fFitOpt.ToLower(); 
+    if(!fFitOpt.Contains("s")) fFitOpt += "s";
+  }
   void SetDefaults(Int_t type);
-  void SetFitRange(Double_t min, Double_t max) {fFitMin=min;fFitMax=max;}
-
-  void SetUseIntegral(Bool_t integral=kTRUE) { fUseIntegral=integral; }
-  
-  const char* GetFitOption()          const { return fFitOpt.Data(); }
-  TF1*  GetSignalFunction()     const { return fSignal;        }
-  TF1*  GetBackgroundFunction() const { return fBackground;    }
-  TF1*  GetCombinedFunction()   const { return fSigBack;       }
-  
-  Double_t GetFitMin()      const { return fFitMin; }
-  Double_t GetFitMax()      const { return fFitMax; }
+    
+  TF1*  GetSignalFunction()     { return fFuncSignal;        }
+  TF1*  GetBackgroundFunction() { return fFuncBackground;    }
+  TF1*  GetCombinedFunction()   { return fFuncSigBack;       }
   
   virtual void Draw(const Option_t* option = "");
   
 private:
-  TF1 *fSignal;                // Function for the signal description
-  TF1 *fBackground;            // Function for the background description
-  TF1 *fSigBack;               // Combined function signal plus background
-  TVectorD fVInitParam;        // initial fit parameters
-  TString fFitOpt;             // fit option used
-
-  Bool_t fUseIntegral;         // use integral instead of bin counts
-  
-  Double_t fFitMin;            // fit range min
-  Double_t fFitMax;            // fit range max
-
-  Int_t fParM;                 // Paramter which defines the mass
-  Int_t fParMres;              // Paramter which defines the resolution of the mass
 
-  TH1 *fSignalHist;            // Current signal histogram
+  TF1 *fFuncSignal;                // Function for the signal description
+  TF1 *fFuncBackground;            // Function for the background description
+  TF1 *fFuncSigBack;               // Combined function signal plus background
+  Int_t fParMass;                  // the index of the parameter corresponding to the resonance mass
+  Int_t fParMassWidth;             // the index of the parameter corresponding to the resonance mass width
   
-  AliDielectronSignalFunc(const AliDielectronSignalFunc &c);
-  AliDielectronSignalFunc &operator=(const AliDielectronSignalFunc &c);
+  TString fFitOpt;             // fit option used
+  Bool_t fUseIntegral;         // use the integral of the fitted functions to extract signal and background
 
-  ClassDef(AliDielectronSignalFunc,1)         // Dielectron SignalFunc
+  ClassDef(AliDielectronSignalFunc,2)         // Dielectron SignalFunc
 };
 
-
 #endif