Task for physics selection
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 5 Jan 2010 16:24:15 +0000 (16:24 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 5 Jan 2010 16:24:15 +0000 (16:24 +0000)
- its usage enables physics selection via the input handler
- creates the physics selection object and passes it to the input handler
- manages the histograms (bookkeeping) produced by the selection
(JFGO, AM)

ANALYSIS/ANALYSISaliceLinkDef.h
ANALYSIS/AliPhysicsSelectionTask.cxx [new file with mode: 0644]
ANALYSIS/AliPhysicsSelectionTask.h [new file with mode: 0644]
ANALYSIS/libANALYSISalice.pkg
ANALYSIS/macros/AddTaskPhysicsSelection.C [new file with mode: 0644]

index eb413da..c5df86f 100644 (file)
@@ -23,7 +23,9 @@
 #pragma link C++ class AliMultiEventInputHandler+;
 
 #pragma link C++ class AliTriggerAnalysis+;
+
 #pragma link C++ class AliPhysicsSelection+;
+#pragma link C++ class AliPhysicsSelectionTask+;
 
 #pragma link C++ class  AliAnalysisFilter+;
 #pragma link C++ class  AliAnalysisCuts+;
diff --git a/ANALYSIS/AliPhysicsSelectionTask.cxx b/ANALYSIS/AliPhysicsSelectionTask.cxx
new file mode 100644 (file)
index 0000000..7d98b90
--- /dev/null
@@ -0,0 +1,129 @@
+/* $Id$ */
+
+#include "AliPhysicsSelectionTask.h"
+
+#include <TFile.h>
+#include <TH1F.h>
+#include <TH2F.h>
+
+#include <AliLog.h>
+#include <AliESDEvent.h>
+#include <AliHeader.h>
+
+#include "AliPhysicsSelection.h"
+#include "AliAnalysisManager.h"
+#include "AliInputEventHandler.h"
+
+//#include "AliBackgroundSelection.h"
+
+ClassImp(AliPhysicsSelectionTask)
+
+AliPhysicsSelectionTask::AliPhysicsSelectionTask() :
+  AliAnalysisTaskSE("AliPhysicsSelectionTask"),
+  fOutput(0),
+  fOption(""),
+  fPhysicsSelection(0)
+{
+  //
+  // Default event handler
+  //
+}
+
+AliPhysicsSelectionTask::AliPhysicsSelectionTask(const char* opt) :
+  AliAnalysisTaskSE("AliPhysicsSelectionTask"),
+  fOutput(0),
+  fOption(opt),
+  fPhysicsSelection(new AliPhysicsSelection())
+{
+  //
+  // Constructor. Initialization of pointers
+  //
+  AliInputEventHandler* handler = dynamic_cast<AliInputEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
+  if (handler) {
+    handler->SetEventSelection(fPhysicsSelection);
+    AliInfo("Physics Event Selection enabled.");
+  } else {
+    AliError("No input event handler connected to analysis manager. No Physics Event Selection.");
+  }
+  // Define input and output slots here
+  DefineOutput(1, TList::Class());
+  
+  AliLog::SetClassDebugLevel("AliPhysicsSelectionTask", AliLog::kWarning);
+}
+
+AliPhysicsSelectionTask::~AliPhysicsSelectionTask()
+{
+  //
+  // Destructor
+  //
+
+  // histograms are in the output list and deleted when the output
+  // list is deleted by the TSelector dtor
+
+  if (fOutput) {
+    delete fOutput;
+    fOutput = 0;
+  }
+}
+
+void AliPhysicsSelectionTask::UserCreateOutputObjects()
+{
+  // create result objects and add to output list
+
+  Printf("AliPhysicsSelectionTask::CreateOutputObjects");
+
+  fOutput = new TList;
+  fOutput->SetOwner();
+  
+  if (!fPhysicsSelection)
+    fPhysicsSelection = new AliPhysicsSelection;
+  
+  fOutput->Add(fPhysicsSelection);
+}
+
+void AliPhysicsSelectionTask::UserExec(Option_t*)
+{
+  // process the event
+
+  // post the data already here
+  PostData(1, fOutput);
+
+  AliESDEvent* esd = dynamic_cast<AliESDEvent*> (InputEvent());
+
+  if (!esd)
+  {
+    AliError("ESD branch not available");
+    return;
+  }
+  
+  fPhysicsSelection->IsCollisionCandidate(esd);
+}
+
+void AliPhysicsSelectionTask::Terminate(Option_t *)
+{
+  // The Terminate() function is the last function to be called during
+  // a query. It always runs on the client, it can be used to present
+  // the results graphically or save the results to file.
+
+  fOutput = dynamic_cast<TList*> (GetOutputData(1));
+  if (!fOutput)
+    Printf("ERROR: fOutput not available");
+    
+  if (fOutput)
+  {
+    fPhysicsSelection = dynamic_cast<AliPhysicsSelection*> (fOutput->FindObject("AliPhysicsSelection"));
+  }
+
+  TFile* fout = new TFile("event_stat.root", "RECREATE");
+
+  if (fPhysicsSelection)
+  {
+    fPhysicsSelection->Print();
+    fPhysicsSelection->SaveHistograms("physics_selection");
+  }
+    
+  fout->Write();
+  fout->Close();
+  
+  Printf("Writting result to event_stat.root");
+}
diff --git a/ANALYSIS/AliPhysicsSelectionTask.h b/ANALYSIS/AliPhysicsSelectionTask.h
new file mode 100644 (file)
index 0000000..de6752e
--- /dev/null
@@ -0,0 +1,43 @@
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+
+/* $Id$ */
+
+#ifndef ALIPHYSICSSELECTIONTASK_H
+#define ALIPHYSICSSELECTIONTASK_H
+
+#include "AliAnalysisTaskSE.h"
+
+class AliPhysicsSelection;
+
+class AliPhysicsSelectionTask : public AliAnalysisTaskSE {
+  public:
+    AliPhysicsSelectionTask();
+    AliPhysicsSelectionTask(const char* opt);
+
+    virtual ~AliPhysicsSelectionTask();
+
+    virtual void   UserCreateOutputObjects();
+    virtual void   UserExec(Option_t*);
+    virtual void   Terminate(Option_t*);
+
+    void SetOption(const char* opt) { fOption = opt; }
+    
+    void SetPhysicsSelection(AliPhysicsSelection* physicsSelection) { fPhysicsSelection = physicsSelection; }
+    AliPhysicsSelection* GetPhysicsSelection() const {return fPhysicsSelection; }
+
+ protected:
+    TList* fOutput;                  //! list send on output slot 1
+    TString fOption;                 // option string  
+    
+    AliPhysicsSelection* fPhysicsSelection; // event selection class
+
+ private:
+    AliPhysicsSelectionTask(const AliPhysicsSelectionTask&);
+    AliPhysicsSelectionTask& operator=(const AliPhysicsSelectionTask&);
+
+  ClassDef(AliPhysicsSelectionTask, 1);
+};
+
+#endif
index c7186a6..288c14d 100644 (file)
@@ -8,6 +8,7 @@ SRCS =  AliAnalysisTaskSE.cxx AliAnalysisTaskME.cxx \
         AliMultiEventInputHandler.cxx \
        AliTriggerAnalysis.cxx \
         AliPhysicsSelection.cxx \
+        AliPhysicsSelectionTask.cxx \
         AliAnalysisFilter.cxx AliAnalysisCuts.cxx 
 
 
diff --git a/ANALYSIS/macros/AddTaskPhysicsSelection.C b/ANALYSIS/macros/AddTaskPhysicsSelection.C
new file mode 100644 (file)
index 0000000..5be0b3a
--- /dev/null
@@ -0,0 +1,43 @@
+
+
+AliPhysicsSelectionTask* AddTaskPhysicsSelection() {
+    
+    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+    if (!mgr) {
+       ::Error("AddTaskQAsym", "No analysis manager to connect to.");
+       return NULL;
+    }  
+    
+    // Check the analysis type using the event handlers connected to the analysis manager.
+    //==============================================================================
+    if (!mgr->GetInputEventHandler()) {
+       ::Error("AddTasQAsym", "This task requires an input event handler");
+       return NULL;
+    }
+    TString inputDataType = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"
+    
+    // Configure analysis
+    //===========================================================================
+    
+    
+
+  AliPhysicsSelectionTask *task= new AliPhysicsSelectionTask("");
+  mgr->AddTask(task);
+
+
+
+  AliAnalysisDataContainer *cinput0 = mgr->GetCommonInputContainer();
+  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("cstatsout",
+                                                           TList::Class(),
+                                                           AliAnalysisManager::kOutputContainer,
+                                                           "EventStat.root");
+
+
+
+  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
+  mgr->ConnectOutput(task,1,coutput1);
+
+  return task;
+  
+}   
+//_____________________________________________________________________________