Now muondep depends on base (Philippe P.)
[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>
6#include "AliFMDAnaParameters.h"
7#include "AliLog.h"
8#include <TH2D.h>
9
10ClassImp(AliFMDCorrections)
11#if 0
12; // For Emacs
13#endif
14
15//____________________________________________________________________
16AliFMDCorrections::AliFMDCorrections()
17 : TNamed(),
18 fRingHistos(),
19 fMultCut(0.3)
20{}
21
22//____________________________________________________________________
23AliFMDCorrections::AliFMDCorrections(const char* title)
24 : TNamed("fmdCorrections", title),
25 fRingHistos(),
26 fMultCut(0.3)
27{
28 fRingHistos.SetName(GetName());
29 fRingHistos.Add(new RingHistos(1, 'I'));
30 fRingHistos.Add(new RingHistos(2, 'I'));
31 fRingHistos.Add(new RingHistos(2, 'O'));
32 fRingHistos.Add(new RingHistos(3, 'I'));
33 fRingHistos.Add(new RingHistos(3, 'O'));
34}
35
36//____________________________________________________________________
37AliFMDCorrections::AliFMDCorrections(const AliFMDCorrections& o)
38 : TNamed(o),
39 fRingHistos(),
40 fMultCut(o.fMultCut)
41{
42 TIter next(&o.fRingHistos);
43 TObject* obj = 0;
44 while ((obj = next())) fRingHistos.Add(obj);
45}
46
47//____________________________________________________________________
48AliFMDCorrections::~AliFMDCorrections()
49{
50 fRingHistos.Delete();
51}
52
53//____________________________________________________________________
54AliFMDCorrections&
55AliFMDCorrections::operator=(const AliFMDCorrections& o)
56{
57 SetName(o.GetName());
58 SetTitle(o.GetTitle());
59
60 fMultCut = o.fMultCut;
61
62 fRingHistos.Delete();
63 TIter next(&o.fRingHistos);
64 TObject* obj = 0;
65 while ((obj = next())) fRingHistos.Add(obj);
66
67 return *this;
68}
69
70//____________________________________________________________________
71AliFMDCorrections::RingHistos*
72AliFMDCorrections::GetRingHistos(UShort_t d, Char_t r) const
73{
74 Int_t idx = -1;
75 switch (d) {
76 case 1: idx = 0; break;
77 case 2: idx = 1 + (r == 'I' || r == 'i' ? 0 : 1); break;
78 case 3: idx = 3 + (r == 'I' || r == 'i' ? 0 : 1); break;
79 }
80 if (idx < 0 || idx >= fRingHistos.GetEntries()) return 0;
81
82 return static_cast<RingHistos*>(fRingHistos.At(idx));
83}
84
85//____________________________________________________________________
86Bool_t
87AliFMDCorrections::Correct(AliForwardUtil::Histos& hists,
88 Int_t vtxbin)
89{
90 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
91
92 for (UShort_t d=1; d<=3; d++) {
93 UShort_t nr = (d == 1 ? 1 : 2);
94 for (UShort_t q=0; q<nr; q++) {
95 Char_t r = (q == 0 ? 'I' : 'O');
96 TH2D* h = hists.Get(d,r);
97 RingHistos* rh= GetRingHistos(d,r);
98 TH2F* bg= pars->GetBackgroundCorrection(d, r, vtxbin);
99 TH2F* ef= pars->GetEventSelectionEfficiency("INEL",vtxbin,r);
100 if (!bg) {
101 AliWarning(Form("No secondary correction for FMDM%d%c in vertex bin %d",
102 d, r, vtxbin));
103 continue;
104 }
105 if (!ef) {
106 AliWarning(Form("No event %s selection efficiency in vertex bin %d",
107 "INEL", vtxbin));
108 continue;
109 }
110
111 // Divide by primary/total ratio
112 h->Divide(bg);
113
114 // Divide by the event selection efficiency
115 h->Divide(ef);
116
117 if(!pars->SharingEffPresent()) {
118 AliWarning("No sharing efficiencies");
119 continue;
120 }
121
122 TH1F* sf = pars->GetSharingEfficiencyTrVtx(d,r,vtxbin);
123
124 for (Int_t ieta = 1; ieta <= h->GetNbinsX(); ieta++) {
125 Float_t c = sf->GetBinContent(ieta);
126 Float_t ec = sf->GetBinError(ieta);
127
128 if (c == 0) continue;
129
130 for (Int_t iphi = 1; iphi <= h->GetNbinsY(); iphi++) {
131 Double_t m = h->GetBinContent(ieta, iphi) / c;
132 Double_t em = h->GetBinError(ieta, iphi);
133
134 Double_t e = TMath::Sqrt(em * em + (m * ec) * (m * ec));
135
136 h->SetBinContent(ieta,iphi,m);
137 h->SetBinError(ieta,iphi,e);
138 }
139 }
140
141 rh->fDensity->Add(h);
142 }
143 }
144
145 return kTRUE;
146}
147
148//____________________________________________________________________
149void
150AliFMDCorrections::ScaleHistograms(Int_t nEvents)
151{
152 if (nEvents <= 0) return;
153
154 TIter next(&fRingHistos);
155 RingHistos* o = 0;
156 while ((o = static_cast<RingHistos*>(next()))) {
157 o->fDensity->Scale(1. / nEvents);
158 }
159}
160
161//____________________________________________________________________
162void
163AliFMDCorrections::Output(TList* dir)
164{
165 TList* d = new TList;
166 d->SetName(GetName());
167 dir->Add(d);
168 TIter next(&fRingHistos);
169 RingHistos* o = 0;
170 while ((o = static_cast<RingHistos*>(next()))) {
171 o->Output(d);
172 }
173}
174
175//====================================================================
176AliFMDCorrections::RingHistos::RingHistos()
177 : fDet(0),
178 fRing('\0'),
179 fDensity(0)
180{}
181
182//____________________________________________________________________
183AliFMDCorrections::RingHistos::RingHistos(UShort_t d, Char_t r)
184 : fDet(d),
185 fRing(r),
186 fDensity(0)
187{
188 fDensity = new TH2D(Form("FMD%d%c_Primary_Density", d, r),
189 Form("in FMD%d%c", d, r),
190 200, -4, 6, (r == 'I' || r == 'i' ? 20 : 40),
191 0, 2*TMath::Pi());
192 fDensity->SetDirectory(0);
193 fDensity->SetXTitle("#eta");
194 fDensity->SetYTitle("#phi [radians]");
195 fDensity->SetZTitle("Primary N_{ch} density");
196}
197//____________________________________________________________________
198AliFMDCorrections::RingHistos::RingHistos(const RingHistos& o)
199 : TObject(o),
200 fDet(o.fDet),
201 fRing(o.fRing),
202 fDensity(o.fDensity)
203{}
204
205//____________________________________________________________________
206AliFMDCorrections::RingHistos&
207AliFMDCorrections::RingHistos::operator=(const RingHistos& o)
208{
209 fDet = o.fDet;
210 fRing = o.fRing;
211
212 if (fDensity) delete fDensity;
213
214 fDensity = static_cast<TH2D*>(o.fDensity->Clone());
215
216 return *this;
217}
218//____________________________________________________________________
219AliFMDCorrections::RingHistos::~RingHistos()
220{
221 if (fDensity) delete fDensity;
222}
223
224//____________________________________________________________________
225void
226AliFMDCorrections::RingHistos::Output(TList* dir)
227{
228 TList* d = new TList;
229 d->SetName(Form("FMD%d%c", fDet, fRing));
230 d->Add(fDensity);
231 dir->Add(d);
232}
233
234//____________________________________________________________________
235//
236// EOF
237//
238
239
240