1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 //-------------------------------------------------------------------------
18 // Analysis Task that uses the Soft K-Means Algorithm to find clusters in
19 // the eta-phi space of Minimum Bias. No pt information is used for the clustering.
22 // Author: Andreas Morsch (CERN)
23 // andreas.morsch@cern.ch
24 //-------------------------------------------------------------------------
35 #include "TParticle.h"
36 #include "TParticlePDG.h"
41 #include "AliAnalysisTask.h"
42 #include "AliAnalysisManager.h"
44 #include "AliESDEvent.h"
46 #include "AliESDVertex.h"
47 #include "AliESDInputHandler.h"
48 #include "AliESDtrackCuts.h"
49 #include "AliMultiplicity.h"
51 #include "AliMCParticle.h"
52 #include "AliMCEvent.h"
53 #include "AliAnalysisTaskKMeans.h"
54 #include "AliTrackReference.h"
56 #include "AliHeader.h"
57 #include "AliKMeansClustering.h"
61 ClassImp(AliAnalysisTaskKMeans)
63 AliAnalysisTaskKMeans::AliAnalysisTaskKMeans()
91 //________________________________________________________________________
92 AliAnalysisTaskKMeans::AliAnalysisTaskKMeans(const char *name)
93 : AliAnalysisTaskSE(name)
118 DefineOutput(1, TList::Class());
122 //________________________________________________________________________
123 void AliAnalysisTaskKMeans::UserCreateOutputObjects()
127 fHists = new TList();
128 fH1CEta = new TH1F("fH1CEta", "eta distribution of clusters", 90, -1.5, 1.5);
129 fH1CEtaR = new TH1F("fH1CEtaR", "eta distribution of clusters", 90, -1.5, 1.5);
130 fH1CPhi = new TH1F("fH1CPhi", "phi distribution of clusters", 157, 0.0, 2. * TMath::Pi());
131 fH2N1N2 = new TH2F("fH2N1N2", "multiplicity distribution", 50, 0., 50., 50, 0., 50.);
133 fH1Pt = new TH1F("fH1Pt", "pt distribution",50, 0., 10.);
134 fH1PtC = new TH1F("fH1PtC", "pt distribution",50, 0., 10.);
135 fH1PtC1 = new TH1F("fH1PtC1", "pt distribution",50, 0., 10.);
136 fH1PtC2 = new TH1F("fH1PtC2", "pt distribution",50, 0., 10.);
138 fH1SPt = new TH1F("fH1SPt", "sum pt distribution",50, 0., 10.);
139 fH1SPtC = new TH1F("fH1SPtC", "sum pt distribution",50, 0., 10.);
141 fH1DR = new TH1F("fH1DR", "dR distribution", 50, 0., 5.);
142 fH1DPhi = new TH1F("fH1DPhi", "dPhi distribution", 31, 0., TMath::Pi());
143 fH2DPhiEta = new TH2F("fH2DPhiEta","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
144 fH2DPhiEtaR = new TH2F("fH2DPhiEtaR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
145 fH2DPhiEtaL = new TH2F("fH2DPhiEtaL","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
146 fH2DPhiEtaC = new TH2F("fH2DPhiEtaC","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
147 fH2DPhiEtaCR = new TH2F("fH2DPhiEtaCR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
148 fH1DRR = new TH1F("fH1DRR", "dR distribution", 50, 0., 5.);
152 fHists->Add(fH1CEta);
153 fHists->Add(fH1CEtaR);
154 fHists->Add(fH1CPhi);
155 fHists->Add(fH2N1N2);
158 fHists->Add(fH1PtC1);
159 fHists->Add(fH1PtC2);
161 fHists->Add(fH1SPtC);
163 fHists->Add(fH1DPhi);
164 fHists->Add(fH2DPhiEta);
165 fHists->Add(fH2DPhiEtaR);
166 fHists->Add(fH2DPhiEtaL);
167 fHists->Add(fH2DPhiEtaC);
168 fHists->Add(fH2DPhiEtaCR);
172 AliKMeansClustering::SetBeta(20.);
176 //________________________________________________________________________
177 void AliAnalysisTaskKMeans::UserExec(Option_t *)
180 // Called for each event
192 Printf("ERROR: fESD not available");
196 AliESDEvent* esdE = (AliESDEvent*) fInputEvent;
200 // Fill eta-phi positions
203 const AliMultiplicity *spdMult = esdE->GetMultiplicity();
204 for (Int_t i = 0; i < spdMult->GetNumberOfTracklets(); ++i) {
205 phi[ic] = spdMult->GetPhi(i);
206 eta[ic] = spdMult->GetEta(i);
213 for (Int_t iTracks = 0; iTracks < esdE->GetNumberOfTracks(); iTracks++) {
214 AliESDtrack* track = esdE->GetTrack(iTracks);
215 if ((fCuts->AcceptTrack(track)))
217 phi[ic] = track->Phi();
218 phiR[ic] = 2. * TMath::Pi() * gRandom->Rndm();
219 eta[ic] = track->Eta();
220 etaR[ic] = 2. * gRandom->Rndm() - 1.;
221 pt[ic] = track->Pt();
222 if (pt[ic] > ptmax) {
237 AliKMeansClustering::SoftKMeans(2, ic, phi, eta, mPhi, mEta, rk);
240 TMath::Sort(2, rk, ind);
244 // Cluster Multiplicity
245 Int_t mult[2] = {0, 0};
247 Double_t dphic = DeltaPhi(mPhi[0], mPhi[1]);
248 Double_t detac = TMath::Abs(mEta[0] - mEta[1]);
249 fH2DPhiEtaC->Fill(dphic, detac);
254 for (Int_t i = 0; i < 1; i++) {
255 fH1CEta->Fill(mEta[ind[i]]);
256 fH1CPhi->Fill(mPhi[ind[i]]);
257 for (Int_t j = 0; j < ic; j++) {
258 Double_t r = DeltaR(mPhi[ind[i]], mEta[ind[i]], phi[j], eta[j]);
259 Double_t dphi = DeltaPhi(mPhi[ind[i]], phi[j]);
260 Double_t deta = mEta[ind[i]] - eta[j];
264 fH2DPhiEta->Fill(dphi, TMath::Abs(deta));
265 if (j == icmax) fH2DPhiEtaL->Fill(dphi, TMath::Abs(deta));
268 fH1PtC2->Fill(pt[j]);
272 fH1PtC1->Fill(pt[j]);
284 if (r > 0.7 && r < 1.) {
290 fH2N1N2->Fill(Float_t(mult[0]), Float_t(mult[1]));
291 fH1SPt ->Fill(sumPt);
292 fH1SPtC->Fill(sumPtC);
297 AliKMeansClustering::SoftKMeans(2, ic, phiR, etaR, mPhi, mEta, rk);
300 TMath::Sort(2, rk, ind);
304 // Cluster Multiplicity
305 for (Int_t i = 0; i < 1; i++) {
306 fH1CEtaR->Fill(mEta[ind[i]]);
308 for (Int_t i = 0; i < 2; i++) {
309 for (Int_t j = 0; j < ic; j++) {
310 Double_t dphi = DeltaPhi(mPhi[ind[i]], phi[j]);
311 Double_t deta = mEta[ind[i]] - eta[j];
312 Double_t r = DeltaR(mPhi[ind[i]], mEta[ind[i]], phi[j], eta[j]);
314 fH2DPhiEtaR->Fill(dphi, TMath::Abs(deta));
317 dphic = DeltaPhi(mPhi[0], mPhi[1]);
318 detac = TMath::Abs(mEta[0] - mEta[1]);
319 fH2DPhiEtaCR->Fill(dphic, detac);
327 Double_t AliAnalysisTaskKMeans::DeltaPhi(Double_t phi1, Double_t phi2)
329 Double_t dphi = TMath::Abs(phi1 - phi2);
330 if (dphi > TMath::Pi()) dphi = 2. * TMath::Pi() - dphi;
334 Double_t AliAnalysisTaskKMeans::DeltaR(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
336 Double_t dphi = DeltaPhi(phi1, phi2);
337 Double_t deta = eta1 - eta2;
338 return (TMath::Sqrt(dphi * dphi + deta * deta));
342 //________________________________________________________________________
343 void AliAnalysisTaskKMeans::Terminate(Option_t *)