end-of-line normalization
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / AntiprotonToProton / AliProtonFeedDownAnalysisTask.cxx
CommitLineData
a65a7e70 1#include "TChain.h"
2#include "TTree.h"
3#include "TString.h"
4#include "TList.h"
5#include "TH2F.h"
6
7#include "AliAnalysisTask.h"
8#include "AliAnalysisManager.h"
9
10#include "AliESDEvent.h"
11#include "AliESDInputHandler.h"
12#include "AliAODEvent.h"
13#include "AliAODInputHandler.h"
14#include "AliMCEventHandler.h"
15#include "AliMCEvent.h"
16#include "AliStack.h"
17#include "AliESDVertex.h"
18
19#include "AliProtonFeedDownAnalysis.h"
20#include "AliProtonAnalysisBase.h"
21#include "AliProtonFeedDownAnalysisTask.h"
22#include <Riostream.h>
23
24ClassImp(AliProtonFeedDownAnalysisTask)
25
26//________________________________________________________________________
27AliProtonFeedDownAnalysisTask::AliProtonFeedDownAnalysisTask()
28 : AliAnalysisTask(), fESD(0), fAOD(0), fMC(0),
29 fList(0), fProtonAnalysis(0),fStatHist(0)
30 {
31 //Dummy constructor
32
33}
34
35//________________________________________________________________________
36AliProtonFeedDownAnalysisTask::AliProtonFeedDownAnalysisTask(const char *name)
37 : AliAnalysisTask(name, ""), fESD(0), fAOD(0), fMC(0),
38 fList(0), fProtonAnalysis(0),fStatHist(0)
39 {
40 // Constructor
41
42 // Define input and output slots here
43 // Input slot #0 works with a TChain
44 DefineInput(0, TChain::Class());
45 // Output slot #0 writes into a TList container
46 DefineOutput(0, TList::Class());
47}
48
49//________________________________________________________________________
50void AliProtonFeedDownAnalysisTask::ConnectInputData(Option_t *)
51{
52 // Connect ESD or AOD here
53 // Called once
54 TString gAnalysisLevel = dynamic_cast<AliProtonAnalysisBase*>(fProtonAnalysis->GetProtonAnalysisBaseObject())->GetAnalysisLevel();
55
56 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
57 if (!tree)
58 {
59 Printf("ERROR: Could not read chain from input slot 0");
60 }
61 else
62 {
63 if(gAnalysisLevel == "ESD")
64 {
65 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
66 if (!esdH)
67 {
68 Printf("ERROR: Could not get ESDInputHandler");
69 }
70 else
71 fESD = esdH->GetEvent();
72 AliMCEventHandler* mcH = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
73 if (!mcH)
74 {
75 Printf("ERROR: Could not retrieve MC event handler");
76 }
77 else
78 fMC = mcH->MCEvent();
79 }
80 else if(gAnalysisLevel == "AOD")
81 {
82 AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
83 if (!aodH)
84 {
85 Printf("ERROR: Could not get AODInputHandler");
86 }
87 else
88 fAOD = aodH->GetEvent();
89 }
90 else
91 Printf("Wrong analysis type: Only ESD, AOD types are allowed!");
92 }
93}
94//________________________________________________________________________
95void AliProtonFeedDownAnalysisTask::CreateOutputObjects()
96{
97 // Create output objects
98 // Called once
99 fList = new TList();
100 fList->Add(fProtonAnalysis->GetProtonContainer());
101 fList->Add(fProtonAnalysis->GetAntiProtonContainer());
102 fList->Add(fProtonAnalysis->GetLambdaHist());
103 fList->Add(fProtonAnalysis->GetLambdaweightedHist());
104 fList->Add(fProtonAnalysis->GetAntiLambdaHist());
105 fList->Add(fProtonAnalysis->GetAntiLambdaweightedHist());
106 fStatHist=new TH1F("StatsHist","StatsHist",10,-0.5,9.5);
107 fList->Add(fStatHist);
108 fStatHist->GetXaxis()->SetBinLabel(1,"level1cut");
109 fStatHist->GetXaxis()->SetBinLabel(2,"level2cut");
110 fStatHist->GetXaxis()->SetBinLabel(3,"level3cut");
111 fStatHist->GetXaxis()->SetBinLabel(4,"level4cut");
112}
113//________________________________________________________________________
114void AliProtonFeedDownAnalysisTask::Exec(Option_t *)
115{
116 // Main loop
117 // Called for each event
118 TString gAnalysisLevel = dynamic_cast<AliProtonAnalysisBase*>(fProtonAnalysis->GetProtonAnalysisBaseObject())->GetAnalysisLevel();
119 //TString gAnalysisLevel = (fProtonAnalysis->GetProtonAnalysisBaseObject())->GetAnalysisLevel();
120 if(gAnalysisLevel == "ESD")
121 {
122 if (!fESD)
123 {
124 Printf("ERROR: fESD not available");
125 return;
126 }
127 fStatHist->Fill(0);
128 if(dynamic_cast<AliProtonAnalysisBase*>(fProtonAnalysis->GetProtonAnalysisBaseObject())->IsEventTriggered(fESD,dynamic_cast<AliProtonAnalysisBase*>(fProtonAnalysis->GetProtonAnalysisBaseObject())->GetTriggerMode()))
129 {
130 fStatHist->Fill(1);
131 const AliESDVertex *vertex = dynamic_cast<AliProtonAnalysisBase*>(fProtonAnalysis->GetProtonAnalysisBaseObject())->GetVertex(fESD,dynamic_cast<AliProtonAnalysisBase*>(fProtonAnalysis->GetProtonAnalysisBaseObject())->GetAnalysisMode(),dynamic_cast<AliProtonAnalysisBase*>(fProtonAnalysis->GetProtonAnalysisBaseObject())->GetVxMax(),dynamic_cast<AliProtonAnalysisBase*>(fProtonAnalysis->GetProtonAnalysisBaseObject())->GetVyMax(),dynamic_cast<AliProtonAnalysisBase*>(fProtonAnalysis->GetProtonAnalysisBaseObject())->GetVzMax());
132 if(vertex)
133 {
134 fStatHist->Fill(2);
135 Printf("Proton ESD analysis task: There are %d tracks in this event", fESD->GetNumberOfTracks());
136 AliStack* stack1=0x0;
137 if(!fMC)
138 return;
139 stack1 = fMC->Stack();
140 if(!stack1)
141 return;
142 fStatHist->Fill(3);
143 fProtonAnalysis->Analyze(fESD,vertex,stack1);
144 fProtonAnalysis->Analyze(stack1);
145
146 }//reconstructed vertex
147 }//triggered event
148 }//ESD analysis
149
150 else if(gAnalysisLevel == "AOD")
151 {
152 if (!fAOD)
153 {
154 Printf("ERROR: fAOD not available");
155 return;
156 }
157 Printf("Proton AOD analysis task: There are %d tracks in this event", fAOD->GetNumberOfTracks());
158 fProtonAnalysis->Analyze(fAOD);
159 }//AOD analysis
160
161
162 // Post output data.
163 PostData(0, fList);
164}
165//__________________________________________________________________________________________
166void AliProtonFeedDownAnalysisTask::Terminate(Option_t *)
167{
168
169}
170
171