]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGDQ/dielectron/AliAnalysisTaskDielectronSE.cxx
including switch to set on/off iso-track core removal, cleaning and bug fix
[u/mrichter/AliRoot.git] / PWGDQ / dielectron / AliAnalysisTaskDielectronSE.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 //                      for Dielectron Analysis                          //
20 //                                                                       //
21 ///////////////////////////////////////////////////////////////////////////
22
23 #include <TChain.h>
24 #include <TH1D.h>
25
26 #include <AliCFContainer.h>
27 #include <AliVEvent.h>
28 #include <AliInputEventHandler.h>
29 #include <AliESDInputHandler.h>
30 #include <AliAnalysisManager.h>
31 #include <AliAODInputHandler.h>
32 #include <AliTriggerAnalysis.h>
33
34 #include "AliDielectron.h"
35 #include "AliDielectronHistos.h"
36 #include "AliDielectronCF.h"
37 #include "AliAnalysisTaskDielectronSE.h"
38
39 ClassImp(AliAnalysisTaskDielectronSE)
40
41 //_________________________________________________________________________________
42 AliAnalysisTaskDielectronSE::AliAnalysisTaskDielectronSE() :
43   AliAnalysisTaskSE(),
44   fDielectron(0),
45   fSelectPhysics(kFALSE),
46   fTriggerMask(AliVEvent::kMB),
47   fTriggerOnV0AND(kFALSE),
48   fRejectPileup(kFALSE),
49   fTriggerAnalysis(0x0),
50   fEventFilter(0x0),
51   fEventStat(0x0)
52 {
53   //
54   // Constructor
55   //
56 }
57
58 //_________________________________________________________________________________
59 AliAnalysisTaskDielectronSE::AliAnalysisTaskDielectronSE(const char *name) :
60   AliAnalysisTaskSE(name),
61   fDielectron(0),
62   fSelectPhysics(kFALSE),
63   fTriggerMask(AliVEvent::kMB),
64   fTriggerOnV0AND(kFALSE),
65   fRejectPileup(kFALSE),
66   fTriggerAnalysis(0x0),
67   fEventFilter(0x0),
68   fEventStat(0x0)
69 {
70   //
71   // Constructor
72   //
73   DefineInput(0,TChain::Class());
74   DefineOutput(1, THashList::Class());
75   DefineOutput(2, AliCFContainer::Class());
76   DefineOutput(3, TH1D::Class());
77 }
78
79 //_________________________________________________________________________________
80 void AliAnalysisTaskDielectronSE::UserCreateOutputObjects()
81 {
82   //
83   // Initialise the framework objects
84   //
85   if (!fDielectron){
86     AliError("No Dielectron framework object set !!!");
87     return;
88   }
89   fDielectron->Init();
90   if (fDielectron->GetHistogramList()){
91     PostData(1, const_cast<THashList*>(fDielectron->GetHistogramList()));
92   }
93   if (fDielectron->GetCFManagerPair()){
94     PostData(2, const_cast<AliCFContainer*>(fDielectron->GetCFManagerPair()->GetContainer()));
95   }
96   
97   if (!fEventStat){
98     fEventStat=new TH1D("hEventStat","Event statistics",5,0,5);
99     fEventStat->GetXaxis()->SetBinLabel(1,"Before Phys. Sel.");
100     fEventStat->GetXaxis()->SetBinLabel(2,"After Phys. Sel.");
101   }
102   Int_t nbins=kNbinsEvent+2;
103   if (!fEventStat){
104     fEventStat=new TH1D("hEventStat","Event statistics",nbins,0,nbins);
105     fEventStat->GetXaxis()->SetBinLabel(1,"Before Phys. Sel.");
106     fEventStat->GetXaxis()->SetBinLabel(2,"After Phys. Sel.");
107
108     //default names
109     fEventStat->GetXaxis()->SetBinLabel(3,"Bin3 not used");
110     fEventStat->GetXaxis()->SetBinLabel(4,"Bin4 not used");
111     fEventStat->GetXaxis()->SetBinLabel(5,"Bin5 not used");
112
113     if(fTriggerOnV0AND) fEventStat->GetXaxis()->SetBinLabel(3,"V0and triggers");
114     if (fEventFilter) fEventStat->GetXaxis()->SetBinLabel(4,"After Event Filter");
115     if (fRejectPileup) fEventStat->GetXaxis()->SetBinLabel(5,"After Pileup rejection");
116
117     fEventStat->GetXaxis()->SetBinLabel((kNbinsEvent+1),Form("#splitline{1 candidate}{%s}",fDielectron->GetName()));
118     fEventStat->GetXaxis()->SetBinLabel((kNbinsEvent+2),Form("#splitline{With >1 candidate}{%s}",fDielectron->GetName()));
119
120   }
121
122   if (!fTriggerAnalysis) fTriggerAnalysis=new AliTriggerAnalysis;
123   fTriggerAnalysis->EnableHistograms();
124   fTriggerAnalysis->SetAnalyzeMC(AliDielectronMC::Instance()->HasMC());
125   
126   PostData(3,fEventStat);
127   
128 }
129
130 //_________________________________________________________________________________
131 void AliAnalysisTaskDielectronSE::UserExec(Option_t *)
132 {
133   //
134   // Main loop. Called for every event
135   //
136
137   if (!fDielectron) return;
138   
139   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
140   Bool_t isESD=man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class();
141   Bool_t isAOD=man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();
142
143   AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
144   if (!inputHandler) return;
145
146   if ( inputHandler->GetPIDResponse() ){
147     AliDielectronVarManager::SetPIDResponse( inputHandler->GetPIDResponse() );
148   } else {
149     AliFatal("This task needs the PID response attached to the input event handler!");
150   }
151
152   // Was event selected ?
153   UInt_t isSelected = AliVEvent::kAny;
154   if( fSelectPhysics && inputHandler){
155   if((isESD && inputHandler->GetEventSelection()) || isAOD){
156       isSelected = inputHandler->IsEventSelected();
157       isSelected&=fTriggerMask;
158       }
159    }
160
161
162   //Before physics selection
163   fEventStat->Fill(kAllEvents);
164   if (isSelected==0) {
165     PostData(3,fEventStat);
166     return;
167   }
168   //after physics selection
169   fEventStat->Fill(kSelectedEvents);
170
171   //V0and
172   if(fTriggerOnV0AND){
173   if(isESD){if (!fTriggerAnalysis->IsOfflineTriggerFired(static_cast<AliESDEvent*>(InputEvent()), AliTriggerAnalysis::kV0AND))
174             return;}
175   if(isAOD){if(!((static_cast<AliAODEvent*>(InputEvent()))->GetVZEROData()->GetV0ADecision() == AliVVZERO::kV0BB &&
176             (static_cast<AliAODEvent*>(InputEvent()))->GetVZEROData()->GetV0CDecision() == AliVVZERO::kV0BB) )
177             return;}
178    }
179
180
181   fEventStat->Fill(kV0andEvents);
182
183   //Fill Event histograms before the event filter
184   Double_t values[AliDielectronVarManager::kNMaxValues]={0};
185   Double_t valuesMC[AliDielectronVarManager::kNMaxValues]={0};
186   AliDielectronVarManager::Fill(InputEvent(),values);
187   Bool_t hasMC=AliDielectronMC::Instance()->HasMC();
188   if (hasMC) {
189     if (AliDielectronMC::Instance()->ConnectMCEvent())
190       AliDielectronVarManager::Fill(AliDielectronMC::Instance()->GetMCEvent(),valuesMC);
191   }
192   
193   AliDielectronHistos *h=fDielectron->GetHistoManager();
194   if (h){
195     if (h->GetHistogramList()->FindObject("Event_noCuts"))
196       h->FillClass("Event_noCuts",AliDielectronVarManager::kNMaxValues,values);
197     if (hasMC && h->GetHistogramList()->FindObject("MCEvent_noCuts"))
198       h->FillClass("Event_noCuts",AliDielectronVarManager::kNMaxValues,valuesMC);
199   }
200   
201   //event filter
202   if (fEventFilter) {
203     if (!fEventFilter->IsSelected(InputEvent())) return;
204   }
205   fEventStat->Fill(kFilteredEvents);
206   
207   //pileup
208   if (fRejectPileup){
209     if (InputEvent()->IsPileupFromSPD(3,0.8,3.,2.,5.)) return;
210   }
211   fEventStat->Fill(kPileupEvents);
212   
213   //bz for AliKF
214   Double_t bz = InputEvent()->GetMagneticField();
215   AliKFParticle::SetField( bz );
216
217   // make an artificial shift in the electron nsigma. Configured in the Config file
218   AliDielectronPID::SetCorrVal((Double_t)InputEvent()->GetRunNumber());
219
220   //
221   // Actual data processing
222   //
223   fDielectron->Process(InputEvent());
224
225   //statistics for number of selected candidates
226   Int_t ncandidates=fDielectron->GetPairArray(1)->GetEntriesFast();
227   if (ncandidates==1) fEventStat->Fill((kNbinsEvent));
228   else if (ncandidates>1) fEventStat->Fill((kNbinsEvent+1));
229
230   //Publish the data
231   if (fDielectron->GetHistogramList()){
232     PostData(1, const_cast<THashList*>(fDielectron->GetHistogramList()));
233   }
234   if (fDielectron->GetCFManagerPair()){
235     PostData(2, const_cast<AliCFContainer*>(fDielectron->GetCFManagerPair()->GetContainer()));
236   }
237   PostData(3,fEventStat);
238 }
239