]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGUD/selectors/eventStats/AliEventStatsTask.cxx
d624126be36f898fb3b86ce79266f0e23bc42855
[u/mrichter/AliRoot.git] / PWGUD / selectors / eventStats / AliEventStatsTask.cxx
1 /* $Id: AliEventStatsTask.cxx 35782 2009-10-22 11:54:31Z jgrosseo $ */
2
3 #include "AliEventStatsTask.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 "AliBackgroundSelection.h"
15
16 ClassImp(AliEventStatsTask)
17
18 AliEventStatsTask::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
34 AliEventStatsTask::~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
49 void 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   
58   if (!fPhysicsSelection)
59     fPhysicsSelection = new AliPhysicsSelection;
60   
61   fOutput->Add(fPhysicsSelection);
62 }
63
64 void 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
82 void 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 }