]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/AliAnalysisTaskGamma.cxx
update Toolkit classes
[u/mrichter/AliRoot.git] / PWG4 / AliAnalysisTaskGamma.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 // root
17 #include <TROOT.h>
18 #include <TSystem.h>
19 #include <TInterpreter.h>
20 #include <TChain.h>
21 #include <TFile.h>
22 #include <Riostream.h>
23
24 // analysis
25 #include "AliAnalysisTaskGamma.h"
26 #include "AliAnalysisManager.h"
27 #include "AliMCEventHandler.h"
28 #include "AliMCEvent.h"
29 #include "AliAnaGamma.h"
30 #include "AliGammaReader.h"
31 #include "AliESDEvent.h"
32 #include "AliAODEvent.h"
33 #include "AliAODHandler.h"
34 #include "AliStack.h"
35 #include "AliLog.h"
36
37 ClassImp(AliAnalysisTaskGamma)
38
39 ////////////////////////////////////////////////////////////////////////
40
41 AliAnalysisTaskGamma::AliAnalysisTaskGamma():
42     fAna(0x0),
43     fChain(0x0),
44     fESD(0x0),
45     fAOD(0x0),
46     fTreeG(0x0),
47     fOutputContainer(0x0)
48 {
49   // Default constructor
50 }
51
52 //_____________________________________________________
53 AliAnalysisTaskGamma::AliAnalysisTaskGamma(const char* name):
54     AliAnalysisTask(name, "AnalysisTaskGamma"),
55     fAna(0x0),
56     fChain(0x0),
57     fESD(0x0),
58     fAOD(0x0),
59     fTreeG(0x0),
60     fOutputContainer(0x0)
61 {
62   // Default constructor
63  
64   DefineInput (0, TChain::Class());
65   DefineOutput(0, TTree::Class());
66   DefineOutput(1, TList::Class());
67
68 }
69
70 //_____________________________________________________
71 AliAnalysisTaskGamma::~AliAnalysisTaskGamma() 
72 {
73   // Remove all pointers
74  
75   if(fOutputContainer){
76     fOutputContainer->Clear() ; 
77     delete fOutputContainer ;
78   }
79   
80   if(fTreeG) delete fTreeG ; 
81
82 }
83
84 //_____________________________________________________
85 void AliAnalysisTaskGamma::CreateOutputObjects()
86 {
87   // Create the output container
88   
89   //AODs
90   OpenFile(0);
91   AliAODHandler* handler = (AliAODHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
92   fAOD   = handler->GetAOD();
93   fTreeG = handler->GetTree();
94   fAna->ConnectAOD(fAOD);
95
96   //Histograms container
97   OpenFile(1);
98   fOutputContainer = fAna->GetOutputContainer();
99   
100 }
101
102 //_____________________________________________________
103 void AliAnalysisTaskGamma::Init()
104 {
105   // Initialization
106   AliDebug(1,"Begin");
107   
108   // Call configuration file
109   gROOT->LoadMacro("ConfigGammaAnalysis.C");
110   fAna = (AliAnaGamma*) gInterpreter->ProcessLine("ConfigGammaAnalysis()");
111   
112   if(!fAna)
113     AliFatal("Analysis pointer not initialized, abort analysis!");
114   
115   // Initialise Gamma Analysis
116   fAna->Init();
117   
118   //In case of MC analysis
119   Int_t  datatype = fAna->GetReader()->GetDataType();
120   if(datatype == AliGammaReader::kMC || datatype == AliGammaReader::kMCData ){
121     AliMCEventHandler * mc = new AliMCEventHandler();
122     (AliAnalysisManager::GetAnalysisManager())->SetMCtruthEventHandler(mc);
123   }
124   
125   AliDebug(1,"End");
126   
127 }
128
129 //_____________________________________________________
130 void AliAnalysisTaskGamma::ConnectInputData(Option_t */*option*/)
131 {
132   // Connect the input data
133   //
134   AliDebug(1,"ConnectInputData() ");
135   fChain = (TChain*)GetInputData(0);
136   fESD = new AliESDEvent();
137   fESD->ReadFromTree(fChain);
138   
139 }
140
141 //_____________________________________________________
142 void AliAnalysisTaskGamma::Exec(Option_t */*option*/)
143 {
144   // Execute analysis for current event
145   //
146
147   //Get the type of data, check if type is correct
148   Int_t  datatype = fAna->GetReader()->GetDataType();
149   if(datatype != AliGammaReader::kData && 
150      datatype != AliGammaReader::kMC && 
151      datatype != AliGammaReader::kMCData){
152     AliFatal("Wrong type of data");
153     return ;
154   }
155
156   //Get MC data
157   AliStack* stack = 0x0; 
158   if(datatype == AliGammaReader::kMC || datatype == AliGammaReader::kMCData ){
159     AliMCEventHandler*    mctruth = (AliMCEventHandler*) 
160       ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
161     
162     if(mctruth)
163       stack = mctruth->MCEvent()->Stack();
164     
165   }
166   
167   //Get Event
168   Long64_t ientry = fChain->GetReadEntry();
169   if ( !((ientry)%100) ) 
170     AliInfo(Form("Analysing event # %5d\n", (Int_t) ientry));
171   
172   //Pass ESD pointer to analysis      
173   if (!fESD) {
174     AliError("fESD is not connected to the input!") ; 
175     return ; 
176   } 
177   
178   fAna->SetData(fESD);
179   
180   //In case of montecarlo analysis, pass the stack also.
181   if((datatype == AliGammaReader::kMC || datatype == AliGammaReader::kMCData ) && stack)
182     fAna -> SetKine(stack);
183   
184   //Process event
185   fAna->ProcessEvent(ientry);
186   
187   PostData(0, fTreeG); 
188   PostData(1, fOutputContainer);
189   
190 }
191
192 //_____________________________________________________
193 void AliAnalysisTaskGamma::Terminate(Option_t */*option*/)
194 {
195   // Terminate analysis
196   //
197   AliDebug(1,"Do nothing in Terminate");
198  
199 }
200