]>
Commit | Line | Data |
---|---|---|
be94a07d | 1 | /* $Id$ */ |
2 | ||
3 | #include <TFile.h> | |
4 | #include <TH1F.h> | |
5 | #include <TH2F.h> | |
6 | #include <TROOT.h> | |
7 | #include "AliAnalysisDataContainer.h" | |
8 | #include "AliAnalysisDataSlot.h" | |
9 | #include "AliAnalysisManager.h" | |
10 | #include "AliEmcalPhysicsSelection.h" | |
11 | #include "AliEmcalPhysicsSelectionTask.h" | |
12 | #include "AliESDEvent.h" | |
13 | #include "AliInputEventHandler.h" | |
14 | #include "AliLog.h" | |
15 | ||
16 | ClassImp(AliEmcalPhysicsSelectionTask) | |
17 | ||
18 | //__________________________________________________________________________________________________ | |
19 | AliEmcalPhysicsSelectionTask::AliEmcalPhysicsSelectionTask() : | |
20 | AliPhysicsSelectionTask(), | |
21 | fDoWriteHistos(1), | |
22 | fNCalled(0), | |
23 | fNAccepted(0), | |
24 | fHAcc(0) | |
25 | { | |
26 | // Default constructor. | |
27 | } | |
28 | ||
29 | //__________________________________________________________________________________________________ | |
30 | AliEmcalPhysicsSelectionTask::AliEmcalPhysicsSelectionTask(const char* opt) : | |
31 | AliPhysicsSelectionTask(), | |
32 | fDoWriteHistos(1), | |
33 | fNCalled(0), | |
34 | fNAccepted(0), | |
35 | fHAcc(0) | |
36 | { | |
37 | // Constructor. | |
38 | ||
39 | fOption = opt; | |
40 | fPhysicsSelection = new AliEmcalPhysicsSelection; | |
41 | ||
42 | AliInputEventHandler* handler = dynamic_cast<AliInputEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()); | |
43 | if (handler) { | |
44 | handler->SetEventSelection(fPhysicsSelection); | |
45 | AliInfo("Physics Event Selection enabled."); | |
46 | } else { | |
47 | AliError("No input event handler connected to analysis manager. No Physics Event Selection."); | |
48 | } | |
49 | // Define input and output slots here | |
50 | DefineOutput(1, TList::Class()); | |
51 | fBranchNames = "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,AliESDFMD.,AliESDVZERO.,AliESDZDC.,SPDVertex.,PrimaryVertex."; | |
52 | ||
53 | AliLog::SetClassDebugLevel("AliEmcalPhysicsSelectionTask", AliLog::kWarning); | |
54 | } | |
55 | ||
56 | //__________________________________________________________________________________________________ | |
57 | void AliEmcalPhysicsSelectionTask::UserCreateOutputObjects() | |
58 | { | |
59 | // User create outputs. | |
60 | ||
61 | AliPhysicsSelectionTask::UserCreateOutputObjects(); | |
62 | fHAcc = new TH1D("hEvCount",";0=rej/1=acc;#",2,-0.5,1.5); | |
63 | fOutput->Add(fHAcc); | |
64 | if (!fDoWriteHistos) { | |
65 | fOutput->Remove(fPhysicsSelection); | |
66 | } | |
67 | } | |
68 | ||
69 | //__________________________________________________________________________________________________ | |
70 | void AliEmcalPhysicsSelectionTask::UserExec(const Option_t *opt) | |
71 | { | |
72 | // User exec. | |
73 | ||
74 | AliPhysicsSelectionTask::UserExec(opt); | |
75 | ||
76 | ++fNCalled; | |
77 | ||
78 | UInt_t res = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected(); | |
79 | if (res>0) { | |
80 | ++fNAccepted; | |
81 | fHAcc->Fill(1); | |
82 | } else { | |
83 | fHAcc->Fill(0); | |
84 | } | |
85 | } | |
86 | ||
87 | //__________________________________________________________________________________________________ | |
88 | void AliEmcalPhysicsSelectionTask::Terminate(Option_t *) | |
89 | { | |
90 | // The Terminate() function is the last function to be called during | |
91 | // a query. It always runs on the client, it can be used to present | |
92 | // the results graphically or save the results to file. | |
93 | ||
94 | AliInfo(Form("Called %d times, accepted %d events", fNCalled, fNAccepted)); | |
95 | ||
96 | if (!fDoWriteHistos) | |
97 | return; | |
98 | ||
99 | fOutput = dynamic_cast<TList*> (GetOutputData(1)); | |
100 | if (!fOutput) { | |
101 | AliError("fOutput not available"); | |
102 | return; | |
103 | } | |
104 | ||
105 | AliAnalysisDataSlot *oslot = GetOutputSlot(1); | |
106 | if (!oslot) | |
107 | return; | |
108 | ||
109 | AliAnalysisDataContainer *ocont = oslot->GetContainer(); | |
110 | if (!ocont) | |
111 | return; | |
112 | ||
113 | TFile *file = OpenFile(1); | |
114 | if (!file) | |
115 | return; | |
116 | ||
117 | TDirectory::TContext context(file); | |
118 | if (AliAnalysisManager::GetAnalysisManager()->IsProofMode()) { | |
119 | fPhysicsSelection = dynamic_cast<AliPhysicsSelection*> (fOutput->FindObject("AliPhysicsSelection")); | |
120 | } | |
121 | if (fPhysicsSelection) { | |
122 | //fPhysicsSelection->Print(); | |
123 | fPhysicsSelection->SaveHistograms(Form("%sHists",ocont->GetName())); | |
124 | AliInfo(Form("Writing result to %s",file->GetName())); | |
125 | } | |
126 | fOutput->Remove(fPhysicsSelection); | |
127 | } |