5581411c54b63a03d2bc3fe93648e2531b8b419b
[u/mrichter/AliRoot.git] / PWG3 / 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
32 #include "AliDielectron.h"
33 #include "AliDielectronHistos.h"
34 #include "AliDielectronCF.h"
35 #include "AliAnalysisTaskDielectronSE.h"
36
37 ClassImp(AliAnalysisTaskDielectronSE)
38
39 //_________________________________________________________________________________
40 AliAnalysisTaskDielectronSE::AliAnalysisTaskDielectronSE() :
41   AliAnalysisTaskSE(),
42   fDielectron(0),
43   fSelectPhysics(kFALSE),
44   fTriggerMask(AliVEvent::kMB),
45   fEventStat(0x0)
46 {
47   //
48   // Constructor
49   //
50 }
51
52 //_________________________________________________________________________________
53 AliAnalysisTaskDielectronSE::AliAnalysisTaskDielectronSE(const char *name) :
54   AliAnalysisTaskSE(name),
55   fDielectron(0),
56   fSelectPhysics(kFALSE),
57   fTriggerMask(AliVEvent::kMB),
58   fEventStat(0x0)
59 {
60   //
61   // Constructor
62   //
63   DefineInput(0,TChain::Class());
64   DefineOutput(1, THashList::Class());
65   DefineOutput(2, AliCFContainer::Class());
66   DefineOutput(3, TH1D::Class());
67 }
68
69 //_________________________________________________________________________________
70 void AliAnalysisTaskDielectronSE::UserCreateOutputObjects()
71 {
72   //
73   // Initialise the framework objects
74   //
75   if (!fDielectron){
76     AliError("No Dielectron framework object set !!!");
77     return;
78   }
79   fDielectron->Init();
80   if (fDielectron->GetHistogramList()){
81     PostData(1, const_cast<THashList*>(fDielectron->GetHistogramList()));
82   }
83   if (fDielectron->GetCFManagerPair()){
84     PostData(2, const_cast<AliCFContainer*>(fDielectron->GetCFManagerPair()->GetContainer()));
85   }
86   
87   if (!fEventStat){
88     fEventStat=new TH1D("hEventStat","Event statistics",5,0,5);
89     fEventStat->GetXaxis()->SetBinLabel(1,"Before Phys. Sel.");
90     fEventStat->GetXaxis()->SetBinLabel(2,"After Phys. Sel.");
91   }
92   
93   PostData(3,fEventStat);
94   
95 }
96
97 //_________________________________________________________________________________
98 void AliAnalysisTaskDielectronSE::UserExec(Option_t *)
99 {
100   //
101   // Main loop. Called for every event
102   //
103
104   if (!fDielectron) return;
105   
106   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
107   AliESDInputHandler *esdHandler=0x0;
108   if ( (esdHandler=dynamic_cast<AliESDInputHandler*>(man->GetInputEventHandler())) && esdHandler->GetESDpid() ){
109     AliDielectronVarManager::SetESDpid(esdHandler->GetESDpid());
110   } else {
111     //load esd pid bethe bloch parameters depending on the existance of the MC handler
112     // yes: MC parameters
113     // no:  data parameters
114     
115     //ESD case
116     if (man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class()){
117       if (!AliDielectronVarManager::GetESDpid()){
118         
119         if (AliDielectronMC::Instance()->HasMC()) {
120           AliDielectronVarManager::InitESDpid();
121         } else {
122           AliDielectronVarManager::InitESDpid(1);
123         }
124       }
125     }
126     //AOD case
127     if (man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class()){
128       if (!AliDielectronVarManager::GetAODpidUtil()){
129         if (AliDielectronMC::Instance()->HasMC()) {
130           AliDielectronVarManager::InitAODpidUtil();
131         } else {
132           AliDielectronVarManager::InitAODpidUtil(1);
133         }
134       }
135     }
136   }
137   // Was event selected ?
138   AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
139   UInt_t isSelected = AliVEvent::kAny;
140   if( fSelectPhysics && inputHandler && inputHandler->GetEventSelection() ) {
141     isSelected = inputHandler->IsEventSelected();
142     isSelected&=fTriggerMask;
143   }
144   
145   //Before physics selection
146   fEventStat->Fill(0.);
147   if (isSelected==0) {
148     PostData(3,fEventStat);
149     return;
150   }
151   //after physics selection
152   fEventStat->Fill(1.);
153   
154   //bz for AliKF
155   Double_t bz = InputEvent()->GetMagneticField();
156   AliKFParticle::SetField( bz );
157   
158   fDielectron->Process(InputEvent());
159
160   if (fDielectron->GetHistogramList()){
161     PostData(1, const_cast<THashList*>(fDielectron->GetHistogramList()));
162   }
163   if (fDielectron->GetCFManagerPair()){
164     PostData(2, const_cast<AliCFContainer*>(fDielectron->GetCFManagerPair()->GetContainer()));
165   }
166   PostData(3,fEventStat);
167 }
168