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