]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTracker.cxx
uniformize name of newer histograms added for primary decays with other existing...
[u/mrichter/AliRoot.git] / MUON / AliMUONTracker.cxx
index d769a3baca6ba3f70dc8974bf817f441158a97c9..eccf3727953412cb90ddc6630c2190acb4ce3620 100644 (file)
 /// 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);
+/// Tracking modes (ORIGINAL, KALMAN) and associated options and parameters can be changed
+/// through the AliMUONRecoParam object set in the reconstruction macro or read from the CDB
+/// (see methods in AliMUONRecoParam.h file for details)
 ///
 /// \author Christian Finck and Laurent Aphecetche, SUBATECH Nantes
 //-----------------------------------------------------------------------------
 #include "AliMUONTriggerTrackStoreV1.h"
 #include "AliMUONTriggerTrack.h"
 #include "AliMUONLocalTrigger.h"
-#include "AliMUONVCluster.h"
 #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)
@@ -67,38 +66,41 @@ ClassImp(AliMUONTracker)
 
 
 //_____________________________________________________________________________
-AliMUONTracker::AliMUONTracker(AliMUONVClusterServer* clusterServer,
-                               const AliMUONVDigitStore& digitStore,
-                               const AliMUONDigitMaker* digitMaker,
+AliMUONTracker::AliMUONTracker(const AliMUONRecoParam* recoParam,
+                               AliMUONVClusterServer* clusterServer,
+                               AliMUONVDigitStore& digitStore,
                                const AliMUONGeometryTransformer* transformer,
-                               const AliMUONTriggerCircuit* triggerCircuit)
+                               const AliMUONTriggerCircuit* triggerCircuit,
+                               const AliMUONTriggerUtilities* triggerUtilities)
 : AliTracker(),
-  fDigitMaker(digitMaker), // not owner
-  fTransformer(transformer), // not owner
-  fTriggerCircuit(triggerCircuit), // not owner
-  fTrackHitPatternMaker(0x0),
-  fTrackReco(0x0),
-  fClusterStore(0x0),
-  fTriggerStore(0x0),
-  fClusterServer(clusterServer), 
-  fIsOwnerOfClusterServer(kFALSE),
-  fDigitStore(digitStore), // not owner
-  fInputClusterStore(0x0),
-  fTriggerTrackStore(0x0)
+fkTransformer(transformer), // not owner
+fkTriggerCircuit(triggerCircuit), // not owner
+fTrackHitPatternMaker(0x0),
+fTrackReco(0x0),
+fClusterStore(0x0),
+fTriggerStore(0x0),
+fClusterServer(clusterServer), 
+fIsOwnerOfClusterServer(kFALSE),
+fkDigitStore(digitStore), // not owner
+fInputClusterStore(0x0),
+fTriggerTrackStore(0x0),
+fkRecoParam(recoParam),
+fInternalTrackStore(0x0)
 {
   /// constructor
-  if (fTransformer && fDigitMaker)
-    fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
+  
+  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(fDigitStore.CreateIterator());
-    fClusterServer->UseDigits(next);
+    TIter next(fkDigitStore.CreateIterator());
+    fClusterServer->UseDigits(next,&digitStore);
     
     SetupClusterServer(*fClusterServer);
   }
@@ -108,6 +110,7 @@ AliMUONTracker::AliMUONTracker(AliMUONVClusterServer* clusterServer,
 AliMUONTracker::~AliMUONTracker()
 {
   /// dtor
+  
   delete fTrackReco;
   delete fTrackHitPatternMaker;
   delete fClusterStore;
@@ -115,6 +118,7 @@ AliMUONTracker::~AliMUONTracker()
   if ( fIsOwnerOfClusterServer ) delete fClusterServer;
   delete fInputClusterStore;
   delete fTriggerTrackStore;
+  delete fInternalTrackStore;
 }
 
 //_____________________________________________________________________________
@@ -146,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)
   {
@@ -163,20 +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(*fTransformer,fInputClusterStore);
-    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);
@@ -188,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(AliMUONReconstructor::GetRecoParam()->GetTrackingMode(),fClusterServer);
+    fTrackReco = CreateTrackReconstructor(GetRecoParam(),fClusterServer,fkTransformer);
+    fInternalTrackStore = new AliMUONTrackStoreV1;
   }
   
   // if the required tracking mode does not exist
@@ -211,162 +235,128 @@ Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
   }
 
   // Make trigger tracks
-  if ( fTriggerCircuit ) 
+  if ( fkTriggerCircuit ) 
   {
     TriggerTrackStore()->Clear();
-    fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
+    fTrackReco->EventReconstructTrigger(*fkTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
   }
   
-  // Make tracker tracks
-  AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
-  fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
+  if ( TriggerTrackStore()->GetSize() > GetRecoParam()->GetMaxTriggerTracks() ) 
+  {
+    // cut to reject shower events
+    
+    AliCodeTimerAuto("MUON Shower events",1);
+
+    AliWarning(Form("Probably got a shower event (%d trigger tracks). Will not reconstruct tracks.",
+                    TriggerTrackStore()->GetSize()));
+    
+    return 0;
+  }
+       
+  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;
 }
 
 //_____________________________________________________________________________
