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 **************************************************************************/
18 //////////////////////////////////////////////////////////////////////////
20 // Base class for filtering friends
22 //////////////////////////////////////////////////////////////////////////
28 #include "AliAnalysisTaskFilter.h"
29 #include "AliAnalysisManager.h"
30 #include "AliAnalysisDataSlot.h"
31 #include "AliESDEvent.h"
33 #include "AliVEvent.h"
34 #include "AliESDHandler.h"
35 #include "AliInputEventHandler.h"
37 #include "AliESDfriend.h"
38 #include "AliESDfriendTrack.h"
41 ClassImp(AliAnalysisTaskFilter)
43 ////////////////////////////////////////////////////////////////////////
45 AliAnalysisTaskFilter::AliAnalysisTaskFilter():
51 fOutputESDfriend(0x0),
56 // Default constructor
60 //______________________________________________________________________
62 AliAnalysisTaskFilter::AliAnalysisTaskFilter(const char* name):
63 AliAnalysisTask(name, "AnalysisTaskFilter"),
68 fOutputESDfriend(0x0),
73 // Default constructor
76 DefineInput (0, TChain::Class());
77 DefineOutput(0, TTree::Class());
80 //______________________________________________________________________
82 AliAnalysisTaskFilter::AliAnalysisTaskFilter(const AliAnalysisTaskFilter& obj):
88 fOutputESDfriend(0x0),
98 fInputEvent = obj.fInputEvent;
99 fInputHandler = obj.fInputHandler;
100 fOutputESDfriend = obj.fOutputESDfriend;
101 fTreeEF = obj.fTreeEF;
102 fInputESDfriend = obj.fInputESDfriend;
106 //______________________________________________________________________
108 AliAnalysisTaskFilter& AliAnalysisTaskFilter::operator=(const AliAnalysisTaskFilter& other)
114 if (&other != this) {
115 AliAnalysisTask::operator=(other);
116 fDebug = other.fDebug;
117 fEntry = other.fEntry;
118 fInputEvent = other.fInputEvent;
119 fInputHandler = other.fInputHandler;
120 fOutputESDfriend = other.fOutputESDfriend;
121 fTreeEF = other.fTreeEF;
122 fInputESDfriend = other.fInputESDfriend;
128 //______________________________________________________________________
130 void AliAnalysisTaskFilter::ConnectInputData(Option_t* /*option*/)
133 // Connect the input data
136 if (fDebug > 1) printf("AnalysisTaskFilter::ConnectInputData() \n");
137 fInputHandler = (AliInputEventHandler*)
138 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
140 fInputEvent = fInputHandler->GetEvent();
142 fInputESDfriend = (AliESDfriend*)(fInputEvent->FindListObject("AliESDfriend"));
143 if (!fInputESDfriend){
144 AliError("No friend found");
148 AliError("No Input Event found, the friend will remain empty");
152 AliError("No Input Event Handler connected") ;
157 //______________________________________________________________________
159 void AliAnalysisTaskFilter::CreateOutputObjects()
162 // Create the output container
165 if (fDebug > 1) printf("AnalysisTaskFilter::CreateOutPutData() \n");
167 AliESDHandler* handler = (AliESDHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
170 fTreeEF = handler->GetTree();
173 AliWarning("No AOD Event Handler connected.") ;
176 UserCreateOutputObjects();
179 //______________________________________________________________________
181 void AliAnalysisTaskFilter::Exec(Option_t* option)
184 // Exec analysis of one event
187 if (fDebug > 1) AliInfo("AliAnalysisTaskFilter::Exec() \n");
189 if( fInputHandler ) {
190 fEntry = fInputHandler->GetReadEntry();
194 if ( !((Entry()-1)%100) && fDebug > 0) {
195 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
197 AliESDHandler* handler = (AliESDHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
199 if (UserSelectESDfriendForCurrentEvent()){
200 // Call the user analysis only if the event was selected
201 handler->SelectEventForFriends();
202 fOutputESDfriend = handler->GetESDfriend();
204 // copy the VZERO friend only if it is not already there
205 if (fOutputESDfriend->GetVZEROfriend() == 0x0){
206 AliDebug(2,"Copying VZERO friend object");
207 AliESDVZEROfriend* vZEROfriend = fInputESDfriend->GetVZEROfriend();
208 fOutputESDfriend->SetVZEROfriend(vZEROfriend);
212 // Event not selected
213 AliDebug(2,"The event was not selected");
216 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
217 if (out0 && out0->IsConnected()) PostData(0, fTreeEF);
220 //______________________________________________________________________
222 const char* AliAnalysisTaskFilter::CurrentFileName()
224 // Returns the current file name
226 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
231 //______________________________________________________________________
233 void AliAnalysisTaskFilter::AddFriendTrackAt(AliESDfriendTrack* t, Int_t index)
236 // Adds the friend track at the i-th position in the TClonesArray
237 // of the ESD friend tracks
240 AliESDfriendTrack* currentTrack = (AliESDfriendTrack*)fOutputESDfriend->GetTrack(index);
242 if (currentTrack->TestSkipBit()){
243 AliDebug(2,Form("Friend at index %d already there but dummy - the skip bit will be set to FALSE", index));
244 t->SetSkipBit(kFALSE);
247 AliDebug(2,Form("Friend at index %d already there and not dummy", index));
252 AliDebug(2,Form("Track at %d not there yet ",index));
254 AliDebug(2,Form("Adding track at %d",index));
255 fOutputESDfriend->AddTrackAt(t,index);
259 //______________________________________________________________________
261 void AliAnalysisTaskFilter::SkipFriendTrackAt(Int_t index)
264 // Skip the friend track at the i-th position in the TClonesArray
265 // of the ESD friend tracks
268 AliESDfriendTrack* currentTrack = (AliESDfriendTrack*)fOutputESDfriend->GetTrack(index);
270 AliDebug(2,Form("Track already there (no matter what validity) at %d, keeping it as it is", index));
273 AliDebug(2,Form("Adding NULL track at %d, and setting skip bit to TRUE",index));
274 AliESDfriendTrack* tNull = new AliESDfriendTrack();
275 tNull->SetSkipBit(kTRUE);
276 fOutputESDfriend->AddTrackAt(tNull,index);