]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSVertexerZ.cxx
Small optimizations
[u/mrichter/AliRoot.git] / ITS / AliITSVertexerZ.cxx
index d97b164113a79eef6fbec70f7ae3c844e2fae132..d0e17532d20fd11aae6f1e2d2608190fdbf5fcb6 100644 (file)
 #include "AliITSVertexerZ.h"
 #include<TBranch.h>
 #include<TClonesArray.h>
-#include<TFile.h>
 #include<TH1.h>
 #include <TString.h>
 #include<TTree.h>
+#include "AliRunLoader.h"
 #include "AliITSLoader.h"
-#include "AliITSgeom.h"
+#include "AliITSgeomTGeo.h"
 #include "AliITSDetTypeRec.h"
 #include "AliITSRecPoint.h"
 #include "AliITSZPoint.h"
-#include "AliHeader.h"
-#include "AliGenEventHeader.h"
 
 /////////////////////////////////////////////////////////////////
 // this class implements a fast method to determine
@@ -46,8 +44,6 @@ fLastL1(0),
 fFirstL2(0),
 fLastL2(0),
 fDiffPhiMax(0),
-fX0(0.),
-fY0(0.),
 fZFound(0),
 fZsig(0.),
 fZCombc(0),
@@ -77,8 +73,6 @@ fLastL1(0),
 fFirstL2(0),
 fLastL2(0),
 fDiffPhiMax(0),
-fX0(x0),
-fY0(y0),
 fZFound(0),
 fZsig(0.),
 fZCombc(0),
@@ -99,6 +93,7 @@ fWindowWidth(0) {
   SetPPsetting();
   ConfigIterations();
   SetWindowWidth();
+  SetVtxStart((Double_t)x0,(Double_t)y0,0.);
 
 }
 
@@ -109,8 +104,6 @@ fLastL1(vtxr.fLastL1),
 fFirstL2(vtxr.fFirstL2),
 fLastL2(vtxr.fLastL2),
 fDiffPhiMax(vtxr.fDiffPhiMax),
-fX0(vtxr.fX0),
-fY0(vtxr.fY0),
 fZFound(vtxr.fZFound),
 fZsig(vtxr.fZsig),
 fZCombc(vtxr.fZCombc),
@@ -221,16 +214,13 @@ AliESDVertex* AliITSVertexerZ::FindVertexForCurrentEvent(Int_t evnumber){
   return fCurrentVertex;
 }  
 
-
-
-
 //______________________________________________________________________
 void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
   // Defines the AliESDVertex for the current event
   fCurrentVertex = 0;
   AliRunLoader *rl =AliRunLoader::GetRunLoader();
   AliITSLoader* itsLoader = (AliITSLoader*)rl->GetLoader("ITSLoader");
-  AliITSgeom* geom = itsLoader->GetITSgeom();
+  //  AliITSgeom* geom = itsLoader->GetITSgeom();
   itsLoader->LoadRecPoints();
   rl->GetEvent(evnumber);
 
@@ -239,9 +229,9 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
   TTree *tR = itsLoader->TreeR();
   detTypeRec.SetTreeAddressR(tR);
   TClonesArray *itsRec  = 0;
-  // lc and gc are local and global coordinates for layer 1
-  Float_t lc[3]; for(Int_t ii=0; ii<3; ii++) lc[ii]=0.;
-  Float_t gc[3]; for(Int_t ii=0; ii<3; ii++) gc[ii]=0.;
+  // lc1 and gc1 are local and global coordinates for layer 1
+  Float_t lc1[3]; for(Int_t ii=0; ii<3; ii++) lc1[ii]=0.;
+  Float_t gc1[3]; for(Int_t ii=0; ii<3; ii++) gc1[ii]=0.;
   // lc2 and gc2 are local and global coordinates for layer 2
   Float_t lc2[3]; for(Int_t ii=0; ii<3; ii++) lc2[ii]=0.;
   Float_t gc2[3]; for(Int_t ii=0; ii<3; ii++) gc2[ii]=0.;
@@ -252,19 +242,14 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
 
   Int_t nrpL1 = 0;
   Int_t nrpL2 = 0;
+
   // By default fFirstL1=0 and fLastL1=79
