Adding PiKP-only histograms and eliminating a number of switches where histograms...
[u/mrichter/AliRoot.git] / MUON / AliMUONESDInterface.cxx
index 75d28e3..63c73b9 100644 (file)
@@ -23,7 +23,9 @@
 #include "AliMUONVDigit.h"
 #include "AliMUONVDigitStore.h"
 #include "AliMUONLocalTrigger.h"
+#include "AliMUONTriggerTrack.h"
 #include "AliMUONVTriggerStore.h"
+#include "AliMUONVTriggerTrackStore.h"
 #include "AliMUON2DMapIterator.h"
 #include "AliMUONTrackParam.h"
 #include "AliMUONTrackExtrap.h"
@@ -35,7 +37,6 @@
 #include "AliMpExMapIterator.h"
 #include "AliMpVSegmentation.h"
 #include "AliMpSegmentation.h"
-#include "AliMpIntPair.h"
 #include "AliMpPad.h"
 
 #include "AliESDEvent.h"
@@ -49,6 +50,8 @@
 #include <TMath.h>
 #include <TMatrixD.h>
 #include <Riostream.h>
+#include <TGeoGlobalMagField.h>
+#include <TVirtualMagField.h>
 
 //-----------------------------------------------------------------------------
 /// \class AliMUONESDInterface
@@ -78,6 +81,7 @@ TString AliMUONESDInterface::fgTrackStoreName = "AliMUONTrackStoreV1";
 TString AliMUONESDInterface::fgClusterStoreName = "AliMUONClusterStoreV2";
 TString AliMUONESDInterface::fgDigitStoreName = "AliMUONDigitStoreV2R";
 TString AliMUONESDInterface::fgTriggerStoreName = "AliMUONTriggerStoreV1";
+TString AliMUONESDInterface::fgTriggerTrackStoreName = "AliMUONTriggerTrackStoreV1";
 
 //_____________________________________________________________________________
 AliMUONESDInterface::AliMUONESDInterface()
@@ -141,7 +145,7 @@ void AliMUONESDInterface::Reset()
 }
 
 //_____________________________________________________________________________
-void AliMUONESDInterface::LoadEvent(AliESDEvent& esdEvent)
+void AliMUONESDInterface::LoadEvent(AliESDEvent& esdEvent, Bool_t refit)
 {
   /// Extract MUON data from the given ESD event
   
@@ -162,7 +166,7 @@ void AliMUONESDInterface::LoadEvent(AliESDEvent& esdEvent)
     if (!esdTrack->ContainTrackerData()) continue;
     
     // add it to track store
-    AliMUONTrack* track = Add(*esdTrack, *fTracks);
+    AliMUONTrack* track = Add(*esdTrack, *fTracks, refit);
     
     // prepare cluster map
     AliMpExMap* cMap = new AliMpExMap;
@@ -435,7 +439,7 @@ AliMUONVCluster* AliMUONESDInterface::FindClusterInTrack(const AliMUONTrack& tra
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
 
 //_____________________________________________________________________________
-void AliMUONESDInterface::ResetTracker(const AliMUONRecoParam* recoParam)
+void AliMUONESDInterface::ResetTracker(const AliMUONRecoParam* recoParam, Bool_t info)
 {
   /// Reset the MUON tracker using "recoParam" if provided.
   /// If not provided, will use Kalman filter + Smoother
@@ -447,15 +451,28 @@ void AliMUONESDInterface::ResetTracker(const AliMUONRecoParam* recoParam)
     
     fgRecoParam = new AliMUONRecoParam(*recoParam);
     
+    if (info) cout<<"I-AliMUONESDInterface::ResetTracker: will refit tracks with provided RecoParam:"<<endl;
+    
   } else {
     
     fgRecoParam = AliMUONRecoParam::GetLowFluxParam();
-    fgRecoParam->SetTrackingMode("KALMAN");
-    fgRecoParam->UseSmoother(kTRUE);
-    fgRecoParam->SetBendingVertexDispersion(10.);
     
+    cout<<"W-AliMUONESDInterface::ResetTracker: RecoParam not provided. Will use default LowFlux parametrization:"<<endl;
+    
+  }
+  
+  // print useful parameters for refitting
+  if (info) {
+    cout<<"                                     --> Tracking mode = "<<fgRecoParam->GetTrackingMode()<<endl;
+    if (fgRecoParam->UseSmoother()) cout<<"                                     --> Use Smoother"<<endl;
+    else cout<<"                                     --> Do not use smoother"<<endl;
+    cout<<"                                     --> Vertex dispersion in bending direction = "
+    <<fgRecoParam->GetBendingVertexDispersion()<<" cm"<<endl;
   }
   
+  if (!TGeoGlobalMagField::Instance()->GetField())
+    cout<<"W-AliMUONESDInterface::ResetTracker: Magnetic field has not been set --> assume field is OFF"<<endl;
+  
   fgTracker = AliMUONTracker::CreateTrackReconstructor(fgRecoParam,0x0);
   
 }
@@ -508,6 +525,18 @@ AliMUONVTriggerStore* AliMUONESDInterface::NewTriggerStore()
   return reinterpret_cast<AliMUONVTriggerStore*>(classPtr->New());
 }
 
