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