]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSTrackSegmentMakerv1.cxx
new amplitude calibration up to 50 MIPs
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegmentMakerv1.cxx
index 819ebd9163545375eb6dc501ae70c465193314bd..8135da99385ab17e2f28a6e325d46a99a9d25d6c 100644 (file)
 //
 
 // --- ROOT system ---
+#include "TVector3.h"
 #include "TTree.h"
 #include "TBenchmark.h"
 
 #include "AliESDtrack.h"
 #include "AliPHOSEmcRecPoint.h"
 #include "AliPHOSCpvRecPoint.h"
+#include "AliLog.h"
+#include "AliMagF.h"
+#include "AliMagF.h"
+#include "AliTracker.h"
+#include "AliGeomManager.h"
+#include "AliCluster.h"
+#include "AliKalmanTrack.h"
+#include "AliGlobalQADataMaker.h"
+#include "AliVParticle.h"
+
 
 ClassImp( AliPHOSTrackSegmentMakerv1) 
 
@@ -246,67 +257,156 @@ void  AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * em
 //                       // if you change this value, change it as well in xxxRecPoint::Compare()
 
   if(!cpvClu) {
+    
+    trackindex = -1;
+    dx=999.;
+    dz=999.;
+    
+    if(!emcClu) {
+      return;
+    }
 
-    TVector3 emcGlobal;
-    fGeom->GetGlobalPHOS((AliPHOSRecPoint*)emcClu,emcGlobal);
-
-    TVector3 emcLocal;
-    emcClu->GetLocalPosition(emcLocal);
+    // *** Start the matching
+    Int_t nt=fESD->GetNumberOfTracks();
+    Int_t iPHOSMod = emcClu->GetPHOSMod()  ;
+    //Calculate actual distance to PHOS module
+    TVector3 globaPos ;
+    fGeom->Local2Global(iPHOSMod, 0.,0., globaPos) ;
+    const Double_t rPHOS = globaPos.Pt() ; //Distance to PHOS module
+    const Double_t kYmax = 72.+10. ; //Size of the module (with some reserve) in phi direction
+    const Double_t kZmax = 64.+10. ; //Size of the module (with some reserve) in z direction
+    const Double_t kAlpha= 20./180.*TMath::Pi() ; //TPC sector angular size
+    Double_t minDistance = 1.e6;
 
-    // Radius from IP to current point
-    Double_t rEMC = emcGlobal.Pt() ;
+    TMatrixF gmat;
+    TVector3 gposRecPoint; // global (in ALICE frame) position of rec. point
+    emcClu->GetGlobalPosition(gposRecPoint,gmat);
+    Double_t gposTrack[3] ; 
+
+    Double_t bz = AliTracker::GetBz() ; //B-Field for approximate matching
+    Double_t b[3]; 
+    for (Int_t i=0; i<nt; i++) {
+      AliESDtrack *esdTrack=fESD->GetTrack(i);
+
+//     // Skip the tracks having "wrong" status (has to be checked/tuned)
+//     ULong_t status = esdTrack->GetStatus();
+//     if ((status & AliESDtrack::kTRDout)   == 0) continue;
+//     if ((status & AliESDtrack::kTRDrefit) == 1) continue;
+
+      AliExternalTrackParam t(*esdTrack);
+      Int_t isec=Int_t(t.GetAlpha()/kAlpha);
+      Int_t imod=-isec-2; // PHOS module
+
+      Double_t y;                       // Some tracks do not reach the PHOS
+      if (!t.GetYAt(rPHOS,bz,y)) continue; //    because of the bending
+
+      Double_t z; t.GetZAt(rPHOS,bz,z);
+      if (TMath::Abs(z) > kZmax) continue; // Some tracks miss the PHOS in Z
+
+      Bool_t ok=kTRUE;
+      while (TMath::Abs(y) > kYmax) {   // Find the matching module
+        Double_t alp=t.GetAlpha();
+        if (y > kYmax) {
+          if (!t.Rotate(alp+kAlpha)) {ok=kFALSE; break;}
+          imod--;
+        } else if (y < -kYmax) {
+          if (!t.Rotate(alp-kAlpha)) {ok=kFALSE; break;}
+          imod++;
+        }
+        if (!t.GetYAt(rPHOS,bz,y)) {ok=kFALSE; break;}
+      }
+      if (!ok) continue; // Track rotation failed
 
-    // Extrapolate the global track direction to EMC
-    // and find the closest track
 
-    Int_t nTracks = fESD->GetNumberOfTracks();
-    Int_t iClosestTrack = -1;
-    Double_t minDistance = 1.e6;
-    Float_t delta_x,delta_z,distance2Track;
-    
-    AliESDtrack *track;
-    Double_t xyz[3] ;
+      if(imod!= iPHOSMod-1) 
+       continue; //not even approximate coincidence
 
-    for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
-      track = fESD->GetTrack(iTrack);
-      if (!track->GetXYZAt(rEMC, fESD->GetMagneticField(), xyz)) continue;
-      printf("track prolongation: (%.3f,%.3f,%.3f)  emcGlobal: (%.3f,%.3f,%.3f)\n",
-             xyz[0], xyz[1],xyz[2],emcGlobal.X(),emcGlobal.Y(),emcGlobal.Z());
+      //t.CorrectForMaterial(...); // Correct for the TOF material, if needed
+      t.GetBxByBz(b) ;
+      t.PropagateToBxByBz(rPHOS,b);        // Propagate to the matching module
+      t.GetXYZ(gposTrack) ;
       
-      TVector3 globTrack(xyz);
-      TVector3 locTrack;
-      Int_t phosMod = emcClu->GetPHOSMod();
-      fGeom->Global2Local(locTrack,globTrack,phosMod);
-      delta_x = locTrack.X()-emcLocal.X();
-      delta_z = locTrack.Z()-emcLocal.Z();
-      printf("delta_x: %.3f  delta_z: %.3f. PHOS module: %d\n",
-            delta_x,delta_z,phosMod);
-
-      distance2Track = TMath::Sqrt(delta_x*delta_x + delta_z*delta_z);
-
-      if (distance2Track < minDistance) {
-        minDistance = distance2Track;
-        iClosestTrack = iTrack;
-        dx = delta_x;
-        dz = delta_z;
+      Double_t ddx = gposTrack[0] - gposRecPoint.X(), ddy = gposTrack[1] - gposRecPoint.Y(), ddz = gposTrack[2] - gposRecPoint.Z();
+      Double_t d2 = ddx*ddx + ddy*ddy + ddz*ddz;
+      if(d2 < minDistance) {
+       dx = TMath::Sign(TMath::Sqrt(ddx*ddx + ddy*ddy),ddx) ;
+       dz = ddz ;
+       trackindex=i;
+       minDistance=d2 ;
       }
     }
+    return ;
+  }
 
-    trackindex = iClosestTrack;
-    if(trackindex <0) {
-      dx=999.;
-      dz=999.;
-    }
 
-    return;
+  TVector3 emcGlobal;
+  fGeom->GetGlobalPHOS((AliPHOSRecPoint*)emcClu,emcGlobal);
+    
+  // Radius from IP to current point
+  Double_t rEMC = TMath::Abs(emcGlobal.Pt());
+    
+  // Extrapolate the global track direction to EMC
+  // and find the closest track
+    
+  Int_t nTracks = fESD->GetNumberOfTracks();
+    
+  AliESDtrack *track;
+  Double_t xyz[] = {-1,-1,-1};
+  Double_t pxyz[3];
+  Double_t zEMC,xEMC;
+  Int_t module;
+  TVector3 vecP;
+  TVector3 locClu;
+
+  Float_t minDistance = 1.e6;
+  Float_t dr;
+
+  for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
+    track = fESD->GetTrack(iTrack);
+    if (!track->GetXYZAt(rEMC, fESD->GetMagneticField(), xyz)) continue;
+    
+    AliDebug(1,Form("Event %d, iTrack: %d, (%.3f,%.3f,%.3f)",
+                   fESD->GetEventNumberInFile(),iTrack,xyz[0],xyz[1],xyz[2]));
+      
+    if (track->GetPxPyPzAt(rEMC,fESD->GetMagneticField(),pxyz)) { 
+
+      vecP.SetXYZ(pxyz[0],pxyz[1],pxyz[2]);
+      fGeom->ImpactOnEmc(xyz,vecP.Theta(),vecP.Phi(),module,zEMC,xEMC) ;
+
+      if(!module) continue;
+      AliDebug(1,Form("\t\tTrack hit PHOS! Module: %d, (x,z)=(%.3f,%.3f)",module,xEMC,zEMC));
+       
+      if(emcClu->GetPHOSMod() != module) continue;
+       
+      // match track to EMC cluster
+      emcClu->GetLocalPosition(locClu);
+       
+      Float_t delta_x = xEMC - locClu.X();
+      Float_t delta_z = zEMC - locClu.Z();
+      dr = TMath::Sqrt(delta_x*delta_x + delta_z*delta_z);
+      AliDebug(1,Form("\tMatch iTrack=%d: (dx,dz)=(%.3f,%.3f)",iTrack,delta_x,delta_z));
+       
+      if(dr<minDistance) {
+       trackindex = iTrack;
+       minDistance = dr;
+       dx = delta_x;
+       dz = delta_z;
+      }
+    }
+      
   }
