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 ///////////////////////////////////////////////////////////////////////////
25 #include <AliCFContainer.h>
26 #include <AliInputEventHandler.h>
27 #include <AliESDInputHandler.h>
28 #include <AliAODInputHandler.h>
29 #include <AliAnalysisManager.h>
30 #include <AliVEvent.h>
31 #include <AliTriggerAnalysis.h>
32 #include <AliPIDResponse.h>
33 #include <AliTPCPIDResponse.h>
35 #include "AliDielectron.h"
36 #include "AliDielectronHistos.h"
37 #include "AliDielectronCF.h"
38 #include "AliDielectronMC.h"
39 #include "AliDielectronMixingHandler.h"
40 #include "AliAnalysisTaskMultiDielectron.h"
42 ClassImp(AliAnalysisTaskMultiDielectron)
44 //_________________________________________________________________________________
45 AliAnalysisTaskMultiDielectron::AliAnalysisTaskMultiDielectron() :
50 fSelectPhysics(kFALSE),
51 fTriggerMask(AliVEvent::kMB),
52 fExcludeTriggerMask(0),
53 fTriggerOnV0AND(kFALSE),
54 fRejectPileup(kFALSE),
56 fTriggerAnalysis(0x0),
65 //_________________________________________________________________________________
66 AliAnalysisTaskMultiDielectron::AliAnalysisTaskMultiDielectron(const char *name) :
67 AliAnalysisTaskSE(name),
71 fSelectPhysics(kFALSE),
72 fTriggerMask(AliVEvent::kMB),
73 fExcludeTriggerMask(0),
74 fTriggerOnV0AND(kFALSE),
75 fRejectPileup(kFALSE),
77 fTriggerAnalysis(0x0),
84 DefineInput(0,TChain::Class());
85 DefineOutput(1, TList::Class());
86 DefineOutput(2, TList::Class());
87 DefineOutput(3, TH1D::Class());
88 fListHistos.SetName("Dielectron_Histos_Multi");
89 fListCF.SetName("Dielectron_CF_Multi");
90 fListDielectron.SetOwner();
91 fListHistos.SetOwner();
95 //_________________________________________________________________________________
96 AliAnalysisTaskMultiDielectron::~AliAnalysisTaskMultiDielectron()
102 //histograms and CF are owned by the dielectron framework.
103 //however they are streamed to file, so in the first place the
104 //lists need to be owner...
105 fListHistos.SetOwner(kFALSE);
106 fListCF.SetOwner(kFALSE);
109 //_________________________________________________________________________________
110 void AliAnalysisTaskMultiDielectron::UserCreateOutputObjects()
113 // Add all histogram manager histogram lists to the output TList
116 if (!fListHistos.IsEmpty()||!fListCF.IsEmpty()) return; //already initialised
118 // AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
119 // Bool_t isESD=man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class();
120 // Bool_t isAOD=man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();
122 TIter nextDie(&fListDielectron);
123 AliDielectron *die=0;
124 while ( (die=static_cast<AliDielectron*>(nextDie())) ){
126 if (die->GetHistogramList()) fListHistos.Add(const_cast<THashList*>(die->GetHistogramList()));
127 if (die->GetHistogramArray()) fListHistos.Add(const_cast<TObjArray*>(die->GetHistogramArray()));
128 if (die->GetCFManagerPair()) fListCF.Add(const_cast<AliCFContainer*>(die->GetCFManagerPair()->GetContainer()));
131 Int_t cuts=fListDielectron.GetEntries();
132 Int_t nbins=kNbinsEvent+2*cuts;
134 fEventStat=new TH1D("hEventStat","Event statistics",nbins,0,nbins);
135 fEventStat->GetXaxis()->SetBinLabel(1,"Before Phys. Sel.");
136 fEventStat->GetXaxis()->SetBinLabel(2,"After Phys. Sel.");
139 fEventStat->GetXaxis()->SetBinLabel(3,"Bin3 not used");
140 fEventStat->GetXaxis()->SetBinLabel(4,"Bin4 not used");
141 fEventStat->GetXaxis()->SetBinLabel(5,"Bin5 not used");
143 if(fTriggerOnV0AND) fEventStat->GetXaxis()->SetBinLabel(3,"V0and triggers");
144 if (fEventFilter) fEventStat->GetXaxis()->SetBinLabel(4,"After Event Filter");
145 if (fRejectPileup) fEventStat->GetXaxis()->SetBinLabel(5,"After Pileup rejection");
147 for (Int_t i=0; i<cuts; ++i){
148 fEventStat->GetXaxis()->SetBinLabel((kNbinsEvent+1)+2*i,Form("#splitline{1 candidate}{%s}",fListDielectron.At(i)->GetName()));
149 fEventStat->GetXaxis()->SetBinLabel((kNbinsEvent+2)+2*i,Form("#splitline{With >1 candidate}{%s}",fListDielectron.At(i)->GetName()));
153 if (!fTriggerAnalysis) fTriggerAnalysis=new AliTriggerAnalysis;
154 fTriggerAnalysis->EnableHistograms();
155 fTriggerAnalysis->SetAnalyzeMC(AliDielectronMC::Instance()->HasMC());
157 PostData(1, &fListHistos);
158 PostData(2, &fListCF);
159 PostData(3, fEventStat);
162 //_________________________________________________________________________________
163 void AliAnalysisTaskMultiDielectron::UserExec(Option_t *)
166 // Main loop. Called for every event
169 if (fListHistos.IsEmpty()&&fListCF.IsEmpty()) return;
171 AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
172 Bool_t isESD=man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class();
173 Bool_t isAOD=man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();
175 AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
176 if (!inputHandler) return;
178 // AliPIDResponse *pidRes=inputHandler->GetPIDResponse();
179 if ( inputHandler->GetPIDResponse() ){
180 // for the 2.76 pass2 MC private train. Together with a sigma shift of -0.169
181 // pidRes->GetTPCResponse().SetSigma(4.637e-3,2.41332105409873257e+04);
182 AliDielectronVarManager::SetPIDResponse( inputHandler->GetPIDResponse() );
184 AliFatal("This task needs the PID response attached to the input event handler!");
187 // Was event selected ?
188 ULong64_t isSelected = AliVEvent::kAny;
189 Bool_t isRejected = kFALSE;
190 if( fSelectPhysics && inputHandler){
191 if((isESD && inputHandler->GetEventSelection()) || isAOD){
192 isSelected = inputHandler->IsEventSelected();
193 if (fExcludeTriggerMask && (isSelected&fExcludeTriggerMask)) isRejected=kTRUE;
194 if (fTriggerLogic==kAny) isSelected&=fTriggerMask;
195 else if (fTriggerLogic==kExact) isSelected=((isSelected&fTriggerMask)==fTriggerMask);
200 //Before physics selection
201 fEventStat->Fill(kAllEvents);
202 if (isSelected==0||isRejected) {
203 PostData(3,fEventStat);
206 //after physics selection
207 fEventStat->Fill(kSelectedEvents);
211 if(isESD){if (!fTriggerAnalysis->IsOfflineTriggerFired(static_cast<AliESDEvent*>(InputEvent()), AliTriggerAnalysis::kV0AND))
213 if(isAOD){if(!((static_cast<AliAODEvent*>(InputEvent()))->GetVZEROData()->GetV0ADecision() == AliVVZERO::kV0BB &&
214 (static_cast<AliAODEvent*>(InputEvent()))->GetVZEROData()->GetV0CDecision() == AliVVZERO::kV0BB) )
219 fEventStat->Fill(kV0andEvents);
221 //Fill Event histograms before the event filter
222 TIter nextDie(&fListDielectron);
223 AliDielectron *die=0;
224 Double_t values[AliDielectronVarManager::kNMaxValues]={0};
225 Double_t valuesMC[AliDielectronVarManager::kNMaxValues]={0};
226 AliDielectronVarManager::SetEvent(InputEvent());
227 AliDielectronVarManager::Fill(InputEvent(),values);
228 AliDielectronVarManager::Fill(InputEvent(),valuesMC);
229 Bool_t hasMC=AliDielectronMC::Instance()->HasMC();
231 if (AliDielectronMC::Instance()->ConnectMCEvent())
232 AliDielectronVarManager::Fill(AliDielectronMC::Instance()->GetMCEvent(),valuesMC);
235 while ( (die=static_cast<AliDielectron*>(nextDie())) ){
236 AliDielectronHistos *h=die->GetHistoManager();
238 if (h->GetHistogramList()->FindObject("Event_noCuts"))
239 h->FillClass("Event_noCuts",AliDielectronVarManager::kNMaxValues,values);
240 if (hasMC && h->GetHistogramList()->FindObject("MCEvent_noCuts"))
241 h->FillClass("Event_noCuts",AliDielectronVarManager::kNMaxValues,valuesMC);
248 if (!fEventFilter->IsSelected(InputEvent())) return;
250 fEventStat->Fill(kFilteredEvents);
254 if (InputEvent()->IsPileupFromSPD(3,0.8,3.,2.,5.)) return;
256 fEventStat->Fill(kPileupEvents);
259 Double_t bz = InputEvent()->GetMagneticField();
260 AliKFParticle::SetField( bz );
262 AliDielectronPID::SetCorrVal((Double_t)InputEvent()->GetRunNumber());
264 //Process event in all AliDielectron instances
265 // TIter nextDie(&fListDielectron);
266 // AliDielectron *die=0;
268 while ( (die=static_cast<AliDielectron*>(nextDie())) ){
269 die->Process(InputEvent());
270 if (die->HasCandidates()){
271 Int_t ncandidates=die->GetPairArray(1)->GetEntriesFast();
272 if (ncandidates==1) fEventStat->Fill((kNbinsEvent)+2*idie);
273 else if (ncandidates>1) fEventStat->Fill((kNbinsEvent+1)+2*idie);
278 PostData(1, &fListHistos);
279 PostData(2, &fListCF);
280 PostData(3,fEventStat);
283 //_________________________________________________________________________________
284 void AliAnalysisTaskMultiDielectron::FinishTaskOutput()
289 TIter nextDie(&fListDielectron);
290 AliDielectron *die=0;
291 while ( (die=static_cast<AliDielectron*>(nextDie())) ){
292 die->SaveDebugTree();
293 AliDielectronMixingHandler *mix=die->GetMixingHandler();
294 // printf("\n\n\n===============\ncall mix in Terminate: %p (%p)\n=================\n\n",mix,die);
295 if (mix) mix->MixRemaining(die);
297 PostData(1, &fListHistos);
298 PostData(2, &fListCF);