]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/src/AliL3ConfMapper.cxx
Some changes resulting from last week work. The mc stuff has been removed.
[u/mrichter/AliRoot.git] / HLT / src / AliL3ConfMapper.cxx
index 9d0e88f530f9b1542597987618c44ad918674c90..293e1423f2d4aac77d8df1b7cac2ca96779804cf 100644 (file)
@@ -1,24 +1,24 @@
+//$Id$
 
-//Author:        Anders Strand Vestbo
-//Last Modified: 15.12.2000
+// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
+//*-- Copyright &copy ASV 
+#include "AliL3StandardIncludes.h"
+#include <sys/time.h>
 
-#include <iostream.h>
-#include <time.h>
-#include <math.h>
 #include "AliL3ConfMapper.h"
-
-#include "AliL3Logging.h"
-#include "AliL3Transform.h"
+#include "AliL3Logging.h" 
 #include "AliL3Vertex.h"
 #include "AliL3ConfMapTrack.h"
 #include "AliL3ConfMapPoint.h"
 #include "AliL3TrackArray.h"
+#include "AliL3Transform.h"
 
+//_____________________________________________________________
+// AliL3ConfMapper
 //
-//AliL3ConfMapper
+// Conformal mapping base class
 //
-//Conformal mapping base class
-
 ClassImp(AliL3ConfMapper)
 
 Double_t AliL3ConfMapper::pi=3.14159265358979323846;
@@ -36,6 +36,7 @@ AliL3ConfMapper::AliL3ConfMapper()
   fBench = (Bool_t)true;
   fParamSet = (Bool_t)false;
   fVertexConstraint = (Bool_t)true;
+  
 }
 
 
@@ -57,6 +58,46 @@ AliL3ConfMapper::~AliL3ConfMapper()
   }
 
 }
