]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskSE.cxx
fInputHandler set also in CreateOutputObjects
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskSE.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 #include <TROOT.h>
19 #include <TSystem.h>
20 #include <TInterpreter.h>
21 #include <TChain.h>
22 #include <TFile.h>
23 #include <TList.h>
24
25 #include "AliAnalysisTaskSE.h"
26 #include "AliAnalysisManager.h"
27 #include "AliAnalysisCuts.h"
28 #include "AliAnalysisDataSlot.h"
29 #include "AliAnalysisDataContainer.h"
30
31 #include "AliESDEvent.h"
32 #include "AliESDfriend.h"
33 #include "AliESD.h"
34 #include "AliAODEvent.h"
35 #include "AliAODHeader.h"
36 #include "AliAODTracklets.h"
37 #include "AliAODCaloCells.h"
38 #include "AliAODMCParticle.h"
39 #include "AliVEvent.h"
40 #include "AliAODHandler.h"
41 #include "AliAODInputHandler.h"
42 #include "AliMCEventHandler.h"
43 #include "AliInputEventHandler.h"
44 #include "AliMultiInputEventHandler.h"
45 #include "AliESDInputHandler.h"
46 #include "AliMCEvent.h"
47 #include "AliStack.h"
48 #include "AliLog.h"
49 #include "AliAODDimuon.h"
50
51
52 ClassImp(AliAnalysisTaskSE)
53
54 ////////////////////////////////////////////////////////////////////////
55 AliAODHeader*    AliAnalysisTaskSE::fgAODHeader         = NULL;
56 TClonesArray*    AliAnalysisTaskSE::fgAODTracks         = NULL;
57 TClonesArray*    AliAnalysisTaskSE::fgAODVertices       = NULL;
58 TClonesArray*    AliAnalysisTaskSE::fgAODV0s            = NULL;
59 TClonesArray*    AliAnalysisTaskSE::fgAODPMDClusters    = NULL;
60 TClonesArray*    AliAnalysisTaskSE::fgAODJets           = NULL;
61 TClonesArray*    AliAnalysisTaskSE::fgAODFMDClusters    = NULL;
62 TClonesArray*    AliAnalysisTaskSE::fgAODCaloClusters   = NULL;
63 TClonesArray*    AliAnalysisTaskSE::fgAODMCParticles    = NULL;
64 AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets      = NULL;
65 AliAODCaloCells* AliAnalysisTaskSE::fgAODEmcalCells     = NULL;
66 AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells      = NULL;
67 TClonesArray*    AliAnalysisTaskSE::fgAODDimuons        = NULL;
68
69 AliAnalysisTaskSE::AliAnalysisTaskSE():
70     AliAnalysisTask(),
71     fDebug(0),
72     fEntry(0),
73     fInputEvent(0x0),
74     fESDfriend(0x0),
75     fInputHandler(0x0),
76     fOutputAOD(0x0),
77     fMCEvent(0x0),
78     fTreeA(0x0),
79     fCurrentRunNumber(-1),
80     fHistosQA(0x0),
81     fOfflineTriggerMask(0),
82     fMultiInputHandler(0),
83     fMCEventHandler(0)
84 {
85   // Default constructor
86 }
87
88 AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
89     AliAnalysisTask(name, "AnalysisTaskSE"),
90     fDebug(0),
91     fEntry(0),
92     fInputEvent(0x0),
93     fESDfriend(0x0),
94     fInputHandler(0x0),
95     fOutputAOD(0x0),
96     fMCEvent(0x0),
97     fTreeA(0x0),
98     fCurrentRunNumber(-1),
99     fHistosQA(0x0),
100     fOfflineTriggerMask(0),
101     fMultiInputHandler(0),
102     fMCEventHandler(0)
103 {
104   // Default constructor
105     DefineInput (0, TChain::Class());
106     DefineOutput(0,  TTree::Class());
107 }
108
109 AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
110     AliAnalysisTask(obj),
111     fDebug(0),
112     fEntry(0),
113     fInputEvent(0x0),
114     fESDfriend(0x0),
115     fInputHandler(0x0),
116     fOutputAOD(0x0),
117     fMCEvent(0x0),
118     fTreeA(0x0),
119     fCurrentRunNumber(-1),
120     fHistosQA(0x0),
121     fOfflineTriggerMask(0),
122     fMultiInputHandler(obj.fMultiInputHandler),
123     fMCEventHandler(obj.fMCEventHandler)
124 {
125 // Copy constructor
126     fDebug            = obj.fDebug;
127     fEntry            = obj.fEntry;
128     fInputEvent       = obj.fInputEvent;
129     fESDfriend        = obj.fESDfriend;
130     fInputHandler     = obj.fInputHandler;
131     fOutputAOD        = obj.fOutputAOD;
132     fMCEvent          = obj.fMCEvent;
133     fTreeA            = obj.fTreeA;    
134     fCurrentRunNumber = obj.fCurrentRunNumber;
135     fHistosQA         = obj.fHistosQA;
136
137 }
138
139
140 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
141 {
142 // Assignment
143     AliAnalysisTask::operator=(other);
144     fDebug            = other.fDebug;
145     fEntry            = other.fEntry;
146     fInputEvent       = other.fInputEvent;
147     fESDfriend        = other.fESDfriend;
148     fInputHandler     = other.fInputHandler;
149     fOutputAOD        = other.fOutputAOD;
150     fMCEvent          = other.fMCEvent;
151     fTreeA            = other.fTreeA;    
152     fCurrentRunNumber = other.fCurrentRunNumber;
153     fHistosQA         = other.fHistosQA;
154     fOfflineTriggerMask = other.fOfflineTriggerMask;
155     fMultiInputHandler  = other.fMultiInputHandler;
156     fMCEventHandler     = other.fMCEventHandler;
157     return *this;
158 }
159
160 //______________________________________________________________________________
161 Bool_t AliAnalysisTaskSE::CheckPostData() const
162 {
163 // Checks if data was posted to all outputs defined by the task. If task does
164 // not have output slots this returns always kTRUE.
165    AliAnalysisDataContainer *coutput;
166    for (Int_t islot=1; islot<fNoutputs; islot++) {
167       coutput = GetOutputSlot(islot)->GetContainer();
168       if (!coutput->GetData()) return kFALSE;
169    }
170    return kTRUE;
171 }
172
173 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
174 {
175 // Connect the input data
176     if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
177
178    // Connect input handlers (multi input handler is handled)
179    ConnectMultiHandler();
180
181     if (fInputHandler) {
182         if ((fInputHandler->GetTree())->GetBranch("ESDfriend."))
183             fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
184
185         fInputEvent = fInputHandler->GetEvent();
186     } else if( fMCEvent ) {
187          AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ; 
188     } else {
189          AliError("No Input Event Handler connected") ; 
190          return ; 
191     }
192     // Disconnect multi handler
193     DisconnectMultiHandler();
194 }
195
196 void AliAnalysisTaskSE::CreateOutputObjects()
197 {
198 // Create the output container
199 //
200 //  Default AOD
201     if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
202
203     AliAODHandler* handler = dynamic_cast<AliAODHandler*> 
204          ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
205     
206     Bool_t merging = kFALSE;
207     AliAODInputHandler* aodIH = static_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
208     if (aodIH) {
209         if (aodIH->GetMergeEvents()) merging = kTRUE;
210     }
211     
212
213     // Check if AOD replication has been required
214     
215     if (handler) {
216         fOutputAOD   = handler->GetAOD();
217         fTreeA = handler->GetTree();
218         if (fOutputAOD && !(handler->IsStandard())) {
219             if ((handler->NeedsHeaderReplication()) && !(fgAODHeader)) 
220                 {
221                  if (fDebug > 1) AliInfo("Replicating header");
222                  fgAODHeader = new AliAODHeader;
223                  handler->AddBranch("AliAODHeader", &fgAODHeader);
224                 }
225             if ((handler->NeedsTracksBranchReplication() || merging) && !(fgAODTracks))      
226             {   
227                 if (fDebug > 1) AliInfo("Replicating track branch\n");
228                 fgAODTracks = new TClonesArray("AliAODTrack",500);
229                 fgAODTracks->SetName("tracks");
230                 handler->AddBranch("TClonesArray", &fgAODTracks);
231             }    
232             if ((handler->NeedsVerticesBranchReplication() || merging) && !(fgAODVertices))
233             {
234                 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
235                 fgAODVertices = new TClonesArray("AliAODVertex",500);
236                 fgAODVertices->SetName("vertices");
237                 handler->AddBranch("TClonesArray", &fgAODVertices);
238             }   
239             if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))    
240             {   
241                 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
242                 fgAODV0s = new TClonesArray("AliAODv0",500);
243                 fgAODV0s->SetName("v0s");
244                 handler->AddBranch("TClonesArray", &fgAODV0s);
245             }
246             if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))        
247             {   
248                 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
249                 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
250                 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
251             }
252             if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))    
253             {   
254                 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
255                 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
256                 fgAODPMDClusters->SetName("pmdClusters");
257                 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
258             }
259             if ((handler->NeedsJetsBranchReplication() || merging) && !(fgAODJets))       
260             {   
261                 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
262                 fgAODJets = new TClonesArray("AliAODJet",500);
263                 fgAODJets->SetName("jets");
264                 handler->AddBranch("TClonesArray", &fgAODJets);
265             }
266             if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))    
267             {   
268                 AliInfo("Replicating FMDClusters branch\n");
269                 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
270                 fgAODFMDClusters->SetName("fmdClusters");
271                 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
272             }
273             if ((handler->NeedsCaloClustersBranchReplication() || merging) && !(fgAODCaloClusters))       
274             {   
275                 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
276                 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
277                 fgAODCaloClusters->SetName("caloClusters");
278                 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
279
280                 fgAODEmcalCells = new AliAODCaloCells();
281                 fgAODEmcalCells->SetName("emcalCells");
282                 handler->AddBranch("AliAODCaloCells", &fgAODEmcalCells);
283
284                 fgAODPhosCells = new AliAODCaloCells();
285                 fgAODPhosCells->SetName("phosCells");
286                 handler->AddBranch("AliAODCaloCells", &fgAODPhosCells);
287             }
288             if ((handler->NeedsMCParticlesBranchReplication() || merging) && !(fgAODMCParticles))         
289             {   
290                 if (fDebug > 1) AliInfo("Replicating MCParticles branch\n");
291                 fgAODMCParticles = new TClonesArray("AliAODMCParticle",500);
292                 fgAODMCParticles->SetName("mcparticles");
293                 handler->AddBranch("TClonesArray", &fgAODMCParticles);
294             }
295             if ((handler->NeedsDimuonsBranchReplication() || merging) && !(fgAODDimuons))      
296             {   
297                 if (fDebug > 1) AliInfo("Replicating dimuon branch\n");
298                 fgAODDimuons = new TClonesArray("AliAODDimuon",0);
299                 fgAODDimuons->SetName("dimuons");
300                 handler->AddBranch("TClonesArray", &fgAODDimuons);
301             }    
302
303             // cache the pointerd in the AODEvent
304             fOutputAOD->GetStdContent();
305         }
306     }
307     ConnectMultiHandler();
308     UserCreateOutputObjects();
309     DisconnectMultiHandler();
310 }
311
312 void AliAnalysisTaskSE::Exec(Option_t* option)
313 {
314 //
315 // Exec analysis of one event
316
317     ConnectMultiHandler();
318
319     if ( fDebug >= 10)
320       printf("Task is active %5d\n", IsActive());
321     
322     if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
323 //
324     AliAODHandler* handler = dynamic_cast<AliAODHandler*> 
325         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
326
327     AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
328 //
329 // Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
330     UInt_t isSelected = AliVEvent::kAny;
331     if( fInputHandler && fInputHandler->GetEventSelection()) {
332       // Get the actual offline trigger mask for the event and AND it with the
333       // requested mask. If no mask requested select by default the event.
334       if (fOfflineTriggerMask)
335          isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
336     }
337 //  Functionality below moved in the filter tasks (AG)
338 //    if (handler) handler->SetFillAOD(isSelected);
339
340     if( fInputHandler ) {
341         fEntry = fInputHandler->GetReadEntry();
342         fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
343     }
344     
345
346 // Notify the change of run number
347     if (InputEvent() && (InputEvent()->GetRunNumber() != fCurrentRunNumber)) {
348         fCurrentRunNumber = InputEvent()->GetRunNumber();
349         NotifyRun();
350     }    
351            
352     else if( fMCEvent )
353        fEntry = fMCEvent->Header()->GetEvent(); 
354     if ( !((Entry()-1)%100) && fDebug > 0) 
355          AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
356
357     
358     
359
360     if (handler && aodH) {
361         fMCEvent = aodH->MCEvent();
362         Bool_t merging = aodH->GetMergeEvents();
363         AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
364
365         if (aod && !(handler->IsStandard()) && !(handler->AODIsReplicated())) {
366             if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
367             {
368               // copy the contents by assigment
369               *fgAODHeader =  *(aod->GetHeader());
370             }
371             if ((handler->NeedsTracksBranchReplication() || merging) && (fgAODTracks))
372             {
373                 TClonesArray* tracks = aod->GetTracks();
374                 new (fgAODTracks) TClonesArray(*tracks);
375             }
376             if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
377             {
378                 TClonesArray* vertices = aod->GetVertices();
379                 new (fgAODVertices) TClonesArray(*vertices);
380             }
381             if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
382             {
383                 TClonesArray* v0s = aod->GetV0s();
384                 new (fgAODV0s) TClonesArray(*v0s);
385             }
386             if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
387             {
388               *fgAODTracklets = *aod->GetTracklets();
389             }
390             if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
391             {
392                 TClonesArray* pmdClusters = aod->GetPmdClusters();
393                 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
394             }
395             if ((handler->NeedsJetsBranchReplication() || merging) && (fgAODJets))
396             {
397                 TClonesArray* jets = aod->GetJets();
398                 new (fgAODJets) TClonesArray(*jets);
399             }
400             if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
401             {
402                 TClonesArray* fmdClusters = aod->GetFmdClusters();
403                 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
404             }
405             if ((handler->NeedsCaloClustersBranchReplication() || merging) && (fgAODCaloClusters))
406             {
407                 TClonesArray* caloClusters = aod->GetCaloClusters();
408                 new (fgAODCaloClusters) TClonesArray(*caloClusters);
409             }
410
411             if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
412             {
413                 TClonesArray* mcParticles = (TClonesArray*) (aod->FindListObject("mcparticles"));
414                 new (fgAODMCParticles) TClonesArray(*mcParticles);
415             }
416             
417             if ((handler->NeedsDimuonsBranchReplication() || merging) && (fgAODDimuons))
418             {
419                 fgAODDimuons->Clear();
420                 TClonesArray& dimuons = *fgAODDimuons;
421                 TClonesArray& tracksnew = *fgAODTracks;
422                 
423                 Int_t nMuonTrack[100]; 
424                 for(Int_t imuon = 0; imuon < 100; imuon++) nMuonTrack[imuon] = 0;
425                 Int_t nMuons=0;
426                 for(Int_t ii=0; ii < fgAODTracks->GetEntries(); ii++){
427                     AliAODTrack *track = (AliAODTrack*) fgAODTracks->At(ii);
428                     if(track->IsMuonTrack()) {
429                         nMuonTrack[nMuons]= ii;
430                         nMuons++;
431                     }  
432                 }
433                 Int_t jDimuons=0;
434                 if(nMuons >= 2){
435                     for(Int_t i = 0; i < nMuons; i++){
436                         Int_t index0 = nMuonTrack[i];
437                         for(Int_t j = i+1; j < nMuons; j++){
438                             Int_t index1 = nMuonTrack[j];
439                             tracksnew.At(index0)->ResetBit(kIsReferenced);
440                             tracksnew.At(index0)->SetUniqueID(0); 
441                             tracksnew.At(index1)->ResetBit(kIsReferenced);
442                             tracksnew.At(index1)->SetUniqueID(0);
443                             new(dimuons[jDimuons++]) AliAODDimuon(tracksnew.At(index0),tracksnew.At(index1));
444                         }
445                     }    
446                 }
447             }
448             
449             // Additional merging if needed
450             if (merging) {
451                 // mcParticles
452                 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
453                 Int_t npart = mcparticles->GetEntries();
454                 Int_t nc = fgAODMCParticles->GetEntries();
455                 Int_t nc0 = nc;
456                 
457                 for (Int_t i = 0; i < npart; i++) {
458                     AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
459                     new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
460                 }
461                 
462                 // tracks
463                 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
464                 Int_t ntr = tracks->GetEntries();
465                 nc  = fgAODTracks->GetEntries();        
466                 for (Int_t i = 0; i < ntr; i++) {
467                     AliAODTrack*    track = (AliAODTrack*) tracks->At(i);
468                     AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
469                     newtrack->SetLabel(newtrack->GetLabel() + nc0);
470                 }
471
472                 for (Int_t i = 0; i < nc; i++) 
473                 {
474                     AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
475                     track->ResetBit(kIsReferenced);
476                     track->SetUniqueID(0);
477                 }
478                 
479                 
480                 // clusters
481                 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
482                 Int_t ncl  = clusters->GetEntries();
483                 nc         =  fgAODCaloClusters->GetEntries();
484                 for (Int_t i = 0; i < ncl; i++) {
485                     AliAODCaloCluster*    cluster = (AliAODCaloCluster*) clusters->At(i);
486                     new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
487                 }
488                 // cells
489                 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
490                 Int_t ncells  = cellsA->GetNumberOfCells();
491                 nc = fgAODEmcalCells->GetNumberOfCells();
492                 
493                 for (Int_t i  = 0; i < ncells; i++) {
494                     Int_t cn  = cellsA->GetCellNumber(i);
495                     Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
496                     if (pos >= 0) {
497                         Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
498                         fgAODEmcalCells->SetCell(pos, cn, amp);
499                     } else {
500                         Double_t amp = cellsA->GetAmplitude(i);
501                         fgAODEmcalCells->SetCell(nc++, cn, amp);
502                         fgAODEmcalCells->Sort();
503                     }
504                 }
505                 
506                 
507             } // merging
508             
509             handler->SetAODIsReplicated();
510         }
511     }
512
513 // Call the user analysis    
514     if (!fMCEventHandler) {
515         if (isSelected) 
516             UserExec(option);
517     } else {
518         if (isSelected && (fMCEventHandler->InitOk())) 
519             UserExec(option);
520     }
521     
522 // Added protection in case the derived task is not an AOD producer.
523     AliAnalysisDataSlot *out0 = GetOutputSlot(0);
524     if (out0 && out0->IsConnected()) PostData(0, fTreeA);    
525     
526     DisconnectMultiHandler();
527 }
528
529 const char* AliAnalysisTaskSE::CurrentFileName()
530 {
531 // Returns the current file name    
532     if( fInputHandler )
533       return fInputHandler->GetTree()->GetCurrentFile()->GetName();
534     else if( fMCEvent )
535       return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
536     else return "";
537 }
538
539 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
540 {
541     // Add a new branch to the aod tree
542     AliAODHandler* handler = dynamic_cast<AliAODHandler*> 
543         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
544     if (handler) {
545         handler->AddBranch(cname, addobj, fname);
546     }
547 }
548
549 Bool_t AliAnalysisTaskSE::IsStandardAOD() const
550 {
551 // Check if the output AOD handler is configured for standard or delta AOD.
552 // Users should first check that AODEvent() returns non-null.
553     AliAODHandler* handler = dynamic_cast<AliAODHandler*> 
554          ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
555     if (!handler) {
556        Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
557        return kTRUE;
558     }
559     return handler->IsStandard();   
560 }
561
562 Bool_t AliAnalysisTaskSE::Notify()
563 {
564     return (UserNotify());
565 }
566
567 const AliEventTag *AliAnalysisTaskSE::EventTag() const
568 {
569 // Returns tag for the current event, if any. The return value should always be checked by the user.
570    if (!fInputHandler) {
571       Error("EventTag", "Input handler not yet available. Call this in UserExec");
572       return NULL;
573    }
574    return fInputHandler->GetEventTag();
575 }
576
577 void AliAnalysisTaskSE::LoadBranches() const
578 {
579 // Load all branches declared in fBranchNames data member of the parent class.
580 // Should be called in UserExec.
581   if (!fInputHandler) {
582      Error("LoadBranches", "Input handler not available yet. Call this in UserExec");
583      return;
584   }
585   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
586   if (mgr->GetAutoBranchLoading()) return;
587   TString taskbranches;
588   GetBranches(fInputHandler->GetDataType(), taskbranches);
589   if (taskbranches.IsNull()) return;
590   TObjArray *arr = taskbranches.Tokenize(",");
591   TIter next(arr);
592   TObject *obj;
593   while ((obj=next())) mgr->LoadBranch(obj->GetName());
594 }
595
596
597 //_________________________________________________________________________________________________
598 void AliAnalysisTaskSE::ConnectMultiHandler()
599 {
600    //
601    // Connect MultiHandler
602    //
603    fInputHandler = (AliInputEventHandler *)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
604    fMultiInputHandler = dynamic_cast<AliMultiInputEventHandler *>(fInputHandler);
605    if (fMultiInputHandler) {
606       fInputHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstInputEventHandler());
607       fMCEventHandler = dynamic_cast<AliMCEventHandler *>(fMultiInputHandler->GetFirstMCEventHandler());
608    } else { 
609       fMCEventHandler = dynamic_cast<AliMCEventHandler *>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
610    }
611    if (fMCEventHandler) fMCEvent = fMCEventHandler->MCEvent();
612 }
613
614 //_________________________________________________________________________________________________
615 void AliAnalysisTaskSE::DisconnectMultiHandler()
616 {
617    //
618    // Disconnect MultiHandler
619    //
620    if (fMultiInputHandler) fInputHandler = fMultiInputHandler;
621 }