]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGDQ/dielectron/AliDielectronSignalBase.cxx
012f2c0a26af665fc54d9908d58a37ef4d471c4f
[u/mrichter/AliRoot.git] / PWGDQ / dielectron / AliDielectronSignalBase.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 SignalBase                                  //
18 //                                                                       //
19 //                                                                       //
20 /*
21 Base class for signal extraction from a histogram or an array of histograms
22 The histogram is assumed to be an inv. mass spectrum,
23 the array of histograms is assumed to be an array with inv. mass histograms
24 resulting from single and mixed events, as defined in AliDielectron.cxx
25
26 */
27 //                                                                       //
28 ///////////////////////////////////////////////////////////////////////////
29
30
31 #include <TVectorT.h>
32 #include <TPaveText.h>
33 #include <TH1F.h>
34 #include "AliDielectronSignalBase.h"
35
36 ClassImp(AliDielectronSignalBase)
37
38 AliDielectronSignalBase::AliDielectronSignalBase() :
39   TNamed(),
40   fHistSignal(0),
41   fHistBackground(0),
42   fHistDataPM(0),
43   fHistDataPP(0),
44   fHistDataMM(0),
45   fHistDataME(0),
46   fHistRfactor(0),
47   fValues(6),
48   fErrors(6),
49   fIntMin(0),
50   fIntMax(0),
51   fFitMin(0),
52   fFitMax(0),
53   fRebin(1),
54   fMethod(kLikeSign),
55   fScaleMin(0.),
56   fScaleMax(0.),
57   fScaleFactor(1.),
58   fMixingCorr(kFALSE),
59   fProcessed(kFALSE)
60 {
61   //
62   // Default Constructor
63   //
64 }
65
66 //______________________________________________
67 AliDielectronSignalBase::AliDielectronSignalBase(const char* name, const char* title) :
68   TNamed(name, title),
69   fHistSignal(0),
70   fHistBackground(0),
71   fHistDataPM(0),
72   fHistDataPP(0),
73   fHistDataMM(0),
74   fHistDataME(0),
75   fHistRfactor(0),
76   fValues(6),
77   fErrors(6),
78   fIntMin(0),
79   fIntMax(0),
80   fFitMin(0),
81   fFitMax(0),
82   fRebin(1),
83   fMethod(kLikeSign),
84   fScaleMin(0.),
85   fScaleMax(0.),
86   fScaleFactor(1.),
87   fMixingCorr(kFALSE),
88   fProcessed(kFALSE)
89 {
90   //
91   // Named Constructor
92   //
93 }
94
95 //______________________________________________
96 AliDielectronSignalBase::~AliDielectronSignalBase()
97 {
98   //
99   // Default Destructor
100   //
101   if(fHistSignal) delete fHistSignal;
102   if(fHistBackground) delete fHistBackground;
103   if (fHistDataPP) delete fHistDataPP;
104   if (fHistDataPM) delete fHistDataPM;
105   if (fHistDataMM) delete fHistDataMM;
106   if (fHistDataME) delete fHistDataME;
107   if (fHistRfactor)delete fHistRfactor;  
108 }
109
110 //______________________________________________
111 TPaveText* AliDielectronSignalBase::DrawStats(Double_t x1/*=0.*/, Double_t y1/*=0.*/, Double_t x2/*=0.*/, Double_t y2/*=0.*/)
112 {
113   //
114   // Draw extracted values in a TPaveText
115   // with the corners x1,y2,x2,y2
116   //
117   if (TMath::Abs(x1)<1e-20&&TMath::Abs(x2)<1e-20){
118     x1=.6;
119     x2=.9;
120     y1=.7;
121     y2=.9;
122   }
123   TPaveText *t=new TPaveText(x1,y1,x2,y2,"brNDC");
124   t->SetFillColor(kWhite);
125   t->SetBorderSize(1);
126   t->SetTextAlign(12);
127   t->AddText(Form("Range  : %.2f - %.2f GeV/c^{2}", fIntMin, fIntMax));
128   t->AddText(Form("Signal : %.1f #pm %.1f", fValues(0), fErrors(0)));
129   t->AddText(Form("Backgnd: %.1f #pm %.1f", fValues(1), fErrors(1)));
130   t->AddText(Form("Signif.: %.2f #pm %.2f", fValues(2), fErrors(2)));
131   t->AddText(Form("S/B    : %.2f #pm %.2f", fValues(3), fErrors(3)));
132   if(fValues(4)>0) {
133     t->AddText(Form("Mass: %.2f #pm %.2f GeV/c^{2}", fValues(4), fErrors(4)));
134     t->AddText(Form("Mass res.: %.1f #pm %.1f MeV/c^{2}", 1000*fValues(5), 1000*fErrors(5)));
135   }
136   t->Draw();
137
138   return t;
139 }
140
141 //______________________________________________
142 void AliDielectronSignalBase::Print(Option_t */*option*/) const
143 {
144   //
145   // Print the statistics
146   //
147   printf("Signal : %.5g #pm %.5g\n",fValues(0), fErrors(0));
148   printf("Backgnd: %.5g #pm %.5g\n",fValues(1), fErrors(1));
149   printf("Signif.: %.5g #pm %.5g\n",fValues(2), fErrors(2));
150   printf("SoB    : %.5g #pm %.5g\n",fValues(3), fErrors(3));
151   if(fValues(4)>0){
152     printf("Mass: %.5g #pm %.5g\n", fValues(4), fErrors(4));
153     printf("Mass res.: %.5g #pm %.5g\n", fValues(5), fErrors(5));
154   }
155 }
156
157 //______________________________________________
158 Double_t AliDielectronSignalBase::ScaleHistograms(TH1* histRaw, TH1* histBackground, Double_t intMin, Double_t intMax)
159 {
160   //
161   // scale histBackground to match the integral of histRaw in the interval intMin, intMax
162   //
163
164   //protect using over and underflow bins in normalisation calculation
165   if (intMin<histRaw->GetXaxis()->GetXmin()) intMin=histRaw->GetXaxis()->GetXmin();
166   if (intMin<histBackground->GetXaxis()->GetXmin()) intMin=histBackground->GetXaxis()->GetXmin();
167   
168   if (intMax>histRaw->GetXaxis()->GetXmax())
169     intMax=histRaw->GetXaxis()->GetXmax()-histRaw->GetBinWidth(histRaw->GetNbinsX())/2.;
170   if (intMax>histBackground->GetXaxis()->GetXmax())
171     intMax=histBackground->GetXaxis()->GetXmax()-histBackground->GetBinWidth(histBackground->GetNbinsX())/2.;
172   
173   Double_t intRaw  = histRaw->Integral(histRaw->FindBin(intMin),histRaw->FindBin(intMax));
174   Double_t intBack = histBackground->Integral(histBackground->FindBin(intMin),histBackground->FindBin(intMax));
175   Double_t scaleFactor=intBack>0?intRaw/intBack:0.;
176   if (intBack>0){
177     histBackground->Sumw2();
178     histBackground->Scale(scaleFactor);
179   }
180
181   return scaleFactor;
182 }