Adding PiKP-only histograms and eliminating a number of switches where histograms...
[u/mrichter/AliRoot.git] / MUON / AliMUONTracker.cxx
index baa20bf..462d4e3 100644 (file)
 #include "AliMUONVClusterServer.h"
 #include "AliMUONVDigitStore.h"
 #include "AliMUONVTriggerStore.h"
+#include "AliMUONTriggerUtilities.h"
 #include <Riostream.h>
 #include <TRandom.h>
 #include <TTree.h>
+#include "AliLog.h"
 
 /// \cond CLASSIMP
 ClassImp(AliMUONTracker)
@@ -66,12 +68,11 @@ ClassImp(AliMUONTracker)
 //_____________________________________________________________________________
 AliMUONTracker::AliMUONTracker(const AliMUONRecoParam* recoParam,
                                AliMUONVClusterServer* clusterServer,
-                               const AliMUONVDigitStore& digitStore,
-                               const AliMUONDigitMaker* digitMaker,
+                               AliMUONVDigitStore& digitStore,
                                const AliMUONGeometryTransformer* transformer,
-                               const AliMUONTriggerCircuit* triggerCircuit)
+                               const AliMUONTriggerCircuit* triggerCircuit,
+                               const AliMUONTriggerUtilities* triggerUtilities)
 : AliTracker(),
-fkDigitMaker(digitMaker), // not owner
 fkTransformer(transformer), // not owner
 fkTriggerCircuit(triggerCircuit), // not owner
 fTrackHitPatternMaker(0x0),
@@ -83,21 +84,23 @@ fIsOwnerOfClusterServer(kFALSE),
 fkDigitStore(digitStore), // not owner
 fInputClusterStore(0x0),
 fTriggerTrackStore(0x0),
