Re-structured digitizer
[u/mrichter/AliRoot.git] / CORRFW / AliCFDataGrid.cxx
CommitLineData
563113d0 1/* $Id$ */
2
3//--------------------------------------------------------------------//
4// //
5// AliCFDataGrid Class //
6// Class to handle observed data and correct them //
7// //
8// -- Author : S.Arcelli //
9// //
10// //
11// //
12//--------------------------------------------------------------------//
13//
14//
15#include <TROOT.h>
16#include <TMath.h>
17#include <TFile.h>
18#include <AliLog.h>
19#include "AliCFDataGrid.h"
20
21//____________________________________________________________________
22ClassImp(AliCFDataGrid)
23
24//____________________________________________________________________
25AliCFDataGrid::AliCFDataGrid() :
26 AliCFGrid(),
27 fSelData(-1),
28 fContainer(0x0)
29{
30 //
31 // default constructor
32 //
33 SumW2(); //errors saved
34}
35
36//____________________________________________________________________
37AliCFDataGrid::AliCFDataGrid(const Char_t* name,const Char_t* title) :
38 AliCFGrid(name,title),
39 fSelData(-1),
40 fContainer(0x0)
41{
42 //
43 // default constructor
44 //
45 SumW2(); //errors saved
46}
47
48//____________________________________________________________________
49AliCFDataGrid::AliCFDataGrid(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn, const Float_t *binLimitsIn) :
50 AliCFGrid(name,title,nVarIn,nBinIn,binLimitsIn),
51 fSelData(-1),
52 fContainer(0x0)
53{
54 //
55 // main constructor
56 //
57 SumW2();// errors saved
58}
59//____________________________________________________________________
60AliCFDataGrid::AliCFDataGrid(const Char_t* name, const Char_t* title, const AliCFContainer &c) :
61 AliCFGrid(name,title,c.GetNVar(),c.GetNBins(),c.GetBinLimits()),
62 fSelData(-1),
63 fContainer(0x0)
64{
65 //
66 // main constructor
67 //
68 SumW2();
69 //assign the container;
70 fContainer=&c;
71
72}
73//____________________________________________________________________
74AliCFDataGrid::AliCFDataGrid(const AliCFDataGrid& data) : AliCFGrid(),
75 fSelData(-1),
76 fContainer(0x0)
77{
78 //
79 // copy constructor
80 //
81 ((AliCFDataGrid &)data).Copy(*this);
82}
83
84//____________________________________________________________________
85AliCFDataGrid::~AliCFDataGrid()
86{
87 //
88 // destructor
89 //
90}
91//____________________________________________________________________
92AliCFDataGrid &AliCFDataGrid::operator=(const AliCFDataGrid &c)
93{
94 //
95 // assigment operator
96 //
97 if (this != &c)
98 ((AliCFDataGrid &) c).Copy(*this);
99 return *this;
100}
101//____________________________________________________________________
102
103void AliCFDataGrid::SetMeasured(Int_t istep)
104{
105 //
106 // Deposit observed data over the grid
107 //
108 Int_t nEmptyBins=0;
109 fSelData=istep;
110 //Initially, set the corrected data to the measured data
111 for(Int_t i=0;i<fNDim;i++){
112 Float_t meas=fContainer->GetGrid(fSelData)->GetElement(i);
113 Float_t dmeas=fContainer->GetGrid(fSelData)->GetElementError(i);
114 SetElement(i,meas);
115 SetElementError(i,dmeas);
116 if(meas <=0)nEmptyBins++;
117 }
118 fNentriesTot=fNDim;
119 AliInfo(Form("retrieving measured data from Container %s at selection step %i: %i empty bins were found.",fContainer->GetName(),fSelData,nEmptyBins));
120}
121//____________________________________________________________________
122void AliCFDataGrid::ApplyEffCorrection(const AliCFEffGrid &c)
123{
124
125 //
126 // Apply the efficiency correction
127 //
128 if(c.GetNVar()!=fNVar){
129 AliInfo("Different number of variables, cannot apply correction");
130 return;
131 }
132 if(c.GetNDim()!=fNDim){
133 AliInfo("Different number of dimension, cannot apply correction");
134 return;
135 }
136
137 //Get the data
138 Int_t ncorr=0;
139 Int_t nnocorr=0;
140 Float_t eff,deff,unc,dunc,corr,dcorr;
141 //Apply the correction
142 for(Int_t i=0;i<fNDim;i++){
143 eff =c.GetElement(i);
144 deff =TMath::Sqrt(c.GetElementError(i));
145 unc =GetElement(i);
146 dunc =TMath::Sqrt(GetElementError(i));
147 if(eff>0 && unc>0){
148 ncorr++;
149 corr=unc/eff;
150 dcorr=TMath::Sqrt(dunc*dunc/unc/unc+deff*deff/eff/eff)*corr;
151 SetElement(i,corr);
152 SetElementError(i,dcorr*dcorr);
153
154 } else{
155 if(unc>0)nnocorr++;
156 SetElement(i,0);
157 SetElementError(i,0);
158 }
159 }
160 AliInfo(Form("correction applied for %i cells in correction matrix of Container %s, having entries in Data Container %s.",ncorr,c.GetName(),GetName()));
161 AliInfo(Form("No correction applied for %i empty bins in correction matrix of Container %s, having entries in Data Container %s. Their content in the corrected data container was set to zero",nnocorr,c.GetName(),GetName()));
162}
163//____________________________________________________________________
164void AliCFDataGrid::ApplyBGCorrection(const AliCFDataGrid &c)
165{
166
167 //
168 // Apply correction for background
169 //
170 if(c.GetNVar()!=fNVar){
171 AliInfo("Different number of variables, cannot apply correction");
172 return;
173 }
174 if(c.GetNDim()!=fNDim){
175 AliInfo("Different number of dimension, cannot apply correction");
176 return;
177 }
178
179 //Get the data
180 Float_t bkg,dbkg,unc,dunc,corr,dcorr;
181
182 //Apply the correction
183
184 for(Int_t i=0;i<fNDim;i++){
185 bkg =c.GetElement(i);
186 dbkg =TMath::Sqrt(c.GetElementError(i));
187 unc =GetElement(i);
188 dunc =TMath::Sqrt(GetElementError(i));
189 corr=unc-bkg;
190 dcorr=TMath::Sqrt(unc+bkg); //stats only, check this
191 SetElement(i,corr);
192 SetElementError(i,dcorr*dcorr);
193
194 }
195}
196
197//____________________________________________________________________
198void AliCFDataGrid::Copy(TObject& eff) const
199{
200 // copy function
201
202 Copy(eff);
203 AliCFDataGrid& target = (AliCFDataGrid &) eff;
204 target.fContainer=fContainer;
205 target.fSelData=fSelData;
206
207}