Main changes:
[u/mrichter/AliRoot.git] / MUON / AliMUONTracker.cxx
index 54ab081..ffd551b 100644 (file)
 
 /* $Id$ */
 
+//-----------------------------------------------------------------------------
 /// \class AliMUONTracker
 ///
 /// Steering class for use in global tracking framework;
 /// reconstruct tracks from recpoints
 ///
 /// Actual tracking is performed by some AliMUONVTrackReconstructor children
+/// Tracking modes (ORIGINAL, KALMAN) and associated options and parameters
+/// can be changed by using:
+/// AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLow(High)FluxParam();
+/// muonRecoParam->Set...(); // see methods in AliMUONRecoParam.h for details
+/// AliMUONReconstructor::SetRecoParam(muonRecoParam);
 ///
 /// \author Christian Finck and Laurent Aphecetche, SUBATECH Nantes
+//-----------------------------------------------------------------------------
 
 #include "AliMUONTracker.h"
 
+#include "AliMUONReconstructor.h"
+#include "AliMUONRecoParam.h"
 #include "AliMUONTrack.h"
 #include "AliMUONTrackExtrap.h"
 #include "AliMUONTrackHitPattern.h"
 #include "AliMUONTrackParam.h"
+#include "AliMUONVCluster.h"
 #include "AliMUONTrackReconstructor.h"
 #include "AliMUONTrackReconstructorK.h"
 #include "AliMUONTrackStoreV1.h"
 #include "AliESDEvent.h"
 #include "AliESDMuonTrack.h"
 #include "AliESDVertex.h"
-#include "AliLoader.h"
 #include "AliLog.h"
+#include "AliCodeTimer.h"
 
 #include <Riostream.h>
 #include <TTree.h>
 
+/// \cond CLASSIMP
+ClassImp(AliMUONTracker)
+/// \endcond
+
+
 //_____________________________________________________________________________
-AliMUONTracker::AliMUONTracker(AliLoader* loader,
-                               const AliMUONDigitMaker* digitMaker,
+AliMUONTracker::AliMUONTracker(const AliMUONDigitMaker* digitMaker,
                                const AliMUONGeometryTransformer* transformer,
                                const AliMUONTriggerCircuit* triggerCircuit,
-                              AliMUONTriggerChamberEff* chamberEff)
+                               AliMUONTriggerChamberEff* chamberEff)
 : AliTracker(),
-  fLoader(loader),
   fDigitMaker(digitMaker), // not owner
   fTransformer(transformer), // not owner
   fTriggerCircuit(triggerCircuit), // not owner
@@ -66,9 +79,7 @@ AliMUONTracker::AliMUONTracker(AliLoader* loader,
 {
   /// constructor
   if (fTransformer && fDigitMaker)
-  {
     fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
-  }
 }
 
 //_____________________________________________________________________________
@@ -82,13 +93,17 @@ AliMUONTracker::~AliMUONTracker()
 }
 
 //_____________________________________________________________________________
-Int_t 
-AliMUONTracker::LoadClusters(TTree* clustersTree)
+Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
 {
   /// Load clusterStore and triggerStore from clustersTree
   delete fClusterStore;
   delete fTriggerStore;
 
+  if ( ! clustersTree ) {
+    AliFatal("No clustersTree");
+    return 1;
+  }
+
   fClusterStore = AliMUONVClusterStore::Create(*clustersTree);
   fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
   
@@ -112,78 +127,51 @@ AliMUONTracker::LoadClusters(TTree* clustersTree)
 }
 
 //_____________________________________________________________________________