+    
+  if(trackindex>=0)
+    AliDebug(1,Form("\t\tBest match for (xClu,zClu,eClu)=(%.3f,%.3f,%.3f): iTrack=%d, dR=%.3f",
+                   locClu.X(),locClu.Z(),emcClu->GetEnergy(),
+                   trackindex,TMath::Sqrt(dx*dx+dz*dz)));        
+  return;
   
   Float_t distance2Track = fRtpc ; 
   
   trackindex = -1 ; // closest track within fRCpv 
-
+  
   TVector3 vecEmc ;   // Local position of EMC recpoint
-  TVector3 vecP ;     // Momentum direction at CPV plain
   TVector3 vecPloc ;     // Momentum direction at CPV plain
   
   //toofar = kTRUE ;
@@ -315,9 +415,9 @@ void  AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * em
     dz=999. ;
     return ;
   }
-
+  
   emcClu->GetLocalPosition(vecEmc) ;
-
+  
   Double_t xCPV,zCPV ; //EMC-projected coordinates of CPV cluster 
   TVector3 cpvGlobal; // Global position of the CPV recpoint
   fGeom->GetGlobalPHOS((AliPHOSRecPoint*)cpvClu,cpvGlobal);
@@ -325,40 +425,35 @@ void  AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * em
   Int_t dummyMod ;
 
   if (fESD == 0x0) {
-     //if no track information available, assume straight line from IP to emcal
-     fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
-     dx=xCPV - vecEmc.X() ;
-     dz=zCPV - vecEmc.Z() ;
-     return ;
+    //if no track information available, assume straight line from IP to emcal
+    fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
+    dx=xCPV - vecEmc.X() ;
+    dz=zCPV - vecEmc.Z() ;
+    return ;
   } 
