added jet embedding from generator tasks
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliJetEmbeddingFromGenTask.cxx
1 // $Id: AliJetEmbeddingFromGenTask.cxx 57324 2012-06-21 04:33:52Z loizides $
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 void AliJetEmbeddingFromGenTask::ExecOnce() 
58 {
59   // Exec only once.
60
61   cout << "afjalfja " <<endl;
62   if (!gAlice) {
63     new AliRun("gAlice","The ALICE Off-line Simulation Framework");
64     delete gRandom;
65     gRandom = new TRandom3(0);
66   }
67
68   TFolder *folder = new TFolder(GetName(),GetName());
69   AliRunLoader *rl = new AliRunLoader(folder);
70   rl->MakeHeader();
71   rl->MakeStack();
72   AliStack *stack = rl->Stack();
73   fGen->SetStack(stack);
74   fGen->Init();
75
76   if (InputEvent()->FindListObject(fTracksName) == 0) {
77     fOutTracks = new TClonesArray("AliPicoTrack", 1000);
78     fOutTracks->SetName(fTracksName);
79     fNTracks = 0;
80   }
81 }
82
83 //________________________________________________________________________
84 void AliJetEmbeddingFromGenTask::Run() 
85 {
86   // Embed particles.
87
88   if (fCopyArray) 
89     CopyTracks();
90
91   AliStack *stack = fGen->GetStack();
92   stack->Reset();
93   fGen->Generate();
94   const Int_t nprim = stack->GetNprimary();
95   for (Int_t i=0;i<nprim;++i) {
96     if (!stack->IsPhysicalPrimary(i))
97       continue;
98     TParticle *part = stack->Particle(i);
99     TParticlePDG *pdg = part->GetPDG(1);
100     if (!pdg) 
101       continue;
102     Int_t c = (Int_t)(TMath::Abs(pdg->Charge()));
103     if (c==0) 
104       continue;
105     Double_t pt = part->Pt();
106     Double_t eta = part->Eta();
107     Double_t phi = part->Phi();
108     if (eta<fEtaMin)
109       continue;
110     if (eta>fEtaMax)
111       continue;
112     if (phi<fPhiMin)
113       continue;
114     if (phi>fPhiMax)
115       continue;
116     if (pt<fPtMin)
117       continue;
118     if (pt>fPtMax)
119       continue;
120     AddTrack(pt, eta, phi);
121   }
122 }