]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSVertexer.cxx
Added option for different binning of DCAxy axis in THnSparse. Same width for all...
[u/mrichter/AliRoot.git] / ITS / AliITSVertexer.cxx
index 2d6813bf9adcef07d6e22655bf0f66aa6686a8f0..6ecff35c54fe813a2a63e2ebb5f23b8d8417f4f0 100644 (file)
@@ -1,10 +1,12 @@
-#include <AliESDVertex.h>
+#include "AliLog.h"
+#include "AliMultiplicity.h"
 #include "AliITSgeomTGeo.h"
+#include "AliITSDetTypeRec.h"
 #include "AliITSVertexer.h"
-#include "AliRunLoader.h"
 #include "AliITSLoader.h"
-#include "AliMultiplicity.h"
 #include "AliITSMultReconstructor.h"
+#include "AliITSRecPointContainer.h"
+#include "AliRunLoader.h"
 
 const Float_t AliITSVertexer::fgkPipeRadius = 3.0;
 
@@ -13,128 +15,149 @@ ClassImp(AliITSVertexer)
 //////////////////////////////////////////////////////////////////////
 // Base class for primary vertex reconstruction                     //
 // AliESDVertexer is a class for full 3D primary vertex finding     //
-// derived classes: AliITSVertexerIons AliITSvertexer3D             //
+// derived classes: AliITSvertexer3D, AliITSVertexerZ.              //       
 //                  AliITSVertexerCosmics                           //
 //////////////////////////////////////////////////////////////////////
 
+/* $Id$ */
+
 //______________________________________________________________________
 AliITSVertexer::AliITSVertexer():AliVertexer(),
-fLadders(), 
-fLadOnLay2(0)   {
-  // Default Constructor
-  SetLaddersOnLayer2();
-}
-
-AliITSVertexer::AliITSVertexer(TString filename):AliVertexer(),
-fLadders(), 
-fLadOnLay2(0)
+fLadders(NULL), 
+fLadOnLay2(0),
+fComputeMultiplicity(kFALSE),
+fDetTypeRec(NULL),
+fMinTrackletsForPilup(0),
+fIsPileup(0),
+fNTrpuv(-2),
+fZpuv(-9999999.),
+fNoVertices(0),
+fVertArray(NULL),
+fFirstEvent(0),
+fLastEvent(-1)
 {
-  // Standard constructor
-  AliRunLoader *rl = AliRunLoader::GetRunLoader();
-  if(!rl){
-    Fatal("AliITSVertexer","Run Loader not found");
-  }
-  /*
-  if(rl->LoadgAlice()){
-    Fatal("AliITSVertexer","The AliRun object is not available - nothing done");
-  }
-  */
-  fCurrentVertex  = 0;   
-  SetFirstEvent(0);
-  SetLastEvent(0);
-  //  rl->LoadHeader();
-  AliITSLoader* itsLoader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
-  if(!filename.Contains("default"))itsLoader->SetVerticesFileName(filename);
-  if(!filename.Contains("null"))itsLoader->LoadVertices("recreate");
-  itsLoader->LoadRecPoints();
-  //  Int_t lst;
-  SetLastEvent(rl->GetNumberOfEvents()-1);
-  /*
-  if(rl->TreeE()){
-    lst = static_cast<Int_t>(rl->TreeE()->GetEntries());
-    SetLastEvent(lst-1);
-  }
-  */
+  // Default Constructor
   SetLaddersOnLayer2();
+  SetMinTrackletsForPilup();
+  for(Int_t i=0; i<kNSPDMod;i++) fUseModule[i]=kTRUE;
 }
 
 //______________________________________________________________________
