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