]> git.uio.no Git - u/mrichter/AliRoot.git/blame - CORRFW/AliCFDataGrid.cxx
Coding convention violations (RC3 in AliTOFRawStream.h): suppressed
[u/mrichter/AliRoot.git] / CORRFW / AliCFDataGrid.cxx
CommitLineData
563113d0 1/* $Id$ */
1e9dad92 2/**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
563113d0 16//--------------------------------------------------------------------//
17// //
18// AliCFDataGrid Class //
19// Class to handle observed data and correct them //
20// //
21// -- Author : S.Arcelli //
22// //
23// //
24// //
25//--------------------------------------------------------------------//
26//
27//
9f6be3a2 28#include "TMath.h"
29#include "AliLog.h"
563113d0 30#include "AliCFDataGrid.h"
31
32//____________________________________________________________________
33ClassImp(AliCFDataGrid)
34
35//____________________________________________________________________
36AliCFDataGrid::AliCFDataGrid() :
25488e18 37 AliCFGridSparse(),
563113d0 38 fSelData(-1),
39 fContainer(0x0)
40{
41 //
42 // default constructor
43 //
44 SumW2(); //errors saved
45}
46
47//____________________________________________________________________
48AliCFDataGrid::AliCFDataGrid(const Char_t* name,const Char_t* title) :
25488e18 49 AliCFGridSparse(name,title),
563113d0 50 fSelData(-1),
51 fContainer(0x0)
52{
53 //
54 // default constructor
55 //
56 SumW2(); //errors saved
57}
58
59//____________________________________________________________________
1e9dad92 60AliCFDataGrid::AliCFDataGrid(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn, const Double_t *binLimitsIn) :
25488e18 61 AliCFGridSparse(name,title,nVarIn,nBinIn,binLimitsIn),
563113d0 62 fSelData(-1),
63 fContainer(0x0)
64{
65 //
66 // main constructor
67 //
68 SumW2();// errors saved
69}
70//____________________________________________________________________
71AliCFDataGrid::AliCFDataGrid(const Char_t* name, const Char_t* title, const AliCFContainer &c) :
25488e18 72 AliCFGridSparse(name,title,c.GetNVar(),c.GetNBins(),c.GetBinLimits()),
563113d0 73 fSelData(-1),
74 fContainer(0x0)
75{
76 //
77 // main constructor
78 //
79 SumW2();
80 //assign the container;
81 fContainer=&c;
82
83}
84//____________________________________________________________________
25488e18 85AliCFDataGrid::AliCFDataGrid(const AliCFDataGrid& data) : AliCFGridSparse(),
563113d0 86 fSelData(-1),
87 fContainer(0x0)
88{
89 //
90 // copy constructor
91 //
92 ((AliCFDataGrid &)data).Copy(*this);
93}
94
95//____________________________________________________________________
96AliCFDataGrid::~AliCFDataGrid()
97{
98 //
99 // destructor
100 //
101}
102//____________________________________________________________________
103AliCFDataGrid &AliCFDataGrid::operator=(const AliCFDataGrid &c)
104{
105 //
106 // assigment operator
107 //
108 if (this != &c)
109 ((AliCFDataGrid &) c).Copy(*this);
110 return *this;
111}
112//____________________________________________________________________
113
114void AliCFDataGrid::SetMeasured(Int_t istep)
115{
116 //
117 // Deposit observed data over the grid
118 //
119 Int_t nEmptyBins=0;
120 fSelData=istep;
121 //Initially, set the corrected data to the measured data
122 for(Int_t i=0;i<fNDim;i++){
123 Float_t meas=fContainer->GetGrid(fSelData)->GetElement(i);
124 Float_t dmeas=fContainer->GetGrid(fSelData)->GetElementError(i);
125 SetElement(i,meas);
126 SetElementError(i,dmeas);
127 if(meas <=0)nEmptyBins++;
128 }
25488e18 129
130 //fNentriesTot=fNDim;
131 GetGrid()->SetEntries(GetData()->GetEntries());
132 //
133
563113d0 134 AliInfo(Form("retrieving measured data from Container %s at selection step %i: %i empty bins were found.",fContainer->GetName(),fSelData,nEmptyBins));
135}
136//____________________________________________________________________
137void AliCFDataGrid::ApplyEffCorrection(const AliCFEffGrid &c)
138{
139
140 //
141 // Apply the efficiency correction
142 //
143 if(c.GetNVar()!=fNVar){
144 AliInfo("Different number of variables, cannot apply correction");
145 return;
146 }
147 if(c.GetNDim()!=fNDim){
148 AliInfo("Different number of dimension, cannot apply correction");
149 return;
150 }
151
152 //Get the data
153 Int_t ncorr=0;
154 Int_t nnocorr=0;
155 Float_t eff,deff,unc,dunc,corr,dcorr;
156 //Apply the correction
157 for(Int_t i=0;i<fNDim;i++){
158 eff =c.GetElement(i);
1e9dad92 159 deff =c.GetElementError(i);
563113d0 160 unc =GetElement(i);
1e9dad92 161 dunc =GetElementError(i);
25488e18 162
563113d0 163 if(eff>0 && unc>0){
164 ncorr++;
165 corr=unc/eff;
166 dcorr=TMath::Sqrt(dunc*dunc/unc/unc+deff*deff/eff/eff)*corr;
167 SetElement(i,corr);
1e9dad92 168 SetElementError(i,dcorr);
563113d0 169 } else{
170 if(unc>0)nnocorr++;
171 SetElement(i,0);
172 SetElementError(i,0);
173 }
174 }
175 AliInfo(Form("correction applied for %i cells in correction matrix of Container %s, having entries in Data Container %s.",ncorr,c.GetName(),GetName()));
176 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()));
177}
178//____________________________________________________________________
179void AliCFDataGrid::ApplyBGCorrection(const AliCFDataGrid &c)
180{
181
182 //
183 // Apply correction for background
184 //
185 if(c.GetNVar()!=fNVar){
186 AliInfo("Different number of variables, cannot apply correction");
187 return;
188 }
189 if(c.GetNDim()!=fNDim){
190 AliInfo("Different number of dimension, cannot apply correction");
191 return;
192 }
193
194 //Get the data
195 Float_t bkg,dbkg,unc,dunc,corr,dcorr;
196
197 //Apply the correction
198
199 for(Int_t i=0;i<fNDim;i++){
200 bkg =c.GetElement(i);
1e9dad92 201 dbkg =c.GetElementError(i);
563113d0 202 unc =GetElement(i);
1e9dad92 203 dunc =GetElementError(i);
563113d0 204 corr=unc-bkg;
1e9dad92 205 dcorr=TMath::Sqrt(unc+bkg); //stat err only...
563113d0 206 SetElement(i,corr);
1e9dad92 207 SetElementError(i,dcorr);
563113d0 208
209 }
210}
563113d0 211//____________________________________________________________________
212void AliCFDataGrid::Copy(TObject& eff) const
213{
214 // copy function
215
216 Copy(eff);
217 AliCFDataGrid& target = (AliCFDataGrid &) eff;
218 target.fContainer=fContainer;
219 target.fSelData=fSelData;
220
221}