]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/PartCorrBase/AliAnalysisTaskCaloTrackCorrelationM.cxx
aa74c050ca416474923c3b99dc745ae131916e5e
[u/mrichter/AliRoot.git] / PWG4 / PartCorrBase / AliAnalysisTaskCaloTrackCorrelationM.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 //_________________________________________________________________________
17 // Analysis task that executes the analysis classes
18 // that depend on the CaloTrackCorr frame, frame for Particle identification 
19 // with calorimeters and tracks and correlations.
20 // Specially designed for calorimeters but also can be used for charged tracks
21 // Input of this task is a configuration file that contains all the settings 
22 // of the analysis
23 //
24 // -- Author: Gustavo Conesa (INFN-LNF, LPSC-Grenoble)
25
26 #include <cstdlib>
27
28 // --- Root ---
29 #include <TROOT.h>
30 #include <TInterpreter.h>
31 #include <TClonesArray.h>
32 //#include <Riostream.h>
33 //#include <TObjectTable.h>
34
35 // --- Analysis ---
36 #include "AliAnalysisTaskCaloTrackCorrelationM.h"
37 #include "AliAnaCaloTrackCorrMaker.h"
38 #include "AliCaloTrackReader.h"
39 #include "AliPDG.h"
40 #include "AliAnalysisManager.h"
41 #include "AliMultiEventInputHandler.h"
42 #include "AliMixedEvent.h"
43 #include "AliAODEvent.h"
44 #include "AliESDEvent.h"
45 #include "AliAnalysisDataSlot.h"
46
47 ClassImp(AliAnalysisTaskCaloTrackCorrelationM)
48
49 //__________________________________________________________________________
50 AliAnalysisTaskCaloTrackCorrelationM::AliAnalysisTaskCaloTrackCorrelationM() :
51   AliAnalysisTaskME(),
52   fAna(0x0),
53   fOutputContainer(0x0),
54   fConfigName(""), 
55   fCuts(0x0), 
56   fInputEvent(NULL)
57 {
58   // Default constructor
59 }
60
61 //__________________________________________________________________________________________
62 AliAnalysisTaskCaloTrackCorrelationM::AliAnalysisTaskCaloTrackCorrelationM(const char* name) :
63   AliAnalysisTaskME(name),
64   fAna(0x0),
65   fOutputContainer(0x0),
66   fConfigName(""), 
67   fCuts(0x0), 
68   fInputEvent(NULL)
69 {
70   // Default constructor
71   
72   DefineOutput(1, TList::Class());
73   DefineOutput(2, TList::Class());  // will contain cuts or local params
74 }
75
76 //___________________________________________________________________________
77 AliAnalysisTaskCaloTrackCorrelationM::~AliAnalysisTaskCaloTrackCorrelationM() 
78 {
79   // Remove all pointers
80         
81   //  // Do not delete it here, already done somewhere else, need to understand where.
82   //  if(fOutputContainer && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()){
83   //    fOutputContainer->Clear() ; 
84   //    delete fOutputContainer ;
85   //  }
86   
87   delete fInputEvent ; 
88   if(fAna) delete fAna;
89   
90 }
91
92 //__________________________________________________________________
93 void AliAnalysisTaskCaloTrackCorrelationM::UserCreateOutputObjects()
94 {
95   // Create the output container
96   if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelationM::UserCreateOutputObjects() - Begin\n");
97   
98   //Get list of aod arrays, add each aod array to analysis frame 
99   TClonesArray *array = 0;
100   TList * list = fAna->FillAndGetAODBranchList();
101   if (DebugLevel() >= 1) printf("AliAnalysisTaskCaloTrackCorrelationM::UserCreateOutputObjects() - n AOD branches %d\n",list->GetEntries());
102   
103   //Put the delta AODs in output file, std or delta
104   if((fAna->GetReader())->WriteDeltaAODToFile()){
105     TString deltaAODName = (fAna->GetReader())->GetDeltaAODFileName();
106     for(Int_t iaod = 0; iaod < list->GetEntries(); iaod++){
107       array = (TClonesArray*) list->At(iaod);
108       if(deltaAODName!="") AddAODBranch("TClonesArray", &array, deltaAODName);//Put it in DeltaAOD file
109       else AddAODBranch("TClonesArray", &array);//Put it in standard AOD file
110     } 
111         }
112         
113   //Histograms container
114   OpenFile(1);
115   fOutputContainer = fAna->GetOutputContainer();
116   
117   if (DebugLevel() >= 1) printf("AliAnalysisTaskCaloTrackCorrelationM::UserCreateOutputObjects() - n histograms %d\n",fOutputContainer->GetEntries());
118   
119   fOutputContainer->SetOwner(kTRUE);
120   
121   if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelationM::UserCreateOutputObjects() - End\n");
122   
123   PostData(1,fOutputContainer);
124         
125 }
126
127 //____________________________________________________
128 void AliAnalysisTaskCaloTrackCorrelationM::LocalInit()
129 {
130         // Local Initialization
131         
132         //Call the Init to initialize the configuration of the analysis
133         Init();
134         
135         // Create cuts/param objects and publish to slot
136         fCuts = fAna->GetListOfAnalysisCuts();
137   fCuts ->SetOwner(kTRUE);
138   
139         // Post Data
140         PostData(2, fCuts);
141         
142 }
143
144 //_______________________________________________
145 void AliAnalysisTaskCaloTrackCorrelationM::Init()
146 {
147   // Initialization
148   
149   if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelationM::Init() - Begin\n");
150   
151   fInputEvent = new AliMixedEvent() ; 
152   
153   // Call configuration file if specified
154   
155   if (fConfigName.Length()) {
156     printf("AliAnalysisTaskCaloTrackCorrelationM::Init() - ### Configuration file is %s.C ###\n", fConfigName.Data());
157     gROOT->LoadMacro(fConfigName+".C");
158     fAna = (AliAnaCaloTrackCorrMaker*) gInterpreter->ProcessLine("ConfigAnalysis()");
159   }
160   
161   if(!fAna) {
162     printf("AliAnalysisTaskCaloTrackCorrelationM::Init() - Analysis maker pointer not initialized, no analysis specified, STOP !\n");
163     abort();
164   }
165   
166   // Add different generator particles to PDG Data Base 
167   // to avoid problems when reading MC generator particles
168   AliPDG::AddParticlesToPdgDataBase();
169   
170   //Set in the reader the name of the task in case is needed
171   (fAna->GetReader())->SetTaskName(GetName());
172         
173   // Initialise analysis
174   fAna->Init();
175   
176   //Delta AOD
177   if((fAna->GetReader())->GetDeltaAODFileName()!="")
178           AliAnalysisManager::GetAnalysisManager()->RegisterExtraFile((fAna->GetReader())->GetDeltaAODFileName());
179   
180   if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelationM::Init() - End\n");
181   
182 }
183
184
185 //_______________________________________________________________________
186 void AliAnalysisTaskCaloTrackCorrelationM::UserExec(Option_t */*option*/)
187 {
188   // Execute analysis for current event
189   
190   if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelationM::UserExec() - Begin\n");
191   
192   //Get the type of data, check if type is correct
193   Int_t  datatype = fAna->GetReader()->GetDataType();
194   if(datatype != AliCaloTrackReader::kESD && datatype != AliCaloTrackReader::kAOD &&
195      datatype != AliCaloTrackReader::kMC){
196     printf("AliAnalysisTaskCaloTrackCorrelationM::UserExec() - Wrong type of data\n");
197     return ;
198   }
199   
200   Int_t nev = fInputHandler->GetBufferSize();
201   fInputEvent->Reset();
202   
203   for (Int_t iev = 0; iev < nev; iev++) {
204     if (datatype == AliCaloTrackReader::kESD) {
205       AliESDEvent* esd = dynamic_cast<AliESDEvent*>(GetEvent(iev));
206       fInputEvent->AddEvent(esd);
207     } else if (datatype == AliCaloTrackReader::kAOD) {
208       AliAODEvent* aod = dynamic_cast<AliAODEvent*>(GetEvent(iev));
209       fInputEvent->AddEvent(aod);
210     } else {
211       AliFatal("need to implement mixed event for MC") ; 
212     }
213   }
214   
215   fInputEvent->Init();
216   
217   fAna->GetReader()->SetInputOutputMCEvent(fInputEvent, AODEvent(), MCEvent());
218   
219   //Process event
220   fAna->ProcessEvent((Int_t) Entry(), CurrentFileName());
221   
222   //printf("AliAnalysisTaskCaloTrackCorrelationM::Current Event %d; Current File Name : %s\n",(Int_t) Entry(), CurrentFileName());
223   if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelationM::UserExec() - End\n");
224   
225   PostData(1, fOutputContainer);
226         
227   AliAnalysisDataSlot *out0 = GetOutputSlot(0);
228   if (out0 && out0->IsConnected()) PostData(0, fTreeA);  
229   
230   //gObjectTable->Print();
231   
232 }
233
234 //________________________________________________________________________
235 void AliAnalysisTaskCaloTrackCorrelationM::Terminate(Option_t */*option*/)
236 {
237   // Terminate analysis
238   // Do some plots
239   
240   // Get merged histograms from the output container
241   // Propagate histagrams to maker
242   fAna->Terminate((TList*)GetOutputData(1));
243         
244 }
245