]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskSE.cxx
running local for SP and LYZEP and new histograms for QC
[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 "AliESDEvent.h"
28 #include "AliESD.h"
29 #include "AliAODEvent.h"
30 #include "AliAODHeader.h"
31 #include "AliAODTracklets.h"
32 #include "AliVEvent.h"
33 #include "AliAODHandler.h"
34 #include "AliAODInputHandler.h"
35 #include "AliMCEventHandler.h"
36 #include "AliInputEventHandler.h"
37 #include "AliMCEvent.h"
38 #include "AliStack.h"
39 #include "AliLog.h"
40
41
42 ClassImp(AliAnalysisTaskSE)
43
44 ////////////////////////////////////////////////////////////////////////
45 AliAODHeader*    AliAnalysisTaskSE::fgAODHeader        = NULL;
46 TClonesArray*    AliAnalysisTaskSE::fgAODTracks        = NULL;
47 TClonesArray*    AliAnalysisTaskSE::fgAODVertices      = NULL;
48 TClonesArray*    AliAnalysisTaskSE::fgAODV0s           = NULL;
49 TClonesArray*    AliAnalysisTaskSE::fgAODPMDClusters   = NULL;
50 TClonesArray*    AliAnalysisTaskSE::fgAODJets          = NULL;
51 TClonesArray*    AliAnalysisTaskSE::fgAODFMDClusters   = NULL;
52 TClonesArray*    AliAnalysisTaskSE::fgAODCaloClusters  = NULL;
53 AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets     = NULL;
54
55
56 AliAnalysisTaskSE::AliAnalysisTaskSE():
57     AliAnalysisTask(),
58     fDebug(0),
59     fEntry(0),
60     fInputEvent(0x0),
61     fInputHandler(0x0),
62     fOutputAOD(0x0),
63     fMCEvent(0x0),
64     fTreeA(0x0)
65 {
66   // Default constructor
67 }
68
69 AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
70     AliAnalysisTask(name, "AnalysisTaskSE"),
71     fDebug(0),
72     fEntry(0),
73     fInputEvent(0x0),
74     fInputHandler(0x0),
75     fOutputAOD(0x0),
76     fMCEvent(0x0),
77     fTreeA(0x0)
78 {
79   // Default constructor
80     DefineInput (0, TChain::Class());
81     DefineOutput(0,  TTree::Class());
82 }
83
84 AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
85     AliAnalysisTask(obj),
86     fDebug(0),
87     fEntry(0),
88     fInputEvent(0x0),
89     fInputHandler(0x0),
90     fOutputAOD(0x0),
91     fMCEvent(0x0),
92     fTreeA(0x0)
93 {
94 // Copy constructor
95     fDebug        = obj.fDebug;
96     fEntry        = obj.fEntry;
97     fInputEvent   = obj.fInputEvent;
98     fInputHandler = obj.fInputHandler;
99     fOutputAOD    = obj.fOutputAOD;
100     fMCEvent      = obj.fMCEvent;
101     fTreeA        = obj.fTreeA;    
102     printf("Constructor (3) \n");
103 }
104
105
106 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
107 {
108 // Assignment
109     AliAnalysisTask::operator=(other);
110     fDebug        = other.fDebug;
111     fEntry        = other.fEntry;
112     fInputEvent   = other.fInputEvent;
113     fInputHandler = other.fInputHandler;
114     fOutputAOD    = other.fOutputAOD;
115     fMCEvent      = other.fMCEvent;
116     fTreeA        = other.fTreeA;    
117     return *this;
118 }
119
120
121 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
122 {
123 // Connect the input data
124     if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
125 //
126 //  ESD
127 //
128     fInputHandler = (AliInputEventHandler*) 
129          ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
130 //
131 //  Monte Carlo
132 //
133     AliMCEventHandler*    mcH = 0;
134     mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
135     if (mcH) fMCEvent = mcH->MCEvent();
136     
137     
138     if (fInputHandler) {
139          fInputEvent = fInputHandler->GetEvent();
140     } else if( fMCEvent ) {
141          AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ; 
142     } else {
143          AliError("No Input Event Handler connected") ; 
144          return ; 
145     }
146 }
147
148 void AliAnalysisTaskSE::CreateOutputObjects()
149 {
150 // Create the output container
151 //
152 //  Default AOD
153     if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
154
155     AliAODHandler* handler = (AliAODHandler*) 
156          ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
157     
158     // Check if AOD replication has been required
159     
160     if (handler) {
161         fOutputAOD   = handler->GetAOD();
162         fTreeA = handler->GetTree();
163         if (!(handler->IsStandard())) {
164             if ((handler->NeedsHeaderReplication()) && !(fgAODHeader)) 
165                 {
166                  if (fDebug > 1) AliInfo("Replicating header");
167                  fgAODHeader = new AliAODHeader;
168                  handler->AddBranch("AliAODHeader", &fgAODHeader);
169                 }
170             if ((handler->NeedsTracksBranchReplication()) && !(fgAODTracks))      
171             {   
172                 if (fDebug > 1) AliInfo("Replicating track branch\n");
173                 fgAODTracks = new TClonesArray("AliAODTrack",500);
174                 fgAODTracks->SetName("tracks");
175                 handler->AddBranch("TClonesArray", &fgAODTracks);
176             }    
177             if ((handler->NeedsVerticesBranchReplication()) && !(fgAODVertices))
178             {
179                 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
180                 fgAODVertices = new TClonesArray("AliAODVertex",500);
181                 fgAODVertices->SetName("vertices");
182                 handler->AddBranch("TClonesArray", &fgAODVertices);
183             }   
184             if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))    
185             {   
186                 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
187                 fgAODV0s = new TClonesArray("AliAODv0",500);
188                 fgAODV0s->SetName("v0s");
189                 handler->AddBranch("TClonesArray", &fgAODV0s);
190             }
191             if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))        
192             {   
193                 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
194                 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
195                 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
196             }
197             if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))    
198             {   
199                 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
200                 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
201                 fgAODPMDClusters->SetName("pmdClusters");
202                 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
203             }
204             if ((handler->NeedsJetsBranchReplication()) && !(fgAODJets))          
205             {   
206                 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
207                 fgAODJets = new TClonesArray("AliAODJet",500);
208                 fgAODJets->SetName("jets");
209                 handler->AddBranch("TClonesArray", &fgAODJets);
210             }
211             if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))    
212             {   
213                 AliInfo("Replicating FMDClusters branch\n");
214                 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
215                 fgAODFMDClusters->SetName("fmdClusters");
216                 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
217             }
218             if ((handler->NeedsCaloClustersBranchReplication()) && !(fgAODCaloClusters))          
219             {   
220                 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
221                 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
222                 fgAODCaloClusters->SetName("caloClusters");
223                 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
224             }
225         }
226     } else {
227         AliWarning("No AOD Event Handler connected.") ; 
228     }
229     UserCreateOutputObjects();
230 }
231
232 void AliAnalysisTaskSE::Exec(Option_t* option)
233 {
234 //
235 // Exec analysis of one event
236     if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
237     if( fInputHandler ) 
238        fEntry = fInputHandler->GetReadEntry();
239     else if( fMCEvent )
240        fEntry = fMCEvent->Header()->GetEvent(); 
241     if ( !((Entry()-1)%100) && fDebug > 0) 
242          AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
243
244     AliAODHandler* handler = (AliAODHandler*) 
245         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
246     AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
247
248     if (handler && aodH) {
249         if (!(handler->IsStandard()) && !(handler->AODIsReplicated())) {
250             if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
251             {
252               // copy the contents by assigment
253               *fgAODHeader =  *(dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader()));
254             }
255             if ((handler->NeedsTracksBranchReplication()) && (fgAODTracks))
256             {
257                 TClonesArray* tracks = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracks();
258                 new (fgAODTracks) TClonesArray(*tracks);
259             }
260             if ((handler->NeedsVerticesBranchReplication()) && (fgAODVertices))
261             {
262                 TClonesArray* vertices = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetVertices();
263                 new (fgAODVertices) TClonesArray(*vertices);
264             }
265             if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
266             {
267                 TClonesArray* V0s = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetV0s();
268                 new (fgAODV0s) TClonesArray(*V0s);
269             }
270             if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
271             {
272               *fgAODTracklets = *(dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracklets();
273             }
274             if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
275             {
276                 TClonesArray* PMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetPmdClusters();
277                 new (fgAODPMDClusters) TClonesArray(*PMDClusters);
278             }
279             if ((handler->NeedsJetsBranchReplication()) && (fgAODJets))
280             {
281                 TClonesArray* Jets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetJets();
282                 new (fgAODJets) TClonesArray(*Jets);
283             }
284             if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
285             {
286                 TClonesArray* FMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetFmdClusters();
287                 new (fgAODFMDClusters) TClonesArray(*FMDClusters);
288             }
289             if ((handler->NeedsCaloClustersBranchReplication()) && (fgAODCaloClusters))
290             {
291                 TClonesArray* CaloClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetCaloClusters();
292                 new (fgAODCaloClusters) TClonesArray(*CaloClusters);
293             }
294             //
295             handler->SetAODIsReplicated();
296             
297         }
298     }
299
300 // Call the user analysis    
301     UserExec(option);
302     PostData(0, fTreeA);
303     
304 }
305
306 const char* AliAnalysisTaskSE::CurrentFileName()
307 {
308 // Returns the current file name    
309     if( fInputHandler )
310       return fInputHandler->GetTree()->GetCurrentFile()->GetName();
311     else if( fMCEvent )
312       return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
313     else return "";
314 }
315
316 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj)
317 {
318     // Add a new branch to the aod tree
319     AliAODHandler* handler = (AliAODHandler*) 
320         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
321     if (handler) {
322         handler->AddBranch(cname, addobj);
323     }
324 }