]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskFilter.cxx
Merge branch 'trackMatcher'
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskFilter.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 //////////////////////////////////////////////////////////////////////////
19 //
20 //  Base class for filtering friends
21 //
22 //////////////////////////////////////////////////////////////////////////
23  
24 #include <TChain.h>
25 #include <TFile.h>
26 #include <TList.h>
27
28 #include "AliAnalysisTaskFilter.h"
29 #include "AliAnalysisManager.h"
30 #include "AliAnalysisDataSlot.h"
31 #include "AliESDEvent.h"
32 #include "AliESD.h"
33 #include "AliVEvent.h"
34 #include "AliESDHandler.h"
35 #include "AliInputEventHandler.h"
36 #include "AliLog.h"
37 #include "AliESDfriend.h"
38 #include "AliESDfriendTrack.h"
39
40
41 ClassImp(AliAnalysisTaskFilter)
42
43 ////////////////////////////////////////////////////////////////////////
44
45 AliAnalysisTaskFilter::AliAnalysisTaskFilter():
46         AliAnalysisTask(),
47         fDebug(0),
48         fEntry(0),
49         fInputEvent(0x0),
50         fInputHandler(0x0),
51         fOutputESD(0x0),
52         fOutputESDfriend(0x0),
53         fTreeE(0x0)
54 {
55         //
56         // Default constructor
57         //
58 }
59
60 //______________________________________________________________________
61
62 AliAnalysisTaskFilter::AliAnalysisTaskFilter(const char* name):
63         AliAnalysisTask(name, "AnalysisTaskFilter"),
64         fDebug(0),
65         fEntry(0),
66         fInputEvent(0x0),
67         fInputHandler(0x0),
68         fOutputESD(0x0),
69         fOutputESDfriend(0x0),
70         fTreeE(0x0)
71 {
72         //
73         // Default constructor
74         //
75
76         DefineInput (0, TChain::Class());
77         DefineOutput(0,  TTree::Class());
78 }
79
80 //______________________________________________________________________
81
82 AliAnalysisTaskFilter::AliAnalysisTaskFilter(const AliAnalysisTaskFilter& obj):
83         AliAnalysisTask(obj),
84         fDebug(0),
85         fEntry(0),
86         fInputEvent(0x0),
87         fInputHandler(0x0),
88         fOutputESD(0x0),
89         fOutputESDfriend(0x0),
90         fTreeE(0x0)
91 {
92         //
93         // Copy constructor
94         //
95
96         fDebug        = obj.fDebug;
97         fEntry        = obj.fEntry;
98         fInputEvent   = obj.fInputEvent;
99         fInputHandler = obj.fInputHandler;
100         fOutputESD    = obj.fOutputESD;
101         fOutputESDfriend = obj.fOutputESDfriend;
102         fTreeE        = obj.fTreeE;    
103 }
104
105
106 //______________________________________________________________________
107
108 AliAnalysisTaskFilter& AliAnalysisTaskFilter::operator=(const AliAnalysisTaskFilter& other)
109 {
110         //
111         // Assignment
112         //
113
114         AliAnalysisTask::operator=(other);
115         fDebug        = other.fDebug;
116         fEntry        = other.fEntry;
117         fInputEvent   = other.fInputEvent;
118         fInputHandler = other.fInputHandler;
119         fOutputESD    = other.fOutputESD;
120         fOutputESDfriend = other.fOutputESDfriend;
121         fTreeE        = other.fTreeE;    
122         return *this;
123 }
124
125
126 //______________________________________________________________________
127
128 void AliAnalysisTaskFilter::ConnectInputData(Option_t* /*option*/)
129 {
130         //
131         // Connect the input data
132         //
133
134         if (fDebug > 1) printf("AnalysisTaskFilter::ConnectInputData() \n");
135         fInputHandler = (AliInputEventHandler*) 
136                 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
137         if (fInputHandler) {
138                 fInputEvent = fInputHandler->GetEvent();
139         } else {
140                 AliError("No Input Event Handler connected") ; 
141                 return ; 
142         }
143 }
144
145 //______________________________________________________________________
146
147 void AliAnalysisTaskFilter::CreateOutputObjects()
148 {
149         //
150         // Create the output container
151         //
152
153         if (fDebug > 1) printf("AnalysisTaskFilter::CreateOutPutData() \n");
154
155         AliESDHandler* handler = (AliESDHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
156     
157         if (handler) {
158                 fOutputESD   = handler->GetESD();
159                 fTreeE = handler->GetTree();
160                 fOutputESD->GetStdContent();
161         }
162         else {
163                 AliWarning("No AOD Event Handler connected.") ; 
164         }
165
166         UserCreateOutputObjects();
167 }
168
169 //______________________________________________________________________
170
171 void AliAnalysisTaskFilter::Exec(Option_t* option)
172 {
173         //
174         // Exec analysis of one event
175         //
176
177         if (fDebug > 1) AliInfo("AliAnalysisTaskFilter::Exec() \n");
178
179         if( fInputHandler ) {
180                 fEntry = fInputHandler->GetReadEntry();
181         }
182     
183            
184         if ( !((Entry()-1)%100) && fDebug > 0) {
185                 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
186         }
187         AliESDHandler* handler = (AliESDHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
188         
189         if (UserSelectESDfriendForCurrentEvent()){
190                 // Call the user analysis only if the event was selected   
191                 fOutputESDfriend   = handler->GetESDfriend();
192                 UserExec(option);
193         }
194
195         // Added protection in case the derived task is not an AOD producer.
196         AliAnalysisDataSlot *out0 = GetOutputSlot(0);
197         if (out0 && out0->IsConnected()) PostData(0, fTreeE);    
198 }
199
200 //______________________________________________________________________
201
202 const char* AliAnalysisTaskFilter::CurrentFileName()
203 {
204         // Returns the current file name    
205         if( fInputHandler ){
206                 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
207         }
208         else return "";
209 }
210
211 //______________________________________________________________________
212
213 void AliAnalysisTaskFilter::AddFriendTrackAt(AliESDfriendTrack* t, Int_t index)
214 {
215         //
216         // Adds the friend track at the i-th position in the TClonesArray
217         // of the ESD friend tracks
218         //
219
220         AliESDfriendTrack* currentTrack = (AliESDfriendTrack*)fOutputESDfriend->GetTrack(index);
221         if(currentTrack && currentTrack->GetCalibObject(0)){
222                 AliWarning("Friend already there");
223         }
224         else {
225                 //              AliInfo("Adding track");
226                 fOutputESDfriend->AddTrackAt(t,index);
227         }
228 }