]>
Commit | Line | Data |
---|---|---|
ff8c4f30 | 1 | /* $Id: AliTriggerTask.cxx 35782 2009-10-22 11:54:31Z jgrosseo $ */ |
2 | ||
3 | #include "AliTriggerTask.h" | |
4 | ||
5 | #include <TCanvas.h> | |
6 | #include <TFile.h> | |
7 | #include <TChain.h> | |
8 | #include <TH1F.h> | |
9 | #include <TH2F.h> | |
10 | #include <TH3F.h> | |
11 | ||
12 | #include <AliLog.h> | |
13 | #include <AliESDEvent.h> | |
14 | #include <AliHeader.h> | |
15 | #include <AliAnalysisManager.h> | |
16 | #include <AliESDInputHandler.h> | |
17 | #include <AliESDHeader.h> | |
18 | ||
19 | ClassImp(AliTriggerTask) | |
20 | ||
21 | AliTriggerTask::AliTriggerTask(const char* opt) : | |
22 | AliAnalysisTask("AliTriggerTask", ""), | |
23 | fESD(0), | |
24 | fOutput(0), | |
25 | fOption(opt), | |
c8d3e441 | 26 | fStartTime(0), |
27 | fEndTime(0), | |
ff8c4f30 | 28 | fNTriggers(0), |
29 | fTriggerList(0), | |
30 | fStats(0) | |
31 | { | |
32 | // | |
33 | // Constructor. Initialization of pointers | |
34 | // | |
35 | ||
36 | // Define input and output slots here | |
37 | DefineInput(0, TChain::Class()); | |
38 | DefineOutput(0, TList::Class()); | |
39 | ||
7a11141c | 40 | fNTriggers = 13; |
ff8c4f30 | 41 | |
7a11141c | 42 | static AliPWG0Helper::Trigger triggerList[] = { AliPWG0Helper::kAcceptAll, AliPWG0Helper::kFPANY, AliPWG0Helper::kMB1, AliPWG0Helper::kMB2, AliPWG0Helper::kMB3, AliPWG0Helper::kSPDGFO, AliPWG0Helper::kV0A, AliPWG0Helper::kV0C, AliPWG0Helper::kZDC, AliPWG0Helper::kZDCA, AliPWG0Helper::kZDCC, AliPWG0Helper::kFMDA, AliPWG0Helper::kFMDC }; |
ff8c4f30 | 43 | fTriggerList = triggerList; |
44 | ||
45 | fStats = new TH1*[fNTriggers]; | |
46 | ||
47 | AliLog::SetClassDebugLevel("AliTriggerTask", AliLog::kWarning); | |
48 | } | |
49 | ||
50 | AliTriggerTask::~AliTriggerTask() | |
51 | { | |
52 | // | |
53 | // Destructor | |
54 | // | |
55 | ||
56 | // histograms are in the output list and deleted when the output | |
57 | // list is deleted by the TSelector dtor | |
58 | ||
59 | if (fOutput) { | |
60 | delete fOutput; | |
61 | fOutput = 0; | |
62 | } | |
63 | } | |
64 | ||
65 | //________________________________________________________________________ | |
66 | void AliTriggerTask::ConnectInputData(Option_t *) | |
67 | { | |
68 | // Connect ESD | |
69 | // Called once | |
70 | ||
71 | Printf("AliTriggerTask::ConnectInputData called"); | |
72 | ||
73 | AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()); | |
74 | ||
75 | if (!esdH) { | |
76 | Printf("ERROR: Could not get ESDInputHandler"); | |
77 | } else { | |
78 | fESD = esdH->GetEvent(); | |
79 | ||
80 | TString branches("AliESDHeader Vertex AliMultiplicity ALIESDVZERO ALIESDZDC FMD"); | |
81 | ||
82 | // Enable only the needed branches | |
83 | esdH->SetActiveBranches(branches); | |
84 | } | |
85 | } | |
86 | ||
87 | void AliTriggerTask::CreateOutputObjects() | |
88 | { | |
89 | // create result objects and add to output list | |
90 | ||
91 | Printf("AliTriggerTask::CreateOutputObjects"); | |
92 | ||
93 | fOutput = new TList; | |
94 | fOutput->SetOwner(); | |
c8d3e441 | 95 | |
96 | if (fStartTime == fEndTime) | |
97 | AliWarning("Start and endtime not set. Automatic binning will be used. This does not work in parallel systems"); | |
ff8c4f30 | 98 | |
c8d3e441 | 99 | Int_t nBins = 1000; |
100 | if (fEndTime - fStartTime > 0) | |
101 | nBins = fEndTime - fStartTime; | |
ff8c4f30 | 102 | for (Int_t i=0; i<fNTriggers; i++) |
103 | { | |
c8d3e441 | 104 | fStats[i] = new TH1F(Form("fStats_%d", i), Form("%s;time;counts", AliPWG0Helper::GetTriggerName(fTriggerList[i])), nBins, 0, fEndTime - fStartTime); |
ff8c4f30 | 105 | fOutput->Add(fStats[i]); |
106 | } | |
107 | } | |
108 | ||
109 | void AliTriggerTask::Exec(Option_t*) | |
110 | { | |
111 | // process the event | |
112 | ||
113 | // post the data already here | |
114 | PostData(0, fOutput); | |
115 | ||
116 | if (!fESD) | |
117 | { | |
118 | AliError("ESD branch not available"); | |
119 | return; | |
120 | } | |
121 | ||
122 | // check event type (should be PHYSICS = 7) | |
123 | AliESDHeader* esdHeader = fESD->GetHeader(); | |
124 | if (!esdHeader) | |
125 | { | |
126 | Printf("ERROR: esdHeader could not be retrieved"); | |
127 | return; | |
128 | } | |
129 | ||
130 | UInt_t eventType = esdHeader->GetEventType(); | |
131 | if (eventType != 7) | |
132 | { | |
133 | Printf("Skipping event because it is of type %d", eventType); | |
134 | return; | |
135 | } | |
136 | ||
137 | //Printf("Trigger classes: %s:", fESD->GetFiredTriggerClasses().Data()); | |
138 | ||
c8d3e441 | 139 | UInt_t timeStamp = fESD->GetTimeStamp() - fStartTime; |
ff8c4f30 | 140 | //Printf("%d", timeStamp); |
141 | ||
142 | for (Int_t i = 0; i < fNTriggers; i++) | |
143 | { | |
144 | Bool_t triggered = AliPWG0Helper::IsEventTriggered(fESD, (AliPWG0Helper::Trigger) (fTriggerList[i] | AliPWG0Helper::kOfflineFlag)); | |
145 | if (triggered) | |
146 | fStats[i]->Fill(timeStamp); | |
147 | //Printf("%s: %d", AliPWG0Helper::GetTriggerName(fTriggerList[i]), triggered); | |
148 | } | |
149 | } | |
150 | ||
151 | void AliTriggerTask::Terminate(Option_t *) | |
152 | { | |
153 | // The Terminate() function is the last function to be called during | |
154 | // a query. It always runs on the client, it can be used to present | |
155 | // the results graphically or save the results to file. | |
156 | ||
157 | fOutput = dynamic_cast<TList*> (GetOutputData(0)); | |
158 | if (!fOutput) | |
159 | Printf("ERROR: fOutput not available"); | |
160 | ||
161 | if (fOutput) | |
162 | { | |
163 | for (Int_t i=0; i<fNTriggers; i++) | |
164 | fStats[i] = dynamic_cast<TH1*> (fOutput->FindObject(Form("fStats_%d", i))); | |
165 | } | |
166 | ||
167 | TFile* fout = new TFile("trigger.root", "RECREATE"); | |
168 | ||
169 | for (Int_t i=0; i<fNTriggers; i++) | |
170 | if (fStats[i]) | |
171 | fStats[i]->Write(); | |
172 | ||
173 | fout->Write(); | |
174 | fout->Close(); | |
175 | ||
c8d3e441 | 176 | Int_t nX = (Int_t) TMath::Sqrt(fNTriggers); |
177 | Int_t nY = nX; | |
178 | ||
179 | while (nX * nY < fNTriggers) | |
180 | { | |
181 | if (nX == nY) | |
182 | nX++; | |
183 | else | |
184 | nY++; | |
185 | } | |
186 | ||
ff8c4f30 | 187 | TCanvas* c = new TCanvas("c", "c", 800, 800); |
c8d3e441 | 188 | c->Divide(nX, nY); |
189 | ||
190 | Printf("+++++++++ TRIGGER STATS:"); | |
7a11141c | 191 | |
192 | Int_t base = 1; | |
193 | if (fStats[0]) | |
194 | base = (Int_t) fStats[0]->Integral(); | |
195 | ||
196 | Int_t length = fEndTime - fStartTime; | |
ff8c4f30 | 197 | |
198 | for (Int_t i=0; i<fNTriggers; i++) | |
199 | if (fStats[i]) | |
200 | { | |
201 | c->cd(i+1); | |
202 | fStats[i]->Draw(); | |
039db886 | 203 | Printf("%s: %d triggers | %f %% of all triggered | Rate: %f Hz", AliPWG0Helper::GetTriggerName(fTriggerList[i]), (UInt_t) fStats[i]->Integral(), 100.0 * fStats[i]->Integral() / base, (length > 0) ? (fStats[i]->Integral() / length) : -1); |
ff8c4f30 | 204 | } |
205 | ||
206 | Printf("Writting result to trigger.root"); | |
207 | } |