major dielectron update (included also the data and plotting macros for paper)
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliAnalysisTaskDielectronFilter.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 <AliLog.h>
26#include <AliAODHandler.h>
ffbede40 27#include <AliAODInputHandler.h>
b2a297fa 28#include <AliAnalysisManager.h>
29#include <AliVEvent.h>
8df8e382 30#include <AliInputEventHandler.h>
31#include <AliESDInputHandler.h>
2a14a7b1 32#include <AliAODInputHandler.h>
b2a297fa 33
34#include "AliDielectron.h"
8df8e382 35#include "AliDielectronMC.h"
b2a297fa 36#include "AliDielectronHistos.h"
8df8e382 37#include "AliDielectronVarManager.h"
b2a297fa 38#include "AliAnalysisTaskDielectronFilter.h"
39
40ClassImp(AliAnalysisTaskDielectronFilter)
41
42//_________________________________________________________________________________
43AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter() :
2a14a7b1 44AliAnalysisTaskSE(),
45fDielectron(0),
46fSelectPhysics(kTRUE),
47fTriggerMask(AliVEvent::kMB),
fb7d2d99 48fEventStat(0x0),
49fStoreLikeSign(kFALSE)
b2a297fa 50{
51 //
52 // Constructor
53 //
54}
55
56//_________________________________________________________________________________
57AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter(const char *name) :
2a14a7b1 58AliAnalysisTaskSE(name),
59fDielectron(0),
60fSelectPhysics(kTRUE),
61fTriggerMask(AliVEvent::kMB),
fb7d2d99 62fEventStat(0x0),
63fStoreLikeSign(kFALSE)
b2a297fa 64{
65 //
66 // Constructor
67 //
68 DefineInput(0,TChain::Class());
69 DefineOutput(1, THashList::Class());
61d106d3 70 DefineOutput(2, TH1D::Class());
b2a297fa 71}
72
73//_________________________________________________________________________________
74void AliAnalysisTaskDielectronFilter::Init()
75{
76 // Initialization
77 if (fDebug > 1) AliInfo("Init() \n");
78
79// require AOD handler
80 AliAODHandler *aodH = (AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
81 if (!aodH) Fatal("Init", "No AOD handler. Halting.");
82
83//require dielectron framework
84 if (!fDielectron) {
85 Error("Init","Dielectron framework class required. Please create and instance with proper cuts and set it via 'SetDielectron' before executing this task!!!");
86 return;
87 }
8df8e382 88 fDielectron->Init();
b2a297fa 89
90 aodH->AddFilteredAOD("AliAOD.Dielectron.root", "DielectronEvents");
91// AddAODBranch("AliDielectronCandidates",fDielectron->GetPairArraysPointer(),"deltaAOD.Dielectron.root");
92}
93
94//_________________________________________________________________________________
61d106d3 95void AliAnalysisTaskDielectronFilter::UserCreateOutputObjects()
96{
97 //
98 // Initilise histograms
99 //
100 if (!fEventStat){
101 fEventStat=new TH1D("hEventStat","Event statistics",5,0,5);
102 fEventStat->GetXaxis()->SetBinLabel(1,"Before Phys. Sel.");
103 fEventStat->GetXaxis()->SetBinLabel(2,"After Phys. Sel.");
104 fEventStat->GetXaxis()->SetBinLabel(3,"After Cand. Sel.");
105 }
2a14a7b1 106
61d106d3 107 PostData(2,fEventStat);
108}
109
110//_________________________________________________________________________________
b2a297fa 111void AliAnalysisTaskDielectronFilter::UserExec(Option_t *)
112{
113 //
114 // Main loop. Called for every event
115 //
8df8e382 116
b2a297fa 117 if (!fDielectron) return;
118
8df8e382 119 AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
120 AliESDInputHandler *esdHandler=0x0;
121 if ( (esdHandler=dynamic_cast<AliESDInputHandler*>(man->GetInputEventHandler())) && esdHandler->GetESDpid() ){
122 AliDielectronVarManager::SetESDpid(esdHandler->GetESDpid());
123 } else {
124 //load esd pid bethe bloch parameters depending on the existance of the MC handler
125 // yes: MC parameters
126 // no: data parameters
2a14a7b1 127
128 //ESD case
129 if (man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class()){
130 if (!AliDielectronVarManager::GetESDpid()){
131
132 if (AliDielectronMC::Instance()->HasMC()) {
133 AliDielectronVarManager::InitESDpid();
134 } else {
135 AliDielectronVarManager::InitESDpid(1);
136 }
137 }
138 }
139 //AOD case
ffbede40 140 if (man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()){
2a14a7b1 141 if (!AliDielectronVarManager::GetAODpidUtil()){
142 if (AliDielectronMC::Instance()->HasMC()) {
143 AliDielectronVarManager::InitAODpidUtil();
144 } else {
145 AliDielectronVarManager::InitAODpidUtil(1);
146 }
8df8e382 147 }
148 }
149 }
2a14a7b1 150
8df8e382 151 // Was event selected ?
152 AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
61d106d3 153 UInt_t isSelected = AliVEvent::kAny;
8df8e382 154 if( fSelectPhysics && inputHandler && inputHandler->GetEventSelection() ) {
155 isSelected = inputHandler->IsEventSelected();
61d106d3 156 isSelected&=fTriggerMask;
8df8e382 157 }
2a14a7b1 158
61d106d3 159 //Before physics selection
160 fEventStat->Fill(0.);
161 if (isSelected==0) {
162 PostData(2,fEventStat);
163 return;
164 }
165 //after physics selection
166 fEventStat->Fill(1.);
8df8e382 167
b2a297fa 168 //bz for AliKF
169 Double_t bz = InputEvent()->GetMagneticField();
170 AliKFParticle::SetField( bz );
171
172 fDielectron->Process(InputEvent());
8df8e382 173
fb7d2d99 174 Bool_t hasCand = kFALSE;
175 if(fStoreLikeSign) hasCand = (fDielectron->HasCandidates() || fDielectron->HasCandidatesLikeSign());
176 else hasCand = (fDielectron->HasCandidates());
177
178 if(hasCand){
45b2b1b8 179 AliAODHandler *aodH=(AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
180 AliAODEvent *aod = aodH->GetAOD();
2a14a7b1 181
182 //replace the references of the legs with the AOD references
183 TObjArray *obj = 0x0;
184 for(Int_t i=0; i < 10; i++ ){
185 obj = (TObjArray*)((*(fDielectron->GetPairArraysPointer()))->UncheckedAt(i));
186 if(!obj) continue;
187 for(int j=0;j<obj->GetEntriesFast();j++){
188 AliAODTrack *leg1 = 0x0;
189 AliAODTrack *leg2 = 0x0;
190 AliDielectronPair *pairObj = (AliDielectronPair*)obj->UncheckedAt(j);
191 Int_t id1 = ((AliVTrack*)pairObj->GetFirstDaughter())->GetID();
192 Int_t id2 = ((AliVTrack*)pairObj->GetSecondDaughter())->GetID();
193
194 for(Int_t it=0;it<aod->GetNumberOfTracks();it++){
195 if(aod->GetTrack(it)->GetID() == id1) leg1 = aod->GetTrack(it);
196 if(aod->GetTrack(it)->GetID() == id2) leg2 = aod->GetTrack(it);
197 }
198 if(!leg1 || !leg2) continue;
199
200 if(man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()){
201 leg1->ResetBit(kIsReferenced);
202 leg1->SetUniqueID(0);
203 leg2->ResetBit(kIsReferenced);
204 leg2->SetUniqueID(0);
8df8e382 205 }
2a14a7b1 206 pairObj->SetRefFirstDaughter(leg1);
207 pairObj->SetRefSecondDaughter(leg2);
8df8e382 208 }
209 }
2a14a7b1 210
45b2b1b8 211 AliAODExtension *extDielectron = aodH->GetFilteredAOD("AliAOD.Dielectron.root");
b2a297fa 212 extDielectron->SelectEvent();
61d106d3 213 //after candidate selection
214 fEventStat->Fill(2.);
215
b2a297fa 216 //see if dielectron candidate branch exists, if not create is
217 TTree *t=extDielectron->GetTree();
2a14a7b1 218
219 if(!t->GetListOfBranches()->GetEntries() && man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class())
220 t->Branch(aod->GetList());
221
b2a297fa 222 if (!t->GetBranch("dielectrons")){
223 t->Bronch("dielectrons","TObjArray",fDielectron->GetPairArraysPointer());
224 }
2a14a7b1 225
226 if(man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()) t->Fill();
b2a297fa 227 }
228
229 PostData(1, const_cast<THashList*>(fDielectron->GetHistogramList()));
61d106d3 230 PostData(2,fEventStat);
b2a297fa 231}
232