Task for physics selection
[u/mrichter/AliRoot.git] / ANALYSIS / AliPhysicsSelectionTask.cxx
CommitLineData
78167ba7 1/* $Id$ */
2
3#include "AliPhysicsSelectionTask.h"
4
5#include <TFile.h>
6#include <TH1F.h>
7#include <TH2F.h>
8
9#include <AliLog.h>
10#include <AliESDEvent.h>
11#include <AliHeader.h>
12
13#include "AliPhysicsSelection.h"
14#include "AliAnalysisManager.h"
15#include "AliInputEventHandler.h"
16
17//#include "AliBackgroundSelection.h"
18
19ClassImp(AliPhysicsSelectionTask)
20
21AliPhysicsSelectionTask::AliPhysicsSelectionTask() :
22 AliAnalysisTaskSE("AliPhysicsSelectionTask"),
23 fOutput(0),
24 fOption(""),
25 fPhysicsSelection(0)
26{
27 //
28 // Default event handler
29 //
30}
31
32AliPhysicsSelectionTask::AliPhysicsSelectionTask(const char* opt) :
33 AliAnalysisTaskSE("AliPhysicsSelectionTask"),
34 fOutput(0),
35 fOption(opt),
36 fPhysicsSelection(new AliPhysicsSelection())
37{
38 //
39 // Constructor. Initialization of pointers
40 //
41 AliInputEventHandler* handler = dynamic_cast<AliInputEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
42 if (handler) {
43 handler->SetEventSelection(fPhysicsSelection);
44 AliInfo("Physics Event Selection enabled.");
45 } else {
46 AliError("No input event handler connected to analysis manager. No Physics Event Selection.");
47 }
48 // Define input and output slots here
49 DefineOutput(1, TList::Class());
50
51 AliLog::SetClassDebugLevel("AliPhysicsSelectionTask", AliLog::kWarning);
52}
53
54AliPhysicsSelectionTask::~AliPhysicsSelectionTask()
55{
56 //
57 // Destructor
58 //
59
60 // histograms are in the output list and deleted when the output
61 // list is deleted by the TSelector dtor
62
63 if (fOutput) {
64 delete fOutput;
65 fOutput = 0;
66 }
67}
68
69void AliPhysicsSelectionTask::UserCreateOutputObjects()
70{
71 // create result objects and add to output list
72
73 Printf("AliPhysicsSelectionTask::CreateOutputObjects");
74
75 fOutput = new TList;
76 fOutput->SetOwner();
77
78 if (!fPhysicsSelection)
79 fPhysicsSelection = new AliPhysicsSelection;
80
81 fOutput->Add(fPhysicsSelection);
82}
83
84void AliPhysicsSelectionTask::UserExec(Option_t*)
85{
86 // process the event
87
88 // post the data already here
89 PostData(1, fOutput);
90
91 AliESDEvent* esd = dynamic_cast<AliESDEvent*> (InputEvent());
92
93 if (!esd)
94 {
95 AliError("ESD branch not available");
96 return;
97 }
98
99 fPhysicsSelection->IsCollisionCandidate(esd);
100}
101
102void AliPhysicsSelectionTask::Terminate(Option_t *)
103{
104 // The Terminate() function is the last function to be called during
105 // a query. It always runs on the client, it can be used to present
106 // the results graphically or save the results to file.
107
108 fOutput = dynamic_cast<TList*> (GetOutputData(1));
109 if (!fOutput)
110 Printf("ERROR: fOutput not available");
111
112 if (fOutput)
113 {
114 fPhysicsSelection = dynamic_cast<AliPhysicsSelection*> (fOutput->FindObject("AliPhysicsSelection"));
115 }
116
117 TFile* fout = new TFile("event_stat.root", "RECREATE");
118
119 if (fPhysicsSelection)
120 {
121 fPhysicsSelection->Print();
122 fPhysicsSelection->SaveHistograms("physics_selection");
123 }
124
125 fout->Write();
126 fout->Close();
127
128 Printf("Writting result to event_stat.root");
129}