]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGDQ/dielectron/AliAnalysisTaskMultiDielectron.cxx
Add Mahmut's pp task
[u/mrichter/AliRoot.git] / PWGDQ / dielectron / AliAnalysisTaskMultiDielectron.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 <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>
34
35 #include "AliDielectron.h"
36 #include "AliDielectronHistos.h"
37 #include "AliDielectronCF.h"
38 #include "AliDielectronMC.h"
39 #include "AliDielectronMixingHandler.h"
40 #include "AliAnalysisTaskMultiDielectron.h"
41
42 ClassImp(AliAnalysisTaskMultiDielectron)
43
44 //_________________________________________________________________________________
45 AliAnalysisTaskMultiDielectron::AliAnalysisTaskMultiDielectron() :
46   AliAnalysisTaskSE(),
47   fListDielectron(),
48   fListHistos(),
49   fListCF(),
50   fSelectPhysics(kFALSE),
51   fTriggerMask(AliVEvent::kMB),
52   fExcludeTriggerMask(0),
53   fTriggerOnV0AND(kFALSE),
54   fRejectPileup(kFALSE),
55   fTriggerLogic(kAny),
56   fTriggerAnalysis(0x0),
57   fEventFilter(0x0),
58   fEventStat(0x0)
59 {
60   //
61   // Constructor
62   //
63 }
64
65 //_________________________________________________________________________________
66 AliAnalysisTaskMultiDielectron::AliAnalysisTaskMultiDielectron(const char *name) :
67   AliAnalysisTaskSE(name),
68   fListDielectron(),
69   fListHistos(),
70   fListCF(),
71   fSelectPhysics(kFALSE),
72   fTriggerMask(AliVEvent::kMB),
73   fExcludeTriggerMask(0),
74   fTriggerOnV0AND(kFALSE),
75   fRejectPileup(kFALSE),
76   fTriggerLogic(kAny),
77   fTriggerAnalysis(0x0),
78   fEventFilter(0x0),
79   fEventStat(0x0)
80 {
81   //
82   // Constructor
83   //
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();
92   fListCF.SetOwner();
93 }
94
95 //_________________________________________________________________________________
96 AliAnalysisTaskMultiDielectron::~AliAnalysisTaskMultiDielectron()
97 {
98   //
99   // Destructor
100   //
101
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);
107   
108 }
109 //_________________________________________________________________________________
110 void AliAnalysisTaskMultiDielectron::UserCreateOutputObjects()
111 {
112   //
113   // Add all histogram manager histogram lists to the output TList
114   //
115
116   if (!fListHistos.IsEmpty()||!fListCF.IsEmpty()) return; //already initialised
117
118 //   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
119 //   Bool_t isESD=man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class();
120 //   Bool_t isAOD=man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();
121   
122   TIter nextDie(&fListDielectron);
123   AliDielectron *die=0;
124   while ( (die=static_cast<AliDielectron*>(nextDie())) ){
125     die->Init();
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()));
129   }
130
131   Int_t cuts=fListDielectron.GetEntries();
132   Int_t nbins=kNbinsEvent+2*cuts;
133   if (!fEventStat){
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.");
137
138     //default names
139     fEventStat->GetXaxis()->SetBinLabel(3,"Bin3 not used");
140     fEventStat->GetXaxis()->SetBinLabel(4,"Bin4 not used");
141     fEventStat->GetXaxis()->SetBinLabel(5,"Bin5 not used");
142     
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");
146     
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()));
150     }
151   }
152
153   if (!fTriggerAnalysis) fTriggerAnalysis=new AliTriggerAnalysis;
154   fTriggerAnalysis->EnableHistograms();
155   fTriggerAnalysis->SetAnalyzeMC(AliDielectronMC::Instance()->HasMC());
156   
157   PostData(1, &fListHistos);
158   PostData(2, &fListCF);
159   PostData(3, fEventStat);
160 }
161
162 //_________________________________________________________________________________
163 void AliAnalysisTaskMultiDielectron::UserExec(Option_t *)
164 {
165   //
166   // Main loop. Called for every event
167   //
168
169   if (fListHistos.IsEmpty()&&fListCF.IsEmpty()) return;
170
171   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
172   Bool_t isESD=man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class();
173   Bool_t isAOD=man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();
174   
175   AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
176   if (!inputHandler) return;
177   
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() );
183   } else {
184     AliFatal("This task needs the PID response attached to the input event handler!");
185   }
186   
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);
196     }
197    }
198  
199  
200   //Before physics selection
201   fEventStat->Fill(kAllEvents);
202   if (isSelected==0||isRejected) {
203     PostData(3,fEventStat);
204     return;
205   }
206   //after physics selection
207   fEventStat->Fill(kSelectedEvents);
208
209   //V0and
210   if(fTriggerOnV0AND){
211   if(isESD){if (!fTriggerAnalysis->IsOfflineTriggerFired(static_cast<AliESDEvent*>(InputEvent()), AliTriggerAnalysis::kV0AND))
212             return;}
213   if(isAOD){if(!((static_cast<AliAODEvent*>(InputEvent()))->GetVZEROData()->GetV0ADecision() == AliVVZERO::kV0BB &&
214             (static_cast<AliAODEvent*>(InputEvent()))->GetVZEROData()->GetV0CDecision() == AliVVZERO::kV0BB) )
215             return;}
216    }
217   
218
219   fEventStat->Fill(kV0andEvents);
220
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();
230   if (hasMC) {
231     if (AliDielectronMC::Instance()->ConnectMCEvent())
232       AliDielectronVarManager::Fill(AliDielectronMC::Instance()->GetMCEvent(),valuesMC);
233   }
234
235   while ( (die=static_cast<AliDielectron*>(nextDie())) ){
236     AliDielectronHistos *h=die->GetHistoManager();
237     if (h){
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);
242     }
243   }
244   nextDie.Reset();
245   
246   //event filter
247   if (fEventFilter) {
248     if (!fEventFilter->IsSelected(InputEvent())) return;
249   }
250   fEventStat->Fill(kFilteredEvents);
251   
252   //pileup
253   if (fRejectPileup){
254     if (InputEvent()->IsPileupFromSPD(3,0.8,3.,2.,5.)) return;
255   }
256   fEventStat->Fill(kPileupEvents);
257   
258   //bz for AliKF
259   Double_t bz = InputEvent()->GetMagneticField();
260   AliKFParticle::SetField( bz );
261
262   AliDielectronPID::SetCorrVal((Double_t)InputEvent()->GetRunNumber());
263   
264   //Process event in all AliDielectron instances
265   //   TIter nextDie(&fListDielectron);
266   //   AliDielectron *die=0;
267   Int_t idie=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);
274     }
275     ++idie;
276   }
277   
278   PostData(1, &fListHistos);
279   PostData(2, &fListCF);
280   PostData(3,fEventStat);
281 }
282
283 //_________________________________________________________________________________
284 void AliAnalysisTaskMultiDielectron::FinishTaskOutput()
285 {
286   //
287   // Write debug tree
288   //
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);
296   }
297   PostData(1, &fListHistos);
298   PostData(2, &fListCF);
299 }
300