More code clean up.
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDCorrections.cxx
CommitLineData
7e4038b5 1#include "AliFMDCorrections.h"
2#include <AliESDFMD.h>
3#include <TAxis.h>
4#include <TList.h>
5#include <TMath.h>
0bd4b00f 6#include "AliForwardCorrectionManager.h"
7// #include "AliFMDAnaParameters.h"
7e4038b5 8#include "AliLog.h"
9#include <TH2D.h>
0bd4b00f 10#include <TROOT.h>
11#include <iostream>
12#include <iomanip>
7e4038b5 13
14ClassImp(AliFMDCorrections)
15#if 0
16; // For Emacs
17#endif
18
19//____________________________________________________________________
20AliFMDCorrections::AliFMDCorrections()
21 : TNamed(),
22 fRingHistos(),
ea3e5d95 23 fDebug(0)
7e4038b5 24{}
25
26//____________________________________________________________________
27AliFMDCorrections::AliFMDCorrections(const char* title)
28 : TNamed("fmdCorrections", title),
29 fRingHistos(),
ea3e5d95 30 fDebug(0)
7e4038b5 31{
32 fRingHistos.SetName(GetName());
33 fRingHistos.Add(new RingHistos(1, 'I'));
34 fRingHistos.Add(new RingHistos(2, 'I'));
35 fRingHistos.Add(new RingHistos(2, 'O'));
36 fRingHistos.Add(new RingHistos(3, 'I'));
37 fRingHistos.Add(new RingHistos(3, 'O'));
38}
39
40//____________________________________________________________________
41AliFMDCorrections::AliFMDCorrections(const AliFMDCorrections& o)
42 : TNamed(o),
43 fRingHistos(),
ea3e5d95 44 fDebug(o.fDebug)
7e4038b5 45{
46 TIter next(&o.fRingHistos);
47 TObject* obj = 0;
48 while ((obj = next())) fRingHistos.Add(obj);
49}
50
51//____________________________________________________________________
52AliFMDCorrections::~AliFMDCorrections()
53{
54 fRingHistos.Delete();
55}
56
57//____________________________________________________________________
58AliFMDCorrections&
59AliFMDCorrections::operator=(const AliFMDCorrections& o)
60{
ea3e5d95 61 TNamed::operator=(o);
7e4038b5 62
ea3e5d95 63 fDebug = o.fDebug;
7e4038b5 64 fRingHistos.Delete();
65 TIter next(&o.fRingHistos);
66 TObject* obj = 0;
67 while ((obj = next())) fRingHistos.Add(obj);
68
69 return *this;
70}
71
72//____________________________________________________________________
73AliFMDCorrections::RingHistos*
74AliFMDCorrections::GetRingHistos(UShort_t d, Char_t r) const
75{
76 Int_t idx = -1;
77 switch (d) {
78 case 1: idx = 0; break;
79 case 2: idx = 1 + (r == 'I' || r == 'i' ? 0 : 1); break;
80 case 3: idx = 3 + (r == 'I' || r == 'i' ? 0 : 1); break;
81 }
82 if (idx < 0 || idx >= fRingHistos.GetEntries()) return 0;
83
84 return static_cast<RingHistos*>(fRingHistos.At(idx));
85}
86
87//____________________________________________________________________
88Bool_t
89AliFMDCorrections::Correct(AliForwardUtil::Histos& hists,
0bd4b00f 90 UShort_t vtxbin)
7e4038b5 91{
0bd4b00f 92 // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
93 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
7e4038b5 94
0bd4b00f 95 UShort_t uvb = vtxbin;
7e4038b5 96 for (UShort_t d=1; d<=3; d++) {
97 UShort_t nr = (d == 1 ? 1 : 2);
98 for (UShort_t q=0; q<nr; q++) {
99 Char_t r = (q == 0 ? 'I' : 'O');
100 TH2D* h = hists.Get(d,r);
101 RingHistos* rh= GetRingHistos(d,r);
0bd4b00f 102 //TH2F* bg= pars->GetBackgroundCorrection(d, r, vtxbin);
103 //TH2F* ef= pars->GetEventSelectionEfficiency("INEL",vtxbin,r);
104 TH2D* bg = fcm.GetSecondaryMap()->GetCorrection(d,r,uvb);
105 TH2D* ef = fcm.GetVertexBias()->GetCorrection(r, uvb);
7e4038b5 106 if (!bg) {
107 AliWarning(Form("No secondary correction for FMDM%d%c in vertex bin %d",
0bd4b00f 108 d, r, uvb));
7e4038b5 109 continue;
110 }
111 if (!ef) {
0bd4b00f 112 AliWarning(Form("No event vertex bias correction in vertex bin %d",
113 uvb));
7e4038b5 114 continue;
115 }
116
117 // Divide by primary/total ratio
118 h->Divide(bg);
119
120 // Divide by the event selection efficiency
121 h->Divide(ef);
122
0bd4b00f 123
124 // if(!pars->SharingEffPresent()) {
125 // AliWarning("No sharing efficiencies");
126 // continue;
127 // }
128 // TH1F* sf = pars->GetSharingEfficiencyTrVtx(d,r,vtxbin);
129 if (!fcm.GetMergingEfficiency()) {
130 AliWarning("No merging efficiencies");
131 continue;
132 }
133 TH1D* sf = fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb);
134 if (!fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb)) {
135 AliWarning(Form("No merging efficiency for FMD%d%c at vertex bin %d",
136 d, r, uvb));
7e4038b5 137 continue;
138 }
139
7e4038b5 140
141 for (Int_t ieta = 1; ieta <= h->GetNbinsX(); ieta++) {
142 Float_t c = sf->GetBinContent(ieta);
143 Float_t ec = sf->GetBinError(ieta);
144
145 if (c == 0) continue;
146
147 for (Int_t iphi = 1; iphi <= h->GetNbinsY(); iphi++) {
148 Double_t m = h->GetBinContent(ieta, iphi) / c;
149 Double_t em = h->GetBinError(ieta, iphi);
150
151 Double_t e = TMath::Sqrt(em * em + (m * ec) * (m * ec));
152
153 h->SetBinContent(ieta,iphi,m);
154 h->SetBinError(ieta,iphi,e);
155 }
156 }
157
158 rh->fDensity->Add(h);
159 }
160 }
161
162 return kTRUE;
163}
164
165//____________________________________________________________________
166void
9d99b0dd 167AliFMDCorrections::ScaleHistograms(TList* dir, Int_t nEvents)
7e4038b5 168{
169 if (nEvents <= 0) return;
9d99b0dd 170 TList* d = static_cast<TList*>(dir->FindObject(GetName()));
171 if (!d) return;
7e4038b5 172
173 TIter next(&fRingHistos);
174 RingHistos* o = 0;
9d99b0dd 175 while ((o = static_cast<RingHistos*>(next())))
176 o->ScaleHistograms(d, nEvents);
7e4038b5 177}
7e4038b5 178//____________________________________________________________________
179void
9d99b0dd 180AliFMDCorrections::DefineOutput(TList* dir)
7e4038b5 181{
182 TList* d = new TList;
183 d->SetName(GetName());
184 dir->Add(d);
185 TIter next(&fRingHistos);
186 RingHistos* o = 0;
187 while ((o = static_cast<RingHistos*>(next()))) {
188 o->Output(d);
189 }
190}
191
0bd4b00f 192//____________________________________________________________________
193void
194AliFMDCorrections::Print(Option_t* /* option */) const
195{
196 char ind[gROOT->GetDirLevel()+1];
197 for (Int_t i = 0; i < gROOT->GetDirLevel(); i++) ind[i] = ' ';
198 ind[gROOT->GetDirLevel()] = '\0';
199 std::cout << ind << "AliFMDCorrections: " << GetName() << std::endl;
200}
201
7e4038b5 202//====================================================================
203AliFMDCorrections::RingHistos::RingHistos()
9d99b0dd 204 : AliForwardUtil::RingHistos(),
7e4038b5 205 fDensity(0)
206{}
207
208//____________________________________________________________________
209AliFMDCorrections::RingHistos::RingHistos(UShort_t d, Char_t r)
9d99b0dd 210 : AliForwardUtil::RingHistos(d,r),
7e4038b5 211 fDensity(0)
212{
213 fDensity = new TH2D(Form("FMD%d%c_Primary_Density", d, r),
214 Form("in FMD%d%c", d, r),
215 200, -4, 6, (r == 'I' || r == 'i' ? 20 : 40),
216 0, 2*TMath::Pi());
217 fDensity->SetDirectory(0);
218 fDensity->SetXTitle("#eta");
219 fDensity->SetYTitle("#phi [radians]");
220 fDensity->SetZTitle("Primary N_{ch} density");
221}
222//____________________________________________________________________
223AliFMDCorrections::RingHistos::RingHistos(const RingHistos& o)
9d99b0dd 224 : AliForwardUtil::RingHistos(o),
7e4038b5 225 fDensity(o.fDensity)
226{}
227
228//____________________________________________________________________
229AliFMDCorrections::RingHistos&
230AliFMDCorrections::RingHistos::operator=(const RingHistos& o)
231{
9d99b0dd 232 AliForwardUtil::RingHistos::operator=(o);
7e4038b5 233
234 if (fDensity) delete fDensity;
235
236 fDensity = static_cast<TH2D*>(o.fDensity->Clone());
237
238 return *this;
239}
240//____________________________________________________________________
241AliFMDCorrections::RingHistos::~RingHistos()
242{
243 if (fDensity) delete fDensity;
244}
245
246//____________________________________________________________________
247void
248AliFMDCorrections::RingHistos::Output(TList* dir)
249{
9d99b0dd 250 TList* d = DefineOutputList(dir);
7e4038b5 251 d->Add(fDensity);
9d99b0dd 252}
253
254//____________________________________________________________________
255void
256AliFMDCorrections::RingHistos::ScaleHistograms(TList* dir, Int_t nEvents)
257{
258 TList* l = GetOutputList(dir);
259 if (!l) return;
260
261 TH1* density = GetOutputHist(l,Form("%s_Primary_Density", fName.Data()));
262 if (density) density->Scale(1./nEvents);
7e4038b5 263}
264
265//____________________________________________________________________
266//
267// EOF
268//
269
270
271