AliVAnalysisMuon::GetSum : use wildcards in histogram patterns (Diego)
authorpcrochet <pcrochet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 20 Jul 2012 11:32:06 +0000 (11:32 +0000)
committerpcrochet <pcrochet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 20 Jul 2012 11:32:06 +0000 (11:32 +0000)
PWG/muon/AliVAnalysisMuon.cxx
PWG/muon/AliVAnalysisMuon.h
PWGPP/MUON/lite/AliAnalysisTaskTrigChEff.cxx

index 475f3d2..cb979db 100644 (file)
@@ -38,6 +38,7 @@
 #include "TStyle.h"
 //#include "TMCProcess.h"
 #include "TLorentzVector.h"
+#include "TRegexp.h"
 
 // STEER includes
 #include "AliInputEventHandler.h"
@@ -378,6 +379,7 @@ void AliVAnalysisMuon::Terminate(Option_t *)
     TString sopt = fTerminateOptions->At(3)->GetName();
     if ( sopt.Contains("verbose") ) fMergeableCollection->Print("*"); 
   }
+  SetCentralityClassesFromOutput();
 }
 
 
@@ -645,8 +647,9 @@ TObject* AliVAnalysisMuon::GetSum(TString physSel, TString trigClassNames, TStri
   /// Sum objects
   /// - physSel, trigClassNames must be in the form: key1,key2
   /// - centrality must be in the form minValue_maxValue
-  /// - objectPattern must be in the form match1&match2&match3,match4
-  ///   meaning that the object name must contain match1 and match2 and either one of match3 and match4
+  /// - objectPattern must be in the form match1,match2
+  ///   meaning that the object name must contain match1 and match2 (and either one of match3 and match4
+  ///   wildcard * is allowed
   
   if ( ! fMergeableCollection ) return 0x0;
   
@@ -671,15 +674,15 @@ TObject* AliVAnalysisMuon::GetSum(TString physSel, TString trigClassNames, TStri
     sumCentralityString += fCentralityClasses->GetBinLabel(icent);
   }
   
-  objectPattern.ReplaceAll(" ","");
-  TObjArray* objPatternList = objectPattern.Tokenize("&");
-  TObjArray objPatternMatrix(objPatternList->GetEntries());
-  objPatternMatrix.SetOwner();
-  for ( Int_t ikey=0; ikey<objPatternList->GetEntries(); ikey++ ) {
-    TObjArray* subKeyList = ((TObjString*)objPatternList->At(ikey))->GetString().Tokenize(",");
-    objPatternMatrix.AddAt(subKeyList, ikey);
-  }
-  delete objPatternList;
+//  objectPattern.ReplaceAll(" ","");
+//  TObjArray* objPatternList = objectPattern.Tokenize("&");
+//  TObjArray objPatternMatrix(objPatternList->GetEntries());
+//  objPatternMatrix.SetOwner();
+//  for ( Int_t ikey=0; ikey<objPatternList->GetEntries(); ikey++ ) {
+//    TObjArray* subKeyList = ((TObjString*)objPatternList->At(ikey))->GetString().Tokenize(",");
+//    objPatternMatrix.AddAt(subKeyList, ikey);
+//  }
+//  delete objPatternList;
   
 
   TObjArray objectNameInCollection;
@@ -703,30 +706,53 @@ TObject* AliVAnalysisMuon::GetSum(TString physSel, TString trigClassNames, TStri
   delete physSelList;
   delete trigClassList;
   delete centralityList;
+  
+  TObjArray* objPatternList = objectPattern.Tokenize(",");
 
   TString matchingObjectNames = "";
   for ( Int_t iobj=0; iobj<objectNameInCollection.GetEntries(); iobj++ ) {
     TString objName = objectNameInCollection.At(iobj)->GetName();
-    Bool_t matchAnd = kTRUE;
-    for ( Int_t ikey=0; ikey<objPatternMatrix.GetEntries(); ikey++ ) {
-      TObjArray*  subKeyList = (TObjArray*)objPatternMatrix.At(ikey);
-      Bool_t matchOr = kFALSE;
-      for ( Int_t isub=0; isub<subKeyList->GetEntries(); isub++ ) {
-        TString subKeyString = ((TObjString*)subKeyList->At(isub))->GetString();
-        if ( objName.Contains(subKeyString.Data()) ) {
-          matchOr = kTRUE;
-          break;
-        }
-      }
-      if ( ! matchOr ) {
-        matchAnd = kFALSE;
-        break;
+    for ( Int_t ipat=0; ipat<objPatternList->GetEntries(); ipat++ ) {
+      TString currPattern = ((TObjString*)objPatternList->At(ipat))->GetString();
+      if ( currPattern.Contains("*") ) {
+        if ( ! objName.Contains(TRegexp(currPattern.Data(),kTRUE)) ) continue;
       }
+      else if ( objName != currPattern ) continue;
+
+      if ( ! matchingObjectNames.IsNull() ) matchingObjectNames.Append(",");
+      matchingObjectNames += objName;
     }
-    if ( ! matchAnd ) continue;
-    if ( ! matchingObjectNames.IsNull() ) matchingObjectNames.Append(",");
-    matchingObjectNames += objName;
   }
+  delete objPatternList;
+  
+//  for ( Int_t iobj=0; iobj<objectNameInCollection.GetEntries(); iobj++ ) {
+//    TString objName = objectNameInCollection.At(iobj)->GetName();
+//    Bool_t matchAnd = kTRUE;
+//    for ( Int_t ikey=0; ikey<objPatternMatrix.GetEntries(); ikey++ ) {
+//      TObjArray*  subKeyList = (TObjArray*)objPatternMatrix.At(ikey);
+//      Bool_t matchOr = kFALSE;
+//      for ( Int_t isub=0; isub<subKeyList->GetEntries(); isub++ ) {
+//        TString subKeyString = ((TObjString*)subKeyList->At(isub))->GetString();
+//        if ( subKeyString.Contains("*") ) {
+//          if ( objName.Contains(TRegexp(subKeyString.Data())) ) {
+//            matchOr = kTRUE;
+//            break;
+//          }
+//        }
+//        else if ( objName == subKeyString ) {
+//          matchOr = kTRUE;
+//          break;
+//        }
+//      }
+//      if ( ! matchOr ) {
+//        matchAnd = kFALSE;
+//        break;
+//      }
+//    }
+//    if ( ! matchAnd ) continue;
+//    if ( ! matchingObjectNames.IsNull() ) matchingObjectNames.Append(",");
+//    matchingObjectNames += objName;
+//  }
 
   TString idPattern = Form("/%s/%s/%s/%s", physSel.Data(), trigClassNames.Data(), sumCentralityString.Data(), matchingObjectNames.Data());
   idPattern.ReplaceAll(" ","");
@@ -900,6 +926,47 @@ void AliVAnalysisMuon::SetCentralityClasses(Int_t nCentralityBins, Double_t* cen
 }
 
 //________________________________________________________________________
+Bool_t AliVAnalysisMuon::SetCentralityClassesFromOutput()
+{
+  //
+  /// Get axis of centrality classes from output key
+  //
+  if ( ! fMergeableCollection ) return kFALSE;
+  TList* centrKeyList = fMergeableCollection->CreateListOfKeys(2);
+  TObjArray centrLimitsList;
+  centrLimitsList.SetOwner();
+  if ( ! centrKeyList ) return kFALSE;
+  for ( Int_t ikey=0; ikey<centrKeyList->GetEntries(); ikey++ ) {
+    TString centr = static_cast<TObjString*>(centrKeyList->At(ikey))->GetString();
+    TObjArray* array = centr.Tokenize("_");
+    for ( Int_t ilim=0; ilim<array->GetEntries(); ilim++ ) {
+      TString currLim = static_cast<TObjString*>(array->At(ilim))->GetString();
+      if ( ! centrLimitsList.FindObject(currLim.Data()) ) centrLimitsList.Add(new TObjString(currLim));
+    }
+    delete array;
+  }
+  delete centrKeyList;
+  
+  // Get unsorted array
+  TArrayD bins(centrLimitsList.GetEntries());
+  for ( Int_t ibin=0; ibin<centrLimitsList.GetEntries(); ibin++ ) {
+    bins[ibin] = static_cast<TObjString*>(centrLimitsList.At(ibin))->GetString().Atof();
+  }
+  
+  // Sort it
+  Int_t index[bins.GetSize()];
+  TMath::Sort(bins.GetSize(),bins.GetArray(),index, kFALSE);
+  
+  TArrayD sortedBins(bins.GetSize());
+  for ( Int_t ibin=0; ibin<centrLimitsList.GetEntries(); ibin++ ) {
+    sortedBins[ibin] = bins[index[ibin]];
+  }
+  
+  SetCentralityClasses(sortedBins.GetSize()-1, sortedBins.GetArray());
+  return kTRUE;
+}
+
+//________________________________________________________________________
 void AliVAnalysisMuon::SetTerminateOptions(TString physSel, TString trigClass, TString centralityRange, TString furtherOpts)
 {
   //
index 55f5106..cd24b4c 100644 (file)
@@ -42,8 +42,9 @@ class AliVAnalysisMuon : public AliAnalysisTaskSE {
   virtual void   FinishTaskOutput();
 
   void SetCentralityClasses(Int_t nCentralityBins = -1, Double_t* centralityBins = 0x0);
+  Bool_t SetCentralityClassesFromOutput();
 
-  void SetTrigClassPatterns(TString pattern = "CINT CMU !CMUP CMBAC CPBI !-ACE- !-AC- !-E- !WU !EGA !EJE");
+  void SetTrigClassPatterns(TString pattern = "CINT CMU !CMUP CMBAC CPBI !-ACE- !-AC- !-E- !WU !EGA !EJE !PHS");
   void SetTrigClassLevels(TString pattern = "MSL:Lpt MSH:Hpt MUL:Lpt MLL:Lpt");
   void SetTerminateOptions(TString physSel="All", TString trigClass="ANY", TString centralityRange="", TString furtherOpts="");
   
index bab47d9..b9e39ce 100644 (file)
@@ -128,7 +128,7 @@ Bool_t AliAnalysisTaskTrigChEff::FillEffHistoList(TString physSel, TString trigC
   Bool_t isOk = kTRUE;
   for ( Int_t icount=0; icount<kNcounts; ++icount ) {
     histoName = GetHistoName(kHchamberEff, icount, -1, -1, -1);
-    histoPattern = Form("%s&%s", histoName.Data(), trackSelection.Data());
+    histoPattern = Form("%s%s", histoName.Data(), trackSelection.Data());
     histo = (TH1*)GetSum(physSel, trigClassNames, centrality, histoPattern);
     if ( histo ) {
       histo->SetName(histoName.Data());
@@ -141,7 +141,7 @@ Bool_t AliAnalysisTaskTrigChEff::FillEffHistoList(TString physSel, TString trigC
   for ( Int_t icount=0; icount<kNcounts; ++icount ) {
     for ( Int_t ich=0; ich<4; ++ich ) {
       histoName = GetHistoName(kHslatEff, icount, ich, -1, -1);
-      histoPattern = Form("%s&%s", histoName.Data(), trackSelection.Data());
+      histoPattern = Form("%s%s", histoName.Data(), trackSelection.Data());
       histo = (TH1*)GetSum(physSel, trigClassNames, centrality, histoPattern);
       if ( histo ) {
         histo->SetName(histoName.Data());
@@ -155,7 +155,7 @@ Bool_t AliAnalysisTaskTrigChEff::FillEffHistoList(TString physSel, TString trigC
   for ( Int_t icount=0; icount<kNcounts; ++icount ) {
     for ( Int_t ich=0; ich<4; ++ich ) {
       histoName = GetHistoName(kHboardEff, icount, ich, -1, -1);
-      histoPattern = Form("%s&%s", histoName.Data(), trackSelection.Data());
+      histoPattern = Form("%s%s", histoName.Data(), trackSelection.Data());
       histo = (TH1*)GetSum(physSel, trigClassNames, centrality, histoPattern);
       if ( histo ) {
         histo->SetName(histoName.Data());
@@ -168,7 +168,7 @@ Bool_t AliAnalysisTaskTrigChEff::FillEffHistoList(TString physSel, TString trigC
   }
   
   histoName = GetHistoName(kHcheckBoard, -1, -1, -1, -1);
-  histoPattern = Form("%s&%s", histoName.Data(), trackSelection.Data());
+  histoPattern = Form("%s%s", histoName.Data(), trackSelection.Data());
   histo = (TH1*)GetSum(physSel, trigClassNames, centrality, histoPattern);
   if ( histo ) {
     histo->SetName(histoName.Data());
@@ -220,7 +220,7 @@ void AliAnalysisTaskTrigChEff::FinishTaskOutput()
   TString physSel = fPhysSelKeys->At(kPhysSelPass)->GetName();
   TString trigClass = "ANY";
   TString centrality = "all";
-  TString histoPattern = Form("%s&%s",fTrackSelKeys->At(kMatchApt)->GetName(),fEffMethodKeys->At(kEffFromTrack)->GetName());
+  TString histoPattern = Form("%s%s",fTrackSelKeys->At(kMatchApt)->GetName(),fEffMethodKeys->At(kEffFromTrack)->GetName());
   
   FillEffHistoList(physSel, trigClass, centrality, histoPattern, fList);
 
@@ -473,6 +473,7 @@ void AliAnalysisTaskTrigChEff::Terminate(Option_t *)
   AliVAnalysisMuon::Terminate("");
   
   if ( ! fMergeableCollection ) return;
+  
 
   Int_t xshift = 100;
   Int_t yshift = 20;
@@ -539,11 +540,11 @@ void AliAnalysisTaskTrigChEff::Terminate(Option_t *)
             for ( Int_t imethodSel=0; imethodSel<methodSel.GetEntries(); ++imethodSel ) {
               for ( Int_t itrackSel=0; itrackSel<trackSel.GetEntries(); ++itrackSel ) {
                 histoName = GetHistoName(chosenType, kAllTracks, ich, -1, -1); // partial name
-                histoName += Form("&%s&%s",trackSel.At(itrackSel)->GetName(),methodSel.At(imethodSel)->GetName());
+                histoName += Form("%s%s",trackSel.At(itrackSel)->GetName(),methodSel.At(imethodSel)->GetName());
                 den = (TH1*)GetSum(physSel->At(isel)->GetName(), trigClasses->At(itrig)->GetName(), centrality->At(icent)->GetName(), histoName.Data());
                 if ( ! den ) continue;
                 histoName = GetHistoName(chosenType, icount, ich, -1, -1); // partial name
-                histoName += Form("&%s&%s",trackSel.At(itrackSel)->GetName(),methodSel.At(imethodSel)->GetName());
+                histoName += Form("%s%s",trackSel.At(itrackSel)->GetName(),methodSel.At(imethodSel)->GetName());
                 num = (TH1*)GetSum(physSel->At(isel)->GetName(), trigClasses->At(itrig)->GetName(), centrality->At(icent)->GetName(), histoName.Data());
                 if ( ! num ) continue;
                 effGraph = new TGraphAsymmErrors(num, den);