]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskFilter.cxx
few changes in configuration VertexingHF for filtering pp 2010 data
[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         fInputESDfriend(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         fOutputESDfriend(0x0),
69         fTreeEF(0x0),
70         fInputESDfriend(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         fOutputESDfriend(0x0),
89         fTreeEF(0x0),
90         fInputESDfriend(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         fOutputESDfriend = obj.fOutputESDfriend;
101         fTreeEF        = obj.fTreeEF;    
102         fInputESDfriend = obj.fInputESDfriend;
103 }
104
105
106 //______________________________________________________________________
107
108 AliAnalysisTaskFilter& AliAnalysisTaskFilter::operator=(const AliAnalysisTaskFilter& other)
109 {
110         //
111         // Assignment
112         //
113
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;
123         }
124         return *this;
125 }
126
127
128 //______________________________________________________________________
129
130 void AliAnalysisTaskFilter::ConnectInputData(Option_t* /*option*/)
131 {
132         //
133         // Connect the input data
134         //
135
136         if (fDebug > 1) printf("AnalysisTaskFilter::ConnectInputData() \n");
137         fInputHandler = (AliInputEventHandler*) 
138                 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
139         if (fInputHandler) {
140                 fInputEvent = fInputHandler->GetEvent();
141                 if (fInputEvent){
142                         fInputESDfriend = (AliESDfriend*)(fInputEvent->FindListObject("AliESDfriend"));
143                         if (!fInputESDfriend){
144                                 AliError("No friend found");
145                         }
146                 }
147                 else {
148                         AliError("No Input Event found, the friend will remain empty");
149                 }
150         } 
151         else {
152                 AliError("No Input Event Handler connected") ; 
153                 return ; 
154         }
155 }
156
157 //______________________________________________________________________
158
159 void AliAnalysisTaskFilter::CreateOutputObjects()
160 {
161         //
162         // Create the output container
163         //
164
165         if (fDebug > 1) printf("AnalysisTaskFilter::CreateOutPutData() \n");
166
167         AliESDHandler* handler = (AliESDHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
168     
169         if (handler) {
170                 fTreeEF = handler->GetTree();
171         }
172         else {
173                 AliWarning("No AOD Event Handler connected.") ; 
174         }
175
176         UserCreateOutputObjects();
177 }
178
179 //______________________________________________________________________
180
181 void AliAnalysisTaskFilter::Exec(Option_t* option)
182 {
183         //
184         // Exec analysis of one event
185         //
186
187         if (fDebug > 1) AliInfo("AliAnalysisTaskFilter::Exec() \n");
188
189         if( fInputHandler ) {
190                 fEntry = fInputHandler->GetReadEntry();
191         }
192     
193            
194         if ( !((Entry()-1)%100) && fDebug > 0) {
195                 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
196         }
197         AliESDHandler* handler = (AliESDHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
198         
199         if (UserSelectESDfriendForCurrentEvent()){
200                 // Call the user analysis only if the event was selected   
201                 handler->SelectEventForFriends();
202                 fOutputESDfriend   = handler->GetESDfriend();
203                 UserExec(option);
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);
209                 }
210         }
211         else {
212                 // Event not selected
213                 AliDebug(2,"The event was not selected");
214         }
215
216         AliAnalysisDataSlot *out0 = GetOutputSlot(0);
217         if (out0 && out0->IsConnected()) PostData(0, fTreeEF);    
218 }
219
220 //______________________________________________________________________
221
222 const char* AliAnalysisTaskFilter::CurrentFileName()
223 {
224         // Returns the current file name    
225         if( fInputHandler ){
226                 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
227         }
228         else return "";
229 }
230
231 //______________________________________________________________________
232
233 void AliAnalysisTaskFilter::AddFriendTrackAt(AliESDfriendTrack* t, Int_t index)
234 {
235         //
236         // Adds the friend track at the i-th position in the TClonesArray
237         // of the ESD friend tracks
238         //
239
240         AliESDfriendTrack* currentTrack = (AliESDfriendTrack*)fOutputESDfriend->GetTrack(index);
241         if(currentTrack){
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);
245                 }
246                 else{
247                         AliDebug(2,Form("Friend at index %d already there and not dummy", index));
248                         return;
249                 }
250         }
251         else{
252                 AliDebug(2,Form("Track at %d not there yet ",index));
253         }
254         AliDebug(2,Form("Adding track at %d",index));
255         fOutputESDfriend->AddTrackAt(t,index);
256         return;
257 }
258
259 //______________________________________________________________________
260
261 void AliAnalysisTaskFilter::SkipFriendTrackAt(Int_t index)
262 {
263         //
264         // Skip the friend track at the i-th position in the TClonesArray
265         // of the ESD friend tracks
266         //
267
268         AliESDfriendTrack* currentTrack = (AliESDfriendTrack*)fOutputESDfriend->GetTrack(index);
269         if (currentTrack){
270                 AliDebug(2,Form("Track already there (no matter what validity) at %d, keeping it as it is", index));
271         }
272         else {
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);
277         }
278         return;
279 }