+//_____________________________________________________________________________
+AliMUONVTriggerTrackStore* AliMUONESDInterface::NewTriggerTrackStore()
+{
+  /// Create an empty trigger track store of type fgTriggerTrackStoreName
+  TClass* classPtr = TClass::GetClass(fgTriggerTrackStoreName);
+  if (!classPtr || !classPtr->InheritsFrom("AliMUONVTriggerTrackStore")) {
+    cout<<"E-AliMUONESDInterface::NewTriggerTrackStore: Unable to create store of type "<<fgTriggerTrackStoreName.Data()<<endl;
+    return 0x0;
+  }
+  return reinterpret_cast<AliMUONVTriggerTrackStore*>(classPtr->New());
+}
+
 //_________________________________________________________________________
 void AliMUONESDInterface::GetParamAtVertex(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
 {
@@ -638,11 +667,12 @@ void AliMUONESDInterface::SetParamCov(const AliMUONTrackParam& trackParam, AliES
 }
 
 //_____________________________________________________________________________
-void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONTrack& track)
+void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONTrack& track, Bool_t refit)
 {
   /// Transfert data from ESDMuon track to MUON track.
-  /// The track parameters at each cluster are obtained by refitting the track
+  /// If refit = kTRUE, the track parameters at each cluster are obtained by refitting the track
   /// or by extrapolating the parameters at the first one if the refit failed.
+  /// If refit = kFALSE, only the track parameters at first cluster are valid.
   /// note: You can set the recoParam used to refit the MUON track with ResetTracker(...);
   ///       By default we use Kalman filter + Smoother
   
@@ -663,11 +693,12 @@ void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONTrac
   track.SetVertexErrXY2(0.,0.);
   track.SetGlobalChi2(esdTrack.GetChi2());
   track.SetMatchTrigger(esdTrack.GetMatchTrigger());
-  track.SetLoTrgNum(-1);
   track.SetChi2MatchTrigger(esdTrack.GetChi2MatchTrigger());
   track.SetHitsPatternInTrigCh(esdTrack.GetHitsPatternInTrigCh());
   track.SetLocalTrigger(esdTrack.LoCircuit(), esdTrack.LoStripX(), esdTrack.LoStripY(),
-                       esdTrack.LoDev(), esdTrack.LoLpt(), esdTrack.LoHpt());
+                       esdTrack.LoDev(), esdTrack.LoLpt(), esdTrack.LoHpt(),
+                       esdTrack.GetTriggerWithoutChamber());
+  track.Connected(esdTrack.IsConnected());
   
   // track parameters at vertex
   AliMUONTrackParam paramAtVertex;
@@ -704,15 +735,20 @@ void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONTrac
       esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().After(esdCluster);
     }
     
-    // recompute parameters at first cluster in case of those stored
-    // in ESD are not related to the most upstream cluster
-    AliMUONTrackParam *firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
-    firstTrackParam->SetZ(esdTrack.GetZUncorrected()); // reset the z to the one stored in ESD
-    AliMUONTrackExtrap::ExtrapToZCov(firstTrackParam,firstTrackParam->GetClusterPtr()->GetZ());
-    
     // refit the track to get better parameters and covariances at each cluster (temporary disable track improvement)
