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());
149 AliAnalysisTaskKMeans::AliAnalysisTaskKMeans(const AliAnalysisTaskKMeans &res)
150 : AliAnalysisTaskSE(res)
181 // Dummy copy constructor
184 AliAnalysisTaskKMeans& AliAnalysisTaskKMeans::operator=(const AliAnalysisTaskKMeans& /*trclass*/)
186 // Dummy assignment operator
192 //________________________________________________________________________
193 void AliAnalysisTaskKMeans::UserCreateOutputObjects()
197 fHists = new TList();
198 fH1CEta = new TH1F("fH1CEta", "eta distribution of clusters", 90, -1.5, 1.5);
199 fH1CEtaR = new TH1F("fH1CEtaR", "eta distribution of clusters", 90, -1.5, 1.5);
200 fH1CPhi = new TH1F("fH1CPhi", "phi distribution of clusters", 157, 0.0, 2. * TMath::Pi());
201 fH2N1N2 = new TH2F("fH2N1N2", "multiplicity distribution", 50, 0., 50., 50, 0., 50.);
203 fH1Pt = new TH1F("fH1Pt", "pt distribution",50, 0., 10.);
204 fH1PtC = new TH1F("fH1PtC", "pt distribution",50, 0., 10.);
205 fH1PtC1 = new TH1F("fH1PtC1", "pt distribution",50, 0., 10.);
206 fH1PtC2 = new TH1F("fH1PtC2", "pt distribution",50, 0., 10.);
207 fH1PtAS = new TH1F("fH1PtAS", "pt distribution",50, 0., 10.);
208 fH1PtR = new TH1F("fH1PtR", "pt distribution",50, 0., 10.);
210 fH1SPt = new TH1F("fH1SPt", "sum pt distribution",50, 0., 10.);
211 fH1SPtC = new TH1F("fH1SPtC", "sum pt distribution",50, 0., 10.);
213 fH1DR = new TH1F("fH1DR", "dR distribution", 50, 0., 5.);
214 fH1DPhi = new TH1F("fH1DPhi", "dPhi distribution", 31, 0., TMath::Pi());
215 fH2DPhiEta = new TH2F("fH2DPhiEta","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
216 fH2DPhiEtaR = new TH2F("fH2DPhiEtaR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
217 fH2DPhiEtaL = new TH2F("fH2DPhiEtaL","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
218 fH2DPhiEtaLR = new TH2F("fH2DPhiEtaLR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
219 fH2DPhiEtaC = new TH2F("fH2DPhiEtaC","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
220 fH2DPhiEtaCR = new TH2F("fH2DPhiEtaCR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
221 fH1DRR = new TH1F("fH1DRR", "dR distribution", 50, 0., 5.);
222 fH1Resp = new TH1F("fH1Resp", "Responsibility", 50, 0., 1.);
223 fH1RespR = new TH1F("fH1RespR", "Responsibility", 50, 0., 1.);
224 fH2Sigma = new TH2F("fH2Sigma", "Sigma", 31, 0., TMath::Pi(), 20, 0., 2.);
225 fH2SigmaR = new TH2F("fH2SigmaR", "Sigma", 31, 0., TMath::Pi(), 20, 0., 2.);
228 fHDensity = new TH1F("fHDensity", "density distribution", 100, 0., 20.);
229 fHCSize = new TH1F("fHCSize", "cluster size", 20, -0.5, 19.5);
231 fHNCluster = new TH1F("fHNCluster", "Number of clusters", 11, -0.5, 10.5);
232 fHPtDensity = new TH2F("fHPtDensity", "Pt vs density", 100, 0., 20., 50, 0., 10.);
237 fHists->Add(fH1CEta);
238 fHists->Add(fH1CEtaR);
239 fHists->Add(fH1CPhi);
240 fHists->Add(fH2N1N2);
244 fHists->Add(fH1PtC1);
245 fHists->Add(fH1PtC2);
246 fHists->Add(fH1PtAS);
248 fHists->Add(fH1SPtC);
250 fHists->Add(fH1DPhi);
251 fHists->Add(fH2DPhiEta);
252 fHists->Add(fH2DPhiEtaR);
253 fHists->Add(fH2DPhiEtaL);
254 fHists->Add(fH2DPhiEtaLR);
255 fHists->Add(fH2DPhiEtaC);
256 fHists->Add(fH2DPhiEtaCR);
258 fHists->Add(fH1RespR);
259 fHists->Add(fH1Resp);
260 fHists->Add(fH2Sigma);
261 fHists->Add(fH2SigmaR);
262 fHists->Add(fHCSize);
263 fHists->Add(fHDensity);
264 fHists->Add(fHNCluster);
265 fHists->Add(fHPtDensity);
267 for (Int_t i = 0; i < 10; i++) {
268 fA[i] = new AliKMeansResult(i+1);
269 fB[i] = new AliKMeansResult(i+1);
273 //________________________________________________________________________
274 void AliAnalysisTaskKMeans::UserExec(Option_t *)
277 // Called for each event
285 Printf("ERROR: fESD not available");
293 // Fill eta-phi positions
299 for (Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++) {
300 AliVParticle* track = fInputEvent->GetTrack(iTracks);
301 if ((fCuts->AcceptTrack((AliESDtrack*)track)))
303 phi [ic] = track->Phi();
304 phiR[ic] = 2. * TMath::Pi() * gRandom->Rndm();
305 eta [ic] = track->Eta();
306 etaR[ic] = 1.8 * gRandom->Rndm() - 0.9;
307 pt [ic] = track->Pt();
308 if (pt[ic] > ptmax) {
325 AliKMeansResult* res = 0;
327 for (Int_t i = 0; i < fK; i++) {
329 AliKMeansClustering::SoftKMeans2(i+1, ic, phi, eta, res->GetMx(),res->GetMy(), res->GetSigma2(), res->GetRk());
330 res->Sort(ic, phi, eta);
331 Int_t j = (res->GetInd())[0];
332 rk0[i] = (res->GetTarget())[j];
337 Double_t* sigma2 = 0;
341 for (Int_t i = 0; i < fK; i++) {
352 sigma2 = res->GetSigma2();
354 Int_t im = (res->GetInd())[0];
355 fHDensity->Fill(rmax / TMath::Pi());
356 fHCSize->Fill(rmax * sigma2[im]);
357 fHNCluster->Fill(Float_t(nk));
359 Double_t dphic, detac;
364 // Cluster Multiplicity
365 Int_t mult[2] = {0, 0};
368 dphic = DeltaPhi(mPhi[0], mPhi[1]);
369 detac = TMath::Abs(mEta[0] - mEta[1]);
370 fH2DPhiEtaC->Fill(dphic, detac);
373 // Random cluster position
374 Int_t ir = Int_t(Float_t(ic) * gRandom->Rndm());
376 Double_t crPhi = phi[ir];
377 Double_t crEta = eta[ir];
382 for (Int_t i = 0; i < 1; i++) {
383 fH1CEta->Fill(mEta[im]);
384 fH1CPhi->Fill(mPhi[im]);
385 for (Int_t j = 0; j < ic; j++) {
386 Double_t r = DeltaR(mPhi[im], mEta[im], phi[j], eta[j]);
387 Double_t dphi = DeltaPhi(mPhi[im], phi[j]);
388 Double_t deta = mEta[im] - eta[j];
389 Double_t rr = DeltaR(crPhi, crEta, phi[j], eta[j]);
393 fH2DPhiEta->Fill(dphi, TMath::Abs(deta));
394 if (j == icmax) fH2DPhiEtaL->Fill(dphi, TMath::Abs(deta));
397 fH1PtC2->Fill(pt[j]);
400 fH1PtC1->Fill(pt[j]);
401 fHPtDensity->Fill(rmax/TMath::Pi(), pt[j]);
412 if (r > 0.7 && dphi < (TMath::Pi() - 0.3)) {
416 if (r > 0.7 && r < 1.) {
420 if (dphi > (TMath::Pi() - 0.3)) {
421 fH1PtAS->Fill(pt[j]);
426 fH2N1N2->Fill(Float_t(mult[0]), Float_t(mult[1]));
427 fH1SPt ->Fill(sumPt);
428 fH1SPtC->Fill(sumPtC);
433 for (Int_t i = 0; i < fK; i++) {
435 AliKMeansClustering::SoftKMeans2(i+1, ic, phiR, etaR, res->GetMx(),res->GetMy(), res->GetSigma2(), res->GetRk());
436 res->Sort(ic, phiR, etaR);
438 Int_t j = (res->GetInd())[0];
439 rk0[i] = (res->GetTarget())[j];
444 for (Int_t i = 0; i < fK; i++) {
453 sigma2 = res->GetSigma2();
456 // fH1RespR->Fill(rk[ind[0]]/(rk[0]+rk[1]));
458 // Cluster Multiplicity
460 for (Int_t i = 0; i < 1; i++) {
461 Int_t im = (res->GetInd())[i];
462 fH1CEtaR->Fill(mEta[im]);
465 for (Int_t i = 0; i < 1; i++) {
466 Int_t im = (res->GetInd())[i];
467 for (Int_t j = 0; j < ic; j++) {
468 Double_t dphi = DeltaPhi(mPhi[im], phiR[j]);
469 Double_t deta = mEta[im] - etaR[j];
470 Double_t r = DeltaR(mPhi[im], mEta[im], phiR[j], etaR[j]);
472 fH2DPhiEtaR->Fill(dphi, TMath::Abs(deta));
473 if (j == icmax) fH2DPhiEtaLR->Fill(dphi, TMath::Abs(deta));
477 dphic = DeltaPhi(mPhi[0], mPhi[1]);
478 detac = TMath::Abs(mEta[0] - mEta[1]);
479 fH2DPhiEtaCR->Fill(dphic, detac);
485 Double_t AliAnalysisTaskKMeans::DeltaPhi(Double_t phi1, Double_t phi2)
487 Double_t dphi = TMath::Abs(phi1 - phi2);
488 if (dphi > TMath::Pi()) dphi = 2. * TMath::Pi() - dphi;
492 Double_t AliAnalysisTaskKMeans::DeltaR(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
494 Double_t dphi = DeltaPhi(phi1, phi2);
495 Double_t deta = eta1 - eta2;
496 return (TMath::Sqrt(dphi * dphi + deta * deta));
500 //________________________________________________________________________
501 void AliAnalysisTaskKMeans::Terminate(Option_t *)