AliRoot Core  3dc7879 (3dc7879)
AliAnalysisTaskFilter.cxx
Go to the documentation of this file.
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 #include <TChain.h>
17 #include <TFile.h>
18 #include <TList.h>
19 
20 #include "AliAnalysisTaskFilter.h"
21 #include "AliAnalysisManager.h"
22 #include "AliAnalysisDataSlot.h"
23 #include "AliESDEvent.h"
24 #include "AliESD.h"
25 #include "AliVEvent.h"
26 #include "AliESDHandler.h"
27 #include "AliInputEventHandler.h"
28 #include "AliLog.h"
29 #include "AliESDfriend.h"
30 #include "AliESDfriendTrack.h"
31 
32 
33 ClassImp(AliAnalysisTaskFilter)
34 
35 
39  fDebug(0),
40  fEntry(0),
41  fInputEvent(0x0),
42  fInputHandler(0x0),
43  fOutputESDfriend(0x0),
44  fTreeEF(0x0),
45  fInputESDfriend(0x0)
46 {
47  //
48  // Default constructor
49  //
50 }
51 
52 //______________________________________________________________________
53 
55  AliAnalysisTask(name, "AnalysisTaskFilter"),
56  fDebug(0),
57  fEntry(0),
58  fInputEvent(0x0),
59  fInputHandler(0x0),
60  fOutputESDfriend(0x0),
61  fTreeEF(0x0),
62  fInputESDfriend(0x0)
63 {
65 
66  DefineInput (0, TChain::Class());
67  DefineOutput(0, TTree::Class());
68 }
69 
70 //______________________________________________________________________
71 
73  AliAnalysisTask(obj),
74  fDebug(0),
75  fEntry(0),
76  fInputEvent(0x0),
77  fInputHandler(0x0),
78  fOutputESDfriend(0x0),
79  fTreeEF(0x0),
80  fInputESDfriend(0x0)
81 {
83 
84  fDebug = obj.fDebug;
85  fEntry = obj.fEntry;
89  fTreeEF = obj.fTreeEF;
91 }
92 
93 
94 //______________________________________________________________________
95 
97 {
99 
100  if (&other != this) {
102  fDebug = other.fDebug;
103  fEntry = other.fEntry;
104  fInputEvent = other.fInputEvent;
107  fTreeEF = other.fTreeEF;
109  }
110  return *this;
111 }
112 
113 
114 //______________________________________________________________________
115 
116 void AliAnalysisTaskFilter::ConnectInputData(Option_t* /*option*/)
117 {
119 
120  if (fDebug > 1) printf("AnalysisTaskFilter::ConnectInputData() \n");
122  ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
123  if (fInputHandler) {
125  if (fInputEvent){
127  if (!fInputESDfriend){
128  AliError("No friend found");
129  }
130  }
131  else {
132  AliError("No Input Event found, the friend will remain empty");
133  }
134  }
135  else {
136  AliError("No Input Event Handler connected") ;
137  return ;
138  }
139 }
140 
141 //______________________________________________________________________
142 
144 {
146 
147  if (fDebug > 1) printf("AnalysisTaskFilter::CreateOutPutData() \n");
148 
149  AliESDHandler* handler = (AliESDHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
150 
151  if (handler) {
152  fTreeEF = handler->GetTree();
153  }
154  else {
155  AliWarning("No AOD Event Handler connected.") ;
156  }
157 
159 }
160 
161 //______________________________________________________________________
162 
163 void AliAnalysisTaskFilter::Exec(Option_t* option)
164 {
166 
167  if (fDebug > 1) AliInfo("AliAnalysisTaskFilter::Exec() \n");
168 
169  if( fInputHandler ) {
171  }
172 
173 
174  if ( !((Entry()-1)%100) && fDebug > 0) {
175  AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
176  }
177  AliESDHandler* handler = (AliESDHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
178 
180  // Call the user analysis only if the event was selected
181  handler->SelectEventForFriends();
182  fOutputESDfriend = handler->GetESDfriend();
183  UserExec(option);
184  // copy the VZERO friend only if it is not already there
185  if (fOutputESDfriend->GetVZEROfriend() == 0x0){
186  AliDebug(2,"Copying VZERO friend object");
188  fOutputESDfriend->SetVZEROfriend(vZEROfriend);
189  }
190  }
191  else {
192  // Event not selected
193  AliDebug(2,"The event was not selected");
194  }
195 
197  if (out0 && out0->IsConnected()) PostData(0, fTreeEF);
198 }
199 
200 //______________________________________________________________________
201 
203 {
205 
206  if( fInputHandler ){
207  return fInputHandler->GetTree()->GetCurrentFile()->GetName();
208  }
209  else return "";
210 }
211 
212 //______________________________________________________________________
213 
215 {
218 
220  if(currentTrack){
221  if (currentTrack->TestSkipBit()){
222  AliDebug(2,Form("Friend at index %d already there but dummy - the skip bit will be set to FALSE", index));
223  t->SetSkipBit(kFALSE);
224  }
225  else{
226  AliDebug(2,Form("Friend at index %d already there and not dummy", index));
227  return;
228  }
229  }
230  else{
231  AliDebug(2,Form("Track at %d not there yet ",index));
232  }
233  AliDebug(2,Form("Adding track at %d",index));
234  fOutputESDfriend->AddTrackAt(t,index);
235  return;
236 }
237 
238 //______________________________________________________________________
239 
241 {
244 
246  if (currentTrack){
247  AliDebug(2,Form("Track already there (no matter what validity) at %d, keeping it as it is", index));
248  }
249  else {
250  AliDebug(2,Form("Adding NULL track at %d, and setting skip bit to TRUE",index));
251  AliESDfriendTrack* tNull = new AliESDfriendTrack();
252  tNull->SetSkipBit(kTRUE);
253  fOutputESDfriend->AddTrackAt(tNull,index);
254  }
255  return;
256 }
AliAnalysysTask - Class representing a basic analysis task. Any user-defined task should derive from...
virtual Long64_t GetReadEntry() const
void SelectEventForFriends()
Definition: AliESDHandler.h:44
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
virtual Bool_t UserSelectESDfriendForCurrentEvent()
void AddFriendTrackAt(AliESDfriendTrack *t, Int_t index)
AliAnalysisTaskFilter & operator=(const AliAnalysisTaskFilter &other)
virtual AliVEvent * GetEvent() const
TTree * fTreeEF
ESD friend output Tree.
Bool_t IsConnected() const
static AliAnalysisManager * GetAnalysisManager()
Bool_t PostData(Int_t iout, TObject *data, Option_t *option="")
void DefineInput(Int_t islot, TClass *type)
AliAnalysisTask & operator=(const AliAnalysisTask &task)
Bool_t TestSkipBit() const
virtual void UserExec(Option_t *)
void SetVZEROfriend(const AliESDVZEROfriend *obj)
void SetSkipBit(Bool_t skip)
AliESDfriend * GetESDfriend()
Definition: AliESDHandler.h:40
#define AliWarning(message)
Definition: AliLog.h:541
virtual TTree * GetTree() const
Definition: AliESDHandler.h:41
virtual TTree * GetTree() const
AliESDfriendTrack * AddTrackAt(const AliESDfriendTrack *t, Int_t i, Bool_t shallow=kFALSE)
Definition: AliESDfriend.h:51
Int_t fEntry
Current entry in the chain.
virtual const char * CurrentFileName()
virtual TObject * FindListObject(const char *name) const =0
AliInputEventHandler * fInputHandler
! Input Handler
AliAnalysysDataSlot Class representing a data slot of an analysis task. An analysis slot enforces a c...
#define AliInfo(message)
Definition: AliLog.h:484
AliVEvent * fInputEvent
! VEvent Input
AliAnalysisDataSlot * GetOutputSlot(Int_t islot) const
AliESDfriend * fInputESDfriend
! ESD friend input
virtual void UserCreateOutputObjects()
virtual void ConnectInputData(Option_t *option="")
AliESDVZEROfriend * GetVZEROfriend()
Definition: AliESDfriend.h:56
virtual Long64_t Entry()
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
Base class for filtering friends.
void SkipFriendTrackAt(Int_t index)
virtual void Exec(Option_t *option)
#define AliError(message)
Definition: AliLog.h:591
void DefineOutput(Int_t islot, TClass *type)
AliESDfriendTrack * GetTrack(Int_t i) const
Definition: AliESDfriend.h:42
AliESDfriend * fOutputESDfriend
! ESD friend out