+void AliL3ConfMapper::InitVolumes()
+{
+  //Data organization.
+  //Allocate volumes, set conformal coordinates and pointers.
+  
+  //Should be done after setting the track parameters
+  
+  fNumRowSegmentPlusOne = AliL3Transform::GetNRows();//NumRows[0]; //Maximum 32.
+  fNumPhiSegmentPlusOne = fNumPhiSegment+1;
+  fNumEtaSegmentPlusOne = fNumEtaSegment+1;
+  fNumPhiEtaSegmentPlusOne = fNumPhiSegmentPlusOne*fNumEtaSegmentPlusOne;
+  fBounds = fNumRowSegmentPlusOne * fNumPhiSegmentPlusOne * fNumEtaSegmentPlusOne;
+  
+  //Allocate volumes:
+  if(fVolume) delete [] fVolume;
+  if(fRow) delete [] fRow;
+  
+  LOG(AliL3Log::kInformational,"AliL3ConfMapper::InitVolumes","Memory")<<AliL3Log::kDec<<
+    "Allocating "<<fBounds*sizeof(AliL3ConfMapContainer)<<" Bytes to fVolume"<<ENDLOG;
+  LOG(AliL3Log::kInformational,"AliL3ConfMapper::InitVolumes","Memory")<<AliL3Log::kDec<<
+    "Allocating "<<fNumRowSegmentPlusOne*sizeof(AliL3ConfMapContainer)<<" Bytes to fRow"<<ENDLOG;
+  
+  fVolume = new AliL3ConfMapContainer[fBounds];
+  fRow = new AliL3ConfMapContainer[fNumRowSegmentPlusOne];
+  
+  memset(fVolume,0,fBounds*sizeof(AliL3ConfMapContainer));
+  memset(fRow,0,fNumRowSegmentPlusOne*sizeof(AliL3ConfMapContainer));
+  
+  Int_t max_num_of_tracks = 1000;
+  Int_t max_num_of_hits = 50000;
+  
+  if(fHit)
+    delete [] fHit;
+  if(fTrack)
+    delete fTrack;
+    
+  fHit = new AliL3ConfMapPoint[max_num_of_hits];
+  fTrack = new AliL3TrackArray("AliL3ConfMapTrack",max_num_of_tracks);
+}
 
 void AliL3ConfMapper::InitSector(Int_t sector,Int_t *rowrange,Float_t *etarange)
 {
@@ -66,17 +107,7 @@ void AliL3ConfMapper::InitSector(Int_t sector,Int_t *rowrange,Float_t *etarange)
   //rowrange[0]=innermost row;
   //rowrange[1]=outermostrow;
   //Finally you can specify etaslices to save time (assuming a good seed from TRD...)
-  
-  if(fHit)
-    {
-      delete [] fHit;
-    }
-  
-  if(fTrack) 
-    {
-      delete fTrack;
-    }
-
+    
   //Define tracking area:
   if(rowrange)
     {
@@ -86,7 +117,7 @@ void AliL3ConfMapper::InitSector(Int_t sector,Int_t *rowrange,Float_t *etarange)
   else //complete sector
     {
       fRowMin = 0;
-      fRowMax = 173;
+      fRowMax = AliL3Transform::GetNRows() - 1;
     }
   if(etarange)
     {
@@ -96,6 +127,7 @@ void AliL3ConfMapper::InitSector(Int_t sector,Int_t *rowrange,Float_t *etarange)
   else
     {
       fEtaMin = 0;
+      //fEtaMax = sector < 18 ? 1 : -1;
       fEtaMax = sector < 18 ? 0.9 : -0.9;
     }
   
@@ -103,20 +135,17 @@ void AliL3ConfMapper::InitSector(Int_t sector,Int_t *rowrange,Float_t *etarange)
   fPhiMin = -1.*10/todeg;//fParam->GetAngle(sector) - 10/todeg;
   fPhiMax = 10/todeg;//fParam->GetAngle(sector) + 10/todeg;
 
-  //rotation angles for sector 2:
-  //cos: 0.766044 sin: 0.642788
-  
-  Int_t max_num_of_tracks = 3000;
-  Int_t max_num_of_hits = 90000;
-
-  fHit = new AliL3ConfMapPoint[max_num_of_hits];
-  fTrack = new AliL3TrackArray("AliL3ConfMapTrack",max_num_of_tracks);
-  
   nTracks=0;
+  fMainVertexTracks = 0;
   fClustersUnused = 0;
+  fEtaHitsOutOfRange=0;
+  fPhiHitsOutOfRange=0;
   
   fNumRowSegment = fRowMax - fRowMin; //number of rows to be considered by tracker
+  LOG(AliL3Log::kInformational,"AliL3ConfMapper::InitSector","B-field")
+    <<"Tracker initializing with a magnetic field of "<<AliL3Transform::GetBField()<<ENDLOG;
+  
+  fTrack->Reset();
 }
 
 
@@ -125,45 +154,30 @@ Bool_t AliL3ConfMapper::ReadHits(UInt_t count, AliL3SpacePointData* hits )
 {
   Int_t nhit=(Int_t)count; 
   for (Int_t i=0;i<nhit;i++)
-    fHit[i].ReadHits(&(hits[i]));
+    {
+      fHit[i].Reset();
+      fHit[i].ReadHits(&(hits[i]));
+    }
   fClustersUnused += nhit;
-  LOG(AliL3Log::kInformational,"AliL3ConfMapper::ReadHits","#hits")<<AliL3Log::kDec
-  <<"hit_counter: "<<nhit<<" count: "<<count<<ENDLOG;
-
+  LOG(AliL3Log::kInformational,"AliL3ConfMapper::ReadHits","#hits")
+    <<AliL3Log::kDec<<"hit_counter: "<<nhit<<" count: "<<count<<ENDLOG;
+  
   return true;
 }
 
 
 void AliL3ConfMapper::SetPointers()
 {
-  //Data organization.
-  //Allocate volumes, set conformal coordinates and pointers.
-  fNumRowSegmentPlusOne = 174;//fNumRowSegment+1;
-  fNumPhiSegmentPlusOne = fNumPhiSegment+1;
-  fNumEtaSegmentPlusOne = fNumEtaSegment+1;
-  fNumPhiEtaSegmentPlusOne = fNumPhiSegmentPlusOne*fNumEtaSegmentPlusOne;
-  fBounds = fNumRowSegmentPlusOne * fNumPhiSegmentPlusOne * fNumEtaSegmentPlusOne;
-  
-  //Allocate volumes:
-  if(fVolume) delete [] fVolume;
-  if(fRow) delete [] fRow;
   
-  LOG(AliL3Log::kInformational,"AliL3ConfMapper::SetPointers","Memory")<<AliL3Log::kDec<<
-    "Allocating "<<fBounds*sizeof(AliL3ConfMapContainer)<<" Bytes to fVolume"<<ENDLOG;
-  LOG(AliL3Log::kInformational,"AliL3ConfMapper::SetPointers","Memory")<<AliL3Log::kDec<<
-    "Allocating "<<fNumRowSegmentPlusOne*sizeof(AliL3ConfMapContainer)<<" Bytes to fRow"<<ENDLOG;
-  
-  fVolume = new AliL3ConfMapContainer[fBounds];
-  fRow = new AliL3ConfMapContainer[fNumRowSegmentPlusOne];
-
-  //set volumes to zero:
+  //Reset detector volumes
   memset(fVolume,0,fBounds*sizeof(AliL3ConfMapContainer));
   memset(fRow,0,fNumRowSegmentPlusOne*sizeof(AliL3ConfMapContainer));
   
   Float_t phiSlice = (fPhiMax-fPhiMin)/fNumPhiSegment;
   Float_t etaSlice = (fEtaMax-fEtaMin)/fNumEtaSegment;
-  
+
   Int_t volumeIndex;
+  Int_t local_counter=0;
   for(Int_t j=0; j<fClustersUnused; j++)
     {
       
@@ -174,12 +188,8 @@ void AliL3ConfMapper::SetPointers()
       
       Int_t localrow = thisHit->GetPadRow();
       
-      //reset pointers:
-      thisHit->nextVolumeHit=thisHit->nextRowHit=0;
-      
       if(localrow < fRowMin || localrow > fRowMax)
        continue;
-      
 
       //Get indexes:
       thisHit->phiIndex=(Int_t)((thisHit->GetPhi()-fPhiMin)/phiSlice +1);
@@ -196,25 +206,35 @@ void AliL3ConfMapper::SetPointers()
          fEtaHitsOutOfRange++;
          continue;
        }
-                  
-      //set volume pointers
-      volumeIndex = localrow*fNumPhiEtaSegmentPlusOne+thisHit->phiIndex*fNumEtaSegmentPlusOne+thisHit->etaIndex;
+      local_counter++;
+      
+      volumeIndex = (localrow-fRowMin)*fNumPhiEtaSegmentPlusOne+thisHit->phiIndex*fNumEtaSegmentPlusOne+thisHit->etaIndex;
+      
       if(fVolume[volumeIndex].first == NULL)
        fVolume[volumeIndex].first = (void *)thisHit;
       else
-       ((AliL3ConfMapPoint *)fVolume[volumeIndex].last)->nextVolumeHit=thisHit;
+       ((AliL3ConfMapPoint *)fVolume[volumeIndex].last)->nextVolumeHit=thisHit;
       fVolume[volumeIndex].last = (void *)thisHit;
       
       
       //set row pointers
-      if(fRow[localrow].first == NULL)
-       fRow[localrow].first = (void *)thisHit;
+      if(fRow[(localrow-fRowMin)].first == NULL)
+       fRow[(localrow-fRowMin)].first = (void *)thisHit;
       else
-       ((AliL3ConfMapPoint *)(fRow[localrow].last))->nextRowHit = thisHit;
-      fRow[localrow].last = (void *)thisHit;
-      
+       ((AliL3ConfMapPoint *)(fRow[(localrow-fRowMin)].last))->nextRowHit = thisHit;
+       fRow[(localrow-fRowMin)].last = (void *)thisHit;
+       
+       
     }
   
+  if(fClustersUnused>0 && local_counter==0)
+    LOG(AliL3Log::kError,"AliL3ConfMapper::SetPointers","Parameters")
+      <<AliL3Log::kDec<<"No points passed to track finder, hits out of range: "
+      <<fEtaHitsOutOfRange+fPhiHitsOutOfRange<<ENDLOG;
+
+  LOG(AliL3Log::kInformational,"AliL3ConfMapper::SetPointers","Setup")
+    <<"Setup finished, hits out of range: "<<fEtaHitsOutOfRange+fPhiHitsOutOfRange
+    <<" hits accepted "<<fClustersUnused<<ENDLOG;
 }
 
 void AliL3ConfMapper::MainVertexTracking_a()
@@ -228,9 +248,15 @@ void AliL3ConfMapper::MainVertexTracking_a()
       return;
     }
 
