]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGJE/EMCALJetTasks/AliJetModelBaseTask.cxx
up from salvatore
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliJetModelBaseTask.cxx
CommitLineData
762e8424 1// $Id$
2//
3// Jet modelling task.
4//
297edd60 5// Author: S.Aiola, C.Loizides
762e8424 6
ffe32451 7#include "AliJetModelBaseTask.h"
8
762e8424 9#include <TClonesArray.h>
787a3c4f 10#include <TH1I.h>
762e8424 11#include <TLorentzVector.h>
12#include <TRandom3.h>
b16bb001 13#include <TList.h>
762e8424 14
b16bb001 15#include "AliVEvent.h"
e44e8726 16#include "AliAODCaloCluster.h"
b16bb001 17#include "AliESDCaloCluster.h"
18#include "AliVCluster.h"
762e8424 19#include "AliEMCALDigit.h"
ffe32451 20#include "AliEMCALRecPoint.h"
b16bb001 21#include "AliESDCaloCells.h"
22#include "AliAODCaloCells.h"
787a3c4f 23#include "AliAODMCParticle.h"
b16bb001 24#include "AliVCaloCells.h"
ffe32451 25#include "AliPicoTrack.h"
b16bb001 26#include "AliEMCALGeometry.h"
27#include "AliLog.h"
762e8424 28
29ClassImp(AliJetModelBaseTask)
30
31//________________________________________________________________________
32AliJetModelBaseTask::AliJetModelBaseTask() :
33 AliAnalysisTaskSE("AliJetModelBaseTask"),
34 fGeomName(),
35 fTracksName(),
36 fOutTracksName(),
37 fCaloName(),
38 fOutCaloName(),
b16bb001 39 fCellsName(),
40 fOutCellsName(),
787a3c4f 41 fMCParticlesName(),
42 fOutMCParticlesName(),
762e8424 43 fSuffix(),
44 fEtaMin(-1),
45 fEtaMax(1),
46 fPhiMin(0),
47 fPhiMax(TMath::Pi() * 2),
48 fPtMin(0),
49 fPtMax(0),
50 fCopyArray(kTRUE),
51 fNClusters(0),
b16bb001 52 fNCells(0),
762e8424 53 fNTracks(0),
7f76e479 54 fMarkMC(99999),
e44e8726 55 fPtSpectrum(0),
b16bb001 56 fQAhistos(kFALSE),
ffe32451 57 fIsInit(0),
762e8424 58 fGeom(0),
59 fClusters(0),
60 fOutClusters(0),
61 fTracks(0),
b16bb001 62 fOutTracks(0),
63 fCaloCells(0),
64 fOutCaloCells(0),
65 fAddedCells(0),
787a3c4f 66 fMCParticles(0),
67 fMCParticlesMap(0),
68 fOutMCParticles(0),
69 fOutMCParticlesMap(0),
70 fMCLabelShift(0),
b16bb001 71 fEsdMode(kFALSE),
72 fOutput(0)
762e8424 73{
74 // Default constructor.
75}
76
77//________________________________________________________________________
b16bb001 78AliJetModelBaseTask::AliJetModelBaseTask(const char *name, Bool_t drawqa) :
762e8424 79 AliAnalysisTaskSE(name),
80 fGeomName(""),
81 fTracksName("PicoTracks"),
82 fOutTracksName("PicoTracksEmbedded"),
83 fCaloName("CaloClustersCorr"),
84 fOutCaloName("CaloClustersCorrEmbedded"),
b16bb001 85 fCellsName(""),
86 fOutCellsName(""),
787a3c4f 87 fMCParticlesName(""),
88 fOutMCParticlesName(""),
762e8424 89 fSuffix("Processed"),
90 fEtaMin(-1),
91 fEtaMax(1),
92 fPhiMin(0),
93 fPhiMax(TMath::Pi() * 2),
94 fPtMin(50),
95 fPtMax(60),
96 fCopyArray(kTRUE),
97 fNClusters(0),
b16bb001 98 fNCells(0),
762e8424 99 fNTracks(1),
7f76e479 100 fMarkMC(99999),
e44e8726 101 fPtSpectrum(0),
b16bb001 102 fQAhistos(drawqa),
ffe32451 103 fIsInit(0),
762e8424 104 fGeom(0),
105 fClusters(0),
106 fOutClusters(0),
107 fTracks(0),
b16bb001 108 fOutTracks(0),
109 fCaloCells(0),
110 fOutCaloCells(0),
111 fAddedCells(0),
787a3c4f 112 fMCParticles(0),
113 fMCParticlesMap(0),
114 fOutMCParticles(0),
115 fOutMCParticlesMap(0),
116 fMCLabelShift(0),
b16bb001 117 fEsdMode(kFALSE),
118 fOutput(0)
762e8424 119{
120 // Standard constructor.
b16bb001 121
122 if (fQAhistos) {
123 DefineOutput(1, TList::Class());
124 }
762e8424 125}
126
127//________________________________________________________________________
128AliJetModelBaseTask::~AliJetModelBaseTask()
129{
130 // Destructor
131}
132
b16bb001 133//________________________________________________________________________
134void AliJetModelBaseTask::UserCreateOutputObjects()
135{
136 // Create user output.
137 if (!fQAhistos)
138 return;
139
140 OpenFile(1);
141 fOutput = new TList();
142 fOutput->SetOwner();
143
144 PostData(1, fOutput);
145}
146
762e8424 147//________________________________________________________________________
ffe32451 148void AliJetModelBaseTask::UserExec(Option_t *)
149{
150 // Execute per event.
151
d63c8c07 152 if (!fIsInit)
153 fIsInit = ExecOnce();
154
155 if (!fIsInit)
156 return;
157
158 if (fCopyArray) {
159 if (fOutTracks)
160 fOutTracks->Delete();
161 if (fOutClusters)
162 fOutClusters->Delete();
787a3c4f 163 if (fOutMCParticles)
164 fOutMCParticles->Delete();
b4ffb4d2 165 }
d63c8c07 166
cd6431de 167 AliVCaloCells *tempCaloCells = 0;
168
b16bb001 169 if (fCaloCells) {
170 fAddedCells = 0;
cd6431de 171 if (!fCopyArray) {
172 tempCaloCells = fCaloCells;
173 fCaloCells = static_cast<AliVCaloCells*>(tempCaloCells->Clone(Form("%s_old",fCaloCells->GetName())));
174 }
b16bb001 175 }
176
ffe32451 177 Run();
cd6431de 178
179 if (fCaloCells) {
180 delete fCaloCells;
181 fCaloCells = tempCaloCells;
182 }
ffe32451 183}
184
b16bb001 185//________________________________________________________________________
186Bool_t AliJetModelBaseTask::ExecOnce()
187{
188 // Init task.
189
190 delete gRandom;
191 gRandom = new TRandom3(0);
192
193 fEsdMode = InputEvent()->InheritsFrom("AliESDEvent");
194
195 if (fPtMax < fPtMin) {
196 AliWarning (Form("PtMax (%f) < PtMin (%f), setting PtMax = PtMin = %f", fPtMax, fPtMin, fPtMin));
197 fPtMax = fPtMin;
198 }
199
200 if (fEtaMax < fEtaMin) {
201 AliWarning (Form("EtaMax (%f) < EtaMin (%f), setting EtaMax = EtaMin = %f", fEtaMax, fEtaMin, fEtaMin));
202 fEtaMax = fEtaMin;
203 }
204
205 if (fPhiMax < fPhiMin) {
206 AliWarning (Form("PhiMax (%f) < PhiMin (%f), setting PhiMax = PhiMin = %f", fPhiMax, fPhiMin, fPhiMin));
207 fPhiMax = fPhiMin;
208 }
209
787a3c4f 210 if (!fCellsName.IsNull()) {
b16bb001 211 fCaloCells = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCellsName));
212 if (!fCaloCells) {
787a3c4f 213 AliWarning(Form("%s: Couldn't retrieve calo cells with name %s!", GetName(), fCellsName.Data()));
b16bb001 214 }
787a3c4f 215 else if (!fCaloCells->InheritsFrom("AliVCaloCells")) {
b16bb001 216 AliError(Form("%s: Collection %s does not contain a AliVCaloCells object!", GetName(), fCellsName.Data()));
217 fCaloCells = 0;
218 return kFALSE;
219 }
220
221 if (!fOutCaloCells) {
222 fOutCellsName = fCellsName;
787a3c4f 223 if (fCopyArray)
b16bb001 224 fOutCellsName += fSuffix;
787a3c4f 225 if (fCopyArray || !fCaloCells) {
b16bb001 226 if (fEsdMode)
227 fOutCaloCells = new AliESDCaloCells(fOutCellsName,fOutCellsName);
228 else
229 fOutCaloCells = new AliAODCaloCells(fOutCellsName,fOutCellsName);
230
231 if (InputEvent()->FindListObject(fOutCellsName)) {
232 AliFatal(Form("%s: Collection %s is already present in the event!", GetName(), fOutCellsName.Data()));
233 return kFALSE;
234 }
235 else {
236 InputEvent()->AddObject(fOutCaloCells);
237 }
238 }
239 else {
240 fOutCaloCells = fCaloCells;
241 }
242 }
243 }
244
787a3c4f 245 if (fNTracks > 0 && !fTracksName.IsNull()) {
b16bb001 246 fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
247 if (!fTracks) {
787a3c4f 248 AliWarning(Form("%s: Couldn't retrieve tracks with name %s!", GetName(), fTracksName.Data()));
b16bb001 249 }
787a3c4f 250 else if (!fTracks->GetClass()->GetBaseClass("AliPicoTrack")) {
b16bb001 251 AliError(Form("%s: Collection %s does not contain AliPicoTrack objects!", GetName(), fTracksName.Data()));
252 fTracks = 0;
253 return kFALSE;
254 }
255
256 if (!fOutTracks) {
257 fOutTracksName = fTracksName;
787a3c4f 258 if (fCopyArray)
b16bb001 259 fOutTracksName += fSuffix;
787a3c4f 260 if (fCopyArray || !fTracks) {
261 fOutTracks = new TClonesArray("AliPicoTrack");
b16bb001 262 fOutTracks->SetName(fOutTracksName);
263 if (InputEvent()->FindListObject(fOutTracksName)) {
264 AliFatal(Form("%s: Collection %s is already present in the event!", GetName(), fOutTracksName.Data()));
265 return kFALSE;
266 }
267 else {
268 InputEvent()->AddObject(fOutTracks);
269 }
270 }
271 else {
272 fOutTracks = fTracks;
273 }
274 }
275 }
276
787a3c4f 277 if (fNClusters > 0 && !fCaloName.IsNull()) {
b16bb001 278 fClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
279
280 if (!fClusters) {
787a3c4f 281 AliWarning(Form("%s: Couldn't retrieve clusters with name %s!", GetName(), fCaloName.Data()));
b16bb001 282 }
787a3c4f 283 else if (!fClusters->GetClass()->GetBaseClass("AliVCluster")) {
b16bb001 284 AliError(Form("%s: Collection %s does not contain AliVCluster objects!", GetName(), fCaloName.Data()));
285 fClusters = 0;
286 return kFALSE;
287 }
288
289 if (!fOutClusters) {
290 fOutCaloName = fCaloName;
787a3c4f 291 if (fCopyArray)
b16bb001 292 fOutCaloName += fSuffix;
787a3c4f 293 if (fCopyArray || !fClusters) {
b16bb001 294 fOutClusters = new TClonesArray(fClusters->GetClass()->GetName(), fClusters->GetSize());
295 fOutClusters->SetName(fOutCaloName);
296 if (InputEvent()->FindListObject(fOutCaloName)) {
297 AliFatal(Form("%s: Collection %s is already present in the event!", GetName(), fOutCaloName.Data()));
298 return kFALSE;
299 }
300 else {
301 InputEvent()->AddObject(fOutClusters);
302 }
303 }
304 else {
305 fOutClusters = fClusters;
306 }
307 }
308 }
309
787a3c4f 310 if (!fMCParticlesName.IsNull()) {
311 fMCParticles = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fMCParticlesName));
312 if (!fMCParticles) {
313 AliWarning(Form("%s: Couldn't retrieve MC particles with name %s!", GetName(), fMCParticlesName.Data()));
314 }
315 else {
316 if (!fMCParticles->GetClass()->GetBaseClass("AliAODMCParticle")) {
317 AliError(Form("%s: Collection %s does not contain AliAODMCParticle objects!", GetName(), fMCParticlesName.Data()));
318 fMCParticles = 0;
319 return kFALSE;
320 }
321
322 fMCParticlesMap = dynamic_cast<TH1I*>(InputEvent()->FindListObject(fMCParticlesName + "_Map"));
323
324 if (!fMCParticlesMap) {
325 AliWarning(Form("%s: Could not retrieve map for MC particles %s! Will assume MC labels consistent with indexes...", GetName(), fMCParticlesName.Data()));
326 fMCParticlesMap = new TH1I(fMCParticlesName + "_Map", fMCParticlesName + "_Map",9999,0,1);
327 for (Int_t i = 0; i < 9999; i++) {
328 fMCParticlesMap->SetBinContent(i,i);
329 }
330 }
331 }
332
333 if (!fOutMCParticles) {
334 fOutMCParticlesName = fMCParticlesName;
335 if (fCopyArray)
336 fOutMCParticlesName += fSuffix;
337 if (fCopyArray || !fMCParticles) {
338
339 fOutMCParticles = new TClonesArray("AliAODMCParticle");
340 fOutMCParticles->SetName(fOutMCParticlesName);
341 if (InputEvent()->FindListObject(fOutMCParticlesName)) {
342 AliFatal(Form("%s: Collection %s is already present in the event!", GetName(), fOutMCParticlesName.Data()));
343 return kFALSE;
344 }
345 else {
346 InputEvent()->AddObject(fOutMCParticles);
347 }
348
349 fOutMCParticlesMap = new TH1I(fOutMCParticlesName + "_Map", fOutMCParticlesName + "_Map",9999,0,1);
350 if (InputEvent()->FindListObject(fOutMCParticlesName + "_Map")) {
351 AliFatal(Form("%s: Map %s_Map is already present in the event!", GetName(), fOutMCParticlesName.Data()));
352 return kFALSE;
353 }
354 else {
355 InputEvent()->AddObject(fOutMCParticlesMap);
356 }
357 }
358 else {
359 fOutMCParticles = fMCParticles;
360 fOutMCParticlesMap = fMCParticlesMap;
361 }
362 }
363 }
364
cfc2ac24 365 if (!fCaloName.IsNull() || !fCellsName.IsNull()) {
366 if (!fGeom) {
367 if (fGeomName.Length() > 0) {
368 fGeom = AliEMCALGeometry::GetInstance(fGeomName);
7f76e479 369 if (!fGeom) {
370 AliFatal(Form("Could not get geometry with name %s!", fGeomName.Data()));
371 return kFALSE;
372 }
cfc2ac24 373 } else {
374 fGeom = AliEMCALGeometry::GetInstance();
7f76e479 375 if (!fGeom) {
376 AliFatal("Could not get default geometry!");
377 return kFALSE;
378 }
cfc2ac24 379 }
b16bb001 380 }
b16bb001 381
cfc2ac24 382 const Double_t EmcalMinEta = fGeom->GetArm1EtaMin();
383 const Double_t EmcalMaxEta = fGeom->GetArm1EtaMax();
384 const Double_t EmcalMinPhi = fGeom->GetArm1PhiMin() * TMath::DegToRad();
385 const Double_t EmcalMaxPhi = fGeom->GetArm1PhiMax() * TMath::DegToRad();
386
387 if (fEtaMax > EmcalMaxEta) fEtaMax = EmcalMaxEta;
388 if (fEtaMax < EmcalMinEta) fEtaMax = EmcalMinEta;
389 if (fEtaMin > EmcalMaxEta) fEtaMin = EmcalMaxEta;
390 if (fEtaMin < EmcalMinEta) fEtaMin = EmcalMinEta;
391
392 if (fPhiMax > EmcalMaxPhi) fPhiMax = EmcalMaxPhi;
393 if (fPhiMax < EmcalMinPhi) fPhiMax = EmcalMinPhi;
394 if (fPhiMin > EmcalMaxPhi) fPhiMin = EmcalMaxPhi;
395 if (fPhiMin < EmcalMinPhi) fPhiMin = EmcalMinPhi;
396 }
b16bb001 397
398 return kTRUE;
399}
400
401//________________________________________________________________________
402Int_t AliJetModelBaseTask::SetNumberOfOutCells(Int_t n)
403{
404 if (fOutCaloCells->GetNumberOfCells() < n) {
405 fOutCaloCells->DeleteContainer();
406 fOutCaloCells->CreateContainer(n);
407 }
408 else {
409 fOutCaloCells->SetNumberOfCells(n);
410 }
411
412 fAddedCells = 0;
413
414 return n;
415}
416
417//________________________________________________________________________
418void AliJetModelBaseTask::CopyCells()
419{
787a3c4f 420 if (!fCaloCells)
421 return;
422
b16bb001 423 for (Short_t i = 0; i < fCaloCells->GetNumberOfCells(); i++) {
7f76e479 424 Short_t mclabel = 0;
b16bb001 425 Double_t efrac = 0.;
426 Double_t time = -1;
427 Short_t cellNum = -1;
428 Double_t amp = -1;
429
430 fCaloCells->GetCell(i, cellNum, amp, time, mclabel, efrac);
431 fOutCaloCells->SetCell(i, cellNum, amp, time, mclabel, efrac);
432 }
433
434 fAddedCells = fCaloCells->GetNumberOfCells();
cd6431de 435
7030f36f 436 AliDebug(2, Form("%d cells from the current event", fAddedCells));
b16bb001 437}
438
439//________________________________________________________________________
440Int_t AliJetModelBaseTask::AddCell(Double_t e, Double_t eta, Double_t phi)
441{
442 // Add a cell to the event.
443
444 Int_t absId = 0;
445 if (eta < -100 || phi < 0) {
446 GetRandomCell(eta, phi, absId);
447 }
448 else {
449 fGeom->EtaPhiFromIndex(absId, eta, phi);
450 }
451
452 if (absId == -1) {
453 AliWarning(Form("Unable to embed cell in eta = %f, phi = %f!"
454 " Maybe the eta-phi range is not inside the EMCal acceptance (eta = [%f, %f], phi = [%f, %f])",
455 eta, phi, fEtaMin, fEtaMax, fPhiMin, fPhiMax));
456 return 0;
457 }
458
459 if (e < 0) {
460 Double_t pt = GetRandomPt();
461 TLorentzVector nPart;
462 nPart.SetPtEtaPhiM(pt, eta, phi, 0);
463 e = nPart.E();
464 }
465
466 return AddCell(e, absId);
467}
468
469//________________________________________________________________________
787a3c4f 470Int_t AliJetModelBaseTask::AddCell(Double_t e, Int_t absId, Double_t time, Int_t label)
b16bb001 471{
472 // Add a cell to the event.
473
787a3c4f 474 if (label == 0)
475 label = fMarkMC;
476 else
477 label += fMCLabelShift;
478
479 Bool_t r = fOutCaloCells->SetCell(fAddedCells, absId, e, time, label, 0);
b16bb001 480
481 if (r) {
482 fAddedCells++;
483 return fAddedCells;
484 }
485 else {
486 return 0;
487 }
488}
489
490
ffe32451 491//________________________________________________________________________
787a3c4f 492AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Double_t eta, Double_t phi, Int_t label)
ffe32451 493{
494 // Add a cluster to the event.
495
496 Int_t absId = 0;
497 if (eta < -100 || phi < 0) {
498 GetRandomCell(eta, phi, absId);
499 }
500 else {
501 fGeom->EtaPhiFromIndex(absId, eta, phi);
502 }
503
504 if (absId == -1) {
505 AliWarning(Form("Unable to embed cluster in eta = %f, phi = %f!"
506 " Maybe the eta-phi range is not inside the EMCal acceptance (eta = [%f, %f], phi = [%f, %f])",
507 eta, phi, fEtaMin, fEtaMax, fPhiMin, fPhiMax));
508 return 0;
509 }
510
511 if (e < 0) {
512 Double_t pt = GetRandomPt();
513 TLorentzVector nPart;
514 nPart.SetPtEtaPhiM(pt, eta, phi, 0);
515 e = nPart.E();
516 }
517
787a3c4f 518 return AddCluster(e, absId, label);
ffe32451 519}
520
521//________________________________________________________________________
787a3c4f 522AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Int_t absId, Int_t label)
ffe32451 523{
524 // Add a cluster to the event.
525
526 const Int_t nClusters = fOutClusters->GetEntriesFast();
527
528 TClonesArray digits("AliEMCALDigit", 1);
529
530 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(digits.New(0));
531 digit->SetId(absId);
532 digit->SetIndexInList(0);
533 digit->SetType(AliEMCALDigit::kHG);
534 digit->SetAmplitude(e);
535
536 AliEMCALRecPoint recPoint("");
537 recPoint.AddDigit(*digit, e, kFALSE);
538 recPoint.EvalGlobalPosition(0, &digits);
539
540 TVector3 gpos;
541 recPoint.GetGlobalPosition(gpos);
542 Float_t g[3];
543 gpos.GetXYZ(g);
544
545 AliVCluster *cluster = static_cast<AliVCluster*>(fOutClusters->New(nClusters));
546 cluster->SetType(AliVCluster::kEMCALClusterv1);
547 cluster->SetE(recPoint.GetEnergy());
548 cluster->SetPosition(g);
549 cluster->SetNCells(1);
550 UShort_t shortAbsId = absId;
551 cluster->SetCellsAbsId(&shortAbsId);
552 Double32_t fract = 1;
553 cluster->SetCellsAmplitudeFraction(&fract);
554 cluster->SetID(nClusters);
555 cluster->SetEmcCpvDistance(-1);
ffe32451 556
f660c2d6 557 //MC label
787a3c4f 558 if (label == 0)
559 label = fMarkMC;
560 else
561 label += fMCLabelShift;
562
f660c2d6 563 if (fEsdMode) {
564 AliESDCaloCluster *esdClus = static_cast<AliESDCaloCluster*>(cluster);
787a3c4f 565 TArrayI parents(1, &label);
f660c2d6 566 esdClus->AddLabels(parents);
567 }
568 else {
569 AliAODCaloCluster *aodClus = static_cast<AliAODCaloCluster*>(cluster);
787a3c4f 570 aodClus->SetLabel(&label, 1);
f660c2d6 571 }
572
ffe32451 573 return cluster;
574}
575
576//________________________________________________________________________
787a3c4f 577AliPicoTrack* AliJetModelBaseTask::AddTrack(Double_t pt, Double_t eta, Double_t phi, Byte_t type, Double_t etaemc, Double_t phiemc, Bool_t ise, Int_t label)
ffe32451 578{
579 // Add a track to the event.
580
581 const Int_t nTracks = fOutTracks->GetEntriesFast();
582
583 if (pt < 0)
584 pt = GetRandomPt();
585 if (eta < -100)
586 eta = GetRandomEta();
587 if (phi < 0)
588 phi = GetRandomPhi();
589
787a3c4f 590 if (label == 0)
591 label = fMarkMC;
592 else
593 label += fMCLabelShift;
594
ffe32451 595 AliPicoTrack *track = new ((*fOutTracks)[nTracks]) AliPicoTrack(pt,
596 eta,
597 phi,
b16bb001 598 1,
787a3c4f 599 label,
b16bb001 600 type,
601 etaemc,
602 phiemc,
603 ise);
604
ffe32451 605 return track;
606}
607
787a3c4f 608//________________________________________________________________________
609AliAODMCParticle* AliJetModelBaseTask::AddMCParticle(AliAODMCParticle *part, Int_t origIndex)
610{
611 const Int_t nPart = fOutMCParticles->GetEntriesFast();
612
613 AliAODMCParticle *aodpart = new ((*fOutMCParticles)[nPart]) AliAODMCParticle(*part);
614
615 fOutMCParticlesMap->SetBinContent(origIndex + fMCLabelShift, nPart);
616
617 return aodpart;
618}
619
ffe32451 620//________________________________________________________________________
621void AliJetModelBaseTask::CopyClusters()
622{
623 // Copy all the clusters in the new collection
787a3c4f 624 if (!fClusters)
625 return;
ffe32451 626
ffe32451 627 const Int_t nClusters = fClusters->GetEntriesFast();
56cc432c 628 Int_t nCopiedClusters = 0;
ffe32451 629
b16bb001 630 if (fEsdMode) {
ffe32451 631 for (Int_t i = 0; i < nClusters; ++i) {
632 AliESDCaloCluster *esdcluster = static_cast<AliESDCaloCluster*>(fClusters->At(i));
56cc432c 633 if (!esdcluster || !esdcluster->IsEMCAL())
ffe32451 634 continue;
56cc432c 635 new ((*fOutClusters)[nCopiedClusters]) AliESDCaloCluster(*esdcluster);
636 nCopiedClusters++;
ffe32451 637 }
638 }
639 else {
640 for (Int_t i = 0; i < nClusters; ++i) {
641 AliAODCaloCluster *aodcluster = static_cast<AliAODCaloCluster*>(fClusters->At(i));
56cc432c 642 if (!aodcluster || !aodcluster->IsEMCAL())
ffe32451 643 continue;
56cc432c 644 new ((*fOutClusters)[nCopiedClusters]) AliAODCaloCluster(*aodcluster);
645 nCopiedClusters++;
ffe32451 646 }
647 }
648}
649
650//________________________________________________________________________
651void AliJetModelBaseTask::CopyTracks()
652{
787a3c4f 653 // Copy all the tracks in the new collection
654
655 if (!fTracks)
656 return;
657
ffe32451 658 const Int_t nTracks = fTracks->GetEntriesFast();
56cc432c 659 Int_t nCopiedTracks = 0;
ffe32451 660 for (Int_t i = 0; i < nTracks; ++i) {
661 AliPicoTrack *track = static_cast<AliPicoTrack*>(fTracks->At(i));
662 if (!track)
663 continue;
56cc432c 664 new ((*fOutTracks)[nCopiedTracks]) AliPicoTrack(*track);
665 nCopiedTracks++;
ffe32451 666 }
667}
668
787a3c4f 669//________________________________________________________________________
670void AliJetModelBaseTask::CopyMCParticles()
671{
672 // Copy all the MC particles in the new collection
673
674 if (!fMCParticles)
675 return;
676
677 const Int_t nPart = fMCParticles->GetEntriesFast();
678 Int_t nCopiedPart = 0;
679 for (Int_t i = 0; i < nPart; ++i) {
680 AliAODMCParticle *part = static_cast<AliAODMCParticle*>(fMCParticles->At(i));
681 if (!part)
682 continue;
683 new ((*fOutMCParticles)[nCopiedPart]) AliAODMCParticle(*part);
684
685 nCopiedPart++;
686 }
687
688 if (!fMCParticlesMap)
689 return;
690
691 Int_t shift = 0;
692
693 for (Int_t i = 0; i < fMCParticlesMap->GetNbinsX()+2; i++) {
694 fOutMCParticlesMap->SetBinContent(i, fMCParticlesMap->GetBinContent(i));
695 if (fMCParticlesMap->GetBinContent(i) != 0)
696 shift = i;
697 }
698
699 fMCLabelShift = shift;
700}
701
762e8424 702//________________________________________________________________________
703void AliJetModelBaseTask::GetRandomCell(Double_t &eta, Double_t &phi, Int_t &absId)
704{
acd859a2 705 // Get random cell.
706
762e8424 707 Int_t repeats = 0;
05debff6 708 Double_t rndEta = eta;
709 Double_t rndPhi = phi;
762e8424 710 do {
05debff6 711 if (eta < -100)
712 rndEta = GetRandomEta();
713 if (phi < 0)
714 rndPhi = GetRandomPhi();
715 fGeom->GetAbsCellIdFromEtaPhi(rndEta, rndPhi, absId);
762e8424 716 repeats++;
717 } while (absId == -1 && repeats < 100);
718
719 if (!(absId > -1)) {
720 AliWarning(Form("Could not extract random cluster! Random eta-phi extracted more than 100 times!\n"
721 "eta [%f, %f], phi [%f, %f]\n", fEtaMin, fEtaMax, fPhiMin, fPhiMax));
722 }
05debff6 723 else {
724 eta = rndEta;
725 phi = rndPhi;
726 }
762e8424 727}
728
729//________________________________________________________________________
730Double_t AliJetModelBaseTask::GetRandomEta()
731{
acd859a2 732 // Get random eta.
733
762e8424 734 return gRandom->Rndm() * (fEtaMax - fEtaMin) + fEtaMin;
735}
736
737//________________________________________________________________________
738Double_t AliJetModelBaseTask::GetRandomPhi()
739{
acd859a2 740 // Get random phi.
741
762e8424 742 return gRandom->Rndm() * (fPhiMax - fPhiMin) + fPhiMin;
743}
744
745//________________________________________________________________________
746Double_t AliJetModelBaseTask::GetRandomPt()
747{
acd859a2 748 // Get random pt.
749
e44e8726 750 if (fPtSpectrum)
751 return fPtSpectrum->GetRandom();
752 else
753 return gRandom->Rndm() * (fPtMax - fPtMin) + fPtMin;
762e8424 754}
755
762e8424 756//________________________________________________________________________
757void AliJetModelBaseTask::Run()
758{
acd859a2 759 // Run.
762e8424 760}