1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 #include <TInterpreter.h>
22 #include <Riostream.h>
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"
37 ClassImp(AliAnalysisTaskGamma)
39 ////////////////////////////////////////////////////////////////////////
41 AliAnalysisTaskGamma::AliAnalysisTaskGamma():
47 fOutputContainer(0x0),
50 // Default constructor
53 //_____________________________________________________
54 AliAnalysisTaskGamma::AliAnalysisTaskGamma(const char* name):
55 AliAnalysisTask(name, "AnalysisTaskGamma"),
61 fOutputContainer(0x0),
62 fConfigName("ConfigGammaAnalysis")
64 // Default constructor
66 DefineInput (0, TChain::Class());
67 DefineOutput(0, TTree::Class());
68 DefineOutput(1, TList::Class());
72 //_____________________________________________________
73 AliAnalysisTaskGamma::~AliAnalysisTaskGamma()
75 // Remove all pointers
78 fOutputContainer->Clear() ;
79 delete fOutputContainer ;
82 if(fTreeG) delete fTreeG ;
86 //_____________________________________________________
87 void AliAnalysisTaskGamma::CreateOutputObjects()
89 // Create the output container
93 AliAODHandler* handler = (AliAODHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
94 fAOD = handler->GetAOD();
95 fTreeG = handler->GetTree();
96 fAna->ConnectAOD(fAOD);
98 //Histograms container
100 fOutputContainer = fAna->GetOutputContainer();
104 //_____________________________________________________
105 void AliAnalysisTaskGamma::Init()
110 // Call configuration file
112 if(fConfigName == ""){
113 fConfigName="ConfigGammaAnalysis";
116 AliInfo(Form("### Configuration file is %s.C ###", fConfigName.Data()));
117 gROOT->LoadMacro(fConfigName+".C");
118 fAna = (AliAnaGamma*) gInterpreter->ProcessLine("ConfigGammaAnalysis()");
121 AliFatal("Analysis pointer not initialized, abort analysis!");
123 // Initialise Gamma Analysis
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);
137 //_____________________________________________________
138 void AliAnalysisTaskGamma::ConnectInputData(Option_t */*option*/)
140 // Connect the input data
142 AliDebug(1,"ConnectInputData() ");
143 fChain = (TChain*)GetInputData(0);
144 fESD = new AliESDEvent();
145 fESD->ReadFromTree(fChain);
149 //_____________________________________________________
150 void AliAnalysisTaskGamma::Exec(Option_t */*option*/)
152 // Execute analysis for current event
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");
165 AliStack* stack = 0x0;
166 if(datatype == AliGammaReader::kMC || datatype == AliGammaReader::kMCData ){
167 AliMCEventHandler* mctruth = (AliMCEventHandler*)
168 ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
171 stack = mctruth->MCEvent()->Stack();
176 Long64_t ientry = fChain->GetReadEntry();
177 if ( !((ientry)%100) )
178 AliInfo(Form("Analysing event # %5d\n", (Int_t) ientry));
180 //Pass ESD pointer to analysis
182 AliError("fESD is not connected to the input!") ;
188 //In case of montecarlo analysis, pass the stack also.
189 if((datatype == AliGammaReader::kMC || datatype == AliGammaReader::kMCData ) && stack)
190 fAna -> SetKine(stack);
193 fAna->ProcessEvent(ientry);
196 PostData(1, fOutputContainer);
200 //_____________________________________________________
201 void AliAnalysisTaskGamma::Terminate(Option_t */*option*/)
203 // Terminate analysis
205 AliDebug(1,"Do nothing in Terminate");