]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliPhysicsSelectionTask.cxx
in test mode enable packages enabling client compilation
[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
3be0b665 63 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
78167ba7 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);
222dc7b5 82 // All tasks must post data once for all outputs (AG)
83 PostData(1, fOutput);
78167ba7 84}
85
86void AliPhysicsSelectionTask::UserExec(Option_t*)
87{
88 // process the event
89
38c52e61 90 // AliPhysicsSelection::IsCollisionCandidate is called from the event handler
91 // post the data here anyway!
78167ba7 92 PostData(1, fOutput);
78167ba7 93}
94
e9247450 95void AliPhysicsSelectionTask::FinishTaskOutput()
96{
97// This gets called at the end of the processing on the worker. It allows dumping
98// statistics printed by the physics selection object to the statistics message
99// handled by the analysis manager.
100 if (fPhysicsSelection) fPhysicsSelection->Print("STAT");
101}
102
78167ba7 103void AliPhysicsSelectionTask::Terminate(Option_t *)
104{
105 // The Terminate() function is the last function to be called during
106 // a query. It always runs on the client, it can be used to present
107 // the results graphically or save the results to file.
108
109 fOutput = dynamic_cast<TList*> (GetOutputData(1));
110 if (!fOutput)
111 Printf("ERROR: fOutput not available");
112
113 if (fOutput)
114 {
115 fPhysicsSelection = dynamic_cast<AliPhysicsSelection*> (fOutput->FindObject("AliPhysicsSelection"));
116 }
117
118 TFile* fout = new TFile("event_stat.root", "RECREATE");
119
120 if (fPhysicsSelection)
121 {
122 fPhysicsSelection->Print();
decf6fd4 123 fPhysicsSelection->SaveHistograms();
78167ba7 124 }
125
126 fout->Write();
127 fout->Close();
128
129 Printf("Writting result to event_stat.root");
130}