]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliPhysicsSelectionTask.cxx
- introduction of gain scenarios (e.g. OROC only - for homogeneous gain in 11h)
[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   fBranchNames = "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,AliESDVZERO.,"
51                  "AliESDZDC.,SPDVertex.,PrimaryVertex.,TPCVertex.,Tracks,SPDPileupVertices";
52   
53   AliLog::SetClassDebugLevel("AliPhysicsSelectionTask", AliLog::kWarning);
54 }
55
56 AliPhysicsSelectionTask::~AliPhysicsSelectionTask()
57 {
58   //
59   // Destructor
60   //
61
62   // histograms are in the output list and deleted when the output
63   // list is deleted by the TSelector dtor
64
65   if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
66     delete fOutput;
67     fOutput = 0;
68   }
69 }
70
71 void AliPhysicsSelectionTask::UserCreateOutputObjects()
72 {
73   // create result objects and add to output list
74
75   Printf("AliPhysicsSelectionTask::CreateOutputObjects");
76
77   fOutput = new TList;
78   fOutput->SetOwner();
79   
80   if (!fPhysicsSelection)
81     fPhysicsSelection = new AliPhysicsSelection;
82   
83   fOutput->Add(fPhysicsSelection);
84   // All tasks must post data once for all outputs (AG)
85   PostData(1, fOutput);
86 }
87
88 void AliPhysicsSelectionTask::UserExec(Option_t*)
89 {
90   // process the event
91
92   // AliPhysicsSelection::IsCollisionCandidate is called from the event handler
93   // post the data here anyway!
94   PostData(1, fOutput);
95 }
96
97 void AliPhysicsSelectionTask::FinishTaskOutput()
98 {
99 // This gets called at the end of the processing on the worker. It allows dumping
100 // statistics printed by the physics selection object to the statistics message
101 // handled by the analysis manager.
102    if (fPhysicsSelection) fPhysicsSelection->Print("STAT");
103 }
104
105 void AliPhysicsSelectionTask::Terminate(Option_t *)
106 {
107   // The Terminate() function is the last function to be called during
108   // a query. It always runs on the client, it can be used to present
109   // the results graphically or save the results to file.
110
111   fOutput = dynamic_cast<TList*> (GetOutputData(1));
112   if (!fOutput)
113     Printf("ERROR: fOutput not available");
114     
115   if (fOutput)
116   {
117     fPhysicsSelection = dynamic_cast<AliPhysicsSelection*> (fOutput->FindObject("AliPhysicsSelection"));
118   }
119
120   TFile* fout = new TFile("event_stat.root", "RECREATE");
121
122   if (fPhysicsSelection)
123   {
124     fPhysicsSelection->Print();
125     fPhysicsSelection->SaveHistograms();
126   }
127     
128   fout->Write();
129   fout->Close();
130   
131   Printf("Writting result to event_stat.root");
132 }