]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliPhysicsSelectionTask.cxx
Beam type (pp or PbPb) is taken from ESD for the initialization of the physics selection
[u/mrichter/AliRoot.git] / ANALYSIS / AliPhysicsSelectionTask.cxx
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
19 ClassImp(AliPhysicsSelectionTask)
20
21 AliPhysicsSelectionTask::AliPhysicsSelectionTask() :
22   AliAnalysisTaskSE("AliPhysicsSelectionTask"),
23   fOutput(0),
24   fOption(""),
25   fPhysicsSelection(0)
26 {
27   //
28   // Default event handler
29   //
30 }
31
32 AliPhysicsSelectionTask::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
54 AliPhysicsSelectionTask::~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 && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
64     delete fOutput;
65     fOutput = 0;
66   }
67 }
68
69 void 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   // All tasks must post data once for all outputs (AG)
83   PostData(1, fOutput);
84 }
85
86 void AliPhysicsSelectionTask::UserExec(Option_t*)
87 {
88   // process the event
89
90   // AliPhysicsSelection::IsCollisionCandidate is called from the event handler
91   // post the data here anyway!
92   PostData(1, fOutput);
93 }
94
95 void 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
103 void 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();
123     fPhysicsSelection->SaveHistograms();
124   }
125     
126   fout->Write();
127   fout->Close();
128   
129   Printf("Writting result to event_stat.root");
130 }