1 /*************************************************************************
2 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////
18 // Basic Analysis Task //
20 ///////////////////////////////////////////////////////////////////////////
26 #include <AliAODHandler.h>
27 #include <AliAODInputHandler.h>
28 #include <AliAnalysisManager.h>
29 #include <AliVEvent.h>
30 #include <AliInputEventHandler.h>
31 #include <AliESDInputHandler.h>
32 #include <AliAODInputHandler.h>
34 #include "AliDielectron.h"
35 #include "AliDielectronMC.h"
36 #include "AliDielectronHistos.h"
37 #include "AliDielectronVarManager.h"
38 #include "AliAnalysisTaskDielectronFilter.h"
40 ClassImp(AliAnalysisTaskDielectronFilter)
42 //_________________________________________________________________________________
43 AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter() :
46 fSelectPhysics(kTRUE),
47 fTriggerMask(AliVEvent::kMB),
49 fStoreLikeSign(kFALSE)
56 //_________________________________________________________________________________
57 AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter(const char *name) :
58 AliAnalysisTaskSE(name),
60 fSelectPhysics(kTRUE),
61 fTriggerMask(AliVEvent::kMB),
63 fStoreLikeSign(kFALSE)
68 DefineInput(0,TChain::Class());
69 DefineOutput(1, THashList::Class());
70 DefineOutput(2, TH1D::Class());
73 //_________________________________________________________________________________
74 void AliAnalysisTaskDielectronFilter::Init()
77 if (fDebug > 1) AliInfo("Init() \n");
79 // require AOD handler
80 AliAODHandler *aodH = (AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
81 if (!aodH) AliFatal("No AOD handler. Halting.");
83 aodH->AddFilteredAOD("AliAOD.Dielectron.root", "DielectronEvents");
84 // AddAODBranch("AliDielectronCandidates",fDielectron->GetPairArraysPointer(),"deltaAOD.Dielectron.root");
87 //_________________________________________________________________________________
88 void AliAnalysisTaskDielectronFilter::UserCreateOutputObjects()
91 // Initilise histograms
94 //require dielectron framework
96 AliFatal("Dielectron framework class required. Please create and instance with proper cuts and set it via 'SetDielectron' before executing this task!!!");
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.");
108 PostData(2,fEventStat);
111 //_________________________________________________________________________________
112 void AliAnalysisTaskDielectronFilter::UserExec(Option_t *)
115 // Main loop. Called for every event
118 if (!fDielectron) return;
120 AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
121 AliESDInputHandler *esdHandler=0x0;
122 if ( (esdHandler=dynamic_cast<AliESDInputHandler*>(man->GetInputEventHandler())) && esdHandler->GetESDpid() ){
123 AliDielectronVarManager::SetESDpid(esdHandler->GetESDpid());
125 //load esd pid bethe bloch parameters depending on the existance of the MC handler
126 // yes: MC parameters
127 // no: data parameters
130 if (man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class()){
131 if (!AliDielectronVarManager::GetESDpid()){
133 if (AliDielectronMC::Instance()->HasMC()) {
134 AliDielectronVarManager::InitESDpid();
136 AliDielectronVarManager::InitESDpid(1);
141 if (man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()){
142 if (!AliDielectronVarManager::GetAODpidUtil()){
143 if (AliDielectronMC::Instance()->HasMC()) {
144 AliDielectronVarManager::InitAODpidUtil();
146 AliDielectronVarManager::InitAODpidUtil(1);
152 // Was event selected ?
153 AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
154 UInt_t isSelected = AliVEvent::kAny;
155 if( fSelectPhysics && inputHandler && inputHandler->GetEventSelection() ) {
156 isSelected = inputHandler->IsEventSelected();
157 isSelected&=fTriggerMask;
160 //Before physics selection
161 fEventStat->Fill(0.);
163 PostData(2,fEventStat);
166 //after physics selection
167 fEventStat->Fill(1.);
170 Double_t bz = InputEvent()->GetMagneticField();
171 AliKFParticle::SetField( bz );
173 fDielectron->Process(InputEvent());
175 Bool_t hasCand = kFALSE;
176 if(fStoreLikeSign) hasCand = (fDielectron->HasCandidates() || fDielectron->HasCandidatesLikeSign());
177 else hasCand = (fDielectron->HasCandidates());
180 AliAODHandler *aodH=(AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
181 AliAODEvent *aod = aodH->GetAOD();
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));
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();
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);
199 if(!leg1 || !leg2) continue;
201 if(man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()){
202 leg1->ResetBit(kIsReferenced);
203 leg1->SetUniqueID(0);
204 leg2->ResetBit(kIsReferenced);
205 leg2->SetUniqueID(0);
207 pairObj->SetRefFirstDaughter(leg1);
208 pairObj->SetRefSecondDaughter(leg2);
212 AliAODExtension *extDielectron = aodH->GetFilteredAOD("AliAOD.Dielectron.root");
213 extDielectron->SelectEvent();
214 //after candidate selection
215 fEventStat->Fill(2.);
217 //see if dielectron candidate branch exists, if not create is
218 TTree *t=extDielectron->GetTree();
220 if(!t->GetListOfBranches()->GetEntries() && man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class())
221 t->Branch(aod->GetList());
223 if (!t->GetBranch("dielectrons")){
224 t->Bronch("dielectrons","TObjArray",fDielectron->GetPairArraysPointer());
227 if(man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()) t->Fill();
230 PostData(1, const_cast<THashList*>(fDielectron->GetHistogramList()));
231 PostData(2,fEventStat);