1 /**************************************************************************
2 * Authors: Martha Spyropoulou-Stassinaki and the members
3 * of the Greek group at Physics Department of Athens University
4 * Paraskevi Ganoti, Anastasia Belogianni and Filimon Roukoutakis
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 **************************************************************************/
16 //-----------------------------------------------------------------
17 // AliAnalysisKinkESDMC class
18 // Example of an analysis task for kink topology study
19 // Kaons from kink topology are 'identified' in this code
20 //-----------------------------------------------------------------
28 #include "TParticle.h"
32 #include "AliAnalysisTask.h"
33 #include "AliAnalysisManager.h"
35 #include "AliVEvent.h"
36 #include "AliESDEvent.h"
37 #include "AliMCEvent.h"
38 #include "AliAnalysisKinkESDMC.h"
40 #include "AliESDpid.h"
41 #include "AliESDkink.h"
43 ClassImp(AliAnalysisKinkESDMC)
46 //________________________________________________________________________
47 AliAnalysisKinkESDMC::AliAnalysisKinkESDMC(const char *name)
48 : AliAnalysisTaskSE(name), fHistPtESD(0),fHistPt(0),fHistQtAll(0),fHistQt1(0),fHistQt2(0)
49 , fHistPtKaon(0),fHistPtKPDG(0),fHistEta(0),fHistEtaK(0),fptKMC(0),fMultiplMC(0),fESDMult(0),fgenpt(0),frad(0),
50 fKinkKaon(0), fKinkKaonBg(0), fM1kaon(0), fgenPtEtR(0),fPtKink(0), fptKink(0),
51 fcodeH(0), fdcodeH(0), fAngMomK(0),fAngMomPi(0), fAngMomKC(0), fMultESDK(0), fMultMCK(0),
53 fZvXv(0),fZvYv(0), fXvYv(0), fPtPrKink(0), f1(0), f2(0),
59 // Define input and output slots here
60 // Input slot #0 works with a TChain
61 // DefineInput(0, TChain::Class());
62 DefineOutput(1, TList::Class());
65 //________________________________________________________________________
66 void AliAnalysisKinkESDMC::UserCreateOutputObjects()
71 f1=new TF1("f1","((atan([0]*[1]*(1.0/(sqrt((x^2)*(1.0-([1]^2))-([0]^2)*([1]^2))))))*180.)/[2]",1.1,10.0);
72 f1->SetParameter(0,0.493677);
73 f1->SetParameter(1,0.9127037);
74 f1->SetParameter(2,TMath::Pi());
77 f2=new TF1("f2","((atan([0]*[1]*(1.0/(sqrt((x^2)*(1.0-([1]^2))-([0]^2)*([1]^2))))))*180.)/[2]",0.1,10.0);
78 f2->SetParameter(0,0.13957018);
79 f2->SetParameter(1,0.2731374);
80 f2->SetParameter(2,TMath::Pi());
84 fHistPtESD = new TH1F("fHistPtESD", "P_{T} distribution",100, 0.0,10.0);
85 fHistPtESD->GetXaxis()->SetTitle("P_{T} (GeV/c)");
86 fHistPtESD->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
87 fHistPtESD->SetMarkerStyle(kFullCircle);
88 fHistPt = new TH1F("fHistPt", "P_{T} distribution",100, 0.0,10.0);
89 fHistQtAll = new TH1F("fHistQtAll", "Q_{T} distr All Kinks ",100, 0.0,.250);
90 fHistQt1= new TH1F("fHistQt1", "Q_{T} distribution",100, 0.0,.300);
91 fHistQt2= new TH1F("fHistQt2", "Q_{T} distribution",100, 0.0,.300);
92 fHistPtKaon = new TH1F("fHistPtKaon", "P_{T}Kaon distribution",100, 0.0,10.0);
93 fHistPtKPDG = new TH1F("fHistPtKPDG", "P_{T}Kaon distribution",100, 0.0,10.0);
94 fHistEta= new TH1F("fHistEta", "Eta distribution", 26,-1.3, 1.3);
95 fHistEtaK= new TH1F("fHistEtaK", "EtaK distribution", 26,-1.3, 1.3);
96 fptKMC= new TH1F("fptKMC", "P_{T}Kaon generated",100, 0.0,10.0);
97 fMultiplMC= new TH1F("fMultiplMC", "charge multiplicity MC",60, 0.5,120.5);
98 fESDMult= new TH1F("fESDMult", "charge multipliESD", 60, 0.5,120.5);
99 fgenpt= new TH1F("fgenpt", "genpt K distribution",100, 0.0,10.0);
100 frad= new TH1F("frad", "radius K generated",100,0.,400.);
101 fKinkKaon= new TH1F("fKinkKaon", "P_{T}Kaon kinks identi",100, 0.0,10.0);
102 fKinkKaonBg= new TH1F("fKinkKaonBg", "P_{T}Kaon kinks backgr",100, 0.0,10.0);
103 fM1kaon= new TH1F("fM1kaon","Invar m(kaon) from kink->mu+netrino decay",80,0.0, 0.8);
104 fgenPtEtR= new TH1F("fgenPtEtR", "P_{T}Kaon distribution",100, 0.0,10.0);
105 fPtKink= new TH1F("fPtKink", "P_{T}Kaon Kink bution",100, 0.0,10.0);
106 fptKink= new TH1F("fptKink", "P_{T}Kaon Kink bution",100, 0.0,10.0);
107 fcodeH = new TH2F("fcodeH", "code vrs dcode dist. kinks,K",100,0.,2500.,100,0.,2500.);
108 fdcodeH = new TH2F("fdcodeH", "code vrs dcode dist. kinks,K",100,0.,2500.,100,0.,2500.);
109 fAngMomK= new TH2F("fAngMomK","Decay angle vrs Mother Mom,K",100,0.0,5.0,80,0.,80.);
110 fAngMomPi= new TH2F("fAngMomPi","Decay angle vrs Mother Mom,Pi",100,0.0,5.0,80,0.,80.);
111 fAngMomKC= new TH2F("fAngMomKC","Decay angle vrs Mother Mom,K",100,0.0,5.0,80,0.,80.);
112 fMultESDK=new TH1F("fMultESDK", "charge multipliESD kaons", 60, 0.5,240.5);
113 fMultMCK=new TH1F("fMultMCK", "charge multipli MC kaons",100, 0.5,600.5);
114 fRpr = new TH1D("fRpr", "rad distribution PID pr",50,0.0, 2.5);
115 fZpr = new TH1D("fZpr", "z distribution PID pr ",60,-15.,15.);
116 fZvXv= new TH2F("fZvXv","Xv-Zv main vtx",60,-0.5,0.5,60, -15., 15.0);
117 fZvYv= new TH2F("fZvYv","Yv-Zv main vtx",60,-0.5,0.5, 60, -15., 15.);
118 fXvYv= new TH2F("fXvYv","Xv-Yv main vtx", 60,-1.5,1.5, 60, -1.5, 1.5);
119 fPtPrKink=new TH1F("fPtPrKink","pt of ESD kaonKink tracks",100, 0.0,10.0);
121 fListOfHistos=new TList();
123 fListOfHistos->Add(fHistPtESD);
124 fListOfHistos->Add(fHistPt);
125 fListOfHistos->Add(fHistQtAll);
126 fListOfHistos->Add(fHistQt1);
127 fListOfHistos->Add(fHistQt2);
128 fListOfHistos->Add(fHistPtKaon);
129 fListOfHistos->Add(fHistPtKPDG);
130 fListOfHistos->Add(fHistEta);
131 fListOfHistos->Add(fHistEtaK);
132 fListOfHistos->Add(fptKMC);
133 fListOfHistos->Add(fMultiplMC);
134 fListOfHistos->Add(fESDMult);
135 fListOfHistos->Add(fgenpt);
136 fListOfHistos->Add(frad);
137 fListOfHistos->Add(fKinkKaon);
138 fListOfHistos->Add(fKinkKaonBg);
139 fListOfHistos->Add(fM1kaon);
140 fListOfHistos->Add(fgenPtEtR);
141 fListOfHistos->Add(fPtKink);
142 fListOfHistos->Add(fptKink);
143 fListOfHistos->Add(fcodeH);
144 fListOfHistos->Add(fdcodeH);
145 fListOfHistos->Add(fAngMomK);
146 fListOfHistos->Add(fAngMomPi);
147 fListOfHistos->Add(fAngMomKC);
148 fListOfHistos->Add(fMultESDK);
149 fListOfHistos->Add(fMultMCK);
150 fListOfHistos->Add(fRpr);
151 fListOfHistos->Add(fZpr);
152 fListOfHistos->Add(fZvXv);
153 fListOfHistos->Add(fZvYv);
154 fListOfHistos->Add(fXvYv);
155 fListOfHistos->Add(fPtPrKink);
158 //________________________________________________________________________
159 void AliAnalysisKinkESDMC::UserExec(Option_t *)
162 // Called for each event
164 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
165 // This handler can return the current MC event
167 AliVEvent *event = InputEvent();
169 Printf("ERROR: Could not retrieve event");
173 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event);
175 Printf("ERROR: Could not retrieve esd");
179 AliMCEvent* mcEvent = MCEvent();
181 Printf("ERROR: Could not retrieve MC event");
185 Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
187 AliStack* stack=mcEvent->Stack();
189 //primary tracks in MC
190 Int_t nPrim = stack->GetNprimary();
192 const AliESDVertex *vertex=GetEventVertex(esd);
196 vertex->GetXYZ(vpos);
199 Double_t vtrack[3], ptrack[3];
202 // Int_t nESDTracK = 0;
204 Int_t nGoodTracks = esd->GetNumberOfTracks();
205 fESDMult->Fill(nGoodTracks);
209 for (Int_t iTracks = 0; iTracks < esd->GetNumberOfTracks(); iTracks++) {
210 // loop only on primary tracks
212 AliESDtrack* track = esd->GetTrack(iTracks);
214 Printf("ERROR: Could not receive track %d", iTracks);
219 fHistPt->Fill(track->Pt());
222 Int_t label = track->GetLabel();
223 label = TMath::Abs(label);
224 TParticle * part = stack->Particle(label);
226 // loop only on Primary tracks
227 if (label > nPrim) continue; /// primary tracks only , 26/8/09 EFF study
230 if ( (track->Pt())<.300)continue;
232 // UInt_t status=track->GetStatus();
234 // if((status&AliESDtrack::kITSrefit)==0) continue;
235 // if((status&AliESDtrack::kTPCrefit)==0) continue;
236 // ayksanei to ratio BG/real if((track->GetTPCchi2()/track->GetTPCclusters(0))>4.5) continue;
237 if((track->GetTPCchi2()/track->GetTPCclusters(0))>4.5) continue;
239 Double_t extCovPos[15];
240 track->GetExternalCovariance(extCovPos);
241 // if(extCovPos[0]>2) continue;
242 // if(extCovPos[2]>2) continue;
243 // if(extCovPos[5]>0.5) continue;
244 // if(extCovPos[9]>0.5) continue;
245 // if(extCovPos[14]>2) continue;
248 track->GetXYZ(vtrack);
249 fXvYv->Fill(vtrack[0],vtrack[1]);
250 fZvYv->Fill(vtrack[0],vtrack[2]);
251 fZvXv->Fill(vtrack[1],vtrack[2]);
254 track->GetPxPyPz(ptrack);
256 TVector3 trackMom(ptrack[0],ptrack[1],ptrack[2]);
258 Double_t trackEta=trackMom.Eta();
262 Float_t nSigmaToVertex = GetSigmaToVertex(track);
266 track->GetImpactParameters(bpos,bCovpos);
268 if (bCovpos[0]<=0 || bCovpos[2]<=0) {
269 Printf("Estimated b resolution lower or equal zero!");
270 bCovpos[0]=0; bCovpos[2]=0;
273 Float_t dcaToVertexXYpos = bpos[0];
274 Float_t dcaToVertexZpos = bpos[1];
276 fRpr->Fill(dcaToVertexZpos);
277 // test for secondary kinks , 5/7/2009
278 if(nSigmaToVertex>=4) continue;
279 // if((dcaToVertexXYpos>3.0)||(dcaToVertexZpos>3.0)) continue; //arxiko
280 if((dcaToVertexXYpos>4.0)||(dcaToVertexZpos>5.0)) continue; // 27/8
284 if( (TMath::Abs(trackEta )) > 0.9 ) continue;
285 fHistPtESD->Fill(track->Pt());
289 Int_t indexKinkPos=track->GetKinkIndex(0);
292 fPtKink->Fill(track->Pt()); /// pt from track
296 AliESDkink *kink=esd->GetKink(TMath::Abs(indexKinkPos)-1);
299 Int_t eSDfLabel1=kink->GetLabel(0);
300 TParticle *particle1= stack->Particle(TMath::Abs(eSDfLabel1));
301 Int_t code1= particle1->GetPdgCode();
303 Int_t eSDfLabeld=kink->GetLabel(1);
304 TParticle *particled= stack->Particle(TMath::Abs(eSDfLabeld));
305 Int_t dcode1= particled->GetPdgCode();
307 const TVector3 motherMfromKink(kink->GetMotherP());
308 const TVector3 daughterMKink(kink->GetDaughterP());
309 Float_t qT=kink->GetQt();
311 fHistQtAll->Fill(qT) ; // Qt distr
313 fptKink->Fill(motherMfromKink.Pt()); /// pt from kink
315 Float_t kinkAngle=TMath::RadToDeg()*kink->GetAngle(2);
317 // fake kinks, small Qt and small kink angle
318 if(( kinkAngle<1.)&&(TMath::Abs(code1)==321)&&(TMath::Abs(dcode1)==13)) fHistQt1 ->Fill(qT) ; // Qt distr
320 if(qT<0.012) continue; // remove fake kinks
322 //remove the double taracks
323 if( (kinkAngle<1.) ) continue;
327 if((kink->GetR()>120.)&&(kink->GetR()<220.)&&(TMath::Abs(trackEta)<0.9)&&(label<nPrim)) {
328 if( ( (TMath::Abs(code1)==321)&&(TMath::Abs(dcode1)==13))||
329 ( (TMath::Abs(code1)==321)&&(TMath::Abs(dcode1)==11)) ||
330 ( (TMath::Abs(code1)==321)&&(TMath::Abs(dcode1)==211)) ) {
331 fHistPtKPDG->Fill(track->Pt()); // ALL KAONS (pdg) inside ESD kink sample
332 fHistEta->Fill(trackEta) ; // Eta distr of PDG kink ESD kaons
333 fMultESDK->Fill(nGoodTracks);
334 fHistQt2->Fill(qT); // PDG ESD kaons
338 // maximum decay angle at a given mother momentum
339 Double_t maxDecAngKmu=f1->Eval(motherMfromKink.Mag(),0.,0.,0.);
340 Double_t maxDecAngpimu=f2->Eval(motherMfromKink.Mag(),0.,0.,0.);
341 // two dimensional plot
342 if(TMath::Abs(code1)==321) fAngMomK->Fill(motherMfromKink.Mag(), kinkAngle);
343 if(TMath::Abs(code1)==211) fAngMomPi->Fill(motherMfromKink.Mag(), kinkAngle);
345 // invariant mass of mother track decaying to mu
346 Float_t energyDaughterMu=TMath::Sqrt(daughterMKink.Mag()*daughterMKink.Mag()+0.105658*0.105658);
347 Float_t p1XM= motherMfromKink.Px();
348 Float_t p1YM= motherMfromKink.Py();
349 Float_t p1ZM= motherMfromKink.Pz();
350 Float_t p2XM= daughterMKink.Px();
351 Float_t p2YM= daughterMKink.Py();
352 Float_t p2ZM= daughterMKink.Pz();
353 Float_t p3Daughter=TMath::Sqrt(((p1XM-p2XM)*(p1XM-p2XM))+((p1YM-p2YM)*(p1YM-p2YM))+((p1ZM-p2ZM)*(p1ZM-p2ZM)));
354 Double_t invariantMassKmu= TMath::Sqrt((energyDaughterMu+p3Daughter)*(energyDaughterMu+p3Daughter)-motherMfromKink.Mag()*motherMfromKink.Mag());
356 fM1kaon->Fill(invariantMassKmu);
358 // kaon selection from kinks
359 //if((kinkAngle>maxDecAngpimu)&&(qT>0.05)&&(qT<0.25)&&((kink->GetR()>120.)&&(kink->GetR()<220.))&&(TMath::Abs(trackEta)<0.9)&&(invariantMassKmu<0.6)) {
360 if((kinkAngle>maxDecAngpimu)&&(qT>0.04)&&(qT<0.30)&&((kink->GetR()>120.)&&(kink->GetR()<220.))&&(TMath::Abs(trackEta)<0.9)&&(invariantMassKmu<0.6)) {
362 if( (kinkAngle>maxDecAngKmu*1.1) && ( motherMfromKink.Mag()> 1.2 ) ) fcodeH->Fill(TMath::Abs(code1), TMath::Abs(dcode1));
363 if ( (kinkAngle>maxDecAngKmu*1.1) && ( motherMfromKink.Mag()> 1.2 ) ) fAngMomKC->Fill(motherMfromKink.Mag(), kinkAngle);
366 if ( (kinkAngle>maxDecAngKmu*1.1) && ( motherMfromKink.Mag()> 1.2 ) ) continue; // maximum angle selection revised 22/10/2009
368 fHistPtKaon->Fill(track->Pt()); //all PID kink-kaon
370 // kaons from k to mun and k to pipi and to e decay
371 if( ( (TMath::Abs(code1)==321)&&(TMath::Abs(dcode1)==13))||
372 ( (TMath::Abs(code1)==321)&&(TMath::Abs(dcode1)==11)) ||
373 ( (TMath::Abs(code1)==321)&&(TMath::Abs(dcode1)==211)) ) {
375 if ( label<=nPrim ) fPtPrKink->Fill(track->Pt());
376 fKinkKaon->Fill(track->Pt());
377 fHistEtaK->Fill(trackEta);
380 fKinkKaonBg->Fill(track->Pt());
381 fdcodeH->Fill( TMath::Abs(code1), TMath::Abs(dcode1)); // put it here, 22/10/2009
382 } // primary and all +BG
387 } //End Kink Information
392 // loop over mc particles
394 // variable to count tracks
398 for (Int_t iMc = 0; iMc < nPrim; iMc++)
400 // AliDebug(AliLog::kDebug+1, Form("MC Loop: Processing particle %d.", iMc));
402 TParticle* particle = stack->Particle(iMc);
406 // AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
411 Float_t eta = particle->Eta();
413 if (TMath::Abs(eta) > 0.9)
416 Double_t ptK = particle->Pt();
418 if( ptK <0.300) continue;
420 Int_t code = particle->GetPdgCode();
421 Int_t mcProcess=-1011;
422 if ((code==321)||(code==-321)){
428 // fMultiplMC->Fill(nPrim);
431 Int_t firstD=particle->GetFirstDaughter();
432 Int_t lastD=particle->GetLastDaughter();
433 //loop on secondaries
434 for (Int_t k=firstD;k<=lastD;k++) {
436 TParticle* daughter1=stack->Particle(k); // 27/8
437 Int_t dcode = daughter1->GetPdgCode();
439 mcProcess=daughter1->GetUniqueID();
443 // frad->Fill(daughter1->R());
445 if (((daughter1->R())>120)&&((daughter1->R())<220) ){
446 if (( ( code==321 )&& ( dcode ==-13 ))|| (( code == -321 )&& ( dcode == 13))) fgenPtEtR->Fill( ptK );//to muon
447 // if (( ( code==321 )&& ( dcode ==211 ))|| (( code == -321 )&& ( dcode ==-211))) fgenPtEtR->Fill( ptK );//to pion
448 if (( ( code==321 )&& ( dcode ==-11 ))|| (( code == -321 )&& ( dcode ==11))) fgenPtEtR->Fill( ptK );// to electr
449 if (( ( code==321 )&& ( dcode ==211 ))|| (( code == -321 )&& ( dcode ==-211))) nMCKpi++ ;
451 //fMultMCK->Fill(nPrim);
452 frad->Fill(daughter1->R());
455 // next only to mu decay
456 if (((code==321)&&(dcode==-13))||((code==-321)&&(dcode==13))){
459 if (((daughter1->R())>120)&&((daughter1->R())<220)){
460 // fgenpt->Fill(ptK);
466 if( nMCKpi == 1) fgenPtEtR->Fill(ptK); // k to pipi
467 if( nMCKpi > 1) fgenpt->Fill(ptK);// k to pipipi
474 }// end of mc particle
476 // printf("hello mc");
477 fMultiplMC->Fill(nMCTracks);
478 if( nMCKinkKs>0) fMultMCK->Fill(nPrim);
480 PostData(1, fListOfHistos);
484 //________________________________________________________________________
485 void AliAnalysisKinkESDMC::Terminate(Option_t *)
487 // Draw result to the screen
488 // Called once at the end of the query
491 //____________________________________________________________________//
493 Float_t AliAnalysisKinkESDMC::GetSigmaToVertex(AliESDtrack* esdTrack) const {
494 // Calculates the number of sigma to the vertex.
500 esdTrack->GetImpactParameters(b,bCov);
502 if (bCov[0]<=0 || bCov[2]<=0) {
503 //AliDebug(1, "Estimated b resolution lower or equal zero!");
504 bCov[0]=0; bCov[2]=0;
506 bRes[0] = TMath::Sqrt(bCov[0]);
507 bRes[1] = TMath::Sqrt(bCov[2]);
509 if (bRes[0] == 0 || bRes[1] ==0) return -1;
511 Float_t d = TMath::Sqrt(TMath::Power(b[0]/bRes[0],2) + TMath::Power(b[1]/bRes[1],2));
513 if (TMath::Exp(-d * d / 2) < 1e-10) return 1000;
515 d = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);
519 //____________________________________________________________________//
521 const AliESDVertex* AliAnalysisKinkESDMC::GetEventVertex(const AliESDEvent* esd) const
522 // Get the vertex from the ESD and returns it if the vertex is valid
527 const AliESDVertex* vertex = esd->GetPrimaryVertex();
529 if((vertex->GetStatus()==kTRUE)&&(vertex->GetNContributors()>2)) return vertex;
532 vertex = esd->GetPrimaryVertexSPD();
533 if((vertex->GetStatus()==kTRUE)&&(vertex->GetNContributors()>2)) return vertex;