]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSVertexerZ.cxx
Changes required in order to cope with the new version of ITSVertexerZ. The HLT verte...
[u/mrichter/AliRoot.git] / ITS / AliITSVertexerZ.cxx
index 4502f240c60f200b6d518791a53a57125f1e7ac5..d97b164113a79eef6fbec70f7ae3c844e2fae132 100644 (file)
@@ -14,6 +14,8 @@
  **************************************************************************/
 #include "AliITSVertexerZ.h"
 #include<TBranch.h>
+#include<TClonesArray.h>
+#include<TFile.h>
 #include<TH1.h>
 #include <TString.h>
 #include<TTree.h>
@@ -21,6 +23,9 @@
 #include "AliITSgeom.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,25 +51,23 @@ fY0(0.),
 fZFound(0),
 fZsig(0.),
 fZCombc(0),
-fZCombv(0),
-fZCombf(0),
 fLowLim(0.),
 fHighLim(0.),
 fStepCoarse(0),
-fStepFine(0),
 fTolerance(0.),
-fMaxIter(0){
+fMaxIter(0),
+fWindowWidth(0) {
   // Default constructor
-  SetDiffPhiMax(0);
-  SetFirstLayerModules(0);
-  SetSecondLayerModules(0);
-  SetLowLimit(0.);
-  SetHighLimit(0.);
-  SetBinWidthCoarse(0.);
-  SetBinWidthFine(0.);
-  SetTolerance(0.);
-  SetPPsetting(0.,0.);
+  SetDiffPhiMax();
+  SetFirstLayerModules();
+  SetSecondLayerModules();
+  SetLowLimit();
+  SetHighLimit();
+  SetBinWidthCoarse();
+  SetTolerance();
+  SetPPsetting();
   ConfigIterations();
+  SetWindowWidth();
 }
 
 //______________________________________________________________________
@@ -79,14 +82,12 @@ fY0(y0),
 fZFound(0),
 fZsig(0.),
 fZCombc(0),
-fZCombv(0),
-fZCombf(0),
 fLowLim(0.),
 fHighLim(0.),
 fStepCoarse(0),
-fStepFine(0),
 fTolerance(0.),
-fMaxIter(0) {
+fMaxIter(0),
+fWindowWidth(0) {
   // Standard Constructor
   SetDiffPhiMax();
   SetFirstLayerModules();
@@ -94,10 +95,10 @@ fMaxIter(0) {
   SetLowLimit();
   SetHighLimit();
   SetBinWidthCoarse();
-  SetBinWidthFine();
   SetTolerance();
   SetPPsetting();
   ConfigIterations();
+  SetWindowWidth();
 
 }
 
@@ -113,14 +114,12 @@ fY0(vtxr.fY0),
 fZFound(vtxr.fZFound),
 fZsig(vtxr.fZsig),
 fZCombc(vtxr.fZCombc),
-fZCombv(vtxr.fZCombv),
-fZCombf(vtxr.fZCombf),
 fLowLim(vtxr.fLowLim),
 fHighLim(vtxr.fHighLim),
 fStepCoarse(vtxr.fStepCoarse),
-fStepFine(vtxr.fStepFine),
 fTolerance(vtxr.fTolerance),
-fMaxIter(vtxr.fMaxIter) {
+fMaxIter(vtxr.fMaxIter),
+fWindowWidth(vtxr.fWindowWidth){
   // Copy constructor
 
 }
@@ -138,8 +137,6 @@ AliITSVertexerZ& AliITSVertexerZ::operator=(const AliITSVertexerZ&  vtxr ){
 AliITSVertexerZ::~AliITSVertexerZ() {
   // Destructor
   delete fZCombc;
-  delete fZCombf;
-  delete fZCombv;
 }
 
 //______________________________________________________________________
@@ -259,7 +256,7 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
   // 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;
+    //    if(module%4==0 || module%4==3)continue;
     //   cout<<"Procesing module "<<module<<" ";
     branch->GetEvent(module);
     //    cout<<"Number of clusters "<<clusters->GetEntries()<<endl;
@@ -285,29 +282,25 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
   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]);
-  // By default nbinfine = (10+10)/0.0005=40000
-  Int_t nbinfine = static_cast<Int_t>((fHighLim-fLowLim)/fStepFine);
   // By default nbincoarse=(10+10)/0.01=2000
   Int_t nbincoarse = static_cast<Int_t>((fHighLim-fLowLim)/fStepCoarse);
-  // Set stepverycoarse = 3*fStepCoarse
-  Int_t nbinvcoarse = static_cast<Int_t>((fHighLim-fLowLim)/(3.*fStepCoarse));
   if(fZCombc)delete fZCombc;
   fZCombc = new TH1F("fZCombc","Z",nbincoarse,fLowLim,fLowLim+nbincoarse*fStepCoarse);
-  if(fZCombv)delete fZCombv;
-  fZCombv = new TH1F("fZCombv","Z",nbinvcoarse,fLowLim,fLowLim+nbinvcoarse*3.*fStepCoarse);
-  if(fZCombf)delete fZCombf;
-  fZCombf = new TH1F("fZCombf","Z",nbinfine,fLowLim,fLowLim+nbinfine*fStepFine);
-  // Loop on modules of layer 1 (restricted to central modules)
+
+  // Loop on modules of layer 1 
+
   for(Int_t module= fFirstL1; module<=fLastL1;module++){
-    if(module%4==0 || module%4==3)continue;
+    //    if(module%4==0 || module%4==3)continue;
     branch->GetEvent(module);
     Int_t nrecp1 = itsRec->GetEntries();
     for(Int_t j=0;j<nrecp1;j++){
@@ -325,6 +318,7 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
       // 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();
@@ -345,12 +339,26 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
       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();
   }
  
-  // Int_t nolines=0;
+/* 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;
+  Float_t p2=pmed*pmed;
+  Float_t rBP=3; //Beam Pipe radius = 3cm
+  Float_t dBP=0.08/35.3; // 800 um of Be
+  Float_t dL1=0.01; //approx. 1% of radiation length  
+  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);
+  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
@@ -358,19 +366,16 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
       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
-       fZCombf->Fill(zr0);
+       Float_t ezr0q=(r2*r2*err1[i]+r1*r1*err2[j])/(r2-r1)/(r2-r1); //error on Z @ null radius
+       /*
+        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);
-       fZCombv->Fill(zr0);
-       Double_t pA[3];
-       Double_t pB[3];
-       pA[0]=xc1[i];
-       pA[1]=yc1[i];
-       pA[2]=zc1[i];
-       pB[0]=xc2[j];
-       pB[1]=yc2[j];
-       pB[2]=zc2[j];
-       //      MakeTracklet(pA,pB,nolines);
       }
     }
   }
@@ -378,10 +383,15 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
   delete [] yc1;
   delete [] zc1;
   delete [] phi1;
+  delete [] err1;
   delete [] xc2;
   delete [] yc2;
   delete [] zc2;
   delete [] phi2;
+  delete [] err2;
+
+  points->Sort();
+
   Double_t contents = fZCombc->GetEntries()- fZCombc->GetBinContent(0)-fZCombc->GetBinContent(nbincoarse+1);
   if(contents<1.){
     //    Warning("FindVertexForCurrentEvent","Insufficient number of rec. points\n");
@@ -394,94 +404,46 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
   TH1F *hc = fZCombc;
 
   
-  if(hc->GetBinContent(hc->GetMaximumBin())<3)hc = fZCombv;
+  if(hc->GetBinContent(hc->GetMaximumBin())<3)hc->Rebin(3);
   Int_t binmin,binmax;
   Int_t nPeaks=GetPeakRegion(hc,binmin,binmax);   
   if(nPeaks==2)AliWarning("2 peaks found");
-  Int_t ii1=1+static_cast<Int_t>((hc->GetBinLowEdge(binmin)-fLowLim)/fStepFine);
-  Int_t ii2=1+static_cast<Int_t>((hc->GetBinLowEdge(binmax)+hc->GetBinWidth(binmax)-fLowLim)/fStepFine);
-  Float_t centre = 0.;
-  Int_t nn=0;
-  for(Int_t ii=ii1;ii<=ii2;ii++){
-    centre+= fZCombf->GetBinCenter(ii)*fZCombf->GetBinContent(ii);
-    nn+=static_cast<Int_t>(fZCombf->GetBinContent(ii));
+  Float_t zm =0.;
+  Float_t ezm =0.;
+  Float_t lim1 = hc->GetBinLowEdge(binmin);
+  Float_t lim2 = hc->GetBinLowEdge(binmax)+hc->GetBinWidth(binmax);
+
+  if(nPeaks ==1 && (lim2-lim1)<fWindowWidth){
+    Float_t c=(lim1+lim2)/2.;
+    lim1=c-fWindowWidth/2.;
+    lim2=c+fWindowWidth/2.;
   }
-  if (nn) centre/=nn;
-
-  // n1 is the bin number of fine histogram containing the point located 1 coarse bin less than "centre"
-  Int_t n1 = 1+static_cast<Int_t>((centre-hc->GetBinWidth(1)-fLowLim)/fStepFine);
-  // n2 is the bin number of fine histogram containing the point located 1 coarse bin more than "centre"
-  Int_t n2 = 1+static_cast<Int_t>((centre+hc->GetBinWidth(1)-fLowLim)/fStepFine);
-  if(n1<1)n1=1;
-  if(n2>nbinfine)n2=nbinfine;
-  Int_t niter = 0;
-  Bool_t goon = kTRUE;
-  Int_t num=0;
-  Bool_t last = kFALSE;
-
-  while(goon || last){
-    fZFound = 0.;
-    fZsig = 0.;
-    num=0;
-    // at the end of the loop:
-    // fZFound = N*(Average Z) - where N is the number of tracklets
-    // num=N
-    // fZsig = N*Q - where Q is the average of Z*Z
-    for(Int_t n=n1;n<=n2;n++){
-      fZFound+=fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
-      num+=static_cast<Int_t>(fZCombf->GetBinContent(n));
-      fZsig+=fZCombf->GetBinCenter(n)*fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
-    }
-    if(num<2){
-      fZsig = 5.3;  // Default error from the beam sigmoid
-    }
-    else{
-      Float_t radi =  fZsig/(num-1)-fZFound*fZFound/num/(num-1);
-      // radi = square root of sample variance of Z
-      if(radi>0.)fZsig=TMath::Sqrt(radi);
-      else fZsig=5.3;  // Default error from the beam sigmoid
-      // fZfound - Average Z
-      fZFound/=num;
+  Int_t niter = 0, ncontr=0;
+  do {
+    // symmetrization
+    if(zm  !=0.){
+      Float_t semilarg=TMath::Min((lim2-zm),(zm-lim1));
+      lim1=zm - semilarg;
+      lim2=zm + semilarg;
     }
-    if(!last){
-      // goon is true if the distance between the found Z and the lower bin differs from the distance between the found Z and
-      // the upper bin by more than tolerance (0.002)
-      goon = TMath::Abs(TMath::Abs(fZFound-fZCombf->GetBinCenter(n1))-TMath::Abs(fZFound-fZCombf->GetBinCenter(n2)))>fTolerance;
-      // a window in the fine grained histogram is centered aroung the found Z. The width is 2 bins of
-      // the coarse grained histogram
-      if(num>0){
-       n1 = 1+static_cast<Int_t>((fZFound-hc->GetBinWidth(1)-fLowLim)/fStepFine);
-       if(n1<1)n1=1;
-       n2 = 1+static_cast<Int_t>((fZFound+hc->GetBinWidth(1)-fLowLim)/fStepFine);
-       if(n2>nbinfine)n2=nbinfine;
-      }
-      else {
-       n1 = 1+static_cast<Int_t>((centre-(niter+2)*hc->GetBinWidth(1)-fLowLim)/fStepFine);
-       n2 = 1+static_cast<Int_t>((centre+(niter+2)*hc->GetBinWidth(1)-fLowLim)/fStepFine);
-       if(n1<1)n1=1;
-       if(n2>nbinfine)n2=nbinfine;
-      }
-      niter++;
-      // no more than 10 adjusting iterations
-      if(niter>=10)goon = kFALSE;
-
-      if((fZsig> 0.0001) && !goon && num>5){
-       last = kTRUE;
-       n1 = 1+static_cast<Int_t>((fZFound-fZsig-fLowLim)/fStepFine);
-       if(n1<1)n1=1;
-       n2 = 1+static_cast<Int_t>((fZFound+fZsig-fLowLim)/fStepFine);  
-       if(n2>nbinfine)n2=nbinfine;
+
+    zm=0.;
+    ezm=0.;
+    ncontr=0;
+    for(Int_t i =0; i<points->GetEntriesFast(); i++){
+      AliITSZPoint* p=(AliITSZPoint*)points->UncheckedAt(i);
+      if(p->GetZ()>lim1 && p->GetZ()<lim2){
+        Float_t deno = p->GetErrZ();
+        zm+=p->GetZ()/deno;
+        ezm+=1./deno;
+        ncontr++;
       }
     }
-    else {
-      last = kFALSE;
-    }
-
-  }
-  //  if(fDebug>0)cout<<"Numer of Iterations "<<niter<<endl<<endl;
-  //  if(num!=0)fZsig/=TMath::Sqrt(num);
-  if (fZsig<=0) fZsig=5.3; // Default error from the beam sigmoid
-  fCurrentVertex = new AliESDVertex(fZFound,fZsig,num);
+    zm/=ezm;
+    ezm=TMath::Sqrt(1./ezm);
+    niter++;
+  } while(niter<10 && TMath::Abs((zm-lim1)-(lim2-zm))>fTolerance);
+  fCurrentVertex = new AliESDVertex(zm,ezm,ncontr);
   fCurrentVertex->SetTitle("vertexer: B");
   ResetHistograms();
   itsLoader->UnloadRecPoints();
@@ -492,11 +454,7 @@ void AliITSVertexerZ::VertexZFinder(Int_t evnumber){
 void AliITSVertexerZ::ResetHistograms(){
   // delete TH1 data members
   if(fZCombc)delete fZCombc;
-  if(fZCombf)delete fZCombf;
-  if(fZCombv)delete fZCombv;
   fZCombc = 0;
-  fZCombf = 0;
-  fZCombv = 0;
 }
 
 //______________________________________________________________________
@@ -512,14 +470,6 @@ void AliITSVertexerZ::FindVertices(){
     if(fCurrentVertex){
       WriteCurrentVertex();
     }
-    /*
-    else {
-      if(fDebug>0){
-       cout<<"Vertex not found for event "<<i<<endl;
-       cout<<"fZFound = "<<fZFound<<", fZsig= "<<fZsig<<endl;
-      }
-    }
-    */
   }
 }
 
@@ -533,7 +483,7 @@ void AliITSVertexerZ::PrintStatus() const {
   cout <<fLastL2<<endl;
   cout <<" Max Phi difference: "<<fDiffPhiMax<<endl;
   cout <<"Limits for Z histograms: "<<fLowLim<<"; "<<fHighLim<<endl;
-  cout <<"Bin sizes for coarse and fine z histos "<<fStepCoarse<<"; "<<fStepFine<<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;
@@ -544,18 +494,6 @@ void AliITSVertexerZ::PrintStatus() const {
   else{
     cout<<"fZCombc does not exist\n";
   }
-  if(fZCombv){
-    cout<<"fZCombv exists - entries="<<fZCombv->GetEntries()<<endl;
-  }
-  else{
-    cout<<"fZCombv does not exist\n";
-  }
-   if(fZCombf){
-    cout<<"fZCombf exists - entries="<<fZCombv->GetEntries()<<endl;
-  }
-  else{
-    cout<<"fZCombf does not exist\n";
-  }
  
   cout <<"=======================================================\n";
 }