AliPhysics  master (3d17d9d)
AliAnalysisTaskRhoAverage.cxx
Go to the documentation of this file.
1 /************************************************************************************
2  * Copyright (C) 2012, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  ************************************************************************************/
28 
29 #include <TClonesArray.h>
30 #include <TMath.h>
31 
32 #include "TLorentzVector.h"
33 #include "AliLog.h"
34 #include "AliRhoParameter.h"
35 #include "AliVCluster.h"
36 #include "AliVTrack.h"
37 #include "AliClusterContainer.h"
38 #include "AliParticleContainer.h"
39 
41 
44  fRhoType(0),
45  fNExclLeadPart(0),
46  fUseMedian(kFALSE),
47  fTotalArea(1)
48 {
49 }
50 
52  AliAnalysisTaskRhoBase(name, histo),
53  fRhoType(0),
54  fNExclLeadPart(0),
55  fUseMedian(kFALSE),
56  fTotalArea(1)
57 {
58 }
59 
61 {
62  const Int_t NMAX = 9999;
63  static Double_t rhovec[NMAX];
64  Int_t NpartAcc = 0;
65 
66  Int_t maxPartIds[] = {0, 0};
67  Float_t maxPartPts[] = {0, 0};
68 
69  // push all jets within selected acceptance into stack
70 
73 
74  if (fNExclLeadPart > 0) {
75 
76  if (tracks && (fRhoType == 0 || fRhoType == 1)) {
77 
78  AliVParticle *track = 0;
79  tracks->ResetCurrentID();
80  while ((track = tracks->GetNextAcceptParticle())) {
81 
82  if (track->Pt() > maxPartPts[0]) {
83  maxPartPts[1] = maxPartPts[0];
84  maxPartIds[1] = maxPartIds[0];
85  maxPartPts[0] = track->Pt();
86  maxPartIds[0] = tracks->GetCurrentID()+1;
87  }
88  else if (track->Pt() > maxPartPts[1]) {
89  maxPartPts[1] = track->Pt();
90  maxPartIds[1] = tracks->GetCurrentID()+1;
91  }
92  }
93  }
94 
95  if (clusters && (fRhoType == 0 || fRhoType == 2)) {
96 
97  AliVCluster *cluster = 0;
98  clusters->ResetCurrentID();
99  while ((cluster = clusters->GetNextAcceptCluster())) {
100  TLorentzVector nPart;
101  clusters->GetMomentum(nPart, clusters->GetCurrentID());
102 
103  if (nPart.Pt() > maxPartPts[0]) {
104  maxPartPts[1] = maxPartPts[0];
105  maxPartIds[1] = maxPartIds[0];
106  maxPartPts[0] = nPart.Pt();
107  maxPartIds[0] = -clusters->GetCurrentID()-1;
108  }
109  else if (nPart.Pt() > maxPartPts[1]) {
110  maxPartPts[1] = nPart.Pt();
111  maxPartIds[1] = -clusters->GetCurrentID()-1;
112  }
113  }
114  }
115 
116  if (fNExclLeadPart < 2) {
117  maxPartIds[1] = 0;
118  maxPartPts[1] = 0;
119  }
120  }
121 
122  if (tracks && (fRhoType == 0 || fRhoType == 1)) {
123  AliVParticle *track = 0;
124  tracks->ResetCurrentID();
125  while ((track = tracks->GetNextAcceptParticle()) && NpartAcc < NMAX) {
126 
127  // exlcuding lead particles
128  if (tracks->GetCurrentID() == maxPartIds[0]-1 || tracks->GetCurrentID() == maxPartIds[1]-1)
129  continue;
130 
131  rhovec[NpartAcc] = track->Pt();
132  ++NpartAcc;
133  }
134  }
135 
136  if (clusters && (fRhoType == 0 || fRhoType == 2)) {
137 
138  AliVCluster *cluster = 0;
139  clusters->ResetCurrentID();
140  while ((cluster = clusters->GetNextAcceptCluster()) && NpartAcc < NMAX) {
141  // exlcuding lead particles
142  if (clusters->GetCurrentID() == -maxPartIds[0]-1 || clusters->GetCurrentID() == -maxPartIds[1]-1)
143  continue;
144 
145  TLorentzVector nPart;
146  clusters->GetMomentum(nPart, clusters->GetCurrentID());
147 
148  rhovec[NpartAcc] = nPart.Pt();
149  ++NpartAcc;
150  }
151  }
152 
153  if (NpartAcc == NMAX) {
154  AliError(Form("%s: NpartAcc >= %d", GetName(), NMAX));
155  }
156 
157  Double_t rho = 0;
158 
159  if (NpartAcc > 0) {
160  if (fUseMedian)
161  rho = TMath::Median(NpartAcc, rhovec);
162  else
163  rho = TMath::Mean(NpartAcc, rhovec);
164 
165  rho *= NpartAcc / fTotalArea;
166  }
167 
168  fOutRho->SetVal(rho);
169 
170  if (fScaleFunction) {
171  Double_t rhoScaled = rho * GetScaleFactor(fCent);
172  fOutRhoScaled->SetVal(rhoScaled);
173  }
174 
175  return kTRUE;
176 }
177 
179 {
181 
183  if (!partCont) {
184  AliError(Form("%s: No particle container found! Assuming area = 1...",GetName()));
185  fTotalArea = 1;
186  return;
187  }
188 
189  Float_t maxEta = partCont->GetParticleEtaMax();
190  Float_t minEta = partCont->GetParticleEtaMin();
191  Float_t maxPhi = partCont->GetParticlePhiMax();
192  Float_t minPhi = partCont->GetParticlePhiMin();
193 
194  if (maxPhi > TMath::Pi() * 2) maxPhi = TMath::Pi() * 2;
195  if (minPhi < 0) minPhi = 0;
196 
197  fTotalArea = (maxEta - minEta) * (maxPhi - minPhi);
198 
199  if (fTotalArea < 1e-6) {
200  AliError(Form("%s: Area = %f < 1e-6, assuming area = 1", GetName(), fTotalArea));
201  fTotalArea = 1;
202  }
203 }
virtual AliVParticle * GetNextAcceptParticle()
double Double_t
Definition: External.C:58
void ExecOnce()
Perform steps needed to initialize the analysis.
Double_t GetParticleEtaMin() const
Container for particles within the EMCAL framework.
AliParticleContainer * GetParticleContainer(Int_t i=0) const
Get particle container attached to this task.
AliRhoParameter * fOutRhoScaled
! output scaled rho object
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
Int_t GetCurrentID() const
AliClusterContainer * GetClusterContainer(Int_t i=0) const
Get cluster container attached to this task.
Double_t fCent
!event centrality
virtual Double_t GetScaleFactor(Double_t cent)
Get scale factor per centrality.
Bool_t Run()
Run the analysis.
Double_t GetParticlePhiMax() const
TF1 * fScaleFunction
pre-computed scale factor as a function of centrality
Double_t GetParticleEtaMax() const
Double_t GetParticlePhiMin() const
Bool_t GetMomentum(TLorentzVector &mom, const AliVCluster *vc, Double_t mass) const
Calculation of rho, method: median all particle pt / multiplicity density.
bool Bool_t
Definition: External.C:53
Base class for rho calculation.
void ExecOnce()
Init the analysis.
AliRhoParameter * fOutRho
! output rho object
Bool_t fUseMedian
whether or not use the median to calculate rho (mean is used if false)
AliAnalysisTaskRhoAverage()
Default constructor.
Container structure for EMCAL clusters.
AliVCluster * GetNextAcceptCluster()
void ResetCurrentID(Int_t i=-1)
Reset the iterator to a given index.
Int_t fRhoType
rho type: 0 = charged+neutral, 1 = charged, 2 = neutral
UInt_t fNExclLeadPart
number of leading particles to be excluded from the median calculation