]>
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), | |
fb81cdb7 | 24 | fHAcc(0), |
25 | fHEvtTypes(0) | |
be94a07d | 26 | { |
27 | // Default constructor. | |
28 | } | |
29 | ||
30 | //__________________________________________________________________________________________________ | |
31 | AliEmcalPhysicsSelectionTask::AliEmcalPhysicsSelectionTask(const char* opt) : | |
32 | AliPhysicsSelectionTask(), | |
33 | fDoWriteHistos(1), | |
34 | fNCalled(0), | |
35 | fNAccepted(0), | |
fb81cdb7 | 36 | fHAcc(0), |
37 | fHEvtTypes(0) | |
be94a07d | 38 | { |
39 | // Constructor. | |
40 | ||
41 | fOption = opt; | |
42 | fPhysicsSelection = new AliEmcalPhysicsSelection; | |
43 | ||
44 | AliInputEventHandler* handler = dynamic_cast<AliInputEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()); | |
45 | if (handler) { | |
46 | handler->SetEventSelection(fPhysicsSelection); | |
47 | AliInfo("Physics Event Selection enabled."); | |
48 | } else { | |
49 | AliError("No input event handler connected to analysis manager. No Physics Event Selection."); | |
50 | } | |
51 | // Define input and output slots here | |
52 | DefineOutput(1, TList::Class()); | |
e51eba5c | 53 | fBranchNames = "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,AliESDVZERO.," |
54 | "AliESDZDC.,SPDVertex.,PrimaryVertex.,TPCVertex.,Tracks,SPDPileupVertices"; | |
be94a07d | 55 | |
56 | AliLog::SetClassDebugLevel("AliEmcalPhysicsSelectionTask", AliLog::kWarning); | |
57 | } | |
58 | ||
59 | //__________________________________________________________________________________________________ | |
60 | void AliEmcalPhysicsSelectionTask::UserCreateOutputObjects() | |
61 | { | |
62 | // User create outputs. | |
63 | ||
64 | AliPhysicsSelectionTask::UserCreateOutputObjects(); | |
65 | fHAcc = new TH1D("hEvCount",";0=rej/1=acc;#",2,-0.5,1.5); | |
66 | fOutput->Add(fHAcc); | |
31e6d0e8 | 67 | fHEvtTypes = new TH1D("hEvtTypes",";#",10,-0.5,9.5); |
fb81cdb7 | 68 | fHEvtTypes->GetXaxis()->SetBinLabel(1,"All"); |
69 | fHEvtTypes->GetXaxis()->SetBinLabel(2,"MB"); | |
70 | fHEvtTypes->GetXaxis()->SetBinLabel(3,"FO"); | |
71 | fHEvtTypes->GetXaxis()->SetBinLabel(4,"EMC"); | |
31e6d0e8 | 72 | fHEvtTypes->GetXaxis()->SetBinLabel(5,"EJE"); |
73 | fHEvtTypes->GetXaxis()->SetBinLabel(6,"EGA"); | |
74 | fHEvtTypes->GetXaxis()->SetBinLabel(7,"Good"); | |
75 | fHEvtTypes->GetXaxis()->SetBinLabel(8,"HC"); | |
76 | fHEvtTypes->GetXaxis()->SetBinLabel(9,"HT"); | |
77 | fHEvtTypes->GetXaxis()->SetBinLabel(10,"LED"); | |
fb81cdb7 | 78 | fOutput->Add(fHEvtTypes); |
be94a07d | 79 | if (!fDoWriteHistos) { |
80 | fOutput->Remove(fPhysicsSelection); | |
81 | } | |
82 | } | |
83 | ||
84 | //__________________________________________________________________________________________________ | |
85 | void AliEmcalPhysicsSelectionTask::UserExec(const Option_t *opt) | |
86 | { | |
87 | // User exec. | |
88 | ||
89 | AliPhysicsSelectionTask::UserExec(opt); | |
90 | ||
91 | ++fNCalled; | |
92 | ||
93 | UInt_t res = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected(); | |
94 | if (res>0) { | |
95 | ++fNAccepted; | |
96 | fHAcc->Fill(1); | |
97 | } else { | |
98 | fHAcc->Fill(0); | |
99 | } | |
fb81cdb7 | 100 | |
101 | AliEmcalPhysicsSelection *ps=static_cast<AliEmcalPhysicsSelection *>(fPhysicsSelection); | |
102 | fHEvtTypes->Fill(0); | |
103 | if (res&AliVEvent::kAnyINT) | |
104 | fHEvtTypes->Fill(1); | |
105 | if (ps->IsFastOnly()) | |
106 | fHEvtTypes->Fill(2); | |
107 | if ((res&AliVEvent::kEMC1) || (res&AliVEvent::kEMC7)) | |
108 | fHEvtTypes->Fill(3); | |
31e6d0e8 | 109 | if (res&AliVEvent::kEMCEJE) |
fb81cdb7 | 110 | fHEvtTypes->Fill(4); |
31e6d0e8 | 111 | if (res&AliVEvent::kEMCEGA) |
fb81cdb7 | 112 | fHEvtTypes->Fill(5); |
31e6d0e8 | 113 | if (ps->IsGoodEvent()) |
fb81cdb7 | 114 | fHEvtTypes->Fill(6); |
31e6d0e8 | 115 | if (res&AliEmcalPhysicsSelection::kEmcalHC) |
fb81cdb7 | 116 | fHEvtTypes->Fill(7); |
31e6d0e8 | 117 | if (res&AliEmcalPhysicsSelection::kEmcalHT) |
118 | fHEvtTypes->Fill(8); | |
119 | if (ps->IsLedEvent()) | |
120 | fHEvtTypes->Fill(9); | |
be94a07d | 121 | } |
122 | ||
123 | //__________________________________________________________________________________________________ | |
124 | void AliEmcalPhysicsSelectionTask::Terminate(Option_t *) | |
125 | { | |
126 | // The Terminate() function is the last function to be called during | |
127 | // a query. It always runs on the client, it can be used to present | |
128 | // the results graphically or save the results to file. | |
129 | ||
130 | AliInfo(Form("Called %d times, accepted %d events", fNCalled, fNAccepted)); | |
131 | ||
132 | if (!fDoWriteHistos) | |
133 | return; | |
134 | ||
135 | fOutput = dynamic_cast<TList*> (GetOutputData(1)); | |
136 | if (!fOutput) { | |
137 | AliError("fOutput not available"); | |
138 | return; | |
139 | } | |
140 | ||
141 | AliAnalysisDataSlot *oslot = GetOutputSlot(1); | |
142 | if (!oslot) | |
143 | return; | |
144 | ||
145 | AliAnalysisDataContainer *ocont = oslot->GetContainer(); | |
146 | if (!ocont) | |
147 | return; | |
148 | ||
149 | TFile *file = OpenFile(1); | |
150 | if (!file) | |
151 | return; | |
152 | ||
153 | TDirectory::TContext context(file); | |
154 | if (AliAnalysisManager::GetAnalysisManager()->IsProofMode()) { | |
155 | fPhysicsSelection = dynamic_cast<AliPhysicsSelection*> (fOutput->FindObject("AliPhysicsSelection")); | |
156 | } | |
157 | if (fPhysicsSelection) { | |
158 | //fPhysicsSelection->Print(); | |
159 | fPhysicsSelection->SaveHistograms(Form("%sHists",ocont->GetName())); | |
160 | AliInfo(Form("Writing result to %s",file->GetName())); | |
161 | } | |
162 | fOutput->Remove(fPhysicsSelection); | |
163 | } |