]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/AliCentralMultiplicityTask.cxx
Cleaned up error handling when missing corrections. Previously
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliCentralMultiplicityTask.cxx
CommitLineData
6f791cc3 1//====================================================================
2//
3// Base class for classes that calculate the multiplicity in the
4// central region event-by-event
5//
6// Inputs:
7// - AliESDEvent
8//
9// Outputs:
10// - AliAODCentralMult
11//
12// Histograms
13//
14// Corrections used
15#include "AliCentralMultiplicityTask.h"
52047b6f 16#include "AliAODForwardMult.h"
6f791cc3 17#include "AliForwardUtil.h"
18#include "AliLog.h"
19#include "AliAODHandler.h"
6f791cc3 20#include "AliAnalysisManager.h"
21#include "AliESDEvent.h"
22#include "AliMultiplicity.h"
23#include <TROOT.h>
2a276c75 24#include <TSystem.h>
6f791cc3 25#include <TFile.h>
3e478dba 26#include <TError.h>
28b4012a 27#include <TSystem.h>
6f791cc3 28#include <iostream>
29#include <iomanip>
30
31//====================================================================
32AliCentralMultiplicityTask::AliCentralMultiplicityTask(const char* name)
33 : AliAnalysisTaskSE(name),
52047b6f 34 fInspector("centralEventInspector"),
6f791cc3 35 fData(0),
36 fList(0),
37 fAODCentral(kFALSE),
3b2bfb07 38 fManager(),
e58000b7 39 fUseSecondary(true),
9453b19e 40 fUseAcceptance(true),
52047b6f 41 fFirstEventSeen(false),
28b4012a 42 fIvz(0),
43 fNClusterTracklet(0),
44 fClusterPerTracklet(0),
45 fNCluster(0),
9ecab72f 46 fNTracklet(0),
47 fEtaMin(0),
48 fEtaMax(0)
6f791cc3 49{
fb3430ac 50 //
51 // Constructor
52 //
6ab100ec 53 DGUARD(fDebug,0,"Named CTOR of AliCentralMultiplicityTask: %s", name);
6f791cc3 54 DefineOutput(1, TList::Class());
a59cbd24 55 fBranchNames =
56 "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,"
57 "SPDVertex.,PrimaryVertex.";
6f791cc3 58}
59//____________________________________________________________________
9c825779 60AliCentralMultiplicityTask::AliCentralMultiplicityTask()
61 : AliAnalysisTaskSE(),
52047b6f 62 fInspector(),
9c825779 63 fData(0),
64 fList(0),
65 fAODCentral(),
3b2bfb07 66 fManager(),
e58000b7 67 fUseSecondary(true),
9453b19e 68 fUseAcceptance(true),
52047b6f 69 fFirstEventSeen(false),
28b4012a 70 fIvz(0),
71 fNClusterTracklet(0),
72 fClusterPerTracklet(0),
73 fNCluster(0),
9ecab72f 74 fNTracklet(0),
75 fEtaMin(0),
76 fEtaMax(0)
9c825779 77{
fb3430ac 78 //
79 // Constructor
80 //
6ab100ec 81 DGUARD(fDebug,0,"Default CTOR of AliCentralMultiplicityTask");
9c825779 82}
83//____________________________________________________________________
84AliCentralMultiplicityTask::AliCentralMultiplicityTask(const AliCentralMultiplicityTask& o)
85 : AliAnalysisTaskSE(o),
52047b6f 86 fInspector(o.fInspector),
9c825779 87 fData(o.fData),
88 fList(o.fList),
89 fAODCentral(o.fAODCentral),
3b2bfb07 90 fManager(o.fManager),
e58000b7 91 fUseSecondary(o.fUseSecondary),
9453b19e 92 fUseAcceptance(o.fUseAcceptance),
52047b6f 93 fFirstEventSeen(o.fFirstEventSeen),
28b4012a 94 fIvz(0),
95 fNClusterTracklet(o.fNClusterTracklet),
96 fClusterPerTracklet(o.fClusterPerTracklet),
97 fNCluster(o.fNCluster),
9ecab72f 98 fNTracklet(o.fNTracklet),
99 fEtaMin(o.fEtaMin),
100 fEtaMax(o.fEtaMax)
9c825779 101{
fb3430ac 102 //
103 // Copy constructor
104 //
6ab100ec 105 DGUARD(fDebug,0,"COPY CTOR of AliCentralMultiplicityTask");
106
9c825779 107}
108//____________________________________________________________________
109AliCentralMultiplicityTask&
110AliCentralMultiplicityTask::operator=(const AliCentralMultiplicityTask& o)
111{
fb3430ac 112 //
113 // Assignment operator
114 //
6ab100ec 115 DGUARD(fDebug,3,"Assignment of AliCentralMultiplicityTask");
d015ecfe 116 if (&o == this) return *this;
28b4012a 117 fInspector = o.fInspector;
118 fData = o.fData;
119 fList = o.fList;
120 fAODCentral = o.fAODCentral;
121 fManager = o.fManager;
122 fUseSecondary = o.fUseSecondary;
123 fUseAcceptance = o.fUseAcceptance;
124 fFirstEventSeen = o.fFirstEventSeen;
125 fIvz = 0;
126 fNClusterTracklet = o.fNClusterTracklet;
127 fClusterPerTracklet= o.fClusterPerTracklet;
128 fNCluster = o.fNCluster;
129 fNTracklet = o.fNTracklet;
9ecab72f 130 fEtaMin = o.fEtaMin;
131 fEtaMax = o.fEtaMax;
9c825779 132 return *this;
133}
2a276c75 134//____________________________________________________________________
135Bool_t
136AliCentralMultiplicityTask::Configure(const char* macro)
137{
138 // --- Configure the task ------------------------------------------
139 TString macroPath(gROOT->GetMacroPath());
140 if (!macroPath.Contains("$(ALICE_ROOT)/PWGLF/FORWARD/analysis2")) {
141 macroPath.Append(":$(ALICE_ROOT)/PWGLF/FORWARD/analysis2");
142 gROOT->SetMacroPath(macroPath);
143 }
144 const char* config = gSystem->Which(gROOT->GetMacroPath(),macro);
145 if (!config) {
146 AliWarningF("%s not found in %s", macro, gROOT->GetMacroPath());
147 return false;
148 }
149
150 AliInfoF("Loading configuration of '%s' from %s", ClassName(), config);
151 gROOT->Macro(Form("%s((AliCentralMultiplicityTask*)%p)", config, this));
152 delete config;
153
154 return true;
155}
156
9c825779 157//____________________________________________________________________
3e478dba 158void AliCentralMultiplicityTask::UserCreateOutputObjects()
159{
fb3430ac 160 //
161 // Create output objects
162 //
163 //
6ab100ec 164 DGUARD(fDebug,1,"Create user output in AliCentralMultiplicityTask");
6f791cc3 165
166 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
167 AliAODHandler* ah =
168 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
169 if (!ah) AliFatal("No AOD output handler set in analysis manager");
170
171
172 TObject* obj = &fAODCentral;
173 ah->AddBranch("AliAODCentralMult", &obj);
614f9452 174
175
52047b6f 176
6f791cc3 177 fList = new TList();
9d05ffeb 178 fList->SetOwner();
52047b6f 179
180 fInspector.DefineOutput(fList);
181
182 PostData(1,fList);
183}
184
185//____________________________________________________________________
186AliESDEvent*
187AliCentralMultiplicityTask::GetESDEvent()
188{
189 //
190 // Get the ESD event. IF this is the first event, initialise
191 //
6ab100ec 192 DGUARD(fDebug,1,"Get ESD event in AliCentralMultiplicityTask");
6ff251d8 193 if (IsZombie()) return 0;
52047b6f 194 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
195 if (!esd) {
196 AliWarning("No ESD event found for input event");
197 return 0;
198 }
28b4012a 199
200 // IF we've read the first event already, just return the event
52047b6f 201 if (fFirstEventSeen) return esd;
6f791cc3 202
28b4012a 203 // Read the details of the rung
52047b6f 204 fInspector.ReadRunDetails(esd);
28b4012a 205
206 // If we weren't initialised before (i.e., in the setup), do so now.
207 if (!GetManager().IsInit()) {
208 GetManager().Init(fInspector.GetCollisionSystem(),
209 fInspector.GetEnergy(),
210 fInspector.GetField());
6ff251d8 211 //AliInfo("Manager of corrections in AliCentralMultiplicityTask init");
212 }
213 Bool_t ok = true;
214 if (!GetManager().HasSecondaryCorrection()) {
215 ok = false;
216 AliError("No secondary correction defined!");
217 }
218 if (!GetManager().HasAcceptanceCorrection()) {
219 ok = false;
220 AliError("No acceptance correction defined!");
221 }
222 // If the corrections are not seen, make this a zombie, and prevent
223 // further execution of this task.
224 if (!ok) {
225 AliError("Missing corrections, make this a zombie");
226 SetZombie(true);
227 esd = 0;
228 fFirstEventSeen = true;
229 return esd;
28b4012a 230 }
231
232 // Check for existence and get secondary map
52047b6f 233 AliCentralCorrSecondaryMap* secMap = GetManager().GetSecMap();
52047b6f 234 const TAxis& vaxis = secMap->GetVertexAxis();
235
9ecab72f 236 FindEtaLimits();
237
28b4012a 238 fNClusterTracklet = new TH2D("nClusterVsnTracklet",
9ecab72f 239 "Total number of cluster vs number of tracklets",
2b556440 240 100, 0, 10000, 100, 0, 10000);
28b4012a 241 fNClusterTracklet->SetDirectory(0);
242 fNClusterTracklet->SetXTitle("# of free clusters");
243 fNClusterTracklet->SetYTitle("# of tracklets");
244 fNClusterTracklet->SetStats(0);
245 fList->Add(fNClusterTracklet);
246
247 Int_t nEta = 80;
248 Double_t lEta = 2;
249 fClusterPerTracklet = new TH2D("clusterPerTracklet",
250 "N_{free cluster}/N_{tracklet} vs. #eta",
251 nEta,-lEta,lEta, 101, -.05, 10.05);
252 fClusterPerTracklet->SetDirectory(0);
253 fClusterPerTracklet->SetXTitle("#eta");
254 fClusterPerTracklet->SetYTitle("N_{free cluster}/N_{tracklet}");
255 fClusterPerTracklet->SetStats(0);
256 fList->Add(fClusterPerTracklet);
257
258 // Cache histograms
259 fNCluster = new TH1D("cacheCluster", "", nEta,-lEta,lEta);
260 fNCluster->SetDirectory(0);
261 fNCluster->Sumw2();
262
263 fNTracklet = new TH1D("cacheTracklet", "", nEta,-lEta,lEta);
264 fNTracklet->SetDirectory(0);
265 fNTracklet->Sumw2();
266
267 // Initialize the inspecto
52047b6f 268 fInspector.Init(vaxis);
52047b6f 269 fFirstEventSeen = kTRUE;
28b4012a 270
271 // Print some information
52047b6f 272 Print();
273
274 return esd;
6f791cc3 275}
52047b6f 276//____________________________________________________________________
277void
278AliCentralMultiplicityTask::MarkEventForStore() const
279{
280 // Make sure the AOD tree is filled
6ab100ec 281 DGUARD(fDebug,1,"Mark AOD event for store in AliCentralMultiplicityTask");
52047b6f 282 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
283 AliAODHandler* ah =
284 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
285 if (!ah)
286 AliFatal("No AOD output handler set in analysis manager");
287
288 ah->SetFillAOD(kTRUE);
289}
290
9ecab72f 291//____________________________________________________________________
292void AliCentralMultiplicityTask::FindEtaLimits()
293{
6ab100ec 294 // Find our pseudo-rapidity limits
295 //
296 // Uses the secondary map to do so.
297 DGUARD(fDebug,1,"Find eta limits in AliCentralMultiplicityTask");
9ecab72f 298 AliCentralCorrSecondaryMap* secMap = GetManager().GetSecMap();
4bcdcbc1 299
9ecab72f 300 const TAxis& vaxis = secMap->GetVertexAxis();
614f9452 301
9ecab72f 302 fEtaMin.Set(vaxis.GetNbins());
303 fEtaMax.Set(vaxis.GetNbins());
614f9452 304
305 TList* hits = new TList;
306 hits->SetOwner();
307 hits->SetName("hitMaps");
308 fList->Add(hits);
309
9ecab72f 310 TList* secs = new TList;
311 secs->SetOwner();
312 secs->SetName("secondaryMaps");
313 fList->Add(secs);
6ab100ec 314 unsigned short s = 1;
614f9452 315 TH2D* hCoverage = new TH2D("coverage", "#eta coverage per v_{z}",
6ab100ec 316 secMap->GetCorrection(s)->GetXaxis()->GetNbins(),
317 secMap->GetCorrection(s)->GetXaxis()->GetXmin(),
318 secMap->GetCorrection(s)->GetXaxis()->GetXmax(),
614f9452 319 vaxis.GetNbins(),vaxis.GetXmin(),vaxis.GetXmax());
320 hCoverage->SetDirectory(0);
321 hCoverage->SetXTitle("#eta");
322 hCoverage->SetYTitle("v_{z} [cm]");
323 hCoverage->SetZTitle("n_{bins}");
324 fList->Add(hCoverage);
9ecab72f 325
326 for (Int_t v = 1; v <= vaxis.GetNbins(); v++) {
327 TH2D* corr = secMap->GetCorrection(UShort_t(v));
328 TH1D* proj = corr->ProjectionX(Form("secCor%02d", v));
329 proj->Scale(1. / corr->GetNbinsY());
330 proj->SetTitle(Form("Projection of secondary correction "
331 "for %+5.1f<v_{z}<%+5.1f",
332 vaxis.GetBinLowEdge(v), vaxis.GetBinUpEdge(v)));
333 proj->SetYTitle("#LT 2^{nd} correction#GT");
334 proj->SetDirectory(0);
335 proj->SetMarkerStyle(20);
336 proj->SetMarkerColor(kBlue+1);
337 secs->Add(proj);
614f9452 338
339 TH2D* obg = static_cast<TH2D*>(corr->Clone(Form("secCor2DFiducial%02d",v)));
340 obg->SetDirectory(0);
341 secs->Add(obg);
342
9ecab72f 343 TH1D* after = static_cast<TH1D*>(proj->Clone(Form("secCorFiducial%02d",v)));
344 after->SetDirectory(0);
345 after->SetMarkerColor(kRed+1);
346 secs->Add(after);
614f9452 347
348 TH2D* data = static_cast<TH2D*>(corr->Clone(Form("hitMap%02d",v)));
349 //d->SetTitle(Form("hitMap%02d",v));
350 data->SetTitle(Form("d^{2}N/d#eta d#phi "
351 "for %+5.1f<v_{z}<%+5.1f",
352 vaxis.GetBinLowEdge(v), vaxis.GetBinUpEdge(v)));
353 data->GetZaxis()->SetTitle("");
354 data->SetMarkerColor(kBlack);
355 data->SetMarkerStyle(1);
356 hits->Add(data);
357
358 TH1D* hAcceptance = fManager.GetAcceptanceCorrection(v);
359 TH1D* accClone = static_cast<TH1D*>(hAcceptance->Clone(Form("acceptance%02d",v)));
360 secs->Add(accClone);
361
b4db5d3b 362 // Double_t prev = 0;
9ecab72f 363 for (Int_t e = 1; e <= proj->GetNbinsX(); e++) {
364 Double_t c = proj->GetBinContent(e);
614f9452 365 if (c > .5 /*&& TMath::Abs(c - prev) < .1*c*/) {
9ecab72f 366 fEtaMin[v-1] = e;
367 break;
368 }
b4db5d3b 369 // prev = c;
9ecab72f 370 after->SetBinContent(e, 0);
371 after->SetBinError(e, 0);
c6523308 372 for(Int_t nn =1; nn <=obg->GetNbinsY();nn++)
373 obg->SetBinContent(e,nn,0);
374
9ecab72f 375 }
376 for (Int_t e = proj->GetNbinsX(); e >= 1; e--) {
377 Double_t c = proj->GetBinContent(e);
614f9452 378 if (c > .5 /*&& TMath::Abs(c - prev) < .1*c*/) {
9ecab72f 379 fEtaMax[v-1] = e;
380 break;
381 }
b4db5d3b 382 // prev = c;
9ecab72f 383 after->SetBinContent(e, 0);
384 after->SetBinError(e, 0);
c6523308 385 for(Int_t nn =1; nn <=obg->GetNbinsY();nn++)
386 obg->SetBinContent(e,nn,0);
387
9ecab72f 388 }
614f9452 389
390 for (Int_t nn = fEtaMin[v-1]; nn<=fEtaMax[v-1]; nn++) {
391 hCoverage->SetBinContent(nn,v,1);
392 }
393
9ecab72f 394 }
395}
396
6f791cc3 397//____________________________________________________________________
3e478dba 398void AliCentralMultiplicityTask::UserExec(Option_t* /*option*/)
399{
fb3430ac 400 //
401 // Process each event
402 //
403 // Parameters:
404 // option Not used
405 //
6ab100ec 406 DGUARD(fDebug,1,"Process event in AliCentralMultiplicityTask");
c4a7e081 407 fAODCentral.Clear("");
52047b6f 408 fIvz = 0;
409
410 AliESDEvent* esd = GetESDEvent();
6ff251d8 411 if (!esd) return;
412
52047b6f 413 Bool_t lowFlux = kFALSE;
414 UInt_t triggers = 0;
415 UShort_t ivz = 0;
416 Double_t vz = 0;
417 Double_t cent = -1;
418 UShort_t nClusters = 0;
419 UInt_t found = fInspector.Process(esd, triggers, lowFlux,
420 ivz, vz, cent, nClusters);
421
422 // No event or no trigger
423 if (found & AliFMDEventInspector::kNoEvent) return;
424 if (found & AliFMDEventInspector::kNoTriggers) return;
6f791cc3 425
426 // Make sure AOD is filled
52047b6f 427 MarkEventForStore();
428
429 if (found == AliFMDEventInspector::kNoSPD) return;
430 if (found == AliFMDEventInspector::kNoVertex) return;
431 if (triggers & AliAODForwardMult::kPileUp) return;
432 if (found == AliFMDEventInspector::kBadVertex) return; // Out of range
6f791cc3 433
434 //Doing analysis
52047b6f 435 fIvz = ivz;
6f791cc3 436 const AliMultiplicity* spdmult = esd->GetMultiplicity();
52047b6f 437
438 TH2D& aodHist = fAODCentral.GetHistogram();
439
440 ProcessESD(aodHist, spdmult);
441 CorrectData(aodHist, ivz);
614f9452 442 //Producing hit maps
443 TList* hitList = static_cast<TList*>(fList->FindObject("hitMaps"));
444 TH2D* data = 0;
445 if(hitList)
446 data = static_cast<TH2D*>(hitList->At(ivz-1));
447 if(data)
448 data->Add(&aodHist);
449
52047b6f 450 PostData(1,fList);
451}
452//____________________________________________________________________
453void
454AliCentralMultiplicityTask::ProcessESD(TH2D& aodHist,
455 const AliMultiplicity* spdmult) const
456{
6ab100ec 457 DGUARD(fDebug,1,"Process the ESD in AliCentralMultiplicityTask");
28b4012a 458 fNTracklet->Reset();
459 fNCluster->Reset();
460
6f791cc3 461 //Filling clusters in layer 1 used for tracklets...
28b4012a 462 for(Int_t j = 0; j< spdmult->GetNumberOfTracklets();j++) {
463 Double_t eta = spdmult->GetEta(j);
464 fNTracklet->Fill(eta);
465 aodHist.Fill(eta,spdmult->GetPhi(j));
466 }
3e478dba 467
6f791cc3 468 //...and then the unused ones in layer 1
28b4012a 469 for(Int_t j = 0; j< spdmult->GetNumberOfSingleClusters();j++) {
470 Double_t eta = -TMath::Log(TMath::Tan(spdmult->GetThetaSingle(j)/2.));
471 fNCluster->Fill(eta);
472 aodHist.Fill(eta, spdmult->GetPhiSingle(j));
473 }
474 fNClusterTracklet->Fill(fNCluster->GetEntries(),
475 fNTracklet->GetEntries());
476
477 fNCluster->Divide(fNTracklet);
478 for (Int_t j = 1; j <= fNCluster->GetNbinsX(); j++)
479 fClusterPerTracklet->Fill(fNCluster->GetXaxis()->GetBinCenter(j),
480 fNCluster->GetBinContent(j));
481
52047b6f 482}
483
484//____________________________________________________________________
485void
486AliCentralMultiplicityTask::CorrectData(TH2D& aodHist, UShort_t vtxbin) const
487{
3e478dba 488 // Corrections
6ab100ec 489 DGUARD(fDebug,1,"Correct data in AliCentralMultiplicityTask");
6f791cc3 490 TH1D* hAcceptance = fManager.GetAcceptanceCorrection(vtxbin);
9453b19e 491 TH2D* hSecMap = fManager.GetSecMapCorrection(vtxbin);
12fffad7 492
9453b19e 493 if (!hSecMap) AliFatal("No secondary map!");
494 if (!hAcceptance) AliFatal("No acceptance!");
dbe8d9ed 495
52047b6f 496 if (fUseSecondary && hSecMap) aodHist.Divide(hSecMap);
6f791cc3 497
52047b6f 498 for(Int_t nx = 1; nx <= aodHist.GetNbinsX(); nx++) {
3b2bfb07 499 Float_t accCor = hAcceptance->GetBinContent(nx);
9453b19e 500 Float_t accErr = hAcceptance->GetBinError(nx);
9ecab72f 501
502 Bool_t fiducial = true;
503 if (nx < fEtaMin[vtxbin-1] || nx > fEtaMax[vtxbin-1])
504 fiducial = false;
d7d87bc9 505 // Bool_t etabinSeen = kFALSE;
52047b6f 506 for(Int_t ny = 1; ny <= aodHist.GetNbinsY(); ny++) {
9ecab72f 507#if 1
508 if (!fiducial) {
509 aodHist.SetBinContent(nx, ny, 0);
510 aodHist.SetBinError(nx, ny, 0);
511 continue;
512 }
513#endif
9453b19e 514 // Get currrent value
52047b6f 515 Float_t aodValue = aodHist.GetBinContent(nx,ny);
516 Float_t aodErr = aodHist.GetBinError(nx,ny);
9453b19e 517
9ecab72f 518#if 0 // This is done once in the FindEtaBins function
9453b19e 519 // Set underflow bin
12fffad7 520 Float_t secCor = 0;
52047b6f 521 if(hSecMap) secCor = hSecMap->GetBinContent(nx,ny);
3b2bfb07 522 if (secCor > 0.5) etabinSeen = kTRUE;
9ecab72f 523#endif
52047b6f 524 if (aodValue < 0.000001) {
525 aodHist.SetBinContent(nx,ny, 0);
9ecab72f 526 aodHist.SetBinError(nx,ny, 0);
52047b6f 527 continue;
528 }
9453b19e 529 if (!fUseAcceptance) continue;
530
531 // Acceptance correction
3b2bfb07 532 if (accCor < 0.000001) accCor = 1;
533 Float_t aodNew = aodValue / accCor ;
12fffad7 534 Float_t error = aodNew*TMath::Sqrt(TMath::Power(aodErr/aodValue,2) +
535 TMath::Power(accErr/accCor,2) );
52047b6f 536 aodHist.SetBinContent(nx,ny, aodNew);
12fffad7 537 //test
52047b6f 538 aodHist.SetBinError(nx,ny,error);
539 aodHist.SetBinError(nx,ny,aodErr);
6f791cc3 540 }
541 //Filling underflow bin if we eta bin is in range
9ecab72f 542 if (fiducial) aodHist.SetBinContent(nx,0, 1.);
543 // if (etabinSeen) aodHist.SetBinContent(nx,0, 1.);
6f791cc3 544 }
6f791cc3 545}
52047b6f 546
6f791cc3 547//____________________________________________________________________
3e478dba 548void AliCentralMultiplicityTask::Terminate(Option_t* /*option*/)
549{
fb3430ac 550 //
551 // End of job
552 //
553 // Parameters:
554 // option Not used
555 //
6ab100ec 556 DGUARD(fDebug,1,"Process merged output in AliCentralMultiplicityTask");
6f791cc3 557}
558//____________________________________________________________________
559void
52047b6f 560AliCentralMultiplicityTask::Print(Option_t* option) const
6f791cc3 561{
fb3430ac 562 //
563 // Print information
564 //
565 // Parameters:
566 // option Not used
567 //
52047b6f 568 std::cout << ClassName() << ": " << GetName() << "\n"
569 << std::boolalpha
570 << " Use secondary correction: " << fUseSecondary << '\n'
571 << " Use acceptance correction: " << fUseAcceptance << '\n'
572 << " Off-line trigger mask: 0x"
573 << std::hex << std::setfill('0')
574 << std::setw (8) << fOfflineTriggerMask
575 << std::dec << std::setfill (' ')
576 << std::noboolalpha << std::endl;
9ecab72f 577 AliCentralCorrSecondaryMap* secMap = GetManager().GetSecMap();
578 if (secMap) {
579 const TAxis& vaxis = secMap->GetVertexAxis();
580 std::cout << " Eta ranges:\n"
581 << " Vertex | Eta bins\n"
582 << " bin range | \n"
583 << " ----------------+-----------" << std::endl;
584 for (Int_t v = 1; v <= vaxis.GetNbins(); v++) {
585 std::cout << " " << std::setw(2) << v << " "
586 << std::setw(5) << vaxis.GetBinLowEdge(v) << "-"
587 << std::setw(5) << vaxis.GetBinUpEdge(v) << " | "
588 << std::setw(3) << fEtaMin[v-1] << "-"
589 << std::setw(3) << fEtaMax[v-1] << std::endl;
590 }
591 }
592
52047b6f 593 gROOT->IncreaseDirLevel();
594 fManager.Print(option);
595 fInspector.Print(option);
596 gROOT->DecreaseDirLevel();
597
6f791cc3 598}
3e478dba 599//====================================================================
6f791cc3 600AliCentralMultiplicityTask::Manager::Manager() :
bd6f5206 601 fAcceptancePath("$ALICE_ROOT/PWGLF/FORWARD/corrections/CentralAcceptance"),
602 fSecMapPath("$ALICE_ROOT/PWGLF/FORWARD/corrections/CentralSecMap"),
6f791cc3 603 fAcceptance(),
604 fSecmap(),
605 fAcceptanceName("centralacceptance"),
e58000b7 606 fSecMapName("centralsecmap"),
607 fIsInit(kFALSE)
6f791cc3 608{
fb3430ac 609 //
610 // Constructor
611 //
6f791cc3 612}
613//____________________________________________________________________
3e478dba 614AliCentralMultiplicityTask::Manager::Manager(const Manager& o)
615 :fAcceptancePath(o.fAcceptancePath),
616 fSecMapPath(o.fSecMapPath),
617 fAcceptance(o.fAcceptance),
618 fSecmap(o.fSecmap),
619 fAcceptanceName(o.fAcceptanceName),
e58000b7 620 fSecMapName(o.fSecMapName),
621 fIsInit(o.fIsInit)
fb3430ac 622{
623 //
624 // Copy Constructor
625 //
626}
3e478dba 627//____________________________________________________________________
628AliCentralMultiplicityTask::Manager&
629AliCentralMultiplicityTask::Manager::operator=(const Manager& o)
630{
fb3430ac 631 //
632 // Assignment operator
633 //
d015ecfe 634 if (&o == this) return *this;
3e478dba 635 fAcceptancePath = o.fAcceptancePath;
636 fSecMapPath = o.fSecMapPath;
637 fAcceptance = o.fAcceptance;
638 fSecmap = o.fSecmap;
639 fAcceptanceName = o.fAcceptanceName;
640 fSecMapName = o.fSecMapName;
e58000b7 641 fIsInit = o.fIsInit;
3e478dba 642 return *this;
643}
644
645//____________________________________________________________________
646const char*
647AliCentralMultiplicityTask::Manager::GetFullFileName(UShort_t what,
648 UShort_t sys,
649 UShort_t sNN,
650 Short_t field) const
651{
fb3430ac 652 //
653 // Get full path name to object file
654 //
655 // Parameters:
656 // what What to get
657 // sys Collision system
658 // sNN Center of mass energy
659 // field Magnetic field
660 //
661 // Return:
662 //
663 //
3e478dba 664 return Form("%s/%s",
665 what == 0 ? GetSecMapPath() : GetAcceptancePath(),
666 GetFileName(what, sys, sNN, field));
667}
668
669//____________________________________________________________________
670const char*
671AliCentralMultiplicityTask::Manager::GetFileName(UShort_t what ,
672 UShort_t sys,
673 UShort_t sNN,
674 Short_t field) const
675{
fb3430ac 676 //
677 // Get the full path name
678 //
679 // Parameters:
680 // what What to get
681 // sys Collision system
682 // sNN Center of mass energy
683 // field Magnetic field
684 //
685 // Return:
686 //
687 //
3e478dba 688 // Must be static - otherwise the data may disappear on return from
689 // this member function
690 static TString fname = "";
6f791cc3 691
692 switch(what) {
28b4012a 693 case 0: fname = fSecMapName; break;
694 case 1: fname = fAcceptanceName; break;
6f791cc3 695 default:
3e478dba 696 ::Error("GetFileName",
697 "Invalid indentifier %d for central object, must be 0 or 1!", what);
6f791cc3 698 break;
699 }
28b4012a 700 fname.Append(Form("_%s_%04dGeV_%c%1dkG.root",
6f791cc3 701 AliForwardUtil::CollisionSystemString(sys),
702 sNN, (field < 0 ? 'm' : 'p'), TMath::Abs(field)));
703
704 return fname.Data();
6f791cc3 705}
3e478dba 706
6f791cc3 707//____________________________________________________________________
3e478dba 708TH2D*
709AliCentralMultiplicityTask::Manager::GetSecMapCorrection(UShort_t vtxbin) const
710{
fb3430ac 711 //
712 // Get the secondary map
713 //
714 // Parameters:
715 // vtxbin
716 //
717 // Return:
718 //
719 //
3e478dba 720 if (!fSecmap) {
721 ::Warning("GetSecMapCorrection","No secondary map defined");
722 return 0;
723 }
724 return fSecmap->GetCorrection(vtxbin);
725}
726//____________________________________________________________________
727TH1D*
728AliCentralMultiplicityTask::Manager::GetAcceptanceCorrection(UShort_t vtxbin)
729 const
730{
fb3430ac 731 //
732 // Get the acceptance correction
733 //
734 // Parameters:
735 // vtxbin
736 //
737 // Return:
738 //
739 //
3e478dba 740 if (!fAcceptance) {
741 ::Warning("GetAcceptanceCorrection","No acceptance map defined");
742 return 0;
743 }
744 return fAcceptance->GetCorrection(vtxbin);
745}
746
747//____________________________________________________________________
748void
749AliCentralMultiplicityTask::Manager::Init(UShort_t sys,
750 UShort_t sNN,
751 Short_t field)
752{
fb3430ac 753 //
754 // Initialize
755 //
756 // Parameters:
0151a6c6 757 // sys Collision system (1: pp, 2: PbPb, 3: pPb)
fb3430ac 758 // sNN Center of mass energy per nucleon pair [GeV]
759 // field Magnetic field [kG]
760 //
e58000b7 761 if(fIsInit) ::Warning("Init","Already initialised - overriding...");
762
6f791cc3 763 TFile fsec(GetFullFileName(0,sys,sNN,field));
3e478dba 764 fSecmap =
765 dynamic_cast<AliCentralCorrSecondaryMap*>(fsec.Get(fSecMapName.Data()));
6f791cc3 766 if(!fSecmap) {
3e478dba 767 ::Error("Init", "no central Secondary Map found!") ;
6f791cc3 768 return;
769 }
770 TFile facc(GetFullFileName(1,sys,sNN,field));
3e478dba 771 fAcceptance =
772 dynamic_cast<AliCentralCorrAcceptance*>(facc.Get(fAcceptanceName.Data()));
773 if(!fAcceptance) {
774 ::Error("Init", "no central Acceptance found!") ;
775 return;
776 }
e58000b7 777
778 if(fSecmap && fAcceptance) {
779 fIsInit = kTRUE;
780 ::Info("Init",
52047b6f 781 "Central Manager initialised for %s, energy %dGeV, field %dkG",
0151a6c6 782 sys == 1 ? "pp" : sys == 2 ? "PbPb" : sys == 3 ? "pPb" : "unknown", sNN,field);
52047b6f 783 }
784}
28b4012a 785//____________________________________________________________________
786Bool_t
787AliCentralMultiplicityTask::Manager::WriteFile(UShort_t what,
788 UShort_t sys,
789 UShort_t sNN,
790 Short_t fld,
791 TObject* obj,
792 Bool_t full) const
793{
794 //
795 // Write correction output to (a temporary) file
796 //
797 // Parameters:
798 // What What to write
0151a6c6 799 // sys Collision system (1: pp, 2: PbPb, 3: pPb)
28b4012a 800 // sNN Center of mass energy per nucleon (GeV)
801 // fld Field (kG)
802 // obj Object to write
803 // full if true, write to full path, otherwise locally
804 //
805 // Return:
806 // true on success.
807 TString ofName;
808 if (!full)
809 ofName = GetFileName(what, sys, sNN, fld);
810 else
811 ofName = GetFullFileName(what, sys, sNN, fld);
812 if (ofName.IsNull()) {
813 AliErrorGeneral("Manager",Form("Unknown object type %d", what));
814 return false;
815 }
816 TFile* output = TFile::Open(ofName, "RECREATE");
817 if (!output) {
818 AliErrorGeneral("Manager",Form("Failed to open file %s", ofName.Data()));
819 return false;
820 }
821
822 TString oName(GetObjectName(what));
823 Int_t ret = obj->Write(oName);
824 if (ret <= 0) {
825 AliErrorGeneral("Manager",Form("Failed to write %p to %s/%s (%d)",
826 obj, ofName.Data(), oName.Data(), ret));
827 return false;
828 }
829
830 ret = output->Write();
831 if (ret < 0) {
832 AliErrorGeneral("Manager",
833 Form("Failed to write %s to disk (%d)", ofName.Data(),ret));
834 return false;
835 }
836 output->ls();
837 output->Close();
838
839 TString cName(obj->IsA()->GetName());
840 AliInfoGeneral("Manager",
841 Form("Wrote %s object %s to %s\n",
842 cName.Data(),oName.Data(), ofName.Data()));
843 if (!full) {
844 TString dName(GetFileDir(what));
845 AliInfoGeneral("Manager",
846 Form("%s should be copied to %s\n"
847 "Do for example\n\t"
bd6f5206 848 "aliroot $ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/"
28b4012a 849 "MoveCorrections.C\\(%d\\)\nor\n\t"
850 "cp %s %s/",
851 ofName.Data(),dName.Data(),
852 what, ofName.Data(),
853 gSystem->ExpandPathName(dName.Data())));
854
855
856 }
857 return true;
858}
6f791cc3 859
52047b6f 860//____________________________________________________________________
861void
862AliCentralMultiplicityTask::Manager::Print(Option_t* option) const
863{
28b4012a 864 //
865 // Print information to standard output
866 //
52047b6f 867 std::cout << " AliCentralMultiplicityTask::Manager\n"
868 << std::boolalpha
869 << " Initialized: " << fIsInit << '\n'
870 << " Acceptance path: " << fAcceptancePath << '\n'
871 << " Acceptance name: " << fAcceptanceName << '\n'
872 << " Acceptance: " << fAcceptance << '\n'
873 << " Secondary path: " << fSecMapPath << '\n'
874 << " Secondary name: " << fSecMapName << '\n'
875 << " Secondary map: " << fSecmap
876 << std::noboolalpha << std::endl;
877 if (fAcceptance) fAcceptance->Print(option);
878 if (fSecmap) fSecmap->Print(option);
6f791cc3 879}
52047b6f 880
6f791cc3 881//
882// EOF
883//