-  // This loop counts the number of recpoints on layer1 (central modules)
   for(Int_t module= fFirstL1; module<=fLastL1;module++){
-    // Keep only central modules
-    //    if(module%4==0 || module%4==3)continue;
-    //   cout<<"Procesing module "<<module<<" ";
     branch->GetEvent(module);
-    //    cout<<"Number of clusters "<<clusters->GetEntries()<<endl;
     nrpL1+= itsRec->GetEntries();
     detTypeRec.ResetRecPoints();
   }
   //By default fFirstL2=80 and fLastL2=239
-  //This loop counts the number of RP on layer 2
   for(Int_t module= fFirstL2; module<=fLastL2;module++){
     branch->GetEvent(module);
     nrpL2+= itsRec->GetEntries();
@@ -276,19 +261,6 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
     fCurrentVertex = new AliESDVertex(0.,5.3,-2);
     return;
   }
-  // The vertex finding is attempted only if the number of RP is !=0 on
-  // both layers
-  Float_t *xc1 = new Float_t [nrpL1]; // coordinates of the L1 Recpoints
-  Float_t *yc1 = new Float_t [nrpL1];
-  Float_t *zc1 = new Float_t [nrpL1];
-  Float_t *phi1 = new Float_t [nrpL1];
-  Float_t *err1 = new Float_t [nrpL1];
-  Float_t *xc2 = new Float_t [nrpL2]; // coordinates of the L1 Recpoints
-  Float_t *yc2 = new Float_t [nrpL2];
-  Float_t *zc2 = new Float_t [nrpL2];
-  Float_t *phi2 = new Float_t [nrpL2];
-  Float_t *err2 = new Float_t [nrpL2];
-  Int_t ind = 0;// running index for RP
   // Force a coarse bin size of 200 microns if the number of clusters on layer 2
   // is low
   if(nrpL2<fPPsetting[0])SetBinWidthCoarse(fPPsetting[1]);
@@ -297,55 +269,7 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
   if(fZCombc)delete fZCombc;
   fZCombc = new TH1F("fZCombc","Z",nbincoarse,fLowLim,fLowLim+nbincoarse*fStepCoarse);
 
-  // Loop on modules of layer 1 
-
-  for(Int_t module= fFirstL1; module<=fLastL1;module++){
-    //    if(module%4==0 || module%4==3)continue;
-    branch->GetEvent(module);
-    Int_t nrecp1 = itsRec->GetEntries();
-    for(Int_t j=0;j<nrecp1;j++){
-      AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
-      // Local coordinates of this recpoint
-      lc[0]=recp->GetDetLocalX();
-      lc[2]=recp->GetDetLocalZ();
-      geom->LtoG(module,lc,gc);
-      // Global coordinates of this recpoints
-      gc[0]-=fX0; // Possible beam offset in the bending plane
-      gc[1]-=fY0; //   "               "
-      xc1[ind]=gc[0];
-      yc1[ind]=gc[1];
-      zc1[ind]=gc[2];
-      // azimuthal angle is computed in the interval 0 --> 2*pi
-      phi1[ind] = TMath::ATan2(gc[1],gc[0]);
-      if(phi1[ind]<0)phi1[ind]=2*TMath::Pi()+phi1[ind];
-      err1[ind]=recp->GetSigmaZ2();
-      ind++;
-    }
-    detTypeRec.ResetRecPoints();
-  }
-  ind = 0; // the running index is reset for Layer 2
-  for(Int_t module= fFirstL2; module<=fLastL2;module++){
-    branch->GetEvent(module);
-    Int_t nrecp2 = itsRec->GetEntries();
-    for(Int_t j=0;j<nrecp2;j++){
-      AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
-      lc[0]=recp->GetDetLocalX();
-      lc[2]=recp->GetDetLocalZ();
-      geom->LtoG(module,lc,gc);
-      gc[0]-=fX0;
-      gc[1]-=fY0;
-      xc2[ind]=gc[0];
-      yc2[ind]=gc[1];
-      zc2[ind]=gc[2];
-      phi2[ind] = TMath::ATan2(gc[1],gc[0]);
-      if(phi2[ind]<0)phi2[ind]=2*TMath::Pi()+phi2[ind];
-      err2[ind]=recp->GetSigmaZ2();
-      ind++;
-    }
-    detTypeRec.ResetRecPoints();
-  }
-/* Test the ffect of mutiple scatternig on error. Negligible
+ /* Test the ffect of mutiple scatternig on error. Negligible
   // Multiple scattering
   Float_t beta=1.,pmed=0.875; //pmed=875 MeV (for tracks with dphi<0.01 rad)
   Float_t beta2=beta*beta;
@@ -356,39 +280,82 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
   Float_t theta2BP=14.1*14.1/(beta2*p2*1e6)*TMath::Abs(dBP);
   Float_t theta2L1=14.1*14.1/(beta2*p2*1e6)*TMath::Abs(dL1);
 */
