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