3e718ed1a704d20448619fd8360dc7078feb66a8
[u/mrichter/AliRoot.git] / JETAN / AliAnalysisTaskJets.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 #include <TROOT.h>
17 #include <TSystem.h>
18 #include <TInterpreter.h>
19 #include <TChain.h>
20 #include <TFile.h>
21 #include <TH1.h>
22
23 #include "AliAnalysisTaskJets.h"
24 #include "AliAnalysisManager.h"
25 #include "AliJetFinder.h"
26 #include "AliESDEvent.h"
27 #include "AliAODEvent.h"
28 #include "AliAODHandler.h"
29 #include "AliMCEventHandler.h"
30 #include "AliStack.h"
31
32
33 ClassImp(AliAnalysisTaskJets)
34
35 ////////////////////////////////////////////////////////////////////////
36
37 AliAnalysisTaskJets::AliAnalysisTaskJets():
38     fDebug(0),
39     fJetFinder(0x0),
40     fChain(0x0),
41     fESD(0x0),
42     fAOD(0x0),
43     fTreeA(0x0),
44     fHisto(0x0)
45 {
46   // Default constructor
47 }
48
49 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
50     AliAnalysisTask(name, "AnalysisTaskJets"),
51     fDebug(0),
52     fJetFinder(0x0),
53     fChain(0x0),
54     fESD(0x0),
55     fAOD(0x0),
56     fTreeA(0x0),
57     fHisto(0x0)
58 {
59   // Default constructor
60     DefineInput (0, TChain::Class());
61     DefineOutput(0, TTree::Class());
62     DefineOutput(1, TH1F::Class());
63 }
64
65 void AliAnalysisTaskJets::CreateOutputObjects()
66 {
67 // Create the output container
68 //
69 //  Default AOD
70     if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
71     AliAODHandler* handler = (AliAODHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
72     
73     fAOD   = handler->GetAOD();
74     fTreeA = handler->GetTree();
75     fJetFinder->ConnectAOD(fAOD);
76 //
77 //  Histogram
78     OpenFile(1);
79     fHisto = new TH1F("fHisto", "Jet Et", 100, 0., 100.);
80     
81 }
82
83 void AliAnalysisTaskJets::Init()
84 {
85     // Initialization
86     if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
87
88     // Call configuration file
89     gROOT->LoadMacro("ConfigJetAnalysis.C");
90     fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
91     // Initialise Jet Analysis
92     fJetFinder->Init();
93     // Write header information to local file
94     fJetFinder->WriteHeaders();
95 }
96
97 void AliAnalysisTaskJets::ConnectInputData(Option_t */*option*/)
98 {
99 // Connect the input data
100     if (fDebug > 1) printf("AnalysisTaskJets::ConnectInputData() \n");
101     fChain = (TChain*)GetInputData(0);
102     fESD = new AliESDEvent();
103     fESD->ReadFromTree(fChain);
104     fJetFinder->ConnectTree(fChain, fESD);
105 }
106
107 void AliAnalysisTaskJets::Exec(Option_t */*option*/)
108 {
109 // Execute analysis for current event
110 //
111     AliMCEventHandler*    mctruth = (AliMCEventHandler*) 
112         ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
113     AliStack* stack = mctruth->Stack();
114     printf("AliAnalysisTaskJets: Number of tracks %5d\n", stack->GetNtrack());
115
116     Long64_t ientry = fChain->GetReadEntry();
117     if (fDebug > 1) printf("Analysing event # %5d\n", (Int_t) ientry);
118     fJetFinder->ProcessEvent(ientry);
119     PostData(0, fTreeA);
120     PostData(1, fHisto);
121 }
122
123 void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
124 {
125 // Terminate analysis
126 //
127     if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
128     // if (fJetFinder) fJetFinder->FinishRun();
129 }
130