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 // Analysis Taks for reconstructed particle correlation
18 // (first implementation done for D mesons) with jets
19 // (use the so called Emcal framework)
21 //-----------------------------------------------------------------------
23 // C. Bianchin (Utrecht University) chiara.bianchin@cern.ch
24 // A. Grelli (Utrecht University) a.grelli@uu.nl
25 // X. Zhang (LBNL) XMZhang@lbl.gov
26 //-----------------------------------------------------------------------
28 #include <TDatabasePDG.h>
29 #include <TParticle.h>
32 #include <THnSparse.h>
34 #include <TObjectTable.h>
36 #include "AliAnalysisTaskFlavourJetCorrelations.h"
37 #include "AliAODMCHeader.h"
38 #include "AliAODHandler.h"
39 #include "AliAnalysisManager.h"
41 #include "AliEmcalJet.h"
42 #include "AliJetContainer.h"
43 #include "AliAODRecoDecay.h"
44 #include "AliAODRecoCascadeHF.h"
45 #include "AliAODRecoDecayHF2Prong.h"
46 #include "AliESDtrack.h"
47 #include "AliAODMCParticle.h"
48 #include "AliPicoTrack.h"
49 #include "AliRDHFCutsD0toKpi.h"
50 #include "AliRDHFCutsDStartoKpipi.h"
52 ClassImp(AliAnalysisTaskFlavourJetCorrelations)
55 //_______________________________________________________________________________
57 AliAnalysisTaskFlavourJetCorrelations::AliAnalysisTaskFlavourJetCorrelations() :
58 AliAnalysisTaskEmcalJet("",kTRUE),
71 fLeadingJetOnly(kFALSE),
83 fSwitchOnOutOfConeAxis(0),
90 //SetMakeGeneralHistograms(kTRUE);
94 //_______________________________________________________________________________
96 AliAnalysisTaskFlavourJetCorrelations::AliAnalysisTaskFlavourJetCorrelations(const Char_t* name, AliRDHFCuts* cuts,ECandidateType candtype, Bool_t jetOnly) :
97 AliAnalysisTaskEmcalJet(name,kTRUE),
110 fLeadingJetOnly(kFALSE),
114 fJetOnlyMode(jetOnly),
122 fSwitchOnOutOfConeAxis(0),
127 // Constructor. Initialization of Inputs and Outputs
130 Info("AliAnalysisTaskFlavourJetCorrelations","Calling Constructor");
132 fCandidateType=candtype;
133 const Int_t nptbins=fCuts->GetNPtBins();
134 Float_t defaultSigmaD013[13]={0.012, 0.012, 0.012, 0.015, 0.015,0.018,0.018,0.020,0.020,0.030,0.030,0.037,0.040};
136 switch(fCandidateType){
140 fPDGdaughters[0]=211;//pi
141 fPDGdaughters[1]=321;//K
142 fPDGdaughters[2]=0; //empty
143 fPDGdaughters[3]=0; //empty
144 fBranchName="D0toKpi";
150 fPDGdaughters[1]=211;//pi soft
151 fPDGdaughters[0]=421;//D0
152 fPDGdaughters[2]=211;//pi fromD0
153 fPDGdaughters[3]=321; // K from D0
155 fCandArrName="Dstar";
158 for(Int_t ipt=0;ipt<nptbins;ipt++) fSigmaD0[ipt]= defaultSigmaD013[ipt];
160 AliFatal(Form("Default sigma D0 not enough for %d pt bins, use SetSigmaD0ForDStar to set them",nptbins));
164 printf("%d not accepted!!\n",fCandidateType);
168 if(fCandidateType==kD0toKpi)SetMassLimits(0.15,fPDGmother);
169 if(fCandidateType==kDstartoKpipi) SetMassLimits(0.015, fPDGmother);
172 DefineOutput(1,TList::Class()); //histos with jet info
173 DefineOutput(2,AliRDHFCuts::Class()); // my cuts
176 DefineInput(1, TClonesArray::Class());
177 DefineInput(2, TClonesArray::Class());
179 DefineOutput(1,TList::Class()); // histos
180 DefineOutput(2,AliRDHFCuts::Class()); // my cuts
184 //_______________________________________________________________________________
186 AliAnalysisTaskFlavourJetCorrelations::~AliAnalysisTaskFlavourJetCorrelations() {
191 Info("~AliAnalysisTaskFlavourJetCorrelations","Calling Destructor");
197 //_______________________________________________________________________________
199 void AliAnalysisTaskFlavourJetCorrelations::Init(){
204 if(fDebug > 1) printf("AnalysisTaskRecoJetCorrelations::Init() \n");
206 switch(fCandidateType){
209 AliRDHFCutsD0toKpi* copyfCuts=new AliRDHFCutsD0toKpi(*(static_cast<AliRDHFCutsD0toKpi*>(fCuts)));
210 copyfCuts->SetName("AnalysisCutsDzero");
212 PostData(2,copyfCuts);
217 AliRDHFCutsDStartoKpipi* copyfCuts=new AliRDHFCutsDStartoKpipi(*(static_cast<AliRDHFCutsDStartoKpipi*>(fCuts)));
218 copyfCuts->SetName("AnalysisCutsDStar");
220 PostData(2,copyfCuts);
230 //_______________________________________________________________________________
232 void AliAnalysisTaskFlavourJetCorrelations::UserCreateOutputObjects() {
234 Info("UserCreateOutputObjects","CreateOutputObjects of task %s\n", GetName());
235 AliAnalysisTaskEmcal::UserCreateOutputObjects();
237 // the TList fOutput is already defined in AliAnalysisTaskEmcal::UserCreateOutputObjects()
238 DefineHistoForAnalysis();
244 //_______________________________________________________________________________
246 Bool_t AliAnalysisTaskFlavourJetCorrelations::Run()
248 // user exec from AliAnalysisTaskEmcal is used
251 AliAODEvent* aodEvent = dynamic_cast<AliAODEvent*>(fInputEvent);
253 TClonesArray *arrayDStartoD0pi=0;
255 if (!aodEvent && AODEvent() && IsStandardAOD()) {
257 // In case there is an AOD handler writing a standard AOD, use the AOD
258 // event in memory rather than the input (ESD) event.
259 aodEvent = dynamic_cast<AliAODEvent*> (AODEvent());
261 // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
262 // have to taken from the AOD event hold by the AliAODExtension
263 AliAODHandler* aodHandler = (AliAODHandler*)
264 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
265 if(aodHandler->GetExtensions()) {
266 AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
267 AliAODEvent *aodFromExt = ext->GetAOD();
268 arrayDStartoD0pi=(TClonesArray*)aodFromExt->GetList()->FindObject(fBranchName.Data());
271 arrayDStartoD0pi=(TClonesArray*)aodEvent->GetList()->FindObject(fBranchName.Data());
274 if (!arrayDStartoD0pi) {
275 AliInfo(Form("Could not find array %s, skipping the event",fBranchName.Data()));
277 } else AliDebug(2, Form("Found %d vertices",arrayDStartoD0pi->GetEntriesFast()));
279 TClonesArray* mcArray = 0x0;
281 mcArray = dynamic_cast<TClonesArray*>(aodEvent->FindListObject(AliAODMCParticle::StdBranchName()));
283 printf("AliAnalysisTaskSEDStarSpectra::UserExec: MC particles not found!\n");
289 fTrackArr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("PicoTracks"));
290 //clusArr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("CaloClustersCorr"));
291 //jetArr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fJetArrName));
292 fJetRadius=GetJetContainer(0)->GetJetRadius();
295 AliInfo(Form("Could not find the track array\n"));
300 fCandidateArray = dynamic_cast<TClonesArray*>(GetInputData(1));
301 if (!fCandidateArray) return kFALSE;
302 if (fCandidateType==1 && fSwitchOnSB) {
303 fSideBandArray = dynamic_cast<TClonesArray*>(GetInputData(2));
304 if (!fSideBandArray) return kFALSE;
306 //Printf("ncandidates found %d",fCandidateArray->GetEntriesFast());
309 TH1I* hstat=(TH1I*)fOutput->FindObject("hstat");
310 TH1F* hPtJetTrks=(TH1F*)fOutput->FindObject("hPtJetTrks");
311 TH1F* hPhiJetTrks=(TH1F*)fOutput->FindObject("hPhiJetTrks");
312 TH1F* hEtaJetTrks=(TH1F*)fOutput->FindObject("hEtaJetTrks");
313 TH1F* hEjetTrks=(TH1F*)fOutput->FindObject("hEjetTrks");
314 TH1F* hPtJet=(TH1F*)fOutput->FindObject("hPtJet");
315 TH1F* hPhiJet=(TH1F*)fOutput->FindObject("hPhiJet");
316 TH1F* hEtaJet=(TH1F*)fOutput->FindObject("hEtaJet");
317 TH1F* hEjet=(TH1F*)fOutput->FindObject("hEjet");
318 TH1F* hNtrArr=(TH1F*)fOutput->FindObject("hNtrArr");
319 TH1F* hNJetPerEv=(TH1F*)fOutput->FindObject("hNJetPerEv");
320 TH1F* hdeltaRJetTracks=(TH1F*)fOutput->FindObject("hdeltaRJetTracks");
321 TH1F* hNDPerEvNoJet=(TH1F*)fOutput->FindObject("hNDPerEvNoJet");
322 TH1F* hptDPerEvNoJet=(TH1F*)fOutput->FindObject("hptDPerEvNoJet");
323 TH1F* hNJetPerEvNoD=(TH1F*)fOutput->FindObject("hNJetPerEvNoD");
324 TH1F* hPtJetPerEvNoD=(TH1F*)fOutput->FindObject("hPtJetPerEvNoD");
325 THnSparseF* hnspDstandalone=(THnSparseF*)fOutput->FindObject("hsDstandalone");
326 THnSparseF* hsJet=(THnSparseF*)fOutput->FindObject("hsJet");
328 TH1F* hztracksinjet=(TH1F*)fOutput->FindObject("hztracksinjet");
329 TH1F* hDiffPtTrPtJzNok=(TH1F*)fOutput->FindObject("hDiffPtTrPtJzNok");
330 TH1F* hDiffPtTrPtJzok=(TH1F*)fOutput->FindObject("hDiffPtTrPtJzok");
331 TH1F* hDiffPzTrPtJzok=(TH1F*)fOutput->FindObject("hDiffPzTrPtJzok");
332 TH1F* hDiffPzTrPtJzNok=(TH1F*)fOutput->FindObject("hDiffPzTrPtJzNok");
333 TH1I* hNtrkjzNok=(TH1I*)fOutput->FindObject("hNtrkjzNok");
334 TH1F* hztracksinjetT=(TH1F*)fOutput->FindObject("hztracksinjetT");
339 // fix for temporary bug in ESDfilter
340 // the AODs with null vertex pointer didn't pass the PhysSel
341 if(!aodEvent->GetPrimaryVertex() || TMath::Abs(aodEvent->GetMagneticField())<0.001) return kFALSE;
344 Bool_t iseventselected=fCuts->IsEventSelected(aodEvent);
345 TString firedTriggerClasses=((AliAODEvent*)aodEvent)->GetFiredTriggerClasses();
346 if(!iseventselected) return kFALSE;
350 //retrieve charm candidates selected
351 Int_t candidates = 0;
352 Int_t njets=GetJetContainer()->GetNJets();
355 candidates = fCandidateArray->GetEntriesFast();
359 hstat->Fill(6, candidates);
360 hNDPerEvNoJet->Fill(candidates);
361 for(Int_t iD=0;iD<candidates;iD++){
362 AliVParticle* cand=(AliVParticle*)fCandidateArray->At(iD);
364 hptDPerEvNoJet->Fill(cand->Pt());
371 //loop on candidates standalone (checking the candidates are there and their phi-eta distributions)
373 for(Int_t ic = 0; ic < candidates; ic++) {
376 AliAODRecoDecayHF* charm=0x0;
377 AliAODRecoCascadeHF* dstar=0x0;
380 charm=(AliAODRecoDecayHF*)fCandidateArray->At(ic);
383 if(fCandidateType==kDstartoKpipi){
384 dstar=(AliAODRecoCascadeHF*)fCandidateArray->At(ic);
390 Double_t candsparse[4]={charm->Eta(), charm->Phi(), charm->Pt(), 0};
392 if(fCandidateType==kDstartoKpipi) {
394 Double_t deltamass= dstar->DeltaInvMass();
395 candsparse[3]=deltamass;
396 } else candsparse[3] = 0.145; //for generated
397 if(fSwitchOnSparses) hnspDstandalone->Fill(candsparse);
399 if(fCandidateType==kD0toKpi){
401 AliAODRecoDecayHF* dzero=(AliAODRecoDecayHF*)charm;
402 Int_t isselected=fCuts->IsSelected(dzero,AliRDHFCuts::kAll,aodEvent);
403 //not a further selection,just to get the value of isselected for the D0
405 Int_t pdgdaughtersD0[2]={211,321};//pi,K
406 Int_t pdgdaughtersD0bar[2]={321,211};//K,pi
408 masses[0]=dzero->InvMass(fNProngs,(UInt_t*)pdgdaughtersD0); //D0
409 masses[1]=dzero->InvMass(fNProngs,(UInt_t*)pdgdaughtersD0bar); //D0bar
410 if(isselected==1 || isselected==3) {
411 candsparse[3]=masses[0];
412 if(fSwitchOnSparses) hnspDstandalone->Fill(candsparse);
415 candsparse[3]=masses[1];
416 if(fSwitchOnSparses) hnspDstandalone->Fill(candsparse);
420 Int_t pdg=((AliAODMCParticle*)charm)->GetPdgCode();
421 candsparse[3]=TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
422 if(fSwitchOnSparses) hnspDstandalone->Fill(candsparse);
428 // we start with jets
433 Double_t leadingJet =0;
436 Int_t ntrarr=fTrackArr->GetEntriesFast();
437 hNtrArr->Fill(ntrarr);
439 for(Int_t i=0;i<ntrarr;i++){
440 AliVTrack *jtrack=static_cast<AliVTrack*>(fTrackArr->At(i));
442 hPtJetTrks->Fill(jtrack->Pt());
443 hPhiJetTrks->Fill(jtrack->Phi());
444 hEtaJetTrks->Fill(jtrack->Eta());
445 hEjetTrks->Fill(jtrack->E());
449 //option to use only the leading jet
451 for (Int_t iJetsL = 0; iJetsL<njets; iJetsL++) {
452 AliEmcalJet* jetL = (AliEmcalJet*)GetJetFromArray(iJetsL);
454 if(ptjet>leadingJet ) leadingJet = ptjet;
460 //loop over jets and consider only the leading jet in the event
461 for (Int_t iJets = 0; iJets<njets; iJets++) {
466 //Printf("Jet N %d",iJets);
467 AliEmcalJet* jet = (AliEmcalJet*)GetJetFromArray(iJets);
468 //Printf("Corr task Accept Jet");
469 if(!AcceptJet(jet)) {
479 Double_t origPtJet=fPtJet;
485 pointJ[4] = jet->GetNumberOfConstituents();
486 pointJ[5] = jet->Area();
488 // choose the leading jet
489 if(fLeadingJetOnly && (ejet<leadingJet)) continue;
490 //used for normalization
493 // fill energy, eta and phi of the jet
495 hPhiJet ->Fill(phiJet);
496 hEtaJet ->Fill(etaJet);
497 hPtJet ->Fill(fPtJet);
498 if(fJetOnlyMode && fSwitchOnSparses) hsJet->Fill(pointJ,1);
499 //loop on jet particles
500 Int_t ntrjet= jet->GetNumberOfTracks();
501 Double_t sumPtTracks=0,sumPzTracks=0;
503 for(Int_t itrk=0;itrk<ntrjet;itrk++){
505 AliPicoTrack* jetTrk=(AliPicoTrack*)jet->TrackAt(itrk,fTrackArr);
506 hdeltaRJetTracks->Fill(DeltaR(jet,jetTrk));
507 Double_t ztrackj=Z(jetTrk,jet);
508 hztracksinjet->Fill(ztrackj);
509 sumPtTracks+=jetTrk->Pt();
510 sumPzTracks+=jetTrk->Pz();
515 Double_t ztrackjTr=Z(jetTrk,jet,kTRUE);
516 hztracksinjetT->Fill(ztrackjTr);
518 }//end loop on jet tracks
520 hNtrkjzNok->Fill(zg1jtrk);
521 Double_t diffpt=origPtJet-sumPtTracks;
522 Double_t diffpz=jet->Pz()-sumPzTracks;
524 hDiffPtTrPtJzNok->Fill(diffpt);
525 hDiffPzTrPtJzNok->Fill(diffpz);
528 hDiffPtTrPtJzok->Fill(diffpt);
529 hDiffPzTrPtJzok->Fill(diffpz);
534 hPtJetPerEvNoD->Fill(fPtJet);
537 //Printf("N candidates %d ", candidates);
538 for(Int_t ic = 0; ic < candidates; ic++) {
541 AliVParticle* charm=0x0;
542 charm=(AliVParticle*)fCandidateArray->At(ic);
544 AliAODRecoDecayHF *charmdecay=(AliAODRecoDecayHF*) charm;
545 fIsDInJet=IsDInJet(jet, charmdecay, kTRUE);
546 if (fIsDInJet) FlagFlavour(jet);
547 if (jet->TestFlavourTag(AliEmcalJet::kDStar)) hstat->Fill(4);
549 //Note: the z component of the jet momentum comes from the eta-phi direction of the jet particles, it is not calculated from the z component of the tracks since, as default, the scheme used for jet reco is the pt-scheme which sums the scalar component, not the vectors. Addind the D daughter momentum component by componet as done here is not 100% correct, but the difference is small, for fairly collimated particles.
553 RecalculateMomentum(pjet,fPmissing);
554 fPtJet=TMath::Sqrt(pjet[0]*pjet[0]+pjet[1]*pjet[1]);
557 //debugging histograms
558 Double_t pmissing=TMath::Sqrt(fPmissing[0]*fPmissing[0]+fPmissing[1]*fPmissing[1]+fPmissing[2]*fPmissing[2]);
559 for(Int_t k=0;k<3;k++) ((TH1F*)fOutput->FindObject(Form("hMissP%d",k)))->Fill(fPmissing[k]);
561 ((TH1F*)fOutput->FindObject("hmissingp"))->Fill(pmissing);
562 Double_t ptdiff=fPtJet-origPtJet;
563 ((TH1F*)fOutput->FindObject("hDeltaPtJet"))->Fill(ptdiff);
564 ((TH1F*)fOutput->FindObject("hRelDeltaPtJet"))->Fill(ptdiff/origPtJet);
566 FillHistogramsRecoJetCorr(charm, jet, aodEvent);
568 }//end loop on candidates
570 //retrieve side band background candidates for Dstar
571 Int_t nsbcand = 0; if(fSideBandArray) nsbcand=fSideBandArray->GetEntriesFast();
573 for(Int_t ib=0;ib<nsbcand;ib++){
574 if(fCandidateType==kDstartoKpipi && !fUseMCInfo){
575 AliAODRecoCascadeHF *sbcand=(AliAODRecoCascadeHF*)fSideBandArray->At(ib);
576 if(!sbcand) continue;
578 fIsDInJet=IsDInJet(jet, sbcand,kFALSE);
581 RecalculateMomentum(pjet,fPmissing);
582 fPtJet=TMath::Sqrt(pjet[0]*pjet[0]+pjet[1]*pjet[1]);
584 SideBandBackground(sbcand,jet);
588 AliAODRecoDecayHF* charmbg = 0x0;
589 charmbg=(AliAODRecoDecayHF*)fCandidateArray->At(ib);
590 if(!charmbg) continue;
591 fIsDInJet=IsDInJet(jet, charmbg,kFALSE);
595 RecalculateMomentum(pjet,fPmissing);
596 fPtJet=TMath::Sqrt(pjet[0]*pjet[0]+pjet[1]*pjet[1]);
598 MCBackground(charmbg);
604 hNJetPerEv->Fill(cntjet);
605 if(candidates==0) hNJetPerEvNoD->Fill(cntjet);
610 //_______________________________________________________________________________
612 void AliAnalysisTaskFlavourJetCorrelations::Terminate(Option_t*)
614 // The Terminate() function is the last function to be called during
615 // a query. It always runs on the client, it can be used to present
616 // the results graphically or save the results to file.
618 Info("Terminate"," terminate");
619 AliAnalysisTaskSE::Terminate();
621 fOutput = dynamic_cast<TList*> (GetOutputData(1));
623 printf("ERROR: fOutput not available\n");
628 //_______________________________________________________________________________
630 void AliAnalysisTaskFlavourJetCorrelations::SetMassLimits(Double_t range, Int_t pdg){
632 Int_t abspdg=TMath::Abs(pdg);
634 mass=TDatabasePDG::Instance()->GetParticle(abspdg)->Mass();
635 // compute the Delta mass for the D*
636 if(fCandidateType==kDstartoKpipi){
638 mass1=TDatabasePDG::Instance()->GetParticle(421)->Mass();
642 fMinMass = mass-range;
643 fMaxMass = mass+range;
645 AliInfo(Form("Setting mass limits to %f, %f",fMinMass,fMaxMass));
646 if (fMinMass<0 || fMaxMass<=0 || fMaxMass<fMinMass) AliFatal("Wrong mass limits!\n");
649 //_______________________________________________________________________________
651 void AliAnalysisTaskFlavourJetCorrelations::SetMassLimits(Double_t lowlimit, Double_t uplimit){
658 printf("Error! Lower limit larger than upper limit!\n");
659 fMinMass = uplimit - uplimit*0.2;
664 //_______________________________________________________________________________
666 Bool_t AliAnalysisTaskFlavourJetCorrelations::SetD0WidthForDStar(Int_t nptbins,Float_t *width){
668 AliInfo("Maximum number of bins allowed is 30!");
671 if(!width) return kFALSE;
672 for(Int_t ipt=0;ipt<nptbins;ipt++) fSigmaD0[ipt]=width[ipt];
676 //_______________________________________________________________________________
678 Double_t AliAnalysisTaskFlavourJetCorrelations::Z(AliVParticle* part,AliEmcalJet* jet, Bool_t transverse) const{
680 printf("Particle or jet do not exist!\n");
684 Bool_t okpp=part->PxPyPz(p);
685 Bool_t okpj=jet->PxPyPz(pj);
687 printf("Problems getting momenta\n");
691 RecalculateMomentum(pj, fPmissing);
692 if(transverse) return ZT(p,pj);
697 //_______________________________________________________________________________
698 Double_t AliAnalysisTaskFlavourJetCorrelations::Z(Double_t* p, Double_t *pj) const{
700 Double_t pjet2=pj[0]*pj[0]+pj[1]*pj[1]+pj[2]*pj[2];
701 Double_t z=(p[0]*pj[0]+p[1]*pj[1]+p[2]*pj[2])/(pjet2);
706 //_______________________________________________________________________________
707 Double_t AliAnalysisTaskFlavourJetCorrelations::ZT(Double_t* p, Double_t *pj) const{
709 Double_t pjet2=pj[0]*pj[0]+pj[1]*pj[1];
710 Double_t z=(p[0]*pj[0]+p[1]*pj[1])/(pjet2);
714 //_______________________________________________________________________________
716 void AliAnalysisTaskFlavourJetCorrelations::RecalculateMomentum(Double_t* pj, const Double_t* pmissing) const {
724 //_______________________________________________________________________________
726 Bool_t AliAnalysisTaskFlavourJetCorrelations::DefineHistoForAnalysis(){
729 TH1I* hstat=new TH1I("hstat","Statistics",8,-0.5,7.5);
730 hstat->GetXaxis()->SetBinLabel(1,"N ev anal");
731 hstat->GetXaxis()->SetBinLabel(2,"N ev sel");
732 hstat->GetXaxis()->SetBinLabel(3,"N cand sel & jet");
733 hstat->GetXaxis()->SetBinLabel(4,"N jets");
734 hstat->GetXaxis()->SetBinLabel(5,"N cand in jet");
735 hstat->GetXaxis()->SetBinLabel(6,"N jet rej");
736 hstat->GetXaxis()->SetBinLabel(7,"N cand sel & !jet");
737 hstat->GetXaxis()->SetBinLabel(8,"N jets & !D");
738 hstat->SetNdivisions(1);
741 const Int_t nbinsmass=200;
742 const Int_t nbinsptjet=500;
743 const Int_t nbinsptD=100;
744 const Int_t nbinsz=100;
745 const Int_t nbinsphi=200;
746 const Int_t nbinseta=100;
748 //binning for THnSparse
749 const Int_t nbinsSpsmass=50;
750 const Int_t nbinsSpsptjet=100;
751 const Int_t nbinsSpsptD=50;
752 const Int_t nbinsSpsz=100;
753 const Int_t nbinsSpsphi=100;
754 const Int_t nbinsSpseta=60;
755 const Int_t nbinsSpsContrib=100;
756 const Int_t nbinsSpsA=100;
758 const Float_t ptjetlims[2]={0.,200.};
759 const Float_t ptDlims[2]={0.,50.};
760 const Float_t zlims[2]={0.,1.2};
761 const Float_t philims[2]={0.,6.3};
762 const Float_t etalims[2]={-1.5,1.5};
763 const Int_t nContriblims[2]={0,100};
764 const Float_t arealims[2]={0.,2};
766 // jet related fistograms
768 TH1F* hEjetTrks = new TH1F("hEjetTrks", "Jet tracks energy distribution;Energy (GeV)",500,0,200);
770 TH1F* hPhiJetTrks = new TH1F("hPhiJetTrks","Jet tracks #phi distribution; #phi (rad)", nbinsphi,philims[0],philims[1]);
771 hPhiJetTrks->Sumw2();
772 TH1F* hEtaJetTrks = new TH1F("hEtaJetTrks","Jet tracks #eta distribution; #eta", nbinseta,etalims[0],etalims[1]);
773 hEtaJetTrks->Sumw2();
774 TH1F* hPtJetTrks = new TH1F("hPtJetTrks", "Jet tracks Pt distribution; p_{T} (GeV/c)",nbinsptjet,ptjetlims[0],ptjetlims[1]);
777 TH1F* hEjet = new TH1F("hEjet", "Jet energy distribution;Energy (GeV)",500,0,200);
779 TH1F* hPhiJet = new TH1F("hPhiJet","Jet #phi distribution; #phi (rad)", nbinsphi,philims[0],philims[1]);
781 TH1F* hEtaJet = new TH1F("hEtaJet","Jet #eta distribution; #eta", nbinseta,etalims[0],etalims[1]);
783 TH1F* hPtJet = new TH1F("hPtJet", "Jet Pt distribution; p_{T} (GeV/c)",nbinsptjet,ptjetlims[0],ptjetlims[1]);
786 TH1F* hdeltaRJetTracks=new TH1F("hdeltaRJetTracks","Delta R of tracks in the jets",200, 0.,10.);
787 hdeltaRJetTracks->Sumw2();
789 TH1F* hNtrArr= new TH1F("hNtrArr", "Number of tracks in the array of jets; number of tracks",500,0,1000);
792 TH1F *hNJetPerEv=new TH1F("hNJetPerEv","Number of jets used per event; number of jets/ev",10,-0.5,9.5);
796 fOutput->Add(hEjetTrks);
797 fOutput->Add(hPhiJetTrks);
798 fOutput->Add(hEtaJetTrks);
799 fOutput->Add(hPtJetTrks);
801 fOutput->Add(hPhiJet);
802 fOutput->Add(hEtaJet);
803 fOutput->Add(hPtJet);
804 fOutput->Add(hdeltaRJetTracks);
805 fOutput->Add(hNtrArr);
806 fOutput->Add(hNJetPerEv);
808 if(fJetOnlyMode && fSwitchOnSparses){
811 const Int_t nbinsSparse[nAxis]={nbinsSpsphi,nbinsSpseta, nbinsSpsptjet, nbinsSpsptjet,nbinsSpsContrib, nbinsSpsA};
812 const Double_t minSparse[nAxis]={philims[0],etalims[0],ptjetlims[0],ptjetlims[0],static_cast<Double_t>(nContriblims[0]),arealims[0]};
814 maxSparse[nAxis]={philims[1],etalims[1],ptjetlims[1],ptjetlims[1],static_cast<Double_t>(nContriblims[1]),arealims[1]};
815 THnSparseF *hsJet=new THnSparseF("hsJet","#phi, #eta, p_{T}^{jet}, E^{jet}, N contrib, Area", nAxis, nbinsSparse, minSparse, maxSparse);
824 //debugging histograms
825 TH1I* hControlDInJ=new TH1I("hControlDInJ","Checks D in Jet",8, -0.5,7.5);
826 hControlDInJ->GetXaxis()->SetBinLabel(1,"DR In,1 daugh out");
827 hControlDInJ->GetXaxis()->SetBinLabel(2,"DR In,2 daugh out");
828 hControlDInJ->GetXaxis()->SetBinLabel(3,"DR In,3 daugh out");
829 hControlDInJ->GetXaxis()->SetBinLabel(4,"Tot tracks non matched");
830 hControlDInJ->GetXaxis()->SetBinLabel(5,"D0 daug missing");
831 hControlDInJ->GetXaxis()->SetBinLabel(6,"soft pi missing");
832 hControlDInJ->GetXaxis()->SetBinLabel(7,"IDprong diff GetDau");
833 hControlDInJ->GetXaxis()->SetBinLabel(8,"still z>1 (cand)");
835 hControlDInJ->SetNdivisions(1);
836 hControlDInJ->GetXaxis()->SetLabelSize(0.05);
837 fOutput->Add(hControlDInJ);
839 TH1F *hmissingp=new TH1F("hmissingp", "Distribution of missing momentum (modulo);|p_{missing}|", 200, 0.,20.);
840 fOutput->Add(hmissingp);
842 for(Int_t k=0;k<3;k++) {
843 TH1F *hMissPi=new TH1F(Form("hMissP%d",k), Form("Missing p component {%d};p_{%d}",k,k), 400, -10.,10.);
844 fOutput->Add(hMissPi);
846 TH1F *hDeltaPtJet=new TH1F("hDeltaPtJet", "Difference between the jet pt before and after correction;p_{T}^{jet,recalc}-p_{T}^{jet,orig}", 200, 0.,20.);
848 fOutput->Add(hDeltaPtJet);
849 TH1F *hRelDeltaPtJet=new TH1F("hRelDeltaPtJet", "Difference between the jet pt before and after correction/ original pt;(p_{T}^{jet,recalc}-p_{T}^{jet,orig})/p_{T}^{jet,orig}", 200, 0.,1.);
850 fOutput->Add(hRelDeltaPtJet);
852 TH1F* hzDinjet=new TH1F("hzDinjet","Z of candidates with daughters in jet;z",nbinsz,zlims[0],zlims[1]);
853 fOutput->Add(hzDinjet);
854 //frag func of tracks in the jet
855 TH1F* hztracksinjet=new TH1F("hztracksinjet","Z of tracks in jet;z",nbinsz,zlims[0],zlims[1]);
856 fOutput->Add(hztracksinjet);
858 //check jet and tracks
859 TH1F* hDiffPtTrPtJzok=new TH1F("hDiffPtTrPtJzok","Sum p_{T}^{trks} - p_{T}^{jet}, for z<1;(#Sigma p_{T}^{trks}) - p_{T}^{jet}", 100,-0.2,0.2);
860 fOutput->Add(hDiffPtTrPtJzok);
861 TH1F* hDiffPtTrPtJzNok=new TH1F("hDiffPtTrPtJzNok","Sum p_{T}^{trks} - p_{T}^{jet}, for z>1;(#Sigma p_{T}^{trks}) - p_{T}^{jet}", 100,-0.2,0.2);
862 fOutput->Add(hDiffPtTrPtJzNok);
863 TH1F* hDiffPzTrPtJzok=new TH1F("hDiffPzTrPtJzok","Sum p_{z}^{trks} - p_{z}^{jet}, for z<1;(#Sigma p_{z}^{trks}) - p_{z}^{jet}", 100,-0.2,0.2);
864 fOutput->Add(hDiffPzTrPtJzok);
865 TH1F* hDiffPzTrPtJzNok=new TH1F("hDiffPzTrPtJzNok","Sum p_{z}^{trks} - p_{z}^{jet}, for z>1;(#Sigma p_{z}^{trks}) - p_{z}^{jet}", 100,-0.2,0.2);
866 fOutput->Add(hDiffPzTrPtJzNok);
867 TH1I* hNtrkjzNok=new TH1I("hNtrkjzNok", "Number of tracks in a jet with z>1;N^{tracks} (z>1)",5,0,5);
868 fOutput->Add(hNtrkjzNok);
870 //calculate frag func with pt (simply ptD(or track)\cdot pt jet /ptjet^2)
871 TH1F* hzDT=new TH1F("hzDT", "Z of D in jet in transverse components;(p_{T}^{D} dot p_{T}^{jet})/p_{T}^{jet}^{2} ",nbinsz,zlims[0],zlims[1]);
873 TH1F* hztracksinjetT=new TH1F("hztracksinjetT", "Z of jet tracks in transverse components;(p_{T}^{trks} dot p_{T}^{jet})/p_{T}^{jet}^{2}",nbinsz,zlims[0],zlims[1]);
874 fOutput->Add(hztracksinjetT);
876 TH1I* hIDddaugh=new TH1I("hIDddaugh", "ID of daughters;ID", 2001,-1000,1000);
877 fOutput->Add(hIDddaugh);
878 TH1I* hIDddaughOut=new TH1I("hIDddaughOut", "ID of daughters not found in jet;ID", 2001,-1000,1000);
879 fOutput->Add(hIDddaughOut);
880 TH1I* hIDjetTracks=new TH1I("hIDjetTracks", "ID of jet tracks;ID", 2001,-1000,1000);
881 fOutput->Add(hIDjetTracks);
883 TH1F* hDRdaughOut=new TH1F("hDRdaughOut", "#Delta R of daughters not belonging to the jet tracks (D in jet);#Delta R",200, 0.,2.);
884 fOutput->Add(hDRdaughOut);
887 if(fCandidateType==kDstartoKpipi)
890 TH2F* hDiffSideBand = new TH2F("hDiffSideBand","M(kpipi)-M(kpi) Side Band Background",nbinsmass,fMinMass,fMaxMass,nbinsptD, ptDlims[0],ptDlims[1]);
891 hDiffSideBand->SetStats(kTRUE);
892 hDiffSideBand->GetXaxis()->SetTitle("M(kpipi)-M(Kpi) GeV");
893 hDiffSideBand->GetYaxis()->SetTitle("p_{t}^{D} (GeV/c)");
894 hDiffSideBand->Sumw2();
895 fOutput->Add(hDiffSideBand);
898 TH1F* hPtPion = new TH1F("hPtPion","Primary pions candidates pt ",500,0,10);
899 hPtPion->SetStats(kTRUE);
900 hPtPion->GetXaxis()->SetTitle("GeV/c");
901 hPtPion->GetYaxis()->SetTitle("Entries");
903 fOutput->Add(hPtPion);
906 // D related histograms
907 TH1F *hNDPerEvNoJet=new TH1F("hNDPerEvNoJet","Number of candidates per event with no jets; N candidate/ev with no jet", 20, 0., 20.);
908 hNDPerEvNoJet->Sumw2();
909 fOutput->Add(hNDPerEvNoJet);
911 TH1F *hptDPerEvNoJet=new TH1F("hptDPerEvNoJet","pt distribution of candidates per events with no jets; p_{t}^{D} (GeV/c)",nbinsptD, ptDlims[0],ptDlims[1]);
912 hptDPerEvNoJet->Sumw2();
913 fOutput->Add(hptDPerEvNoJet);
915 if(fSwitchOnSparses){
916 const Int_t nAxisD=4;
917 const Int_t nbinsSparseD[nAxisD]={nbinsSpseta,nbinsSpsphi,nbinsSpsptD,nbinsSpsmass};
918 const Double_t minSparseD[nAxisD] ={etalims[0],philims[0],ptDlims[0],fMinMass};
919 const Double_t maxSparseD[nAxisD] ={etalims[1],philims[1],ptDlims[1],fMaxMass};
920 THnSparseF *hsDstandalone=new THnSparseF("hsDstandalone","#phi, #eta, p_{T}^{D}, and mass", nAxisD, nbinsSparseD, minSparseD, maxSparseD);
921 hsDstandalone->Sumw2();
923 fOutput->Add(hsDstandalone);
927 TH3F* hPtJetWithD=new TH3F("hPtJetWithD","D-Jet Pt distribution; p_{T} (GeV/c);delta mass (GeV/c^{2})",nbinsptjet,ptjetlims[0],ptjetlims[1],nbinsmass,fMinMass,fMaxMass,nbinsptD, ptDlims[0],ptDlims[1]);
928 hPtJetWithD->Sumw2();
929 //for the MC this histogram is filled with the real background
930 TH3F* hPtJetWithDsb=new TH3F("hPtJetWithDsb","D(background)-Jet Pt distribution; p_{T} (GeV/c);delta mass (GeV/c^{2});p_{T}^{D} (GeV/c)",nbinsptjet,ptjetlims[0],ptjetlims[1],nbinsmass,fMinMass,fMaxMass,nbinsptD, ptDlims[0],ptDlims[1]);
931 hPtJetWithDsb->Sumw2();
933 fOutput->Add(hPtJetWithD);
934 fOutput->Add(hPtJetWithDsb);
937 TH1F *hNJetPerEvNoD=new TH1F("hNJetPerEvNoD","Number of jets per event with no D; number of jets/ev with no D",10,-0.5,9.5);
938 hNJetPerEvNoD->Sumw2();
940 TH1F *hPtJetPerEvNoD=new TH1F("hPtJetPerEvNoD","pt distribution of jets per event with no D; p_{T}^{jet} (GeV/c)",nbinsptjet,ptjetlims[0],ptjetlims[1]);
941 hPtJetPerEvNoD->Sumw2();
943 fOutput->Add(hNJetPerEvNoD);
944 fOutput->Add(hPtJetPerEvNoD);
946 TH1F* hDeltaRD=new TH1F("hDeltaRD","#Delta R distribution of D candidates selected;#Delta R",200, 0.,10.);
948 fOutput->Add(hDeltaRD);
950 //background (side bands for the Dstar and like sign for D0)
951 fJetRadius=GetJetContainer(0)->GetJetRadius();
952 TH2F* hInvMassptD = new TH2F("hInvMassptD",Form("D (Delta R < %.1f) invariant mass distribution p_{T}^{j} > threshold",fJetRadius),nbinsmass,fMinMass,fMaxMass,nbinsptD,ptDlims[0],ptDlims[1]);
953 hInvMassptD->SetStats(kTRUE);
954 hInvMassptD->GetXaxis()->SetTitle("mass (GeV)");
955 hInvMassptD->GetYaxis()->SetTitle("p_{t}^{D} (GeV/c)");
956 hInvMassptD->Sumw2();
958 fOutput->Add(hInvMassptD);
961 TH2F* hInvMassptDbg = new TH2F("hInvMassptDbg",Form("Background D (Delta R < %.1f) invariant mass distribution p_{T}^{j} > threshold",fJetRadius),nbinsmass,fMinMass,fMaxMass,nbinsptD,ptDlims[0],ptDlims[1]);
962 hInvMassptDbg->GetXaxis()->SetTitle(Form("%s (GeV)",(fCandidateType==kDstartoKpipi) ? "M(Kpipi)" : "M(Kpi)"));
963 hInvMassptDbg->GetYaxis()->SetTitle("p_{t}^{D} (GeV/c)");
964 hInvMassptDbg->Sumw2();
965 fOutput->Add(hInvMassptDbg);
969 if(fSwitchOnSparses){
970 Double_t pi=TMath::Pi(), philims2[2];
971 philims2[0]=-pi*1./2.;
972 philims2[1]=pi*3./2.;
973 THnSparseF *hsDphiz=0x0; //definition below according to the switches
975 if(fSwitchOnSB && fSwitchOnPhiAxis && fSwitchOnOutOfConeAxis){
976 AliInfo("Creating a 9 axes container: This might cause large memory usage");
978 const Int_t nbinsSparse[nAxis]={nbinsSpsz,nbinsSpsphi,nbinsSpsptjet,nbinsSpsptD,nbinsSpsmass,2, 2, 2, 2};
979 const Double_t minSparse[nAxis]={zlims[0],philims2[0],ptjetlims[0],ptDlims[0],fMinMass,-0.5, -0.5,-0.5,-0.5};
980 const Double_t maxSparse[nAxis]={zlims[1],philims2[1],ptjetlims[1],ptDlims[1],fMaxMass, 1.5, 1.5, 1.5 , 1.5};
981 fNAxesBigSparse=nAxis;
983 hsDphiz=new THnSparseF("hsDphiz","Z and #Delta#phi vs p_{T}^{jet}, p_{T}^{D}, mass. SB? D within the jet cone?, D in EMCal acc?, jet in EMCal acc?", nAxis, nbinsSparse, minSparse, maxSparse);
986 if(!fSwitchOnPhiAxis || !fSwitchOnOutOfConeAxis || !fSwitchOnSB){
988 fSwitchOnOutOfConeAxis=0;
990 AliInfo("Creating a 6 axes container");
992 const Int_t nbinsSparse[nAxis]={nbinsSpsz,nbinsSpsptjet,nbinsSpsptD,nbinsSpsmass, 2, 2};
993 const Double_t minSparse[nAxis]={zlims[0],ptjetlims[0],ptDlims[0],fMinMass,-0.5,-0.5};
994 const Double_t maxSparse[nAxis]={zlims[1],ptjetlims[1],ptDlims[1],fMaxMass, 1.5, 1.5};
995 fNAxesBigSparse=nAxis;
997 hsDphiz=new THnSparseF("hsDphiz","Z vs p_{T}^{jet}, p_{T}^{D}, mass., D in EMCal acc?, jet in EMCal acc?", nAxis, nbinsSparse, minSparse, maxSparse);
999 if(!hsDphiz) AliFatal("No THnSparse created");
1002 fOutput->Add(hsDphiz);
1005 PostData(1, fOutput);
1010 //_______________________________________________________________________________
1012 void AliAnalysisTaskFlavourJetCorrelations::FillHistogramsRecoJetCorr(AliVParticle* candidate, AliEmcalJet *jet, AliAODEvent* aodEvent){
1014 Double_t ptD=candidate->Pt();
1015 Double_t deltaR=DeltaR(candidate,jet);
1016 Double_t phiD=candidate->Phi();
1017 Double_t deltaphi = jet->Phi()-phiD;
1018 if(deltaphi<=-(TMath::Pi())/2.) deltaphi = deltaphi+2.*(TMath::Pi());
1019 if(deltaphi>(3.*(TMath::Pi()))/2.) deltaphi = deltaphi-2.*(TMath::Pi());
1020 Double_t z=Z(candidate,jet);
1023 ((TH1I*)fOutput->FindObject("hControlDInJ"))->Fill(7);
1024 Double_t pmissing=TMath::Sqrt(fPmissing[0]*fPmissing[0]+fPmissing[1]*fPmissing[1]+fPmissing[2]*fPmissing[2]);
1026 for(Int_t k=0;k<3;k++) ((TH1F*)fOutput->FindObject(Form("hMissP%d",k)))->Fill(fPmissing[k]);
1028 ((TH1F*)fOutput->FindObject("hmissingp"))->Fill(pmissing);
1029 Double_t ptdiff=fPtJet-jet->Pt();
1030 ((TH1F*)fOutput->FindObject("hDeltaPtJet"))->Fill(ptdiff);
1031 ((TH1F*)fOutput->FindObject("hRelDeltaPtJet"))->Fill(ptdiff/jet->Pt());
1036 if(fIsDInJet)((TH1F*)fOutput->FindObject("hzDT"))->Fill(Z(candidate,jet,kTRUE));
1038 TH1F* hDeltaRD=(TH1F*)fOutput->FindObject("hDeltaRD");
1039 hDeltaRD->Fill(deltaR);
1040 Bool_t bDInEMCalAcc=InEMCalAcceptance(candidate);
1041 Bool_t bJetInEMCalAcc=InEMCalAcceptance(jet);
1043 if(fCandidateType==kD0toKpi) {
1044 AliAODRecoDecayHF* dzero=(AliAODRecoDecayHF*)candidate;
1046 FillHistogramsD0JetCorr(dzero,deltaphi,z,ptD,fPtJet,bDInEMCalAcc,bJetInEMCalAcc, aodEvent);
1050 if(fCandidateType==kDstartoKpipi) {
1051 AliAODRecoCascadeHF* dstar = (AliAODRecoCascadeHF*)candidate;
1052 FillHistogramsDstarJetCorr(dstar,deltaphi,z,ptD,fPtJet,bDInEMCalAcc,bJetInEMCalAcc);
1055 } else{ //generated level
1056 //AliInfo("Non reco");
1057 FillHistogramsMCGenDJetCorr(deltaphi,z,ptD,fPtJet,bDInEMCalAcc,bJetInEMCalAcc);
1061 //_______________________________________________________________________________
1063 void AliAnalysisTaskFlavourJetCorrelations::FillHistogramsD0JetCorr(AliAODRecoDecayHF* candidate, Double_t dPhi, Double_t z, Double_t ptD, Double_t ptj, Bool_t bDInEMCalAcc, Bool_t bJetInEMCalAcc, AliAODEvent* aodEvent){
1066 Double_t masses[2]={0.,0.};
1067 Int_t pdgdaughtersD0[2]={211,321};//pi,K
1068 Int_t pdgdaughtersD0bar[2]={321,211};//K,pi
1070 masses[0]=candidate->InvMass(fNProngs,(UInt_t*)pdgdaughtersD0); //D0
1071 masses[1]=candidate->InvMass(fNProngs,(UInt_t*)pdgdaughtersD0bar); //D0bar
1073 //TH3F* hPtJetWithD=(TH3F*)fOutput->FindObject("hPtJetWithD");
1074 THnSparseF* hsDphiz=(THnSparseF*)fOutput->FindObject("hsDphiz");
1075 Double_t *point=0x0;
1076 if(fNAxesBigSparse==9){
1077 point=new Double_t[9];
1084 point[6]=static_cast<Double_t>(fIsDInJet ? 1 : 0);
1085 point[7]=static_cast<Double_t>(bDInEMCalAcc ? 1 : 0);
1086 point[8]=static_cast<Double_t>(bJetInEMCalAcc ? 1 : 0);
1088 if(fNAxesBigSparse==6){
1089 point=new Double_t[6];
1094 point[4]=static_cast<Double_t>(bDInEMCalAcc ? 1 : 0);
1095 point[5]=static_cast<Double_t>(bJetInEMCalAcc ? 1 : 0);
1099 Printf("Candidate in FillHistogramsD0JetCorr IsA %s", (candidate->IsA())->GetName());
1100 Int_t isselected=fCuts->IsSelected(candidate,AliRDHFCuts::kAll,aodEvent);
1101 if(isselected==1 || isselected==3) {
1103 //if(fIsDInJet) hPtJetWithD->Fill(ptj,masses[0],ptD);
1105 FillMassHistograms(masses[0], ptD);
1106 if(fSwitchOnOutOfConeAxis || fIsDInJet) hsDphiz->Fill(point,1.);
1109 //if(fIsDInJet) hPtJetWithD->Fill(ptj,masses[1],ptD);
1111 FillMassHistograms(masses[1], ptD);
1112 if(fNAxesBigSparse==9) point[4]=masses[1];
1113 if(fNAxesBigSparse==6) point[3]=masses[1];
1114 if(fSwitchOnOutOfConeAxis || fIsDInJet) hsDphiz->Fill(point,1.);
1119 //_______________________________________________________________________________
1121 void AliAnalysisTaskFlavourJetCorrelations::FillHistogramsDstarJetCorr(AliAODRecoCascadeHF* dstar, Double_t dPhi, Double_t z, Double_t ptD, Double_t ptj, Bool_t bDInEMCalAcc, Bool_t bJetInEMCalAcc){
1122 //dPhi and z not used at the moment,but will be (re)added
1124 AliAODTrack *softpi = (AliAODTrack*)dstar->GetBachelor();
1125 Double_t deltamass= dstar->DeltaInvMass();
1126 //Double_t massD0= dstar->InvMassD0();
1129 TH1F* hPtPion=(TH1F*)fOutput->FindObject("hPtPion");
1130 hPtPion->Fill(softpi->Pt());
1132 //TH3F* hPtJetWithD=(TH3F*)fOutput->FindObject("hPtJetWithD");
1133 THnSparseF* hsDphiz=(THnSparseF*)fOutput->FindObject("hsDphiz");
1134 Int_t isSB=0;//IsDzeroSideBand(dstar);
1136 //Double_t point[]={z,dPhi,ptj,ptD,deltamass,static_cast<Double_t>(isSB), static_cast<Double_t>(fIsDInJet ? 1 : 0),bDInEMCalAcc,bJetInEMCalAcc};
1137 Double_t *point=0x0;
1138 if(fNAxesBigSparse==9){
1139 point=new Double_t[9];
1145 point[5]=static_cast<Double_t>(isSB);
1146 point[6]=static_cast<Double_t>(fIsDInJet ? 1 : 0);
1147 point[7]=static_cast<Double_t>(bDInEMCalAcc ? 1 : 0);
1148 point[8]=static_cast<Double_t>(bJetInEMCalAcc ? 1 : 0);
1150 if(fNAxesBigSparse==6){
1151 point=new Double_t[6];
1156 point[4]=static_cast<Double_t>(bDInEMCalAcc ? 1 : 0);
1157 point[5]=static_cast<Double_t>(bJetInEMCalAcc ? 1 : 0);
1160 //if(fIsDInJet) hPtJetWithD->Fill(ptj,deltamass,ptD);
1162 FillMassHistograms(deltamass, ptD);
1163 if(fSwitchOnSparses && (fSwitchOnOutOfConeAxis || fIsDInJet)) hsDphiz->Fill(point,1.);
1167 //_______________________________________________________________________________
1169 void AliAnalysisTaskFlavourJetCorrelations::FillHistogramsMCGenDJetCorr(Double_t dPhi,Double_t z,Double_t ptD,Double_t ptjet, Bool_t bDInEMCalAcc, Bool_t bJetInEMCalAcc){
1172 //TH3F* hPtJetWithD=(TH3F*)fOutput->FindObject("hPtJetWithD");
1173 THnSparseF* hsDphiz=(THnSparseF*)fOutput->FindObject("hsDphiz");
1174 //Double_t point[9]={z,dPhi,ptjet,ptD,pdgmass,0, static_cast<Double_t>(fIsDInJet ? 1 : 0),bDInEMCalAcc,bJetInEMCalAcc};
1175 Double_t *point=0x0;
1176 if(fNAxesBigSparse==9){
1177 point=new Double_t[9];
1184 point[6]=static_cast<Double_t>(fIsDInJet ? 1 : 0);
1185 point[7]=static_cast<Double_t>(bDInEMCalAcc ? 1 : 0);
1186 point[8]=static_cast<Double_t>(bJetInEMCalAcc ? 1 : 0);
1188 if(fNAxesBigSparse==6){
1189 point=new Double_t[6];
1194 point[4]=static_cast<Double_t>(bDInEMCalAcc ? 1 : 0);
1195 point[5]=static_cast<Double_t>(bJetInEMCalAcc ? 1 : 0);
1198 if(fCandidateType==kD0toKpi) pdgmass=TDatabasePDG::Instance()->GetParticle(421)->Mass();
1199 if(fCandidateType==kDstartoKpipi) pdgmass=TDatabasePDG::Instance()->GetParticle(413)->Mass()-TDatabasePDG::Instance()->GetParticle(421)->Mass();
1200 if(fNAxesBigSparse==9) point[4]=pdgmass;
1201 if(fNAxesBigSparse==6) point[3]=pdgmass;
1202 if(fSwitchOnSparses && (fSwitchOnOutOfConeAxis || fIsDInJet)) hsDphiz->Fill(point,1.);
1204 // hPtJetWithD->Fill(ptjet,pdgmass,ptD); // candidates within a jet
1209 //_______________________________________________________________________________
1211 void AliAnalysisTaskFlavourJetCorrelations::FillMassHistograms(Double_t mass,Double_t ptD){
1214 TH2F* hInvMassptD=(TH2F*)fOutput->FindObject("hInvMassptD");
1215 hInvMassptD->Fill(mass,ptD);
1219 //________________________________________________________________________________
1221 void AliAnalysisTaskFlavourJetCorrelations::FlagFlavour(AliEmcalJet *jet){
1223 AliEmcalJet::EFlavourTag tag=AliEmcalJet::kDStar;
1224 if (fCandidateType==kD0toKpi) tag=AliEmcalJet::kD0;
1225 if (fIsDInJet) jet->AddFlavourTag(tag);
1231 //_______________________________________________________________________________
1233 void AliAnalysisTaskFlavourJetCorrelations::SideBandBackground(AliAODRecoCascadeHF *candDstar, AliEmcalJet *jet){
1235 // D* side band background method. Two side bands, in M(Kpi) are taken at ~6 sigmas
1236 // (expected detector resolution) on the left and right frm the D0 mass. Each band
1237 // has a width of ~5 sigmas. Two band needed for opening angle considerations
1238 TH2F* hDiffSideBand=(TH2F*)fOutput->FindObject("hDiffSideBand");
1239 //TH3F* hPtJetWithDsb=(TH3F*)fOutput->FindObject("hPtJetWithDsb");
1240 THnSparseF* hsDphiz=(THnSparseF*)fOutput->FindObject("hsDphiz");
1242 Bool_t bDInEMCalAcc=InEMCalAcceptance(candDstar);
1243 Bool_t bJetInEMCalAcc=InEMCalAcceptance(jet);
1245 Double_t deltaM=candDstar->DeltaInvMass();
1246 //Printf("Inv mass = %f between %f and %f or %f and %f?",invM, sixSigmal,fourSigmal,fourSigmar,sixSigmar);
1247 Double_t z=Z(candDstar,jet);
1248 Double_t ptD=candDstar->Pt();
1250 Double_t dPhi=jet->Phi()-candDstar->Phi();
1252 if(dPhi<=-(TMath::Pi())/2) dPhi = dPhi+2*(TMath::Pi());
1253 if(dPhi>(3*(TMath::Pi()))/2) dPhi = dPhi-2*(TMath::Pi());
1255 Int_t isSideBand=1;//IsDzeroSideBand(candDstar);
1256 //if no SB analysis we should not enter here, so no need of checking the number of axes
1257 Double_t point[9]={z,dPhi,fPtJet,ptD,deltaM,static_cast<Double_t>(isSideBand), static_cast<Double_t>(fIsDInJet ? 1 : 0),static_cast<Double_t>(bDInEMCalAcc? 1 : 0),static_cast<Double_t>(bJetInEMCalAcc? 1 : 0)};
1258 //fill the background histogram with the side bands or when looking at MC with the real background
1260 hDiffSideBand->Fill(deltaM,ptD); // M(Kpipi)-M(Kpi) side band background
1261 //hdeltaPhiDjaB->Fill(deltaM,ptD,dPhi);
1262 if(fSwitchOnSparses) hsDphiz->Fill(point,1.);
1263 //if(fIsDInJet){ // evaluate in the near side
1264 // hPtJetWithDsb->Fill(fPtJet,deltaM,ptD);
1269 //_______________________________________________________________________________
1271 void AliAnalysisTaskFlavourJetCorrelations::MCBackground(AliAODRecoDecayHF *candbg){
1273 //need mass, deltaR, pt jet, ptD
1274 //two cases: D0 and Dstar
1276 Int_t isselected=fCuts->IsSelected(candbg,AliRDHFCuts::kAll, AODEvent());
1277 if(!isselected) return;
1279 Double_t ptD=candbg->Pt();
1281 TH2F* hInvMassptDbg=(TH2F*)fOutput->FindObject("hInvMassptDbg");
1282 //TH3F* hPtJetWithDsb=(TH3F*)fOutput->FindObject("hPtJetWithDsb");
1285 if(fCandidateType==kDstartoKpipi){
1286 AliAODRecoCascadeHF* dstarbg = (AliAODRecoCascadeHF*)candbg;
1287 Double_t deltaM=dstarbg->DeltaInvMass();
1288 hInvMassptDbg->Fill(deltaM,ptD);
1289 //if(fIsDInJet) hPtJetWithDsb->Fill(fPtJet,deltaM,ptD);
1292 if(fCandidateType==kD0toKpi){
1293 Double_t masses[2]={0.,0.};
1294 Int_t pdgdaughtersD0[2]={211,321};//pi,K
1295 Int_t pdgdaughtersD0bar[2]={321,211};//K,pi
1297 masses[0]=candbg->InvMass(fNProngs,(UInt_t*)pdgdaughtersD0); //D0
1298 masses[1]=candbg->InvMass(fNProngs,(UInt_t*)pdgdaughtersD0bar); //D0bar
1301 if(isselected==1 || isselected==3) {
1302 //if(fIsDInJet) hPtJetWithDsb->Fill(fPtJet,masses[0],ptD);
1303 hInvMassptDbg->Fill(masses[0],ptD);
1306 //if(fIsDInJet) hPtJetWithDsb->Fill(fPtJet,masses[1],ptD);
1307 hInvMassptDbg->Fill(masses[1],ptD);
1314 //_______________________________________________________________________________
1316 Float_t AliAnalysisTaskFlavourJetCorrelations::DeltaR(AliVParticle *p1, AliVParticle *p2) const {
1317 //Calculate DeltaR between p1 and p2: DeltaR=sqrt(Delataphi^2+DeltaEta^2)
1319 if(!p1 || !p2) return -1;
1320 Double_t phi1=p1->Phi(),eta1=p1->Eta();
1321 Double_t phi2 = p2->Phi(),eta2 = p2->Eta() ;
1323 Double_t dPhi=phi1-phi2;
1324 if(dPhi<=-(TMath::Pi())/2) dPhi = dPhi+2*(TMath::Pi());
1325 if(dPhi>(3*(TMath::Pi()))/2) dPhi = dPhi-2*(TMath::Pi());
1327 Double_t dEta=eta1-eta2;
1328 Double_t deltaR=TMath::Sqrt(dEta*dEta + dPhi*dPhi );
1333 //_______________________________________________________________________________
1335 Int_t AliAnalysisTaskFlavourJetCorrelations::IsDzeroSideBand(AliAODRecoCascadeHF *candDstar){
1337 Double_t ptD=candDstar->Pt();
1338 Int_t bin = fCuts->PtBin(ptD);
1340 // /PWGHF/vertexingHF/AliRDHFCuts::PtBin(Double_t) const may return values below zero depending on config.
1341 bin = 9999; // void result code for coverity (bin later in the code non-zero) - will coverity pick up on this?
1342 return -1; // out of bounds
1345 Double_t invM=candDstar->InvMassD0();
1346 Double_t mPDGD0=TDatabasePDG::Instance()->GetParticle(421)->Mass();
1348 Float_t fourSigmal= mPDGD0-4.*fSigmaD0[bin] , sixSigmal= mPDGD0-8.*fSigmaD0[bin];
1349 Float_t fourSigmar= mPDGD0+4.*fSigmaD0[bin] , sixSigmar= mPDGD0+8.*fSigmaD0[bin];
1351 if((invM>=sixSigmal && invM<fourSigmal) || (invM>fourSigmar && invM<=sixSigmar)) return 1;
1356 //_______________________________________________________________________________
1358 Bool_t AliAnalysisTaskFlavourJetCorrelations::AreDaughtersInJet(AliEmcalJet *thejet, AliAODRecoDecayHF* charm, Int_t*& daughOutOfJetID, AliAODTrack**& dtrks, Bool_t fillH){
1359 //returns true/false and the array of particles not found among jet constituents
1361 TH1I* hControlDInJ=(TH1I*)fOutput->FindObject("hControlDInJ");
1362 TH1I* hIDddaugh =(TH1I*)fOutput->FindObject("hIDddaugh");
1363 TH1I* hIDddaughOut=(TH1I*)fOutput->FindObject("hIDddaughOut");
1364 TH1I* hIDjetTracks=(TH1I*)fOutput->FindObject("hIDjetTracks");
1366 Int_t daughtersID[3];
1368 Int_t dmatchedID[3]={0,0,0};
1369 Int_t countmatches=0;
1370 if (fCandidateType==kDstartoKpipi){
1371 AliAODRecoCascadeHF* dstar = (AliAODRecoCascadeHF*)charm;
1372 AliAODRecoDecayHF2Prong* dzero=dstar->Get2Prong();
1373 daughtersID[0]=dzero->GetProngID(0);
1374 daughtersID[1]=dzero->GetProngID(1);
1375 daughtersID[2]=dstar->GetBachelor()->GetID();
1378 dtrks=new AliAODTrack*[3];
1379 dtrks[0]=(AliAODTrack*)dzero->GetDaughter(0);
1380 dtrks[1]=(AliAODTrack*)dzero->GetDaughter(1);
1381 dtrks[2]=(AliAODTrack*)dstar->GetBachelor();
1385 if(daughtersID[0]!=((AliAODTrack*)dtrks[0])->GetID() || daughtersID[1]!=((AliAODTrack*)dtrks[1])->GetID()) hControlDInJ->Fill(6);
1387 hIDddaugh->Fill(daughtersID[0]);
1388 hIDddaugh->Fill(daughtersID[1]);
1389 hIDddaugh->Fill(daughtersID[2]);
1392 //Printf("ID daughters %d, %d, %d",daughtersID[0], daughtersID[1], daughtersID[2]);
1395 if (fCandidateType==kD0toKpi){
1396 daughtersID[0]=charm->GetProngID(0);
1397 daughtersID[1]=charm->GetProngID(1);
1400 hIDddaugh->Fill(daughtersID[0]);
1401 hIDddaugh->Fill(daughtersID[1]);
1403 dtrks=new AliAODTrack*[2];
1404 dtrks[0]=(AliAODTrack*)charm->GetDaughter(0);
1405 dtrks[1]=(AliAODTrack*)charm->GetDaughter(1);
1409 const Int_t cndaugh=ndaugh;
1410 daughOutOfJetID=new Int_t[cndaugh];
1412 Int_t nchtrk=thejet->GetNumberOfTracks();
1413 for(Int_t itk=0;itk<nchtrk;itk++){
1414 AliVTrack* tkjet=((AliPicoTrack*)thejet->TrackAt(itk,fTrackArr))->GetTrack();
1415 Int_t idtkjet=tkjet->GetID();
1416 if(fillH) hIDjetTracks->Fill(idtkjet);
1417 for(Int_t id=0;id<ndaugh;id++){
1418 if(idtkjet==daughtersID[id]) {
1419 dmatchedID[id]=daughtersID[id]; //daughter which matches a track in the jet
1424 if(countmatches==ndaugh) break;
1427 //reverse: include in the array the ID of daughters not matching
1429 for(Int_t id=0;id<ndaugh;id++){
1430 if(dmatchedID[id]==0) {
1431 daughOutOfJetID[id]=daughtersID[id];
1432 if(fillH) hIDddaughOut->Fill(daughOutOfJetID[id]);
1434 else daughOutOfJetID[id]=0;
1437 if((ndaugh-countmatches) == 1) hControlDInJ->Fill(0);
1438 if((ndaugh-countmatches) == 2) hControlDInJ->Fill(1);
1439 if((ndaugh-countmatches) == 3) hControlDInJ->Fill(2);
1441 if(ndaugh!=countmatches){
1448 //_______________________________________________________________________________
1450 Bool_t AliAnalysisTaskFlavourJetCorrelations::IsDInJet(AliEmcalJet *thejet, AliAODRecoDecayHF* charm, Bool_t fillH){
1452 //check the conditions type:
1453 //type 0 : DeltaR < jet radius, don't check daughters (and don't correct pt jet)
1454 //type 1 : DeltaR < jet radius and check for all daughters among jet tracks, don't correct ptjet
1455 //type 2 (default) : DeltaR < jet radius and check for all daughters among jet tracks, if not present, correct the ptjet
1457 TH1I* hControlDInJ=(TH1I*)fOutput->FindObject("hControlDInJ");
1458 TH1F* hDRdaughOut=(TH1F*)fOutput->FindObject("hDRdaughOut");
1464 Bool_t testDeltaR=kFALSE;
1465 if(DeltaR(thejet,charm)<fJetRadius) testDeltaR=kTRUE;
1467 Int_t* daughOutOfJet;
1468 AliAODTrack** charmDaugh;
1469 Bool_t testDaugh=AreDaughtersInJet(thejet, charm, daughOutOfJet,charmDaugh,fillH);
1470 if(testDaugh && testDeltaR) {
1471 //Z of candidates with daughters in the jet
1472 ((TH1F*)fOutput->FindObject("hzDinjet"))->Fill(Z(charm,thejet));
1475 if(!testDaugh && testDeltaR && fTypeDInJet==2){
1478 if(fCandidateType==kD0toKpi) ndaugh=2;
1481 for(Int_t id=0;id<ndaugh;id++){
1482 if(daughOutOfJet[id]!=0){ //non-matched daughter
1483 //get track and its momentum
1486 hControlDInJ->Fill(3);
1487 if(id<2) hControlDInJ->Fill(4);
1488 if(id==2)hControlDInJ->Fill(5);
1489 hDRdaughOut->Fill(DeltaR(thejet, charmDaugh[id]));
1491 fPmissing[0]+=charmDaugh[id]->Px();
1492 fPmissing[1]+=charmDaugh[id]->Py();
1493 fPmissing[2]+=charmDaugh[id]->Pz();
1498 //now the D in within the jet
1503 delete[] charmDaugh;
1506 switch(fTypeDInJet){
1511 result=testDeltaR && testDaugh;
1514 result=testDeltaR && testDaugh;
1517 AliInfo("Selection type not specified, use 1");
1518 result=testDeltaR && testDaugh;
1524 Bool_t AliAnalysisTaskFlavourJetCorrelations::InEMCalAcceptance(AliVParticle *vpart){
1525 //check eta phi of a VParticle: return true if it is in the EMCal acceptance, false otherwise
1527 Double_t phiEMCal[2]={1.405,3.135},etaEMCal[2]={-0.7,0.7};
1528 Bool_t binEMCal=kTRUE;
1529 Double_t phi=vpart->Phi(), eta=vpart->Eta();
1530 if(phi<phiEMCal[0] || phi>phiEMCal[1]) binEMCal=kFALSE;
1531 if(eta<etaEMCal[0] || eta>etaEMCal[1]) binEMCal=kFALSE;