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