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 "AliAnalysisTaskSE.h"
33 #include "AliAnalysisManager.h"
35 #include "AliESDEvent.h"
36 #include "AliESDInputHandler.h"
38 #include "AliMCEventHandler.h"
39 #include "AliMCEvent.h"
41 #include "AliAnalysisKinkESDMC.h"
44 #include "AliESDpid.h"
45 #include "AliESDkink.h"
47 ClassImp(AliAnalysisKinkESDMC)
49 //________________________________________________________________________
50 AliAnalysisKinkESDMC::AliAnalysisKinkESDMC()
51 : AliAnalysisTaskSE(), fESD(0),fHistPtESD(),fHistPt(0),fHistQtAll(0),fHistQt1(0),fHistQt2(0)
52 , fHistPtKaon(0),fHistPtKPDG(0),fHistEta(0),fHistEtaK(0),fptKMC(0),fMultiplMC(0),fESDMult(0),fgenpt(0),frad(0),
53 fKinkKaon(0), fKinkKaonBg(0), fM1kaon(0), fgenPtEtR(0),fPtKink(0), fptKink(0),
54 fcodeH(0), fdcodeH(0), fAngMomK(0),fAngMomPi(0),
57 fZvXv(0),fZvYv(0), fXvYv(0), fPtPrKink(0), f1(0), f2(0),
66 //________________________________________________________________________
67 AliAnalysisKinkESDMC::AliAnalysisKinkESDMC(const char *name)
68 : AliAnalysisTaskSE(name), fESD(0),fHistPtESD(0),fHistPt(0),fHistQtAll(0),fHistQt1(0),fHistQt2(0)
69 , fHistPtKaon(0),fHistPtKPDG(0),fHistEta(0),fHistEtaK(0),fptKMC(0),fMultiplMC(0),fESDMult(0),fgenpt(0),frad(0),
70 fKinkKaon(0), fKinkKaonBg(0), fM1kaon(0), fgenPtEtR(0),fPtKink(0), fptKink(0),
71 fcodeH(0), fdcodeH(0), fAngMomK(0),fAngMomPi(0),
74 fZvXv(0),fZvYv(0), fXvYv(0), fPtPrKink(0), f1(0), f2(0),
76 // , faod(0), fSignalTree(0)
81 // Define input and output slots here
82 // Input slot #0 works with a TChain
83 DefineInput(0, TChain::Class());
84 DefineOutput(1, TList::Class());
87 //________________________________________________________________________
88 void AliAnalysisKinkESDMC::ConnectInputData(Option_t *)
90 // Connect ESD or AOD here
93 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
95 Printf("ERROR: Could not read chain from input slot 0");
97 // Disable all branches, we want to process only MC
98 tree->SetBranchStatus("*", kTRUE);
99 // tree->SetBranchStatus("fTracks.*", kTRUE);
100 tree->SetBranchStatus("*Calo*", kFALSE);
101 tree->SetBranchStatus("FMD", kFALSE);
103 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
106 Printf("ERROR: Could not get ESDInputHandler");
108 fESD = esdH->GetEvent();
112 //________________________________________________________________________
113 void AliAnalysisKinkESDMC::CreateOutputObjects()
118 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);
119 f1->SetParameter(0,0.493677);
120 f1->SetParameter(1,0.9127037);
121 f1->SetParameter(2,TMath::Pi());
124 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);
125 f2->SetParameter(0,0.13957018);
126 f2->SetParameter(1,0.2731374);
127 f2->SetParameter(2,TMath::Pi());
131 fHistPtESD = new TH1F("fHistPtESD", "P_{T} distribution", 60, 0.0, 6.0);
132 fHistPtESD->GetXaxis()->SetTitle("P_{T} (GeV/c)");
133 fHistPtESD->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
134 fHistPtESD->SetMarkerStyle(kFullCircle);
135 fHistPt = new TH1F("fHistPt", "P_{T} distribution", 60, 0.0, 6.0);
136 fHistQtAll = new TH1F("fHistQtAll", "Q_{T} distr All Kinks ",100, 0.0,.250);
137 fHistQt1= new TH1F("fHistQt1", "Q_{T} distribution",100, 0.0,.300);
138 fHistQt2= new TH1F("fHistQt2", "Q_{T} distribution",100, 0.0,.300);
139 fHistPtKaon = new TH1F("fHistPtKaon", "P_{T}Kaon distribution", 60, 0.0, 6.0);
140 fHistPtKPDG = new TH1F("fHistPtKPDG", "P_{T}Kaon distribution", 60, 0.0, 6.0);
141 fHistEta= new TH1F("fHistEta", "Eta distribution", 26,-1.3, 1.3);
142 fHistEtaK= new TH1F("fHistEtaK", "EtaK distribution", 26,-1.3, 1.3);
143 fptKMC= new TH1F("fptKMC", "P_{T}Kaon generated", 60, 0.0, 6.0);
144 fMultiplMC= new TH1F("fMultiplMC", "charge multiplicity MC", 60, 0.5,120.5);
145 fESDMult= new TH1F("fESDMult", "charge multipliESD", 60, 0.5,120.5);
146 fgenpt= new TH1F("fgenpt", "genpt K distribution", 60, 0.0, 6.0);
147 frad= new TH1F("frad", "radius K generated",100,0.,400.);
148 fKinkKaon= new TH1F("fKinkKaon", "P_{T}Kaon kinks identi", 60, 0.0, 6.0);
149 fKinkKaonBg= new TH1F("fKinkKaonBg", "P_{T}Kaon kinks backgr", 60, 0.0, 6.0);
150 fM1kaon= new TH1F("fM1kaon","Invar m(kaon) from kink->mu+netrino decay",80,0.0, 0.8);
151 fgenPtEtR= new TH1F("fgenPtEtR", "P_{T}Kaon distribution", 60, 0.0, 6.0);
152 fPtKink= new TH1F("fPtKink", "P_{T}Kaon Kink bution", 60, 0.0, 6.0);
153 fptKink= new TH1F("fptKink", "P_{T}Kaon Kink bution", 60, 0.0, 6.0);
154 fcodeH = new TH2F("fcodeH", "code vrs dcode dist. kinks,K",100,0.,2500.,100,0.,2500.);
155 fdcodeH = new TH2F("fdcodeH", "code vrs dcode dist. kinks,K",100,0.,2500.,100,0.,2500.);
156 fAngMomK= new TH2F("fAngMomK","Decay angle vrs Mother Mom,K",100,0.0,5.0,80,0.,80.);
157 fAngMomPi= new TH2F("fAngMomPi","Decay angle vrs Mother Mom,Pi",100,0.0,5.0,80,0.,80.);
159 fRpr = new TH1D("fRpr", "rad distribution PID pr",50,0.0, 2.5);
160 fZpr = new TH1D("fZpr", "z distribution PID pr ",60,-15.,15.);
161 fAngMomKC= new TH2F("fAngMomKC","Decay angle vrs Mother Mom,K",100,0.0,5.0,80,0.,80.);
162 fZvXv= new TH2F("fZvXv","Xv-Zv main vtx",60,-0.5,0.5,60, -15., 15.0);
163 fZvYv= new TH2F("fZvYv","Yv-Zv main vtx",60,-0.5,0.5, 60, -15., 15.);
164 fXvYv= new TH2F("fXvYv","Xv-Yv main vtx", 60,-1.5,1.5, 60, -1.5, 1.5);
165 fPtPrKink=new TH1F("fPtPrKink","pt of ESD kaonKink tracks", 60, 0.0, 6.0);
167 fListOfHistos=new TList();
169 fListOfHistos->Add(fHistPtESD);
170 fListOfHistos->Add(fHistPt);
171 fListOfHistos->Add(fHistQtAll);
172 fListOfHistos->Add(fHistQt1);
173 fListOfHistos->Add(fHistQt2);
174 fListOfHistos->Add(fHistPtKaon);
175 fListOfHistos->Add(fHistPtKPDG);
176 fListOfHistos->Add(fHistEta);
177 fListOfHistos->Add(fHistEtaK);
178 fListOfHistos->Add(fptKMC);
179 fListOfHistos->Add(fMultiplMC);
180 fListOfHistos->Add(fESDMult);
181 fListOfHistos->Add(fgenpt);
182 fListOfHistos->Add(frad);
183 fListOfHistos->Add(fKinkKaon);
184 fListOfHistos->Add(fKinkKaonBg);
185 fListOfHistos->Add(fM1kaon);
186 fListOfHistos->Add(fgenPtEtR);
187 fListOfHistos->Add(fPtKink);
188 fListOfHistos->Add(fptKink);
189 fListOfHistos->Add(fcodeH);
190 fListOfHistos->Add(fdcodeH);
191 fListOfHistos->Add(fdcodeH);
192 fListOfHistos->Add(fAngMomK);
193 fListOfHistos->Add(fAngMomPi);
194 fListOfHistos->Add(fRpr);
195 fListOfHistos->Add(fZpr);
196 fListOfHistos->Add(fAngMomKC);
197 fListOfHistos->Add(fZvXv);
198 fListOfHistos->Add(fZvYv);
199 fListOfHistos->Add(fXvYv);
200 fListOfHistos->Add(fPtPrKink);
203 //________________________________________________________________________
204 void AliAnalysisKinkESDMC::Exec(Option_t *)
207 // Called for each event
209 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
210 // This handler can return the current MC event
212 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
214 Printf("ERROR: Could not retrieve MC event handler");
218 AliMCEvent* mcEvent = eventHandler->MCEvent();
220 Printf("ERROR: Could not retrieve MC event");
224 Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
227 Printf("ERROR: fESD not available");
230 AliStack* stack=mcEvent->Stack();
232 //primary tracks in MC
233 Int_t nPrim = stack->GetNprimary();
235 const AliESDVertex *vertex=GetEventVertex(fESD);
239 vertex->GetXYZ(vpos);
241 fZvXv->Fill( vpos[1], vpos[2]);
242 fZvYv->Fill( vpos[0], vpos[2]);
244 Double_t vtrack[3], ptrack[3];
248 Int_t nGoodTracks = fESD->GetNumberOfTracks();
249 fESDMult->Fill(nGoodTracks);
252 for (Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
253 AliESDtrack* track = fESD->GetTrack(iTracks);
255 Printf("ERROR: Could not receive track %d", iTracks);
260 fHistPt->Fill(track->Pt());
263 if ( (track->Pt())<.300)continue;
265 UInt_t status=track->GetStatus();
267 // if((status&AliESDtrack::kITSrefit)==0) continue;
268 if((status&AliESDtrack::kTPCrefit)==0) continue;
269 if((track->GetTPCchi2()/track->GetTPCclusters(0))>3.5) continue;
271 Double_t extCovPos[15];
272 track->GetExternalCovariance(extCovPos);
273 if(extCovPos[0]>2) continue;
274 if(extCovPos[2]>2) continue;
275 if(extCovPos[5]>0.5) continue;
276 if(extCovPos[9]>0.5) continue;
277 if(extCovPos[14]>2) continue;
280 track->GetXYZ(vtrack);
281 fXvYv->Fill(vtrack[0],vtrack[1]);
284 track->GetPxPyPz(ptrack);
286 TVector3 trackMom(ptrack[0],ptrack[1],ptrack[2]);
288 Double_t trackEta=trackMom.Eta();
292 Float_t nSigmaToVertex = GetSigmaToVertex(track);
296 track->GetImpactParameters(bpos,bCovpos);
298 if (bCovpos[0]<=0 || bCovpos[2]<=0) {
299 Printf("Estimated b resolution lower or equal zero!");
300 bCovpos[0]=0; bCovpos[2]=0;
303 Float_t dcaToVertexXYpos = bpos[0];
304 Float_t dcaToVertexZpos = bpos[1];
306 fRpr->Fill(dcaToVertexZpos);
308 if(nSigmaToVertex>=4) continue;
309 if((dcaToVertexXYpos>3.0)||(dcaToVertexZpos>3.0)) continue;
312 Int_t label = track->GetLabel();
313 label = TMath::Abs(label);
314 TParticle * part = stack->Particle(label);
318 if( (TMath::Abs(trackEta )) > 1.1 ) continue;
319 fHistPtESD->Fill(track->Pt());
323 Int_t indexKinkPos=track->GetKinkIndex(0);
326 fPtKink->Fill(track->Pt()); /// pt from track
330 AliESDkink *kink=fESD->GetKink(TMath::Abs(indexKinkPos)-1);
333 Int_t eSDfLabel1=kink->GetLabel(0);
334 TParticle *particle1= stack->Particle(TMath::Abs(eSDfLabel1));
335 Int_t code1= particle1->GetPdgCode();
337 Int_t eSDfLabeld=kink->GetLabel(1);
338 TParticle *particled= stack->Particle(TMath::Abs(eSDfLabeld));
339 Int_t dcode1= particled->GetPdgCode();
341 const TVector3 motherMfromKink(kink->GetMotherP());
342 const TVector3 daughterMKink(kink->GetDaughterP());
343 Float_t qT=kink->GetQt();
345 fHistEta->Fill(trackEta) ; // Eta distr
346 fHistQtAll->Fill(qT) ; // Qt distr
348 fptKink->Fill(motherMfromKink.Pt()); /// pt from kink
350 // fake kinks, small Qt and small kink angle
351 if ( qT<0.012) fcodeH->Fill( TMath::Abs(code1), TMath::Abs(dcode1) );
352 if(qT<0.012) continue; // remove fake kinks
354 Float_t kinkAngle=TMath::RadToDeg()*kink->GetAngle(2);
356 //remove the double taracks
358 if( (kinkAngle<1.) ) continue;
360 if( (qT>0.05)&& ( qT<0.25) ) fHistQt2->Fill(qT); // candidate kaon kinks
362 if (TMath::Abs(code1)==321) fHistPtKPDG->Fill(track->Pt()); // ALL KAONS (pdg) inside kink sample
364 // maximum decay angle at a given mother momentum
365 Double_t maxDecAngKmu=f1->Eval(motherMfromKink.Mag(),0.,0.,0.);
366 Double_t maxDecAngpimu=f2->Eval(motherMfromKink.Mag(),0.,0.,0.);
367 // two dimensional plot
368 if(TMath::Abs(code1)==321) fAngMomK->Fill(motherMfromKink.Mag(), kinkAngle);
369 if(TMath::Abs(code1)==211) fAngMomPi->Fill(motherMfromKink.Mag(), kinkAngle);
371 // invariant mass of mother track decaying to mu
372 Float_t energyDaughterMu=TMath::Sqrt(daughterMKink.Mag()*daughterMKink.Mag()+0.105658*0.105658);
373 Float_t p1XM= motherMfromKink.Px();
374 Float_t p1YM= motherMfromKink.Py();
375 Float_t p1ZM= motherMfromKink.Pz();
376 Float_t p2XM= daughterMKink.Px();
377 Float_t p2YM= daughterMKink.Py();
378 Float_t p2ZM= daughterMKink.Pz();
379 Float_t p3Daughter=TMath::Sqrt(((p1XM-p2XM)*(p1XM-p2XM))+((p1YM-p2YM)*(p1YM-p2YM))+((p1ZM-p2ZM)*(p1ZM-p2ZM)));
380 Double_t invariantMassKmu= TMath::Sqrt((energyDaughterMu+p3Daughter)*(energyDaughterMu+p3Daughter)-motherMfromKink.Mag()*motherMfromKink.Mag());
382 fM1kaon->Fill(invariantMassKmu);
384 // kaon selection from kinks
385 if((kinkAngle>maxDecAngpimu)&&(qT>0.05)&&(qT<0.25)&&((kink->GetR()>110.)&&(kink->GetR()<230.))&&(TMath::Abs(trackEta)<1.1)&&(invariantMassKmu<0.6)) {
386 fHistEtaK->Fill(trackEta);
388 if(TMath::Abs(code1)==321) fAngMomKC->Fill(motherMfromKink.Mag(), kinkAngle); // real kaons
390 fHistQt1 ->Fill(qT) ; // Qt distr
391 if ( (kinkAngle>maxDecAngKmu) && ( motherMfromKink.Mag()> 1.1 ) ) continue; // maximum angle selection
393 fHistPtKaon->Fill(track->Pt()); //all PID kink-kaon
395 // background inside the identified kaons, e.g KK , Kp
396 if((TMath::Abs(code1)==321)&&(( TMath::Abs(dcode1)) >=(TMath::Abs(code1)) )) fdcodeH->Fill( TMath::Abs(code1), TMath::Abs(dcode1));
398 if((TMath::Abs(code1)==321) ) {
400 if ( label< nPrim ) fPtPrKink->Fill(track->Pt());
401 fKinkKaon->Fill(track->Pt()); }
403 fKinkKaonBg->Fill(track->Pt());
404 } // primary and secondary
409 } //End Kink Information
414 // loop over mc particles
416 // variable to count tracks
419 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
421 // AliDebug(AliLog::kDebug+1, Form("MC Loop: Processing particle %d.", iMc));
423 TParticle* particle = stack->Particle(iMc);
427 // AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
432 Float_t eta = particle->Eta();
434 if (TMath::Abs(eta) > 1.1)
437 Double_t ptK = particle->Pt();
439 if( ptK <0.300) continue;
441 Float_t code = particle->GetPdgCode();
442 if (code==321 || code==-321){
447 Int_t firstD=particle->GetFirstDaughter();
448 Int_t lastD=particle->GetLastDaughter();
449 //loop on secondaries
450 for (Int_t k=firstD;k<lastD;k++) {
451 TParticle* daughter1=stack->Particle(k+1);
452 Float_t dcode = daughter1->GetPdgCode();
456 frad->Fill(daughter1->R());
458 if (((daughter1->R())>110)&&((daughter1->R())<230) ){
459 if (( ( code==321 )&& ( dcode ==-13 ))|| (( code == -321 )&& ( dcode == 13))) fgenPtEtR->Fill( ptK );//to muon
460 if (( ( code==321 )&& ( dcode ==211 ))|| (( code == -321 )&& ( dcode ==-211))) fgenPtEtR->Fill( ptK );//to pion
461 // if (( ( code==321 )&& ( dcode ==-11 ))|| (( code == -321 )&& ( dcode ==11))) fgenPtEtR->Fill( ptK );// to electr
464 // next only to mu decay
465 if (((code==321)&&(dcode==-13))||((code==-321)&&(dcode==13))){
468 if (((daughter1->R())>110)&&((daughter1->R())<230)){
479 }// end of mc particle
481 // printf("hello mc");
482 fMultiplMC->Fill(nMCTracks);
484 PostData(1, fListOfHistos);
488 //________________________________________________________________________
489 void AliAnalysisKinkESDMC::Terminate(Option_t *)
491 // Draw result to the screen
492 // Called once at the end of the query
495 //____________________________________________________________________//
497 Float_t AliAnalysisKinkESDMC::GetSigmaToVertex(AliESDtrack* esdTrack) const {
498 // Calculates the number of sigma to the vertex.
504 esdTrack->GetImpactParameters(b,bCov);
506 if (bCov[0]<=0 || bCov[2]<=0) {
507 //AliDebug(1, "Estimated b resolution lower or equal zero!");
508 bCov[0]=0; bCov[2]=0;
510 bRes[0] = TMath::Sqrt(bCov[0]);
511 bRes[1] = TMath::Sqrt(bCov[2]);
513 if (bRes[0] == 0 || bRes[1] ==0) return -1;
515 Float_t d = TMath::Sqrt(TMath::Power(b[0]/bRes[0],2) + TMath::Power(b[1]/bRes[1],2));
517 if (TMath::Exp(-d * d / 2) < 1e-10) return 1000;
519 d = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);
523 //____________________________________________________________________//
525 const AliESDVertex* AliAnalysisKinkESDMC::GetEventVertex(const AliESDEvent* esd) const
526 // Get the vertex from the ESD and returns it if the vertex is valid
531 const AliESDVertex* vertex = esd->GetPrimaryVertex();
533 if((vertex->GetStatus()==kTRUE)&&(vertex->GetNContributors()>2)) return vertex;
536 vertex = esd->GetPrimaryVertexSPD();
537 if((vertex->GetStatus()==kTRUE)&&(vertex->GetNContributors()>2)) return vertex;