-  
+  Double_t initCpuTime,cpuTime;
+  initCpuTime = CpuTime();
   SetPointers();
   SetVertexConstraint(true);
+  cpuTime = CpuTime() - initCpuTime;
+  if(fBench)
+    LOG(AliL3Log::kInformational,"AliL3ConfMapper::MainVertexTracking_a","Timing")
+      <<AliL3Log::kDec<<"Setup finished in "<<cpuTime*1000<<" ms"<<ENDLOG;
+  
 }
 
 void AliL3ConfMapper::MainVertexTracking_b()
@@ -243,8 +269,15 @@ void AliL3ConfMapper::MainVertexTracking_b()
        "Tracking parameters not set!"<<ENDLOG;
       return;
     }
-
+  Double_t initCpuTime,cpuTime;
+  initCpuTime = CpuTime();
+  
   ClusterLoop();
+  cpuTime = CpuTime() - initCpuTime;
+  if(fBench)
+    LOG(AliL3Log::kInformational,"AliL3ConfMapper::MainVertexTracking_b","Timing")
+      <<AliL3Log::kDec<<"Main Tracking finished in "<<cpuTime*1000<<" ms"<<ENDLOG;
 }
 
 void AliL3ConfMapper::MainVertexTracking()
@@ -270,7 +303,7 @@ void AliL3ConfMapper::MainVertexTracking()
   if(fBench)
     LOG(AliL3Log::kInformational,"AliL3ConfMapper::MainVertexTracking","Timing")<<AliL3Log::kDec<<
       "Tracking finished in "<<cpuTime*1000<<" ms"<<ENDLOG;
