]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGLF/FORWARD/analysis2/AliForwardUtil.cxx
Fixes for pA indenfication of events
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliForwardUtil.cxx
index 07d5ca53512a87f4538efcd6a6f8e33cb435d9ac..182f33a0762d7d1800b00704633adc1ebb6a5dc1 100644 (file)
@@ -7,16 +7,22 @@
 #include "AliAODForwardMult.h"
 #include <AliLog.h>
 #include <AliInputEventHandler.h>
+#include <AliAODInputHandler.h>
+#include <AliAODHandler.h>
+#include <AliAODEvent.h>
 #include <AliESDEvent.h>
+#include <AliAnalysisTaskSE.h>
 #include <AliPhysicsSelection.h>
 #include <AliTriggerAnalysis.h>
 #include <AliMultiplicity.h>
+#include <TParameter.h>
 #include <TH2D.h>
 #include <TH1I.h>
 #include <TF1.h>
 #include <TFitResult.h>
 #include <TMath.h>
 #include <TError.h>
+#include <TROOT.h>
 
 //====================================================================
 UShort_t
@@ -41,6 +47,7 @@ AliForwardUtil::ParseCollisionSystem(const char* sys)
   // we do pA first to avoid pp catch on ppb string (AH)
   if (s.Contains("p-pb")  || s.Contains("ppb"))   return AliForwardUtil::kPPb;
   if (s.Contains("p-a")   || s.Contains("pa"))    return AliForwardUtil::kPPb;
+  if (s.Contains("a-p")   || s.Contains("ap"))    return AliForwardUtil::kPPb;
   if (s.Contains("p-p")   || s.Contains("pp"))    return AliForwardUtil::kPP; 
   if (s.Contains("pb-pb") || s.Contains("pbpb"))  return AliForwardUtil::kPbPb;
   if (s.Contains("a-a")   || s.Contains("aa"))    return AliForwardUtil::kPbPb;
@@ -91,6 +98,7 @@ AliForwardUtil::ParseCenterOfMassEnergy(UShort_t /* sys */, Float_t v)
   if (TMath::Abs(energy - 2400.)  < 10)  return 2400;
   if (TMath::Abs(energy - 2750.)  < 20)  return 2750;
   if (TMath::Abs(energy - 4400.)  < 10)  return 4400;
+  if (TMath::Abs(energy - 5022.)  < 10)  return 5000;
   if (TMath::Abs(energy - 5500.)  < 40)  return 5500;
   if (TMath::Abs(energy - 7000.)  < 10)  return 7000;
   if (TMath::Abs(energy - 8000.)  < 10)  return 8000;
@@ -146,6 +154,126 @@ AliForwardUtil::MagneticFieldString(Short_t f)
   //
   return Form("%01dkG", f);
 }
