]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGDQ/dielectron/AliDielectronSignalBase.cxx
New macros for the kaon train
[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   fScaleMin2(0.),
58   fScaleMax2(0.),
59   fScaleFactor(1.),
60   fMixingCorr(kFALSE),
61   fProcessed(kFALSE)
62 {
63   //
64   // Default Constructor
65   //
66 }
67
68 //______________________________________________
69 AliDielectronSignalBase::AliDielectronSignalBase(const char* name, const char* title) :
70   TNamed(name, title),
71   fHistSignal(0),
72   fHistBackground(0),
73   fHistDataPM(0),
74   fHistDataPP(0),
75   fHistDataMM(0),
76   fHistDataME(0),
77   fHistRfactor(0),
78   fValues(6),
79   fErrors(6),
80   fIntMin(0),
81   fIntMax(0),
82   fFitMin(0),
83   fFitMax(0),
84   fRebin(1),
85   fMethod(kLikeSign),
86   fScaleMin(0.),
87   fScaleMax(0.),
88   fScaleMin2(0.),
89   fScaleMax2(0.),
90   fScaleFactor(1.),
91   fMixingCorr(kFALSE),
92   fProcessed(kFALSE)
93 {
94   //
95   // Named Constructor
96   //
97 }
98
99 //______________________________________________
100 AliDielectronSignalBase::~AliDielectronSignalBase()
101 {
102   //
103   // Default Destructor
104   //
105   if(fHistSignal) delete fHistSignal;
106   if(fHistBackground) delete fHistBackground;
107   if (fHistDataPP) delete fHistDataPP;
108   if (fHistDataPM) delete fHistDataPM;
109   if (fHistDataMM) delete fHistDataMM;
110   if (fHistDataME) delete fHistDataME;
111   if (fHistRfactor)delete fHistRfactor;  
112 }
113
114 //______________________________________________
115 TPaveText* AliDielectronSignalBase::DrawStats(Double_t x1/*=0.*/, Double_t y1/*=0.*/, Double_t x2/*=0.*/, Double_t y2/*=0.*/)
116 {
117   //
118   // Draw extracted values in a TPaveText
119   // with the corners x1,y2,x2,y2
120   //
121   if (TMath::Abs(x1)<1e-20&&TMath::Abs(x2)<1e-20){
122     x1=.6;
123     x2=.9;
124     y1=.7;
125     y2=.9;
126   }
127   TPaveText *t=new TPaveText(x1,y1,x2,y2,"brNDC");
128   t->SetFillColor(kWhite);
129   t->SetBorderSize(1);
130   t->SetTextAlign(12);
131   t->AddText(Form("Range  : %.2f - %.2f GeV/c^{2}", fIntMin, fIntMax));
132   t->AddText(Form("Signal : %.1f #pm %.1f", fValues(0), fErrors(0)));
133   t->AddText(Form("Backgnd: %.1f #pm %.1f", fValues(1), fErrors(1)));
134   t->AddText(Form("Signif.: %.2f #pm %.2f", fValues(2), fErrors(2)));
135   t->AddText(Form("S/B    : %.2f #pm %.2f", fValues(3), fErrors(3)));
136   if(fValues(4)>0) {
137     t->AddText(Form("Mass: %.2f #pm %.2f GeV/c^{2}", fValues(4), fErrors(4)));
138     t->AddText(Form("Mass res.: %.1f #pm %.1f MeV/c^{2}", 1000*fValues(5), 1000*fErrors(5)));
139   }
140   t->Draw();
141
142   return t;
143 }
144
145 //______________________________________________
146 void AliDielectronSignalBase::Print(Option_t */*option*/) const
147 {
148   //
149   // Print the statistics
150   //
151   printf("Signal : %.5g #pm %.5g\n",fValues(0), fErrors(0));
152   printf("Backgnd: %.5g #pm %.5g\n",fValues(1), fErrors(1));
153   printf("Signif.: %.5g #pm %.5g\n",fValues(2), fErrors(2));
154   printf("SoB    : %.5g #pm %.5g\n",fValues(3), fErrors(3));
155   if(fValues(4)>0){
156     printf("Mass: %.5g #pm %.5g\n", fValues(4), fErrors(4));
157     printf("Mass res.: %.5g #pm %.5g\n", fValues(5), fErrors(5));
158   }
159 }
160
161 //______________________________________________
162 Double_t AliDielectronSignalBase::ScaleHistograms(TH1* histRaw, TH1* histBackground, Double_t intMin, Double_t intMax)
163 {
164   //
165   // scale histBackground to match the integral of histRaw in the interval intMin, intMax
166   //
167   printf("scale %f %f \n",intMin,intMax);
168   //protect using over and underflow bins in normalisation calculation
169   if (intMin<histRaw->GetXaxis()->GetXmin()) intMin=histRaw->GetXaxis()->GetXmin();
170   if (intMin<histBackground->GetXaxis()->GetXmin()) intMin=histBackground->GetXaxis()->GetXmin();
171   
172   if (intMax>histRaw->GetXaxis()->GetXmax())
173     intMax=histRaw->GetXaxis()->GetXmax()-histRaw->GetBinWidth(histRaw->GetNbinsX())/2.;
174   if (intMax>histBackground->GetXaxis()->GetXmax())
175     intMax=histBackground->GetXaxis()->GetXmax()-histBackground->GetBinWidth(histBackground->GetNbinsX())/2.;
176   
177   Double_t intRaw  = histRaw->Integral(histRaw->FindBin(intMin),histRaw->FindBin(intMax));
178   Double_t intBack = histBackground->Integral(histBackground->FindBin(intMin),histBackground->FindBin(intMax));
179   Double_t scaleFactor=intBack>0?intRaw/intBack:0.;
180   if (intBack>0){
181     histBackground->Sumw2();
182     histBackground->Scale(scaleFactor);
183   }
184
185   return scaleFactor;
186 }
187 //______________________________________________
188 Double_t AliDielectronSignalBase::ScaleHistograms(TH1* histRaw, TH1* histBackground, Double_t intMin, Double_t intMax, Double_t intMin2, Double_t intMax2)
189 {
190   //
191   // scale histBackground to match the integral of histRaw in the interval intMin, intMax and intMin2, intMax2
192   //
193   printf("scale %f %f %f %f\n",intMin,intMax, intMin2, intMax2);
194   if(intMin2==intMax2) return (ScaleHistograms(histRaw, histBackground, intMin, intMax));
195
196   //protect using over and underflow bins in normalisation calculation
197   if (intMin<histRaw->GetXaxis()->GetXmin()) intMin=histRaw->GetXaxis()->GetXmin();
198   if (intMin<histBackground->GetXaxis()->GetXmin()) intMin=histBackground->GetXaxis()->GetXmin();
199   
200   if (intMax2>histRaw->GetXaxis()->GetXmax())
201     intMax2=histRaw->GetXaxis()->GetXmax()-histRaw->GetBinWidth(histRaw->GetNbinsX())/2.;
202   if (intMax2>histBackground->GetXaxis()->GetXmax())
203     intMax2=histBackground->GetXaxis()->GetXmax()-histBackground->GetBinWidth(histBackground->GetNbinsX())/2.;
204   
205   Double_t intRaw  = histRaw->Integral(histRaw->FindBin(intMin),histRaw->FindBin(intMax));
206   Double_t intBack = histBackground->Integral(histBackground->FindBin(intMin),histBackground->FindBin(intMax));
207   intRaw  += histRaw->Integral(histRaw->FindBin(intMin2),histRaw->FindBin(intMax2));
208   intBack += histBackground->Integral(histBackground->FindBin(intMin2),histBackground->FindBin(intMax2));
209
210   Double_t scaleFactor=intBack>0?intRaw/intBack:0.;
211   if (intBack>0){
212     histBackground->Sumw2();
213     histBackground->Scale(scaleFactor);
214   }
215
216   return scaleFactor;
217 }