]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/AliAnalysisTaskGamma.cxx
94337cea98de975e5f1946f9b4d3783e322fce2b
[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     fConfigName(0)
49 {
50   // Default constructor
51 }
52
53 //_____________________________________________________
54 AliAnalysisTaskGamma::AliAnalysisTaskGamma(const char* name):
55     AliAnalysisTask(name, "AnalysisTaskGamma"),
56     fAna(0x0),
57     fChain(0x0),
58     fESD(0x0),
59     fAOD(0x0),
60     fTreeG(0x0),
61     fOutputContainer(0x0),
62     fConfigName("ConfigGammaAnalysis")
63 {
64   // Default constructor
65  
66   DefineInput (0, TChain::Class());
67   DefineOutput(0, TTree::Class());
68   DefineOutput(1, TList::Class());
69
70 }
71
72 //_____________________________________________________
73 AliAnalysisTaskGamma::~AliAnalysisTaskGamma() 
74 {
75   // Remove all pointers
76  
77   if(fOutputContainer){
78     fOutputContainer->Clear() ; 
79     delete fOutputContainer ;
80   }
81   
82   if(fTreeG) delete fTreeG ; 
83
84 }
85
86 //_____________________________________________________
87 void AliAnalysisTaskGamma::CreateOutputObjects()
88 {
89   // Create the output container
90   
91   //AODs
92   OpenFile(0);
93   AliAODHandler* handler = (AliAODHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
94   fAOD   = handler->GetAOD();
95   fTreeG = handler->GetTree();
96   fAna->ConnectAOD(fAOD);
97
98   //Histograms container
99   OpenFile(1);
100   fOutputContainer = fAna->GetOutputContainer();
101   
102 }
103
104 //_____________________________________________________
105 void AliAnalysisTaskGamma::Init()
106 {
107   // Initialization
108   AliDebug(1,"Begin");
109   
110   // Call configuration file
111
112   if(fConfigName == ""){
113     fConfigName="ConfigGammaAnalysis";
114   }
115  
116   AliInfo(Form("### Configuration file is %s.C ###", fConfigName.Data()));
117   gROOT->LoadMacro(fConfigName+".C");
118   fAna = (AliAnaGamma*) gInterpreter->ProcessLine("ConfigGammaAnalysis()");
119   
120   if(!fAna)
121     AliFatal("Analysis pointer not initialized, abort analysis!");
122   
123   // Initialise Gamma Analysis
124   fAna->Init();
125   
126   //In case of MC analysis
127   Int_t  datatype = fAna->GetReader()->GetDataType();
128   if(datatype == AliGammaReader::kMC || datatype == AliGammaReader::kMCData ){
129     AliMCEventHandler * mc = new AliMCEventHandler();
130     (AliAnalysisManager::GetAnalysisManager())->SetMCtruthEventHandler(mc);
131   }
132   
133   AliDebug(1,"End");
134   
135 }
136
137 //_____________________________________________________
138 void AliAnalysisTaskGamma::ConnectInputData(Option_t */*option*/)
139 {
140   // Connect the input data
141   //
142   AliDebug(1,"ConnectInputData() ");
143   fChain = (TChain*)GetInputData(0);
144   fESD = new AliESDEvent();
145   fESD->ReadFromTree(fChain);
146   
147 }
148
149 //_____________________________________________________
150 void AliAnalysisTaskGamma::Exec(Option_t */*option*/)
151 {
152   // Execute analysis for current event
153   //
154
155   //Get the type of data, check if type is correct
156   Int_t  datatype = fAna->GetReader()->GetDataType();
157   if(datatype != AliGammaReader::kData && 
158      datatype != AliGammaReader::kMC && 
159      datatype != AliGammaReader::kMCData){
160     AliFatal("Wrong type of data");
161     return ;
162   }
163
164   //Get MC data
165   AliStack* stack = 0x0; 
166   if(datatype == AliGammaReader::kMC || datatype == AliGammaReader::kMCData ){
167     AliMCEventHandler*    mctruth = (AliMCEventHandler*) 
168       ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
169     
170     if(mctruth)
171       stack = mctruth->MCEvent()->Stack();
172     
173   }
174   
175   //Get Event
176   Long64_t ientry = fChain->GetReadEntry();
177   if ( !((ientry)%100) ) 
178     AliInfo(Form("Analysing event # %5d\n", (Int_t) ientry));
179   
180   //Pass ESD pointer to analysis      
181   if (!fESD) {
182     AliError("fESD is not connected to the input!") ; 
183     return ; 
184   } 
185   
186   fAna->SetData(fESD);
187   
188   //In case of montecarlo analysis, pass the stack also.
189   if((datatype == AliGammaReader::kMC || datatype == AliGammaReader::kMCData ) && stack)
190     fAna -> SetKine(stack);
191   
192   //Process event
193   fAna->ProcessEvent(ientry);
194   
195   PostData(0, fTreeG); 
196   PostData(1, fOutputContainer);
197   
198 }
199
200 //_____________________________________________________
201 void AliAnalysisTaskGamma::Terminate(Option_t */*option*/)
202 {
203   // Terminate analysis
204   //
205   AliDebug(1,"Do nothing in Terminate");
206  
207 }
208