]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTracker.cxx
ESD file is added to the list of proof output files. It is then automatically merged...
[u/mrichter/AliRoot.git] / MUON / AliMUONTracker.cxx
index 961300579b069b0b287a03ff9a84edc89e50c6c0..0ec3dc39017c698599006ab7572e29b65e57fbe1 100644 (file)
 
 #include "AliMUONTracker.h"
 
-#include "AliMUONReconstructor.h"
+#include "AliCodeTimer.h"
+#include "AliESDEvent.h"
+#include "AliESDMuonTrack.h"
+#include "AliESDVertex.h"
+#include "AliLog.h"
+#include "AliMUONClusterStoreV2.h"
+#include "AliMUONESDInterface.h"
+#include "AliMUONLegacyClusterServer.h"
 #include "AliMUONRecoParam.h"
+#include "AliMUONReconstructor.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 "AliMUONTriggerChamberEff.h"
 #include "AliMUONTriggerTrackStoreV1.h"
-#include "AliMUONVClusterStore.h"
+#include "AliMUONTriggerTrack.h"
+#include "AliMUONLocalTrigger.h"
+#include "AliMUONVCluster.h"
+#include "AliMUONVClusterServer.h"
+#include "AliMUONVDigitStore.h"
 #include "AliMUONVTriggerStore.h"
-
-#include "AliESDEvent.h"
-#include "AliESDMuonTrack.h"
-#include "AliESDMuonCluster.h"
-#include "AliESDVertex.h"
-#include "AliLog.h"
-#include "AliCodeTimer.h"
-
 #include <Riostream.h>
+#include <TRandom.h>
 #include <TTree.h>
 
 /// \cond CLASSIMP
@@ -64,23 +67,43 @@ ClassImp(AliMUONTracker)
 
 
 //_____________________________________________________________________________
-AliMUONTracker::AliMUONTracker(const AliMUONDigitMaker* digitMaker,
+AliMUONTracker::AliMUONTracker(const AliMUONRecoParam* recoParam,
+                               AliMUONVClusterServer* clusterServer,
+                               const AliMUONVDigitStore& digitStore,
+                               const AliMUONDigitMaker* digitMaker,
                                const AliMUONGeometryTransformer* transformer,
-                               const AliMUONTriggerCircuit* triggerCircuit,
-                               AliMUONTriggerChamberEff* chamberEff)
+                               const AliMUONTriggerCircuit* triggerCircuit)
 : AliTracker(),
-  fDigitMaker(digitMaker), // not owner
-  fTransformer(transformer), // not owner
-  fTriggerCircuit(triggerCircuit), // not owner
-  fTrigChamberEff(chamberEff), // not owner
-  fTrackHitPatternMaker(0x0),
-  fTrackReco(0x0),
-  fClusterStore(0x0),
-  fTriggerStore(0x0)
+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),
+fRecoParam(recoParam)
 {
   /// constructor
   if (fTransformer && fDigitMaker)
-    fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
+    fTrackHitPatternMaker = new AliMUONTrackHitPattern(recoParam,*fTransformer,*fDigitMaker);
+  
+  if (!fClusterServer)
+  {
+    AliInfo("No cluster server given. Will use AliMUONLegacyClusterServer");
+    fIsOwnerOfClusterServer = kTRUE;
+  }
+  else
+  {
+    TIter next(fDigitStore.CreateIterator());
+    fClusterServer->UseDigits(next);
+    
+    SetupClusterServer(*fClusterServer);
+  }
 }
 
 //_____________________________________________________________________________
@@ -91,35 +114,73 @@ AliMUONTracker::~AliMUONTracker()
   delete fTrackHitPatternMaker;
   delete fClusterStore;
   delete fTriggerStore;
