]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliV0vertexer.cxx
Mixtures instead of materials with fractional Z in SPD (SPD bus and SPD end ladder
[u/mrichter/AliRoot.git] / ITS / AliV0vertexer.cxx
index 207648f6853498310975a02b4157658966284b14..9e7c23d125066b32a3ac5bbb54fc674379ee80ee 100644 (file)
 
 //-------------------------------------------------------------------------
 //               Implementation of the V0 vertexer class
-//
+//                  reads tracks writes out V0 vertices
+//                      fills the ESD with the V0s       
 //     Origin: Iouri Belikov, IReS, Strasbourg, Jouri.Belikov@cern.ch
 //-------------------------------------------------------------------------
-#include <Riostream.h>
-#include <TFile.h>
-#include <TPDGCode.h>
 #include <TObjArray.h>
 #include <TTree.h>
 
+#include "AliESD.h"
+#include "AliESDtrack.h"
 #include "AliITStrackV2.h"
 #include "AliV0vertex.h"
 #include "AliV0vertexer.h"
 
 ClassImp(AliV0vertexer)
 
-Int_t AliV0vertexer::Tracks2V0vertices(const TFile *inp, TFile *out) {
+Int_t AliV0vertexer::Tracks2V0vertices(AliESD *event) {
   //--------------------------------------------------------------------
   //This function reconstructs V0 vertices
   //--------------------------------------------------------------------
-   TFile *in=(TFile*)inp;
-   TDirectory *savedir=gDirectory; 
 
-   if (!in->IsOpen()) {
-     cerr<<"AliV0vertexer::Tracks2V0vertices(): ";
-     cerr<<"file with ITS tracks has not been open !\n";
-     return 1;
-   }
+   Int_t nentr=event->GetNumberOfTracks();
+
+   TObjArray negtrks(nentr/2);
+   TObjArray postrks(nentr/2);
+
+   Int_t nneg=0, npos=0, nvtx=0;
+
+   Int_t i;
+   for (i=0; i<nentr; i++) {
+     AliESDtrack *esd=event->GetTrack(i);
+     UInt_t status=esd->GetStatus();
+     UInt_t flags=AliESDtrack::kITSin|AliESDtrack::kTPCin|
+                  AliESDtrack::kTPCpid|AliESDtrack::kESDpid;
+
+     if ((status&AliESDtrack::kITSrefit)==0)
+        if (flags!=status) continue;
+
+     AliITStrackV2 *iotrack=new AliITStrackV2(*esd);
+     iotrack->SetLabel(i);  // now it is the index in array of ESD tracks
+     if ((status&AliESDtrack::kITSrefit)==0)   //correction for the beam pipe
+        if (!iotrack->PropagateTo(3.,0.0023,65.19)) {
+         delete iotrack;
+         continue;
+       }
+     if (!iotrack->PropagateTo(2.5,0.,0.)) {
+       delete iotrack;
+       continue;
+     }
+
+     if (iotrack->Get1Pt() < 0.) {nneg++; negtrks.AddLast(iotrack);}
+     else {npos++; postrks.AddLast(iotrack);}
+   }   
+
+
+   for (i=0; i<nneg; i++) {
+      //if (i%10==0) cerr<<nneg-i<<'\r';
+      AliITStrackV2 *ntrk=(AliITStrackV2 *)negtrks.UncheckedAt(i);
+
+      if (TMath::Abs(ntrk->GetD(fX,fY))<fDPmin) continue;
+      if (TMath::Abs(ntrk->GetD(fX,fY))>fRmax) continue;
+
+      for (Int_t k=0; k<npos; k++) {
+         AliITStrackV2 *ptrk=(AliITStrackV2 *)postrks.UncheckedAt(k);
 
-   if (!out->IsOpen()) {
-     cerr<<"AliV0vertexer::Tracks2V0vertices(): ";
-     cerr<<"file for V0 vertices has not been open !\n";
-     return 2;
+         if (TMath::Abs(ptrk->GetD(fX,fY))<fDPmin) continue;
+         if (TMath::Abs(ptrk->GetD(fX,fY))>fRmax) continue;
+
+         if (TMath::Abs(ntrk->GetD(fX,fY))<fDNmin)
+         if (TMath::Abs(ptrk->GetD(fX,fY))<fDNmin) continue;
+
+
+         AliITStrackV2 nt(*ntrk), pt(*ptrk), *pnt=&nt, *ppt=&pt;
+
+         Double_t dca=PropagateToDCA(pnt,ppt);
+         if (dca > fDCAmax) continue;
+
+         AliV0vertex vertex(*pnt,*ppt);
+         if (vertex.GetChi2() > fChi2max) continue;
+        
+         /*  Think of something better here ! 
+         nt.PropagateToVertex(); if (TMath::Abs(nt.GetZ())<0.04) continue;
+         pt.PropagateToVertex(); if (TMath::Abs(pt.GetZ())<0.04) continue;
+        */
+
+         Double_t x,y,z; vertex.GetXYZ(x,y,z); 
+         Double_t r2=x*x + y*y; 
+         if (r2 > fRmax*fRmax) continue;
+         if (r2 < fRmin*fRmin) continue;
+
+         Double_t px,py,pz; vertex.GetPxPyPz(px,py,pz);
+         Double_t p2=px*px+py*py+pz*pz;
+         Double_t cost=((x-fX)*px + (y-fY)*py + (z-fZ)*pz)/
+               TMath::Sqrt(p2*((x-fX)*(x-fX) + (y-fY)*(y-fY) + (z-fZ)*(z-fZ)));
+
+        //if (cost < (5*fCPAmax-0.9-TMath::Sqrt(r2)*(fCPAmax-1))/4.1) continue;
+         if (cost < fCPAmax) continue;
+        vertex.SetDcaDaughters(dca);
+         //vertex.ChangeMassHypothesis(); //default is Lambda0 
+
+         event->AddV0(&vertex);
+
+         nvtx++;
+      }
    }
 
-   in->cd();
+   Info("Tracks2V0vertices","Number of reconstructed V0 vertices: %d",nvtx);
+
+   negtrks.Delete();
+   postrks.Delete();
 
-   Char_t name[100];
-   sprintf(name,"TreeT_ITS_%d",fEventN);
-   TTree *trkTree=(TTree*)in->Get(name);
-   TBranch *branch=trkTree->GetBranch("tracks");
-   Int_t nentr=(Int_t)trkTree->GetEntries();
+   return 0;
+}
+
+Int_t AliV0vertexer::Tracks2V0vertices(TTree *tTree, TTree *vTree) {
+  //--------------------------------------------------------------------
+  //This function reconstructs V0 vertices
+  //--------------------------------------------------------------------
+  Warning("Tracks2V0vertices(TTree*,TTree*)",
+         "Will be removed soon !  Use Tracks2V0vertices(AliESD*) instead");
+
+   TBranch *branch=tTree->GetBranch("tracks");
+   if (!branch) {
+      Error("Tracks2V0vertices","Can't get the branch !");
+      return 1;
+   }
+   Int_t nentr=(Int_t)tTree->GetEntries();
 
    TObjArray negtrks(nentr/2);
    TObjArray postrks(nentr/2);
@@ -66,24 +151,30 @@ Int_t AliV0vertexer::Tracks2V0vertices(const TFile *inp, TFile *out) {
    for (i=0; i<nentr; i++) {
        AliITStrackV2 *iotrack=new AliITStrackV2;
        branch->SetAddress(&iotrack);
-       trkTree->GetEvent(i);
+       tTree->GetEvent(i);
 
-       iotrack->PropagateTo(3.,0.0023,65.19); iotrack->PropagateTo(2.5,0.,0.);
+       if (!iotrack->PropagateTo(3.,0.0023,65.19)) {
+        delete iotrack;
+        continue; 
+       }
+       if (!iotrack->PropagateTo(2.5,0.,0.)) {
+        delete iotrack;
+        continue;
+       }
 
        if (iotrack->Get1Pt() > 0.) {nneg++; negtrks.AddLast(iotrack);}
        else {npos++; postrks.AddLast(iotrack);}
    }   
 
 
-   out->cd();
-   sprintf(name,"TreeV%d",fEventN);
-   TTree vtxTree(name,"Tree with V0 vertices");
    AliV0vertex *ioVertex=0;
-   vtxTree.Branch("vertices","AliV0vertex",&ioVertex,32000,0);
+   branch=vTree->GetBranch("vertices");
+   if (!branch) vTree->Branch("vertices","AliV0vertex",&ioVertex,32000,3);
+   else branch->SetAddress(&ioVertex);
 
 
    for (i=0; i<nneg; i++) {
-      if (i%10==0) cerr<<nneg-i<<'\r';
+      //if (i%10==0) cerr<<nneg-i<<'\r';
       AliITStrackV2 *ntrk=(AliITStrackV2 *)negtrks.UncheckedAt(i);
 
       if (TMath::Abs(ntrk->GetD(fX,fY))<fDPmin) continue;
@@ -120,175 +211,34 @@ Int_t AliV0vertexer::Tracks2V0vertices(const TFile *inp, TFile *out) {
          Double_t px,py,pz; vertex.GetPxPyPz(px,py,pz);
          Double_t p2=px*px+py*py+pz*pz;
          Double_t cost=((x-fX)*px + (y-fY)*py + (z-fZ)*pz)/
-                TMath::Sqrt(p2*((x-fX)*(x-fX) + (y-fY)*(y-fY) + (z-fZ)*(z-fZ)));
+               TMath::Sqrt(p2*((x-fX)*(x-fX) + (y-fY)*(y-fY) + (z-fZ)*(z-fZ)));
 
-         //if (cost < (5*fCPAmax-0.9-TMath::Sqrt(r2)*(fCPAmax-1))/4.1) continue;
+        //if (cost < (5*fCPAmax-0.9-TMath::Sqrt(r2)*(fCPAmax-1))/4.1) continue;
          if (cost < fCPAmax) continue;
-
+        vertex.SetDcaDaughters(dca);
          //vertex.ChangeMassHypothesis(); //default is Lambda0 
 
-         ioVertex=&vertex; vtxTree.Fill();
+         ioVertex=&vertex; vTree->Fill();
 
          nvtx++;
       }
    }
 
-   cerr<<"Number of reconstructed V0 vertices: "<<nvtx<<endl;
-
-   vtxTree.Write();
+   Info("Tracks2V0vertices","Number of reconstructed V0 vertices: %d",nvtx);
 
    negtrks.Delete();
    postrks.Delete();
 
-   savedir->cd();
-   
-   delete trkTree;
-
    return 0;
 }
 
-
-static void External2Helix(const AliITStrackV2 *t, Double_t helix[6]) { 
-  //--------------------------------------------------------------------
-  // External track parameters -> helix parameters 
-  //--------------------------------------------------------------------
-  Double_t alpha,x,cs,sn;
-  t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
-
-  cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
-  helix[5]=x*cs - helix[0]*sn;            // x0
-  helix[0]=x*sn + helix[0]*cs;            // y0
-//helix[1]=                               // z0
-  helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
-//helix[3]=                               // tgl
-  helix[4]=helix[4]/t->GetConvConst();    // C
-}
-
-static void Evaluate(const Double_t *h, Double_t t,
-                     Double_t r[3],  //radius vector
-                     Double_t g[3],  //first defivatives
-                     Double_t gg[3]) //second derivatives
-{
-  //--------------------------------------------------------------------
-  // Calculate position of a point on a track and some derivatives
-  //--------------------------------------------------------------------
-  Double_t phase=h[4]*t+h[2];
-  Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
-
-  r[0] = h[5] + (sn - h[6])/h[4];
-  r[1] = h[0] - (cs - h[7])/h[4];  
-  r[2] = h[1] + h[3]*t;
-
-  g[0] = cs; g[1]=sn; g[2]=h[3];
-  
-  gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
-}
-
-Double_t AliV0vertexer::PropagateToDCA(AliITStrackV2 *n, AliITStrackV2 *p) {
+Double_t 
+AliV0vertexer::PropagateToDCA(AliITStrackV2 *n, AliITStrackV2 *p) const {
   //--------------------------------------------------------------------
   // This function returns the DCA between two tracks
   // The tracks will be moved to the point of DCA ! 
   //--------------------------------------------------------------------
-  Double_t dy2=n->GetSigmaY2() + p->GetSigmaY2();
-  Double_t dz2=n->GetSigmaZ2() + p->GetSigmaZ2();
-  Double_t dx2=dy2; 
-
-  //dx2=dy2=dz2=1.;
-
-  Double_t p1[8]; External2Helix(n,p1);
-  p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
-  Double_t p2[8]; External2Helix(p,p2);
-  p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
-
-
-  Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
-  Evaluate(p1,t1,r1,g1,gg1);
-  Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
-  Evaluate(p2,t2,r2,g2,gg2);
-
-  Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
-  Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
-
-  Int_t max=27;
-  while (max--) {
-     Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
-     Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
-     Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 + 
-                  (g1[1]*g1[1] - dy*gg1[1])/dy2 +
-                  (g1[2]*g1[2] - dz*gg1[2])/dz2;
-     Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 + 
-                  (g2[1]*g2[1] + dy*gg2[1])/dy2 +
-                  (g2[2]*g2[2] + dz*gg2[2])/dz2;
-     Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
-
-     Double_t det=h11*h22-h12*h12;
-
-     Double_t dt1,dt2;
-     if (TMath::Abs(det)<1.e-33) {
-        //(quasi)singular Hessian
-        dt1=-gt1; dt2=-gt2;
-     } else {
-        dt1=-(gt1*h22 - gt2*h12)/det; 
-        dt2=-(h11*gt2 - h12*gt1)/det;
-     }
-
-     if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
-
-     //check delta(phase1) ?
-     //check delta(phase2) ?
-
-     if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
-     if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
-        if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2) 
-          cerr<<"AliV0vertexer::PropagateToDCA:"
-                 " stopped at not a stationary point !\n";
-        Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
-        if (lmb < 0.) 
-          cerr<<"AliV0vertexer::PropagateToDCA:"
-                 " stopped at not a minimum !\n";
-        break;
-     }
-
-     Double_t dd=dm;
-     for (Int_t div=1 ; ; div*=2) {
-        Evaluate(p1,t1+dt1,r1,g1,gg1);
-        Evaluate(p2,t2+dt2,r2,g2,gg2);
-        dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
-        dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
-       if (dd<dm) break;
-        dt1*=0.5; dt2*=0.5;
-        if (div>512) {
-           cerr<<"AliV0vertexer::PropagateToDCA: overshoot !\n"; break;
-        }   
-     }
-     dm=dd;
-
-     t1+=dt1;
-     t2+=dt2;
-
-  }
-
-  if (max<=0) cerr<<"AliV0vertexer::PropagateToDCA: too many iterations !\n";  
-  
-  //propagate tracks to the points of DCA
-  Double_t cs=TMath::Cos(n->GetAlpha());
-  Double_t sn=TMath::Sin(n->GetAlpha());
-  Double_t x=r1[0]*cs + r1[1]*sn;
-  if (!n->PropagateTo(x,0.,0.)) {
-    //cerr<<"AliV0vertexer::PropagateToDCA: propagation failed !\n";
-    return 1.e+33;
-  }  
-
-  cs=TMath::Cos(p->GetAlpha());
-  sn=TMath::Sin(p->GetAlpha());
-  x=r2[0]*cs + r2[1]*sn;
-  if (!p->PropagateTo(x,0.,0.)) {
-    //cerr<<"AliV0vertexer::PropagateToDCA: propagation failed !\n";
-    return 1.e+33;
-  }  
-
-  return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
-  //return TMath::Sqrt(dx*dx + dy*dy + dz*dz);
+  return n->PropagateToDCA(p);
 }