1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
16 // Analysis task for B2
17 // author: Eulogio Serradilla <eulogio.serradilla@cern.ch>
19 #include <Riostream.h>
26 #include <AliAnalysisTask.h>
27 #include <AliAnalysisManager.h>
30 #include <AliESDEvent.h>
31 #include <AliESDInputHandler.h>
32 #include <AliESDtrackCuts.h>
33 #include <AliExternalTrackParam.h>
35 #include <AliMCEvent.h>
36 #include <AliMCEventHandler.h>
37 #include <AliMCVertex.h>
39 #include <TParticle.h>
40 #include <TParticlePDG.h>
41 #include <TMCProcess.h>
43 #include <AliTriggerAnalysis.h> // for offline signals
44 #include <AliCentrality.h>
45 #include <AliESDUtils.h>
47 #include <AliESDpid.h>
53 #include "AliLnHistoMap.h"
54 #include "AliAnalysisTaskB2.h"
56 ClassImp(AliAnalysisTaskB2)
58 AliAnalysisTaskB2::AliAnalysisTaskB2()
61 , fPartCode(AliPID::kProton)
104 , fTimeZeroType(AliESDpid::kTOF_T0)
111 // Default constructor
113 AliLog::SetGlobalLogLevel(AliLog::kFatal);
115 fTrigAna = new AliTriggerAnalysis();
118 AliAnalysisTaskB2::AliAnalysisTaskB2(const char* name)
119 : AliAnalysisTask(name,"")
121 , fPartCode(AliPID::kProton)
132 , fMaxKNOmult(100000)
134 , fMaxCentrality(100)
164 , fTimeZeroType(AliESDpid::kTOF_T0)
173 DefineInput(0, TChain::Class());
174 DefineOutput(0, AliLnHistoMap::Class());
176 //kFatal, kError, kWarning, kInfo, kDebug, kMaxType
177 AliLog::SetGlobalLogLevel(AliLog::kFatal);
179 fTrigAna = new AliTriggerAnalysis();
182 void AliAnalysisTaskB2::ConnectInputData(Option_t *)
185 // Connect input data
187 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
190 this->Error("ConnectInputData", "could not read chain from input slot 0");
194 // Get the pointer to the existing analysis manager via the static access method.
195 AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
198 this->Error("ConnectInputData", "could not get analysis manager");
202 // cast type AliVEventHandler
203 AliESDInputHandler* esdH = dynamic_cast<AliESDInputHandler*>(mgr->GetInputEventHandler());
206 this->Error("ConnectInputData", "could not get ESDInputHandler");
210 // Get pointer to esd event from input handler
211 fESDevent = esdH->GetEvent();
213 // PID object for TOF
214 fESDpid = esdH->GetESDpid();
217 { //in case of no Tender attached
218 fESDpid = new AliESDpid();
222 if(!fSimulation) return;
224 AliMCEventHandler* mcH = dynamic_cast<AliMCEventHandler*> (mgr->GetMCtruthEventHandler());
227 this->Error("ConnectInputData", "could not get AliMCEventHandler");
231 fMCevent = mcH->MCEvent();
234 this->Error("ConnectInputData", "could not get MC fLnEvent");
239 void AliAnalysisTaskB2::CreateOutputObjects()
242 // Create output objects
244 if(fHistoMap == 0) exit(1); // should be created somewhere else
246 PostData(0, fHistoMap);
249 AliAnalysisTaskB2::~AliAnalysisTaskB2()
252 // Default destructor
255 delete fESDtrackCuts;
260 if(fIsPidOwner) delete fESDpid;
263 void AliAnalysisTaskB2::SetParticleSpecies(const TString& species)
266 // set the particle species and the AliPID code
269 fPartCode = this->GetPidCode(species);
272 void AliAnalysisTaskB2::Exec(Option_t* )
275 // Execute analysis for the current event
279 this->Error("Exec", "AliESDEvent not available");
283 if(fESDtrackCuts == 0)
285 this->Error("Exec", "ESD track cuts not set");
291 this->Error("Exec", "PID not set");
295 fMultTrigger = kFALSE;
296 fCentTrigger = kFALSE;
297 fTriggerFired = kFALSE;
298 fGoodVertex = kFALSE;
299 fPileUpEvent = kFALSE;
301 // --------- multiplicity and centrality ------------------
303 fNtrk = AliESDtrackCuts::GetReferenceMultiplicity(fESDevent);
305 ((TH1D*)fHistoMap->Get(fSpecies + "_Event_Ntrk"))->Fill(fNtrk);
307 fKNOmult = fNtrk/fMeanNtrk;
309 if( (fKNOmult >= fMinKNOmult) && (fKNOmult < fMaxKNOmult) ) fMultTrigger = kTRUE;
313 AliCentrality* esdCent = fESDevent->GetCentrality();
315 Float_t centrality = esdCent->GetCentralityPercentile("V0M");
317 if((centrality >= fMinCentrality) && (centrality < fMaxCentrality)) fCentTrigger = kTRUE;
320 Float_t v0Mult = AliESDUtils::GetCorrV0(fESDevent,v0ScaMult);
322 ((TH1D*)fHistoMap->Get(fSpecies + "_V0_Mult"))->Fill(v0Mult);
323 ((TH1D*)fHistoMap->Get(fSpecies + "_V0_Scaled_Mult"))->Fill(v0ScaMult);
326 // ----------------- trigger --------------------
328 AliInputEventHandler* eventH = dynamic_cast<AliInputEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
331 this->Error("Exec", "could not get AliInputEventHandler");
335 UInt_t triggerBits = eventH->IsEventSelected();
339 fTriggerFired = ( this->IsMB(triggerBits) && fCentTrigger );
343 fTriggerFired = this->IsMB(triggerBits);
344 if(fNoFastOnly) fTriggerFired = ( fTriggerFired && !this->IsFastOnly(triggerBits) );
345 if(fV0AND) fTriggerFired = ( fTriggerFired && this->IsV0AND() );
347 fTriggerFired = ( fTriggerFired && fMultTrigger );
350 // --------------------- vertex --------------
352 const AliESDVertex* vtx = fESDevent->GetPrimaryVertex(); // best primary vertex
358 ((TH2D*)fHistoMap->Get(fSpecies + "_Vertex_YX"))->Fill(vtx->GetX(), vtx->GetY());
359 ((TH2D*)fHistoMap->Get(fSpecies + "_Vertex_YZ"))->Fill(vtx->GetZ(), vtx->GetY());
360 ((TH2D*)fHistoMap->Get(fSpecies + "_Vertex_XZ"))->Fill(vtx->GetZ(), vtx->GetX());
363 if(fESDevent->GetPrimaryVertex()->IsFromVertexerZ())
365 if(fESDevent->GetPrimaryVertex()->GetDispersion() > 0.02) fGoodVertex=kFALSE;
366 if(fESDevent->GetPrimaryVertex()->GetZRes() > 0.25 ) fGoodVertex=kFALSE;
369 if( (vtx->GetX() <= fMinVx) || (vtx->GetX() >= fMaxVx) ) fGoodVertex=kFALSE;
370 if( (vtx->GetY() <= fMinVy) || (vtx->GetY() >= fMaxVy) ) fGoodVertex=kFALSE;
371 if( (vtx->GetZ() <= fMinVz) || (vtx->GetZ() >= fMaxVz) ) fGoodVertex=kFALSE;
373 // -------------------- pile up ------------------
375 if(fESDevent->IsPileupFromSPDInMultBins()) fPileUpEvent = kTRUE;
377 // ---------------- event stats ----------------
379 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(0); // number of events
383 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(1); // triggered events
387 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(3); // valid vertex within a triggered event
389 if((vtx->GetZ() > fMinVz) && (vtx->GetZ() < fMaxVz))
391 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(4); // Vz
393 if( (vtx->GetX() > fMinVx) && (vtx->GetX() < fMaxVx)
394 && (vtx->GetY() > fMinVy) && (vtx->GetY() < fMaxVy))
396 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(5); // Vx, Vy
400 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(6); // VertexerZ
404 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(7); // no pile-up
412 // ------------- Particles and tracks for this event ---------------
414 Int_t nParticles = 0;
417 nParticles = this->GetParticles();
422 // Post the data (input/output slots #0 already used by the base class)
423 PostData(0, fHistoMap);
426 Int_t AliAnalysisTaskB2::GetParticles()
429 // Get particles from current event
431 Int_t nParticles = 0;
433 AliStack* stack = fMCevent->Stack();
436 AliDebug(AliLog::kWarning, "stack not available");
440 for (Int_t i = 0; i < fMCevent->GetNumberOfTracks(); ++i)
442 TParticle* iParticle = stack->Particle(i);
444 if(!iParticle) continue;
446 Int_t pid = fLnID->GetPID(iParticle);
448 if(pid != fPartCode) continue;
450 // ------- physical primaries ------------
452 if(!stack->IsPhysicalPrimary(i)) continue;
454 TString particle = fSpecies;
455 if(iParticle->GetPDG()->Charge() < 0) particle.Prepend("Anti");
457 Double_t genP = iParticle->P();
458 Double_t genPt = iParticle->Pt();
459 Double_t genY = iParticle->Y();
460 Double_t genPhi = iParticle->Phi();
461 Double_t genEta = iParticle->Eta();
463 // --------- all events -----------
465 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_P"))->Fill(genP);
466 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_Pt"))->Fill(genPt);
467 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_Y"))->Fill(genY);
468 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_Phi"))->Fill(genPhi);
469 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_Eta"))->Fill(genEta);
470 ((TH2D*)fHistoMap->Get(particle + "_Gen_Prim_PtY"))->Fill(genY, genPt);
471 ((TH2D*)fHistoMap->Get(particle + "_Gen_Prim_EtaY"))->Fill(genY, genEta);
473 // ------- multiplicity and centrality -------------
475 if( fHeavyIons && !fCentTrigger) continue;
476 if(!fHeavyIons && !fMultTrigger) continue;
478 ((TH1D*)fHistoMap->Get(particle + "_Gen_Mult_Prim_PtY"))->Fill(genY,genPt);
480 // ------ is within phase space? ----------
482 if(TMath::Abs(genY) >= fMaxY) continue;
484 ((TH1D*)fHistoMap->Get(particle + "_Gen_PhS_Prim_Pt"))->Fill(genPt);
486 // ------- is from a triggered event? (same as rec.) --------
490 ((TH1D*)fHistoMap->Get(particle + "_Gen_NoTrig_Prim_Pt"))->Fill(genPt);
494 ((TH1D*)fHistoMap->Get(particle + "_Gen_Trig_Prim_Pt"))->Fill(genPt);
496 // ------- is from an triggered event with good vertex? -------------
498 if(!fESDevent->GetPrimaryVertex()->GetStatus())
500 ((TH1D*)fHistoMap->Get(particle + "_Gen_NoVtx_Prim_Pt"))->Fill(genPt);
503 if(!fGoodVertex) continue;
504 if(fPileUpEvent) continue;
506 ((TH1D*)fHistoMap->Get(particle + "_Gen_Vtx_Prim_Pt"))->Fill(genPt);
508 // ------ is within the geometrical acceptance? ------------
510 if(TMath::Abs(iParticle->Eta()) >= fMaxEta) continue;
512 ((TH2D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_PtY"))->Fill(genY,genPt);
513 ((TH1D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_P"))->Fill(genP);
514 ((TH1D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_Pt"))->Fill(genPt);
515 ((TH1D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_Phi"))->Fill(genPhi);
516 ((TH1D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_Y"))->Fill(genY);
522 Int_t AliAnalysisTaskB2::GetTracks()
525 // Get tracks from current event
531 // --------- trigger, vertex and pile-up -----------
533 if(!fTriggerFired) return 0;
534 if(!fGoodVertex) return 0;
535 if(fPileUpEvent) return 0;
537 // ------------ this is a 'good' event -------------
539 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(2); // analyzed events
541 ((TH1D*)fHistoMap->Get(fSpecies + "_Ana_Event_Ntrk"))->Fill(fNtrk);
545 Double_t nch = this->GetChargedMultiplicity(0.5);
546 ((TH2D*)fHistoMap->Get(fSpecies + "_Ana_Event_Nch_Ntrk"))->Fill(fNtrk, nch);
549 const AliESDVertex* vtx = fESDevent->GetPrimaryVertex();
551 ((TH2D*)fHistoMap->Get(fSpecies + "_Ana_Vertex_YX"))->Fill(vtx->GetX(), vtx->GetY());
552 ((TH2D*)fHistoMap->Get(fSpecies + "_Ana_Vertex_YZ"))->Fill(vtx->GetZ(), vtx->GetY());
553 ((TH2D*)fHistoMap->Get(fSpecies + "_Ana_Vertex_XZ"))->Fill(vtx->GetZ(), vtx->GetX());
558 Float_t v0Mult = AliESDUtils::GetCorrV0(fESDevent,v0ScaMult);
560 ((TH1D*)fHistoMap->Get(fSpecies + "_Ana_V0_Mult"))->Fill(v0Mult);
561 ((TH1D*)fHistoMap->Get(fSpecies + "_Ana_V0_Scaled_Mult"))->Fill(v0ScaMult);
564 // ------- track loop --------
566 for(Int_t i = 0; i < fESDevent->GetNumberOfTracks(); ++i)
568 AliESDtrack* iTrack = fESDevent->GetTrack(i);
570 if(!iTrack) continue;
572 // -------- track cuts ------------------------
574 Double_t theta = this->GetTheta(iTrack);
575 Double_t phi = this->GetPhi(iTrack);
577 ((TH2D*)fHistoMap->Get(fSpecies + "_Before_Phi_Theta"))->Fill(theta,phi);
579 if(!fESDtrackCuts->AcceptTrack(iTrack)) continue; // with next track
580 if(fTOFmatch && !this->AcceptTOFtrack(iTrack)) continue; // with next track
582 // --------------------- end track cuts -----------------------
584 ((TH2D*)fHistoMap->Get(fSpecies + "_After_Phi_Theta"))->Fill(theta, phi);
591 if(fPartCode>AliPID::kTriton) z = 2;
594 TString particle = fSpecies;
595 if(iTrack->GetSign()<0 )
597 particle.Prepend("Anti");
604 iTrack->GetImpactParameters(dcaxy, dcaz);
609 Double_t nSigmaVtx = fESDtrackCuts->GetSigmaToVertex(iTrack);
613 Double_t pt = iTrack->Pt()*z; // pt at DCA
614 Double_t y = this->GetRapidity(iTrack, fPartCode);
615 Double_t pITS = this->GetITSmomentum(iTrack);
616 Double_t pTPC = iTrack->GetTPCmomentum();
617 Double_t pTOF = this->GetTOFmomentum(iTrack);
618 Double_t dEdxITS = iTrack->GetITSsignal();
619 Double_t dEdxTPC = iTrack->GetTPCsignal();
620 Int_t nPointsITS = this->GetITSnPointsPID(iTrack);
621 Int_t nPointsTPC = iTrack->GetTPCsignalN();
631 // --------- track cuts ------------
633 ((TH1D*)fHistoMap->Get(fSpecies + "_TrackCuts_DCAxy"))->Fill(dcaxy);
634 ((TH1D*)fHistoMap->Get(fSpecies + "_TrackCuts_DCAz"))->Fill(dcaz);
635 ((TH1D*)fHistoMap->Get(fSpecies + "_TrackCuts_NSigma"))->Fill(nSigmaVtx);
637 ((TH1D*)fHistoMap->Get(fSpecies + "_TrackCuts_ITSchi2PerCls"))->Fill(this->GetITSchi2PerCluster(iTrack));
639 ((TH1D*)fHistoMap->Get(fSpecies + "_TrackCuts_TPCncls"))->Fill(iTrack->GetTPCNcls());
640 ((TH1D*)fHistoMap->Get(fSpecies + "_TrackCuts_TPCclsOverF"))->Fill((Double_t)iTrack->GetTPCNcls()/(Double_t)iTrack->GetTPCNclsF());
641 ((TH1D*)fHistoMap->Get(fSpecies + "_TrackCuts_TPCxRows"))->Fill(iTrack->GetTPCCrossedRows());
642 ((TH1D*)fHistoMap->Get(fSpecies + "_TrackCuts_TPCchi2PerCls"))->Fill(iTrack->GetTPCchi2()/iTrack->GetTPCNcls());
643 ((TH1D*)fHistoMap->Get(fSpecies + "_TrackCuts_TPCchi2Global"))->Fill(iTrack->GetChi2TPCConstrainedVsGlobal(fESDevent->GetPrimaryVertex()));
647 ((TH2D*)fHistoMap->Get(fSpecies + "_ITS_dEdx_P"))->Fill(pITS, dEdxITS);
648 ((TH2D*)fHistoMap->Get(fSpecies + "_TPC_dEdx_P"))->Fill(pTPC, dEdxTPC);
650 if(this->TOFmatch(iTrack))
652 beta = this->GetBeta(iTrack);
653 m2 = this->GetMassSquare(iTrack);
654 mass = TMath::Sqrt(TMath::Abs(m2));
656 ((TH2D*)fHistoMap->Get(fSpecies + "_TOF_Beta_P"))->Fill(pTOF, beta);
657 ((TH2D*)fHistoMap->Get(fSpecies + "_TOF_Mass_P"))->Fill(pTOF, mass);
660 // -----------------------------------------------
661 // for pid and efficiency
662 // -----------------------------------------------
665 TParticle* iParticle = 0;
669 iParticle = this->GetParticle(iTrack);
671 if(iParticle == 0) continue;
673 simPt = iParticle->Pt();
674 simPhi = iParticle->Phi();
675 simY = iParticle->Y();
677 simpid = fLnID->GetPID(iParticle);
679 if(simpid == fPartCode)
681 TString simparticle = fSpecies;
682 if(this->GetSign(iParticle)<0) simparticle.Prepend("Anti");
684 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_PtY"))->Fill(simY, simPt);
686 if(TMath::Abs(y) < fMaxY)
688 ((TH2D*)fHistoMap->Get(simparticle + "_Response_Matrix"))->Fill(pt, simPt);
691 if(!this->IsFakeTrack(iTrack))
693 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Pt"))->Fill(simPt);
695 if(this->IsPhysicalPrimary(iParticle)) // the efficiency is calculated on the primaries
697 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Prim_Pt"))->Fill(simPt);
698 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Prim_Y"))->Fill(simY);
699 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Prim_Phi"))->Fill(simPhi);
701 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Prim_DCAxy_Pt"))->Fill(simPt,dcaxy);
703 ((TH2D*)fHistoMap->Get(simparticle + "_Prim_Response_Matrix"))->Fill(pt, simPt);
705 ((TH2D*)fHistoMap->Get(simparticle + "_Prim_DiffPt_RecPt"))->Fill(pt,simPt-pt);
707 if( this->TOFmatch(iTrack) )
709 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Prim_M2_P"))->Fill(pTOF, m2);
710 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Prim_M2_Pt"))->Fill(pt, m2);
713 else if(this->IsFromWeakDecay(iParticle))
715 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fdwn_Pt"))->Fill(simPt);
717 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Fdwn_DCAxy_Pt"))->Fill(simPt,dcaxy);
719 else // if(this->IsFromMaterial(iParticle)
721 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Mat_Pt"))->Fill(simPt);
723 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Mat_DCAxy_Pt"))->Fill(simPt,dcaxy);
728 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fake_Pt"))->Fill(simPt);
729 if(this->IsPhysicalPrimary(iParticle))
731 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fake_Prim_Pt"))->Fill(simPt);
733 else if(this->IsFromWeakDecay(iParticle))
735 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fake_Fdwn_Pt"))->Fill(simPt);
739 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fake_Mat_Pt"))->Fill(simPt);
747 Int_t pid = fLnID->GetPID( fPartCode, pITS, dEdxITS, nPointsITS, pTPC, dEdxTPC, nPointsTPC, pTOF, beta, fMaxNSigmaITS, fMaxNSigmaTPC, fMaxNSigmaTOF);
749 // pid table for prior probabilities (only Bayes)
751 Int_t offset = AliPID::kDeuteron - 5;
755 Int_t sim = simpid > AliPID::kProton ? simpid - offset : simpid;
756 Int_t rec = pid > AliPID::kProton ? pid - offset : pid;
758 if((sim > -1) && (rec > -1)) // pid performance
760 ((TH2D*)fHistoMap->Get(fSpecies + "_Stats_PID_Table"))->Fill(sim, rec);
761 ((TH2D*)fHistoMap->Get(fSpecies + "_Stats_PID_Table"))->Fill(9, rec);
765 ((TH2D*)fHistoMap->Get(fSpecies + "_Stats_PID_Table"))->Fill(sim, 9);
769 // for bayes iteration
772 Int_t iBin = pid > AliPID::kProton ? pid - offset : pid;
773 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats_PID"))->Fill(iBin);
776 if(pid != fPartCode) continue;
782 goodPid = ( simpid == pid );
786 ((TH2D*)fHistoMap->Get(particle + "_PID_ITSdEdx_P"))->Fill(pITS, dEdxITS);
787 ((TH2D*)fHistoMap->Get(particle + "_PID_TPCdEdx_P"))->Fill(pTPC, dEdxTPC);
789 if(this->TOFmatch(iTrack))
791 ((TH2D*)fHistoMap->Get(particle + "_PID_Beta_P"))->Fill(pTOF, beta);
792 ((TH2D*)fHistoMap->Get(particle + "_PID_Mass_P"))->Fill(pTOF, mass);
793 if(fSimulation && goodPid)
795 ((TH1D*)fHistoMap->Get(particle + "_Sim_PID_Mass"))->Fill(mass);
799 // ---------------------------------
800 // results in |y| < fMaxY
801 // ---------------------------------
803 ((TH1D*)fHistoMap->Get(particle + "_PID_Y"))->Fill(y);
804 ((TH2D*)fHistoMap->Get(particle + "_PID_Pt_Y"))->Fill(y, pt);
806 if(TMath::Abs(y) >= fMaxY) continue;
808 ((TH1D*)fHistoMap->Get(particle + "_PID_Pt"))->Fill(pt);
809 ((TH1D*)fHistoMap->Get(particle + "_PID_Phi"))->Fill(phi);
811 if( this->TOFmatch(iTrack) )
813 ((TH2D*)fHistoMap->Get(particle + "_PID_M2_Pt"))->Fill(pt, m2);
818 Bool_t m2match = kTRUE;
820 if( fTOFmatch && (fLnID->GetPidProcedure() > AliLnID::kMaxLikelihood))
822 if((m2 < fMinM2) || (m2 >= fMaxM2)) m2match = kFALSE;
827 ((TH2D*)fHistoMap->Get(particle + "_PID_DCAxy_Pt"))->Fill(pt, dcaxy);
828 ((TH2D*)fHistoMap->Get(particle + "_PID_DCAz_Pt"))->Fill(pt, dcaz);
829 ((TH2D*)fHistoMap->Get(particle + "_PID_NSigma_Pt"))->Fill(pt, nSigmaVtx);
832 if(fSimulation && goodPid)
834 // for unfolding and pid contamination
835 if(!this->IsFakeTrack(iTrack))
837 ((TH1D*)fHistoMap->Get(particle + "_Sim_PID_Pt"))->Fill(simPt);
839 if( this->TOFmatch(iTrack) )
841 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_M2_Pt"))->Fill(pt, m2);
844 if(this->IsPhysicalPrimary(iParticle))
846 ((TH1D*)fHistoMap->Get(particle + "_Sim_PID_Prim_Pt"))->Fill(simPt);
851 if(this->IsPhysicalPrimary(iParticle))
853 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Prim_DCAxy_Pt"))->Fill(pt, dcaxy);
854 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Prim_DCAz_Pt"))->Fill(pt, dcaz);
855 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Prim_NSigma_Pt"))->Fill(pt, nSigmaVtx);
857 else if(this->IsFromWeakDecay(iParticle))
859 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fdwn_DCAxy_Pt"))->Fill(pt, dcaxy);
860 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fdwn_DCAz_Pt"))->Fill(pt, dcaz);
861 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fdwn_NSigma_Pt"))->Fill(pt, nSigmaVtx);
863 else // from materials
865 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Mat_DCAxy_Pt"))->Fill(pt, dcaxy);
866 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Mat_DCAz_Pt"))->Fill(pt, dcaz);
867 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Mat_NSigma_Pt"))->Fill(pt, nSigmaVtx);
873 ((TH1D*)fHistoMap->Get(particle + "_Sim_PID_Fake_Pt"))->Fill(simPt);
877 if(this->IsPhysicalPrimary(iParticle))
879 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fake_Prim_DCAxy_Pt"))->Fill(pt, dcaxy);
881 else if(this->IsFromWeakDecay(iParticle))
883 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fake_Fdwn_DCAxy_Pt"))->Fill(pt, dcaxy);
885 else // from materials
887 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fake_Mat_DCAxy_Pt"))->Fill(pt, dcaxy);
897 void AliAnalysisTaskB2::Terminate(Option_t* )
899 // The Terminate() function is the last function to be called during
900 // a query. It always runs on the client, it can be used to present
901 // the results graphically or save the results to file.
905 Bool_t AliAnalysisTaskB2::IsV0AND() const
908 // signals in both V0A and V0C
910 return ( fTrigAna->IsOfflineTriggerFired(fESDevent, AliTriggerAnalysis::kV0A) &&
911 fTrigAna->IsOfflineTriggerFired(fESDevent, AliTriggerAnalysis::kV0C) );
914 Bool_t AliAnalysisTaskB2::IsFastOnly(UInt_t triggerBits) const
919 return ( (triggerBits&AliVEvent::kFastOnly) == AliVEvent::kFastOnly );
922 Bool_t AliAnalysisTaskB2::IsMB(UInt_t triggerBits) const
927 return ( (triggerBits&AliVEvent::kMB) == AliVEvent::kMB );
930 Bool_t AliAnalysisTaskB2::TOFmatch(const AliESDtrack* trk) const
933 // Check for TOF match signal
935 return ( trk->IsOn(AliESDtrack::kTOFout) && trk->IsOn(AliESDtrack::kTIME) );
938 Bool_t AliAnalysisTaskB2::AcceptTOFtrack(const AliESDtrack* trk) const
941 // Additional checks for TOF match signal
943 if( !this->TOFmatch(trk) ) return kFALSE;
944 if( trk->GetIntegratedLength() < 350) return kFALSE;
945 if( trk->GetTOFsignal() < 1e-6) return kFALSE;
950 TParticle* AliAnalysisTaskB2::GetParticle(const AliESDtrack* trk) const
953 // Particle that left the track
955 AliStack* stack = fMCevent->Stack();
957 Int_t label = TMath::Abs(trk->GetLabel()); // if negative then it shares points from other tracks
958 if( label >= fMCevent->GetNumberOfTracks() ) return 0;
960 return stack->Particle(label);
963 Bool_t AliAnalysisTaskB2::IsFakeTrack(const AliESDtrack* trk) const
966 // Check if the track shares some clusters with different particles
968 return ( trk->GetLabel() < 0 );
971 Bool_t AliAnalysisTaskB2::IsPhysicalPrimary(const TParticle* prt) const
974 // Check if the particle is physical primary
976 AliStack* stack = fMCevent->Stack();
977 Int_t index = stack->Particles()->IndexOf(prt);
979 return stack->IsPhysicalPrimary(index);
982 Bool_t AliAnalysisTaskB2::IsFromMaterial(const TParticle* prt) const
985 // Check if the particle is originated at the materials
987 AliStack* stack = fMCevent->Stack();
988 Int_t index = stack->Particles()->IndexOf(prt);
990 return stack->IsSecondaryFromMaterial(index);
993 Bool_t AliAnalysisTaskB2::IsFromWeakDecay(const TParticle* prt) const
996 // Check if the particle comes from a weak decay
998 AliStack* stack = fMCevent->Stack();
999 Int_t index = stack->Particles()->IndexOf(prt);
1001 return stack->IsSecondaryFromWeakDecay(index);
1004 Double_t AliAnalysisTaskB2::GetSign(TParticle* prt) const
1007 // Sign of the particle
1009 TParticlePDG* pdg = prt->GetPDG();
1011 if(pdg != 0) return pdg->Charge();
1016 Double_t AliAnalysisTaskB2::GetPhi(const AliESDtrack* trk) const
1019 // Azimuthal angle [0,2pi) using the pt at the DCA point
1021 Double_t px = trk->Px();
1022 Double_t py = trk->Py();
1024 return TMath::Pi()+TMath::ATan2(-py, -px);
1027 Double_t AliAnalysisTaskB2::GetTheta(const AliESDtrack* trk) const
1030 // Polar angle using the pt at the DCA point
1032 Double_t p = trk->GetP();
1033 Double_t pz = trk->Pz();
1035 return (pz == 0) ? TMath::PiOver2() : TMath::ACos(pz/p);
1038 Double_t AliAnalysisTaskB2::GetRapidity(const AliESDtrack* trk, Int_t pid) const
1041 // Rapidity assuming the given particle hypothesis
1042 // and using the momentum at the DCA
1044 Double_t m = AliPID::ParticleMass(pid);
1045 Double_t p = (pid>AliPID::kTriton) ? 2.*trk->GetP() : trk->GetP();
1046 Double_t e = TMath::Sqrt(p*p + m*m);
1047 Double_t pz = (pid>AliPID::kTriton) ? 2.*trk->Pz() : trk->Pz();
1049 if(e <= pz) return 1.e+16;
1051 return 0.5*TMath::Log( (e+pz)/(e-pz) );
1054 Double_t AliAnalysisTaskB2::GetITSmomentum(const AliESDtrack* trk) const
1057 // Momentum for ITS pid
1059 Double_t pDCA = trk->GetP();
1060 Double_t pTPC = trk->GetTPCmomentum();
1062 return (pDCA+pTPC)/2.;
1065 Double_t AliAnalysisTaskB2::GetTOFmomentum(const AliESDtrack* trk) const
1068 // Momentum for TOF pid
1070 Double_t pDCA = trk->GetP();
1072 const AliExternalTrackParam* param = trk->GetOuterParam();
1073 Double_t pOut = param ? param->GetP() : trk->GetP();
1075 return (pDCA+pOut)/2.;
1078 Double_t AliAnalysisTaskB2::GetBeta(const AliESDtrack* trk) const
1083 Double_t t = this->GetTimeOfFlight(trk); // ps
1084 Double_t l = trk->GetIntegratedLength(); // cm
1086 if(t <= 0) return 1.e6; // 1M times the speed of light ;)
1088 return (l/t)/2.99792458e-2;
1091 Double_t AliAnalysisTaskB2::GetMassSquare(const AliESDtrack* trk) const
1096 Double_t p = (fPartCode>AliPID::kTriton) ? 2.*this->GetTOFmomentum(trk) : this->GetTOFmomentum(trk);
1097 Double_t beta = this->GetBeta(trk);
1099 return p*p*(1./(beta*beta) - 1.);
1102 Int_t AliAnalysisTaskB2::GetChargedMultiplicity(Double_t etaMax) const
1105 // Charged particle multiplicity using ALICE physical primary definition
1107 AliStack* stack = fMCevent->Stack();
1110 //for (Int_t i=0; i < stack->GetNprimary(); ++i)
1111 for (Int_t i=0; i < stack->GetNtrack(); ++i)
1113 if(!stack->IsPhysicalPrimary(i)) continue;
1115 TParticle* iParticle = stack->Particle(i);
1117 if(TMath::Abs(iParticle->Eta()) >= etaMax) continue;
1118 //if (iParticle->Pt() < -1) continue;
1120 TParticlePDG* iPDG = iParticle->GetPDG(); // There are some particles with no PDG
1121 if (iPDG && iPDG->Charge() == 0) continue;
1129 Double_t AliAnalysisTaskB2::GetTimeOfFlight(const AliESDtrack* trk) const
1132 // Time of flight associated to the track.
1133 // Adapted from ANALYSIS/AliAnalysisTaskESDfilter.cxx
1135 if(!fESDevent->GetTOFHeader())
1136 { //protection in case the pass2 LHC10b,c,d have been processed without tender.
1137 Float_t t0spread[10];
1138 Float_t intrinsicTOFres=100; //ps ok for LHC10b,c,d pass2!!
1139 for (Int_t j=0; j<10; j++) t0spread[j] = (TMath::Sqrt(fESDevent->GetSigma2DiamondZ()))/0.03; //0.03 to convert from cm to ps
1140 fESDpid->GetTOFResponse().SetT0resolution(t0spread);
1141 fESDpid->GetTOFResponse().SetTimeResolution(intrinsicTOFres);
1143 fESDpid->SetTOFResponse(fESDevent, (AliESDpid::EStartTimeType_t)fTimeZeroType);
1146 if(fESDevent->GetTOFHeader() && fIsPidOwner) fESDpid->SetTOFResponse(fESDevent, (AliESDpid::EStartTimeType_t)fTimeZeroType); //in case of AOD production strating form LHC10e without Tender.
1148 Double_t timeZero = fESDpid->GetTOFResponse().GetStartTime(trk->P());
1150 return trk->GetTOFsignal()-timeZero;
1153 Int_t AliAnalysisTaskB2::GetITSnClusters(const AliESDtrack* trk) const
1156 // ITS number of clusters
1158 UChar_t map = trk->GetITSClusterMap();
1161 for(Int_t j=0; j<6; j++)
1163 if(map&(1<<j)) ++npoints;
1169 Double_t AliAnalysisTaskB2::GetITSchi2PerCluster(const AliESDtrack* trk) const
1172 // ITS chi2 per number of clusters
1174 Double_t chi2 = trk->GetITSchi2();
1175 Int_t ncls = this->GetITSnClusters(trk);
1177 Double_t chi2ncls = (ncls==0) ? 1.e10 : chi2/ncls;
1182 Int_t AliAnalysisTaskB2::GetITSnPointsPID(const AliESDtrack* trk) const
1185 // ITS number of points for PID
1187 UChar_t map = trk->GetITSClusterMap();
1190 for(Int_t j=2; j<6; j++)
1192 if(map&(1<<j)) ++npoints;
1198 Int_t AliAnalysisTaskB2::GetPidCode(const TString& species) const
1201 // Return AliPID code of the given species
1203 TString name = species;
1206 if(name == "electron") return AliPID::kElectron;
1207 if(name == "muon") return AliPID::kMuon;
1208 if(name == "pion") return AliPID::kPion;
1209 if(name == "kaon") return AliPID::kKaon;
1210 if(name == "proton") return AliPID::kProton;
1211 if(name == "deuteron") return AliPID::kDeuteron;
1212 if(name == "triton") return AliPID::kTriton;
1213 if(name == "he3") return AliPID::kHe3;
1214 if(name == "alpha") return AliPID::kAlpha;