+  if ( fIsOwnerOfClusterServer ) delete fClusterServer;
+  delete fInputClusterStore;
+  delete fTriggerTrackStore;
+}
+
+//_____________________________________________________________________________
+AliMUONVClusterStore*
+AliMUONTracker::ClusterStore() const
+{
+  /// Return (and create if necessary) the cluster container
+  if (!fClusterStore) 
+  {
+    fClusterStore = new AliMUONClusterStoreV2;
+  }
+  return fClusterStore;
+}
+
+//_____________________________________________________________________________
+AliMUONVTriggerTrackStore*
+AliMUONTracker::TriggerTrackStore() const
+{
+  /// Return (and create if necessary) the trigger track container
+  if (!fTriggerTrackStore) 
+  {
+    fTriggerTrackStore = new AliMUONTriggerTrackStoreV1;
+  }
+  return fTriggerTrackStore;
 }
 
 //_____________________________________________________________________________
 Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
 {
-  /// Load clusterStore and triggerStore from clustersTree
-  delete fClusterStore;
+  /// Load triggerStore from clustersTree
+
   delete fTriggerStore;
+  delete fInputClusterStore;
+  fInputClusterStore=0x0;
 
   if ( ! clustersTree ) {
     AliFatal("No clustersTree");
     return 1;
   }
 
-  fClusterStore = AliMUONVClusterStore::Create(*clustersTree);
   fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
   
-  if (!fClusterStore)
-  {
-    AliError("Could not get clusterStore");
-    return 1;
-  }
   if (!fTriggerStore)
   {
     AliError("Could not get triggerStore");
     return 2;
   }
   
-  fClusterStore->Connect(*clustersTree,kFALSE);
+  if ( fIsOwnerOfClusterServer )
+  {
+    fInputClusterStore = AliMUONVClusterStore::Create(*clustersTree);
+    if ( fInputClusterStore ) 
+    {
+      AliInfo(Form("Created %s from cluster tree",fInputClusterStore->ClassName()));
+      fInputClusterStore->Clear();
+      fInputClusterStore->Connect(*clustersTree,kFALSE);
+    }
+    delete fClusterServer;
+    fClusterServer = new AliMUONLegacyClusterServer(*fTransformer,fInputClusterStore,
+                                                                                                                                                                                                               GetRecoParam()->BypassSt4(),
+                                                                                                                                                                                                               GetRecoParam()->BypassSt5());
+    SetupClusterServer(*fClusterServer);
+  }
+  
   fTriggerStore->Connect(*clustersTree,kFALSE);
   
   clustersTree->GetEvent(0);
@@ -134,12 +195,16 @@ Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
   AliDebug(1,"");
   AliCodeTimerAuto("")
   
-  if (!fTrackReco) CreateTrackReconstructor();
+  if (!fTrackReco) 
+  {
+    fTrackReco = CreateTrackReconstructor(GetRecoParam(),fClusterServer);
+  }
   
   // if the required tracking mode does not exist
   if  (!fTrackReco) return 1;
   
-  if (!fClusterStore) {
+  if ( ! ClusterStore() ) 
+  {
     AliError("ClusterStore is NULL");
     return 2;
   }
@@ -148,28 +213,36 @@ Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
     AliError("TriggerStore is NULL");
     return 3;
   }
-  
-  // Make tracker tracks
-  AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
-  fTrackReco->EventReconstruct(*fClusterStore,*trackStore);
-  
+
   // Make trigger tracks
-  AliMUONVTriggerTrackStore* triggerTrackStore(0x0);
-  if ( fTriggerCircuit ) {
-    triggerTrackStore = new AliMUONTriggerTrackStoreV1;
-    fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*triggerTrackStore);
+  if ( fTriggerCircuit ) 
+  {
+    TriggerTrackStore()->Clear();
+    fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
   }
+  
+  if ( ( GetRecoParam()->BypassSt4() || 
+                                GetRecoParam()->BypassSt5() ) && 
+                       TriggerTrackStore()->GetSize() > 5 ) 
+  {
+    // Hard cut to reject shower events
+    
+    AliCodeTimerAuto("MUON Shower events");
 
-  // Match tracker/trigger tracks
-  if ( triggerTrackStore && fTrackHitPatternMaker ) {
-    fTrackReco->ValidateTracksWithTrigger(*trackStore,*triggerTrackStore,*fTriggerStore,*fTrackHitPatternMaker);
+    AliWarning(Form("Probably got a shower event (%d trigger tracks). Will not reconstruct tracks.",
+                    TriggerTrackStore()->GetSize()));
+    
+    return 0;
   }
+       
+  // Make tracker tracks
+  AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
+  fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
   
-  // Compute trigger chamber efficiency
-  if( triggerTrackStore && fTrigChamberEff){
-      AliCodeTimerStart("EventChamberEff");
-      fTrigChamberEff->EventChamberEff(*fTriggerStore,*triggerTrackStore,*trackStore);
-      AliCodeTimerStop("EventChamberEff");
+  // Match tracker/trigger tracks
+  if ( fTrackHitPatternMaker ) 
+  {
+    fTrackReco->ValidateTracksWithTrigger(*trackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
   }
   
   // Fill ESD
@@ -177,7 +250,6 @@ Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
   
   // cleanup
   delete trackStore;
-  delete triggerTrackStore;
   
   return 0;
 }
@@ -189,101 +261,150 @@ void AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) c
   AliDebug(1,"");
   AliCodeTimerAuto("")
   
-  // Get vertex 
-  Double_t vertex[3] = {0};
-  Double_t errXVtx = 0., errYVtx = 0.;
+  // get ITS vertex
+  Double_t vertex[3] = {0., 0., 0.};
   const AliESDVertex* esdVert = esd->GetVertex(); 
-  if (esdVert->GetNContributors()) 
-  {
+  if (esdVert->GetNContributors()) {
     esdVert->GetXYZ(vertex);
-    errXVtx = esdVert->GetXRes();
-    errYVtx = esdVert->GetYRes();
     AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
   }
   
-  // setting ESD MUON class
-  AliESDMuonTrack esdTrack;
-  AliESDMuonCluster esdCluster;
-  
+  // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
   AliMUONTrack* track;
-  AliMUONVCluster* cluster;
+  AliMUONLocalTrigger* locTrg;
+  AliESDMuonTrack esdTrack;
   TIter next(trackStore.CreateIterator());
-  
-  while ( ( track = static_cast<AliMUONTrack*>(next()) ) )
-  {
-    AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track->GetTrackParamAtCluster())->First());
+  if (GetRecoParam()->SaveFullClusterInESD() && 
+      gRandom->Uniform(100.) <= GetRecoParam()->GetPercentOfFullClusterInESD()) {
+    
+    while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
+      
+      if (track->GetMatchTrigger() > 0) {
+       locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
+       AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fDigitStore, locTrg);
+      } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fDigitStore);
+      
+      esd->AddMuonTrack(&esdTrack);
+    }
     
