]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/dielectron/AliAnalysisTaskDielectronFilter.cxx
Add AliEMCALRecoUtils pointer to remove bad or exotic clusters for cluster histograms...
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliAnalysisTaskDielectronFilter.cxx
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>
23 #include <TH1D.h>
24
25 #include <AliLog.h>
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>
33
34 #include "AliDielectron.h"
35 #include "AliDielectronMC.h"
36 #include "AliDielectronHistos.h"
37 #include "AliDielectronVarManager.h"
38 #include "AliAnalysisTaskDielectronFilter.h"
39
40 ClassImp(AliAnalysisTaskDielectronFilter)
41
42 //_________________________________________________________________________________
43 AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter() :
44 AliAnalysisTaskSE(),
45 fDielectron(0),
46 fSelectPhysics(kTRUE),
47 fTriggerMask(AliVEvent::kMB),
48 fEventStat(0x0),
49 fStoreLikeSign(kFALSE)
50 {
51   //
52   // Constructor
53   //
54 }
55
56 //_________________________________________________________________________________
57 AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter(const char *name) :
58 AliAnalysisTaskSE(name),
59 fDielectron(0),
60 fSelectPhysics(kTRUE),
61 fTriggerMask(AliVEvent::kMB),
62 fEventStat(0x0),
63 fStoreLikeSign(kFALSE)
64 {
65   //
66   // Constructor
67   //
68   DefineInput(0,TChain::Class());
69   DefineOutput(1, THashList::Class());
70   DefineOutput(2, TH1D::Class());
71 }
72
73 //_________________________________________________________________________________
74 void 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) AliFatal("No AOD handler. Halting.");
82     
83   aodH->AddFilteredAOD("AliAOD.Dielectron.root", "DielectronEvents");
84 //   AddAODBranch("AliDielectronCandidates",fDielectron->GetPairArraysPointer(),"deltaAOD.Dielectron.root");
85 }
86
87 //_________________________________________________________________________________
88 void AliAnalysisTaskDielectronFilter::UserCreateOutputObjects()
89 {
90   //
91   // Initilise histograms
92   //
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
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   }
107   
108   PostData(2,fEventStat);
109 }
110
111 //_________________________________________________________________________________
112 void AliAnalysisTaskDielectronFilter::UserExec(Option_t *)
113 {
114   //
115   // Main loop. Called for every event
116   //
117   
118   if (!fDielectron) return;
119   
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
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
141     if (man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()){
142       if (!AliDielectronVarManager::GetAODpidUtil()){
143         if (AliDielectronMC::Instance()->HasMC()) {
144           AliDielectronVarManager::InitAODpidUtil();
145         } else {
146           AliDielectronVarManager::InitAODpidUtil(1);
147         }
148       }
149     }
150   }
151   
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;
158   }
159   
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.);
168   
169   //bz for AliKF
170   Double_t bz = InputEvent()->GetMagneticField();
171   AliKFParticle::SetField( bz );
172   
173   fDielectron->Process(InputEvent());
174   
175   Bool_t hasCand = kFALSE;
176   if(fStoreLikeSign) hasCand = (fDielectron->HasCandidates() || fDielectron->HasCandidatesLikeSign());
177   else hasCand = (fDielectron->HasCandidates());
178   
179   if(hasCand){
180     AliAODHandler *aodH=(AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
181     AliAODEvent *aod = aodH->GetAOD();
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);
206         }
207         pairObj->SetRefFirstDaughter(leg1);
208         pairObj->SetRefSecondDaughter(leg2);
209       }
210     }
211     
212     AliAODExtension *extDielectron = aodH->GetFilteredAOD("AliAOD.Dielectron.root");
213     extDielectron->SelectEvent();
214     //after candidate selection
215     fEventStat->Fill(2.);
216     
217     //see if dielectron candidate branch exists, if not create is
218     TTree *t=extDielectron->GetTree();
219
220     if(!t->GetListOfBranches()->GetEntries() && man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class())
221       t->Branch(aod->GetList());
222     
223     if (!t->GetBranch("dielectrons")){
224       t->Bronch("dielectrons","TObjArray",fDielectron->GetPairArraysPointer());
225     }
226     
227     if(man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()) t->Fill();
228   }
229   
230   PostData(1, const_cast<THashList*>(fDielectron->GetHistogramList()));
231   PostData(2,fEventStat);
232 }
233