]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/PartCorrBase/AliAnaPartCorrMaker.cxx
remove assignment operator, not needed and could caus problems due to the TLists
[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 & maker) :   
63 TObject(),
64 fOutputContainer(new TList()), fAnalysisContainer(new TList()), 
65 fMakeHisto(maker.fMakeHisto), fMakeAOD(maker.fMakeAOD), fAnaDebug(maker.fAnaDebug),
66 fReader(new AliCaloTrackReader(*maker.fReader)), fAODBranchList(new TList())
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 //  delete fOutputContainer;   fOutputContainer    = source.fOutputContainer ;
81 //  delete fAnalysisContainer; fAnalysisContainer  = source.fAnalysisContainer ;
82 //  fAnaDebug           = source.fAnaDebug;
83 //  fMakeHisto          = source.fMakeHisto;
84 //  fMakeAOD            = source.fMakeAOD;
85 //  
86 //  delete fReader ;        fReader             = new AliCaloTrackReader(*source.fReader) ;
87 //  delete fAODBranchList; 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           TClonesArray *tca = dynamic_cast<TClonesArray*> (fAODBranchList->At(iaod));
243           if(tca) tca->Delete();
244   }
245
246   //Tell the reader to fill the data in the 3 detector lists
247   Bool_t ok = fReader->FillInputEvent(iEntry, currentFileName);
248   if(!ok){
249           if(fAnaDebug >= 1 )printf("*** Skip event *** %d \n",iEntry);
250           return ;
251   }
252         
253   //printf(">>>>>>>>>> BEFORE >>>>>>>>>>>\n");
254   //gObjectTable->Print();
255   //Loop on analysis algorithms
256   if(fAnaDebug > 0 ) printf("*** Begin analysis *** \n");
257   Int_t nana = fAnalysisContainer->GetEntries() ;
258   for(Int_t iana = 0; iana <  nana; iana++){
259     AliAnaPartCorrBaseClass * ana =  ((AliAnaPartCorrBaseClass *) fAnalysisContainer->At(iana)) ; 
260     
261         ana->ConnectInputOutputAODBranches(); //Sets branches for each analysis
262     //Make analysis, create aods in aod branch or AODCaloClusters
263     if(fMakeAOD)   ana->MakeAnalysisFillAOD()  ;
264     //Make further analysis with aod branch and fill histograms
265     if(fMakeHisto) ana->MakeAnalysisFillHistograms()  ;
266     
267   }
268   
269   fReader->ResetLists();
270   
271   //printf(">>>>>>>>>> AFTER >>>>>>>>>>>\n");
272   //gObjectTable->Print();
273         
274   if(fAnaDebug > 0 ) printf("*** End analysis *** \n");
275   
276 }
277
278 //________________________________________________________________________
279 void AliAnaPartCorrMaker::Terminate(TList * outputList)
280 {  
281   //Execute Terminate of analysis
282   //Do some final plots.
283   
284   if (!outputList) {
285           Error("Terminate", "No output list");
286           return;
287   }
288         
289   for(Int_t iana = 0; iana <  fAnalysisContainer->GetEntries(); iana++){
290     
291     AliAnaPartCorrBaseClass * ana =  ((AliAnaPartCorrBaseClass *) fAnalysisContainer->At(iana)) ;
292     ana->Terminate(outputList);
293     
294   }//Loop on analysis defined
295 }