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 <AliAODInputHandler.h>
33 #include "AliDielectron.h"
34 #include "AliDielectronMC.h"
35 #include "AliDielectronHistos.h"
36 #include "AliDielectronVarManager.h"
37 #include "AliAnalysisTaskDielectronFilter.h"
39 ClassImp(AliAnalysisTaskDielectronFilter)
41 //_________________________________________________________________________________
42 AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter() :
45 fSelectPhysics(kTRUE),
46 fTriggerMask(AliVEvent::kMB),
48 fStoreLikeSign(kFALSE),
49 fStoreRotatedPairs(kFALSE),
57 //_________________________________________________________________________________
58 AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter(const char *name) :
59 AliAnalysisTaskSE(name),
61 fSelectPhysics(kTRUE),
62 fTriggerMask(AliVEvent::kMB),
64 fStoreLikeSign(kFALSE),
65 fStoreRotatedPairs(kFALSE),
71 DefineInput(0,TChain::Class());
72 DefineOutput(1, THashList::Class());
73 DefineOutput(2, TH1D::Class());
76 //_________________________________________________________________________________
77 void AliAnalysisTaskDielectronFilter::Init()
80 if (fDebug > 1) AliInfo("Init() \n");
82 // require AOD handler
83 AliAODHandler *aodH = (AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
84 if (!aodH) AliFatal("No AOD handler. Halting.");
86 aodH->AddFilteredAOD("AliAOD.Dielectron.root", "DielectronEvents");
87 // AddAODBranch("AliDielectronCandidates",fDielectron->GetPairArraysPointer(),"deltaAOD.Dielectron.root");
90 //_________________________________________________________________________________
91 void AliAnalysisTaskDielectronFilter::UserCreateOutputObjects()
94 // Initilise histograms
97 //require dielectron framework
99 AliFatal("Dielectron framework class required. Please create and instance with proper cuts and set it via 'SetDielectron' before executing this task!!!");
102 if(fStoreRotatedPairs) fDielectron->SetStoreRotatedPairs(kTRUE);
106 fEventStat=new TH1D("hEventStat","Event statistics",6,0,6);
107 fEventStat->GetXaxis()->SetBinLabel(1,"Before Phys. Sel.");
108 fEventStat->GetXaxis()->SetBinLabel(2,"After Phys. Sel.");
109 fEventStat->GetXaxis()->SetBinLabel(3,"After Phys. Sel.");
110 fEventStat->GetXaxis()->SetBinLabel(4,"After Cand. Sel.");
113 PostData(2,fEventStat);
116 //_________________________________________________________________________________
117 void AliAnalysisTaskDielectronFilter::UserExec(Option_t *)
120 // Main loop. Called for every event
123 if (!fDielectron) return;
125 AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
127 AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
128 if (!inputHandler) return;
130 if ( inputHandler->GetPIDResponse() ){
131 AliDielectronVarManager::SetPIDResponse( inputHandler->GetPIDResponse() );
133 AliFatal("This task needs the PID response attached to the input event handler!");
136 // Was event selected ?
137 UInt_t isSelected = AliVEvent::kAny;
138 if( fSelectPhysics && inputHandler && inputHandler->GetEventSelection() ) {
139 isSelected = inputHandler->IsEventSelected();
140 isSelected&=fTriggerMask;
143 //Before physics selection
144 fEventStat->Fill(0.);
146 PostData(2,fEventStat);
149 //after physics selection
150 fEventStat->Fill(1.);
154 if (!fEventFilter->IsSelected(InputEvent())) return;
156 fEventStat->Fill(2.);
159 Double_t bz = InputEvent()->GetMagneticField();
160 AliKFParticle::SetField( bz );
162 fDielectron->Process(InputEvent());
164 Bool_t hasCand = kFALSE;
165 if(fStoreLikeSign) hasCand = (fDielectron->HasCandidates() || fDielectron->HasCandidatesLikeSign());
166 else hasCand = (fDielectron->HasCandidates());
168 if(fStoreRotatedPairs) hasCand = (hasCand || fDielectron->HasCandidatesTR());
171 AliAODHandler *aodH=(AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
172 AliAODEvent *aod = aodH->GetAOD();
174 //replace the references of the legs with the AOD references
175 TObjArray *obj = 0x0;
176 for(Int_t i=0; i < 11; i++ ){
177 obj = (TObjArray*)((*(fDielectron->GetPairArraysPointer()))->UncheckedAt(i));
179 for(int j=0;j<obj->GetEntriesFast();j++){
180 AliAODTrack *leg1 = 0x0;
181 AliAODTrack *leg2 = 0x0;
182 AliDielectronPair *pairObj = (AliDielectronPair*)obj->UncheckedAt(j);
183 Int_t id1 = ((AliVTrack*)pairObj->GetFirstDaughter())->GetID();
184 Int_t id2 = ((AliVTrack*)pairObj->GetSecondDaughter())->GetID();
186 for(Int_t it=0;it<aod->GetNumberOfTracks();it++){
187 if(aod->GetTrack(it)->GetID() == id1) leg1 = aod->GetTrack(it);
188 if(aod->GetTrack(it)->GetID() == id2) leg2 = aod->GetTrack(it);
190 if(!leg1 || !leg2) continue;
192 if(man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()){
193 leg1->ResetBit(kIsReferenced);
194 leg1->SetUniqueID(0);
195 leg2->ResetBit(kIsReferenced);
196 leg2->SetUniqueID(0);
198 pairObj->SetRefFirstDaughter(leg1);
199 pairObj->SetRefSecondDaughter(leg2);
203 AliAODExtension *extDielectron = aodH->GetFilteredAOD("AliAOD.Dielectron.root");
204 extDielectron->SelectEvent();
205 //after candidate selection
206 fEventStat->Fill(3.);
208 //see if dielectron candidate branch exists, if not create is
209 TTree *t=extDielectron->GetTree();
211 if(!t->GetListOfBranches()->GetEntries() && man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class())
212 t->Branch(aod->GetList());
214 if (!t->GetBranch("dielectrons")){
215 t->Bronch("dielectrons","TObjArray",fDielectron->GetPairArraysPointer());
218 if(man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()) t->Fill();
221 PostData(1, const_cast<THashList*>(fDielectron->GetHistogramList()));
222 PostData(2,fEventStat);