ids plus comments, authors
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliEmcalCompatTask.cxx
1 // $Id$
2 //
3 // Task to setup emcal related global objects.
4 //
5 // Author: C.Loizides
6
7 #include "AliEmcalCompatTask.h"
8 #include <TClonesArray.h>
9 #include "AliAnalysisManager.h"
10 #include "AliESDEvent.h"
11 #include "AliEsdTrackExt.h"
12 #include "AliEventplane.h"
13 #include "AliCentrality.h"
14 ClassImp(AliEmcalCompatTask)
15
16 //________________________________________________________________________
17 AliEmcalCompatTask::AliEmcalCompatTask() : 
18   AliAnalysisTaskSE(),
19   fDoCent(1),
20   fDoEp(1)
21 {
22   // Constructor.
23 }
24
25 //________________________________________________________________________
26 AliEmcalCompatTask::AliEmcalCompatTask(const char *name) : 
27   AliAnalysisTaskSE(name),
28   fDoCent(1),
29   fDoEp(1)
30 {
31   // Constructor.
32
33   fBranchNames = "ESD:AliESDHeader.,AliESDRun.,Tracks";
34 }
35
36 //________________________________________________________________________
37 AliEmcalCompatTask::~AliEmcalCompatTask()
38 {
39   // Destructor.
40 }
41
42 //________________________________________________________________________
43 void AliEmcalCompatTask::UserExec(Option_t *) 
44 {
45   // Main loop, called for each event.
46
47   AliESDEvent *esdEv = dynamic_cast<AliESDEvent*>(InputEvent());
48   if (!esdEv) {
49     AliError("Task works only on ESD events, returning");
50     return;
51   }
52
53   AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
54   if (!am) {
55     AliError("Manager zero, returning");
56     return;
57   }
58
59   am->LoadBranch("AliESDHeader.");
60   am->LoadBranch("AliESDRun.");
61
62   AliESDHeader *header = esdEv->GetHeader();
63   TString title;
64   if (header)
65     title = header->GetTitle();
66   if (title.Length()==0)
67     return;
68
69   if (fDoCent) {
70     am->LoadBranch("Centrality.");
71     AliCentrality *centin = dynamic_cast<AliCentrality*>(esdEv->FindListObject("Centrality"));
72     AliCentrality *centout = esdEv->GetCentrality();
73     if (centin&&centout&&centout->GetQuality()==999) {
74       centout->SetQuality(centin->GetQuality());
75       centout->SetCentralityV0M(centin->GetCentralityPercentileUnchecked("V0M"));
76       centout->SetCentralityFMD(centin->GetCentralityPercentileUnchecked("FMD"));
77       centout->SetCentralityTRK(centin->GetCentralityPercentileUnchecked("TRK"));
78       centout->SetCentralityTKL(centin->GetCentralityPercentileUnchecked("TKL"));
79       centout->SetCentralityCL0(centin->GetCentralityPercentileUnchecked("CL0"));
80       centout->SetCentralityCL1(centin->GetCentralityPercentileUnchecked("CL1"));
81       centout->SetCentralityV0MvsFMD(centin->GetCentralityPercentileUnchecked("V0MvsFMD"));
82       centout->SetCentralityTKLvsV0M(centin->GetCentralityPercentileUnchecked("TKLvsV0M"));
83       centout->SetCentralityZEMvsZDC(centin->GetCentralityPercentileUnchecked("ZEMvsZDC"));
84     }
85   }
86
87   if (fDoEp) {
88     am->LoadBranch("Eventplane.");
89     AliEventplane *epin  = dynamic_cast<AliEventplane*>(esdEv->FindListObject("Eventplane"));
90     AliEventplane *epout = esdEv->GetEventplane();
91     if (epin&&epout&&(epout->GetQVector()==0)&&(epin->GetQVector()!=0)) {
92       epout->SetQVector(new TVector2(*epin->GetQVector()));
93       epout->SetEventplaneQ(epin->GetEventplane("Q"));
94       epout->SetQsub(new TVector2(*epin->GetQsub1()),new TVector2(*epin->GetQsub2()));
95       epout->SetQsubRes(epin->GetQsubRes());
96     }
97   }
98
99   TTree *tree = am->GetTree();
100   if (tree&&tree->GetBranch("PicoTracks"))
101     am->LoadBranch("PicoTracks");
102
103   if (tree&&tree->GetBranch("Tracks")) {
104     am->LoadBranch("Tracks");
105     TClonesArray *ts = dynamic_cast<TClonesArray*>(esdEv->FindListObject("Tracks"));
106     if (ts) {
107       TString clsname(ts->GetClass()->GetName());
108       if (clsname == "AliEsdTrackExt") {
109         const Int_t N = ts->GetEntries();
110         for (Int_t i=0; i<N; ++i) {
111           AliEsdTrackExt *t = static_cast<AliEsdTrackExt*>(ts->At(i));
112           if (t) {
113             t->SetESDEvent(esdEv);
114             t->Setup();
115           }
116         }
117       }
118     }
119   }
120 }