-    if (!fgTracker) ResetTracker();
-    if (!fgTracker->RefitTrack(track, kFALSE)) track.UpdateCovTrackParamAtCluster();
+    if (refit) {
+      
+      AliMUONTrackParam *firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
+      AliMUONTrackParam paramSave(*firstTrackParam);
+      
+      if (!fgTracker) ResetTracker();
+      
+      if (!fgTracker->RefitTrack(track, kFALSE) && track.GetGlobalChi2() < AliMUONTrack::MaxChi2()) {
+       *firstTrackParam = paramSave;
+       track.UpdateCovTrackParamAtCluster();
+      }
+      
+    }
     
   } else {
     
@@ -750,12 +786,14 @@ void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONLoca
     return;
   }
   
+  locTrg.SetUniqueID(esdTrack.GetUniqueID());
   locTrg.SetLoCircuit(esdTrack.LoCircuit());
   locTrg.SetLoStripX(esdTrack.LoStripX());
   locTrg.SetLoStripY(esdTrack.LoStripY());
   locTrg.SetDeviation(esdTrack.LoDev());
   locTrg.SetLoLpt(esdTrack.LoLpt());
   locTrg.SetLoHpt(esdTrack.LoHpt());
+  locTrg.SetTriggerWithoutChamber(esdTrack.GetTriggerWithoutChamber());
   locTrg.SetLoTrigY(1);
   locTrg.SetX1Pattern(esdTrack.GetTriggerX1Pattern());
   locTrg.SetX2Pattern(esdTrack.GetTriggerX2Pattern());
