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