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"
40 #include "TObjArray.h"
42 #include "AliAnalysisTask.h"
43 #include "AliAnalysisManager.h"
45 #include "AliVEvent.h"
46 #include "AliESDEvent.h"
48 #include "AliESDVertex.h"
49 #include "AliESDInputHandler.h"
50 #include "AliESDtrackCuts.h"
51 #include "AliMultiplicity.h"
53 #include "AliMCParticle.h"
54 #include "AliMCEvent.h"
55 #include "AliAnalysisTaskKMeans.h"
56 #include "AliTrackReference.h"
58 #include "AliHeader.h"
59 #include "AliKMeansClustering.h"
63 ClassImp(AliAnalysisTaskKMeans)
65 AliAnalysisTaskKMeans::AliAnalysisTaskKMeans()
106 //________________________________________________________________________
107 AliAnalysisTaskKMeans::AliAnalysisTaskKMeans(const char *name)
108 : AliAnalysisTaskSE(name)
146 DefineOutput(1, TList::Class());
150 //________________________________________________________________________
151 void AliAnalysisTaskKMeans::UserCreateOutputObjects()
155 fHists = new TList();
156 fH1CEta = new TH1F("fH1CEta", "eta distribution of clusters", 90, -1.5, 1.5);
157 fH1CEtaR = new TH1F("fH1CEtaR", "eta distribution of clusters", 90, -1.5, 1.5);
158 fH1CPhi = new TH1F("fH1CPhi", "phi distribution of clusters", 157, 0.0, 2. * TMath::Pi());
159 fH2N1N2 = new TH2F("fH2N1N2", "multiplicity distribution", 50, 0., 50., 50, 0., 50.);
161 fH1Pt = new TH1F("fH1Pt", "pt distribution",50, 0., 10.);
162 fH1PtC = new TH1F("fH1PtC", "pt distribution",50, 0., 10.);
163 fH1PtC1 = new TH1F("fH1PtC1", "pt distribution",50, 0., 10.);
164 fH1PtC2 = new TH1F("fH1PtC2", "pt distribution",50, 0., 10.);
165 fH1PtAS = new TH1F("fH1PtAS", "pt distribution",50, 0., 10.);
166 fH1PtR = new TH1F("fH1PtR", "pt distribution",50, 0., 10.);
168 fH1SPt = new TH1F("fH1SPt", "sum pt distribution",50, 0., 10.);
169 fH1SPtC = new TH1F("fH1SPtC", "sum pt distribution",50, 0., 10.);
171 fH1DR = new TH1F("fH1DR", "dR distribution", 50, 0., 5.);
172 fH1DPhi = new TH1F("fH1DPhi", "dPhi distribution", 31, 0., TMath::Pi());
173 fH2DPhiEta = new TH2F("fH2DPhiEta","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
174 fH2DPhiEtaR = new TH2F("fH2DPhiEtaR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
175 fH2DPhiEtaL = new TH2F("fH2DPhiEtaL","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
176 fH2DPhiEtaLR = new TH2F("fH2DPhiEtaLR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
177 fH2DPhiEtaC = new TH2F("fH2DPhiEtaC","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
178 fH2DPhiEtaCR = new TH2F("fH2DPhiEtaCR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
179 fH1DRR = new TH1F("fH1DRR", "dR distribution", 50, 0., 5.);
180 fH1Resp = new TH1F("fH1Resp", "Responsibility", 50, 0., 1.);
181 fH1RespR = new TH1F("fH1RespR", "Responsibility", 50, 0., 1.);
182 fH2Sigma = new TH2F("fH2Sigma", "Sigma", 31, 0., TMath::Pi(), 20, 0., 2.);
183 fH2SigmaR = new TH2F("fH2SigmaR", "Sigma", 31, 0., TMath::Pi(), 20, 0., 2.);
186 fHDensity = new TH1F("fHDensity", "density distribution", 100, 0., 20.);
187 fHCSize = new TH1F("fHCSize", "cluster size", 20, -0.5, 19.5);
189 fHNCluster = new TH1F("fHNCluster", "Number of clusters", 11, -0.5, 10.5);
190 fHPtDensity = new TH2F("fHPtDensity", "Pt vs density", 100, 0., 20., 50, 0., 10.);
195 fHists->Add(fH1CEta);
196 fHists->Add(fH1CEtaR);
197 fHists->Add(fH1CPhi);
198 fHists->Add(fH2N1N2);
202 fHists->Add(fH1PtC1);
203 fHists->Add(fH1PtC2);
204 fHists->Add(fH1PtAS);
206 fHists->Add(fH1SPtC);
208 fHists->Add(fH1DPhi);
209 fHists->Add(fH2DPhiEta);
210 fHists->Add(fH2DPhiEtaR);
211 fHists->Add(fH2DPhiEtaL);
212 fHists->Add(fH2DPhiEtaLR);
213 fHists->Add(fH2DPhiEtaC);
214 fHists->Add(fH2DPhiEtaCR);
216 fHists->Add(fH1RespR);
217 fHists->Add(fH1Resp);
218 fHists->Add(fH2Sigma);
219 fHists->Add(fH2SigmaR);
220 fHists->Add(fHCSize);
221 fHists->Add(fHDensity);
222 fHists->Add(fHNCluster);
223 fHists->Add(fHPtDensity);
225 for (Int_t i = 0; i < 10; i++) {
226 fA[i] = new AliKMeansResult(i+1);
227 fB[i] = new AliKMeansResult(i+1);
231 //________________________________________________________________________
232 void AliAnalysisTaskKMeans::UserExec(Option_t *)
235 // Called for each event
243 Printf("ERROR: fESD not available");
251 // Fill eta-phi positions
257 for (Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++) {
258 AliVParticle* track = fInputEvent->GetTrack(iTracks);
259 if ((fCuts->AcceptTrack((AliESDtrack*)track)))
261 phi [ic] = track->Phi();
262 phiR[ic] = 2. * TMath::Pi() * gRandom->Rndm();
263 eta [ic] = track->Eta();
264 etaR[ic] = 1.8 * gRandom->Rndm() - 0.9;
265 pt [ic] = track->Pt();
266 if (pt[ic] > ptmax) {
281 Double_t* rk0 = new Double_t[10];
283 AliKMeansResult* res = 0;
285 for (Int_t i = 0; i < fK; i++) {
287 AliKMeansClustering::SoftKMeans2(i+1, ic, phi, eta, res->GetMx(),res->GetMy(), res->GetSigma2(), res->GetRk());
288 res->Sort(ic, phi, eta);
289 Int_t j = (res->GetInd())[0];
290 rk0[i] = (res->GetTarget())[j];
295 Double_t* sigma2 = 0;
299 for (Int_t i = 0; i < fK; i++) {
310 sigma2 = res->GetSigma2();
312 Int_t im = (res->GetInd())[0];
313 fHDensity->Fill(rmax / TMath::Pi());
314 fHCSize->Fill(rmax * sigma2[im]);
315 fHNCluster->Fill(Float_t(nk));
317 Double_t dphic, detac;
322 // Cluster Multiplicity
323 Int_t mult[2] = {0, 0};
326 dphic = DeltaPhi(mPhi[0], mPhi[1]);
327 detac = TMath::Abs(mEta[0] - mEta[1]);
328 fH2DPhiEtaC->Fill(dphic, detac);
331 // Random cluster position
332 Int_t ir = Int_t(Float_t(ic) * gRandom->Rndm());
334 Double_t crPhi = phi[ir];
335 Double_t crEta = eta[ir];
340 for (Int_t i = 0; i < 1; i++) {
341 fH1CEta->Fill(mEta[im]);
342 fH1CPhi->Fill(mPhi[im]);
343 for (Int_t j = 0; j < ic; j++) {
344 Double_t r = DeltaR(mPhi[im], mEta[im], phi[j], eta[j]);
345 Double_t dphi = DeltaPhi(mPhi[im], phi[j]);
346 Double_t deta = mEta[im] - eta[j];
347 Double_t rr = DeltaR(crPhi, crEta, phi[j], eta[j]);
351 fH2DPhiEta->Fill(dphi, TMath::Abs(deta));
352 if (j == icmax) fH2DPhiEtaL->Fill(dphi, TMath::Abs(deta));
355 fH1PtC2->Fill(pt[j]);
358 fH1PtC1->Fill(pt[j]);
359 fHPtDensity->Fill(rmax/TMath::Pi(), pt[j]);
370 if (r > 0.7 && dphi < (TMath::Pi() - 0.3)) {
374 if (r > 0.7 && r < 1.) {
378 if (dphi > (TMath::Pi() - 0.3)) {
379 fH1PtAS->Fill(pt[j]);
384 fH2N1N2->Fill(Float_t(mult[0]), Float_t(mult[1]));
385 fH1SPt ->Fill(sumPt);
386 fH1SPtC->Fill(sumPtC);
391 for (Int_t i = 0; i < fK; i++) {
393 AliKMeansClustering::SoftKMeans2(i+1, ic, phiR, etaR, res->GetMx(),res->GetMy(), res->GetSigma2(), res->GetRk());
394 res->Sort(ic, phiR, etaR);
396 Int_t j = (res->GetInd())[0];
397 rk0[i] = (res->GetTarget())[j];
402 for (Int_t i = 0; i < fK; i++) {
411 sigma2 = res->GetSigma2();
414 // fH1RespR->Fill(rk[ind[0]]/(rk[0]+rk[1]));
416 // Cluster Multiplicity
418 for (Int_t i = 0; i < 1; i++) {
419 Int_t im = (res->GetInd())[i];
420 fH1CEtaR->Fill(mEta[im]);
423 for (Int_t i = 0; i < 1; i++) {
424 Int_t im = (res->GetInd())[i];
425 for (Int_t j = 0; j < ic; j++) {
426 Double_t dphi = DeltaPhi(mPhi[im], phiR[j]);
427 Double_t deta = mEta[im] - etaR[j];
428 Double_t r = DeltaR(mPhi[im], mEta[im], phiR[j], etaR[j]);
430 fH2DPhiEtaR->Fill(dphi, TMath::Abs(deta));
431 if (j == icmax) fH2DPhiEtaLR->Fill(dphi, TMath::Abs(deta));
435 dphic = DeltaPhi(mPhi[0], mPhi[1]);
436 detac = TMath::Abs(mEta[0] - mEta[1]);
437 fH2DPhiEtaCR->Fill(dphic, detac);
443 Double_t AliAnalysisTaskKMeans::DeltaPhi(Double_t phi1, Double_t phi2)
445 Double_t dphi = TMath::Abs(phi1 - phi2);
446 if (dphi > TMath::Pi()) dphi = 2. * TMath::Pi() - dphi;
450 Double_t AliAnalysisTaskKMeans::DeltaR(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
452 Double_t dphi = DeltaPhi(phi1, phi2);
453 Double_t deta = eta1 - eta2;
454 return (TMath::Sqrt(dphi * dphi + deta * deta));
458 //________________________________________________________________________
459 void AliAnalysisTaskKMeans::Terminate(Option_t *)