]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/AliJetModelBaseTask.cxx
#100552: EMCal MC labels overflow and re-index bug fix (Jiri Kral)
[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   AliVCaloCells *tempCaloCells = 0;
168
169   if (fCaloCells) {
170     fAddedCells = 0;
171     if (!fCopyArray) {
172       tempCaloCells = fCaloCells;
173       fCaloCells = static_cast<AliVCaloCells*>(tempCaloCells->Clone(Form("%s_old",fCaloCells->GetName())));
174     }
175   }
176
177   Run();
178
179   if (fCaloCells) {
180     delete fCaloCells;
181     fCaloCells = tempCaloCells;
182   }
183 }
184
185 //________________________________________________________________________
186 Bool_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
210   if (!fCellsName.IsNull()) {
211     fCaloCells = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCellsName));
212     if (!fCaloCells) {
213       AliWarning(Form("%s: Couldn't retrieve calo cells with name %s!", GetName(), fCellsName.Data()));
214     }
215     else if (!fCaloCells->InheritsFrom("AliVCaloCells")) {
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;
223       if (fCopyArray) 
224         fOutCellsName += fSuffix;
225       if (fCopyArray || !fCaloCells) {
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
245   if (fNTracks > 0 && !fTracksName.IsNull()) {
246     fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
247     if (!fTracks) {
248       AliWarning(Form("%s: Couldn't retrieve tracks with name %s!", GetName(), fTracksName.Data()));
249     }
250     else if (!fTracks->GetClass()->GetBaseClass("AliPicoTrack")) {
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;
258       if (fCopyArray)
259         fOutTracksName += fSuffix;
260       if (fCopyArray || !fTracks) {
261         fOutTracks = new TClonesArray("AliPicoTrack");
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
277   if (fNClusters > 0 && !fCaloName.IsNull()) {
278     fClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
279  
280     if (!fClusters) {
281       AliWarning(Form("%s: Couldn't retrieve clusters with name %s!", GetName(), fCaloName.Data()));
282     }
283     else if (!fClusters->GetClass()->GetBaseClass("AliVCluster")) {
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;
291       if (fCopyArray) 
292         fOutCaloName += fSuffix;
293       if (fCopyArray || !fClusters) {
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
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
365   if (!fCaloName.IsNull() || !fCellsName.IsNull()) {
366     if (!fGeom) {
367       if (fGeomName.Length() > 0) {
368         fGeom = AliEMCALGeometry::GetInstance(fGeomName);
369         if (!fGeom) {
370           AliFatal(Form("Could not get geometry with name %s!", fGeomName.Data()));
371           return kFALSE;
372         }
373       } else {
374         fGeom = AliEMCALGeometry::GetInstance();
375         if (!fGeom) {
376           AliFatal("Could not get default geometry!");
377           return kFALSE;
378         }
379       }
380     }
381   
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   }
397
398   return kTRUE;
399 }
400
401 //________________________________________________________________________
402 Int_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 //________________________________________________________________________
418 void AliJetModelBaseTask::CopyCells()
419 {
420   if (!fCaloCells)
421     return;
422
423   for (Short_t i = 0; i < fCaloCells->GetNumberOfCells(); i++) {
424     Int_t mclabel = 0;
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();
435
436   AliDebug(2, Form("%d cells from the current event", fAddedCells));
437 }
438
439 //________________________________________________________________________
440 Int_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 //________________________________________________________________________
470 Int_t AliJetModelBaseTask::AddCell(Double_t e, Int_t absId, Double_t time, Int_t label)
471 {
472   // Add a cell to the event.
473
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);
480
481   if (r) {
482     fAddedCells++;
483     return fAddedCells;
484   }
485   else {
486     return 0;
487   }
488 }
489
490
491 //________________________________________________________________________
492 AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Double_t eta, Double_t phi, Int_t label)
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
518   return AddCluster(e, absId, label);
519 }
520       
521 //________________________________________________________________________
522 AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Int_t absId, Int_t label)
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);
556
557   //MC label
558   if (label == 0)
559     label = fMarkMC;
560   else
561     label += fMCLabelShift;
562
563   if (fEsdMode) {
564     AliESDCaloCluster *esdClus = static_cast<AliESDCaloCluster*>(cluster);
565     TArrayI parents(1, &label);
566     esdClus->AddLabels(parents); 
567   }
568   else {
569     AliAODCaloCluster *aodClus = static_cast<AliAODCaloCluster*>(cluster);
570     aodClus->SetLabel(&label, 1); 
571   }
572   
573   return cluster;
574 }
575
576 //________________________________________________________________________
577 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)
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
590   if (label == 0)
591     label = fMarkMC;
592   else
593     label += fMCLabelShift;
594
595   AliPicoTrack *track = new ((*fOutTracks)[nTracks]) AliPicoTrack(pt, 
596                                                                   eta, 
597                                                                   phi, 
598                                                                   1,
599                                                                   label,
600                                                                   type, 
601                                                                   etaemc, 
602                                                                   phiemc, 
603                                                                   ise);
604
605   return track;
606 }
607
608 //________________________________________________________________________
609 AliAODMCParticle* 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
620 //________________________________________________________________________
621 void AliJetModelBaseTask::CopyClusters()
622 {
623   // Copy all the clusters in the new collection
624   if (!fClusters)
625     return;
626
627   const Int_t nClusters = fClusters->GetEntriesFast();
628   Int_t nCopiedClusters = 0;
629   
630   if (fEsdMode) {
631     for (Int_t i = 0; i < nClusters; ++i) {
632       AliESDCaloCluster *esdcluster = static_cast<AliESDCaloCluster*>(fClusters->At(i));
633       if (!esdcluster || !esdcluster->IsEMCAL())
634         continue;
635       new ((*fOutClusters)[nCopiedClusters]) AliESDCaloCluster(*esdcluster);
636       nCopiedClusters++;
637     }
638   }
639   else {
640     for (Int_t i = 0; i < nClusters; ++i) {
641       AliAODCaloCluster *aodcluster = static_cast<AliAODCaloCluster*>(fClusters->At(i));
642       if (!aodcluster || !aodcluster->IsEMCAL())
643         continue;
644       new ((*fOutClusters)[nCopiedClusters]) AliAODCaloCluster(*aodcluster);
645       nCopiedClusters++;
646     }
647   }
648 }
649
650 //________________________________________________________________________
651 void AliJetModelBaseTask::CopyTracks()
652 {
653   // Copy all the tracks in the new collection
654
655   if (!fTracks)
656     return;
657
658   const Int_t nTracks = fTracks->GetEntriesFast();
659   Int_t nCopiedTracks = 0;
660   for (Int_t i = 0; i < nTracks; ++i) {
661     AliPicoTrack *track = static_cast<AliPicoTrack*>(fTracks->At(i));
662     if (!track)
663       continue;
664     new ((*fOutTracks)[nCopiedTracks]) AliPicoTrack(*track);
665     nCopiedTracks++;
666   }
667 }
668
669 //________________________________________________________________________
670 void 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
702 //________________________________________________________________________
703 void AliJetModelBaseTask::GetRandomCell(Double_t &eta, Double_t &phi, Int_t &absId)
704 {
705   // Get random cell.
706
707   Int_t repeats = 0;
708   Double_t rndEta = eta;
709   Double_t rndPhi = phi;
710   do {
711     if (eta < -100)
712       rndEta = GetRandomEta();
713     if (phi < 0)
714       rndPhi = GetRandomPhi();
715     fGeom->GetAbsCellIdFromEtaPhi(rndEta, rndPhi, absId);  
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   }
723   else {
724     eta = rndEta;
725     phi = rndPhi;
726   }
727 }
728
729 //________________________________________________________________________
730 Double_t AliJetModelBaseTask::GetRandomEta()
731 {
732   // Get random eta.
733
734   return gRandom->Rndm() * (fEtaMax - fEtaMin) + fEtaMin;
735 }
736
737 //________________________________________________________________________
738 Double_t AliJetModelBaseTask::GetRandomPhi()
739 {
740   // Get random phi.
741
742   return gRandom->Rndm() * (fPhiMax - fPhiMin) + fPhiMin;
743 }
744
745 //________________________________________________________________________
746 Double_t AliJetModelBaseTask::GetRandomPt()
747 {
748   // Get random pt.
749
750   if (fPtSpectrum)
751     return fPtSpectrum->GetRandom();
752   else
753     return gRandom->Rndm() * (fPtMax - fPtMin) + fPtMin;
754 }
755
756 //________________________________________________________________________
757 void AliJetModelBaseTask::Run() 
758 {
759   // Run.
760 }