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>
54 #include "AliLnHistoMap.h"
55 #include "AliAnalysisTaskB2.h"
57 ClassImp(AliAnalysisTaskB2)
59 AliAnalysisTaskB2::AliAnalysisTaskB2()
62 , fPartCode(AliPID::kProton)
107 , fTimeZeroType(AliESDpid::kTOF_T0)
114 // Default constructor
116 AliLog::SetGlobalLogLevel(AliLog::kFatal);
118 fTrigAna = new AliTriggerAnalysis();
121 AliAnalysisTaskB2::AliAnalysisTaskB2(const char* name)
122 : AliAnalysisTask(name,"")
124 , fPartCode(AliPID::kProton)
135 , fMaxKNOmult(100000)
137 , fMaxCentrality(100)
159 , fOutputContainer(0)
169 , fTimeZeroType(AliESDpid::kTOF_T0)
178 DefineInput(0, TChain::Class());
179 DefineOutput(0, TTree::Class());
180 DefineOutput(1, TList::Class());
182 //kFatal, kError, kWarning, kInfo, kDebug, kMaxType
183 AliLog::SetGlobalLogLevel(AliLog::kFatal);
185 fTrigAna = new AliTriggerAnalysis();
188 void AliAnalysisTaskB2::ConnectInputData(Option_t *)
191 // Connect input data
193 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
196 this->Error("ConnectInputData", "could not read chain from input slot 0");
200 // Get the pointer to the existing analysis manager via the static access method.
201 AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
204 this->Error("ConnectInputData", "could not get analysis manager");
208 // cast type AliVEventHandler
209 AliESDInputHandler* esdH = dynamic_cast<AliESDInputHandler*>(mgr->GetInputEventHandler());
212 this->Error("ConnectInputData", "could not get ESDInputHandler");
216 // Get pointer to esd event from input handler
217 fESDevent = esdH->GetEvent();
219 // PID object for TOF
220 fESDpid = esdH->GetESDpid();
223 { //in case of no Tender attached
224 fESDpid = new AliESDpid();
228 if(!fSimulation) return;
230 AliMCEventHandler* mcH = dynamic_cast<AliMCEventHandler*> (mgr->GetMCtruthEventHandler());
233 this->Error("ConnectInputData", "could not get AliMCEventHandler");
237 fMCevent = mcH->MCEvent();
240 this->Error("ConnectInputData", "could not get MC fLnEvent");
245 void AliAnalysisTaskB2::CreateOutputObjects()
248 // Create output objects
250 if(fHistoMap == 0) exit(1); // should be created somewhere else
252 fOutputContainer = new TList();
253 fOutputContainer->SetOwner(kTRUE);
256 TIter iter(fHistoMap->GetMap());
257 while((key = (TObjString*)iter.Next())) fOutputContainer->Add((TH1*)fHistoMap->Get(key));
259 PostData(1, fOutputContainer);
262 AliAnalysisTaskB2::~AliAnalysisTaskB2()
265 // Default destructor
268 delete fOutputContainer;
269 delete fESDtrackCuts;
274 if(fIsPidOwner) delete fESDpid;
277 void AliAnalysisTaskB2::SetParticleSpecies(const TString& species)
280 // set the particle species and the AliPID code
283 fPartCode = this->GetPidCode(species);
286 void AliAnalysisTaskB2::Exec(Option_t* )
289 // Execute analysis for the current event
293 this->Error("Exec", "AliESDEvent not available");
297 if(fESDtrackCuts == 0)
299 this->Error("Exec", "ESD track cuts not set");
305 this->Error("Exec", "PID not set");
309 fMultTrigger = kFALSE;
310 fCentTrigger = kFALSE;
311 fTriggerFired = kFALSE;
312 fGoodVertex = kFALSE;
313 fPileUpEvent = kFALSE;
315 // --------- multiplicity and centrality ------------------
317 fNtrk = AliESDtrackCuts::GetReferenceMultiplicity(fESDevent, AliESDtrackCuts::kTrackletsITSTPC, fMaxEta);
318 if(fSimulation) fNch = this->GetChargedMultiplicity(fMaxEta);
320 ((TH1D*)fHistoMap->Get(fSpecies + "_Event_Ntrk"))->Fill(fNtrk);
322 fKNOmult = fNtrk/fMeanNtrk;
324 if( (fKNOmult >= fMinKNOmult) && (fKNOmult < fMaxKNOmult) ) fMultTrigger = kTRUE;
328 AliCentrality* esdCent = fESDevent->GetCentrality();
330 Float_t centrality = esdCent->GetCentralityPercentile("V0M");
332 if((centrality >= fMinCentrality) && (centrality < fMaxCentrality)) fCentTrigger = kTRUE;
335 Float_t v0Mult = AliESDUtils::GetCorrV0(fESDevent,v0ScaMult);
337 ((TH1D*)fHistoMap->Get(fSpecies + "_V0_Mult"))->Fill(v0Mult);
338 ((TH1D*)fHistoMap->Get(fSpecies + "_V0_Scaled_Mult"))->Fill(v0ScaMult);
341 // ----------------- trigger --------------------
343 AliInputEventHandler* eventH = dynamic_cast<AliInputEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
346 this->Error("Exec", "could not get AliInputEventHandler");
350 UInt_t triggerBits = eventH->IsEventSelected();
354 fTriggerFired = ( this->IsMB(triggerBits) && fCentTrigger );
358 fTriggerFired = this->IsMB(triggerBits);
359 if(fNoFastOnly) fTriggerFired = ( fTriggerFired && !this->IsFastOnly(triggerBits) );
360 if(fV0AND) fTriggerFired = ( fTriggerFired && this->IsV0AND() );
362 fTriggerFired = ( fTriggerFired && fMultTrigger );
365 // --------------------- vertex --------------
367 const AliESDVertex* vtx = fESDevent->GetPrimaryVertex(); // best primary vertex
373 ((TH2D*)fHistoMap->Get(fSpecies + "_Vertex_YX"))->Fill(vtx->GetX(), vtx->GetY());
374 ((TH2D*)fHistoMap->Get(fSpecies + "_Vertex_YZ"))->Fill(vtx->GetZ(), vtx->GetY());
375 ((TH2D*)fHistoMap->Get(fSpecies + "_Vertex_XZ"))->Fill(vtx->GetZ(), vtx->GetX());
378 if(fESDevent->GetPrimaryVertex()->IsFromVertexerZ())
380 if(fESDevent->GetPrimaryVertex()->GetDispersion() > 0.02) fGoodVertex=kFALSE;
381 if(fESDevent->GetPrimaryVertex()->GetZRes() > 0.25 ) fGoodVertex=kFALSE;
384 if( (vtx->GetX() <= fMinVx) || (vtx->GetX() >= fMaxVx) ) fGoodVertex=kFALSE;
385 if( (vtx->GetY() <= fMinVy) || (vtx->GetY() >= fMaxVy) ) fGoodVertex=kFALSE;
386 if( (vtx->GetZ() <= fMinVz) || (vtx->GetZ() >= fMaxVz) ) fGoodVertex=kFALSE;
388 // -------------------- pile up ------------------
390 if(fESDevent->IsPileupFromSPDInMultBins()) fPileUpEvent = kTRUE;
392 // ---------------- event stats ----------------
394 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(0); // number of events
398 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(1); // triggering events
402 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(3); // valid vertex within a triggering event
404 if((vtx->GetZ() > fMinVz) && (vtx->GetZ() < fMaxVz))
406 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(4); // Vz
408 if( (vtx->GetX() > fMinVx) && (vtx->GetX() < fMaxVx)
409 && (vtx->GetY() > fMinVy) && (vtx->GetY() < fMaxVy))
411 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(5); // Vx, Vy
415 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(6); // VertexerZ
419 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(7); // no pile-up
427 // ------------- Particles and tracks for this event ---------------
429 Int_t nParticles = 0;
432 nParticles = this->GetParticles();
437 // Post the data (input/output slots #0 already used by the base class)
438 PostData(1, fOutputContainer);
441 Int_t AliAnalysisTaskB2::GetParticles()
444 // Get particles from current event
446 Int_t nParticles = 0;
448 AliStack* stack = fMCevent->Stack();
451 AliDebug(AliLog::kWarning, "stack not available");
455 for (Int_t i = 0; i < fMCevent->GetNumberOfTracks(); ++i)
457 TParticle* iParticle = stack->Particle(i);
459 if(!iParticle) continue;
461 Int_t pid = fLnID->GetPID(iParticle);
463 if(pid != fPartCode) continue;
465 // ------- physical primaries ------------
467 if(!stack->IsPhysicalPrimary(i)) continue;
469 TString particle = fSpecies;
470 if(iParticle->GetPDG()->Charge() < 0) particle.Prepend("Anti");
472 Double_t genP = iParticle->P();
473 Double_t genPt = iParticle->Pt();
474 Double_t genY = iParticle->Y();
475 Double_t genPhi = iParticle->Phi();
476 Double_t genEta = iParticle->Eta();
478 // ------- multiplicity and centrality -------------
480 if( fHeavyIons && !fCentTrigger) continue;
481 if(!fHeavyIons && !fMultTrigger) continue;
483 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_P"))->Fill(genP);
484 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_Pt"))->Fill(genPt);
485 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_Y"))->Fill(genY);
486 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_Phi"))->Fill(genPhi);
487 ((TH1D*)fHistoMap->Get(particle + "_Gen_Prim_Eta"))->Fill(genEta);
488 ((TH2D*)fHistoMap->Get(particle + "_Gen_Prim_PtY"))->Fill(genY, genPt);
489 ((TH2D*)fHistoMap->Get(particle + "_Gen_Prim_EtaY"))->Fill(genY, genEta);
491 // ------ is within phase space? ----------
493 if(TMath::Abs(genY) >= fMaxY) continue;
495 ((TH1D*)fHistoMap->Get(particle + "_Gen_PhS_Prim_P"))->Fill(genP);
496 ((TH1D*)fHistoMap->Get(particle + "_Gen_PhS_Prim_Pt"))->Fill(genPt);
498 // ------- is from a triggering event? (same as rec.) --------
502 ((TH1D*)fHistoMap->Get(particle + "_Gen_NoTrig_Prim_Pt"))->Fill(genPt);
506 ((TH1D*)fHistoMap->Get(particle + "_Gen_Trig_Prim_Pt"))->Fill(genPt);
508 // ------- is from a triggering event with good vertex? -------------
510 if(!fESDevent->GetPrimaryVertex()->GetStatus())
512 ((TH1D*)fHistoMap->Get(particle + "_Gen_NoVtx_Prim_Pt"))->Fill(genPt);
515 if(!fGoodVertex) continue;
516 if(fPileUpEvent) continue;
518 ((TH1D*)fHistoMap->Get(particle + "_Gen_Nch"))->Fill(fNch);
519 ((TH1D*)fHistoMap->Get(particle + "_Gen_Vtx_Prim_Pt"))->Fill(genPt);
521 // ------ is within the geometrical acceptance? ------------
523 if(TMath::Abs(genEta) >= fMaxEta) continue;
525 ((TH2D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_PtY"))->Fill(genY,genPt);
526 ((TH1D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_P"))->Fill(genP);
527 ((TH1D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_Pt"))->Fill(genPt);
528 ((TH1D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_Phi"))->Fill(genPhi);
529 ((TH1D*)fHistoMap->Get(particle + "_Gen_Acc_Prim_Y"))->Fill(genY);
535 Int_t AliAnalysisTaskB2::GetTracks()
538 // Get tracks from current event
544 // --------- trigger, vertex and pile-up -----------
546 if(!fTriggerFired) return 0;
547 if(!fGoodVertex) return 0;
548 if(fPileUpEvent) return 0;
550 // ------------ this is a 'good' event -------------
552 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats"))->Fill(2); // analyzed events
554 ((TH1D*)fHistoMap->Get(fSpecies + "_Ana_Event_Ntrk"))->Fill(fNtrk);
558 ((TH2D*)fHistoMap->Get(fSpecies + "_Ana_Event_Nch_Ntrk"))->Fill(fNtrk, fNch);
561 const AliESDVertex* vtx = fESDevent->GetPrimaryVertex();
563 ((TH2D*)fHistoMap->Get(fSpecies + "_Ana_Vertex_YX"))->Fill(vtx->GetX(), vtx->GetY());
564 ((TH2D*)fHistoMap->Get(fSpecies + "_Ana_Vertex_YZ"))->Fill(vtx->GetZ(), vtx->GetY());
565 ((TH2D*)fHistoMap->Get(fSpecies + "_Ana_Vertex_XZ"))->Fill(vtx->GetZ(), vtx->GetX());
570 Float_t v0Mult = AliESDUtils::GetCorrV0(fESDevent,v0ScaMult);
572 ((TH1D*)fHistoMap->Get(fSpecies + "_Ana_V0_Mult"))->Fill(v0Mult);
573 ((TH1D*)fHistoMap->Get(fSpecies + "_Ana_V0_Scaled_Mult"))->Fill(v0ScaMult);
576 // ------- track loop --------
578 for(Int_t i = 0; i < fESDevent->GetNumberOfTracks(); ++i)
580 AliESDtrack* iTrack = fESDevent->GetTrack(i);
582 if(!iTrack) continue;
585 TString particle = fSpecies;
586 if(iTrack->GetSign()<0 )
588 particle.Prepend("Anti");
592 // -------- track cuts ------------------------
594 Double_t eta = iTrack->Eta();
595 Double_t phi = this->GetPhi(iTrack);
597 ((TH2D*)fHistoMap->Get(particle + "_Before_Phi_Eta"))->Fill(eta,phi);
599 if(!fESDtrackCuts->AcceptTrack(iTrack)) continue; // with next track
600 if(fTOFmatch && !this->AcceptTOFtrack(iTrack)) continue; // with next track
602 // --------------------- end track cuts -----------------------
604 ((TH2D*)fHistoMap->Get(particle + "_After_Phi_Eta"))->Fill(eta, phi);
611 if(fPartCode>AliPID::kTriton) z = 2;
615 iTrack->GetImpactParameters(dcaxy, dcaz);
620 Double_t nSigmaVtx = fESDtrackCuts->GetSigmaToVertex(iTrack);
624 Double_t pt = iTrack->Pt()*z; // pt at DCA
625 Double_t y = this->GetRapidity(iTrack, fPartCode);
626 Double_t pITS = this->GetITSmomentum(iTrack);
627 Double_t pTPC = iTrack->GetTPCmomentum();
628 Double_t pTOF = this->GetTOFmomentum(iTrack);
629 Double_t dEdxITS = iTrack->GetITSsignal();
630 Double_t dEdxTPC = iTrack->GetTPCsignal();
631 Int_t nPointsITS = this->GetITSnPointsPID(iTrack);
632 Int_t nPointsTPC = iTrack->GetTPCsignalN();
642 // --------- track cuts ------------
644 ((TH1D*)fHistoMap->Get(particle + "_TrackCuts_DCAxy"))->Fill(dcaxy);
645 ((TH1D*)fHistoMap->Get(particle + "_TrackCuts_DCAz"))->Fill(dcaz);
646 ((TH1D*)fHistoMap->Get(particle + "_TrackCuts_NSigma"))->Fill(nSigmaVtx);
648 ((TH1D*)fHistoMap->Get(particle + "_TrackCuts_ITSchi2PerCls"))->Fill(this->GetITSchi2PerCluster(iTrack));
650 ((TH1D*)fHistoMap->Get(particle + "_TrackCuts_TPCncls"))->Fill(iTrack->GetTPCNcls());
651 ((TH1D*)fHistoMap->Get(particle + "_TrackCuts_TPCclsOverF"))->Fill((Double_t)iTrack->GetTPCNcls()/(Double_t)iTrack->GetTPCNclsF());
652 ((TH1D*)fHistoMap->Get(particle + "_TrackCuts_TPCxRows"))->Fill(iTrack->GetTPCCrossedRows());
653 ((TH1D*)fHistoMap->Get(particle + "_TrackCuts_TPCchi2PerCls"))->Fill(iTrack->GetTPCchi2()/iTrack->GetTPCNcls());
654 ((TH1D*)fHistoMap->Get(particle + "_TrackCuts_TPCchi2Global"))->Fill(iTrack->GetChi2TPCConstrainedVsGlobal(fESDevent->GetPrimaryVertex()));
658 ((TH2D*)fHistoMap->Get(particle + "_ITS_dEdx_P"))->Fill(pITS, dEdxITS);
659 ((TH2D*)fHistoMap->Get(particle + "_TPC_dEdx_P"))->Fill(pTPC, dEdxTPC);
661 if(this->TOFmatch(iTrack))
663 beta = this->GetBeta(iTrack);
664 m2 = this->GetMassSquare(iTrack);
665 mass = TMath::Sqrt(TMath::Abs(m2));
667 ((TH2D*)fHistoMap->Get(particle + "_TOF_Beta_P"))->Fill(pTOF, beta);
668 ((TH2D*)fHistoMap->Get(particle + "_TOF_Mass_P"))->Fill(pTOF, mass);
671 // -----------------------------------------------
672 // for pid and efficiency
673 // -----------------------------------------------
676 TParticle* iParticle = 0;
680 iParticle = this->GetParticle(iTrack);
682 if(iParticle == 0) continue;
684 simPt = iParticle->Pt();
685 simPhi = iParticle->Phi();
686 simY = iParticle->Y();
688 simpid = fLnID->GetPID(iParticle);
690 if(simpid == fPartCode)
692 TString simparticle = fSpecies;
693 if(this->GetSign(iParticle)<0) simparticle.Prepend("Anti");
695 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_PtY"))->Fill(simY, simPt);
697 if(TMath::Abs(y) < fMaxY)
699 ((TH2D*)fHistoMap->Get(simparticle + "_Response_Matrix"))->Fill(pt, simPt);
701 if(this->IsPhysicalPrimary(iParticle))
703 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Ntrk"))->Fill(fNtrk);
707 if(!this->IsFakeTrack(iTrack))
709 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Pt"))->Fill(simPt);
711 if(this->IsPhysicalPrimary(iParticle)) // the efficiency is calculated on the primaries
713 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Prim_Pt"))->Fill(simPt);
714 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Prim_Y"))->Fill(simY);
715 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Prim_Phi"))->Fill(simPhi);
716 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Prim_Rec_Pt"))->Fill(pt);
718 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Prim_DCAxy_Pt"))->Fill(simPt,dcaxy);
720 ((TH2D*)fHistoMap->Get(simparticle + "_Prim_Response_Matrix"))->Fill(pt, simPt);
722 ((TH2D*)fHistoMap->Get(simparticle + "_Prim_DiffPt_RecPt"))->Fill(pt,simPt-pt);
724 if( this->TOFmatch(iTrack) )
726 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Prim_M2_P"))->Fill(pTOF, m2);
727 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Prim_M2_Pt"))->Fill(pt, m2);
730 else if(this->IsFromWeakDecay(iParticle))
732 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fdwn_Pt"))->Fill(simPt);
734 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Fdwn_DCAxy_Pt"))->Fill(simPt,dcaxy);
736 else // if(this->IsFromMaterial(iParticle)
738 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Mat_Pt"))->Fill(simPt);
740 ((TH2D*)fHistoMap->Get(simparticle + "_Sim_Mat_DCAxy_Pt"))->Fill(simPt,dcaxy);
745 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fake_Pt"))->Fill(simPt);
746 if(this->IsPhysicalPrimary(iParticle))
748 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fake_Prim_Pt"))->Fill(simPt);
750 else if(this->IsFromWeakDecay(iParticle))
752 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fake_Fdwn_Pt"))->Fill(simPt);
756 ((TH1D*)fHistoMap->Get(simparticle + "_Sim_Fake_Mat_Pt"))->Fill(simPt);
764 Int_t pid = fLnID->GetPID( fPartCode, pITS, dEdxITS, nPointsITS, pTPC, dEdxTPC, nPointsTPC, pTOF, beta, fMaxNSigmaITS, fMaxNSigmaTPC, fMaxNSigmaTOF);
766 // pid table for prior probabilities (only Bayes)
768 Int_t offset = AliPID::kDeuteron - 5;
772 Int_t sim = simpid > AliPID::kProton ? simpid - offset : simpid;
773 Int_t rec = pid > AliPID::kProton ? pid - offset : pid;
775 if((sim > -1) && (rec > -1)) // pid performance
777 ((TH2D*)fHistoMap->Get(fSpecies + "_Stats_PID_Table"))->Fill(sim, rec);
778 ((TH2D*)fHistoMap->Get(fSpecies + "_Stats_PID_Table"))->Fill(9, rec);
782 ((TH2D*)fHistoMap->Get(fSpecies + "_Stats_PID_Table"))->Fill(sim, 9);
786 // for bayes iteration
789 Int_t iBin = pid > AliPID::kProton ? pid - offset : pid;
790 ((TH1D*)fHistoMap->Get(fSpecies + "_Stats_PID"))->Fill(iBin);
793 if(pid != fPartCode) continue;
799 goodPid = ( simpid == pid );
802 ((TH1D*)fHistoMap->Get(particle + "_PID_Ntrk_pTPC"))->Fill(pTPC,fNtrk);
803 ((TH1D*)fHistoMap->Get(particle + "_PID_Zmult_pTPC"))->Fill(pTPC,fKNOmult);
806 ((TH2D*)fHistoMap->Get(particle + "_PID_ITSdEdx_P"))->Fill(pITS, dEdxITS);
807 ((TH2D*)fHistoMap->Get(particle + "_PID_TPCdEdx_P"))->Fill(pTPC, dEdxTPC);
809 if(this->TOFmatch(iTrack))
811 ((TH2D*)fHistoMap->Get(particle + "_PID_Beta_P"))->Fill(pTOF, beta);
812 ((TH2D*)fHistoMap->Get(particle + "_PID_Mass_P"))->Fill(pTOF, mass);
813 if(fSimulation && goodPid)
815 ((TH1D*)fHistoMap->Get(particle + "_Sim_PID_Mass"))->Fill(mass);
819 // ---------------------------------
820 // results in |y| < fMaxY
821 // ---------------------------------
823 ((TH1D*)fHistoMap->Get(particle + "_PID_Y"))->Fill(y);
824 ((TH2D*)fHistoMap->Get(particle + "_PID_Pt_Y"))->Fill(y, pt);
826 if(TMath::Abs(y) >= fMaxY) continue;
828 ((TH1D*)fHistoMap->Get(particle + "_PID_Pt"))->Fill(pt);
829 ((TH1D*)fHistoMap->Get(particle + "_PID_Phi"))->Fill(phi);
831 if(iTrack->IsOn(AliESDtrack::kTRDin))
833 ((TH1D*)fHistoMap->Get(particle + "_PID_TRDin_Pt"))->Fill(pt);
835 if(iTrack->IsOn(AliESDtrack::kTRDout)) ((TH1D*)fHistoMap->Get(particle + "_PID_TRDin_TRDout_Pt"))->Fill(pt);
836 if(iTrack->IsOn(AliESDtrack::kTOFout)) ((TH1D*)fHistoMap->Get(particle + "_PID_TRDin_TOFout_Pt"))->Fill(pt);
839 if(iTrack->IsOn(AliESDtrack::kTOFin))
841 ((TH1D*)fHistoMap->Get(particle + "_PID_TOFin_Pt"))->Fill(pt);
843 if(iTrack->IsOn(AliESDtrack::kTOFout)) ((TH1D*)fHistoMap->Get(particle + "_PID_TOFin_TOFout_Pt"))->Fill(pt);
846 if( this->TOFmatch(iTrack) )
848 ((TH2D*)fHistoMap->Get(particle + "_PID_M2_Pt"))->Fill(pt, m2);
849 ((TH1D*)fHistoMap->Get(particle + "_PID_TOFmatch_Pt"))->Fill(pt);
854 Bool_t m2match = kTRUE;
856 if( fTOFmatch && (fLnID->GetPidProcedure() > AliLnID::kMaxLikelihood))
858 if((m2 < fMinM2) || (m2 >= fMaxM2)) m2match = kFALSE;
863 ((TH2D*)fHistoMap->Get(particle + "_PID_DCAxy_Pt"))->Fill(pt, dcaxy);
864 ((TH2D*)fHistoMap->Get(particle + "_PID_DCAz_Pt"))->Fill(pt, dcaz);
865 ((TH2D*)fHistoMap->Get(particle + "_PID_NSigma_Pt"))->Fill(pt, nSigmaVtx);
868 if(fSimulation && goodPid)
870 // for unfolding and pid contamination
871 if(!this->IsFakeTrack(iTrack))
873 ((TH1D*)fHistoMap->Get(particle + "_Sim_PID_Pt"))->Fill(simPt);
875 if( this->TOFmatch(iTrack) )
877 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_M2_Pt"))->Fill(pt, m2);
880 if(this->IsPhysicalPrimary(iParticle))
882 ((TH1D*)fHistoMap->Get(particle + "_Sim_PID_Prim_Pt"))->Fill(simPt);
887 if(this->IsPhysicalPrimary(iParticle))
889 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Prim_DCAxy_Pt"))->Fill(pt, dcaxy);
890 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Prim_DCAz_Pt"))->Fill(pt, dcaz);
891 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Prim_NSigma_Pt"))->Fill(pt, nSigmaVtx);
893 else if(this->IsFromWeakDecay(iParticle))
895 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fdwn_DCAxy_Pt"))->Fill(pt, dcaxy);
896 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fdwn_DCAz_Pt"))->Fill(pt, dcaz);
897 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fdwn_NSigma_Pt"))->Fill(pt, nSigmaVtx);
899 else // from materials
901 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Mat_DCAxy_Pt"))->Fill(pt, dcaxy);
902 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Mat_DCAz_Pt"))->Fill(pt, dcaz);
903 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Mat_NSigma_Pt"))->Fill(pt, nSigmaVtx);
909 ((TH1D*)fHistoMap->Get(particle + "_Sim_PID_Fake_Pt"))->Fill(simPt);
913 if(this->IsPhysicalPrimary(iParticle))
915 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fake_Prim_DCAxy_Pt"))->Fill(pt, dcaxy);
917 else if(this->IsFromWeakDecay(iParticle))
919 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fake_Fdwn_DCAxy_Pt"))->Fill(pt, dcaxy);
921 else // from materials
923 ((TH2D*)fHistoMap->Get(particle + "_Sim_PID_Fake_Mat_DCAxy_Pt"))->Fill(pt, dcaxy);
933 void AliAnalysisTaskB2::Terminate(Option_t* )
935 // The Terminate() function is the last function to be called during
936 // a query. It always runs on the client, it can be used to present
937 // the results graphically or save the results to file.
941 Bool_t AliAnalysisTaskB2::IsV0AND() const
944 // signals in both V0A and V0C
946 return ( fTrigAna->IsOfflineTriggerFired(fESDevent, AliTriggerAnalysis::kV0A) &&
947 fTrigAna->IsOfflineTriggerFired(fESDevent, AliTriggerAnalysis::kV0C) );
950 Bool_t AliAnalysisTaskB2::IsFastOnly(UInt_t triggerBits) const
955 return ( (triggerBits&AliVEvent::kFastOnly) == AliVEvent::kFastOnly );
958 Bool_t AliAnalysisTaskB2::IsMB(UInt_t triggerBits) const
963 return ( (triggerBits&AliVEvent::kMB) == AliVEvent::kMB );
966 Bool_t AliAnalysisTaskB2::TOFmatch(const AliESDtrack* trk) const
969 // Check for TOF match signal
971 return ( trk->IsOn(AliESDtrack::kTOFout) && trk->IsOn(AliESDtrack::kTIME) );
974 Bool_t AliAnalysisTaskB2::AcceptTOFtrack(const AliESDtrack* trk) const
977 // Additional checks for TOF match signal
979 if( !this->TOFmatch(trk) ) return kFALSE;
980 if( trk->GetIntegratedLength() < 350) return kFALSE;
981 if( trk->GetTOFsignal() < 1e-6) return kFALSE;
986 TParticle* AliAnalysisTaskB2::GetParticle(const AliESDtrack* trk) const
989 // Particle that left the track
991 AliStack* stack = fMCevent->Stack();
993 Int_t label = TMath::Abs(trk->GetLabel()); // if negative then it shares points from other tracks
994 if( label >= fMCevent->GetNumberOfTracks() ) return 0;
996 return stack->Particle(label);
999 Bool_t AliAnalysisTaskB2::IsFakeTrack(const AliESDtrack* trk) const
1002 // Check if the track shares some clusters with different particles
1003 // (definition changed to label=0? )
1005 return ( trk->GetLabel() < 0 );
1008 Bool_t AliAnalysisTaskB2::IsPhysicalPrimary(const TParticle* prt) const
1011 // Check if the particle is physical primary
1013 AliStack* stack = fMCevent->Stack();
1014 Int_t index = stack->Particles()->IndexOf(prt);
1016 return stack->IsPhysicalPrimary(index);
1019 Bool_t AliAnalysisTaskB2::IsFromMaterial(const TParticle* prt) const
1022 // Check if the particle is originated at the materials
1024 AliStack* stack = fMCevent->Stack();
1025 Int_t index = stack->Particles()->IndexOf(prt);
1027 return stack->IsSecondaryFromMaterial(index);
1030 Bool_t AliAnalysisTaskB2::IsFromWeakDecay(const TParticle* prt) const
1033 // Check if the particle comes from a weak decay
1035 AliStack* stack = fMCevent->Stack();
1036 Int_t index = stack->Particles()->IndexOf(prt);
1038 return stack->IsSecondaryFromWeakDecay(index);
1041 Double_t AliAnalysisTaskB2::GetSign(TParticle* prt) const
1044 // Sign of the particle
1046 TParticlePDG* pdg = prt->GetPDG();
1048 if(pdg != 0) return pdg->Charge();
1053 Double_t AliAnalysisTaskB2::GetPhi(const AliESDtrack* trk) const
1056 // Azimuthal angle [0,2pi) using the pt at the DCA point
1058 Double_t px = trk->Px();
1059 Double_t py = trk->Py();
1061 return TMath::Pi()+TMath::ATan2(-py, -px);
1064 Double_t AliAnalysisTaskB2::GetTheta(const AliESDtrack* trk) const
1067 // Polar angle using the pt at the DCA point
1069 Double_t p = trk->GetP();
1070 Double_t pz = trk->Pz();
1072 return (pz == 0) ? TMath::PiOver2() : TMath::ACos(pz/p);
1075 Double_t AliAnalysisTaskB2::GetRapidity(const AliESDtrack* trk, Int_t pid) const
1078 // Rapidity assuming the given particle hypothesis
1079 // and using the momentum at the DCA
1081 Double_t m = AliPID::ParticleMass(pid);
1082 Double_t p = (pid>AliPID::kTriton) ? 2.*trk->GetP() : trk->GetP();
1083 Double_t e = TMath::Sqrt(p*p + m*m);
1084 Double_t pz = (pid>AliPID::kTriton) ? 2.*trk->Pz() : trk->Pz();
1086 if(e <= pz) return 1.e+16;
1088 return 0.5*TMath::Log( (e+pz)/(e-pz) );
1091 Double_t AliAnalysisTaskB2::GetITSmomentum(const AliESDtrack* trk) const
1094 // Momentum for ITS pid
1096 Double_t pDCA = trk->GetP();
1097 Double_t pTPC = trk->GetTPCmomentum();
1099 return (pDCA+pTPC)/2.;
1102 Double_t AliAnalysisTaskB2::GetTOFmomentum(const AliESDtrack* trk) const
1105 // Momentum for TOF pid
1107 Double_t pDCA = trk->GetP();
1109 const AliExternalTrackParam* param = trk->GetOuterParam();
1110 Double_t pOut = param ? param->GetP() : trk->GetP();
1112 return (pDCA+pOut)/2.;
1115 Double_t AliAnalysisTaskB2::GetBeta(const AliESDtrack* trk) const
1120 Double_t t = this->GetTimeOfFlight(trk); // ps
1121 Double_t l = trk->GetIntegratedLength(); // cm
1123 if(t <= 0) return 1.e6; // 1M times the speed of light ;)
1125 return (l/t)/2.99792458e-2;
1128 Double_t AliAnalysisTaskB2::GetMassSquare(const AliESDtrack* trk) const
1133 Double_t p = (fPartCode>AliPID::kTriton) ? 2.*this->GetTOFmomentum(trk) : this->GetTOFmomentum(trk);
1134 Double_t beta = this->GetBeta(trk);
1136 return p*p*(1./(beta*beta) - 1.);
1139 Int_t AliAnalysisTaskB2::GetChargedMultiplicity(Double_t etaMax) const
1142 // Charged particle multiplicity using ALICE physical primary definition
1144 AliStack* stack = fMCevent->Stack();
1147 //for (Int_t i=0; i < stack->GetNprimary(); ++i)
1148 for (Int_t i=0; i < stack->GetNtrack(); ++i)
1150 if(!stack->IsPhysicalPrimary(i)) continue;
1152 TParticle* iParticle = stack->Particle(i);
1154 if(TMath::Abs(iParticle->Eta()) >= etaMax) continue;
1155 //if (iParticle->Pt() < -1) continue;
1157 TParticlePDG* iPDG = iParticle->GetPDG(); // There are some particles with no PDG
1158 if (iPDG && iPDG->Charge() == 0) continue;
1166 Double_t AliAnalysisTaskB2::GetTimeOfFlight(const AliESDtrack* trk) const
1169 // Time of flight associated to the track.
1170 // Adapted from ANALYSIS/AliAnalysisTaskESDfilter.cxx
1172 if(!fESDevent->GetTOFHeader())
1173 { //protection in case the pass2 LHC10b,c,d have been processed without tender.
1174 Float_t t0spread[10];
1175 Float_t intrinsicTOFres=100; //ps ok for LHC10b,c,d pass2!!
1176 for (Int_t j=0; j<10; j++) t0spread[j] = (TMath::Sqrt(fESDevent->GetSigma2DiamondZ()))/0.03; //0.03 to convert from cm to ps
1177 fESDpid->GetTOFResponse().SetT0resolution(t0spread);
1178 fESDpid->GetTOFResponse().SetTimeResolution(intrinsicTOFres);
1180 fESDpid->SetTOFResponse(fESDevent, (AliESDpid::EStartTimeType_t)fTimeZeroType);
1183 if(fESDevent->GetTOFHeader() && fIsPidOwner) fESDpid->SetTOFResponse(fESDevent, (AliESDpid::EStartTimeType_t)fTimeZeroType); //in case of AOD production strating form LHC10e without Tender.
1185 Double_t timeZero = fESDpid->GetTOFResponse().GetStartTime(trk->P());
1187 return trk->GetTOFsignal()-timeZero;
1190 Int_t AliAnalysisTaskB2::GetITSnClusters(const AliESDtrack* trk) const
1193 // ITS number of clusters
1195 UChar_t map = trk->GetITSClusterMap();
1198 for(Int_t j=0; j<6; j++)
1200 if(map&(1<<j)) ++npoints;
1206 Double_t AliAnalysisTaskB2::GetITSchi2PerCluster(const AliESDtrack* trk) const
1209 // ITS chi2 per number of clusters
1211 Double_t chi2 = trk->GetITSchi2();
1212 Int_t ncls = this->GetITSnClusters(trk);
1214 Double_t chi2ncls = (ncls==0) ? 1.e10 : chi2/ncls;
1219 Int_t AliAnalysisTaskB2::GetITSnPointsPID(const AliESDtrack* trk) const
1222 // ITS number of points for PID
1224 UChar_t map = trk->GetITSClusterMap();
1227 for(Int_t j=2; j<6; j++)
1229 if(map&(1<<j)) ++npoints;
1235 Int_t AliAnalysisTaskB2::GetPidCode(const TString& species) const
1238 // Return AliPID code of the given species
1240 TString name = species;
1243 if(name == "electron") return AliPID::kElectron;
1244 if(name == "muon") return AliPID::kMuon;
1245 if(name == "pion") return AliPID::kPion;
1246 if(name == "kaon") return AliPID::kKaon;
1247 if(name == "proton") return AliPID::kProton;
1248 if(name == "deuteron") return AliPID::kDeuteron;
1249 if(name == "triton") return AliPID::kTriton;
1250 if(name == "he3") return AliPID::kHe3;
1251 if(name == "alpha") return AliPID::kAlpha;