-Int_t
-AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
+Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
 {
-  /// Performs the tracking and store the resulting tracks in both
-  /// the TreeT and the ESD
+  /// Performs the tracking and store the resulting tracks in the ESD
+  AliDebug(1,"");
+  AliCodeTimerAuto("")
   
-  Int_t rv(0);
+  if (!fTrackReco) CreateTrackReconstructor();
   
-  TTree* tracksTree = fLoader->TreeT();
+  // if the required tracking mode does not exist
+  if  (!fTrackReco) return 1;
   
-  if (!tracksTree)
-  {
-    AliError("Cannot get TreeT");
-    rv=1;
-  }
-  if (!fClusterStore)
-  {
+  if (!fClusterStore) {
     AliError("ClusterStore is NULL");
-    rv=2;
+    return 2;
   }
-  if (!fTriggerStore)
-  {
+  
+  if (!fTriggerStore) {
     AliError("TriggerStore is NULL");
-    rv=3;
-  }
-  if (!rv)
-  {
-    rv = Clusters2Tracks(*tracksTree,esd);
+    return 3;
   }
-  return rv;
-}
-
-//_____________________________________________________________________________
-Int_t AliMUONTracker::Clusters2Tracks(TTree& tracksTree, AliESDEvent* esd)
-{
-  /// Performs the tracking
-  
-  AliDebug(1,"");
-  
-  AliMUONVTrackStore* trackStore(0x0);
-  AliMUONVTriggerTrackStore* triggerTrackStore(0x0);
   
   // Make tracker tracks
-  if ( fClusterStore ) 
-  {
-    trackStore = new AliMUONTrackStoreV1;
-    Bool_t alone = ( ( fTriggerStore && fTriggerCircuit ) ? kFALSE : kTRUE );
-    trackStore->Connect(tracksTree,alone);
-    fTrackReco->EventReconstruct(*fClusterStore,*trackStore);
-  }
+  AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
+  fTrackReco->EventReconstruct(*fClusterStore,*trackStore);
   
-  if ( fTriggerStore && fTriggerCircuit )
-  {
-    // Make trigger tracks
+  // Make trigger tracks
+  AliMUONVTriggerTrackStore* triggerTrackStore(0x0);
+  if ( fTriggerCircuit ) {
     triggerTrackStore = new AliMUONTriggerTrackStoreV1;
-    Bool_t alone = ( fClusterStore ? kFALSE : kTRUE );
-    triggerTrackStore->Connect(tracksTree,alone);
     fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*triggerTrackStore);
   }
 
-  if ( trackStore && triggerTrackStore && fTriggerStore && fTrackHitPatternMaker )
-  {
+  // Match tracker/trigger tracks
+  if ( triggerTrackStore && fTrackHitPatternMaker ) {
     fTrackReco->ValidateTracksWithTrigger(*trackStore,*triggerTrackStore,*fTriggerStore,*fTrackHitPatternMaker);
   }
   
-  // Fills output TreeT 
-  tracksTree.Fill();
-
-  if( trackStore && triggerTrackStore && fTriggerStore && fTrigChamberEff){
+  // Compute trigger chamber efficiency
+  if( triggerTrackStore && fTrigChamberEff){
+      AliCodeTimerStart("EventChamberEff");
       fTrigChamberEff->EventChamberEff(*fTriggerStore,*triggerTrackStore,*trackStore);
+      AliCodeTimerStop("EventChamberEff");
   }
-
+  
+  // Fill ESD
   FillESD(*trackStore,esd);
   
   // cleanup
@@ -194,12 +182,11 @@ Int_t AliMUONTracker::Clusters2Tracks(TTree& tracksTree, AliESDEvent* esd)
 }
 
 //_____________________________________________________________________________
-void 
-AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
+void AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
 {
   /// Fill the ESD from the trackStore
-  
   AliDebug(1,"");
+  AliCodeTimerAuto("")
   
   // Get vertex 
   Double_t vertex[3] = {0};
@@ -218,7 +205,7 @@ AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
   
   while ( ( track = static_cast<AliMUONTrack*>(next()) ) )
   {
-    AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track->GetTrackParamAtHit())->First());
+    AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track->GetTrackParamAtCluster())->First());
     AliMUONTrackParam trackParamAtVtx(*trackParam);
     
     /// Extrapolate to vertex (which is set to (0,0,0) if not available, see above)
@@ -227,25 +214,21 @@ AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
     // setting data member of ESD MUON
     
     // at first station
-    esdTrack.SetInverseBendingMomentumUncorrected(trackParam->GetInverseBendingMomentum());
-    esdTrack.SetThetaXUncorrected(TMath::ATan(trackParam->GetNonBendingSlope()));
-    esdTrack.SetThetaYUncorrected(TMath::ATan(trackParam->GetBendingSlope()));
-    esdTrack.SetZUncorrected(trackParam->GetZ());
-    esdTrack.SetBendingCoorUncorrected(trackParam->GetBendingCoor());
-    esdTrack.SetNonBendingCoorUncorrected(trackParam->GetNonBendingCoor());
+    trackParam->SetParamForUncorrected(esdTrack);
+    trackParam->SetCovFor(esdTrack);
     // at vertex
-    esdTrack.SetInverseBendingMomentum(trackParamAtVtx.GetInverseBendingMomentum());
-    esdTrack.SetThetaX(TMath::ATan(trackParamAtVtx.GetNonBendingSlope()));
-    esdTrack.SetThetaY(TMath::ATan(trackParamAtVtx.GetBendingSlope()));
-    esdTrack.SetZ(trackParamAtVtx.GetZ());
-    esdTrack.SetBendingCoor(trackParamAtVtx.GetBendingCoor());
-    esdTrack.SetNonBendingCoor(trackParamAtVtx.GetNonBendingCoor());
+    trackParamAtVtx.SetParamFor(esdTrack);
     // global info
-    esdTrack.SetChi2(track->GetFitFMin());
-    esdTrack.SetNHit(track->GetNTrackHits());
+    esdTrack.SetChi2(track->GetGlobalChi2());
+    esdTrack.SetNHit(track->GetNClusters());
     esdTrack.SetLocalTrigger(track->GetLocalTrigger());
     esdTrack.SetChi2MatchTrigger(track->GetChi2MatchTrigger());
     esdTrack.SetHitsPatternInTrigCh(track->GetHitsPatternInTrigCh());
+    // muon cluster map
+    while (trackParam) {
+      esdTrack.AddInMuonClusterMap(trackParam->GetClusterPtr()->GetChamberId());
+      trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
+    }
     
     // storing ESD MUON Track into ESD Event 
     esd->AddMuonTrack(&esdTrack);
@@ -253,23 +236,32 @@ AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
 }
 
 //_____________________________________________________________________________
-void AliMUONTracker::SetOption(Option_t* option)
+void AliMUONTracker::CreateTrackReconstructor()
 {
-  /// set reconstructor class
+  /// Create track reconstructor, depending on tracking mode set in RecoParam
   
-  if (strstr(option,"Original")) 
+  TString opt(AliMUONReconstructor::GetRecoParam()->GetTrackingMode());
+  opt.ToUpper();
+  
+  if (strstr(opt,"ORIGINAL"))
   {
-    fTrackReco = new AliMUONTrackReconstructor;
+    fTrackReco = new AliMUONTrackReconstructor();
   }
-  else 
+  else if (strstr(opt,"KALMAN"))
   {
     fTrackReco = new AliMUONTrackReconstructorK();
   }
+  else
+  {
+    AliError(Form("tracking mode \"%s\" does not exist",opt.Data()));
+    return;
+  }
+  
+  AliInfo(Form("Will use %s for tracking",fTrackReco->ClassName()));
 }
 
 //_____________________________________________________________________________
-void 
-AliMUONTracker::UnloadClusters()
+void AliMUONTracker::UnloadClusters()
 {
   /// Delete internal clusterStore
   delete fClusterStore;