-    
+  
   return;
 }
 
@@ -284,8 +317,7 @@ void AliL3ConfMapper::NonVertexTracking()
   SetVertexConstraint(false);
   ClusterLoop();
   LOG(AliL3Log::kInformational,"AliL3ConfMapper::NonVertexTracking","ntracks")<<AliL3Log::kDec<<
-    "Number of nonvertex tracks found: "<<nTracks-fMainVertexTracks<<ENDLOG;
-
+    "Number of nonvertex tracks found: "<<(nTracks-fMainVertexTracks)<<ENDLOG;
   return;
 }
 
@@ -305,7 +337,6 @@ void AliL3ConfMapper::MainVertexSettings(Int_t trackletlength, Int_t tracklength
   SetMinPoints(tracklength,(Bool_t)true);
   fMaxPhi=maxphi;
   fMaxEta=maxeta;
-  
 }
 
 void AliL3ConfMapper::NonVertexSettings(Int_t trackletlength, Int_t tracklength,
@@ -317,18 +348,19 @@ void AliL3ConfMapper::NonVertexSettings(Int_t trackletlength, Int_t tracklength,
   SetMinPoints(tracklength,(Bool_t)false);
 }
 
-void AliL3ConfMapper::SetTrackCuts(Double_t hitChi2Cut, Double_t goodHitChi2, Int_t trackChi2Cut,Int_t maxdist)
+void AliL3ConfMapper::SetTrackCuts(Double_t hitChi2Cut, Double_t goodHitChi2, Double_t trackChi2Cut,Int_t maxdist,
+                                  Bool_t vertexconstraint)
 {
   //Settings for tracks. The cuts are:
   //HitChi2Cut:     Maximum hit chi2
   //goodHitChi2:    Chi2 to stop look for next hit
   //trackChi2Cut:   Maximum track chi2
   //maxdist:        Maximum distance between two clusters when forming segments
-
-  fHitChi2Cut = hitChi2Cut;
-  fGoodHitChi2 = goodHitChi2;
-  fTrackChi2Cut = trackChi2Cut;
-  fMaxDist = maxdist;
+  
+  SetHitChi2Cut(hitChi2Cut,vertexconstraint);
+  SetGoodHitChi2(goodHitChi2,vertexconstraint);
+  SetTrackChi2Cut(trackChi2Cut,vertexconstraint);
+  SetMaxDist(maxdist,vertexconstraint);
 }
 
 void AliL3ConfMapper::SetTrackletCuts(Double_t maxangle,Double_t goodDist, Bool_t vertex_constraint)
@@ -352,9 +384,9 @@ void AliL3ConfMapper::ClusterLoop()
   
   for(row_segm = fRowMax; row_segm >= lastrow; row_segm--)
     {
-      if(fRow[row_segm].first && ((AliL3ConfMapPoint*)fRow[row_segm].first)->GetPadRow() < fRowMin + 1)
+      if(fRow[(row_segm-fRowMin)].first && ((AliL3ConfMapPoint*)fRow[(row_segm-fRowMin)].first)->GetPadRow() < fRowMin + 1)
        break;
-      for(hit = (AliL3ConfMapPoint*)fRow[row_segm].first; hit!=0; hit=hit->nextRowHit)
+      for(hit = (AliL3ConfMapPoint*)fRow[(row_segm-fRowMin)].first; hit!=0; hit=hit->nextRowHit)
        {
          if(hit->GetUsage() == true)
            continue;
@@ -437,7 +469,6 @@ void AliL3ConfMapper::CreateTrack(AliL3ConfMapPoint *hit)
             
       if(TrackletAngle(track) > fMaxAngleTracklet[fVertexConstraint])
        {//proof if the first points seem to be a beginning of a track
-       
          track->SetProperties(false);
          track->DeleteCandidate();
          fTrack->RemoveLast();
@@ -454,7 +485,7 @@ void AliL3ConfMapper::CreateTrack(AliL3ConfMapPoint *hit)
          
          for(point = fTrackletLength[fVertexConstraint]; point <= fNumRowSegment; point++)
            {
-             track->fChiSq[0] = fHitChi2Cut;
+             track->fChiSq[0] = fHitChi2Cut[fVertexConstraint];
              closest_hit = GetNextNeighbor((AliL3ConfMapPoint*)track->lastHit,track);
              
              if(closest_hit)
@@ -477,9 +508,9 @@ void AliL3ConfMapper::CreateTrack(AliL3ConfMapPoint *hit)
                  //add closest hit to track
                  closest_hit->SetUsage(true);
                  closest_hit->SetTrackNumber(tracks-1);
-               
+                 
                }//closest_hit
-           
+             
              else
                {
                  //closest hit does not exist
@@ -494,7 +525,7 @@ void AliL3ConfMapper::CreateTrack(AliL3ConfMapPoint *hit)
          Double_t normalized_chi2 = (track->fChiSq[0]+track->fChiSq[1])/track->GetNumberOfPoints();
          
          //remove tracks with not enough points already now
-         if(track->GetNumberOfPoints() < fMinPoints[fVertexConstraint] || normalized_chi2 > fTrackChi2Cut)
+         if(track->GetNumberOfPoints() < fMinPoints[fVertexConstraint] || normalized_chi2 > fTrackChi2Cut[fVertexConstraint])
            {
              track->SetProperties(false);
              nTracks--;
@@ -528,7 +559,7 @@ AliL3ConfMapPoint *AliL3ConfMapper::GetNextNeighbor(AliL3ConfMapPoint *start_hit
   //When forming segments: Finds closest hit to input hit
   //When forming tracks: Find closest hit to track fit.
   
-  Double_t dist,closest_dist = fMaxDist;
+  Double_t dist,closest_dist = fMaxDist[fVertexConstraint];
   
   AliL3ConfMapPoint *hit = NULL;
   AliL3ConfMapPoint *closest_hit = NULL;
@@ -584,7 +615,7 @@ AliL3ConfMapPoint *AliL3ConfMapper::GetNextNeighbor(AliL3ConfMapPoint *start_hit
                continue;//segment exceeds bounds->skip it
              
              //loop over hits in this sub segment:
-             volumeIndex= sub_row_segm*fNumPhiEtaSegmentPlusOne +
+             volumeIndex= (sub_row_segm-fRowMin)*fNumPhiEtaSegmentPlusOne +
                sub_phi_segm*fNumEtaSegmentPlusOne + sub_eta_segm;
              
              if(volumeIndex<0)
@@ -697,7 +728,7 @@ Int_t AliL3ConfMapper::EvaluateHit(AliL3ConfMapPoint *start_hit,AliL3ConfMapPoin
       hit->SetS(slocal);
   
       //if chi2 good enough, stop here:
-      if(lchi2 < fGoodHitChi2) 
+      if(lchi2 < fGoodHitChi2[fVertexConstraint]
         return 2;
       
       return 1;
@@ -714,7 +745,7 @@ Double_t AliL3ConfMapper::CalcDistance(const AliL3ConfMapPoint *hit1,const AliL3
   Double_t phi_diff = fabs( hit1->GetPhi() - hit2->GetPhi() );
   if (phi_diff > pi) phi_diff = twopi - phi_diff;
   
-  return todeg*fabs(hit1->GetPadRow() - hit2->GetPadRow()) * (phi_diff + fabs( hit1->GetEta() - hit2->GetEta() ));
+  return todeg*fabs((Float_t)((hit1->GetPadRow() - hit2->GetPadRow()) * (phi_diff + fabs( hit1->GetEta() - hit2->GetEta()))));
 }
 
 Bool_t AliL3ConfMapper::VerifyRange(const AliL3ConfMapPoint *hit1,const AliL3ConfMapPoint *hit2) const
@@ -792,6 +823,8 @@ Int_t AliL3ConfMapper::FillTracks()
 Double_t AliL3ConfMapper::CpuTime()
 {
   //Return the Cputime in seconds.
-
-  return (Double_t)(clock()) / CLOCKS_PER_SEC;
+ struct timeval tv;
+ gettimeofday( &tv, NULL );
+ return tv.tv_sec+(((Double_t)tv.tv_usec)/1000000.);
+ //return (Double_t)(clock()) / CLOCKS_PER_SEC;
 }