]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/PartCorrBase/AliAnaPartCorrMaker.cxx
1) Changes needed to read deltaAODs as input, handling of acces to delta AO branches...
[u/mrichter/AliRoot.git] / PWG4 / PartCorrBase / AliAnaPartCorrMaker.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 /* $Id: $ */
16
17 //_________________________________________________________________________
18 // Steering class for particle (gamma, hadron) identification and correlation analysis
19 // It is called by the task class AliAnalysisTaskParticleCorrelation and it connects the input 
20 // (ESD/AOD/MonteCarlo) got with AliCaloTrackReader (produces TClonesArrays of AODs 
21 // (TParticles in MC case if requested)), with the 
22 // analysis classes that derive from AliAnaPartCorrBaseClass
23 //
24 // -- Author: Gustavo Conesa (INFN-LNF)
25
26 #include <cstdlib>
27
28 // --- ROOT system ---
29 #include "TClonesArray.h"
30 #include "TList.h"
31 #include "TH1.h"
32 //#include "Riostream.h"
33 //#include <TObjectTable.h>
34
35 //---- AliRoot system ---- 
36 #include "AliAnaPartCorrBaseClass.h" 
37 #include "AliAnaPartCorrMaker.h" 
38 #include "AliCaloTrackReader.h" 
39
40
41 ClassImp(AliAnaPartCorrMaker)
42
43
44 //____________________________________________________________________________
45 AliAnaPartCorrMaker::AliAnaPartCorrMaker() : 
46 TObject(),
47 fOutputContainer(new TList ), fAnalysisContainer(new TList ),
48 fMakeHisto(0), fMakeAOD(0), fAnaDebug(0), 
49 fReader(0x0), fAODBranchList(new TList )
50 {
51   //Default Ctor
52   if(fAnaDebug > 1 ) printf("*** Analysis Maker  Constructor *** \n");
53   
54   //Initialize parameters, pointers and histograms
55   if(!fReader)
56     fReader = new AliCaloTrackReader();
57   
58   InitParameters();
59 }
60
61 //____________________________________________________________________________
62 AliAnaPartCorrMaker::AliAnaPartCorrMaker(const AliAnaPartCorrMaker & g) :   
63 TObject(),
64 fOutputContainer(g. fOutputContainer), fAnalysisContainer(g.fAnalysisContainer), 
65 fMakeHisto(g.fMakeHisto), fMakeAOD(fMakeAOD), fAnaDebug(g. fAnaDebug),
66 fReader(g.fReader), fAODBranchList(g.fAODBranchList)
67 {
68   // cpy ctor
69         
70 }
71
72 //_________________________________________________________________________
73 AliAnaPartCorrMaker & AliAnaPartCorrMaker::operator = (const AliAnaPartCorrMaker & source)
74 {
75   // assignment operator
76   
77   if(this == &source)return *this;
78   ((TObject *)this)->operator=(source);
79   
80   fOutputContainer    = source.fOutputContainer ;
81   fAnalysisContainer  = source.fAnalysisContainer ;
82   fAnaDebug           = source.fAnaDebug;
83   fMakeHisto          = source.fMakeHisto;
84   fMakeAOD            = source.fMakeAOD;
85   
86   fReader             = source.fReader ;
87   fAODBranchList      = source.fAODBranchList;
88         
89   return *this;
90   
91 }
92
93 //____________________________________________________________________________
94 AliAnaPartCorrMaker::~AliAnaPartCorrMaker() 
95 {
96   // Remove all pointers.
97   
98   // Protection added in case of NULL pointers (MG)
99   if (fOutputContainer) {
100     fOutputContainer->Clear();
101     delete fOutputContainer ;
102   }   
103   
104   if (fAnalysisContainer) {
105     fAnalysisContainer->Clear();
106     delete fAnalysisContainer ;
107   }   
108   
109   if (fReader) delete fReader ;
110   
111   
112   if(fAODBranchList){
113 //              for(Int_t iaod = 0; iaod < fAODBranchList->GetEntries(); iaod++)
114 //                      fAODBranchList->At(iaod)->Clear();
115         
116     fAODBranchList->Clear();
117     delete fAODBranchList ;
118   }
119   
120 }
121
122 //________________________________________________________________________
123 TList * AliAnaPartCorrMaker::GetAODBranchList()
124
125
126 // Get any new output AOD branches from analysis and put them in a list
127 // The list is filled in the maker, and new branch passed to the analysis frame
128 // AliAnalysisTaskPartCorr
129  
130   for(Int_t iana = 0; iana <  fAnalysisContainer->GetEntries(); iana++){
131     
132     AliAnaPartCorrBaseClass * ana =  ((AliAnaPartCorrBaseClass *) fAnalysisContainer->At(iana)) ;
133     if(ana->NewOutputAOD()) fAODBranchList->Add(ana->GetCreateOutputAODBranch());
134   }
135   
136   return fAODBranchList ;
137   
138 }
139
140 //________________________________________________________________________
141 TList *AliAnaPartCorrMaker::GetOutputContainer()
142 {
143 // Fill the output list of histograms during the CreateOutputObjects stage.
144   if(!fAnalysisContainer || fAnalysisContainer->GetEntries()==0){
145     printf("AliAnaPartCorrMaker::GetOutputContainer() - Analysis job list not initialized!!!\n");
146     //abort();
147   }
148
149   char newname[128];
150   for(Int_t iana = 0; iana <  fAnalysisContainer->GetEntries(); iana++){
151     AliAnaPartCorrBaseClass * ana =  ((AliAnaPartCorrBaseClass *) fAnalysisContainer->At(iana)) ;
152     if(fMakeHisto){// Analysis with histograms as output on
153       //Fill container with appropriate histograms                      
154       TList * templist =  ana -> GetCreateOutputObjects(); 
155       for(Int_t i = 0; i < templist->GetEntries(); i++){
156
157         //Add only  to the histogram name the name of the task
158         if(   strcmp((templist->At(i))->ClassName(),"TObjString")   ) {
159           sprintf(newname,"%s%s", (ana->GetAddedHistogramsStringToName()).Data(), (templist->At(i))->GetName());  
160           ((TH1*) templist->At(i))->SetName(newname);
161         }
162         //Add histogram to general container
163         fOutputContainer->Add(templist->At(i)) ;
164       }
165     }// Analysis with histograms as output on
166   }//Loop on analysis defined
167   
168   return fOutputContainer;
169
170 }
171
172 //________________________________________________________________________
173 void AliAnaPartCorrMaker::Init()
174 {  
175   //Init container histograms and other common variables
176   // Fill the output list of histograms during the CreateOutputObjects stage.
177  
178   if(!fAnalysisContainer || fAnalysisContainer->GetEntries()==0){
179     printf("AliAnaPartCorrMaker::GetOutputInit() - Analysis job list not initialized!!!\n");
180     //abort();
181   }
182
183   //Initialize reader
184   fReader->Init();
185         
186   for(Int_t iana = 0; iana <  fAnalysisContainer->GetEntries(); iana++){
187     
188     AliAnaPartCorrBaseClass * ana =  ((AliAnaPartCorrBaseClass *) fAnalysisContainer->At(iana)) ;
189     ana->SetReader(fReader); //SetReader for each analysis
190     ana->Init();
191     
192   }//Loop on analysis defined
193 }
194
195 //____________________________________________________________________________
196 void AliAnaPartCorrMaker::InitParameters()
197 {       
198   //Init data members
199   
200   fMakeHisto = kTRUE;
201   fMakeAOD = kTRUE; 
202   fAnaDebug = 0; // No debugging info displayed by default
203         
204 }
205
206 //__________________________________________________________________
207 void AliAnaPartCorrMaker::Print(const Option_t * opt) const
208 {       
209   //Print some relevant parameters set for the analysis
210         
211   if(! opt)
212     return;
213   
214   printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
215   printf("Debug level                =     %d\n", fAnaDebug) ;
216   printf("Produce Histo              =     %d\n", fMakeHisto) ;
217   printf("Produce AOD                =     %d\n", fMakeAOD) ;
218  
219
220
221
222 //____________________________________________________________________________
223 void AliAnaPartCorrMaker::ProcessEvent(const Int_t iEntry, const char * currentFileName){
224   //Process analysis for this event
225   
226   if(fMakeHisto && !fOutputContainer){
227     printf("AliAnaPartCorrMaker::ProcessEvent() - Histograms not initialized\n");
228     abort();
229   }
230         
231   if(fAnaDebug >= 0 ){ 
232                 printf("***  Event %d   ***  \n",iEntry);
233           if(fAnaDebug > 1 ) {
234                   printf("AliAnaPartCorrMaker::ProcessEvent() - Current File Name : %s\n", currentFileName);
235                   //printf("fAODBranchList %p, entries %d\n",fAODBranchList,fAODBranchList->GetEntries());
236           }
237   }
238   //Each event needs an empty branch
239   Int_t nAODBranches = fAODBranchList->GetEntries();
240   for(Int_t iaod = 0; iaod < nAODBranches; iaod++)
241                 fAODBranchList->At(iaod)->Clear();
242
243   //Tell the reader to fill the data in the 3 detector lists
244   Bool_t ok = fReader->FillInputEvent(iEntry, currentFileName);
245   if(!ok){
246           if(fAnaDebug >= 1 )printf("*** Skip event *** %d \n",iEntry);
247           return ;
248   }
249         
250   //printf(">>>>>>>>>> BEFORE >>>>>>>>>>>\n");
251   //gObjectTable->Print();
252   //Loop on analysis algorithms
253   if(fAnaDebug > 0 ) printf("*** Begin analysis *** \n");
254   Int_t nana = fAnalysisContainer->GetEntries() ;
255   for(Int_t iana = 0; iana <  nana; iana++){
256     AliAnaPartCorrBaseClass * ana =  ((AliAnaPartCorrBaseClass *) fAnalysisContainer->At(iana)) ; 
257     
258         ana->ConnectInputOutputAODBranches(); //Sets branches for each analysis
259     //Make analysis, create aods in aod branch or AODCaloClusters
260     if(fMakeAOD)   ana->MakeAnalysisFillAOD()  ;
261     //Make further analysis with aod branch and fill histograms
262     if(fMakeHisto) ana->MakeAnalysisFillHistograms()  ;
263     
264   }
265   
266   fReader->ResetLists();
267   
268   //printf(">>>>>>>>>> AFTER >>>>>>>>>>>\n");
269   //gObjectTable->Print();
270         
271   if(fAnaDebug > 0 ) printf("*** End analysis *** \n");
272   
273 }
274
275 //________________________________________________________________________
276 void AliAnaPartCorrMaker::Terminate(TList * outputList)
277 {  
278   //Execute Terminate of analysis
279   //Do some final plots.
280   
281   if (!outputList) {
282           Error("Terminate", "No output list");
283           return;
284   }
285         
286   for(Int_t iana = 0; iana <  fAnalysisContainer->GetEntries(); iana++){
287     
288     AliAnaPartCorrBaseClass * ana =  ((AliAnaPartCorrBaseClass *) fAnalysisContainer->At(iana)) ;
289     ana->Terminate(outputList);
290     
291   }//Loop on analysis defined
292 }