AliPhysics  95775ff (95775ff)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliAODRecoDecayHF.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2006, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
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  **************************************************************************/
15 
16 /* $Id$ */
17 
19 //
20 // Base class for AOD reconstructed heavy-flavour decay
21 //
22 // Author: A.Dainese, andrea.dainese@lnl.infn.it
24 
25 #include <TDatabasePDG.h>
26 #include <TVector3.h>
27 #include <TRandom.h>
28 #include "AliAODRecoDecay.h"
29 #include "AliAODRecoDecayHF.h"
30 #include "AliAODEvent.h"
31 #include "AliVertexerTracks.h"
32 #include "AliExternalTrackParam.h"
33 #include "AliKFVertex.h"
34 #include "AliVVertex.h"
35 #include "AliESDVertex.h"
36 
40 
41 //--------------------------------------------------------------------------
43  AliAODRecoDecay(),
44  fOwnPrimaryVtx(0x0),
45  fEventPrimaryVtx(),
46  fListOfCuts(),
47  fd0err(0x0),
48  fProngID(0x0),
49  fSelectionMap(0),
50  fIsFilled(1)
51 {
52  //
53  // Default Constructor
54  //
55 }
56 //--------------------------------------------------------------------------
58  Double_t *px,Double_t *py,Double_t *pz,
59  Double_t *d0,Double_t *d0err) :
60  AliAODRecoDecay(vtx2,nprongs,charge,px,py,pz,d0),
61  fOwnPrimaryVtx(0x0),
62  fEventPrimaryVtx(),
63  fListOfCuts(),
64  fd0err(0x0),
65  fProngID(0x0),
66  fSelectionMap(0),
67  fIsFilled(1)
68 {
69  //
70  // Constructor with AliAODVertex for decay vertex
71  //
72  fd0err = new Double_t[GetNProngs()];
73  for(Int_t i=0; i<GetNProngs(); i++) fd0err[i] = d0err[i];
74 }
75 //--------------------------------------------------------------------------
77  Double_t *d0,Double_t *d0err) :
78  AliAODRecoDecay(vtx2,nprongs,charge,d0),
79  fOwnPrimaryVtx(0x0),
80  fEventPrimaryVtx(),
81  fListOfCuts(),
82  fd0err(0x0),
83  fProngID(0x0),
84  fSelectionMap(0),
85  fIsFilled(1)
86 {
87  //
88  // Constructor with AliAODVertex for decay vertex and without prongs momenta
89  //
90  fd0err = new Double_t[GetNProngs()];
91  for(Int_t i=0; i<GetNProngs(); i++) fd0err[i] = d0err[i];
92 }
93 //--------------------------------------------------------------------------
95  Int_t nprongs,Short_t charge,
96  Double_t *px,Double_t *py,Double_t *pz,
97  Double_t *d0) :
98  AliAODRecoDecay(0x0,nprongs,charge,px,py,pz,d0),
99  fOwnPrimaryVtx(0x0),
100  fEventPrimaryVtx(),
101  fListOfCuts(),
102  fd0err(0x0),
103  fProngID(0x0),
104  fSelectionMap(0),
105  fIsFilled(1)
106 {
107  //
108  // Constructor that can used for a "MC" object
109  //
110 
111  fOwnPrimaryVtx = new AliAODVertex(vtx1);
112 
113  AliAODVertex *vtx = new AliAODVertex(vtx2);
114  SetOwnSecondaryVtx(vtx);
115 
116 }
117 //--------------------------------------------------------------------------
119  AliAODRecoDecay(source),
120  fOwnPrimaryVtx(0x0),
121  fEventPrimaryVtx(source.fEventPrimaryVtx),
122  fListOfCuts(source.fListOfCuts),
123  fd0err(0x0),
124  fProngID(0x0),
125  fSelectionMap(source.fSelectionMap),
126  fIsFilled(source.fIsFilled)
127 {
128  //
129  // Copy constructor
130  //
131  if(source.GetOwnPrimaryVtx()) fOwnPrimaryVtx = new AliAODVertex(*(source.GetOwnPrimaryVtx()));
132 
133  if(source.GetNProngs()>0) {
134  fd0err = new Double_t[GetNProngs()];
135  memcpy(fd0err,source.fd0err,GetNProngs()*sizeof(Double_t));
136  if(source.fProngID) {
137  fProngID = new UShort_t[GetNProngs()];
138  memcpy(fProngID,source.fProngID,GetNProngs()*sizeof(UShort_t));
139  }
140  }
141 }
142 //--------------------------------------------------------------------------
144 {
145  //
146  // assignment operator
147  //
148  if(&source == this) return *this;
149 
150  AliAODRecoDecay::operator=(source);
151 
153  fListOfCuts = source.fListOfCuts;
154  fSelectionMap = source.fSelectionMap;
155  fIsFilled=source.fIsFilled;
156 
157  if(source.GetOwnPrimaryVtx()) {
158  delete fOwnPrimaryVtx;
159  fOwnPrimaryVtx = new AliAODVertex(*(source.GetOwnPrimaryVtx()));
160  }
161 
162  if(source.GetNProngs()>0) {
163  if(source.fd0err) {
164  delete [] fd0err;
165  fd0err = new Double_t[GetNProngs()];
166  memcpy(fd0err,source.fd0err,GetNProngs()*sizeof(Double_t));
167  }
168  if(source.fProngID) {
169  delete [] fProngID;
170  fProngID = new UShort_t[GetNProngs()];
171  memcpy(fProngID,source.fProngID,GetNProngs()*sizeof(UShort_t));
172  }
173  }
174  return *this;
175 }
176 //--------------------------------------------------------------------------
178  //
179  // Default Destructor
180  //
181  if(fOwnPrimaryVtx) delete fOwnPrimaryVtx;
182  if(fd0err) delete [] fd0err;
183  if(fProngID) delete [] fProngID;
184 }
185 //---------------------------------------------------------------------------
186 AliKFParticle *AliAODRecoDecayHF::ApplyVertexingKF(Int_t *iprongs,Int_t nprongs,Int_t *pdgs,Bool_t topoCostraint, Double_t bzkG, Double_t *mass) const {
187  //
188  // Applies the KF vertexer
189  // Int_t iprongs[nprongs] = indices of the prongs to be used from the vertexer
190  // Int_t pdgs[nprongs] = pdgs assigned to the prongs, needed to define the AliKFParticle
191  // Bool_t topoCostraint = if kTRUE, the topological constraint is applied
192  // Double_t bzkG = magnetic field
193  // Double_t mass[2] = {mass, sigma} for the mass constraint (if mass[0]>0 the constraint is applied).
194  //
195 
196  AliKFParticle::SetField(bzkG);
197  AliKFParticle *vertexKF=0;
198 
199  AliKFVertex copyKF;
200  Int_t nt=0,ntcheck=0;
201 
202  Double_t pos[3]={0.,0.,0.};
203  if(!fOwnPrimaryVtx) {
204  printf("AliAODRecoDecayHF::ApplyVertexingKF(): cannot apply because primary vertex is not found\n");
205  return vertexKF;
206  }
207  fOwnPrimaryVtx->GetXYZ(pos);
208  Int_t contr=fOwnPrimaryVtx->GetNContributors();
209  Double_t covmatrix[6]={0.,0.,0.,0.,0.,0.};
210  fOwnPrimaryVtx->GetCovarianceMatrix(covmatrix);
211  Double_t chi2=fOwnPrimaryVtx->GetChi2();
212  AliESDVertex primaryVtx2(pos,covmatrix,chi2,contr,"Vertex");
213 
214 
215  if(topoCostraint){
216  copyKF=AliKFVertex(primaryVtx2);
217  nt=primaryVtx2.GetNContributors();
218  ntcheck=nt;
219  }
220 
221  vertexKF = new AliKFParticle();
222  for(Int_t i= 0;i<nprongs;i++){
223  Int_t ipr=iprongs[i];
224  AliAODTrack *aodTrack = (AliAODTrack*)GetDaughter(ipr);
225  if(!aodTrack) {
226  printf("AliAODRecoDecayHF::ApplyVertexingKF(): no daughters available\n");
227  delete vertexKF; vertexKF=NULL;
228  return vertexKF;
229  }
230  AliKFParticle daughterKF(*aodTrack,pdgs[i]);
231  vertexKF->AddDaughter(daughterKF);
232 
233  if(topoCostraint && nt>0){
234  //Int_t index=(Int_t)GetProngID(ipr);
235  if(!aodTrack->GetUsedForPrimVtxFit()) continue;
236  copyKF -= daughterKF;
237  ntcheck--;
238  }
239  }
240 
241  if(topoCostraint){
242  if(ntcheck>0) {
243  copyKF += (*vertexKF);
244  vertexKF->SetProductionVertex(copyKF);
245  }
246  }
247 
248  if(mass[0]>0.){
249  vertexKF->SetMassConstraint(mass[0],mass[1]);
250  }
251 
252  return vertexKF;
253 }
254 //---------------------------------------------------------------------------
256  //
257  // This method returns a primary vertex without the daughter tracks of the
258  // candidate and it recalculates the impact parameters and errors.
259  //
260  // The output vertex is created with "new". The user has to
261  // set it to the candidate with SetOwnPrimaryVtx(), unset it at the end
262  // of processing with UnsetOwnPrimaryVtx() and delete it.
263  // If a NULL pointer is returned, the removal failed (too few tracks left).
264  //
265  // For the moment, the primary vertex is recalculated from scratch without
266  // the daughter tracks.
267  //
268 
269  AliAODVertex *vtxAOD = aod->GetPrimaryVertex();
270  if(!vtxAOD) return 0;
271  TString title=vtxAOD->GetTitle();
272  if(!title.Contains("VertexerTracks")) return 0;
273 
274 
275 
276  AliVertexerTracks *vertexer = new AliVertexerTracks(aod->GetMagneticField());
277 
278  Int_t ndg = GetNDaughters();
279 
280  vertexer->SetITSMode();
281  vertexer->SetMinClusters(3);
282  vertexer->SetConstraintOff();
283 
284  if(title.Contains("WithConstraint")) {
285  Float_t diamondcovxy[3];
286  aod->GetDiamondCovXY(diamondcovxy);
287  Double_t pos[3]={aod->GetDiamondX(),aod->GetDiamondY(),0.};
288  Double_t cov[6]={diamondcovxy[0],diamondcovxy[1],diamondcovxy[2],0.,0.,10.*10.};
289  AliESDVertex *diamond = new AliESDVertex(pos,cov,1.,1);
290  vertexer->SetVtxStart(diamond);
291  delete diamond; diamond=NULL;
292  }
293 
294  Int_t skipped[10]; for(Int_t i=0;i<10;i++) skipped[i]=-1;
295  Int_t nTrksToSkip=0,id;
296  AliAODTrack *t = 0;
297  for(Int_t i=0; i<ndg; i++) {
298  t = (AliAODTrack*)GetDaughter(i);
299  id = (Int_t)t->GetID();
300  if(id<0) continue;
301  skipped[nTrksToSkip++] = id;
302  }
303 
304  vertexer->SetSkipTracks(nTrksToSkip,skipped);
305  AliESDVertex *vtxESDNew = vertexer->FindPrimaryVertex(aod);
306 
307  delete vertexer; vertexer=NULL;
308 
309  if(!vtxESDNew) return 0;
310  if(vtxESDNew->GetNContributors()<=0) {
311  delete vtxESDNew; vtxESDNew=NULL;
312  return 0;
313  }
314 
315  // convert to AliAODVertex
316  Double_t pos[3],cov[6],chi2perNDF;
317  vtxESDNew->GetXYZ(pos); // position
318  vtxESDNew->GetCovMatrix(cov); //covariance matrix
319  chi2perNDF = vtxESDNew->GetChi2toNDF();
320  delete vtxESDNew; vtxESDNew=NULL;
321 
322  AliAODVertex *vtxAODNew = new AliAODVertex(pos,cov,chi2perNDF);
323 
324  RecalculateImpPars(vtxAODNew,aod);
325 
326  return vtxAODNew;
327 }
328 //-----------------------------------------------------------------------------------
329 void AliAODRecoDecayHF::RecalculateImpPars(AliAODVertex *vtxAODNew,AliAODEvent* aod) {
330  //
331  // now recalculate the daughters impact parameters
332  //
333  Double_t dz[2],covdz[3];
334  for(Int_t i=0; i<GetNDaughters(); i++) {
335  AliAODTrack *t = (AliAODTrack*)GetDaughter(i);
336  AliExternalTrackParam etp; etp.CopyFromVTrack(t);
337  if(etp.PropagateToDCA(vtxAODNew,aod->GetMagneticField(),3.,dz,covdz)) {
338  fd0[i] = dz[0];
339  fd0err[i] = TMath::Sqrt(covdz[0]);
340  }
341  }
342 
343  return;
344 }
345 //-----------------------------------------------------------------------------------
347  //
348  // Method to smear the impact parameter of the duaghter tracks
349  // and the sec. vtx position accordinlgy
350  // Useful to study effect of misalignment.
351  // The starting point are parameterisations of the impact parameter resolution
352  // from MC and data
353  // Errors on d0 and vtx are not recalculated (to be done)
354  //
355  if(misal=="null")return;
356  Double_t pard0rphiMC[3]={36.7,36.,1.25};// d0(pt)=[0]+[1]/(pt^[2]); in micron, conversion to cm is done later
357  Double_t pard0rphimisal[3]={0,0,0};
358  Double_t pard0zMC[3]={85.,130.,0.7};// d0(pt)=[0]+[1]/(pt^[2]); in micron, conversion to cm is done later
359  Double_t pard0zmisal[3]={0,0,0};
360  if(misal=="data") {
361  //use this to reproduce data d0(pt) trend for pions
362  pard0rphimisal[0]=37.;
363  pard0rphimisal[1]=37.5;
364  pard0rphimisal[2]=1.25;
365  pard0zmisal[0]=96.;
366  pard0zmisal[1]=131.;
367  pard0zmisal[2]=0.7;
368  }
369  else if(misal=="resB") {
370  // temporary values: asymptotic value larger by a factor 1.2 w.r.t. MC
371  pard0rphimisal[0]=44.4;
372  pard0rphimisal[1]=37.5;
373  pard0rphimisal[2]=1.25;
374  pard0zmisal[0]=115.2;
375  pard0zmisal[1]=131.;
376  pard0zmisal[2]=0.7;
377  }
378  else if(misal=="resC") {
379  // temporary values: slightly larger asymptotic value, larger values at low pt
380  pard0rphimisal[0]=40.;
381  pard0rphimisal[1]=40.;
382  pard0rphimisal[2]=1.3;
383  pard0zmisal[0]=125.;
384  pard0zmisal[1]=131.;
385  pard0zmisal[2]=0.85;
386  }
387  else printf("AliAODRecoDecayHF::Misalign(): wrong misalign type specified \n");
388 
389 
390  AliAODVertex *evVtx=0x0,*secVtx=0x0;
391  Double_t evVtxPos[3]={-9999.,-9999.,-9999.},secVtxPos[3]={-9999.,9999.,9999.};
392  if(fOwnPrimaryVtx)fOwnPrimaryVtx->GetXYZ(evVtxPos);
393  else {
394  evVtx=(AliAODVertex*)(fEventPrimaryVtx.GetObject());
395  evVtx->GetXYZ(evVtxPos);
396  }
397  secVtx=(AliAODVertex*)GetSecondaryVtx();
398  secVtx->GetXYZ(secVtxPos);
399 
400  TVector3 v2v1(secVtxPos[0]-evVtxPos[0],secVtxPos[1]-evVtxPos[1],0.);
401 
402  Double_t sigmarphinull,sigmarphimisal,sigmarphiadd;
403  Double_t sigmaznull,sigmazmisal,sigmazadd;
404  Double_t deltad0rphi[10],deltad0z[10];
405 
406  // loop on the two prongs
407  for(Int_t i=0; i<fNProngs; i++) {
408  sigmarphinull = pard0rphiMC[0]+pard0rphiMC[1]/TMath::Power(PtProng(i),pard0rphiMC[2]);
409  sigmarphimisal = pard0rphimisal[0]+pard0rphimisal[1]/TMath::Power(PtProng(i),pard0rphimisal[2]);
410  if(sigmarphimisal>sigmarphinull) {
411  sigmarphiadd = TMath::Sqrt(sigmarphimisal*sigmarphimisal-
412  sigmarphinull*sigmarphinull);
413  deltad0rphi[i] = gRandom->Gaus(0.,sigmarphiadd);
414  } else {
415  deltad0rphi[i] = 0.;
416  }
417 
418  sigmaznull = pard0zMC[0]+pard0zMC[1]/TMath::Power(PtProng(i),pard0zMC[2]);
419  sigmazmisal = pard0zmisal[0]+pard0zmisal[1]/TMath::Power(PtProng(i),pard0zmisal[2]);
420  if(sigmazmisal>sigmaznull) {
421  sigmazadd = TMath::Sqrt(sigmazmisal*sigmazmisal-
422  sigmaznull*sigmaznull);
423  deltad0z[i] = gRandom->Gaus(0.,sigmazadd);
424  } else {
425  deltad0z[i] = 0.;
426  }
427 
428  TVector3 pxy(fPx[i],fPy[i],0.);
429  TVector3 pxycrossv2v1=pxy.Cross(v2v1);
430  if( pxycrossv2v1.Z()*fd0[i] > 0 ) {
431  secVtxPos[0]+=1.e-4*deltad0rphi[i]*(-fPy[i])/PtProng(i);// e-4: conversion to cm
432  secVtxPos[1]+=1.e-4*deltad0rphi[i]*(+fPx[i])/PtProng(i);
433  } else {
434  secVtxPos[0]+=1.e-4*deltad0rphi[i]*(+fPy[i])/PtProng(i);
435  secVtxPos[1]+=1.e-4*deltad0rphi[i]*(-fPx[i])/PtProng(i);
436  }
437 
438  // change d0rphi
439  fd0[i] += 1.e-4*deltad0rphi[i]; // e-4: conversion to cm
440  // change secondary vertex z
441  secVtxPos[2]+=0.5e-4*deltad0z[i];
442  }
443  secVtx->SetX(secVtxPos[0]);
444  secVtx->SetY(secVtxPos[1]);
445  secVtx->SetZ(secVtxPos[2]);
446 
447  return;
448 }
449 //-----------------------------------------------------------------------------------
451  // compute the difference between measured and expected track impact parameter
452 
453  Double_t d0meas=Getd0Prong(ip);
454  Double_t errd0meas=Getd0errProng(ip);
455  Double_t lxy=DecayLengthXY();
456  AliAODVertex* secVtx=(AliAODVertex*)GetSecondaryVtx();
457  Double_t errlxy2=secVtx->Error2DistanceXYToVertex(GetPrimaryVtx());
458 
459  AliAODTrack *trk = (AliAODTrack*)GetDaughter(ip);
460  AliExternalTrackParam etp;
461  etp.CopyFromVTrack(trk);
462  Double_t dz[2],dtrkcovar[3];
463  etp.PropagateToDCA(secVtx,magf,3.,dz,dtrkcovar);
464  Double_t pxt=etp.Px();
465  Double_t pyt=etp.Py();
466  Double_t sinThetap=(pxt*Py()-pyt*Px())/(Pt()*PtProng(ip));
467  diff=d0meas-lxy*sinThetap;
468  errdiff=TMath::Sqrt(errd0meas*errd0meas+errlxy2*sinThetap*sinThetap);
469 }
470 //_____________________________
472  // Delete data members to reduce the size of AliAOD.VertexingHF.root
473  // They will be recomputed at the analysis level
474  AliAODRecoDecay::DeleteRecoD();// delete data members of AliAODRecoDecay
475  if(fOwnPrimaryVtx) {delete fOwnPrimaryVtx; fOwnPrimaryVtx=NULL;}
476  if(fd0err) {
477  delete [] fd0err;fd0err=NULL;
478  }
479  SetIsFilled(0);
480 
481  return;
482 }
Int_t charge
Double_t * fd0err
error on prongs rphi impact param [cm]
AliAODRecoDecayHF & operator=(const AliAODRecoDecayHF &source)
double Double_t
Definition: External.C:58
void Getd0MeasMinusExpProng(Int_t ip, Double_t magf, Double_t &d0diff, Double_t &errd0diff) const
const char * title
Definition: MakeQAPdf.C:26
AliAODVertex * fOwnPrimaryVtx
TPC+ITS tracks not passing the StandardCuts2010 with loose DCA.
Double_t mass
Int_t fIsFilled
used to store outcome of selection in AliAnalysisVertexingHF
virtual void DeleteRecoD()
TRandom * gRandom
void RecalculateImpPars(AliAODVertex *vtxAODNew, AliAODEvent *aod)
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
AliAODVertex * GetOwnPrimaryVtx() const
Double_t Getd0errProng(Int_t ip) const
prongs
UShort_t * fProngID
track ID of daughters
AliAODVertex * RemoveDaughtersFromPrimaryVtx(AliAODEvent *aod)
void Misalign(TString misal="null")
misalign
short Short_t
Definition: External.C:23
Double_t DecayLengthXY() const
TRef fEventPrimaryVtx
primary vertex for this candidate
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
TRef fListOfCuts
ref to primary vertex of the event
unsigned short UShort_t
Definition: External.C:28
AliAODVertex * GetPrimaryVtx() const
AliKFParticle * ApplyVertexingKF(Int_t *iprongs, Int_t nprongs, Int_t *pdgs, Bool_t topoCostraint, Double_t bzkG, Double_t *mass) const
vertexing KF:
bool Bool_t
Definition: External.C:53
void SetIsFilled(Int_t filled)