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 **************************************************************************/
16 //-----------------------------------------------------------------------
17 // Class for HF corrections as a function of many variables and step
18 // Author : C. Zampolli, CERN
19 // D. Caffarri, Univ & INFN Padova caffarri@pd.infn.it
20 // Base class for HF Unfolding - agrelli@uu.nl
21 //-----------------------------------------------------------------------
23 #include "TParticle.h"
24 #include "TClonesArray.h"
25 #include "AliAODMCParticle.h"
26 #include "AliAODRecoDecayHF.h"
27 #include "AliAODRecoDecayHF2Prong.h"
28 #include "AliAODRecoDecayHF3Prong.h"
29 #include "AliAODRecoDecayHF4Prong.h"
30 #include "AliAODMCHeader.h"
31 #include "AliAODEvent.h"
33 #include "AliESDtrackCuts.h"
34 #include "AliESDtrack.h"
36 #include "AliCFVertexingHF.h"
38 //___________________________________________________________
39 AliCFVertexingHF::AliCFVertexingHF() :
42 fmcPartCandidate(0x0),
47 fFillFromGenerated(0),
50 fKeepDfromBOnly(kFALSE),
63 //_____________________________________________________
64 AliCFVertexingHF::AliCFVertexingHF(TClonesArray *mcArray, UShort_t originDselection) :
67 fmcPartCandidate(0x0),
72 fFillFromGenerated(0),
75 fKeepDfromBOnly(kFALSE),
80 // constructor with mcArray
83 SetDselection(originDselection);
87 //_______________________________________________________
88 AliCFVertexingHF::~AliCFVertexingHF()
94 if (fmcArray) fmcArray = 0x0;
95 if (fRecoCandidate) fRecoCandidate = 0x0;
96 if (fmcPartCandidate) fmcPartCandidate = 0x0;
99 //_____________________________________________________
100 AliCFVertexingHF& AliCFVertexingHF::operator=(const AliCFVertexingHF& c)
103 // assigment operator
107 TObject::operator=(c);
108 fmcArray = c.fmcArray;
109 fRecoCandidate = c.fRecoCandidate;
110 fmcPartCandidate = c.fmcPartCandidate;
111 fNDaughters = c.fNDaughters;
113 fzPrimVertex = c.fzPrimVertex;
114 fzMCVertex = c.fzMCVertex;
115 fFillFromGenerated = c.fFillFromGenerated;
116 fOriginDselection = c.fOriginDselection;
117 fKeepDfromB = c.fKeepDfromB;
118 fKeepDfromBOnly = c.fKeepDfromBOnly;
119 fmcLabel = c.fmcLabel;
126 //____________________________________________________
127 AliCFVertexingHF::AliCFVertexingHF(const AliCFVertexingHF &c) :
129 fmcArray(c.fmcArray),
130 fRecoCandidate(c.fRecoCandidate),
131 fmcPartCandidate(c.fmcPartCandidate),
132 fNDaughters(c.fNDaughters),
134 fzPrimVertex(c.fzPrimVertex),
135 fzMCVertex(c.fzMCVertex),
136 fFillFromGenerated(c.fFillFromGenerated),
137 fOriginDselection (c.fOriginDselection),
138 fKeepDfromB (c.fKeepDfromB),
139 fKeepDfromBOnly (c.fKeepDfromBOnly),
140 fmcLabel(c.fmcLabel),
148 //___________________________________________________________
149 void AliCFVertexingHF::SetDselection(UShort_t originDselection)
151 // setting the way the D0 will be selected
152 // 0 --> only from c quarks
153 // 1 --> only from b quarks
154 // 2 --> from both c quarks and b quarks
156 fOriginDselection = originDselection;
158 if (fOriginDselection == 0) {
159 fKeepDfromB = kFALSE;
160 fKeepDfromBOnly = kFALSE;
163 if (fOriginDselection == 1) {
165 fKeepDfromBOnly = kTRUE;
168 if (fOriginDselection == 2) {
170 fKeepDfromBOnly = kFALSE;
176 //______________________________________________________
177 void AliCFVertexingHF::SetMCCandidateParam(Int_t label)
180 // setting the parameters (candidate and n. daughters)
183 fmcPartCandidate = dynamic_cast <AliAODMCParticle*> (fmcArray->At(label));
184 fNDaughters = fmcPartCandidate->GetNDaughters();
188 //____________________________________________________________
189 Int_t AliCFVertexingHF::MCcquarkCounting(AliAODMCParticle* mcPart) const
192 // counting the c-quarks
196 if (mcPart->GetPdgCode() == 4) cquarks++;
197 if (mcPart->GetPdgCode() == -4) cquarks++;
199 AliWarning("Particle not found in tree, skipping\n");
206 //________________________________________________________
207 Bool_t AliCFVertexingHF::CheckMCPartFamily(AliAODMCParticle */*mcPart*/, TClonesArray */*mcArray*/) const
210 //checking the family
213 Int_t pdgGranma = CheckOrigin();
214 if (pdgGranma == -9999){
215 AliDebug(2,"This particle come from a B decay channel but according to the settings of the task, we keep only the prompt charm particles\n");
216 AliInfo("This particle come from a B decay channel but according to the settings of the task, we keep only the prompt charm particles\n");
220 if (pdgGranma == -999){
221 AliDebug(2,"This particle come from a prompt charm particles but according to the settings of the task, we want only the ones coming from B\n");
222 AliInfo("This particle come from a prompt charm particles but according to the settings of the task, we want only the ones coming from B\n");
226 if (!CheckMCDaughters()) {
227 Printf("CheckMCDaughters false");
230 if (!CheckMCChannelDecay()) {
231 Printf("CheckMCChannelDecay false");
237 //_________________________________________________________________________________________________
238 Int_t AliCFVertexingHF::CheckOrigin() const
241 // checking whether the mother of the particles come from a charm or a bottom quark
246 mother = fmcPartCandidate->GetMother();
250 AliDebug(2,Form("mother at step %d = %d", istep, mother));
251 AliAODMCParticle* mcGranma = dynamic_cast<AliAODMCParticle*>(fmcArray->At(mother));
252 pdgGranma = mcGranma->GetPdgCode();
253 AliDebug(2,Form("Pdg mother at step %d = %d", istep, pdgGranma));
254 Int_t abspdgGranma = TMath::Abs(pdgGranma);
255 if ((abspdgGranma > 500 && abspdgGranma < 600) || (abspdgGranma > 5000 && abspdgGranma < 6000)) {
256 if (!fKeepDfromB) return -9999; //skip particle if come from a B meson.
263 if (fKeepDfromBOnly) return -999;
266 mother = mcGranma->GetMother();
273 //___________________________________________
274 Bool_t AliCFVertexingHF::CheckMCDaughters()const
277 // checking the daughters
280 Printf("CheckMCDaughters");
282 AliAODMCParticle *mcPartDaughter;
283 Bool_t checkDaughters = kFALSE;
285 Int_t label0 = fmcPartCandidate->GetDaughter(0);
286 Int_t label1 = fmcPartCandidate->GetDaughter(1);
287 Printf("label0 = %d, label1 = %d",label0,label1);
288 if (label1==0 || label0 == 0){
289 AliDebug(2, Form("The MC particle doesn't jave correct daughters, skipping!!"));
290 AliInfo(Form("The MC particle doesn't jave correct daughters, skipping!!"));
291 return checkDaughters;
294 if (label1 - label0 != fProngs-1){
295 AliDebug(2, Form("The MC particle doesn't come from a %d-prong decay, skipping!!", fProngs));
296 AliInfo(Form("The MC particle doesn't come from a %d-prong decay, skipping!!", fProngs));
297 return checkDaughters;
300 for (Int_t iProng = 0; iProng<fProngs; iProng++){
301 mcPartDaughter = dynamic_cast<AliAODMCParticle*>(fmcArray->At(label0+iProng));
302 if (!mcPartDaughter) {
303 AliWarning("At least one Daughter Particle not found in tree, skipping");
304 return checkDaughters;
308 checkDaughters = kTRUE;
309 return checkDaughters;
312 //______________________________________________________
313 Bool_t AliCFVertexingHF::FillMCContainer(Double_t *containerInputMC)
316 // fill the container for Generator level selection
319 Bool_t mcContainerFilled = kFALSE;
321 Double_t* vectorMC = new Double_t[fNVar];
322 for (Int_t iVar = 0; iVar<fNVar; iVar++) vectorMC[iVar]= 9999.;
324 if (GetGeneratedValuesFromMCParticle(&vectorMC[0])){
325 for (Int_t iVar = 0; iVar<fNVar; iVar++){
326 containerInputMC[iVar] = vectorMC[iVar];
328 mcContainerFilled = kTRUE;
332 return mcContainerFilled;
335 //______________________________________________________
336 Bool_t AliCFVertexingHF::FillRecoContainer(Double_t *containerInput)
339 // fill the container for Reconstrucred level selection
342 Bool_t recoContainerFilled = kFALSE;
343 Double_t* vectorValues = new Double_t[fNVar];
344 Double_t* vectorReco = new Double_t[fNVar];
346 for (Int_t iVar = 0; iVar<fNVar; iVar++) {
347 vectorValues[iVar]= 9999.;
348 vectorReco[iVar]=9999.;
351 if(fFillFromGenerated){
352 //filled with MC values
353 if (GetGeneratedValuesFromMCParticle(&vectorValues[0])){
354 for (Int_t iVar = 0; iVar<fNVar; iVar++){
355 containerInput[iVar] = vectorValues[iVar];
357 recoContainerFilled = kTRUE;
361 //filled with Reco values
363 if (GetRecoValuesFromCandidate(&vectorReco[0])){
364 for (Int_t iVar = 0; iVar<fNVar; iVar++){
365 containerInput[iVar] = vectorReco[iVar];
367 recoContainerFilled = kTRUE;
371 delete [] vectorValues;
372 delete [] vectorReco;
375 return recoContainerFilled;
378 //_____________________________________________________
379 Bool_t AliCFVertexingHF::MCAcceptanceStep() const
382 // checking the MC acceptance step
385 Bool_t bMCAccStep = kFALSE;
387 AliAODMCParticle *mcPartDaughter;
388 Int_t label0 = fmcPartCandidate->GetDaughter(0);
389 Int_t label1 = fmcPartCandidate->GetDaughter(1);
390 if (label1==0 || label0 == 0){
391 AliDebug(2, Form("The MC particle doesn't have correct daughters, skipping!!"));
395 if (label1 - label0 != fProngs-1){
396 AliDebug(2, Form("The MC particle doesn't come from a %d-prong decay, skipping!!", fProngs));
400 for (Int_t iProng = 0; iProng<fProngs; iProng++){
401 mcPartDaughter = dynamic_cast<AliAODMCParticle*>(fmcArray->At(label0+iProng));
402 if (!mcPartDaughter) {
403 AliWarning("At least one Daughter Particle not found in tree, skipping");
406 Double_t eta = mcPartDaughter->Eta();
407 Double_t pt = mcPartDaughter->Pt();
409 //set values of eta and pt in the constructor.
410 if (TMath::Abs(eta) > 0.9 || pt < 0.1){
411 AliDebug(3,"At least one daughter has eta>0.9 or pt < 0.1 \n");
420 //_____________________________________________________
422 Bool_t AliCFVertexingHF::MCRefitStep(AliAODEvent *aodEvent, AliESDtrackCuts *trackCuts) const
424 // check on the kTPCrefit and kITSrefit conditions of the daughters
425 Bool_t bRefitStep = kTRUE;
427 Int_t label0 = fmcPartCandidate->GetDaughter(0);
428 Int_t label1 = fmcPartCandidate->GetDaughter(1);
430 if (label1==0 || label0 == 0){
431 AliDebug(2, Form("The MC particle doesn't have correct daughters, skipping!!"));
432 AliInfo(Form("The MC particle doesn't have correct daughters, skipping!! **** THIS SHOULD NOT HAPPEN 1"));
436 if (label1 - label0 != fProngs-1){
437 AliDebug(2, Form("The MC particle doesn't come from a %d-prong decay, skipping!!", fProngs));
438 AliInfo(Form("The MC particle doesn't come from a %d-prong decay, skipping!! **** THIS SHOULD NOT HAPPEN 1", fProngs));
442 Int_t foundDaughters = 0;
444 if (trackCuts->GetRequireTPCRefit() || trackCuts->GetRequireITSRefit()){
446 for(Int_t iaod =0; iaod<aodEvent->GetNumberOfTracks(); iaod++){
447 AliAODTrack *track = (AliAODTrack*)aodEvent->GetTrack(iaod);
448 if (track->GetLabel()>= label0 && track->GetLabel()<=label1){
450 printf("daughter %d \n",foundDaughters);
451 if(trackCuts->GetRequireTPCRefit()){
452 if(!(track->GetStatus()&AliESDtrack::kTPCrefit)) {
454 AliDebug(3, "Refit cut not passed , missing TPC refit\n");
455 AliInfo( "Refit cut not passed , missing TPC refit\n");
459 AliDebug(3, "TPC Refit cut passed\n");
460 AliInfo( "TPC Refit cut passed\n");
464 if (trackCuts->GetRequireITSRefit()) {
465 if(!(track->GetStatus()&AliESDtrack::kITSrefit)){
467 AliDebug(3, "Refit cut not passed , missing ITS refit\n");
468 AliInfo("Refit cut not passed , missing ITS refit\n");
472 AliDebug(3, "ITS Refit cut passed\n");
473 AliInfo("ITS Refit cut passed\n");
477 if (foundDaughters == fProngs){
484 if (foundDaughters==fProng) return bRefitStep;
489 //_____________________________________________________
490 Bool_t AliCFVertexingHF::MCRefitStep(AliAODEvent *aodEvent, AliESDtrackCuts *trackCuts) const
493 // check on the kTPCrefit and kITSrefit conditions of the daughters
495 Bool_t bRefitStep = kFALSE;
497 Int_t label0 = fmcPartCandidate->GetDaughter(0);
498 Int_t label1 = fmcPartCandidate->GetDaughter(1);
500 if (label1==0 || label0 == 0){
501 AliDebug(2, Form("The MC particle doesn't have correct daughters, skipping!!"));
505 if (label1 - label0 != fProngs-1){
506 AliDebug(2, Form("The MC particle doesn't come from a %d-prong decay, skipping!!", fProngs));
507 //AliInfo(Form("The MC particle doesn't come from a %d-prong decay, skipping!!", fProngs));
511 Int_t foundDaughters = 0;
513 if (trackCuts->GetRequireTPCRefit() || trackCuts->GetRequireITSRefit()){
515 for(Int_t iaod =0; iaod<aodEvent->GetNumberOfTracks(); iaod++){
516 AliAODTrack *track = (AliAODTrack*)aodEvent->GetTrack(iaod);
517 if (track->GetLabel()>= label0 && track->GetLabel()<=label1){
519 AliDebug(4,Form("daughter %d \n",foundDaughters));
520 if(trackCuts->GetRequireTPCRefit()){
521 if(track->GetStatus()&AliESDtrack::kTPCrefit) {
525 AliDebug(3, "Refit cut not passed , missing TPC refit\n");
530 if (trackCuts->GetRequireITSRefit()) {
531 if(track->GetStatus()&AliESDtrack::kITSrefit){
535 AliDebug(3, "Refit cut not passed , missing ITS refit\n");
540 if (foundDaughters == fProngs){
545 if (foundDaughters== fProngs) return bRefitStep;
549 //____________________________________________________________________________
551 Bool_t AliCFVertexingHF::RecoStep()
554 //check also vertex and ITS Refit and TPC Refit
557 Bool_t bRecoStep = kFALSE;
558 Int_t mcLabel = GetMCLabel();
561 AliDebug(2,"No MC particle found");
565 fmcPartCandidate = (AliAODMCParticle*)fmcArray->At(mcLabel);
566 if (!fmcPartCandidate){
567 AliWarning("Could not find associated MC in AOD MC tree");
572 Int_t pdgGranma = CheckOrigin();
574 if (pdgGranma == -9999){
575 AliDebug(2,"This particle come from a B decay channel but according to the settings of the task, we keep only prompt charm particles\n");
579 if (pdgGranma == -999){
580 AliDebug(2,"This particle come from a prompt charm particle but according to the settings of the task, we want only the ones coming from B\n");
587 //____________________________________________
588 Double_t AliCFVertexingHF::GetEtaProng(Int_t iProng) const
591 // getting eta of the prong
595 Double_t etaProng = fRecoCandidate->EtaProng(iProng);
600 //______________________________________________________
601 Double_t AliCFVertexingHF::GetPtProng(Int_t iProng) const
604 // getting pt of the prong
608 Double_t ptProng = fRecoCandidate->PtProng(iProng);
615 //____________________________________________________________________
617 Bool_t AliCFVertexingHF::RecoAcceptStep(AliESDtrackCuts *trackCuts) const
620 // reco Acceptance step
623 Bool_t bRecoAccStep = kFALSE;
625 Float_t etaCutMin, ptCutMin, etaCutMax, ptCutMax;
626 trackCuts->GetEtaRange(etaCutMin, etaCutMax);
627 trackCuts->GetPtRange(ptCutMin, ptCutMax);
629 Float_t etaProng=0., ptProng=0.;
631 for (Int_t iProng =0; iProng<fProngs; iProng++){
633 etaProng = GetEtaProng(iProng);
634 ptProng = GetPtProng(iProng);
636 Bool_t acceptanceProng = (etaProng>etaCutMin && etaProng<etaCutMax && ptProng>ptCutMin && ptProng<ptCutMax);
637 if (!acceptanceProng) {
638 AliDebug(2,"At least one reconstructed prong isn't in the acceptance\n");
646 //___________________________________________________________
648 Bool_t AliCFVertexingHF::FillUnfoldingMatrix(Double_t *fill) const
651 // filling the unfolding matrix
654 fill = new Double_t[4];
656 if(fmcPartCandidate){
658 fill[0] = GetPtCand();
659 fill[1] = GetYCand();
661 fill[2] = fmcPartCandidate->Pt();
662 fill[3] = fmcPartCandidate->Y();
671 //___________________________________________________________
673 Int_t AliCFVertexingHF::CheckReflexion()
676 // check for reflexion (particle/antiparticle)
679 Int_t mcLabel = GetMCLabel();
682 AliDebug(2,"No MC particle found");
686 fmcPartCandidate = (AliAODMCParticle*)fmcArray->At(mcLabel);
687 if (!fmcPartCandidate){
688 AliWarning("Could not find associated MC in AOD MC tree");
693 if(fmcPartCandidate->GetPdgCode()>0) return 1; // particle
694 else if(fmcPartCandidate->GetPdgCode()<0) return 2; // antiparticle
695 else return 0; // ....shouldn't be...