+//_____________________________________________________________________
+AliAODEvent* AliForwardUtil::GetAODEvent(AliAnalysisTaskSE* task)
+{
+  // Check if AOD is the output event
+  if (!task) ::Fatal("GetAODEvent", "Null task given, cannot do that");
+
+  AliAODEvent* ret = task->AODEvent();
+  if (ret) return ret; 
+  
+  // Check if AOD is the input event 
+  ret = dynamic_cast<AliAODEvent*>(task->InputEvent());
+  if (!ret) ::Warning("GetAODEvent", "No AOD event found");
+  
+  return ret; 
+}
+//_____________________________________________________________________
+UShort_t AliForwardUtil::CheckForAOD()
+{
+  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
+  if (dynamic_cast<AliAODInputHandler*>(am->GetInputEventHandler())) {
+    ::Info("CheckForAOD", "Found AOD Input handler");
+    return 1;
+  }
+  if (dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler())) {
+    ::Info("CheckForAOD", "Found AOD Output handler");
+    return 2;
+  }
+
+  ::Warning("CheckForAOD", 
+           "Neither and input nor output AOD handler is specified");
+  return 0;
+}
+//_____________________________________________________________________
+Bool_t AliForwardUtil::CheckForTask(const char* clsOrName, Bool_t cls)
+{
+  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
+  if (!cls) { 
+    AliAnalysisTask* t = am->GetTask(clsOrName);
+    if (!t) { 
+      ::Warning("CheckForTask", "Task %s not found in manager", clsOrName);
+      return false;
+    }
+    ::Info("CheckForTask", "Found task %s", clsOrName);
+    return true;
+  }
+  TClass* dep = gROOT->GetClass(clsOrName);
+  if (!dep) { 
+    ::Warning("CheckForTask", "Unknown class %s for needed task", clsOrName);
+    return false;
+  }
+  TIter next(am->GetTasks());
+  TObject* o = 0;
+  while ((o = next())) { 
+    if (o->IsA()->InheritsFrom(dep)) {
+      ::Info("CheckForTask", "Found task of class %s: %s", 
+            clsOrName, o->GetName());
+      return true;
+    }
+  }
+  ::Warning("CheckForTask", "No task of class %s was found", clsOrName);
+  return false;
+}
+
+//_____________________________________________________________________
+TObject* AliForwardUtil::MakeParameter(const Char_t* name, UShort_t value)
+{
+  TParameter<int>* ret = new TParameter<int>(name, value);
+  ret->SetUniqueID(value);
+  return ret;
+}
+//_____________________________________________________________________
+TObject* AliForwardUtil::MakeParameter(const Char_t* name, Int_t value)
+{
+  TParameter<int>* ret = new TParameter<int>(name, value);
+  ret->SetUniqueID(value);
+  return ret;
+}
+//_____________________________________________________________________
+TObject* AliForwardUtil::MakeParameter(const Char_t* name, Double_t value)
+{
+  TParameter<double>* ret = new TParameter<double>(name, value);
+  Float_t v = value;
+  ret->SetUniqueID(*reinterpret_cast<UInt_t*>(&v));
+  return ret;
+}
+//_____________________________________________________________________
+TObject* AliForwardUtil::MakeParameter(const Char_t* name, Bool_t value)
+{
+  TParameter<bool>* ret = new TParameter<bool>(name, value);
+  ret->SetUniqueID(value);
+  return ret;
+}
+
+//_____________________________________________________________________
+void AliForwardUtil::GetParameter(TObject* o, UShort_t& value)
+{
+  if (!o) return;
+  value = o->GetUniqueID();
+}
+//_____________________________________________________________________
+void AliForwardUtil::GetParameter(TObject* o, Int_t& value)
+{
+  if (!o) return;
+  value = o->GetUniqueID();
+}
+//_____________________________________________________________________
+void AliForwardUtil::GetParameter(TObject* o, Double_t& value)
+{
+  if (!o) return;
+  UInt_t  i = o->GetUniqueID();
+  Float_t v = *reinterpret_cast<Float_t*>(&i);
+  value = v;
+}
+//_____________________________________________________________________
+void AliForwardUtil::GetParameter(TObject* o, Bool_t& value)
+{
+  if (!o) return;
+  value = o->GetUniqueID();
+}
+  
 //_____________________________________________________________________
 Double_t AliForwardUtil::GetEtaFromStrip(UShort_t det, Char_t ring, UShort_t sec, UShort_t strip, Double_t zvtx)
 {
@@ -925,6 +1053,61 @@ AliForwardUtil::RingHistos::GetOutputHist(const TList* d, const char* name) cons
   return static_cast<TH1*>(d->FindObject(name));
 }
 
+//====================================================================
+AliForwardUtil::DebugGuard::DebugGuard(Int_t lvl, Int_t msgLvl, 
+                                      const char* format, ...)
+  : fMsg("")
+{
+  if (lvl < msgLvl) return; 
+  va_list ap;
+  va_start(ap, format);
+  Format(fMsg, format, ap);
+  va_end(ap);
+  Output(+1, fMsg);
+}
+//____________________________________________________________________
+AliForwardUtil::DebugGuard::~DebugGuard()
+{
+  if (fMsg.IsNull()) return;
+  Output(-1, fMsg);
+}
+//____________________________________________________________________
+void
+AliForwardUtil::DebugGuard::Message(Int_t lvl, Int_t msgLvl, 
+                                   const char* format, ...)
+{
+  if (lvl < msgLvl) return; 
+  TString msg;
+  va_list ap;
+  va_start(ap, format);
+  Format(msg, format, ap);
+  va_end(ap);
+  Output(0, msg);
+}
+
+//____________________________________________________________________
+void
+AliForwardUtil::DebugGuard::Format(TString& out, const char* format, va_list ap)
+{
+  static char buf[512];
+  Int_t n = gROOT->GetDirLevel() + 2;
+  for (Int_t i = 0; i < n; i++) buf[i] = ' ';
+  vsnprintf(&(buf[n]), 511-n, format, ap);
+  buf[511] = '\0';
+  out = buf;  
+}
+//____________________________________________________________________
+void
+AliForwardUtil::DebugGuard::Output(int in, TString& msg)
+{
+  msg[0] = (in > 0 ? '>' :  in < 0 ? '<' : '=');
+  AliLog::Message(AliLog::kInfo, msg, 0, 0, "PWGLF/forward", 0, 0);
+  if      (in > 0) gROOT->IncreaseDirLevel();
+  else if (in < 0) gROOT->DecreaseDirLevel();
+}
+
+
+
 //
 // EOF
 //