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 AliAnalysisTask::operator=(other);
115 fDebug = other.fDebug;
116 fEntry = other.fEntry;
117 fInputEvent = other.fInputEvent;
118 fInputHandler = other.fInputHandler;
119 fOutputESDfriend = other.fOutputESDfriend;
120 fTreeEF = other.fTreeEF;
121 fInputESDfriend = other.fInputESDfriend;
126 //______________________________________________________________________
128 void AliAnalysisTaskFilter::ConnectInputData(Option_t* /*option*/)
131 // Connect the input data
134 if (fDebug > 1) printf("AnalysisTaskFilter::ConnectInputData() \n");
135 fInputHandler = (AliInputEventHandler*)
136 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
138 fInputEvent = fInputHandler->GetEvent();
140 fInputESDfriend = (AliESDfriend*)(fInputEvent->FindListObject("AliESDfriend"));
141 if (!fInputESDfriend){
142 AliError("No friend found");
146 AliError("No Input Event found, the friend will remain empty");
150 AliError("No Input Event Handler connected") ;
155 //______________________________________________________________________
157 void AliAnalysisTaskFilter::CreateOutputObjects()
160 // Create the output container
163 if (fDebug > 1) printf("AnalysisTaskFilter::CreateOutPutData() \n");
165 AliESDHandler* handler = (AliESDHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
168 fTreeEF = handler->GetTree();
171 AliWarning("No AOD Event Handler connected.") ;
174 UserCreateOutputObjects();
177 //______________________________________________________________________
179 void AliAnalysisTaskFilter::Exec(Option_t* option)
182 // Exec analysis of one event
185 if (fDebug > 1) AliInfo("AliAnalysisTaskFilter::Exec() \n");
187 if( fInputHandler ) {
188 fEntry = fInputHandler->GetReadEntry();
192 if ( !((Entry()-1)%100) && fDebug > 0) {
193 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
195 AliESDHandler* handler = (AliESDHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
197 if (UserSelectESDfriendForCurrentEvent()){
198 // Call the user analysis only if the event was selected
199 handler->SelectEventForFriends();
200 fOutputESDfriend = handler->GetESDfriend();
202 // copy the VZERO friend only if it is not already there
203 if (fOutputESDfriend->GetVZEROfriend() == 0x0){
204 AliDebug(2,"Copying VZERO friend object");
205 AliESDVZEROfriend* vZEROfriend = fInputESDfriend->GetVZEROfriend();
206 fOutputESDfriend->SetVZEROfriend(vZEROfriend);
210 // Event not selected
211 AliDebug(2,"The event was not selected");
214 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
215 if (out0 && out0->IsConnected()) PostData(0, fTreeEF);
218 //______________________________________________________________________
220 const char* AliAnalysisTaskFilter::CurrentFileName()
222 // Returns the current file name
224 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
229 //______________________________________________________________________
231 void AliAnalysisTaskFilter::AddFriendTrackAt(AliESDfriendTrack* t, Int_t index)
234 // Adds the friend track at the i-th position in the TClonesArray
235 // of the ESD friend tracks
238 AliESDfriendTrack* currentTrack = (AliESDfriendTrack*)fOutputESDfriend->GetTrack(index);
240 if (currentTrack->TestSkipBit()){
241 AliDebug(2,Form("Friend at index %d already there but dummy - the skip bit will be set to FALSE", index));
242 t->SetSkipBit(kFALSE);
245 AliDebug(2,Form("Friend at index %d already there and not dummy", index));
250 AliDebug(2,Form("Track at %d not there yet ",index));
252 AliDebug(2,Form("Adding track at %d",index));
253 fOutputESDfriend->AddTrackAt(t,index);
257 //______________________________________________________________________
259 void AliAnalysisTaskFilter::SkipFriendTrackAt(Int_t index)
262 // Skip the friend track at the i-th position in the TClonesArray
263 // of the ESD friend tracks
266 AliESDfriendTrack* currentTrack = (AliESDfriendTrack*)fOutputESDfriend->GetTrack(index);
268 AliDebug(2,Form("Track already there (no matter what validity) at %d, keeping it as it is", index));
271 AliDebug(2,Form("Adding NULL track at %d, and setting skip bit to TRUE",index));
272 AliESDfriendTrack* tNull = new AliESDfriendTrack();
273 tNull->SetSkipBit(kTRUE);
274 fOutputESDfriend->AddTrackAt(tNull,index);