Make sure that histograms are obtained from output list in
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliForwardUtil.cxx
index 1bccf15e22868d94f31578354d7321395c7d1860..bdf2227f2c080508428bbde6fbcf46387477f3d5 100644 (file)
@@ -1,5 +1,14 @@
 #include "AliForwardUtil.h"
+#include <AliAnalysisManager.h>
+#include "AliAODForwardMult.h"
+#include <AliLog.h>
+#include <AliInputEventHandler.h>
+#include <AliESDEvent.h>
+#include <AliPhysicsSelection.h>
+#include <AliTriggerAnalysis.h>
+#include <AliMultiplicity.h>
 #include <TH2D.h>
+#include <TH1I.h>
 #include <TMath.h>
 
 //====================================================================
@@ -75,6 +84,163 @@ AliForwardUtil::Histos::Get(UShort_t d, Char_t r)
   default: return 0;
 }
 #endif
+//====================================================================
+TList*
+AliForwardUtil::RingHistos::DefineOutputList(TList* d) const
+{
+  if (!d) return 0;
+  TList* list = new TList;
+  list->SetName(fName.Data());
+  d->Add(list);
+  return list;
+}
+//____________________________________________________________________
+TList*
+AliForwardUtil::RingHistos::GetOutputList(TList* d) const
+{
+  if (!d) return 0;
+  TList* list = static_cast<TList*>(d->FindObject(fName.Data()));
+  return list;
+}
+
+//____________________________________________________________________
+TH1*
+AliForwardUtil::RingHistos::GetOutputHist(TList* d, const char* name) const
+{
+  return static_cast<TH1*>(d->FindObject(name));
+}
+
+//====================================================================
+Bool_t
+AliForwardUtil::ReadTriggers(AliESDEvent* esd, UInt_t& triggers,
+                            TH1I* hTriggers)
+{
+  triggers = 0;
+
+  // Get the analysis manager - should always be there 
+  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
+  if (!am) { 
+    AliWarningGeneral("ReadTriggers","No analysis manager defined!");
+    return kFALSE;
+  }
+
+  // Get the input handler - should always be there 
+  AliInputEventHandler* ih = 
+    static_cast<AliInputEventHandler*>(am->GetInputEventHandler());
+  if (!ih) { 
+    AliWarningGeneral("ReadTriggers","No input handler");
+    return kFALSE;
+  }
+  
+  // Get the physics selection - add that by using the macro 
+  // AddTaskPhysicsSelection.C 
+  AliPhysicsSelection* ps = 
+    static_cast<AliPhysicsSelection*>(ih->GetEventSelection());
+  if (!ps) { 
+    AliWarningGeneral("ReadTriggers","No physics selection");
+    return kFALSE;
+  }
+  
+  // Check if this is a collision candidate (INEL)
+  Bool_t inel = ps->IsCollisionCandidate(esd);
+  if (inel) { 
+    triggers |= AliAODForwardMult::kInel;
+    hTriggers->Fill(0.5);
+  }
+
+  // IF this is inel, see if we have a tracklet 
+  if (inel) { 
+    const AliMultiplicity* spdmult = esd->GetMultiplicity();
+    if (!spdmult) {
+      AliWarningGeneral("ReadTriggers","No SPD multiplicity");
+    }
+    else { 
+      Int_t n = spdmult->GetNumberOfTracklets();
+      for (Int_t j = 0; j < n; j++) { 
+       if(TMath::Abs(spdmult->GetEta(j)) < 1) { 
+         triggers |= AliAODForwardMult::kInelGt0;
+         hTriggers->Fill(1.5);
+         break;
+       }
+      }
+    }
+  }
+
+  // Analyse some trigger stuff 
+  AliTriggerAnalysis ta;
+  if (ta.IsOfflineTriggerFired(esd, AliTriggerAnalysis::kNSD1)) {
+    triggers |= AliAODForwardMult::kNSD;
+    hTriggers->Fill(2.5);
+  }
+
+  // Get trigger stuff 
+  TString trigStr = esd->GetFiredTriggerClasses();
+  if (trigStr.Contains("CBEAMB-ABCE-NOPF-ALL")) {
+    triggers |= AliAODForwardMult::kEmpty;
+    hTriggers->Fill(3.5);
+  }
+
+  if (trigStr.Contains("CINT1A-ABCE-NOPF-ALL")) {
+    triggers |= AliAODForwardMult::kA;
+    hTriggers->Fill(4.5);
+  }
+
+  if (trigStr.Contains("CINT1B-ABCE-NOPF-ALL")) {
+    triggers |= AliAODForwardMult::kB;
+    hTriggers->Fill(5.5);
+  }
+
+
+  if (trigStr.Contains("CINT1C-ABCE-NOPF-ALL")) {
+    triggers |= AliAODForwardMult::kC;
+    hTriggers->Fill(6.5);
+  }
+
+  if (trigStr.Contains("CINT1-E-NOPF-ALL")) {
+    triggers |= AliAODForwardMult::kE;
+    hTriggers->Fill(7.5);
+  }
+
+  return kTRUE;
+}
+//____________________________________________________________________
+Bool_t
+AliForwardUtil::ReadVertex(AliESDEvent* esd, Double_t& vz, Double_t maxErr)
+{
+  // Get the vertex 
+  const AliESDVertex* vertex = esd->GetPrimaryVertexSPD();
+  if (!vertex) { 
+#ifdef VERBOSE
+    AliWarningGeneral("ReadVertex","No SPD vertex found in ESD");
+#endif
+    return kFALSE;
+  }
+
+  // Check that enough tracklets contributed 
+  if(vertex->GetNContributors() <= 0) {
+#ifdef VERBOSE
+    AliWarningGeneral("ReadVertex",
+                     Form("Number of contributors to vertex is %d<=0",
+                          vertex->GetNContributors()));
+#endif
+    return kFALSE;
+  }
+
+  // Check that the uncertainty isn't too large 
+  if (vertex->GetZRes() > maxErr) { 
+#ifdef VERBOSE
+    AliWarningGeneral("ReadVertex",
+                     Form("Uncertaintity in Z of vertex is too large %f > %d", 
+                          vertex->GetZRes(), maxErr));
+#endif
+    return kFALSE;
+  }
+
+  // Get the z coordiante 
+  vz = vertex->GetZ();
+              
+  return kTRUE;
+}
 
 //
 // EOF