-    /// Extrapolate to vertex (which is set to (0,0,0) if not available, see above)
-    AliMUONTrackParam trackParamAtVtx(*trackParam);
-    AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0], vertex[1], vertex[2], errXVtx, errYVtx);
+  } else {
     
-    /// Extrapolate to vertex plan (which is set to z=0 if not available, see above)
-    AliMUONTrackParam trackParamAtDCA(*trackParam);
-    AliMUONTrackExtrap::ExtrapToVertexWithoutBranson(&trackParamAtDCA, vertex[2]);
+    while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
+      
+      if (track->GetMatchTrigger() > 0) {
+       locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
+       AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, 0x0, locTrg);
+      } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
+      
+      esd->AddMuonTrack(&esdTrack);
+    }
+    
+  }
+  
+  // 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;
+  TIter itTriggerTrack(fTriggerTrackStore->CreateIterator());
+  while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack()) ) ) {
     
-    // setting data member of ESD MUON
-    esdTrack.Clear("C");           // remove already attached clusters
-    esdTrack.SetMuonClusterMap(0); // important to use the Add..() methods
+    locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(triggerTrack->GetLoTrgNum()));
     
-    // at first station
-    trackParam->SetParamForUncorrected(esdTrack);
-    trackParam->SetCovFor(esdTrack);
-    // at vertex
-    trackParamAtVtx.SetParamFor(esdTrack);
-    // at Distance of Closest Approach
-    trackParamAtDCA.SetParamForDCA(esdTrack);
-    // global info
-    esdTrack.SetChi2(track->GetGlobalChi2());
-    esdTrack.SetNHit(track->GetNClusters());
-    esdTrack.SetLocalTrigger(track->GetLocalTrigger());
-    esdTrack.SetChi2MatchTrigger(track->GetChi2MatchTrigger());
-    esdTrack.SetHitsPatternInTrigCh(track->GetHitsPatternInTrigCh());
-    // muon cluster info
-    while (trackParam) {
-      cluster = trackParam->GetClusterPtr();
-      esdCluster.SetUniqueID(cluster->GetUniqueID());
-      esdCluster.SetXYZ(cluster->GetX(), cluster->GetY(), cluster->GetZ());
-      esdCluster.SetErrXY(cluster->GetErrX(), cluster->GetErrY());
-      esdTrack.AddCluster(esdCluster);
-      esdTrack.AddInMuonClusterMap(cluster->GetChamberId());
-      trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
+    // 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, esdTrack, ghostId);
     
-    // storing ESD MUON Track into ESD Event 
     esd->AddMuonTrack(&esdTrack);
-  } // end of loop on tracks
+    ghostId -= 1;
+  }
+  
 }
 
 //_____________________________________________________________________________
