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