]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/AliFMDCorrector.cxx
Fixes for pA indenfication of events
[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"
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
6ab100ec 38 DGUARD(fDebug, 0, "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
6ab100ec 55 DGUARD(fDebug, 0, "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
6ab100ec 78 DGUARD(fDebug, 0, "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
121AliFMDCorrector::Init(const TAxis&)
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
162//____________________________________________________________________
163Bool_t
72cc12cd 164AliFMDCorrector::Correct(AliForwardUtil::Histos& hists,
7ec4d843 165 UShort_t vtxbin)
7e4038b5 166{
7984e5f7 167 //
168 // Do the calculations
169 // Parameters:
170 // hists Cache of histograms
171 // vtxBin Vertex bin
172 //
173 // Return:
174 // true on successs
175 //
6ab100ec 176 DGUARD(fDebug, 1, "Correct histograms of AliFMDCorrector");
0bd4b00f 177 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
7e4038b5 178
0bd4b00f 179 UShort_t uvb = vtxbin;
7e4038b5 180 for (UShort_t d=1; d<=3; d++) {
181 UShort_t nr = (d == 1 ? 1 : 2);
182 for (UShort_t q=0; q<nr; q++) {
72cc12cd 183 Char_t r = (q == 0 ? 'I' : 'O');
184 TH2D* h = hists.Get(d,r);
185 RingHistos* rh = GetRingHistos(d,r);
7ec4d843 186
187 if (fUseSecondaryMap) {
188 TH2D* bg = fcm.GetSecondaryMap()->GetCorrection(d, r, uvb);
189 if (!bg) {
5bb5d1f6 190 AliWarning(Form("No secondary correction for FMDM%d%c "
191 "in vertex bin %d", d, r, uvb));
7ec4d843 192 continue;
193 }
194 // Divide by primary/total ratio
195 h->Divide(bg);
7e4038b5 196 }
7ec4d843 197 if (fUseVertexBias) {
198 TH2D* ef = fcm.GetVertexBias()->GetCorrection(r, uvb);
199 if (!ef) {
200 AliWarning(Form("No event %s vertex bias correction in vertex bin %d",
201 (r == 'I' || r == 'i' ? "inner" : "outer"), uvb));
202 continue;
203 }
204 // Divide by the event selection efficiency
205 h->Divide(ef);
72cc12cd 206 }
7ec4d843 207 if (fUseAcceptance) {
208 TH2D* ac = fcm.GetAcceptance()->GetCorrection(d, r, uvb);
209 if (!ac) {
5bb5d1f6 210 AliWarning(Form("No acceptance correction for FMD%d%c in "
211 "vertex bin %d", d, r, uvb));
7ec4d843 212 continue;
213 }
214 // Divide by the acceptance correction
215 h->Divide(ac);
7e4038b5 216 }
217
81eda625 218 if (fUseMergingEfficiency) {
219 if (!fcm.GetMergingEfficiency()) {
220 AliWarning("No merging efficiencies");
221 continue;
222 }
223 TH1D* sf = fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb);
224 if (!fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb)) {
225 AliWarning(Form("No merging efficiency for FMD%d%c at vertex bin %d",
226 d, r, uvb));
227 continue;
228 }
7e4038b5 229
81eda625 230
231 for (Int_t ieta = 1; ieta <= h->GetNbinsX(); ieta++) {
232 Float_t c = sf->GetBinContent(ieta);
233 Float_t ec = sf->GetBinError(ieta);
234
235 if (c == 0) continue;
7e4038b5 236
81eda625 237 for (Int_t iphi = 1; iphi <= h->GetNbinsY(); iphi++) {
238 Double_t m = h->GetBinContent(ieta, iphi) / c;
239 Double_t em = h->GetBinError(ieta, iphi);
7e4038b5 240
81eda625 241 Double_t e = TMath::Sqrt(em * em + (m * ec) * (m * ec));
242
243 h->SetBinContent(ieta,iphi,m);
244 h->SetBinError(ieta,iphi,e);
245 }
7e4038b5 246 }
247 }
12fffad7 248 //HHD
249 /*
250 TH2D* bg = fcm.GetSecondaryMap()->GetCorrection(d, r, uvb);
251 TH2D hRing("hring","hring",bg->GetNbinsX(),
252 bg->GetXaxis()->GetXmin(),
253 bg->GetXaxis()->GetXmax(),
254 bg->GetNbinsY(),
255 bg->GetYaxis()->GetXmin(),
256 bg->GetYaxis()->GetXmax());
257
258 Int_t edgebin[4] = {0,0,0,0};
259 for(Int_t ii = 1; ii <=bg->GetNbinsX(); ii++) {
260 for(Int_t jj = 1; jj <=bg->GetNbinsY(); jj++) {
261 Float_t bgcor = bg->GetBinContent(ii,jj);
262 if(bgcor<0.1) continue;
263 if(edgebin[0] == 0) edgebin[0] = ii;
264 if(edgebin[0] == ii) continue;
265 if(edgebin[0] > 0 && edgebin[1] == 0) edgebin[1] = ii;
266 if(edgebin[0]>0 && edgebin[1]>0) break;
267 }
268 }
269 for(Int_t ii = bg->GetNbinsX(); ii >= 1; ii--) {
270 for(Int_t jj = 1; jj <=bg->GetNbinsY(); jj++) {
271 Float_t bgcor = bg->GetBinContent(ii,jj);
272 if(bgcor<0.1) continue;
273 if(edgebin[2] == 0) edgebin[2] = ii;
274 if(edgebin[2] == ii) continue;
275 if(edgebin[2] > 0 && edgebin[3] == 0) edgebin[3] = ii;
276 if(edgebin[2]>0 && edgebin[3]>0) break;
277 }
278 }
279 for(Int_t ii = 1; ii <=bg->GetNbinsX(); ii++) {
280 for(Int_t jj = 1; jj <=bg->GetNbinsY(); jj++) {
281 Float_t data = h->GetBinContent(ii,jj);
282 if(data <0.000001) continue;
283 if(edgebin[0] == ii || edgebin[1] == ii || edgebin[2] == ii || edgebin[3] == ii) continue;
284 hRing.SetBinContent(ii,jj,data);
285 hRing.SetBinError(ii,jj,h->GetBinError(ii,jj));
286 }
287 }
288
289 //std::cout<<edgebin[0]<<" "<<edgebin[1]<<" "<<edgebin[2]<<" "<<edgebin[3]<<std::endl;
290 */
291
7e4038b5 292 rh->fDensity->Add(h);
293 }
294 }
295
296 return kTRUE;
297}
298
299//____________________________________________________________________
300void
fb3430ac 301AliFMDCorrector::ScaleHistograms(const TList* dir, Int_t nEvents)
7e4038b5 302{
7984e5f7 303 //
304 // Scale the histograms to the total number of events
305 // Parameters:
306 // dir Where the output is stored
307 // nEvents Number of events
308 //
6ab100ec 309 DGUARD(fDebug, 1, "Scale histograms of AliFMDCorrector");
7e4038b5 310 if (nEvents <= 0) return;
9d99b0dd 311 TList* d = static_cast<TList*>(dir->FindObject(GetName()));
312 if (!d) return;
7e4038b5 313
314 TIter next(&fRingHistos);
315 RingHistos* o = 0;
5bb5d1f6 316 THStack* sums = new THStack("sums", "Sums of ring results");
317 while ((o = static_cast<RingHistos*>(next()))) {
9d99b0dd 318 o->ScaleHistograms(d, nEvents);
5bb5d1f6 319 TH1D* sum = o->fDensity->ProjectionX(o->GetName(), 1,
320 o->fDensity->GetNbinsY(),"e");
321 sum->Scale(1., "width");
322 sum->SetTitle(o->GetName());
323 sum->SetDirectory(0);
324 sum->SetYTitle("#sum N_{ch,primary}");
325 sums->Add(sum);
326 }
327 d->Add(sums);
328
7e4038b5 329}
7e4038b5 330//____________________________________________________________________
331void
72cc12cd 332AliFMDCorrector::DefineOutput(TList* dir)
7e4038b5 333{
fb3430ac 334 //
335 // Output diagnostic histograms to directory
336 //
337 // Parameters:
338 // dir List to write in
339 //
6ab100ec 340 DGUARD(fDebug, 1, "Define output of AliFMDCorrector");
7e4038b5 341 TList* d = new TList;
342 d->SetName(GetName());
343 dir->Add(d);
241cca4d 344
345 d->Add(AliForwardUtil::MakeParameter("secondary", fUseSecondaryMap));
346 d->Add(AliForwardUtil::MakeParameter("vertexBias", fUseVertexBias));
347 d->Add(AliForwardUtil::MakeParameter("acceptance", fUseAcceptance));
348 d->Add(AliForwardUtil::MakeParameter("merging", fUseMergingEfficiency));
349
350
7e4038b5 351 TIter next(&fRingHistos);
352 RingHistos* o = 0;
353 while ((o = static_cast<RingHistos*>(next()))) {
354 o->Output(d);
355 }
356}
357
0bd4b00f 358//____________________________________________________________________
359void
72cc12cd 360AliFMDCorrector::Print(Option_t* /* option */) const
0bd4b00f 361{
7984e5f7 362 //
363 // Print information
364 // Parameters:
365 // option Not used
366 //
0bd4b00f 367 char ind[gROOT->GetDirLevel()+1];
368 for (Int_t i = 0; i < gROOT->GetDirLevel(); i++) ind[i] = ' ';
369 ind[gROOT->GetDirLevel()] = '\0';
1f480471 370 std::cout << ind << ClassName() << ": " << GetName() << "\n"
7ec4d843 371 << std::boolalpha
372 << ind << " Use secondary maps: " << fUseSecondaryMap << "\n"
373 << ind << " Use vertex bias: " << fUseVertexBias << "\n"
374 << ind << " Use acceptance: " << fUseAcceptance << "\n"
375 << ind << " Use merging efficiency: " << fUseMergingEfficiency
8e2bb72a 376 << std::noboolalpha << std::endl;
0bd4b00f 377}
378
7e4038b5 379//====================================================================
72cc12cd 380AliFMDCorrector::RingHistos::RingHistos()
9d99b0dd 381 : AliForwardUtil::RingHistos(),
7e4038b5 382 fDensity(0)
7984e5f7 383{
384 // Constructor
385 //
386 //
387}
7e4038b5 388
389//____________________________________________________________________
72cc12cd 390AliFMDCorrector::RingHistos::RingHistos(UShort_t d, Char_t r)
9d99b0dd 391 : AliForwardUtil::RingHistos(d,r),
7e4038b5 392 fDensity(0)
393{
7984e5f7 394 //
395 // Constructor
396 // Parameters:
397 // d detector
398 // r ring
399 //
5bb5d1f6 400 fDensity = new TH2D("primaryDensity",
401 "#sum N_{ch,primary}/(#Delta#eta#Delta#phi)",
7e4038b5 402 200, -4, 6, (r == 'I' || r == 'i' ? 20 : 40),
403 0, 2*TMath::Pi());
404 fDensity->SetDirectory(0);
5bb5d1f6 405 fDensity->SetMarkerColor(Color());
406 fDensity->Sumw2();
7e4038b5 407 fDensity->SetXTitle("#eta");
408 fDensity->SetYTitle("#phi [radians]");
409 fDensity->SetZTitle("Primary N_{ch} density");
410}
411//____________________________________________________________________
72cc12cd 412AliFMDCorrector::RingHistos::RingHistos(const RingHistos& o)
9d99b0dd 413 : AliForwardUtil::RingHistos(o),
7e4038b5 414 fDensity(o.fDensity)
7984e5f7 415{
416 //
417 // Copy constructor
418 // Parameters:
419 // o Object to copy from
420 //
421}
7e4038b5 422
423//____________________________________________________________________
72cc12cd 424AliFMDCorrector::RingHistos&
425AliFMDCorrector::RingHistos::operator=(const RingHistos& o)
7e4038b5 426{
7984e5f7 427 //
428 // Assignment operator
429 // Parameters:
430 // o Object to assign from
431 //
432 // Return:
433 // Reference to this
434 //
d015ecfe 435 if (&o == this) return *this;
9d99b0dd 436 AliForwardUtil::RingHistos::operator=(o);
7e4038b5 437
438 if (fDensity) delete fDensity;
439
440 fDensity = static_cast<TH2D*>(o.fDensity->Clone());
441
442 return *this;
443}
444//____________________________________________________________________
72cc12cd 445AliFMDCorrector::RingHistos::~RingHistos()
7e4038b5 446{
7984e5f7 447 //
448 // Destructor
449 //
7e4038b5 450 if (fDensity) delete fDensity;
451}
452
453//____________________________________________________________________
454void
72cc12cd 455AliFMDCorrector::RingHistos::Output(TList* dir)
7e4038b5 456{
7984e5f7 457 //
458 // Make output
459 // Parameters:
460 // dir Where to put it
461 //
9d99b0dd 462 TList* d = DefineOutputList(dir);
7e4038b5 463 d->Add(fDensity);
9d99b0dd 464}
465
466//____________________________________________________________________
467void
5bb5d1f6 468AliFMDCorrector::RingHistos::ScaleHistograms(TList* dir, Int_t nEvents)
9d99b0dd 469{
7984e5f7 470 //
471 // Scale the histograms to the total number of events
472 // Parameters:
473 // dir where the output is stored
474 // nEvents Number of events
475 //
9d99b0dd 476 TList* l = GetOutputList(dir);
477 if (!l) return;
478
5bb5d1f6 479 TH1* density = GetOutputHist(l,"primaryDensity");
480 if (density) density->Scale(1./nEvents);
7e4038b5 481}
482
483//____________________________________________________________________
484//
485// EOF
486//
487
488
489