-void AliMUONTracker::CreateTrackReconstructor()
+AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
 {
   /// Create track reconstructor, depending on tracking mode set in RecoParam
   
-  TString opt(AliMUONReconstructor::GetRecoParam()->GetTrackingMode());
+  AliMUONVTrackReconstructor* trackReco(0x0);
+  
+  TString opt(recoParam->GetTrackingMode());
   opt.ToUpper();
   
   if (strstr(opt,"ORIGINAL"))
   {
-    fTrackReco = new AliMUONTrackReconstructor();
+    trackReco = new AliMUONTrackReconstructor(recoParam,clusterServer);
   }
   else if (strstr(opt,"KALMAN"))
   {
-    fTrackReco = new AliMUONTrackReconstructorK();
+    trackReco = new AliMUONTrackReconstructorK(recoParam,clusterServer);
   }
   else
   {
-    AliError(Form("tracking mode \"%s\" does not exist",opt.Data()));
-    return;
+    AliErrorClass(Form("tracking mode \"%s\" does not exist",opt.Data()));
+    return 0x0;
   }
   
-  AliInfo(Form("Will use %s for tracking",fTrackReco->ClassName()));
+  AliInfoClass(Form("Will use %s for tracking",trackReco->ClassName()));
+  
+  return trackReco;
 }
 
 //_____________________________________________________________________________
 void AliMUONTracker::UnloadClusters()
 {
-  /// Delete internal clusterStore
-  delete fClusterStore;
-  fClusterStore = 0x0;
+  /// Clear internal clusterStore
+  
+  delete fInputClusterStore;
+  fInputClusterStore = 0x0;
 }
 
+
+//_____________________________________________________________________________
+void
+AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
+{
+  /// Setup the cluster server
+  
+  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(Form("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN %s, "
+                                                                                       "THUS BYPASSING REAL CLUSTERS IN %s!!!",msg1.Data(),msg2.Data()));    
+    }
+    else
+    {
+      AliWarning("BYPASSING OF ST4 AND/OR 5 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");    
+    }
+  }
+}
+
+