updates from Salvatore/Ruediger
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliJetEmbeddingFromGenTask.cxx
1 // $Id$
2 //
3 // Jet embedding task.
4 //
5 // Author: S.Aiola, C.Loizides
6
7 #include "AliJetEmbeddingFromGenTask.h"
8
9 #include <TClonesArray.h>
10 #include <TFolder.h>
11 #include <TLorentzVector.h>
12 #include <TParticle.h>
13 #include <TParticlePDG.h>
14 #include <TRandom3.h>
15 #include "AliAnalysisManager.h"
16 #include "AliEMCALDigit.h"
17 #include "AliEMCALGeometry.h"
18 #include "AliEMCALRecPoint.h"
19 #include "AliGenerator.h"
20 #include "AliHeader.h"
21 #include "AliLog.h"
22 #include "AliPicoTrack.h"
23 #include "AliRun.h"
24 #include "AliRunLoader.h"
25 #include "AliStack.h"
26 #include "AliStack.h"
27 #include "AliVCluster.h"
28 #include "AliVEvent.h"
29
30 ClassImp(AliJetEmbeddingFromGenTask)
31
32 //________________________________________________________________________
33 AliJetEmbeddingFromGenTask::AliJetEmbeddingFromGenTask() : 
34   AliJetModelBaseTask("AliJetEmbeddingFromGenTask"),
35   fGen(0)
36 {
37   // Default constructor.
38   SetSuffix("EmbeddedFromGen");
39 }
40
41 //________________________________________________________________________
42 AliJetEmbeddingFromGenTask::AliJetEmbeddingFromGenTask(const char *name) : 
43   AliJetModelBaseTask(name),
44   fGen(0)
45 {
46   // Standard constructor.
47   SetSuffix("EmbeddedFromGen");
48 }
49
50 //________________________________________________________________________
51 AliJetEmbeddingFromGenTask::~AliJetEmbeddingFromGenTask()
52 {
53   // Destructor
54 }
55
56 //________________________________________________________________________
57 Bool_t AliJetEmbeddingFromGenTask::ExecOnce() 
58 {
59   // Exec only once.
60
61   if (!gAlice) {
62     new AliRun("gAlice","The ALICE Off-line Simulation Framework");
63     delete gRandom;
64     gRandom = new TRandom3(0);
65   }
66
67   TFolder *folder = new TFolder(GetName(),GetName());
68   AliRunLoader *rl = new AliRunLoader(folder);
69   rl->MakeHeader();
70   rl->MakeStack();
71   AliStack *stack = rl->Stack();
72   fGen->SetStack(stack);
73   fGen->Init();
74
75   if (InputEvent()->FindListObject(fTracksName) == 0) {
76     fOutTracks = new TClonesArray("AliPicoTrack", 1000);
77     fOutTracks->SetName(fTracksName);
78     InputEvent()->AddObject(fOutTracks);
79     fNTracks = 0;
80   }
81
82   return kTRUE;
83 }
84
85 //________________________________________________________________________
86 void AliJetEmbeddingFromGenTask::Run() 
87 {
88   // Embed particles.
89
90   if (fCopyArray) 
91     CopyTracks();
92
93   AliStack *stack = fGen->GetStack();
94   stack->Reset();
95   fGen->Generate();
96   const Int_t nprim = stack->GetNprimary();
97   for (Int_t i=0;i<nprim;++i) {
98     if (!stack->IsPhysicalPrimary(i))
99       continue;
100     TParticle *part = stack->Particle(i);
101     TParticlePDG *pdg = part->GetPDG(1);
102     if (!pdg) 
103       continue;
104     Int_t c = (Int_t)(TMath::Abs(pdg->Charge()));
105     if (c==0) 
106       continue;
107     Double_t pt = part->Pt();
108     Double_t eta = part->Eta();
109     Double_t phi = part->Phi();
110     if (eta<fEtaMin)
111       continue;
112     if (eta>fEtaMax)
113       continue;
114     if (phi<fPhiMin)
115       continue;
116     if (phi>fPhiMax)
117       continue;
118     if (pt<fPtMin)
119       continue;
120     if (pt>fPtMax)
121       continue;
122     AddTrack(pt, eta, phi);
123   }
124 }