+void AliJetModelBaseTask::UserExec(Option_t *)
+{
+ // Execute per event.
+
+ if (!fIsInit)
+ ExecOnce();
+ Run();
+}
+
+//________________________________________________________________________
+AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Double_t eta, Double_t phi)
+{
+ // Add a cluster to the event.
+
+ Int_t absId = 0;
+ if (eta < -100 || phi < 0) {
+ GetRandomCell(eta, phi, absId);
+ }
+ else {
+ fGeom->EtaPhiFromIndex(absId, eta, phi);
+ }
+
+ if (absId == -1) {
+ AliWarning(Form("Unable to embed cluster in eta = %f, phi = %f!"
+ " Maybe the eta-phi range is not inside the EMCal acceptance (eta = [%f, %f], phi = [%f, %f])",
+ eta, phi, fEtaMin, fEtaMax, fPhiMin, fPhiMax));
+ return 0;
+ }
+
+ if (e < 0) {
+ Double_t pt = GetRandomPt();
+ TLorentzVector nPart;
+ nPart.SetPtEtaPhiM(pt, eta, phi, 0);
+ e = nPart.E();
+ }
+
+ return AddCluster(e, absId);
+}
+
+//________________________________________________________________________
+AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Int_t absId)
+{
+ // Add a cluster to the event.
+
+ const Int_t nClusters = fOutClusters->GetEntriesFast();
+
+ TClonesArray digits("AliEMCALDigit", 1);
+
+ AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(digits.New(0));
+ digit->SetId(absId);
+ digit->SetIndexInList(0);
+ digit->SetType(AliEMCALDigit::kHG);
+ digit->SetAmplitude(e);
+
+ AliEMCALRecPoint recPoint("");
+ recPoint.AddDigit(*digit, e, kFALSE);
+ recPoint.EvalGlobalPosition(0, &digits);
+
+ TVector3 gpos;
+ recPoint.GetGlobalPosition(gpos);
+ Float_t g[3];
+ gpos.GetXYZ(g);
+
+ AliVCluster *cluster = static_cast<AliVCluster*>(fOutClusters->New(nClusters));
+ cluster->SetType(AliVCluster::kEMCALClusterv1);
+ cluster->SetE(recPoint.GetEnergy());
+ cluster->SetPosition(g);
+ cluster->SetNCells(1);
+ UShort_t shortAbsId = absId;
+ cluster->SetCellsAbsId(&shortAbsId);
+ Double32_t fract = 1;
+ cluster->SetCellsAmplitudeFraction(&fract);
+ cluster->SetID(nClusters);
+ cluster->SetEmcCpvDistance(-1);
+ if (fMarkMC)
+ cluster->SetChi2(100); // MC flag!
+
+ return cluster;
+}
+
+//________________________________________________________________________
+AliPicoTrack* AliJetModelBaseTask::AddTrack(Double_t pt, Double_t eta, Double_t phi)
+{
+ // Add a track to the event.
+
+ const Int_t nTracks = fOutTracks->GetEntriesFast();
+
+ if (pt < 0)
+ pt = GetRandomPt();
+ if (eta < -100)
+ eta = GetRandomEta();
+ if (phi < 0)
+ phi = GetRandomPhi();
+
+ Int_t label = fMarkMC ? 100 : 0;
+
+ AliPicoTrack *track = new ((*fOutTracks)[nTracks]) AliPicoTrack(pt,
+ eta,
+ phi,
+ 1,
+ label, // MC flag!
+ 0,
+ 0,
+ kFALSE);
+ return track;
+}
+
+//________________________________________________________________________
+void AliJetModelBaseTask::CopyClusters()
+{
+ // Copy all the clusters in the new collection
+
+ Bool_t esdMode = (Bool_t)(fClusters->GetClass()->GetBaseClass("AliESDCaloCluster") != 0);
+ const Int_t nClusters = fClusters->GetEntriesFast();
+
+ if (esdMode) {
+ for (Int_t i = 0; i < nClusters; ++i) {
+ AliESDCaloCluster *esdcluster = static_cast<AliESDCaloCluster*>(fClusters->At(i));
+ if (!esdcluster)
+ continue;
+ if (!esdcluster->IsEMCAL())
+ continue;
+ new ((*fOutClusters)[i]) AliESDCaloCluster(*esdcluster);
+ }
+ }
+ else {
+ for (Int_t i = 0; i < nClusters; ++i) {
+ AliAODCaloCluster *aodcluster = static_cast<AliAODCaloCluster*>(fClusters->At(i));
+ if (!aodcluster)
+ continue;
+ if (!aodcluster->IsEMCAL())
+ continue;
+ new ((*fOutClusters)[i]) AliAODCaloCluster(*aodcluster);
+ }
+ }
+}
+
+//________________________________________________________________________
+void AliJetModelBaseTask::CopyTracks()
+{
+ const Int_t nTracks = fTracks->GetEntriesFast();
+ for (Int_t i = 0; i < nTracks; ++i) {
+ AliPicoTrack *track = static_cast<AliPicoTrack*>(fTracks->At(i));
+ if (!track)
+ continue;
+ new ((*fOutTracks)[i]) AliPicoTrack(*track);
+ }
+}
+
+//________________________________________________________________________
+void AliJetModelBaseTask::ExecOnce()