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