-
+  
   //if there is ESD try to correct distance using TPC information on particle direct in CPV 
   if (fESD != 0x0) {
 
     Double_t rCPV = cpvGlobal.Pt() ;// Radius from IP to current point 
 
     // Extrapolate the global track direction if any to CPV and find the closest track
-    Int_t nTracks = fESD->GetNumberOfTracks();
     Int_t iClosestTrack = -1;
-    Double_t minDistance = 1.e6;
     TVector3 inPHOS ; 
 
-    AliESDtrack *track;
-    Double_t xyz[3] ;
-    Double_t pxyz[3]; 
     for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
       track = fESD->GetTrack(iTrack);
       if (!track->GetXYZAt(rCPV, fESD->GetMagneticField(), xyz))
-           continue; //track coord on the cylinder of PHOS radius
+       continue; //track coord on the cylinder of PHOS radius
       if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
-          continue;
+       continue;
       //Check if this track hits PHOS
       inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
       distance2Track = inPHOS.Angle(cpvGlobal) ;
       // Find the closest track to the CPV recpoint
       if (distance2Track < minDistance) {
-         minDistance = distance2Track;
-        iClosestTrack = iTrack;
+       minDistance = distance2Track;
+       iClosestTrack = iTrack;
       }
     }
 
@@ -545,7 +640,7 @@ void AliPHOSTrackSegmentMakerv1::Clusters2TrackSegments(Option_t *option)
   fTrackSegments->Clear();
 
   //   if(!ReadRecPoints(ievent))   continue; //reads RecPoints for event ievent
-    
+
   for(fModule = 1; fModule <= fGeom->GetNModules() ; fModule++ ) {
     FillOneModule() ; 
     MakeLinks() ;
@@ -598,3 +693,4 @@ void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
     }  
   }
 }
+