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