-  TClonesArray *points = new TClonesArray("AliITSZPoint",nrpL1*nrpL2);
+  Int_t maxdim=TMath::Min(nrpL1*nrpL2,50000);  // temporary; to limit the size in PbPb
+  TClonesArray *points = new TClonesArray("AliITSZPoint",maxdim);
   TClonesArray &pts = *points;
   Int_t nopoints =0;
-  for(Int_t i=0;i<nrpL1;i++){ // loop on L1 RP
-    Float_t r1=TMath::Sqrt(xc1[i]*xc1[i]+yc1[i]*yc1[i]); // radius L1 RP
-    for(Int_t j=0;j<nrpL2;j++){ // loop on L2 RP
-      Float_t diff = TMath::Abs(phi2[j]-phi1[i]); // diff in azimuth
-      if(diff>TMath::Pi())diff=2.*TMath::Pi()-diff; //diff<pi
-      if(diff<fDiffPhiMax){ // cut on 10 milliradians by def.
-       Float_t r2=TMath::Sqrt(xc2[j]*xc2[j]+yc2[j]*yc2[j]); // radius L2 RP
-//     Float_t tgth=(zc2[j]-zc1[i])/(r2-r1); // slope
-       Float_t zr0=(r2*zc1[i]-r1*zc2[j])/(r2-r1); //Z @ null radius
-       Float_t ezr0q=(r2*r2*err1[i]+r1*r1*err2[j])/(r2-r1)/(r2-r1); //error on Z @ null radius
-       /*
+  for(Int_t modul1= fFirstL1; modul1<=fLastL1;modul1++){   // Loop on modules of layer 1
+    UShort_t ladder=int(modul1/4)+1;  // ladders are numbered starting from 1
+    branch->GetEvent(modul1);
+    Int_t nrecp1 = itsRec->GetEntries();
+    TClonesArray *prpl1 = new TClonesArray("AliITSRecPoint",nrecp1);
+    prpl1->SetOwner();
+    TClonesArray &rpl1 = *prpl1;
+    for(Int_t j=0;j<nrecp1;j++){
+      AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
+      new(rpl1[j])AliITSRecPoint(*recp);
+    }
+    detTypeRec.ResetRecPoints();
+    for(Int_t j1=0;j1<nrecp1;j1++){
+      AliITSRecPoint *recp = (AliITSRecPoint*)prpl1->At(j1);
+      /*
+      lc1[0]=recp->GetDetLocalX();
+      lc1[2]=recp->GetDetLocalZ();
+      geom->LtoG(modul1,lc1,gc1);
+      // Global coordinates of this recpoints
+      */
+      recp->GetGlobalXYZ(gc1);
+      gc1[0]-=fNominalPos[0]; // Possible beam offset in the bending plane
+      gc1[1]-=fNominalPos[1]; //   "               "
+      Float_t r1=TMath::Sqrt(gc1[0]*gc1[0]+gc1[1]*gc1[1]);
+      Float_t phi1 = TMath::ATan2(gc1[1],gc1[0]);
+      if(phi1<0)phi1+=2*TMath::Pi();
+      Float_t zc1=gc1[2];
+      Float_t erz1=recp->GetSigmaZ2();
+      for(Int_t ladl2=0 ; ladl2<fLadOnLay2*2+1;ladl2++){
+       for(Int_t k=0;k<4;k++){
+         Int_t ladmod=fLadders[ladder-1]+ladl2;
+         if(ladmod>AliITSgeomTGeo::GetNLadders(2)) ladmod=ladmod-AliITSgeomTGeo::GetNLadders(2);
+         Int_t modul2=AliITSgeomTGeo::GetModuleIndex(2,ladmod,k+1);
+         branch->GetEvent(modul2);
+         Int_t nrecp2 = itsRec->GetEntries();
+         for(Int_t j2=0;j2<nrecp2;j2++){
+           recp = (AliITSRecPoint*)itsRec->At(j2);
+           /*
+           lc2[0]=recp->GetDetLocalX();
+           lc2[2]=recp->GetDetLocalZ();
+           geom->LtoG(modul2,lc2,gc2);
+           */
+           recp->GetGlobalXYZ(gc2);
+           gc2[0]-=fNominalPos[0];
+           gc2[1]-=fNominalPos[1];
+           Float_t r2=TMath::Sqrt(gc2[0]*gc2[0]+gc2[1]*gc2[1]);
+           Float_t phi2 = TMath::ATan2(gc2[1],gc2[0]);
+           if(phi2<0)phi2+=2*TMath::Pi();
+           Float_t zc2=gc2[2];
+           Float_t erz2=recp->GetSigmaZ2();
+
+           Float_t diff = TMath::Abs(phi2-phi1); 
+           if(diff>TMath::Pi())diff=2.*TMath::Pi()-diff;
+           if(diff<fDiffPhiMax){
+             //        Float_t tgth=(zc2[j]-zc1[i])/(r2-r1); // slope (used for multiple scattering)
+             Float_t zr0=(r2*zc1-r1*zc2)/(r2-r1); //Z @ null radius
+             Float_t ezr0q=(r2*r2*erz1+r1*r1*erz2)/(r2-r1)/(r2-r1); //error on Z @ null radius
+        /*
+         // Multiple scattering
         ezr0q+=r1*r1*(1+tgth*tgth)*theta2L1/2; // multiple scattering in layer 1
         ezr0q+=rBP*rBP*(1+tgth*tgth)*theta2BP/2; // multiple scattering in beam pipe
        */
-       new(pts[nopoints++])AliITSZPoint(zr0,ezr0q);
-
-       fZCombc->Fill(zr0);
+             if(nopoints<maxdim) new(pts[nopoints++])AliITSZPoint(zr0,ezr0q);        
+             fZCombc->Fill(zr0);
+           }
+         }
+         detTypeRec.ResetRecPoints();
+       }
       }
     }
+    delete prpl1;
   }
-  delete [] xc1;
-  delete [] yc1;
-  delete [] zc1;
-  delete [] phi1;
-  delete [] err1;
-  delete [] xc2;
-  delete [] yc2;
-  delete [] zc2;
-  delete [] phi2;
-  delete [] err2;
 
   points->Sort();
 
@@ -398,6 +365,8 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
     ResetHistograms();
     itsLoader->UnloadRecPoints();
     fCurrentVertex = new AliESDVertex(0.,5.3,-1);
+    points->Delete();
+    delete points; 
     return;
   }
 
@@ -445,11 +414,14 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
   } while(niter<10 && TMath::Abs((zm-lim1)-(lim2-zm))>fTolerance);
   fCurrentVertex = new AliESDVertex(zm,ezm,ncontr);
   fCurrentVertex->SetTitle("vertexer: B");
+  delete points;
   ResetHistograms();
   itsLoader->UnloadRecPoints();
   return;
 }
 
+
+
 //_____________________________________________________________________
 void AliITSVertexerZ::ResetHistograms(){
   // delete TH1 data members
@@ -485,7 +457,6 @@ void AliITSVertexerZ::PrintStatus() const {
   cout <<"Limits for Z histograms: "<<fLowLim<<"; "<<fHighLim<<endl;
   cout <<"Bin sizes for coarse z histos "<<fStepCoarse<<endl;
   cout <<" Current Z "<<fZFound<<"; Z sig "<<fZsig<<endl;
-  cout <<" Debug flag: "<<fDebug<<endl;
   cout <<"First event to be processed "<<fFirstEvent;
   cout <<"\n Last event to be processed "<<fLastEvent<<endl;
   if(fZCombc){