]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/AliAnalysisTaskRhoBase.cxx
move EMCALJetTasks from PWGGA to PWGJE
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliAnalysisTaskRhoBase.cxx
1 // $Id$
2 //
3 // Base class for rho calculation.
4 // Calculates parameterized rho for given centrality independent of input.
5 //
6 // Author: S.Aiola
7
8 #include <TF1.h>
9
10 #include "AliAnalysisManager.h"
11 #include "AliCentrality.h"
12 #include "AliESDEvent.h"
13 #include "AliEmcalJet.h"
14 #include "AliLog.h"
15 #include "AliRhoParameter.h"
16 #include "AliVCluster.h"
17 #include "AliVEventHandler.h"
18
19 #include "AliAnalysisTaskRhoBase.h"
20
21 ClassImp(AliAnalysisTaskRhoBase)
22
23 //________________________________________________________________________
24 AliAnalysisTaskRhoBase::AliAnalysisTaskRhoBase() : 
25   AliAnalysisTaskSE(),
26   fRhoName("Rho"),
27   fRhoFunction(0x0),
28   fCent(-1),
29   fRho(0),
30   fDoCent(0),
31   fIsInit(0)
32 {
33   // Constructor.
34 }
35
36 //________________________________________________________________________
37 AliAnalysisTaskRhoBase::AliAnalysisTaskRhoBase(const char *name) :
38   AliAnalysisTaskSE(name),
39   fRhoName("Rho"),
40   fRhoFunction(0x0),
41   fCent(-1),
42   fRho(0),
43   fDoCent(0),
44   fIsInit(0)
45 {
46   // Constructor.
47 }
48
49 //________________________________________________________________________
50 void AliAnalysisTaskRhoBase::UserCreateOutputObjects()
51 {
52   // Run at beginning of task.
53
54   AliVEventHandler* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
55   if (!handler) {
56     AliError("Input handler not available!");
57     return;
58   }
59
60   fRho = new AliRhoParameter(fRhoName, 0);
61 }
62
63 //________________________________________________________________________
64 void AliAnalysisTaskRhoBase::UserExec(Option_t *) 
65 {
66   // Main loop, called for each event.
67
68   if (!fIsInit) {
69     ExecOnce();
70     fIsInit = 1;
71   }
72
73   DetermineCent();
74
75   Double_t rho = GetRhoFactor(fCent);
76   fRho->SetVal(rho);
77 }      
78
79 //________________________________________________________________________
80 void AliAnalysisTaskRhoBase::DetermineCent() 
81 {
82   // Determine centrality.
83
84   fCent = 99; 
85   
86   if (fDoCent) {
87     AliCentrality *centrality = InputEvent()->GetCentrality();
88     
89     if (centrality)
90       fCent = centrality->GetCentralityPercentile("V0M");
91     else
92       fCent = 99; // probably pp data
93     
94     if (fCent < 0) {
95       AliWarning(Form("%s: Centrality negative: %f, assuming 99", GetName(), fCent));
96       fCent = 99;
97     }
98   }
99 }
100
101 //________________________________________________________________________
102 void AliAnalysisTaskRhoBase::ExecOnce() 
103 {
104   // Initialize some settings that need to be determined in UserExec.
105
106   // add rho to event if not yet there
107   if (!(InputEvent()->FindListObject(fRhoName))) {
108     InputEvent()->AddObject(fRho);
109   } else {
110     AliFatal(Form("%s: Container with same name %s already present. Aborting", GetName(), fRhoName.Data()));
111     return;
112   }
113
114   // determine if centrality should be used
115   TString bt(GetBeamType());
116   if (bt == "A-A")
117     fDoCent = 1;
118   else fDoCent = 0;
119 }
120
121 //_____________________________________________________
122 TString AliAnalysisTaskRhoBase::GetBeamType()
123 {
124   // Get beam type : pp-AA-pA
125   // ESDs have it directly, AODs get it from hardcoded run number ranges
126   
127   AliVEvent *event = InputEvent();
128   if (!event) { 
129     AliError(Form("%s: Couldn't retrieve event!", GetName()));
130     return "";
131   }
132
133   TString beamType;
134
135   AliESDEvent *esd = dynamic_cast<AliESDEvent*>(event);
136   if (esd) {
137     const AliESDRun *run = esd->GetESDRun();
138     beamType = run->GetBeamType();
139   } else {
140     Int_t runNumber = event->GetRunNumber();
141     if ((runNumber >= 136851 && runNumber <= 139517) ||  // LHC10h
142         (runNumber >= 166529 && runNumber <= 170593)) {  // LHC11h
143       beamType = "A-A";
144     } else {
145       beamType = "p-p";
146     }
147   }
148
149   return beamType;    
150 }
151
152 //________________________________________________________________________
153 Double_t AliAnalysisTaskRhoBase::GetRhoFactor(Double_t cent)
154 {
155   // Return rho per centrality.
156
157   Double_t rho = -1;
158   if (fRhoFunction)
159     rho = fRhoFunction->Eval(cent);
160   return rho;
161 }