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