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