-void AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
+void AliMUONTracker::FillESD(const AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
 {
   /// Fill the ESD from the trackStore
   AliDebug(1,"");
-  AliCodeTimerAuto("")
-  
-  AliMUONTrack* track;
-  AliESDMuonTrack esdTrack;
-  Double_t vertex[3] = {0., 0., 0.};
-  TIter next(trackStore.CreateIterator());
+  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]));
   }
   
   // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
-  if (AliMUONReconstructor::GetRecoParam()->SaveFullClusterInESD() && 
-      gRandom->Uniform(100.) <= AliMUONReconstructor::GetRecoParam()->GetPercentOfFullClusterInESD()) {
+  AliMUONTrack* track;
+  AliMUONLocalTrigger* locTrg;
+  TIter next(trackStore.CreateIterator());
+  if (GetRecoParam()->SaveFullClusterInESD() && 
+      gRandom->Uniform(100.) <= GetRecoParam()->GetPercentOfFullClusterInESD()) {
     
     while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
-      AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fDigitStore);
-      // set the trigger x/y strips pattern
-      if (esdTrack.GetMatchTrigger()) {
-       AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(esdTrack.LoCircuit()));
-       esdTrack.SetTriggerX1Pattern(locTrg->GetX1Pattern());
-       esdTrack.SetTriggerY1Pattern(locTrg->GetY1Pattern());
-       esdTrack.SetTriggerX2Pattern(locTrg->GetX2Pattern());
-       esdTrack.SetTriggerY2Pattern(locTrg->GetY2Pattern());
-       esdTrack.SetTriggerX3Pattern(locTrg->GetX3Pattern());
-       esdTrack.SetTriggerY3Pattern(locTrg->GetY3Pattern());
-       esdTrack.SetTriggerX4Pattern(locTrg->GetX4Pattern());
-       esdTrack.SetTriggerY4Pattern(locTrg->GetY4Pattern());
-      }
-      esd->AddMuonTrack(&esdTrack);
+      
+      if (track->GetMatchTrigger() > 0) {
+       locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
+       AliMUONESDInterface::MUONToESD(*track, *esd, vertex, &fkDigitStore, locTrg);
+      } else AliMUONESDInterface::MUONToESD(*track, *esd, vertex, &fkDigitStore);
+      
     }
     
   } else {
     
     while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
-      AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
-      // set the trigger x/y strips pattern
-      if (esdTrack.GetMatchTrigger()) {
-       AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(esdTrack.LoCircuit()));
-       esdTrack.SetTriggerX1Pattern(locTrg->GetX1Pattern());
-       esdTrack.SetTriggerY1Pattern(locTrg->GetY1Pattern());
-       esdTrack.SetTriggerX2Pattern(locTrg->GetX2Pattern());
-       esdTrack.SetTriggerY2Pattern(locTrg->GetY2Pattern());
-       esdTrack.SetTriggerX3Pattern(locTrg->GetX3Pattern());
-       esdTrack.SetTriggerY3Pattern(locTrg->GetY3Pattern());
-       esdTrack.SetTriggerX4Pattern(locTrg->GetX4Pattern());
-       esdTrack.SetTriggerY4Pattern(locTrg->GetY4Pattern());
-      }
-      esd->AddMuonTrack(&esdTrack);
+      
+      if (track->GetMatchTrigger() > 0) {
+       locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
+       AliMUONESDInterface::MUONToESD(*track, *esd, vertex, 0x0, locTrg);
+      } else AliMUONESDInterface::MUONToESD(*track, *esd, vertex);
+      
     }
     
   }
-
-  // fill the local trigger decisions not matched with tracks 
-  // associate them to "ghost" tracks
-
-  Int_t loTrgNum(-1);
+  
+  // fill the local trigger decisions not matched with tracks (associate them to "ghost" tracks)
+  UInt_t ghostId = 0xFFFFFFFF - 1;
   Bool_t matched = kFALSE;
-
   AliMUONTriggerTrack *triggerTrack;
-  AliMUONTrack muonTrack;
-  AliESDMuonTrack esdGhostTrack;
   TIter itTriggerTrack(fTriggerTrackStore->CreateIterator());