@@ -795,8 +833,13 @@ void AliMUONESDInterface::ESDToMUON(const AliESDMuonPad& esdPad, AliMUONVDigit&
 {
   /// Transfert data from ESDMuon pad to MUON digit
   
+  if (!AliMpSegmentation::Instance(kFALSE)) {
+    cout<<"E-AliMUONESDInterface::ESDToMUON: need mapping segmentation to convert ESD pad to MUON digit"<<endl;
+    return;
+  }
+  
   const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(esdPad.GetDetElemId(), esdPad.GetManuId());  
-  AliMpPad pad = seg->PadByLocation(AliMpIntPair(esdPad.GetManuId(), esdPad.GetManuChannel()), kFALSE);
+  AliMpPad pad = seg->PadByLocation(esdPad.GetManuId(), esdPad.GetManuChannel(), kFALSE);
   
   digit.Saturated(esdPad.IsSaturated());
   digit.Used(kFALSE);
@@ -804,7 +847,7 @@ void AliMUONESDInterface::ESDToMUON(const AliESDMuonPad& esdPad, AliMUONVDigit&
   digit.SetUniqueID(esdPad.GetUniqueID());
   digit.SetCharge(esdPad.GetCharge());
   digit.SetADC(esdPad.GetADC());
-  digit.SetPadXY(pad.GetIndices().GetFirst(), pad.GetIndices().GetSecond());
+  digit.SetPadXY(pad.GetIx(), pad.GetIy());
   
 }
 
@@ -840,6 +883,13 @@ void AliMUONESDInterface::MUONToESD(const AliMUONTrack& track, AliESDMuonTrack&
   SetParamAtFirstCluster(*trackParam, esdTrack);
   SetParamCov(*trackParam, esdTrack);
   
+  // set transverse position at the end of the absorber
+  AliMUONTrackParam trackParamAtAbsEnd(*trackParam);
+  AliMUONTrackExtrap::ExtrapToZ(&trackParamAtAbsEnd, AliMUONConstants::AbsZEnd());
+  Double_t xAbs = trackParamAtAbsEnd.GetNonBendingCoor();
+  Double_t yAbs = trackParamAtAbsEnd.GetBendingCoor();
+  esdTrack.SetRAtAbsorberEnd(TMath::Sqrt(xAbs*xAbs + yAbs*yAbs));
+  
   // set param at vertex
   AliMUONTrackParam trackParamAtVtx(*trackParam);
   AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0], vertex[1], vertex[2], 0., 0.);
@@ -860,6 +910,9 @@ void AliMUONESDInterface::MUONToESD(const AliMUONTrack& track, AliESDMuonTrack&
     trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
   }
   
+  // set connected flag
+  esdTrack.Connected(track.IsConnected());
+  
   // set trigger info
   esdTrack.SetLocalTrigger(track.GetLocalTrigger());
   esdTrack.SetChi2MatchTrigger(track.GetChi2MatchTrigger());
@@ -887,7 +940,8 @@ void AliMUONESDInterface::MUONToESD(const AliMUONTrack& track, AliESDMuonTrack&
 }
 
 //_____________________________________________________________________________
-void AliMUONESDInterface::MUONToESD(const AliMUONLocalTrigger& locTrg, AliESDMuonTrack& esdTrack, UInt_t trackId)
+void AliMUONESDInterface::MUONToESD(const AliMUONLocalTrigger& locTrg, AliESDMuonTrack& esdTrack,
+                                   UInt_t trackId, const AliMUONTriggerTrack* triggerTrack)
 {
   /// Build ghost ESDMuon track containing only informations about trigger track
   
@@ -901,10 +955,10 @@ void AliMUONESDInterface::MUONToESD(const AliMUONLocalTrigger& locTrg, AliESDMuo
                            locTrg.LoStripY(),
                            locTrg.GetDeviation(),
                            locTrg.LoLpt(),
-                           locTrg.LoHpt());
+                           locTrg.LoHpt(),
+                           locTrg.GetTriggerWithoutChamber());
   esdTrack.SetLocalTrigger(muonTrack.GetLocalTrigger());
   esdTrack.SetChi2MatchTrigger(0.);
-  esdTrack.SetHitsPatternInTrigCh(0);
   esdTrack.SetTriggerX1Pattern(locTrg.GetX1Pattern());
   esdTrack.SetTriggerY1Pattern(locTrg.GetY1Pattern());
   esdTrack.SetTriggerX2Pattern(locTrg.GetX2Pattern());
@@ -913,7 +967,16 @@ void AliMUONESDInterface::MUONToESD(const AliMUONLocalTrigger& locTrg, AliESDMuo
   esdTrack.SetTriggerY3Pattern(locTrg.GetY3Pattern());
   esdTrack.SetTriggerX4Pattern(locTrg.GetX4Pattern());
   esdTrack.SetTriggerY4Pattern(locTrg.GetY4Pattern());
-  
+  UShort_t hitPattern = 0;
+  if(triggerTrack){
+    hitPattern = triggerTrack->GetHitsPatternInTrigCh();
+    esdTrack.SetHitsPatternInTrigCh(hitPattern);
+    esdTrack.SetThetaXUncorrected(triggerTrack->GetThetax());
+    esdTrack.SetThetaYUncorrected(triggerTrack->GetThetay());
+    esdTrack.SetNonBendingCoorUncorrected(triggerTrack->GetX11());
+    esdTrack.SetBendingCoorUncorrected(triggerTrack->GetY11());
+    esdTrack.SetZUncorrected(triggerTrack->GetZ11());
+  }
 }
 
 //_____________________________________________________________________________
@@ -960,13 +1023,14 @@ void AliMUONESDInterface::MUONToESD(const AliMUONVDigit& digit, AliESDMuonPad& e
 }
 
 //___________________________________________________________________________
-AliMUONTrack* AliMUONESDInterface::Add(const AliESDMuonTrack& esdTrack, AliMUONVTrackStore& trackStore)
+AliMUONTrack* AliMUONESDInterface::Add(const AliESDMuonTrack& esdTrack, AliMUONVTrackStore& trackStore, Bool_t refit)
 {
   /// Create MUON track from ESDMuon track and add it to the store
+  /// Track parameters at each clusters are recomputed or not depending on the flag "refit"
   /// return a pointer to the track into the store (0x0 if the track already exist)
   if(trackStore.FindObject(esdTrack.GetUniqueID())) return 0x0;
   AliMUONTrack* track = trackStore.Add(AliMUONTrack());
-  ESDToMUON(esdTrack, *track);
+  ESDToMUON(esdTrack, *track, refit);
   return track;
 }
 
@@ -974,7 +1038,7 @@ AliMUONTrack* AliMUONESDInterface::Add(const AliESDMuonTrack& esdTrack, AliMUONV
 void AliMUONESDInterface::Add(const AliESDMuonTrack& esdTrack, AliMUONVTriggerStore& triggerStore)
 {
   /// Create MUON local trigger from ESDMuon track and add it to the store if not already there
-  if (triggerStore.FindLocal(esdTrack.LoCircuit())) return;
+  if (!triggerStore.FindLocal(esdTrack.LoCircuit())->IsNull()) return;
   AliMUONLocalTrigger locTrg;
   ESDToMUON(esdTrack, locTrg);
   triggerStore.Add(locTrg);