-fkRecoParam(recoParam)
+fkRecoParam(recoParam),
+fInternalTrackStore(0x0)
 {
   /// constructor
-  if (fkTransformer && fkDigitMaker)
-    fTrackHitPatternMaker = new AliMUONTrackHitPattern(recoParam,*fkTransformer,*fkDigitMaker);
+  
+  if (fkTransformer)
+    fTrackHitPatternMaker = new AliMUONTrackHitPattern(recoParam,*fkTransformer,fkDigitStore,triggerUtilities);
   
   if (!fClusterServer)
   {
-    AliInfo("No cluster server given. Will use AliMUONLegacyClusterServer");
+    AliDebug(1,"No cluster server given. Will use AliMUONLegacyClusterServer");
     fIsOwnerOfClusterServer = kTRUE;
   }
   else
   {
     TIter next(fkDigitStore.CreateIterator());
-    fClusterServer->UseDigits(next);
+    fClusterServer->UseDigits(next,&digitStore);
     
     SetupClusterServer(*fClusterServer);
   }
@@ -107,6 +110,7 @@ fkRecoParam(recoParam)
 AliMUONTracker::~AliMUONTracker()
 {
   /// dtor
+  
   delete fTrackReco;
   delete fTrackHitPatternMaker;
   delete fClusterStore;
@@ -114,6 +118,7 @@ AliMUONTracker::~AliMUONTracker()
   if ( fIsOwnerOfClusterServer ) delete fClusterServer;
   delete fInputClusterStore;
   delete fTriggerTrackStore;
+  delete fInternalTrackStore;
 }
 
 //_____________________________________________________________________________
@@ -145,16 +150,15 @@ Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
 {
   /// Load triggerStore from clustersTree
 
-  delete fTriggerStore;
-  delete fInputClusterStore;
-  fInputClusterStore=0x0;
-
   if ( ! clustersTree ) {
     AliFatal("No clustersTree");
     return 1;
   }
 
-  fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
+  if ( !fTriggerStore ) 
+  {
+    fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);    
+  }
   
   if (!fTriggerStore)
   {
@@ -162,22 +166,32 @@ Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
     return 2;
   }
   
-  if ( fIsOwnerOfClusterServer )
+  if (!fInputClusterStore) 
   {
     fInputClusterStore = AliMUONVClusterStore::Create(*clustersTree);
-    if ( fInputClusterStore ) 
+    if (!fInputClusterStore)
     {
-      AliInfo(Form("Created %s from cluster tree",fInputClusterStore->ClassName()));
-      fInputClusterStore->Clear();
-      fInputClusterStore->Connect(*clustersTree,kFALSE);
+      AliError("Could not get clusterStore");
+      return 3;
     }
-    delete fClusterServer;
-    fClusterServer = new AliMUONLegacyClusterServer(*fkTransformer,fInputClusterStore,
-                                                                                                                                                                                                               GetRecoParam()->BypassSt4(),
-                                                                                                                                                                                                               GetRecoParam()->BypassSt5());
-    SetupClusterServer(*fClusterServer);
+    AliDebug(1,Form("Created %s from cluster tree",fInputClusterStore->ClassName()));
+  }
+    
+  if ( !fClusterServer && fIsOwnerOfClusterServer )
+  {
+    if ( !fClusterServer ) 
+    {
+      fClusterServer = new AliMUONLegacyClusterServer(*fkTransformer,fInputClusterStore,
+                                                      GetRecoParam()->BypassSt4(),
+                                                      GetRecoParam()->BypassSt5());
+      SetupClusterServer(*fClusterServer);
+    }
+
   }
   
+  fInputClusterStore->Clear();
+  fInputClusterStore->Connect(*clustersTree,kFALSE);
+  fTriggerStore->Clear();
   fTriggerStore->Connect(*clustersTree,kFALSE);
   
   clustersTree->GetEvent(0);
@@ -189,12 +203,21 @@ Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
 Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
 {
   /// Performs the tracking and store the resulting tracks in the ESD
-  AliDebug(1,"");
-  AliCodeTimerAuto("")
+  ///
+  /// note that we're dealing with two cluster stores here : fInputClusterStore
+  /// and ClusterStore().
+  /// The first one is read from the TreeR and may be used by the cluster server 
+  /// (that's the case for the legacy cluster server) to fill the other one.
+  /// The second one is more dynamic and might be created on the fly by the cluster
+  /// server (used by the combined tracking, in which case the first one is not used
+  /// at all).
+  
+  AliCodeTimerAuto("",0)
   
   if (!fTrackReco) 
   {
     fTrackReco = CreateTrackReconstructor(GetRecoParam(),fClusterServer);
+    fInternalTrackStore = new AliMUONTrackStoreV1;
   }
   
   // if the required tracking mode does not exist
@@ -218,13 +241,11 @@ Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
     fTrackReco->EventReconstructTrigger(*fkTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
   }
   
-  if ( ( GetRecoParam()->BypassSt4() || 
-                                GetRecoParam()->BypassSt5() ) && 
-                       TriggerTrackStore()->GetSize() > 5 ) 
+  if ( TriggerTrackStore()->GetSize() > GetRecoParam()->GetMaxTriggerTracks() ) 
   {
-    // Hard cut to reject shower events
+    // cut to reject shower events
     
-    AliCodeTimerAuto("MUON Shower events");
+    AliCodeTimerAuto("MUON Shower events",1);
 
     AliWarning(Form("Probably got a shower event (%d trigger tracks). Will not reconstruct tracks.",
                     TriggerTrackStore()->GetSize()));
@@ -232,21 +253,19 @@ Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
     return 0;
   }
        
-  // Make tracker tracks
-  AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
-  fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
+  fTrackReco->EventReconstruct(*(ClusterStore()),*fInternalTrackStore);
   
   // Match tracker/trigger tracks
   if ( fTrackHitPatternMaker ) 
   {
-    fTrackReco->ValidateTracksWithTrigger(*trackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
+    fTrackReco->ValidateTracksWithTrigger(*fInternalTrackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
   }
   
   // Fill ESD
-  FillESD(*trackStore,esd);
+  FillESD(*fInternalTrackStore,esd);
   
-  // cleanup
-  delete trackStore;
+  fInternalTrackStore->Clear();
+  ClusterStore()->Clear();
   
   return 0;
 }
@@ -256,12 +275,12 @@ void AliMUONTracker::FillESD(const AliMUONVTrackStore& trackStore, AliESDEvent*
 {
   /// Fill the ESD from the trackStore
   AliDebug(1,"");
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
   
   // get ITS vertex
   Double_t vertex[3] = {0., 0., 0.};
   const AliESDVertex* esdVert = esd->GetVertex(); 
-  if (esdVert->GetNContributors()) {
+  if (esdVert->GetNContributors() > 0 || !strcmp(esdVert->GetTitle(),"vertexer: smearMC")) {
     esdVert->GetXYZ(vertex);
     AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
   }
@@ -314,8 +333,8 @@ void AliMUONTracker::FillESD(const AliMUONVTrackStore& trackStore, AliESDEvent*
       if (matched) break;
     }
     if (matched) continue;
-    
-    AliMUONESDInterface::MUONToESD(*locTrg, esdTrack, ghostId);
+
+    AliMUONESDInterface::MUONToESD(*locTrg, esdTrack, ghostId, triggerTrack);
     
     esd->AddMuonTrack(&esdTrack);
     ghostId -= 1;
@@ -347,7 +366,7 @@ AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const AliMU
     return 0x0;
   }
   
-  AliInfoClass(Form("Will use %s for tracking",trackReco->ClassName()));
+  AliDebugClass(1,Form("Will use %s for tracking",trackReco->ClassName()));
   
   return trackReco;
 }
@@ -357,8 +376,7 @@ void AliMUONTracker::UnloadClusters()
 {
   /// Clear internal clusterStore
   
-  delete fInputClusterStore;
-  fInputClusterStore = 0x0;
+  fInputClusterStore->Clear();
 }