major dielectron update (included also the data and plotting macros for paper)
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliAnalysisTaskMultiDielectron.cxx
CommitLineData
b2a297fa 1/*************************************************************************
2* Copyright(c) 1998-2009, 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// //
18// Basic Analysis Task //
19// //
20///////////////////////////////////////////////////////////////////////////
21
22#include <TChain.h>
61d106d3 23#include <TH1D.h>
b2a297fa 24
25#include <AliCFContainer.h>
572b0139 26#include <AliInputEventHandler.h>
27#include <AliESDInputHandler.h>
ffbede40 28#include <AliAODInputHandler.h>
572b0139 29#include <AliAnalysisManager.h>
b2a297fa 30#include <AliVEvent.h>
2a14a7b1 31#include <AliTriggerAnalysis.h>
b2a297fa 32
33#include "AliDielectron.h"
34#include "AliDielectronHistos.h"
35#include "AliDielectronCF.h"
572b0139 36#include "AliDielectronMC.h"
b2a297fa 37#include "AliAnalysisTaskMultiDielectron.h"
38
39ClassImp(AliAnalysisTaskMultiDielectron)
40
41//_________________________________________________________________________________
42AliAnalysisTaskMultiDielectron::AliAnalysisTaskMultiDielectron() :
43 AliAnalysisTaskSE(),
44 fListDielectron(),
45 fListHistos(),
572b0139 46 fListCF(),
61d106d3 47 fSelectPhysics(kFALSE),
48 fTriggerMask(AliVEvent::kMB),
2a14a7b1 49 fTriggerOnV0AND(kFALSE),
50 fRejectPileup(kFALSE),
51 fTriggerAnalysis(0x0),
52 fEventFilter(0x0),
61d106d3 53 fEventStat(0x0)
b2a297fa 54{
55 //
56 // Constructor
57 //
58}
59
60//_________________________________________________________________________________
61AliAnalysisTaskMultiDielectron::AliAnalysisTaskMultiDielectron(const char *name) :
62 AliAnalysisTaskSE(name),
63 fListDielectron(),
64 fListHistos(),
572b0139 65 fListCF(),
61d106d3 66 fSelectPhysics(kFALSE),
67 fTriggerMask(AliVEvent::kMB),
2a14a7b1 68 fTriggerOnV0AND(kFALSE),
69 fRejectPileup(kFALSE),
70 fTriggerAnalysis(0x0),
71 fEventFilter(0x0),
61d106d3 72 fEventStat(0x0)
b2a297fa 73{
74 //
75 // Constructor
76 //
77 DefineInput(0,TChain::Class());
78 DefineOutput(1, TList::Class());
79 DefineOutput(2, TList::Class());
61d106d3 80 DefineOutput(3, TH1D::Class());
b2a297fa 81 fListHistos.SetName("Dielectron_Histos_Multi");
82 fListCF.SetName("Dielectron_CF_Multi");
2a14a7b1 83 fListDielectron.SetOwner();
84 fListHistos.SetOwner();
85 fListCF.SetOwner();
b2a297fa 86}
87
88
89//_________________________________________________________________________________
90void AliAnalysisTaskMultiDielectron::UserCreateOutputObjects()
91{
92 //
93 // Add all histogram manager histogram lists to the output TList
94 //
95
572b0139 96 if (!fListHistos.IsEmpty()||!fListCF.IsEmpty()) return; //already initialised
b2a297fa 97
2a14a7b1 98 AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
99 Bool_t isESD=man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class();
ffbede40 100// Bool_t isAOD=man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();
2a14a7b1 101
b2a297fa 102 TIter nextDie(&fListDielectron);
103 AliDielectron *die=0;
104 while ( (die=static_cast<AliDielectron*>(nextDie())) ){
105 die->Init();
106 if (die->GetHistogramList()) fListHistos.Add(const_cast<THashList*>(die->GetHistogramList()));
107 if (die->GetCFManagerPair()) fListCF.Add(const_cast<AliCFContainer*>(die->GetCFManagerPair()->GetContainer()));
108 }
61d106d3 109
48609e3d 110 Int_t cuts=fListDielectron.GetEntries();
2a14a7b1 111 Int_t nbins=kNbinsEvent+2*cuts;
61d106d3 112 if (!fEventStat){
48609e3d 113 fEventStat=new TH1D("hEventStat","Event statistics",nbins,0,nbins);
61d106d3 114 fEventStat->GetXaxis()->SetBinLabel(1,"Before Phys. Sel.");
115 fEventStat->GetXaxis()->SetBinLabel(2,"After Phys. Sel.");
ba15fdfb 116
117 //default names
118 fEventStat->GetXaxis()->SetBinLabel(3,"Bin3 not used");
119 fEventStat->GetXaxis()->SetBinLabel(4,"Bin4 not used");
120 fEventStat->GetXaxis()->SetBinLabel(5,"Bin5 not used");
121
2a14a7b1 122 if (fTriggerOnV0AND&&isESD) fEventStat->GetXaxis()->SetBinLabel(3,"V0and triggers");
123 if (fEventFilter) fEventStat->GetXaxis()->SetBinLabel(4,"After Event Filter");
124 if (fRejectPileup) fEventStat->GetXaxis()->SetBinLabel(5,"After Pileup rejection");
125
48609e3d 126 for (Int_t i=0; i<cuts; ++i){
2a14a7b1 127 fEventStat->GetXaxis()->SetBinLabel((kNbinsEvent+1)+2*i,Form("#splitline{1 candidate}{%s}",fListDielectron.At(i)->GetName()));
128 fEventStat->GetXaxis()->SetBinLabel((kNbinsEvent+2)+2*i,Form("#splitline{With >1 candidate}{%s}",fListDielectron.At(i)->GetName()));
48609e3d 129 }
61d106d3 130 }
2a14a7b1 131
132 if (!fTriggerAnalysis) fTriggerAnalysis=new AliTriggerAnalysis;
133 fTriggerAnalysis->EnableHistograms();
134 fTriggerAnalysis->SetAnalyzeMC(AliDielectronMC::Instance()->HasMC());
61d106d3 135
136 PostData(1, &fListHistos);
137 PostData(2, &fListCF);
138 PostData(3, fEventStat);
b2a297fa 139}
140
141//_________________________________________________________________________________
142void AliAnalysisTaskMultiDielectron::UserExec(Option_t *)
143{
144 //
145 // Main loop. Called for every event
146 //
147
572b0139 148 if (fListHistos.IsEmpty()&&fListCF.IsEmpty()) return;
149
150 AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
2a14a7b1 151 Bool_t isESD=man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class();
ffbede40 152 Bool_t isAOD=man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();
ba15fdfb 153
154 AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
155
156 if ( inputHandler->GetPIDResponse() ){
157 AliDielectronVarManager::SetPIDResponse( inputHandler->GetPIDResponse() );
572b0139 158 } else {
159 //load esd pid bethe bloch parameters depending on the existance of the MC handler
160 // yes: MC parameters
161 // no: data parameters
2a14a7b1 162
163 //ESD case
164 if (isESD){
165 if (!AliDielectronVarManager::GetESDpid()){
166
167 if (AliDielectronMC::Instance()->HasMC()) {
168 AliDielectronVarManager::InitESDpid();
169 } else {
170 AliDielectronVarManager::InitESDpid(1);
171 }
172 }
173 }
174 //AOD case
175 if (isAOD){
176 if (!AliDielectronVarManager::GetAODpidUtil()){
177 if (AliDielectronMC::Instance()->HasMC()) {
178 AliDielectronVarManager::InitAODpidUtil();
179 } else {
180 AliDielectronVarManager::InitAODpidUtil(1);
181 }
572b0139 182 }
183 }
184 }
185 // Was event selected ?
61d106d3 186 UInt_t isSelected = AliVEvent::kAny;
572b0139 187 if( fSelectPhysics && inputHandler && inputHandler->GetEventSelection() ) {
188 isSelected = inputHandler->IsEventSelected();
61d106d3 189 isSelected&=fTriggerMask;
572b0139 190 }
191
61d106d3 192 //Before physics selection
2a14a7b1 193 fEventStat->Fill(kAllEvents);
61d106d3 194 if (isSelected==0) {
195 PostData(3,fEventStat);
196 return;
197 }
198 //after physics selection
2a14a7b1 199 fEventStat->Fill(kSelectedEvents);
200
201 //V0and
202 if (fTriggerOnV0AND&&isESD){
203 if (!fTriggerAnalysis->IsOfflineTriggerFired(static_cast<AliESDEvent*>(InputEvent()), AliTriggerAnalysis::kV0AND)) return;
204 }
205 fEventStat->Fill(kV0andEvents);
206
207 //event filter
208 if (fEventFilter) {
209 if (!fEventFilter->IsSelected(InputEvent())) return;
210 }
211 fEventStat->Fill(kFilteredEvents);
212
213 //pileup
214 if (fRejectPileup){
215 if (InputEvent()->IsPileupFromSPD(3,0.8,3.,2.,5.)) return;
216 }
217 fEventStat->Fill(kPileupEvents);
b2a297fa 218
219 //bz for AliKF
220 Double_t bz = InputEvent()->GetMagneticField();
221 AliKFParticle::SetField( bz );
222
2a14a7b1 223 AliDielectronPID::SetCorrVal((Double_t)InputEvent()->GetRunNumber());
224
b2a297fa 225 //Process event in all AliDielectron instances
226 TIter nextDie(&fListDielectron);
227 AliDielectron *die=0;
48609e3d 228 Int_t idie=0;
b2a297fa 229 while ( (die=static_cast<AliDielectron*>(nextDie())) ){
b2a297fa 230 die->Process(InputEvent());
48609e3d 231 if (die->HasCandidates()){
232 Int_t ncandidates=die->GetPairArray(1)->GetEntriesFast();
ffbede40 233 if (ncandidates==1) fEventStat->Fill((kNbinsEvent)+2*idie);
234 else if (ncandidates>1) fEventStat->Fill((kNbinsEvent+1)+2*idie);
48609e3d 235 }
236 ++idie;
b2a297fa 237 }
238
239 PostData(1, &fListHistos);
240 PostData(2, &fListCF);
61d106d3 241 PostData(3,fEventStat);
b2a297fa 242}
243
572b0139 244//_________________________________________________________________________________
245void AliAnalysisTaskMultiDielectron::FinishTaskOutput()
246{
247 //
248 // Write debug tree
249 //
250 TIter nextDie(&fListDielectron);
251 AliDielectron *die=0;
252 while ( (die=static_cast<AliDielectron*>(nextDie())) ){
253 die->SaveDebugTree();
254 }
255}
256