]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskSE.cxx
removing old documentation
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskSE.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 /* $Id$ */
17  
18 #include <TROOT.h>
19 #include <TSystem.h>
20 #include <TInterpreter.h>
21 #include <TChain.h>
22 #include <TFile.h>
23 #include <TList.h>
24
25 #include "AliAnalysisTaskSE.h"
26 #include "AliAnalysisManager.h"
27 #include "AliESDEvent.h"
28 #include "AliESD.h"
29 #include "AliAODEvent.h"
30 #include "AliAODHeader.h"
31 #include "AliVEvent.h"
32 #include "AliAODHandler.h"
33 #include "AliAODInputHandler.h"
34 #include "AliMCEventHandler.h"
35 #include "AliInputEventHandler.h"
36 #include "AliMCEvent.h"
37 #include "AliStack.h"
38 #include "AliLog.h"
39
40
41 ClassImp(AliAnalysisTaskSE)
42
43 ////////////////////////////////////////////////////////////////////////
44 Bool_t        AliAnalysisTaskSE::fgHeaderCopied = kFALSE;
45 AliAODHeader* AliAnalysisTaskSE::fgAODHeader    = NULL;
46
47 AliAnalysisTaskSE::AliAnalysisTaskSE():
48     AliAnalysisTask(),
49     fDebug(0),
50     fEntry(0),
51     fInputEvent(0x0),
52     fInputHandler(0x0),
53     fOutputAOD(0x0),
54     fMCEvent(0x0),
55     fTreeA(0x0)
56 {
57   // Default constructor
58 }
59
60 AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
61     AliAnalysisTask(name, "AnalysisTaskSE"),
62     fDebug(0),
63     fEntry(0),
64     fInputEvent(0x0),
65     fInputHandler(0x0),
66     fOutputAOD(0x0),
67     fMCEvent(0x0),
68     fTreeA(0x0)
69 {
70   // Default constructor
71     DefineInput (0, TChain::Class());
72     DefineOutput(0,  TTree::Class());
73 }
74
75 AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
76     AliAnalysisTask(obj),
77     fDebug(0),
78     fEntry(0),
79     fInputEvent(0x0),
80     fInputHandler(0x0),
81     fOutputAOD(0x0),
82     fMCEvent(0x0),
83     fTreeA(0x0)
84 {
85 // Copy constructor
86     fDebug        = obj.fDebug;
87     fEntry        = obj.fEntry;
88     fInputEvent   = obj.fInputEvent;
89     fInputHandler = obj.fInputHandler;
90     fOutputAOD    = obj.fOutputAOD;
91     fMCEvent      = obj.fMCEvent;
92     fTreeA        = obj.fTreeA;    
93     printf("Constructor (3) \n");
94 }
95
96
97 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
98 {
99 // Assignment
100     AliAnalysisTask::operator=(other);
101     fDebug        = other.fDebug;
102     fEntry        = other.fEntry;
103     fInputEvent   = other.fInputEvent;
104     fInputHandler = other.fInputHandler;
105     fOutputAOD    = other.fOutputAOD;
106     fMCEvent      = other.fMCEvent;
107     fTreeA        = other.fTreeA;    
108     return *this;
109 }
110
111
112 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
113 {
114 // Connect the input data
115     if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
116 //
117 //  ESD
118 //
119     fInputHandler = (AliInputEventHandler*) 
120          ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
121 //
122 //  Monte Carlo
123 //
124     AliMCEventHandler*    mcH = 0;
125     mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
126     if (mcH) fMCEvent = mcH->MCEvent();
127     
128     
129     if (fInputHandler) {
130          fInputEvent = fInputHandler->GetEvent();
131     } else if( fMCEvent ) {
132          AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ; 
133     } else {
134          AliError("No Input Event Handler connected") ; 
135          return ; 
136     }
137 }
138
139 void AliAnalysisTaskSE::CreateOutputObjects()
140 {
141 // Create the output container
142 //
143 //  Default AOD
144     if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
145
146     AliAODHandler* handler = (AliAODHandler*) 
147          ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
148     
149     if (handler) {
150         fOutputAOD   = handler->GetAOD();
151         fTreeA = handler->GetTree();
152         fTreeA->Print();
153         
154         // Check if AOD Header replication has been required
155         if (!(handler->IsStandard())            && 
156             (handler->NeedsHeaderReplication()) &&
157             !(fgAODHeader))
158         {
159             fgAODHeader = new AliAODHeader;
160             handler->AddBranch("AliAODHeader", &fgAODHeader);
161         }
162     } else {
163         AliWarning("No AOD Event Handler connected.") ; 
164     }
165     UserCreateOutputObjects();
166 }
167
168 void AliAnalysisTaskSE::Exec(Option_t* option)
169 {
170 //
171 // Exec analysis of one event
172     if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
173     if( fInputHandler ) 
174        fEntry = fInputHandler->GetReadEntry();
175     else if( fMCEvent )
176        fEntry = fMCEvent->Header()->GetEvent(); 
177     if ( !((Entry()-1)%100) && fDebug > 0) 
178          AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
179
180     AliAODHandler* handler = (AliAODHandler*) 
181         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
182
183     if (!(handler->IsStandard())            && 
184         (handler->NeedsHeaderReplication()) &&
185         (fgAODHeader))
186     {
187         // Header should be replicated
188         AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
189         if (aodH) {
190             // Input is AOD
191             fgAODHeader =  dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader());
192             fgHeaderCopied = kTRUE;
193         }
194     }
195
196 // Call the user analysis    
197     UserExec(option);
198     PostData(0, fTreeA);
199     
200 }
201
202 const char* AliAnalysisTaskSE::CurrentFileName()
203 {
204 // Returns the current file name    
205     if( fInputHandler )
206       return fInputHandler->GetTree()->GetCurrentFile()->GetName();
207     else if( fMCEvent )
208       return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
209     else return "";
210 }
211
212 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj)
213 {
214     // Add a new branch to the aod tree
215     AliAODHandler* handler = (AliAODHandler*) 
216         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
217     if (handler) {
218         handler->AddBranch(cname, addobj);
219     }
220 }