]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG/muon/AliVAnalysisMuon.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWG / muon / AliVAnalysisMuon.cxx
index cec8bd8c40362a23589b63fdc9be41ebae4dc80d..e513c2a3678b2db11f039499e01631fe3ad53106 100644 (file)
 // CORRFW includes
 #include "AliCFGridSparse.h"
 
-// PWG3 includes
+// PWG includes
 #include "AliMergeableCollection.h"
 #include "AliMuonEventCuts.h"
 #include "AliMuonTrackCuts.h"
 #include "AliMuonPairCuts.h"
 #include "AliAnalysisMuonUtility.h"
+#include "AliUtilityMuonAncestor.h"
 
 /// \cond CLASSIMP
 ClassImp(AliVAnalysisMuon) // Class implementation in ROOT context
@@ -88,6 +89,8 @@ AliVAnalysisMuon::AliVAnalysisMuon() :
   fChargeKeys(0x0),
   fSrcKeys(0x0),
   fPhysSelKeys(0x0),
+  fWeights(0x0),
+  fUtilityMuonAncestor(0x0),
   fEventCounters(0x0),
   fMergeableCollection(0x0),
   fOutputList(0x0),
@@ -108,6 +111,8 @@ AliVAnalysisMuon::AliVAnalysisMuon(const char *name, const AliMuonTrackCuts& tra
   fChargeKeys(0x0),
   fSrcKeys(0x0),
   fPhysSelKeys(0x0),
+  fWeights(new THashList()),
+  fUtilityMuonAncestor(0x0),
   fEventCounters(0x0),
   fMergeableCollection(0x0),
   fOutputList(0x0),
@@ -120,6 +125,7 @@ AliVAnalysisMuon::AliVAnalysisMuon(const char *name, const AliMuonTrackCuts& tra
   InitKeys();
   SetTrigClassPatterns("");
   SetCentralityClasses();
+  fWeights->SetOwner();
 
   DefineOutput(1, TObjArray::Class());
 }
@@ -136,6 +142,8 @@ AliVAnalysisMuon::AliVAnalysisMuon(const char *name, const AliMuonTrackCuts& tra
   fChargeKeys(0x0),
   fSrcKeys(0x0),
   fPhysSelKeys(0x0),
+  fWeights(new THashList()),
+  fUtilityMuonAncestor(0x0),
   fEventCounters(0x0),
   fMergeableCollection(0x0),
   fOutputList(0x0),
@@ -148,6 +156,7 @@ AliVAnalysisMuon::AliVAnalysisMuon(const char *name, const AliMuonTrackCuts& tra
   InitKeys();
   SetTrigClassPatterns("");
   SetCentralityClasses();
+  fWeights->SetOwner();
   
   DefineOutput(1, TObjArray::Class());
 }
@@ -165,6 +174,8 @@ AliVAnalysisMuon::AliVAnalysisMuon(const char *name, const AliMuonPairCuts& pair
   fChargeKeys(0x0),
   fSrcKeys(0x0),
   fPhysSelKeys(0x0),
+  fWeights(new THashList()),
+  fUtilityMuonAncestor(0x0),
   fEventCounters(0x0),
   fMergeableCollection(0x0),
   fOutputList(0x0),
@@ -176,6 +187,7 @@ AliVAnalysisMuon::AliVAnalysisMuon(const char *name, const AliMuonPairCuts& pair
   InitKeys();
   SetTrigClassPatterns("");
   SetCentralityClasses();
+  fWeights->SetOwner();
     
   DefineOutput(1, TObjArray::Class());
 }
@@ -195,6 +207,8 @@ AliVAnalysisMuon::~AliVAnalysisMuon()
   delete fChargeKeys;
   delete fSrcKeys;
   delete fPhysSelKeys;
+  delete fWeights;
+  delete fUtilityMuonAncestor;
   delete fOutputPrototypeList;
 
 
@@ -213,8 +227,6 @@ void AliVAnalysisMuon::FinishTaskOutput()
 
 
   fMergeableCollection->PruneEmptyObjects();
-
-  TString objectName = "";
   
   // Add stat. info from physics selection
   // (usefull when running on AODs)
@@ -223,7 +235,7 @@ void AliVAnalysisMuon::FinishTaskOutput()
       TString statType = ( istat == 0 ) ? "ALL" : "BIN0";
       TH2* hStat = dynamic_cast<TH2*>(fInputHandler->GetStatistics(statType.Data()));
       if ( hStat ) {
-        objectName = Form("%s_%s", hStat->GetName(), GetName());
+        TString objectName = Form("%s_%s", hStat->GetName(), GetName());
         TH2* cloneStat = static_cast<TH2*>(hStat->Clone(objectName.Data()));
         cloneStat->SetDirectory(0);
         fOutputList->Add(cloneStat);
@@ -267,6 +279,7 @@ void AliVAnalysisMuon::UserCreateOutputObjects()
   fEventCounters->AddRubric("selected", "yes/no");
   fEventCounters->AddRubric("trigger", 100);
   fEventCounters->AddRubric("centrality", centralityClasses);
+  fEventCounters->AddRubric("run", 10000);
   fEventCounters->Init();
   fOutputList->Add(fEventCounters);
  
@@ -278,6 +291,8 @@ void AliVAnalysisMuon::UserCreateOutputObjects()
   fMuonEventCuts->Print();
   
   MyUserCreateOutputObjects();
+  
+  fUtilityMuonAncestor = new AliUtilityMuonAncestor();
 }
 
 
@@ -305,7 +320,7 @@ void AliVAnalysisMuon::UserExec(Option_t * /*option*/)
   //
   // Global event info
   //
-  TObjArray* selectTrigClasses = fMuonEventCuts->GetSelectedTrigClassesInEvent(InputEvent());
+  const TObjArray* selectTrigClasses = fMuonEventCuts->GetSelectedTrigClassesInEvent(InputEvent());
 
   Double_t centrality = fMuonEventCuts->GetCentrality(InputEvent());
   Int_t centralityBin = GetCentralityClasses()->FindBin(centrality);
@@ -314,7 +329,7 @@ void AliVAnalysisMuon::UserExec(Option_t * /*option*/)
   TString selKey = ( physSel == kPhysSelPass ) ? "yes" : "no";
   for ( Int_t itrig=0; itrig<selectTrigClasses->GetEntries(); ++itrig ) {
     TString trigName = selectTrigClasses->At(itrig)->GetName();
-    fEventCounters->Count(Form("trigger:%s/selected:%s/centrality:%s", trigName.Data(), selKey.Data(), centralityBinLabel.Data()));
+    fEventCounters->Count(Form("trigger:%s/selected:%s/centrality:%s/run:%i", trigName.Data(), selKey.Data(), centralityBinLabel.Data(),fCurrentRunNumber));
   }
 
   ProcessEvent(fPhysSelKeys->At(physSel)->GetName(), *selectTrigClasses, centralityBinLabel);
@@ -332,7 +347,9 @@ void AliVAnalysisMuon::Terminate(Option_t *)
   
   if ( ! fTerminateOptions ) SetTerminateOptions();
   
-  if ( gROOT->IsBatch() ) return;
+  TString furtherOpt = ((TObjString*)fTerminateOptions->At(3))->GetString();
+  furtherOpt.ToUpper();
+  if ( gROOT->IsBatch() && ! furtherOpt.Contains("FORCEBATCH") ) return;
     
   fOutputList = dynamic_cast<TObjArray*>(GetOutputData(1));
   if ( ! fOutputList ) return;
@@ -350,78 +367,22 @@ void AliVAnalysisMuon::Terminate(Option_t *)
 
 
 //________________________________________________________________________
-Int_t AliVAnalysisMuon::GetParticleType(AliVParticle* track)
+Int_t AliVAnalysisMuon::GetParticleType ( AliVParticle* track )
 {
   //
   /// Get particle type from mathced MC track
   //
   
-  Int_t trackSrc = kUnidentified;
-  Int_t trackLabel = track->GetLabel();
-  if ( trackLabel >= 0 ) {
-    AliVParticle* matchedMCTrack = AliAnalysisMuonUtility::GetMCTrack(trackLabel,InputEvent(),MCEvent());
-    if ( matchedMCTrack ) trackSrc = RecoTrackMother(matchedMCTrack);
-  } // track has MC label
-  return trackSrc;
-}
-
-
-//________________________________________________________________________
-Int_t AliVAnalysisMuon::RecoTrackMother(AliVParticle* mcParticle)
-{
-  //
-  /// Find track mother from kinematics
-  //
-  
-  Int_t recoPdg = mcParticle->PdgCode();
-  
-  // Track is not a muon
-  if ( TMath::Abs(recoPdg) != 13 ) return kRecoHadron;
-  
-  Int_t imother = AliAnalysisMuonUtility::GetMotherIndex(mcParticle);
-  
-  Int_t den[3] = {100, 1000, 1};
-  
-  Int_t motherType = kDecayMu;
-  while ( imother >= 0 ) {
-    AliVParticle* part = AliAnalysisMuonUtility::GetMCTrack(imother,InputEvent(),MCEvent());
-    //if ( ! part ) return motherType;
-    
-    Int_t absPdg = TMath::Abs(part->PdgCode());
-    
-    Bool_t isPrimary = AliAnalysisMuonUtility::IsPrimary(part, MCEvent());
-    
-    if ( isPrimary ) {
-      if ( absPdg == 24 ) return kWbosonMu;
-      
-      for ( Int_t idec=0; idec<3; idec++ ) {
-        Int_t flv = (absPdg%100000)/den[idec];
-        if ( flv > 0 && flv < 4 ) return kDecayMu;
-        else if ( flv == 0 || flv > 5 ) continue;
-        else {
-          if ( den[idec] == 100 ) motherType = kQuarkoniumMu;
-          else if ( flv == 4 ) motherType = kCharmMu;
-          else motherType = kBeautyMu;
-          break; // break loop on pdg code
-          // but continue the global loop to find higher mass HF
-        }
-      } // loop on pdg code
-      if ( absPdg < 10 ) break; // particle loop
-    } // is primary
-    else {
-      if ( part->Zv() < -90. ) {
-        // If hadronic process => secondary
-        //if ( part->GetUniqueID() == kPHadronic ) {
-        return kSecondaryMu;
-        //}
-      }
-    } // is secondary
-    
-    imother = AliAnalysisMuonUtility::GetMotherIndex(part);
-    
-  } // loop on mothers
-  
-  return motherType;
+  if ( fUtilityMuonAncestor->IsUnidentified(track,MCEvent()) ) return kUnidentified;
+  if ( fUtilityMuonAncestor->IsBeautyMu(track,MCEvent()) ) return kBeautyMu;
+  if ( fUtilityMuonAncestor->IsCharmMu(track,MCEvent()) ) return kCharmMu;
+  if ( fUtilityMuonAncestor->IsWBosonMu(track,MCEvent()) ) return kWbosonMu;
+  if ( fUtilityMuonAncestor->IsZBosonMu(track,MCEvent()) ) return kZbosonMu;
+  if ( fUtilityMuonAncestor->IsDecayMu(track,MCEvent()) ) return kDecayMu;
+  if ( fUtilityMuonAncestor->IsQuarkoniumMu(track,MCEvent()) ) return kQuarkoniumMu;
+  if ( fUtilityMuonAncestor->IsHadron(track,MCEvent()) ) return kRecoHadron;
+  if ( fUtilityMuonAncestor->IsSecondaryMu(track,MCEvent()) ) return kSecondaryMu;
+  return kDecayMu;
 }
 
 
@@ -613,37 +574,9 @@ Bool_t AliVAnalysisMuon::SetSparseRange(AliCFGridSparse* gridSparse,
   /// Check the bin limits.
   //
   
-  option.ToUpper();
-  Int_t minVarBin = -1, maxVarBin = -1;
-  TAxis* axis = gridSparse->GetAxis(ivar);
-  
-  if ( ! axis ) {
-    printf("Warning: Axis %i not found in %s", ivar, gridSparse->GetName());
-    return kFALSE;
-  }
-  
-  if ( ! labelName.IsNull() ) {
-    minVarBin = axis->FindBin(labelName.Data());
-    maxVarBin = minVarBin;
-    if ( minVarBin < 1 ) {
-      printf("Warning: %s: label %s not found. Nothing done", gridSparse->GetName(), labelName.Data());
-      return kFALSE;
-    }
-  }
-  else if ( option.Contains( "USEBIN" ) ) {
-    minVarBin = (Int_t)varMin;
-    maxVarBin = (Int_t)varMax;
-  }
-  else {
-    minVarBin = axis->FindBin(varMin);
-    maxVarBin = axis->FindBin(varMax);
-  }
-  
-  if ( axis->GetFirst() == minVarBin && axis->GetLast() == maxVarBin ) return kFALSE;
+  // Keep for backward compatibility
   
-  gridSparse->SetRangeUser(ivar, axis->GetBinCenter(minVarBin), axis->GetBinCenter(maxVarBin));
-  
-  return kTRUE;
+  return AliAnalysisMuonUtility::SetSparseRange(gridSparse,ivar,labelName,varMin, varMax,option);
 }
 
 //________________________________________________________________________
@@ -660,8 +593,8 @@ void AliVAnalysisMuon::SetTrigClassPatterns(const TString pattern)
   TString currPattern = pattern;
   if ( currPattern.IsNull() ) { 
     currPattern = GetDefaultTrigClassPatterns();
-    currPattern.Append(" !CMUP"); // by default do not account for UltraPeripheral events
-  } 
+    currPattern.Append(",!CMUP*"); // by default do not account for UltraPeripheral events
+  }
   fMuonEventCuts->SetTrigClassPatterns(currPattern);
 }
 
@@ -750,12 +683,36 @@ void AliVAnalysisMuon::SetTerminateOptions(TString physSel, TString trigClass, T
 //________________________________________________________________________
 void AliVAnalysisMuon::InitKeys()
 {
+  //
+  /// Init keys
+  //
   TString chargeKeys = "MuMinus MuPlus";
   fChargeKeys = chargeKeys.Tokenize(" ");
   
-  TString srcKeys = "CharmMu BeautyMu QuarkoniumMu WbosonMu DecayMu SecondaryMu Hadron Unidentified";
+  TString srcKeys = "CharmMu BeautyMu QuarkoniumMu WbosonMu ZbosonMu DecayMu SecondaryMu Hadron Unidentified";
   fSrcKeys = srcKeys.Tokenize(" ");
   
   TString physSelKeys = "PhysSelPass PhysSelReject";
   fPhysSelKeys = physSelKeys.Tokenize(" ");
 }
+
+
+//________________________________________________________________________
+void AliVAnalysisMuon::SetWeight ( TObject* wgtObj )
+{
+  /// Set weight
+  if ( fWeights->FindObject(wgtObj->GetName()) ) {
+    AliWarning(Form("Weight object %s is already in the list",wgtObj->GetName()));
+    return;
+  }
+  fWeights->Add(wgtObj);
+}
+
+//________________________________________________________________________
+TObject* AliVAnalysisMuon::GetWeight ( const Char_t* wgtName )
+{
+  /// Get weight
+  return fWeights->FindObject(wgtName);
+}
+
+