-  while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack() )
-) )
-    {
-      loTrgNum = triggerTrack->GetLoTrgNum();
-      AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(loTrgNum));
-
-      /* verify if this local trigger has been already matched */
-      TIter itTrack(trackStore.CreateIterator());
-      while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) )
-        {
-          if (matched = (track->LoCircuit() == locTrg->LoCircuit())) break;
-        }
-      if (matched) continue;
-
-      muonTrack.SetLocalTrigger(locTrg->LoCircuit(),
-                                locTrg->LoStripX(),
-                                locTrg->LoStripY(),
-                                locTrg->LoDev(),
-                                locTrg->LoLpt(),
-                                locTrg->LoHpt());
-
-      /* make the AliESDMuonTrack from the "track" object */
-
-      esdGhostTrack.SetLocalTrigger(muonTrack.GetLocalTrigger());
-      // set the transverse momentum of this track to "zero"
-      esdGhostTrack.SetInverseBendingMomentum(1.E+10);
-      esdGhostTrack.SetInverseBendingMomentumAtDCA(1.E+10);
-      esdGhostTrack.SetInverseBendingMomentumUncorrected(1.E+10);
-      // set the trigger x/y strips pattern
-      esdGhostTrack.SetTriggerX1Pattern(locTrg->GetX1Pattern());
-      esdGhostTrack.SetTriggerY1Pattern(locTrg->GetY1Pattern());
-      esdGhostTrack.SetTriggerX2Pattern(locTrg->GetX2Pattern());
-      esdGhostTrack.SetTriggerY2Pattern(locTrg->GetY2Pattern());
-      esdGhostTrack.SetTriggerX3Pattern(locTrg->GetX3Pattern());
-      esdGhostTrack.SetTriggerY3Pattern(locTrg->GetY3Pattern());
-      esdGhostTrack.SetTriggerX4Pattern(locTrg->GetX4Pattern());
-      esdGhostTrack.SetTriggerY4Pattern(locTrg->GetY4Pattern());
-      esd->AddMuonTrack(&esdGhostTrack);
-
+  while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack()) ) ) {
+    
+    locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(triggerTrack->GetLoTrgNum()));
+    
+    // check if this local trigger has already been matched
+    TIter itTrack(trackStore.CreateIterator());
+    while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) ) {
+      matched = (track->LoCircuit() == locTrg->LoCircuit());
+      if (matched) break;
     }
+    if (matched) continue;
+
+    AliMUONESDInterface::MUONToESD(*locTrg, *esd, ghostId, triggerTrack);
+    
+    ghostId -= 1;
+  }
   
 }
 
 //_____________________________________________________________________________
-AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const char* trackingMode, AliMUONVClusterServer* clusterServer)
+AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const AliMUONRecoParam* recoParam,
+                                                                    AliMUONVClusterServer* clusterServer,
+                                                                    const AliMUONGeometryTransformer* transformer)
 {
   /// Create track reconstructor, depending on tracking mode set in RecoParam
   
   AliMUONVTrackReconstructor* trackReco(0x0);
   
-  TString opt(trackingMode);
+  TString opt(recoParam->GetTrackingMode());
   opt.ToUpper();
   
   if (strstr(opt,"ORIGINAL"))
   {
-    trackReco = new AliMUONTrackReconstructor(*clusterServer);
+    trackReco = new AliMUONTrackReconstructor(recoParam,clusterServer,transformer);
   }
   else if (strstr(opt,"KALMAN"))
   {
-    trackReco = new AliMUONTrackReconstructorK(*clusterServer);
+    trackReco = new AliMUONTrackReconstructorK(recoParam,clusterServer,transformer);
   }
   else
   {
@@ -374,7 +364,7 @@ AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const char*
     return 0x0;
   }
   
-  AliInfoClass(Form("Will use %s for tracking",trackReco->ClassName()));
+  AliDebugClass(1,Form("Will use %s for tracking",trackReco->ClassName()));
   
   return trackReco;
 }
@@ -384,8 +374,7 @@ void AliMUONTracker::UnloadClusters()
 {
   /// Clear internal clusterStore
   
-  delete fInputClusterStore;
-  fInputClusterStore = 0x0;
+  fInputClusterStore->Clear();
 }
 
 
@@ -395,18 +384,38 @@ AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
 {
   /// Setup the cluster server
   
-  if ( AliMUONReconstructor::GetRecoParam()->BypassSt45() )
+  if ( GetRecoParam()->BypassSt4() ||
+                        GetRecoParam()->BypassSt5() )
   {
     Bool_t ok = clusterServer.UseTriggerTrackStore(TriggerTrackStore());
   
+               TString msg1;
+               TString msg2;
+               
+               if ( GetRecoParam()->BypassSt45() )
+               {
+                       msg1 = "STATIONS 4 AND 5";
+                       msg2 = "THOSE TWO STATIONS";
+               }
+               else if ( GetRecoParam()->BypassSt4() )
+               {
+                       msg1 = "STATION 4";
+                       msg2 = "THAT STATION";
+               }
+               else if ( GetRecoParam()->BypassSt5() )
+               {
+                       msg1 = "STATION 5";
+                       msg2 = "THAT STATION";
+               }
+               
     if ( ok ) 
-    
     {
-      AliWarning("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN STATIONS 4 AND 5, THUS BYPASSING REAL CLUSTERS IN THOSE TWO STATIONS !!!");    
+      AliWarning(Form("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN %s, "
+                                                                                       "THUS BYPASSING REAL CLUSTERS IN %s!!!",msg1.Data(),msg2.Data()));    
     }
     else
     {
-      AliWarning("BYPASSING OF ST45 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");    
+      AliWarning("BYPASSING OF ST4 AND/OR 5 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");    
     }
   }
 }