]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGDQ/dielectron/AliAnalysisTaskDielectronFilter.cxx
changes from Misha
[u/mrichter/AliRoot.git] / PWGDQ / 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 <AliAODInputHandler.h>
32
33 #include "AliDielectron.h"
34 #include "AliDielectronMC.h"
35 #include "AliDielectronHistos.h"
36 #include "AliDielectronVarManager.h"
37 #include "AliAnalysisTaskDielectronFilter.h"
38
39 ClassImp(AliAnalysisTaskDielectronFilter)
40
41 //_________________________________________________________________________________
42 AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter() :
43 AliAnalysisTaskSE(),
44 fDielectron(0),
45 fSelectPhysics(kTRUE),
46 fTriggerMask(AliVEvent::kMB),
47 fEventStat(0x0),
48 fStoreLikeSign(kFALSE),
49 fStoreRotatedPairs(kFALSE),
50 fEventFilter(0x0)
51 {
52   //
53   // Constructor
54   //
55 }
56
57 //_________________________________________________________________________________
58 AliAnalysisTaskDielectronFilter::AliAnalysisTaskDielectronFilter(const char *name) :
59 AliAnalysisTaskSE(name),
60 fDielectron(0),
61 fSelectPhysics(kTRUE),
62 fTriggerMask(AliVEvent::kMB),
63 fEventStat(0x0),
64 fStoreLikeSign(kFALSE),
65 fStoreRotatedPairs(kFALSE),
66 fEventFilter(0x0)
67 {
68   //
69   // Constructor
70   //
71   DefineInput(0,TChain::Class());
72   DefineOutput(1, THashList::Class());
73   DefineOutput(2, TH1D::Class());
74 }
75
76 //_________________________________________________________________________________
77 void AliAnalysisTaskDielectronFilter::Init()
78 {
79   // Initialization
80   if (fDebug > 1) AliInfo("Init() \n");
81   
82 // require AOD handler
83   AliAODHandler *aodH = (AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
84   if (!aodH) AliFatal("No AOD handler. Halting.");
85     
86   aodH->AddFilteredAOD("AliAOD.Dielectron.root", "DielectronEvents");
87 //   AddAODBranch("AliDielectronCandidates",fDielectron->GetPairArraysPointer(),"deltaAOD.Dielectron.root");
88 }
89
90 //_________________________________________________________________________________
91 void AliAnalysisTaskDielectronFilter::UserCreateOutputObjects()
92 {
93   //
94   // Initilise histograms
95   //
96
97   //require dielectron framework
98   if (!fDielectron) {
99     AliFatal("Dielectron framework class required. Please create and instance with proper cuts and set it via 'SetDielectron' before executing this task!!!");
100     return;
101   }
102   if(fStoreRotatedPairs) fDielectron->SetStoreRotatedPairs(kTRUE);
103   fDielectron->Init();
104
105   if (!fEventStat){
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.");
111   }
112   
113   PostData(2,fEventStat);
114 }
115
116 //_________________________________________________________________________________
117 void AliAnalysisTaskDielectronFilter::UserExec(Option_t *)
118 {
119   //
120   // Main loop. Called for every event
121   //
122   
123   if (!fDielectron) return;
124   
125   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
126   
127   AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
128   if (!inputHandler) return;
129
130   if ( inputHandler->GetPIDResponse() ){
131     AliDielectronVarManager::SetPIDResponse( inputHandler->GetPIDResponse() );
132   } else {
133     AliFatal("This task needs the PID response attached to the input event handler!");
134   }
135   
136   // Was event selected ?
137   UInt_t isSelected = AliVEvent::kAny;
138   if( fSelectPhysics && inputHandler && inputHandler->GetEventSelection() ) {
139     isSelected = inputHandler->IsEventSelected();
140     isSelected&=fTriggerMask;
141   }
142   
143   //Before physics selection
144   fEventStat->Fill(0.);
145   if (isSelected==0) {
146     PostData(2,fEventStat);
147     return;
148   }
149   //after physics selection
150   fEventStat->Fill(1.);
151
152   //event filter
153   if (fEventFilter) {
154     if (!fEventFilter->IsSelected(InputEvent())) return;
155   }
156   fEventStat->Fill(2.);
157
158   //bz for AliKF
159   Double_t bz = InputEvent()->GetMagneticField();
160   AliKFParticle::SetField( bz );
161   
162   fDielectron->Process(InputEvent());
163   
164   Bool_t hasCand = kFALSE;
165   if(fStoreLikeSign) hasCand = (fDielectron->HasCandidates() || fDielectron->HasCandidatesLikeSign());
166   else hasCand = (fDielectron->HasCandidates());
167
168   if(fStoreRotatedPairs) hasCand = (hasCand || fDielectron->HasCandidatesTR());
169   
170   if(hasCand){
171     AliAODHandler *aodH=(AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
172     AliAODEvent *aod = aodH->GetAOD();
173     
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));
178       if(!obj) continue;
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();
185         
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);
189         }
190         if(!leg1 || !leg2) continue;
191         
192         if(man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()){
193           leg1->ResetBit(kIsReferenced);
194           leg1->SetUniqueID(0);
195           leg2->ResetBit(kIsReferenced);
196           leg2->SetUniqueID(0);
197         }
198         pairObj->SetRefFirstDaughter(leg1);
199         pairObj->SetRefSecondDaughter(leg2);
200       }
201     }
202     
203     AliAODExtension *extDielectron = aodH->GetFilteredAOD("AliAOD.Dielectron.root");
204     extDielectron->SelectEvent();
205     //after candidate selection
206     fEventStat->Fill(3.);
207     
208     //see if dielectron candidate branch exists, if not create is
209     TTree *t=extDielectron->GetTree();
210
211     if(!t->GetListOfBranches()->GetEntries() && man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class())
212       t->Branch(aod->GetList());
213     
214     if (!t->GetBranch("dielectrons")){
215       t->Bronch("dielectrons","TObjArray",fDielectron->GetPairArraysPointer());
216     }
217     
218     if(man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class()) t->Fill();
219   }
220   
221   PostData(1, const_cast<THashList*>(fDielectron->GetHistogramList()));
222   PostData(2,fEventStat);
223 }
224