]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/dNdEta/AliMultiplicityMCSelector.cxx
effc++ warnings corrected
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AliMultiplicityMCSelector.cxx
CommitLineData
43a9a462 1/* $Id$ */
2
3#include "AliMultiplicityMCSelector.h"
4
5#include <TStyle.h>
6#include <TSystem.h>
7#include <TCanvas.h>
8#include <TVector3.h>
9#include <TChain.h>
10#include <TFile.h>
43a9a462 11#include <TH2F.h>
0a173978 12#include <TH3F.h>
43a9a462 13#include <TParticle.h>
447c325d 14#include <TRandom.h>
15#include <TNtuple.h>
a7904bb7 16#include <TObjString.h>
17#include <TF1.h>
43a9a462 18
19#include <AliLog.h>
20#include <AliESD.h>
21#include <AliStack.h>
0a173978 22#include <AliHeader.h>
23#include <AliGenEventHeader.h>
24#include <AliMultiplicity.h>
43a9a462 25
26#include "esdTrackCuts/AliESDtrackCuts.h"
27#include "AliPWG0Helper.h"
0a173978 28#include "dNdEta/AliMultiplicityCorrection.h"
447c325d 29#include "AliCorrection.h"
30#include "AliCorrectionMatrix3D.h"
43a9a462 31
6d81c2de 32#define TPCMEASUREMENT
33//#define ITSMEASUREMENT
cfc19dd5 34
43a9a462 35ClassImp(AliMultiplicityMCSelector)
36
37AliMultiplicityMCSelector::AliMultiplicityMCSelector() :
38 AliSelectorRL(),
0a173978 39 fMultiplicity(0),
447c325d 40 fEsdTrackCuts(0),
41 fSystSkipParticles(kFALSE),
42 fSelectProcessType(0),
a7904bb7 43 fParticleSpecies(0),
44 fPtSpectrum(0)
43a9a462 45{
46 //
47 // Constructor. Initialization of pointers
48 //
447c325d 49
50 for (Int_t i = 0; i<4; i++)
51 fParticleCorrection[i] = 0;
43a9a462 52}
53
54AliMultiplicityMCSelector::~AliMultiplicityMCSelector()
55{
56 //
57 // Destructor
58 //
59
60 // histograms are in the output list and deleted when the output
61 // list is deleted by the TSelector dtor
62}
63
64void AliMultiplicityMCSelector::Begin(TTree* tree)
65{
66 // Begin function
67
68 AliSelectorRL::Begin(tree);
69
70 ReadUserObjects(tree);
71}
72
73void AliMultiplicityMCSelector::ReadUserObjects(TTree* tree)
74{
75 // read the user objects, called from slavebegin and begin
76
77 if (!fEsdTrackCuts && fInput)
78 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("AliESDtrackCuts"));
79
80 if (!fEsdTrackCuts && tree)
81 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("AliESDtrackCuts"));
82
83 if (!fEsdTrackCuts)
84 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from input list.");
6d81c2de 85
86 if (!fPtSpectrum && fInput)
87 fPtSpectrum = dynamic_cast<TH1*> (fInput->FindObject("pt-spectrum"));
88
89 if (!fPtSpectrum && tree)
90 fPtSpectrum = dynamic_cast<TH1*> (tree->GetUserInfo()->FindObject("pt-spectrum"));
43a9a462 91}
92
93void AliMultiplicityMCSelector::SlaveBegin(TTree* tree)
94{
95 // The SlaveBegin() function is called after the Begin() function.
96 // When running with PROOF SlaveBegin() is called on each slave server.
97 // The tree argument is deprecated (on PROOF 0 is passed).
98
99 AliSelector::SlaveBegin(tree);
100
101 ReadUserObjects(tree);
102
0a173978 103 fMultiplicity = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
447c325d 104
105 TString option(GetOption());
106 if (option.Contains("skip-particles"))
107 {
108 fSystSkipParticles = kTRUE;
109 AliInfo("WARNING: Systematic study enabled. Particles will be skipped.");
110 }
111
112 if (option.Contains("particle-efficiency"))
113 for (Int_t i = 0; i<4; i++)
114 fParticleCorrection[i] = new AliCorrection(Form("correction_%d", i), Form("correction_%d", i));
115
116 if (option.Contains("only-process-type-nd"))
117 fSelectProcessType = 1;
118
119 if (option.Contains("only-process-type-sd"))
120 fSelectProcessType = 2;
121
122 if (option.Contains("only-process-type-dd"))
123 fSelectProcessType = 3;
124
125 if (fSelectProcessType != 0)
126 AliInfo(Form("WARNING: Systematic study enabled. Only considering process type %d", fSelectProcessType));
127
a7904bb7 128 if (option.Contains("pt-spectrum-hist"))
129 {
130 TFile* file = TFile::Open("ptspectrum_fit.root");
131 if (file)
132 {
133 TString subStr(option(option.Index("pt-spectrum")+17, 3));
134 TString histName(Form("ptspectrum_%s", subStr.Data()));
135 AliInfo(Form("Pt-Spectrum modification. Using %s.", histName.Data()));
136 fPtSpectrum = (TH1*) file->Get(histName);
137 if (!fPtSpectrum)
138 AliError("Histogram not found");
139 }
140 else
141 AliError("Could not open ptspectrum_fit.root. Pt Spectrum study could not be enabled.");
142
143 if (fPtSpectrum)
144 AliInfo("WARNING: Systematic study enabled. Pt spectrum will be modified");
145 }
146
147 if (option.Contains("pt-spectrum-func"))
148 {
6d81c2de 149 if (fPtSpectrum)
150 {
151 Printf("Using function from input list for systematic p_t study");
152 }
153 else
154 {
155 fPtSpectrum = new TH1F("fPtSpectrum", "fPtSpectrum", 1, 0, 100);
156 fPtSpectrum->SetBinContent(1, 1);
157 }
a7904bb7 158
159 if (fPtSpectrum)
160 AliInfo("WARNING: Systematic study enabled. Pt spectrum will be modified");
161 }
162
447c325d 163 if (option.Contains("particle-species"))
a7904bb7 164 fParticleSpecies = new TNtuple("fParticleSpecies", "fParticleSpecies", "vtx:Pi_True:K_True:p_True:o_True:Pi_Rec:K_Rec:p_Rec:o_Rec:nolabel:doublePrim:doubleCount");
6d81c2de 165
166 // TODO set seed for random generator
0a173978 167}
168
169void AliMultiplicityMCSelector::Init(TTree* tree)
170{
171 // read the user objects
172
173 AliSelectorRL::Init(tree);
174
b477f4f2 175 // enable only the needed branches
176 if (tree)
0a173978 177 {
178 tree->SetBranchStatus("*", 0);
179 tree->SetBranchStatus("fTriggerMask", 1);
180 tree->SetBranchStatus("fSPDVertex*", 1);
dd701109 181
182 #ifdef ITSMEASUREMENT
183 tree->SetBranchStatus("fSPDMult*", 1);
184 #endif
43a9a462 185
cfc19dd5 186 #ifdef TPCMEASUREMENT
187 AliESDtrackCuts::EnableNeededBranches(tree);
6d81c2de 188 tree->SetBranchStatus("fTracks.fLabel", 1);
cfc19dd5 189 #endif
a7904bb7 190
191 tree->SetCacheSize(0);
b477f4f2 192 }
43a9a462 193}
194
195Bool_t AliMultiplicityMCSelector::Process(Long64_t entry)
196{
197 // The Process() function is called for each entry in the tree (or possibly
198 // keyed object in the case of PROOF) to be processed. The entry argument
199 // specifies which entry in the currently loaded tree is to be processed.
200 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
201 // to read either all or the required parts of the data. When processing
202 // keyed objects with PROOF, the object is already loaded and is available
203 // via the fObject pointer.
204 //
205 // This function should contain the "body" of the analysis. It can contain
206 // simple or elaborate selection criteria, run algorithms on the data
207 // of the event and typically fill histograms.
208
209 // WARNING when a selector is used with a TChain, you must use
210 // the pointer to the current TTree to call GetEntry(entry).
211 // The entry is always the local entry number in the current tree.
212 // Assuming that fTree is the pointer to the TChain being processed,
213 // use fTree->GetTree()->GetEntry(entry).
214
215 if (AliSelectorRL::Process(entry) == kFALSE)
216 return kFALSE;
217
218 // Check prerequisites
219 if (!fESD)
220 {
221 AliDebug(AliLog::kError, "ESD branch not available");
222 return kFALSE;
223 }
224
225 if (!fEsdTrackCuts)
226 {
227 AliDebug(AliLog::kError, "fESDTrackCuts not available");
228 return kFALSE;
229 }
230
0a173978 231 AliHeader* header = GetHeader();
232 if (!header)
233 {
234 AliDebug(AliLog::kError, "Header not available");
235 return kFALSE;
236 }
237
43a9a462 238 AliStack* stack = GetStack();
239 if (!stack)
240 {
241 AliDebug(AliLog::kError, "Stack not available");
242 return kFALSE;
243 }
244
447c325d 245 if (fSelectProcessType > 0)
246 {
247 // getting process information; NB: this only works for Pythia
0f67a57c 248 Int_t processtype = AliPWG0Helper::GetPythiaEventProcessType(header);
447c325d 249
250 Bool_t processEvent = kFALSE;
251
252 // non diffractive
253 if (fSelectProcessType == 1 && processtype !=92 && processtype !=93 && processtype != 94)
254 processEvent = kTRUE;
255
256 // single diffractive
257 if (fSelectProcessType == 2 && (processtype == 92 || processtype == 93))
258 processEvent = kTRUE;
259
260 // double diffractive
261 if (fSelectProcessType == 3 && processtype == 94)
262 processEvent = kTRUE;
263
264 if (!processEvent)
265 {
266 AliDebug(AliLog::kDebug, Form("Skipping this event, because it is not of the requested process type (%d)", processtype));
267 return kTRUE;
268 }
269 }
270
cfc19dd5 271 Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD);
447c325d 272 eventTriggered = kTRUE; // no generated trigger for the simulated events
cfc19dd5 273 Bool_t eventVertex = AliPWG0Helper::IsVertexReconstructed(fESD);
43a9a462 274
0a173978 275 // get the ESD vertex
276 const AliESDVertex* vtxESD = fESD->GetVertex();
277 Double_t vtx[3];
278 vtxESD->GetXYZ(vtx);
279
280 // get the MC vertex
281 AliGenEventHeader* genHeader = header->GenEventHeader();
282 TArrayF vtxMC(3);
283 genHeader->PrimaryVertex(vtxMC);
284
285 // get tracklets
286 const AliMultiplicity* mult = fESD->GetMultiplicity();
287 if (!mult)
288 {
289 AliDebug(AliLog::kError, "AliMultiplicity not available");
290 return kFALSE;
291 }
43a9a462 292
0a173978 293 //const Float_t kPtCut = 0.3;
43a9a462 294
295 // get number of tracks from MC
296 // loop over mc particles
297 Int_t nPrim = stack->GetNprimary();
a7904bb7 298 Int_t nMCPart = stack->GetNtrack();
0a173978 299
300 // tracks in different eta ranges
301 Int_t nMCTracks05 = 0;
6d81c2de 302 Int_t nMCTracks09 = 0;
0a173978 303 Int_t nMCTracks15 = 0;
304 Int_t nMCTracks20 = 0;
305 Int_t nMCTracksAll = 0;
306
447c325d 307 // tracks per particle species, in |eta| < 2 (systematic study)
308 Int_t nMCTracksSpecies[4]; // (pi, K, p, other)
309 for (Int_t i = 0; i<4; ++i)
310 nMCTracksSpecies[i] = 0;
6d81c2de 311 // eta range for nMCTracksSpecies, nESDTracksSpecies
312#ifdef ITSMEASUREMENT
313 const Float_t etaRange = 2.0;
314#else
315 const Float_t etaRange = 0.9;
316#endif
447c325d 317
43a9a462 318 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
319 {
320 AliDebug(AliLog::kDebug+1, Form("MC Loop: Processing particle %d.", iMc));
321
322 TParticle* particle = stack->Particle(iMc);
323
324 if (!particle)
325 {
326 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
327 continue;
328 }
329
447c325d 330 Bool_t debug = kFALSE;
331 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim, debug) == kFALSE)
332 {
333 //printf("%d) DROPPED ", iMC);
334 //particle->Print();
43a9a462 335 continue;
447c325d 336 }
337
338 //printf("%d) OK ", iMC);
339 //particle->Print();
43a9a462 340
0a173978 341 //if (particle->Pt() < kPtCut)
342 // continue;
43a9a462 343
a7904bb7 344 Int_t particleWeight = 1;
345
346 Float_t pt = particle->Pt();
347
348 // in case of systematic study, weight according to the change of the pt spectrum
349 // it cannot be just multiplied because we cannot count "half of a particle"
6d81c2de 350 // instead a random generator decides if the particle is counted twice (if value > 1)
a7904bb7 351 // or not (if value < 0)
6d81c2de 352 if (fPtSpectrum)
a7904bb7 353 {
354 Int_t bin = fPtSpectrum->FindBin(pt);
355 if (bin > 0 && bin <= fPtSpectrum->GetNbinsX())
356 {
6d81c2de 357 Float_t factor = fPtSpectrum->GetBinContent(bin);
358 if (factor > 0)
359 {
360 Float_t random = gRandom->Uniform();
361 if (factor > 1 && random < factor - 1)
362 {
363 particleWeight = 2;
364 }
365 else if (factor < 1 && random < 1 - factor)
366 particleWeight = 0;
367 }
a7904bb7 368 }
369 }
370
371 //Printf("MC weight is: %d", particleWeight);
372
0a173978 373 if (TMath::Abs(particle->Eta()) < 0.5)
a7904bb7 374 nMCTracks05 += particleWeight;
43a9a462 375
6d81c2de 376 if (TMath::Abs(particle->Eta()) < 0.9)
377 nMCTracks09 += particleWeight;
0a173978 378
379 if (TMath::Abs(particle->Eta()) < 1.5)
a7904bb7 380 nMCTracks15 += particleWeight;
0a173978 381
382 if (TMath::Abs(particle->Eta()) < 2.0)
a7904bb7 383 nMCTracks20 += particleWeight;
0a173978 384
a7904bb7 385 nMCTracksAll += particleWeight;
447c325d 386
9521d7a0 387 if (fParticleCorrection[0] || fParticleSpecies)
447c325d 388 {
9521d7a0 389 Int_t id = -1;
390 switch (TMath::Abs(particle->GetPdgCode()))
391 {
392 case 211: id = 0; break;
393 case 321: id = 1; break;
394 case 2212: id = 2; break;
395 default: id = 3; break;
396 }
6d81c2de 397 if (TMath::Abs(particle->Eta()) < etaRange)
9521d7a0 398 nMCTracksSpecies[id]++;
399 if (fParticleCorrection[id])
400 fParticleCorrection[id]->GetTrackCorrection()->FillGene(vtxMC[2], particle->Eta(), particle->Pt());
447c325d 401 }
43a9a462 402 }// end of mc particle
403
6d81c2de 404 fMultiplicity->FillGenerated(vtxMC[2], eventTriggered, eventVertex, (Int_t) nMCTracks05, (Int_t) nMCTracks09, (Int_t) nMCTracks15, (Int_t) nMCTracks20, (Int_t) nMCTracksAll);
cfc19dd5 405
406 if (!eventTriggered || !eventVertex)
407 return kTRUE;
0a173978 408
409 Int_t nESDTracks05 = 0;
6d81c2de 410 Int_t nESDTracks09 = 0;
0a173978 411 Int_t nESDTracks15 = 0;
412 Int_t nESDTracks20 = 0;
413
447c325d 414 // tracks per particle species, in |eta| < 2 (systematic study)
a7904bb7 415 Int_t nESDTracksSpecies[7]; // (pi, K, p, other, nolabel, doublecount_prim, doublecount_all)
416 for (Int_t i = 0; i<7; ++i)
447c325d 417 nESDTracksSpecies[i] = 0;
418
a7904bb7 419 Bool_t* foundPrimaries = new Bool_t[nPrim]; // to prevent double counting
420 for (Int_t i=0; i<nPrim; i++)
421 foundPrimaries[i] = kFALSE;
422
6d81c2de 423 Bool_t* foundTracks = new Bool_t[nMCPart]; // to prevent double counting
a7904bb7 424 for (Int_t i=0; i<nMCPart; i++)
425 foundTracks[i] = kFALSE;
426
cfc19dd5 427#ifdef ITSMEASUREMENT
0a173978 428 // get multiplicity from ITS tracklets
429 for (Int_t i=0; i<mult->GetNumberOfTracklets(); ++i)
430 {
431 //printf("%d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), mult->GetDeltaPhi(i));
432
a7904bb7 433 // This removes non-tracklets in PDC06 data. Very bad solution. New solution is implemented for newer data. Keeping this for compatibility.
0a173978 434 if (mult->GetDeltaPhi(i) < -1000)
435 continue;
436
447c325d 437 // systematic study: 10% lower efficiency
a7904bb7 438 if (fSystSkipParticles && (gRandom->Uniform() < 0.1))
447c325d 439 continue;
440
0a173978 441 Float_t theta = mult->GetTheta(i);
442 Float_t eta = -TMath::Log(TMath::Tan(theta/2.));
6d81c2de 443
444 // TODO define needed, because this only works with new AliRoot
445 Int_t label = mult->GetLabel(i);
cfc19dd5 446#endif
cfc19dd5 447#ifdef TPCMEASUREMENT
0a173978 448 // get multiplicity from ESD tracks
cfc19dd5 449 TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD);
0a173978 450 Int_t nGoodTracks = list->GetEntries();
451 // loop over esd tracks
452 for (Int_t i=0; i<nGoodTracks; i++)
453 {
454 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
455 if (!esdTrack)
456 {
457 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
458 continue;
459 }
460
461 Double_t p[3];
6d81c2de 462 esdTrack->GetConstrainedPxPyPz(p);
0a173978 463 TVector3 vector(p);
464
465 Float_t theta = vector.Theta();
466 Float_t eta = -TMath::Log(TMath::Tan(theta/2.));
0a173978 467
6d81c2de 468 Int_t label = esdTrack->GetLabel();
469
470 //Float_t pt = vector.Pt();
cfc19dd5 471 //if (pt < kPtCut)
472 // continue;
a7904bb7 473#endif
474
475 Int_t particleWeight = 1;
476
477 // in case of systematic study, weight according to the change of the pt spectrum
478 if (fPtSpectrum)
479 {
480 TParticle* mother = 0;
481
6d81c2de 482 // preserve label for later
483 Int_t labelCopy = label;
484 if (labelCopy >= 0)
0f67a57c 485 labelCopy = AliPWG0Helper::FindPrimaryMotherLabel(stack, labelCopy);
6d81c2de 486 if (labelCopy >= 0)
487 mother = stack->Particle(labelCopy);
a7904bb7 488
6d81c2de 489 // in case of pt study we do not count particles w/o label, because they cannot be scaled
a7904bb7 490 if (!mother)
6d81c2de 491 continue;
a7904bb7 492
493 // it cannot be just multiplied because we cannot count "half of a particle"
494 // instead a random generator decides if the particle is counted twice (if value > 1)
495 // or not (if value < 0)
496 Int_t bin = fPtSpectrum->FindBin(mother->Pt());
497 if (bin > 0 && bin <= fPtSpectrum->GetNbinsX())
498 {
6d81c2de 499 Float_t factor = fPtSpectrum->GetBinContent(bin);
500 if (factor > 0)
501 {
502 Float_t random = gRandom->Uniform();
503 if (factor > 1 && random < factor - 1)
504 {
505 particleWeight = 2;
506 }
507 else if (factor < 1 && random < 1 - factor)
508 particleWeight = 0;
509 }
a7904bb7 510 }
511 }
512
513 //Printf("ESD weight is: %d", particleWeight);
0a173978 514
515 if (TMath::Abs(eta) < 0.5)
a7904bb7 516 nESDTracks05 += particleWeight;
43a9a462 517
6d81c2de 518 if (TMath::Abs(eta) < 0.9)
519 nESDTracks09 += particleWeight;
0a173978 520
521 if (TMath::Abs(eta) < 1.5)
a7904bb7 522 nESDTracks15 += particleWeight;
0a173978 523
524 if (TMath::Abs(eta) < 2.0)
a7904bb7 525 nESDTracks20 += particleWeight;
447c325d 526
6d81c2de 527
9521d7a0 528 if (fParticleCorrection[0] || fParticleSpecies)
447c325d 529 {
6d81c2de 530 Int_t motherLabel = -1;
a7904bb7 531 TParticle* mother = 0;
532
533 // find mother
534 if (label >= 0)
0f67a57c 535 motherLabel = AliPWG0Helper::FindPrimaryMotherLabel(stack, label);
6d81c2de 536 if (motherLabel >= 0)
537 mother = stack->Particle(motherLabel);
9521d7a0 538
539 if (!mother)
a7904bb7 540 {
6d81c2de 541 // count tracks that did not have a label
542 if (TMath::Abs(eta) < etaRange)
543 nESDTracksSpecies[4]++;
9521d7a0 544 continue;
a7904bb7 545 }
9521d7a0 546
6d81c2de 547 // get particle type (pion, proton, kaon, other)
9521d7a0 548 Int_t id = -1;
549 switch (TMath::Abs(mother->GetPdgCode()))
550 {
551 case 211: id = 0; break;
552 case 321: id = 1; break;
553 case 2212: id = 2; break;
554 default: id = 3; break;
555 }
6d81c2de 556
557 // double counting is ok for particle ratio study
558 if (TMath::Abs(eta) < etaRange)
9521d7a0 559 nESDTracksSpecies[id]++;
6d81c2de 560
561 // double counting is not ok for efficiency study
562
563 // check if we already counted this particle, this way distinguishes double counted particles (bug/artefact in tracking) or double counted primaries due to secondaries (physics)
564 if (foundTracks[label])
565 {
566 if (TMath::Abs(eta) < etaRange)
567 nESDTracksSpecies[6]++;
568 continue;
569 }
570 foundTracks[label] = kTRUE;
571
572 // particle (primary) already counted?
573 if (foundPrimaries[motherLabel])
574 {
575 if (TMath::Abs(eta) < etaRange)
576 nESDTracksSpecies[5]++;
577 continue;
578 }
579 foundPrimaries[motherLabel] = kTRUE;
580
9521d7a0 581 if (fParticleCorrection[id])
582 fParticleCorrection[id]->GetTrackCorrection()->FillMeas(vtxMC[2], mother->Eta(), mother->Pt());
447c325d 583 }
cfc19dd5 584 }
0a173978 585
a7904bb7 586 delete[] foundTracks;
587 delete[] foundPrimaries;
588
589 if ((Int_t) nMCTracks20 == 0 && nESDTracks20 > 3)
6d81c2de 590 printf("WARNING: Event %lld has %d generated and %d reconstructed...\n", entry, nMCTracks20, nESDTracks20);
a7904bb7 591
592 //printf("%.2f generated and %.2f reconstructed\n", nMCTracks20, nESDTracks20);
447c325d 593
6d81c2de 594 //Printf("%f %f %f %f %f %f %f %f %f %f", vtxMC[2], nMCTracks05, nMCTracks09, nMCTracks15, nMCTracks20, nMCTracksAll, nESDTracks05, nESDTracks09, nESDTracks15, nESDTracks20);
a7904bb7 595
6d81c2de 596 //Printf("%f %f %f %f %f %f %f %f %f %f", vtxMC[2], nMCTracks05, nMCTracks09, nMCTracks15, nMCTracks20, nMCTracksAll, nESDTracks05, nESDTracks09, nESDTracks15, nESDTracks20);
a7904bb7 597
6d81c2de 598 fMultiplicity->FillMeasured(vtx[2], nESDTracks05, nESDTracks09, nESDTracks15, nESDTracks20);
0a173978 599
9521d7a0 600 // fill response matrix using vtxMC (best guess)
6d81c2de 601 fMultiplicity->FillCorrection(vtxMC[2], nMCTracks05, nMCTracks09, nMCTracks15, nMCTracks20, nMCTracksAll, nESDTracks05, nESDTracks09, nESDTracks15, nESDTracks20);
43a9a462 602
447c325d 603 if (fParticleSpecies)
a7904bb7 604 fParticleSpecies->Fill(vtxMC[2], nMCTracksSpecies[0], nMCTracksSpecies[1], nMCTracksSpecies[2], nMCTracksSpecies[3], nESDTracksSpecies[0], nESDTracksSpecies[1], nESDTracksSpecies[2], nESDTracksSpecies[3], nESDTracksSpecies[4], nESDTracksSpecies[5], nESDTracksSpecies[6]);
605
606 //Printf("%d = %d %d %d %d %d %d %d", (Int_t) nESDTracks20, nESDTracksSpecies[0], nESDTracksSpecies[1], nESDTracksSpecies[2], nESDTracksSpecies[3], nESDTracksSpecies[4], nESDTracksSpecies[5], nESDTracksSpecies[6]);
447c325d 607
43a9a462 608 return kTRUE;
609}
610
611void AliMultiplicityMCSelector::SlaveTerminate()
612{
613 // The SlaveTerminate() function is called after all entries or objects
614 // have been processed. When running with PROOF SlaveTerminate() is called
615 // on each slave server.
616
617 AliSelector::SlaveTerminate();
618
619 // Add the histograms to the output on each slave server
620 if (!fOutput)
621 {
622 AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
623 return;
624 }
625
0a173978 626 fOutput->Add(fMultiplicity);
447c325d 627 for (Int_t i = 0; i < 4; ++i)
628 fOutput->Add(fParticleCorrection[i]);
629
630 fOutput->Add(fParticleSpecies);
43a9a462 631}
632
633void AliMultiplicityMCSelector::Terminate()
634{
635 // The Terminate() function is the last function to be called during
636 // a query. It always runs on the client, it can be used to present
637 // the results graphically or save the results to file.
638
639 AliSelector::Terminate();
640
0a173978 641 fMultiplicity = dynamic_cast<AliMultiplicityCorrection*> (fOutput->FindObject("Multiplicity"));
447c325d 642 for (Int_t i = 0; i < 4; ++i)
643 fParticleCorrection[i] = dynamic_cast<AliCorrection*> (fOutput->FindObject(Form("correction_%d", i)));
644 fParticleSpecies = dynamic_cast<TNtuple*> (fOutput->FindObject("fParticleSpecies"));
43a9a462 645
0a173978 646 if (!fMultiplicity)
43a9a462 647 {
0a173978 648 AliDebug(AliLog::kError, Form("ERROR: Histograms not available %p", (void*) fMultiplicity));
43a9a462 649 return;
650 }
651
f31d5d49 652 TFile* file = TFile::Open("multiplicityMC.root", "RECREATE");
43a9a462 653
0a173978 654 fMultiplicity->SaveHistograms();
447c325d 655 for (Int_t i = 0; i < 4; ++i)
656 if (fParticleCorrection[i])
657 fParticleCorrection[i]->SaveHistograms();
a7904bb7 658 if (fParticleSpecies)
659 fParticleSpecies->Write();
660
661 TObjString option(GetOption());
662 option.Write();
43a9a462 663
664 file->Close();
0a173978 665
a7904bb7 666 //fMultiplicity->DrawHistograms();
43a9a462 667}