-AliITSVertexer::AliITSVertexer(const AliITSVertexer &vtxr) : AliVertexer(vtxr) {
-  // Copy constructor
-  // Copies are not allowed. The method is protected to avoid misuse.
-  Error("AliITSVertexer","Copy constructor not allowed\n");
+AliITSVertexer::~AliITSVertexer() {
+  // Destructor
+  delete [] fLadders;
+  delete []fVertArray;
 }
 
 //______________________________________________________________________
-AliITSVertexer& AliITSVertexer::operator=(const AliITSVertexer& /* vtxr */){
-  // Assignment operator
-  // Assignment is not allowed. The method is protected to avoid misuse.
-  Error("= operator","Assignment operator not allowed\n");
-  return *this;
-}
+void AliITSVertexer::ResetVertex(){
+  // Resets vertex related data members
+  if(fNoVertices > 0){
+    if(fVertArray) delete []fVertArray;
+    fVertArray = NULL;
+    fNoVertices = 0;
+  }
+  fIsPileup=kFALSE;
+  fNTrpuv=-2;
+  fZpuv=-99999.;
 
-//______________________________________________________________________
-AliITSVertexer::~AliITSVertexer() {
-  // Destructor
- if(fLadders) delete [] fLadders;
 }
-
 //______________________________________________________________________
-void AliITSVertexer::FindMultiplicity(Int_t evnumber){
+void AliITSVertexer::FindMultiplicity(TTree *itsClusterTree){
   // Invokes AliITSMultReconstructor to determine the
   // charged multiplicity in the pixel layers
   if(fMult){delete fMult; fMult = 0;}
+
   Bool_t success=kTRUE;
+  Bool_t cosmics=kFALSE; 
   if(!fCurrentVertex)success=kFALSE;
   if(fCurrentVertex && fCurrentVertex->GetNContributors()<1)success=kFALSE;
+  if(fCurrentVertex && strstr(fCurrentVertex->GetTitle(),"cosmics")) {
+    success=kFALSE; 
+    cosmics=kTRUE;
+  } 
+
+  // get the FastOr bit mask
+  TBits fastOrFiredMap = fDetTypeRec->GetFastOrFiredMap();
+  TBits firedChipMap = fDetTypeRec->GetFiredChipMap(itsClusterTree);
+  AliITSMultReconstructor multReco;
+
   if(!success){
-    AliWarning("Tracklets multiplicity not determined because the primary vertex was not found");
+    if(!cosmics) {     
+      AliDebug(1,"Tracklets multiplicity not determined because the primary vertex was not found");
+      AliDebug(1,"Just counting the number of cluster-fired chips on the SPD layers");
+    }
+    if (!itsClusterTree) {
+      AliError(" Invalid ITS cluster tree !\n");
+      return;
+    }
+    multReco.LoadClusterFiredChips(itsClusterTree);
+    Short_t nfcL1 = multReco.GetNFiredChips(0);
+    Short_t nfcL2 = multReco.GetNFiredChips(1);
+    fMult = new AliMultiplicity(0,0,0,0,0,0,0,0,0,0,0,nfcL1,nfcL2,fastOrFiredMap);
+    fMult->SetFiredChipMap(firedChipMap);
+    AliITSRecPointContainer* rcont = AliITSRecPointContainer::Instance();
+    fMult->SetITSClusters(0,rcont->GetNClustersInLayer(1,itsClusterTree));
+    for(Int_t kk=2;kk<=6;kk++){
+      fMult->SetITSClusters(kk-1,rcont->GetNClustersInLayerFast(kk));
+    }
     return;
   }
-  AliITSMultReconstructor* multReco = new AliITSMultReconstructor();
-  AliRunLoader *rl =AliRunLoader::GetRunLoader();
-  AliITSLoader* itsLoader = (AliITSLoader*)rl->GetLoader("ITSLoader");
-  multReco->SetGeometry(itsLoader->GetITSgeom());
-  itsLoader->LoadRecPoints();
-  rl->GetEvent(evnumber);
-  TTree* itsClusterTree = itsLoader->TreeR();
+
   if (!itsClusterTree) {
-    AliError(" Can't get the ITS cluster tree !\n");
+    AliError(" Invalid ITS cluster tree !\n");
     return;
   }
   Double_t vtx[3];
   fCurrentVertex->GetXYZ(vtx);
   Float_t vtxf[3];
   for(Int_t i=0;i<3;i++)vtxf[i]=vtx[i];
-  multReco->SetHistOn(kFALSE);
-  multReco->Reconstruct(itsClusterTree,vtxf,vtxf);
-  Int_t notracks=multReco->GetNTracklets();
+  multReco.SetHistOn(kFALSE);
+  multReco.Reconstruct(itsClusterTree,vtxf,vtxf);
+  Int_t notracks=multReco.GetNTracklets();
   Float_t *tht = new Float_t [notracks];
   Float_t *phi = new Float_t [notracks];
+  Float_t *dtht = new Float_t [notracks];
   Float_t *dphi = new Float_t [notracks];
   Int_t *labels = new Int_t[notracks];
-  for(Int_t i=0;i<multReco->GetNTracklets();i++){
-    tht[i] = multReco->GetTracklet(i)[0];
-    phi[i] =  multReco->GetTracklet(i)[1];
-    dphi[i] = multReco->GetTracklet(i)[2];
-    labels[i] = static_cast<Int_t>(multReco->GetTracklet(i)[3]);
+  Int_t *labelsL2 = new Int_t[notracks];
+  for(Int_t i=0;i<multReco.GetNTracklets();i++){
+    tht[i] = multReco.GetTracklet(i)[0];
+    phi[i] =  multReco.GetTracklet(i)[1];
+    dtht[i] = multReco.GetTracklet(i)[3];
+    dphi[i] = multReco.GetTracklet(i)[2];
+    labels[i] = static_cast<Int_t>(multReco.GetTracklet(i)[4]);
+    labelsL2[i] = static_cast<Int_t>(multReco.GetTracklet(i)[5]);
   }
-  Int_t nosingleclus=multReco->GetNSingleClusters();
+  Int_t nosingleclus=multReco.GetNSingleClusters();
   Float_t *ths = new Float_t [nosingleclus];
   Float_t *phs = new Float_t [nosingleclus];
+  Int_t *labelss = new Int_t [nosingleclus];
   for(Int_t i=0;i<nosingleclus;i++){
-    ths[i] = multReco->GetCluster(i)[0];
-    phs[i] =  multReco->GetCluster(i)[1];
+    ths[i] = multReco.GetCluster(i)[0];
+    phs[i] = multReco.GetCluster(i)[1];
+    labelss[i] = (Int_t)multReco.GetCluster(i)[2];
+  }
+  Short_t nfcL1 = multReco.GetNFiredChips(0);
+  Short_t nfcL2 = multReco.GetNFiredChips(1);
+  fMult = new AliMultiplicity(notracks,tht,phi,dtht,dphi,labels,labelsL2,nosingleclus,ths,phs,labelss,nfcL1,nfcL2,fastOrFiredMap);
+  fMult->SetFiredChipMap(firedChipMap);
+  AliITSRecPointContainer* rcont = AliITSRecPointContainer::Instance();
+  fMult->SetITSClusters(0,rcont->GetNClustersInLayer(1,itsClusterTree));
+  for(Int_t kk=2;kk<=6;kk++){
+    fMult->SetITSClusters(kk-1,rcont->GetNClustersInLayerFast(kk));
   }
-  fMult = new AliMultiplicity(notracks,tht,phi,dphi,labels,nosingleclus,ths,phs);
   delete [] tht;
   delete [] phi;
+  delete [] dtht;
   delete [] dphi;
   delete [] ths;
   delete [] phs;
   delete [] labels;
-  itsLoader->UnloadRecPoints();
-  delete multReco;
+  delete [] labelsL2;
+  delete [] labelss;
+
   return;
 }
 
@@ -142,10 +165,8 @@ void AliITSVertexer::FindMultiplicity(Int_t evnumber){
 void AliITSVertexer::SetLaddersOnLayer2(Int_t ladwid){
   // Calculates the array of ladders on layer 2 to be used with a 
   // given ladder on layer 1
+  if(ladwid == fLadOnLay2 && fLadders)return;
   fLadOnLay2=ladwid;
-  //  AliRunLoader *rl =AliRunLoader::GetRunLoader();
-  //  AliITSLoader* itsLoader = (AliITSLoader*)rl->GetLoader("ITSLoader");
-  //  AliITSgeom* geom = itsLoader->GetITSgeom();
   Int_t ladtot1=AliITSgeomTGeo::GetNLadders(1);
   if(fLadders) delete [] fLadders;
   fLadders=new UShort_t[ladtot1];
@@ -181,10 +202,26 @@ void AliITSVertexer::SetLaddersOnLayer2(Int_t ladwid){
 }
 
 
+//______________________________________________________________________
+void AliITSVertexer::Init(TString filename){
+  // Initialize the vertexer in case of
+  // analysis of an entire file
+  AliRunLoader *rl = AliRunLoader::Instance();
+  if(!rl){
+    AliFatal("Run Loader not found");
+    return;
+  }
+  if (fLastEvent < 0) SetLastEvent(rl->GetNumberOfEvents()-1);
+
+  AliITSLoader* itsloader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
+  if(!filename.Contains("default"))itsloader->SetVerticesFileName(filename);
+  if(!filename.Contains("null"))itsloader->LoadVertices("recreate");
+}
+
 //______________________________________________________________________
 void AliITSVertexer::WriteCurrentVertex(){
   // Write the current AliVertex object to file fOutFile
-  AliRunLoader *rl = AliRunLoader::GetRunLoader();
+  AliRunLoader *rl = AliRunLoader::Instance();
   AliITSLoader* itsLoader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
   fCurrentVertex->SetName("Vertex");
   //  const char * name = fCurrentVertex->GetName();
@@ -193,3 +230,22 @@ void AliITSVertexer::WriteCurrentVertex(){
   rc = itsLoader->WriteVertices();
 }
 
+//______________________________________________________________________
+void AliITSVertexer::FindVertices(){
+  // computes the vertices of the events in the range FirstEvent - LastEvent
+
+  AliRunLoader *rl = AliRunLoader::Instance();
+  AliITSLoader* itsloader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
+  itsloader->LoadRecPoints("read");
+  for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
+    rl->GetEvent(i);
+    TTree* cltree = itsloader->TreeR();
+    FindVertexForCurrentEvent(cltree);
+    if(fCurrentVertex){
+      WriteCurrentVertex();
+    }
+    else {
+      AliDebug(1,Form("Vertex not found for event %d",i));
+    }
+  }
+}