1 /**************************************************************************
2 * Copyright(c) 1998-2009, 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 // Base class for Heavy Flavour Correlations Analysis
18 // Single Event and Mixed Event Analysis are implemented
20 //-----------------------------------------------------------------------
23 // Author S.Bjelogrlic
25 // sandro.bjelogrlic@cern.ch
27 //-----------------------------------------------------------------------
31 #include <TParticle.h>
35 #include "AliHFCorrelator.h"
36 #include "AliRDHFCutsDStartoKpipi.h"
37 #include "AliHFAssociatedTrackCuts.h"
38 #include "AliEventPoolManager.h"
39 #include "AliReducedParticle.h"
40 #include "AliCentrality.h"
42 //_____________________________________________________
43 AliHFCorrelator::AliHFCorrelator() :
45 // default constructor
52 fAssociatedTracks(0x0),
63 fUseImpactParameter(0),
82 // default constructor
87 //_____________________________________________________
88 AliHFCorrelator::AliHFCorrelator(const Char_t* name, AliHFAssociatedTrackCuts *cuts, Bool_t ppOrPbPb) :
94 fAssociatedTracks(0x0),
105 fUseImpactParameter(0),
126 //_____________________________________________________
127 AliHFCorrelator::~AliHFCorrelator()
133 if(fPoolMgr) {delete fPoolMgr; fPoolMgr=0;}
134 if(fPool) {delete fPool; fPool=0;}
135 if(fhadcuts) {delete fhadcuts; fhadcuts=0;}
136 if(fAODEvent) {delete fAODEvent; fAODEvent=0;}
137 if(fAssociatedTracks) {delete fAssociatedTracks; fAssociatedTracks=0;}
138 if(fmcArray) {delete fmcArray; fmcArray=0;}
139 if(fReducedPart) {delete fReducedPart; fReducedPart=0;}
140 if(fD0cand) {delete fD0cand; fD0cand=0;}
143 if(fNofTracks) fNofTracks = 0;
145 if(fPhiMin) fPhiMin = 0;
146 if(fPhiMax) fPhiMax = 0;
148 if(fPtTrigger) fPtTrigger=0;
149 if(fPhiTrigger) fPhiTrigger=0;
150 if(fEtaTrigger) fEtaTrigger=0;
152 if(fDeltaPhi) fDeltaPhi=0;
153 if(fDeltaEta) fDeltaEta=0;
155 if(fk0InvMass) fk0InvMass=0;
158 //_____________________________________________________
159 Bool_t AliHFCorrelator::DefineEventPool(){
160 // definition of the Pool Manager for Event Mixing
163 Int_t MaxNofEvents = fhadcuts->GetMaxNEventsInPool();
164 Int_t MinNofTracks = fhadcuts->GetMinNTracksInPool();
165 Int_t NofCentBins = fhadcuts->GetNCentPoolBins();
166 Double_t * CentBins = fhadcuts->GetCentPoolBins();
167 Int_t NofZVrtxBins = fhadcuts->GetNZvtxPoolBins();
168 Double_t *ZVrtxBins = fhadcuts->GetZvtxPoolBins();
171 fPoolMgr = new AliEventPoolManager(MaxNofEvents, MinNofTracks, NofCentBins, CentBins, NofZVrtxBins, ZVrtxBins);
172 if(!fPoolMgr) return kFALSE;
175 //_____________________________________________________
176 Bool_t AliHFCorrelator::Initialize(){
178 cout << "AliHFCorrelator::Initialize"<< endl;
179 if(!fAODEvent) cout << "No AOD event" << endl;
181 AliCentrality *centralityObj = 0;
182 Int_t multiplicity = -1;
183 Double_t MultipOrCent = -1;
185 // initialize the pool for event mixing
187 multiplicity = fAODEvent->GetNTracks();
188 MultipOrCent = multiplicity; // convert from Int_t to Double_t
192 centralityObj = fAODEvent->GetHeader()->GetCentralityP();
193 MultipOrCent = centralityObj->GetCentralityPercentileUnchecked("V0M");
194 AliInfo(Form("Centrality is %f", MultipOrCent));
197 AliAODVertex *vtx = fAODEvent->GetPrimaryVertex();
198 Double_t zvertex = vtx->GetZ(); // zvertex
199 Double_t * CentBins = fhadcuts->GetCentPoolBins();
200 Double_t poolmin=CentBins[0];
201 Double_t poolmax=CentBins[fhadcuts->GetNCentPoolBins()];
204 if(TMath::Abs(zvertex)>=10 || MultipOrCent>poolmax || MultipOrCent < poolmin) {
205 if(!fsystem)AliInfo(Form("pp Event with Zvertex = %.2f cm and multiplicity = %.0f out of pool bounds, SKIPPING",zvertex,MultipOrCent));
206 if(fsystem) AliInfo(Form("PbPb Event with Zvertex = %.2f cm and centrality = %.1f out of pool bounds, SKIPPING",zvertex,MultipOrCent));
211 fPool = fPoolMgr->GetEventPool(MultipOrCent, zvertex);
214 AliInfo(Form("No pool found for multiplicity = %f, zVtx = %f cm", MultipOrCent, zvertex));
217 //fPool->PrintInfo();
221 //_____________________________________________________
222 Bool_t AliHFCorrelator::ProcessEventPool(){
223 // analysis on Mixed Events
224 //cout << "AliHFCorrelator::ProcessEventPool"<< endl;
225 if(!fmixing) return kFALSE;
226 if(!fPool->IsReady()) return kFALSE;
227 if(fPool->GetCurrentNEvents()<fhadcuts->GetMinEventsToMix()) return kFALSE;
228 // fPool->PrintInfo();
229 fPoolContent = fPool->GetCurrentNEvents();
235 //_____________________________________________________
236 Bool_t AliHFCorrelator::ProcessAssociatedTracks(Int_t EventLoopIndex){
238 fAssociatedTracks = new TObjArray();
240 if(!fmixing){ // analysis on Single Event
243 if(fselect==1 || fselect ==2) fAssociatedTracks = AcceptAndReduceTracks(fAODEvent);
244 if(fselect==3) {fAssociatedTracks = AcceptAndReduceKZero(fAODEvent);}
249 if(fmixing) { // analysis on Mixed Events
252 fAssociatedTracks = fPool->GetEvent(EventLoopIndex);
259 if(!fAssociatedTracks) return kFALSE;
261 fNofTracks = fAssociatedTracks->GetEntriesFast();
266 //_____________________________________________________
267 Bool_t AliHFCorrelator::Correlate(Int_t loopindex){
269 if(loopindex >= fNofTracks) return kFALSE;
270 if(!fAssociatedTracks) return kFALSE;
272 fReducedPart = (AliReducedParticle*)fAssociatedTracks->At(loopindex);
275 fDeltaPhi = SetCorrectPhiRange(fPhiTrigger - fReducedPart->Phi());
277 fDeltaEta = fEtaTrigger - fReducedPart->Eta();
283 //_____________________________________________________
284 Bool_t AliHFCorrelator::PoolUpdate(){
286 if(!fmixing) return kFALSE;
287 if(!fPool) return kFALSE;
288 if(fmixing) { // update the pool for Event Mixing
289 TObjArray* objArr = NULL;
290 if(fselect==1 || fselect==2) objArr = (TObjArray*)AcceptAndReduceTracks(fAODEvent);
291 if(fselect==3) objArr = (TObjArray*)AcceptAndReduceKZero(fAODEvent);
292 if(objArr->GetEntriesFast()>0) fPool->UpdatePool(objArr); // updating the pool only if there are entries in the array
299 //_____________________________________________________
300 Double_t AliHFCorrelator::SetCorrectPhiRange(Double_t phi){
301 Double_t pi = TMath::Pi();
303 if(phi<fPhiMin) phi = phi + 2*pi;
304 if(phi>fPhiMax) phi = phi - 2*pi;
309 //_____________________________________________________
310 TObjArray* AliHFCorrelator::AcceptAndReduceTracks(AliAODEvent* inputEvent){
312 Int_t nTracks = inputEvent->GetNTracks();
313 AliAODVertex * vtx = inputEvent->GetPrimaryVertex();
314 Double_t Bz = inputEvent->GetMagneticField();
317 TObjArray* tracksClone = new TObjArray;
318 tracksClone->SetOwner(kTRUE);
319 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
321 AliAODTrack* track = inputEvent->GetTrack(iTrack);
322 if (!track) continue;
323 if(!fhadcuts->IsHadronSelected(track)) continue; // apply ESD level selections
324 if(!fhadcuts->Charge(fDCharge,track)) continue; // apply selection on charge, if required
326 Double_t pT = track->Pt();
328 //compute impact parameter
329 Double_t d0z0[2],covd0z0[3];
330 Double_t d0=-999999.;
331 if(fUseImpactParameter) track->PropagateToDCA(vtx,Bz,100,d0z0,covd0z0);
332 else d0z0[0] = 1. ; // random number - be careful with the cuts you applied
334 if(fUseImpactParameter==1) d0 = TMath::Abs(d0z0[0]); // use impact parameter
335 if(fUseImpactParameter==2) { // use impact parameter over resolution
336 if(TMath::Abs(covd0z0[0])>0.00000001) d0 = TMath::Abs(d0z0[0])/TMath::Abs(covd0z0[0]);
337 else d0 = -1.; // if the resoultion is Zero, rejects the track - to be on the safe side
344 if(!fhadcuts->CheckHadronKinematic(pT,d0)) continue; // apply kinematic cuts
345 Bool_t rejectsoftpi = kFALSE;
346 if(fD0cand) rejectsoftpi = fhadcuts->InvMassDstarRejection(fD0cand,track,fhypD0);
350 if(!fhadcuts->CheckKaonCompatibility(track,fmontecarlo,fmcArray,fPIDmode)) continue; // check if it is a Kaon - data and MC
353 tracksClone->Add(new AliReducedParticle(track->Eta(), track->Phi(), pT,track->GetLabel(),track->GetID(),d0,rejectsoftpi,track->Charge()));
360 //_____________________________________________________
361 TObjArray* AliHFCorrelator::AcceptAndReduceKZero(AliAODEvent* inputEvent){
363 Int_t nOfVZeros = inputEvent->GetNumberOfV0s();
364 TObjArray* KZeroClone = new TObjArray;
365 AliAODVertex *vertex1 = (AliAODVertex*)inputEvent->GetPrimaryVertex();
367 Int_t pdgDgK0toPipi[2] = {211,211};
368 Double_t mPDGK0=0.497614;//TDatabasePDG::Instance()->GetParticle(310)->Mass();
369 const Int_t size = inputEvent->GetNumberOfV0s();
370 Int_t prevnegID[size];
371 Int_t prevposID[size];
372 for(Int_t iv0 =0; iv0< nOfVZeros; iv0++){// loop on all v0 candidates
373 AliAODv0 *v0 = (static_cast<AliAODEvent*> (inputEvent))->GetV0(iv0);
374 if(!v0) {cout << "is not a v0 at step " << iv0 << endl; continue;}
376 if(!fhadcuts->IsKZeroSelected(v0,vertex1)) continue; // check if it is a k0
378 // checks to avoid double counting
382 prevnegID[iv0] = -997;
383 prevposID[iv0]= -996;
384 negID = v0->GetNegID();
385 posID = v0->GetPosID();
386 Bool_t DoubleCounting = kFALSE;
388 for(Int_t k=0; k<iv0; k++){
389 if(((negID==prevnegID[k])&&(posID==prevposID[k]))||((negID==prevposID[k])&&(posID==prevnegID[k]))){
390 DoubleCounting = kTRUE;
396 if(DoubleCounting) continue;
398 prevposID[iv0] = posID;
399 prevnegID[iv0] = negID;
402 if(fmontecarlo) v0label = v0->MatchToMC(310,fmcArray, 0, pdgDgK0toPipi); //match a K0 short
403 Double_t k0pt = v0->Pt();
404 Double_t k0eta = v0->Eta();
405 Double_t k0Phi = v0->Phi();
406 fk0InvMass = v0->MassK0Short();
408 //if (loopindex == 0) {
409 // if(!plotassociation) ((TH2F*)fOutput->FindObject("KZeroSpectra"))->Fill(k0InvMass,k0pt); // spectra for all k0
410 // if(plotassociation) ((TH2F*)fOutput->FindObject("KZeroSpectraifHF"))->Fill(k0InvMass,k0pt); // spectra for k0 in association with a D*
412 // if there are more D* candidates per event, loopindex == 0 makes sure you fill the mass spectra only once!
414 if(TMath::Abs(fk0InvMass-mPDGK0)>3*0.004) continue; // select candidates within 3 sigma
415 KZeroClone->Add(new AliReducedParticle(k0eta,k0Phi,k0pt,v0label));