]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/AliFMDCorrector.cxx
Mior fixes
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDCorrector.cxx
CommitLineData
7984e5f7 1//
2// This class calculates the exclusive charged particle density
3// in each for the 5 FMD rings.
4//
72cc12cd 5#include "AliFMDCorrector.h"
7e4038b5 6#include <AliESDFMD.h>
7#include <TAxis.h>
8#include <TList.h>
9#include <TMath.h>
0bd4b00f 10#include "AliForwardCorrectionManager.h"
fb3430ac 11// #include "AliFMDCorrDoubleHit.h"
12#include "AliFMDCorrVertexBias.h"
13#include "AliFMDCorrMergingEfficiency.h"
14#include "AliFMDCorrAcceptance.h"
7e4038b5 15#include "AliLog.h"
16#include <TH2D.h>
0bd4b00f 17#include <TROOT.h>
5bb5d1f6 18#include <THStack.h>
0bd4b00f 19#include <iostream>
20#include <iomanip>
7e4038b5 21
72cc12cd 22ClassImp(AliFMDCorrector)
7e4038b5 23#if 0
24; // For Emacs
25#endif
26
27//____________________________________________________________________
72cc12cd 28AliFMDCorrector::AliFMDCorrector()
7e4038b5 29 : TNamed(),
30 fRingHistos(),
7ec4d843 31 fUseSecondaryMap(true),
9d05ffeb 32 fUseVertexBias(false),
7ec4d843 33 fUseAcceptance(true),
9d05ffeb 34 fUseMergingEfficiency(false),
ea3e5d95 35 fDebug(0)
7984e5f7 36{
37 // Constructor
38}
7e4038b5 39
40//____________________________________________________________________
72cc12cd 41AliFMDCorrector::AliFMDCorrector(const char* title)
cc83fca2 42 : TNamed("fmdCorrector", title),
7e4038b5 43 fRingHistos(),
7ec4d843 44 fUseSecondaryMap(true),
9d05ffeb 45 fUseVertexBias(false),
7ec4d843 46 fUseAcceptance(true),
9d05ffeb 47 fUseMergingEfficiency(false),
ea3e5d95 48 fDebug(0)
7e4038b5 49{
7984e5f7 50 // Constructor
51 //
52 // Parameters:
53 // title Title
7e4038b5 54 fRingHistos.SetName(GetName());
55 fRingHistos.Add(new RingHistos(1, 'I'));
56 fRingHistos.Add(new RingHistos(2, 'I'));
57 fRingHistos.Add(new RingHistos(2, 'O'));
58 fRingHistos.Add(new RingHistos(3, 'I'));
59 fRingHistos.Add(new RingHistos(3, 'O'));
60}
61
62//____________________________________________________________________
72cc12cd 63AliFMDCorrector::AliFMDCorrector(const AliFMDCorrector& o)
7e4038b5 64 : TNamed(o),
65 fRingHistos(),
7ec4d843 66 fUseSecondaryMap(o.fUseSecondaryMap),
67 fUseVertexBias(o.fUseVertexBias),
68 fUseAcceptance(o.fUseAcceptance),
81eda625 69 fUseMergingEfficiency(o.fUseMergingEfficiency),
ea3e5d95 70 fDebug(o.fDebug)
7e4038b5 71{
7984e5f7 72 // Copy constructor
73 //
74 // Parameters:
75 // o Object to copy from
7e4038b5 76 TIter next(&o.fRingHistos);
77 TObject* obj = 0;
78 while ((obj = next())) fRingHistos.Add(obj);
79}
80
81//____________________________________________________________________
72cc12cd 82AliFMDCorrector::~AliFMDCorrector()
7e4038b5 83{
7984e5f7 84 // Destructor
85 //
86 //
7e4038b5 87 fRingHistos.Delete();
88}
89
90//____________________________________________________________________
72cc12cd 91AliFMDCorrector&
92AliFMDCorrector::operator=(const AliFMDCorrector& o)
7e4038b5 93{
7984e5f7 94 // Assignment operator
95 //
96 // Parameters:
97 // o Object to assign from
ea3e5d95 98 TNamed::operator=(o);
7e4038b5 99
ea3e5d95 100 fDebug = o.fDebug;
7e4038b5 101 fRingHistos.Delete();
7ec4d843 102 fUseSecondaryMap = o.fUseSecondaryMap;
103 fUseVertexBias = o.fUseVertexBias;
104 fUseAcceptance = o.fUseAcceptance;
81eda625 105 fUseMergingEfficiency = o.fUseMergingEfficiency;
7e4038b5 106 TIter next(&o.fRingHistos);
107 TObject* obj = 0;
108 while ((obj = next())) fRingHistos.Add(obj);
109
110 return *this;
111}
112
7ec4d843 113//____________________________________________________________________
114void
115AliFMDCorrector::Init(const TAxis&)
116{
117 //
118 // Initialize this object
119 //
120 // Parameters:
121 // etaAxis Eta axis to use
122 //
123 if (!fUseSecondaryMap)
124 AliWarning("Secondary maps not used - BE CAREFUL");
125 if (!fUseVertexBias)
126 AliWarning("Vertex bias not used");
127 if (!fUseAcceptance)
128 AliWarning("Acceptance from dead-channels not used");
129}
130
7e4038b5 131//____________________________________________________________________
72cc12cd 132AliFMDCorrector::RingHistos*
133AliFMDCorrector::GetRingHistos(UShort_t d, Char_t r) const
7e4038b5 134{
7984e5f7 135 //
136 // Get the ring histogram container
137 // Parameters:
138 // d Detector
139 // r Ring
140 //
141 // Return:
142 // Ring histogram container
143 //
7e4038b5 144 Int_t idx = -1;
145 switch (d) {
146 case 1: idx = 0; break;
147 case 2: idx = 1 + (r == 'I' || r == 'i' ? 0 : 1); break;
148 case 3: idx = 3 + (r == 'I' || r == 'i' ? 0 : 1); break;
149 }
150 if (idx < 0 || idx >= fRingHistos.GetEntries()) return 0;
151
152 return static_cast<RingHistos*>(fRingHistos.At(idx));
153}
154
155//____________________________________________________________________
156Bool_t
72cc12cd 157AliFMDCorrector::Correct(AliForwardUtil::Histos& hists,
7ec4d843 158 UShort_t vtxbin)
7e4038b5 159{
7984e5f7 160 //
161 // Do the calculations
162 // Parameters:
163 // hists Cache of histograms
164 // vtxBin Vertex bin
165 //
166 // Return:
167 // true on successs
168 //
0bd4b00f 169 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
7e4038b5 170
0bd4b00f 171 UShort_t uvb = vtxbin;
7e4038b5 172 for (UShort_t d=1; d<=3; d++) {
173 UShort_t nr = (d == 1 ? 1 : 2);
174 for (UShort_t q=0; q<nr; q++) {
72cc12cd 175 Char_t r = (q == 0 ? 'I' : 'O');
176 TH2D* h = hists.Get(d,r);
177 RingHistos* rh = GetRingHistos(d,r);
7ec4d843 178
179 if (fUseSecondaryMap) {
180 TH2D* bg = fcm.GetSecondaryMap()->GetCorrection(d, r, uvb);
181 if (!bg) {
5bb5d1f6 182 AliWarning(Form("No secondary correction for FMDM%d%c "
183 "in vertex bin %d", d, r, uvb));
7ec4d843 184 continue;
185 }
186 // Divide by primary/total ratio
187 h->Divide(bg);
7e4038b5 188 }
7ec4d843 189 if (fUseVertexBias) {
190 TH2D* ef = fcm.GetVertexBias()->GetCorrection(r, uvb);
191 if (!ef) {
192 AliWarning(Form("No event %s vertex bias correction in vertex bin %d",
193 (r == 'I' || r == 'i' ? "inner" : "outer"), uvb));
194 continue;
195 }
196 // Divide by the event selection efficiency
197 h->Divide(ef);
72cc12cd 198 }
7ec4d843 199 if (fUseAcceptance) {
200 TH2D* ac = fcm.GetAcceptance()->GetCorrection(d, r, uvb);
201 if (!ac) {
5bb5d1f6 202 AliWarning(Form("No acceptance correction for FMD%d%c in "
203 "vertex bin %d", d, r, uvb));
7ec4d843 204 continue;
205 }
206 // Divide by the acceptance correction
207 h->Divide(ac);
7e4038b5 208 }
209
81eda625 210 if (fUseMergingEfficiency) {
211 if (!fcm.GetMergingEfficiency()) {
212 AliWarning("No merging efficiencies");
213 continue;
214 }
215 TH1D* sf = fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb);
216 if (!fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb)) {
217 AliWarning(Form("No merging efficiency for FMD%d%c at vertex bin %d",
218 d, r, uvb));
219 continue;
220 }
7e4038b5 221
81eda625 222
223 for (Int_t ieta = 1; ieta <= h->GetNbinsX(); ieta++) {
224 Float_t c = sf->GetBinContent(ieta);
225 Float_t ec = sf->GetBinError(ieta);
226
227 if (c == 0) continue;
7e4038b5 228
81eda625 229 for (Int_t iphi = 1; iphi <= h->GetNbinsY(); iphi++) {
230 Double_t m = h->GetBinContent(ieta, iphi) / c;
231 Double_t em = h->GetBinError(ieta, iphi);
7e4038b5 232
81eda625 233 Double_t e = TMath::Sqrt(em * em + (m * ec) * (m * ec));
234
235 h->SetBinContent(ieta,iphi,m);
236 h->SetBinError(ieta,iphi,e);
237 }
7e4038b5 238 }
239 }
12fffad7 240 //HHD
241 /*
242 TH2D* bg = fcm.GetSecondaryMap()->GetCorrection(d, r, uvb);
243 TH2D hRing("hring","hring",bg->GetNbinsX(),
244 bg->GetXaxis()->GetXmin(),
245 bg->GetXaxis()->GetXmax(),
246 bg->GetNbinsY(),
247 bg->GetYaxis()->GetXmin(),
248 bg->GetYaxis()->GetXmax());
249
250 Int_t edgebin[4] = {0,0,0,0};
251 for(Int_t ii = 1; ii <=bg->GetNbinsX(); ii++) {
252 for(Int_t jj = 1; jj <=bg->GetNbinsY(); jj++) {
253 Float_t bgcor = bg->GetBinContent(ii,jj);
254 if(bgcor<0.1) continue;
255 if(edgebin[0] == 0) edgebin[0] = ii;
256 if(edgebin[0] == ii) continue;
257 if(edgebin[0] > 0 && edgebin[1] == 0) edgebin[1] = ii;
258 if(edgebin[0]>0 && edgebin[1]>0) break;
259 }
260 }
261 for(Int_t ii = bg->GetNbinsX(); ii >= 1; ii--) {
262 for(Int_t jj = 1; jj <=bg->GetNbinsY(); jj++) {
263 Float_t bgcor = bg->GetBinContent(ii,jj);
264 if(bgcor<0.1) continue;
265 if(edgebin[2] == 0) edgebin[2] = ii;
266 if(edgebin[2] == ii) continue;
267 if(edgebin[2] > 0 && edgebin[3] == 0) edgebin[3] = ii;
268 if(edgebin[2]>0 && edgebin[3]>0) break;
269 }
270 }
271 for(Int_t ii = 1; ii <=bg->GetNbinsX(); ii++) {
272 for(Int_t jj = 1; jj <=bg->GetNbinsY(); jj++) {
273 Float_t data = h->GetBinContent(ii,jj);
274 if(data <0.000001) continue;
275 if(edgebin[0] == ii || edgebin[1] == ii || edgebin[2] == ii || edgebin[3] == ii) continue;
276 hRing.SetBinContent(ii,jj,data);
277 hRing.SetBinError(ii,jj,h->GetBinError(ii,jj));
278 }
279 }
280
281 //std::cout<<edgebin[0]<<" "<<edgebin[1]<<" "<<edgebin[2]<<" "<<edgebin[3]<<std::endl;
282 */
283
7e4038b5 284 rh->fDensity->Add(h);
285 }
286 }
287
288 return kTRUE;
289}
290
291//____________________________________________________________________
292void
fb3430ac 293AliFMDCorrector::ScaleHistograms(const TList* dir, Int_t nEvents)
7e4038b5 294{
7984e5f7 295 //
296 // Scale the histograms to the total number of events
297 // Parameters:
298 // dir Where the output is stored
299 // nEvents Number of events
300 //
7e4038b5 301 if (nEvents <= 0) return;
9d99b0dd 302 TList* d = static_cast<TList*>(dir->FindObject(GetName()));
303 if (!d) return;
7e4038b5 304
305 TIter next(&fRingHistos);
306 RingHistos* o = 0;
5bb5d1f6 307 THStack* sums = new THStack("sums", "Sums of ring results");
308 while ((o = static_cast<RingHistos*>(next()))) {
9d99b0dd 309 o->ScaleHistograms(d, nEvents);
5bb5d1f6 310 TH1D* sum = o->fDensity->ProjectionX(o->GetName(), 1,
311 o->fDensity->GetNbinsY(),"e");
312 sum->Scale(1., "width");
313 sum->SetTitle(o->GetName());
314 sum->SetDirectory(0);
315 sum->SetYTitle("#sum N_{ch,primary}");
316 sums->Add(sum);
317 }
318 d->Add(sums);
319
7e4038b5 320}
7e4038b5 321//____________________________________________________________________
322void
72cc12cd 323AliFMDCorrector::DefineOutput(TList* dir)
7e4038b5 324{
fb3430ac 325 //
326 // Output diagnostic histograms to directory
327 //
328 // Parameters:
329 // dir List to write in
330 //
7e4038b5 331 TList* d = new TList;
332 d->SetName(GetName());
333 dir->Add(d);
334 TIter next(&fRingHistos);
335 RingHistos* o = 0;
336 while ((o = static_cast<RingHistos*>(next()))) {
337 o->Output(d);
338 }
339}
340
0bd4b00f 341//____________________________________________________________________
342void
72cc12cd 343AliFMDCorrector::Print(Option_t* /* option */) const
0bd4b00f 344{
7984e5f7 345 //
346 // Print information
347 // Parameters:
348 // option Not used
349 //
0bd4b00f 350 char ind[gROOT->GetDirLevel()+1];
351 for (Int_t i = 0; i < gROOT->GetDirLevel(); i++) ind[i] = ' ';
352 ind[gROOT->GetDirLevel()] = '\0';
1f480471 353 std::cout << ind << ClassName() << ": " << GetName() << "\n"
7ec4d843 354 << std::boolalpha
355 << ind << " Use secondary maps: " << fUseSecondaryMap << "\n"
356 << ind << " Use vertex bias: " << fUseVertexBias << "\n"
357 << ind << " Use acceptance: " << fUseAcceptance << "\n"
358 << ind << " Use merging efficiency: " << fUseMergingEfficiency
8e2bb72a 359 << std::noboolalpha << std::endl;
0bd4b00f 360}
361
7e4038b5 362//====================================================================
72cc12cd 363AliFMDCorrector::RingHistos::RingHistos()
9d99b0dd 364 : AliForwardUtil::RingHistos(),
7e4038b5 365 fDensity(0)
7984e5f7 366{
367 // Constructor
368 //
369 //
370}
7e4038b5 371
372//____________________________________________________________________
72cc12cd 373AliFMDCorrector::RingHistos::RingHistos(UShort_t d, Char_t r)
9d99b0dd 374 : AliForwardUtil::RingHistos(d,r),
7e4038b5 375 fDensity(0)
376{
7984e5f7 377 //
378 // Constructor
379 // Parameters:
380 // d detector
381 // r ring
382 //
5bb5d1f6 383 fDensity = new TH2D("primaryDensity",
384 "#sum N_{ch,primary}/(#Delta#eta#Delta#phi)",
7e4038b5 385 200, -4, 6, (r == 'I' || r == 'i' ? 20 : 40),
386 0, 2*TMath::Pi());
387 fDensity->SetDirectory(0);
5bb5d1f6 388 fDensity->SetMarkerColor(Color());
389 fDensity->Sumw2();
7e4038b5 390 fDensity->SetXTitle("#eta");
391 fDensity->SetYTitle("#phi [radians]");
392 fDensity->SetZTitle("Primary N_{ch} density");
393}
394//____________________________________________________________________
72cc12cd 395AliFMDCorrector::RingHistos::RingHistos(const RingHistos& o)
9d99b0dd 396 : AliForwardUtil::RingHistos(o),
7e4038b5 397 fDensity(o.fDensity)
7984e5f7 398{
399 //
400 // Copy constructor
401 // Parameters:
402 // o Object to copy from
403 //
404}
7e4038b5 405
406//____________________________________________________________________
72cc12cd 407AliFMDCorrector::RingHistos&
408AliFMDCorrector::RingHistos::operator=(const RingHistos& o)
7e4038b5 409{
7984e5f7 410 //
411 // Assignment operator
412 // Parameters:
413 // o Object to assign from
414 //
415 // Return:
416 // Reference to this
417 //
9d99b0dd 418 AliForwardUtil::RingHistos::operator=(o);
7e4038b5 419
420 if (fDensity) delete fDensity;
421
422 fDensity = static_cast<TH2D*>(o.fDensity->Clone());
423
424 return *this;
425}
426//____________________________________________________________________
72cc12cd 427AliFMDCorrector::RingHistos::~RingHistos()
7e4038b5 428{
7984e5f7 429 //
430 // Destructor
431 //
7e4038b5 432 if (fDensity) delete fDensity;
433}
434
435//____________________________________________________________________
436void
72cc12cd 437AliFMDCorrector::RingHistos::Output(TList* dir)
7e4038b5 438{
7984e5f7 439 //
440 // Make output
441 // Parameters:
442 // dir Where to put it
443 //
9d99b0dd 444 TList* d = DefineOutputList(dir);
7e4038b5 445 d->Add(fDensity);
9d99b0dd 446}
447
448//____________________________________________________________________
449void
5bb5d1f6 450AliFMDCorrector::RingHistos::ScaleHistograms(TList* dir, Int_t nEvents)
9d99b0dd 451{
7984e5f7 452 //
453 // Scale the histograms to the total number of events
454 // Parameters:
455 // dir where the output is stored
456 // nEvents Number of events
457 //
9d99b0dd 458 TList* l = GetOutputList(dir);
459 if (!l) return;
460
5bb5d1f6 461 TH1* density = GetOutputHist(l,"primaryDensity");
462 if (density) density->Scale(1./nEvents);
7e4038b5 463}
464
465//____________________________________________________________________
466//
467// EOF
468//
469
470
471