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