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