]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/RESONANCES/AliRsnMiniParticle.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / AliRsnMiniParticle.cxx
1 //
2 // This object is used as lightweight temporary container
3 // of all information needed from any input object and
4 // useful for resonance analysis.
5 // Lists of such objects are stored in a buffer, in order
6 // to allow an event mixing.
7 //
8
9 #include <TDatabasePDG.h>
10 #include <TParticlePDG.h>
11
12 #include "AliAODEvent.h"
13 #include "AliMCEvent.h"
14 #include "AliRsnEvent.h"
15 #include "AliRsnMiniEvent.h"
16 #include "AliRsnMiniParticle.h"
17
18 ClassImp(AliRsnMiniParticle)
19
20 //__________________________________________________________________________________________________
21 void AliRsnMiniParticle::CopyDaughter(AliRsnDaughter *daughter)
22 {
23 //
24 // Sets data members from the passed object
25 //
26
27    // reset what could not be initialized
28    fDCA = 0.0;  //typically used for D0 analysis
29    fPDG = 0;
30    fMother = -1;
31    fMotherPDG = 0;
32    fNTotSisters = -1;
33    fIsFromB = kFALSE;
34    fIsQuarkFound = kFALSE;
35    fCutBits = 0x0;
36    fPsim[0] = fPrec[0] = fPmother[0] = fPsim[1] = fPrec[1] = fPmother[1] = fPsim[2] = fPrec[2] = fPmother[2] = 0.0;
37
38    // charge
39    if (daughter->IsPos())
40       fCharge = '+';
41    else if (daughter->IsNeg())
42       fCharge = '-';
43    else
44       fCharge = '0';
45
46    // rec info
47    if (daughter->GetRef()) {
48       fPrec[0] = daughter->GetRef()->Px();
49       fPrec[1] = daughter->GetRef()->Py();
50       fPrec[2] = daughter->GetRef()->Pz();
51    }
52
53    // MC info
54    if (daughter->GetRefMC()) {
55       fPsim[0] = daughter->GetRefMC()->Px();
56       fPsim[1] = daughter->GetRefMC()->Py();
57       fPsim[2] = daughter->GetRefMC()->Pz();
58       fPDG = daughter->GetPDG();
59       fMother = daughter->GetMother();
60       fMotherPDG = daughter->GetMotherPDG();
61    }
62    
63    AliRsnEvent *event = (AliRsnEvent *) daughter->GetOwnerEvent();
64    if (!event) {
65      AliWarning("Invalid reference event: cannot copy DCA nor Nsisters.");
66      return;
67    }
68    if (event->IsAOD()){
69      // DCA to Primary Vertex for AOD
70      AliAODTrack *track = (AliAODTrack*) daughter->Ref2AODtrack();   
71      AliAODEvent *aodEvent = (AliAODEvent*) event->GetRefAOD();
72      if (track && aodEvent) {
73        AliVVertex *vertex = (AliVVertex*) aodEvent->GetPrimaryVertex();
74        Double_t b[2], cov[3]; 
75        if (vertex) {
76          if ( !((track->GetStatus() & AliESDtrack::kTPCin) == 0) && !((track->GetStatus() & AliESDtrack::kTPCrefit) == 0) && !((track->GetStatus() & AliESDtrack::kITSrefit) == 0) ){
77            if (track->PropagateToDCA(vertex, aodEvent->GetMagneticField(), kVeryBig, b, cov))
78              fDCA = b[0];
79          }
80        }
81      }
82      // Number of Daughters from MC and Momentum of the Mother
83      if (event->GetRefMC()) {
84        TClonesArray * list = event->GetAODList();
85        AliAODMCParticle *part = (AliAODMCParticle *)list->At(fMother);
86        if (part) {
87          fNTotSisters = part->GetNDaughters();
88          fPmother[0]  = part->Px();
89          fPmother[1]  = part->Py();
90          fPmother[2]  = part->Pz();
91          Int_t istep = 0;
92          Int_t pdgGranma = 0;
93          Int_t abspdgGranma =0;
94          Int_t mother_temp = daughter->GetMother();
95          while (mother_temp >=0 ){
96                istep++;
97                AliDebug(2,Form("mother at step %d = %d", istep, mother_temp));
98                AliAODMCParticle* mcGranma = dynamic_cast<AliAODMCParticle*>(list->At(mother_temp));
99                if (mcGranma){
100                        pdgGranma = mcGranma->GetPdgCode();
101                        AliDebug(2,Form("Pdg mother at step %d = %d", istep, pdgGranma));
102                        abspdgGranma = TMath::Abs(pdgGranma);
103                        if ((abspdgGranma > 500 && abspdgGranma < 600) || (abspdgGranma > 5000 && abspdgGranma < 6000)){
104                          fIsFromB=kTRUE;
105                        }
106                        if(abspdgGranma==4 || abspdgGranma==5) fIsQuarkFound=kTRUE;
107                        mother_temp = mcGranma->GetMother();
108                }else{
109                        AliError("Failed casting the mother particle!");
110                        break;
111                }
112          }
113        }
114      }
115    } else {
116      if (event->IsESD()){
117        //DCA to Primary Vertex for ESD
118        AliESDtrack *track = (AliESDtrack*) daughter->Ref2ESDtrack();   
119        AliESDEvent *esdEvent = (AliESDEvent*) event->GetRefESD();
120        if (track && esdEvent) {
121          AliVVertex *vertex = (AliVVertex*) esdEvent->GetPrimaryVertex();
122          Double_t b[2], cov[3]; 
123          if (vertex) {
124            if ( !((track->GetStatus() & AliESDtrack::kTPCin) == 0) && !((track->GetStatus() & AliESDtrack::kTPCrefit) == 0) && !((track->GetStatus() & AliESDtrack::kITSrefit) == 0) ){
125              if (track->PropagateToDCA(vertex, esdEvent->GetMagneticField(), kVeryBig, b, cov))
126                fDCA = b[0];
127            }
128          }
129        }
130        // Number of Daughters from MC and Momentum of the Mother
131        if (event->GetRefMC()) {
132          AliMCParticle *part = (AliMCParticle *)event->GetRefMC()->GetTrack(fMother);
133          AliMCEvent * MCEvent = event->GetRefMCESD();
134          if(part){
135            fNTotSisters = part->Particle()->GetNDaughters();
136            fPmother[0]  = part->Px();
137            fPmother[1]  = part->Py();
138            fPmother[2]  = part->Pz();
139            Int_t istep = 0;
140            Int_t pdgGranma = 0;
141            Int_t abspdgGranma =0;
142            Int_t mother_temp = daughter->GetMother();
143            while (mother_temp >=0 ){
144                  istep++;
145                  AliDebug(2,Form("mother at step %d = %d", istep, mother_temp));
146                  AliMCParticle* mcGranma = dynamic_cast<AliMCParticle*>(MCEvent->GetTrack(mother_temp));
147                  if (mcGranma){
148                          pdgGranma = mcGranma->PdgCode();
149                          AliDebug(2,Form("Pdg mother at step %d = %d", istep, pdgGranma));
150                          abspdgGranma = TMath::Abs(pdgGranma);
151                          if ((abspdgGranma > 500 && abspdgGranma < 600) || (abspdgGranma > 5000 && abspdgGranma < 6000)){
152                            fIsFromB=kTRUE;
153                          }
154                          if(abspdgGranma==4 || abspdgGranma==5) fIsQuarkFound=kTRUE;
155                          mother_temp = mcGranma->GetMother();
156                  }else{
157                          AliError("Failed casting the mother particle!");
158                          break;
159                  }
160            }
161          }
162        }
163      }
164    }
165 }
166
167 //__________________________________________________________________________________________________
168 Double_t AliRsnMiniParticle::Mass()
169 {
170    //
171    // return mass of particle
172    //
173
174    TDatabasePDG *db   = TDatabasePDG::Instance();
175    TParticlePDG *part = db->GetParticle(PDG());
176    return part->Mass();
177 }
178
179 //__________________________________________________________________________________________________
180 void AliRsnMiniParticle::Set4Vector(TLorentzVector &v, Float_t mass, Bool_t mc)
181 {
182    //
183    // return 4 vector of particle
184    //
185
186    if (mass<0.0) mass = Mass();
187    v.SetXYZM(Px(mc), Py(mc), Pz(mc),mass);
188 }