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()
107 //________________________________________________________________________
108 AliAnalysisTaskKMeans::AliAnalysisTaskKMeans(const char *name)
109 : AliAnalysisTaskSE(name)
148 DefineOutput(1, TList::Class());
151 AliAnalysisTaskKMeans::AliAnalysisTaskKMeans(const AliAnalysisTaskKMeans &res)
152 : AliAnalysisTaskSE(res)
187 // Dummy copy constructor
190 AliAnalysisTaskKMeans& AliAnalysisTaskKMeans::operator=(const AliAnalysisTaskKMeans& /*trclass*/)
192 // Dummy assignment operator
198 //________________________________________________________________________
199 void AliAnalysisTaskKMeans::UserCreateOutputObjects()
203 fHists = new TList();
204 fH1CEta = new TH1F("fH1CEta", "eta distribution of clusters", 90, -1.5, 1.5);
205 fH1CEtaR = new TH1F("fH1CEtaR", "eta distribution of clusters", 90, -1.5, 1.5);
206 fH1CPhi = new TH1F("fH1CPhi", "phi distribution of clusters", 157, 0.0, 2. * TMath::Pi());
207 fH2N1N2 = new TH2F("fH2N1N2", "multiplicity distribution", 50, 0., 50., 50, 0., 50.);
209 fH1Pt = new TH1F("fH1Pt", "pt distribution",50, 0., 10.);
210 fH1PtC = new TH1F("fH1PtC", "pt distribution",50, 0., 10.);
211 fH1PtC1 = new TH1F("fH1PtC1", "pt distribution",50, 0., 10.);
212 fH1PtC2 = new TH1F("fH1PtC2", "pt distribution",50, 0., 10.);
213 fH1PtAS = new TH1F("fH1PtAS", "pt distribution",50, 0., 10.);
214 fH1PtR = new TH1F("fH1PtR", "pt distribution",50, 0., 10.);
216 fH1SPt = new TH1F("fH1SPt", "sum pt distribution",50, 0., 10.);
217 fH1SPtC = new TH1F("fH1SPtC", "sum pt distribution",50, 0., 10.);
219 fH1DR = new TH1F("fH1DR", "dR distribution", 50, 0., 5.);
220 fH1DPhi = new TH1F("fH1DPhi", "dPhi distribution", 31, 0., TMath::Pi());
221 fH2DPhiEta = new TH2F("fH2DPhiEta","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
222 fH2DPhiEtaR = new TH2F("fH2DPhiEtaR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
223 fH2DPhiEtaL = new TH2F("fH2DPhiEtaL","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
224 fH2DPhiEtaLR = new TH2F("fH2DPhiEtaLR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
225 fH2DPhiEtaC = new TH2F("fH2DPhiEtaC","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
226 fH2DPhiEtaCR = new TH2F("fH2DPhiEtaCR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
227 fH1DRR = new TH1F("fH1DRR", "dR distribution", 50, 0., 5.);
228 fH1Resp = new TH1F("fH1Resp", "Responsibility", 50, 0., 1.);
229 fH1RespR = new TH1F("fH1RespR", "Responsibility", 50, 0., 1.);
230 fH2Sigma = new TH2F("fH2Sigma", "Sigma", 31, 0., TMath::Pi(), 20, 0., 2.);
231 fH2SigmaR = new TH2F("fH2SigmaR", "Sigma", 31, 0., TMath::Pi(), 20, 0., 2.);
234 fHDensity = new TH1F("fHDensity", "density distribution", 100, 0., 20.);
235 fHCSize = new TH1F("fHCSize", "cluster size", 20, -0.5, 19.5);
237 fHNCluster = new TH1F("fHNCluster", "Number of clusters", 11, -0.5, 10.5);
238 fHPtDensity = new TH2F("fHPtDensity", "Pt vs density", 100, 0., 20., 50, 0., 10.);
243 fHists->Add(fH1CEta);
244 fHists->Add(fH1CEtaR);
245 fHists->Add(fH1CPhi);
246 fHists->Add(fH2N1N2);
250 fHists->Add(fH1PtC1);
251 fHists->Add(fH1PtC2);
252 fHists->Add(fH1PtAS);
254 fHists->Add(fH1SPtC);
256 fHists->Add(fH1DPhi);
257 fHists->Add(fH2DPhiEta);
258 fHists->Add(fH2DPhiEtaR);
259 fHists->Add(fH2DPhiEtaL);
260 fHists->Add(fH2DPhiEtaLR);
261 fHists->Add(fH2DPhiEtaC);
262 fHists->Add(fH2DPhiEtaCR);
264 fHists->Add(fH1RespR);
265 fHists->Add(fH1Resp);
266 fHists->Add(fH2Sigma);
267 fHists->Add(fH2SigmaR);
268 fHists->Add(fHCSize);
269 fHists->Add(fHDensity);
270 fHists->Add(fHNCluster);
271 fHists->Add(fHPtDensity);
273 for (Int_t i = 0; i < 10; i++) {
274 fA[i] = new AliKMeansResult(i+1);
275 fB[i] = new AliKMeansResult(i+1);
279 //________________________________________________________________________
280 void AliAnalysisTaskKMeans::UserExec(Option_t *)
283 // Called for each event
291 Printf("ERROR: fESD not available");
299 // Fill eta-phi positions
305 for (Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++) {
306 AliVParticle* track = fInputEvent->GetTrack(iTracks);
307 if ((fCuts->AcceptTrack((AliESDtrack*)track)))
309 phi [ic] = track->Phi();
310 phiR[ic] = 2. * TMath::Pi() * gRandom->Rndm();
311 eta [ic] = track->Eta();
312 etaR[ic] = 1.8 * gRandom->Rndm() - 0.9;
313 pt [ic] = track->Pt();
314 if (pt[ic] > ptmax) {
331 AliKMeansResult* res = 0;
333 for (Int_t i = 0; i < fK; i++) {
335 AliKMeansClustering::SoftKMeans2(i+1, ic, phi, eta, res->GetMx(),res->GetMy(), res->GetSigma2(), res->GetRk());
336 res->Sort(ic, phi, eta);
337 Int_t j = (res->GetInd())[0];
338 rk0[i] = (res->GetTarget())[j];
343 Double_t* sigma2 = 0;
347 for (Int_t i = 0; i < fK; i++) {
358 sigma2 = res->GetSigma2();
360 Int_t im = (res->GetInd())[0];
361 fHDensity->Fill(rmax / TMath::Pi());
362 fHCSize->Fill(rmax * sigma2[im]);
363 fHNCluster->Fill(Float_t(nk));
365 Double_t dphic, detac;
370 // Cluster Multiplicity
371 Int_t mult[2] = {0, 0};
374 dphic = DeltaPhi(mPhi[0], mPhi[1]);
375 detac = TMath::Abs(mEta[0] - mEta[1]);
376 fH2DPhiEtaC->Fill(dphic, detac);
379 // Random cluster position
380 Int_t ir = Int_t(Float_t(ic) * gRandom->Rndm());
382 Double_t crPhi = phi[ir];
383 Double_t crEta = eta[ir];
388 for (Int_t i = 0; i < 1; i++) {
389 fH1CEta->Fill(mEta[im]);
390 fH1CPhi->Fill(mPhi[im]);
391 for (Int_t j = 0; j < ic; j++) {
392 Double_t r = DeltaR(mPhi[im], mEta[im], phi[j], eta[j]);
393 Double_t dphi = DeltaPhi(mPhi[im], phi[j]);
394 Double_t deta = mEta[im] - eta[j];
395 Double_t rr = DeltaR(crPhi, crEta, phi[j], eta[j]);
399 fH2DPhiEta->Fill(dphi, TMath::Abs(deta));
400 if (j == icmax) fH2DPhiEtaL->Fill(dphi, TMath::Abs(deta));
403 fH1PtC2->Fill(pt[j]);
406 fH1PtC1->Fill(pt[j]);
407 fHPtDensity->Fill(rmax/TMath::Pi(), pt[j]);
418 if (r > 0.7 && dphi < (TMath::Pi() - 0.3)) {
422 if (r > 0.7 && r < 1.) {
426 if (dphi > (TMath::Pi() - 0.3)) {
427 fH1PtAS->Fill(pt[j]);
432 fH2N1N2->Fill(Float_t(mult[0]), Float_t(mult[1]));
433 fH1SPt ->Fill(sumPt);
434 fH1SPtC->Fill(sumPtC);
439 for (Int_t i = 0; i < fK; i++) {
441 AliKMeansClustering::SoftKMeans2(i+1, ic, phiR, etaR, res->GetMx(),res->GetMy(), res->GetSigma2(), res->GetRk());
442 res->Sort(ic, phiR, etaR);
444 Int_t j = (res->GetInd())[0];
445 rk0[i] = (res->GetTarget())[j];
450 for (Int_t i = 0; i < fK; i++) {
459 sigma2 = res->GetSigma2();
462 // fH1RespR->Fill(rk[ind[0]]/(rk[0]+rk[1]));
464 // Cluster Multiplicity
466 for (Int_t i = 0; i < 1; i++) {
467 im = (res->GetInd())[i];
468 fH1CEtaR->Fill(mEta[im]);
471 for (Int_t i = 0; i < 1; i++) {
472 im = (res->GetInd())[i];
473 for (Int_t j = 0; j < ic; j++) {
474 Double_t dphi = DeltaPhi(mPhi[im], phiR[j]);
475 Double_t deta = mEta[im] - etaR[j];
476 Double_t r = DeltaR(mPhi[im], mEta[im], phiR[j], etaR[j]);
478 fH2DPhiEtaR->Fill(dphi, TMath::Abs(deta));
479 if (j == icmax) fH2DPhiEtaLR->Fill(dphi, TMath::Abs(deta));
483 dphic = DeltaPhi(mPhi[0], mPhi[1]);
484 detac = TMath::Abs(mEta[0] - mEta[1]);
485 fH2DPhiEtaCR->Fill(dphic, detac);
491 Double_t AliAnalysisTaskKMeans::DeltaPhi(Double_t phi1, Double_t phi2)
493 Double_t dphi = TMath::Abs(phi1 - phi2);
494 if (dphi > TMath::Pi()) dphi = 2. * TMath::Pi() - dphi;
498 Double_t AliAnalysisTaskKMeans::DeltaR(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
500 Double_t dphi = DeltaPhi(phi1, phi2);
501 Double_t deta = eta1 - eta2;
502 return (TMath::Sqrt(dphi * dphi + deta * deta));
506 //________________________________________________________________________
507 void AliAnalysisTaskKMeans::Terminate(Option_t *)