]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/TRD/AliAnalysisTaskTRDtriggerCheck.cxx
- first version of PWGTRD lib
[u/mrichter/AliRoot.git] / PWG / TRD / AliAnalysisTaskTRDtriggerCheck.cxx
CommitLineData
9e7843aa 1// ROOT
2#include "TFile.h"
3#include "TList.h"
4#include "TObjArray.h"
5#include "TH1.h"
6#include "TH2.h"
7#include "TH3.h"
8#include "TRandom.h"
9
10// analysis framework
11#include "AliAnalysisManager.h"
12#include "AliInputEventHandler.h"
13#include "AliVEvent.h"
14#include "AliVTrdTrack.h"
15
16// MC stuff
17#include "AliMCEvent.h"
18#include "AliGenPythiaEventHeader.h"
19#include "AliTrackReference.h"
20
21// ESD stuff
22#include "AliESDEvent.h"
23#include "AliESDInputHandler.h"
24#include "AliESDtrack.h"
25#include "AliESDTrdTrack.h"
26#include "AliESDTrdTracklet.h"
27#include "AliESDTrdTrigger.h"
28
29// AOD stuff
30#include "AliAODEvent.h"
31#include "AliAODJet.h"
32#include "AliAODTrack.h"
33
34#include "AliTRDTriggerAnalysis.h"
35
36#include "AliAnalysisTaskTRDtriggerCheck.h"
37
38AliAnalysisTaskTRDtriggerCheck::AliAnalysisTaskTRDtriggerCheck(const char *name) :
39 AliAnalysisTaskSE(name),
40 fOutputList(),
41 fHist(),
42 fShortTaskId("trd_trg_check")
43{
44 // default ctor
45
46 DefineOutput(1, TList::Class());
47}
48
49AliAnalysisTaskTRDtriggerCheck::~AliAnalysisTaskTRDtriggerCheck()
50{
51 // dtor
52
53}
54
55void AliAnalysisTaskTRDtriggerCheck::UserCreateOutputObjects()
56{
57 // create user output objects
58
59 // setup list
60 OpenFile(1);
61 fOutputList = new TList();
62 fOutputList->SetOwner();
63
64 TH2 *h = AddHistogram(ID(kHistTrgStat),
65 "trigger contributions",
66 kTrgLast, -.5, kTrgLast - .5,
67 kLastComb - 1, .5, kLastComb - .5);
68 h->GetXaxis()->SetBinLabel(kTrgHCO + 1, "HCO");
69 h->GetXaxis()->SetBinLabel(kTrgHJT + 1, "HJT");
70 h->GetXaxis()->SetBinLabel(kTrgHSE + 1, "HSE");
71 h->GetXaxis()->SetBinLabel(kTrgHQU + 1, "HQU");
72 h->GetXaxis()->SetBinLabel(kTrgHEE + 1, "HEE");
73 h->GetYaxis()->SetBinLabel(ID(kNothing));
74 h->GetYaxis()->SetBinLabel(ID(kTriggered));
75 h->GetYaxis()->SetBinLabel(ID(kFired));
76 h->GetYaxis()->SetBinLabel(ID(kCondition));
77 h->GetYaxis()->SetBinLabel(ID(kTriggeredFired));
78 h->GetYaxis()->SetBinLabel(ID(kTriggeredCondition));
79 h->GetYaxis()->SetBinLabel(ID(kFiredCondition));
80 h->GetYaxis()->SetBinLabel(ID(kTriggeredFiredCondition));
81
82 h = AddHistogram(ID(kHistTrgStatSec),
83 "SM header flag per sector;;global stack",
84 kTrgLast + 1, -.5, kTrgLast + .5,
85 18, -.5, 17.5);
86 h->GetXaxis()->SetBinLabel(kTrgHCO + 1, "HCO");
87 h->GetXaxis()->SetBinLabel(kTrgHJT + 1, "HJT");
88 h->GetXaxis()->SetBinLabel(kTrgHSE + 1, "HSE");
89 h->GetXaxis()->SetBinLabel(kTrgHQU + 1, "HQU");
90 h->GetXaxis()->SetBinLabel(kTrgHEE + 1, "HEE");
91 h->GetXaxis()->SetBinLabel(kTrgLast + 1, "TO");
92
93 h = AddHistogram(ID(kHistTrgStatStackCond),
94 "condition per stack;;global stack",
95 kTrgLast, -.5, kTrgLast - .5,
96 90, -.5, 89.5);
97 h->GetXaxis()->SetBinLabel(kTrgHCO + 1, "HCO");
98 h->GetXaxis()->SetBinLabel(kTrgHJT + 1, "HJT");
99 h->GetXaxis()->SetBinLabel(kTrgHSE + 1, "HSE");
100 h->GetXaxis()->SetBinLabel(kTrgHQU + 1, "HQU");
101 h->GetXaxis()->SetBinLabel(kTrgHEE + 1, "HEE");
102
103 h = AddHistogram(ID(kHistTrgStatStackCondNotFired),
104 "(condition + !fired) per stack;;global stack",
105 kTrgLast, -.5, kTrgLast - .5,
106 90, -.5, 89.5);
107 h->GetXaxis()->SetBinLabel(kTrgHCO + 1, "HCO");
108 h->GetXaxis()->SetBinLabel(kTrgHJT + 1, "HJT");
109 h->GetXaxis()->SetBinLabel(kTrgHSE + 1, "HSE");
110 h->GetXaxis()->SetBinLabel(kTrgHQU + 1, "HQU");
111 h->GetXaxis()->SetBinLabel(kTrgHEE + 1, "HEE");
112
113 PostData(1, fOutputList);
114}
115
116Bool_t AliAnalysisTaskTRDtriggerCheck::Notify()
117{
118 // actions to be taken upon notification about input file change
119
120 return AliAnalysisTaskSE::Notify();
121}
122
123void AliAnalysisTaskTRDtriggerCheck::UserExec(Option_t * /* option */)
124{
125 // actual work
126
127 // setup pointers to input data (null if unavailable)
128 // mcEvent: MC input
129 // esdEvent: ESD input
130 // outEvent: AOD output
131 // aodEvent: AOD input if available, otherwise AOD output
132 // AliMCEvent *mcEvent = this->MCEvent();
133 AliESDEvent *esdEvent = dynamic_cast<AliESDEvent*>(this->InputEvent()); // could also be AOD input
134 // AliAODEvent* outEvent = this->AODEvent();
135 // AliAODEvent *aodEvent = outEvent;
136 // if (dynamic_cast<AliAODEvent*>(this->InputEvent()))
137 // aodEvent = (AliAODEvent*) (this->InputEvent());
138
139 if ((fDebug > 0) && esdEvent)
140 printf("event: %s-%06i\n", CurrentFileName(), esdEvent->GetEventNumberInFile());
141
142 printf("event: %s-%06i\n", CurrentFileName(), esdEvent->GetEventNumberInFile());
143 if (!InputEvent()->GetFiredTriggerClasses().Contains("WU")) {
144 printf("no TRD, returning\n");
145 return;
146 }
147
148 // reproduce hardware decision
149 AliTRDTriggerAnalysis trgAnalysis;
150 trgAnalysis.SetVerbosity(1);
151 trgAnalysis.SetRequireInTime(kTRUE);
152 trgAnalysis.SetRequireMatchElectron(kFALSE);
153 trgAnalysis.CalcTriggers(InputEvent());
154
155 // now what we rather want
156 AliTRDTriggerAnalysis trgAnalysisGoal;
157 trgAnalysisGoal.SetRequireInTime(kFALSE);
158 trgAnalysisGoal.SetRequireMatchElectron(kTRUE);
159 trgAnalysisGoal.CalcTriggers(InputEvent());
160
161 Int_t nTracks = InputEvent()->GetNumberOfTrdTracks();
162 for (Int_t iTrack = 0; iTrack < nTracks; ++iTrack) {
163 AliVTrdTrack *trk = InputEvent()->GetTrdTrack(iTrack);
164 printf("trk %2i: %02i_%i - pt = %6.2f, PID = %3i, %10s, %10s\n",
165 iTrack, trk->GetSector(), trk->GetStack(),
166 trk->Pt(), trk->GetPID(),
167 trk->GetTrackInTime() ? "in-time" : "not in-time",
168 trk->GetTrackMatch() ? "matched" : "not matched");
169 }
170
171 const Int_t trgBits[] = { 0, 4, 5, 6, 1, 7 };
172 for (Int_t iSector = 0; iSector < 18; ++iSector)
173 for (Int_t iTrg = 0; iTrg <= kTrgLast; ++iTrg)
174 if (trgAnalysis.CheckTrgFlags(trgBits[iTrg], iSector))
175 FillH2(kHistTrgStatSec, iTrg, iSector);
176
177 for (Int_t iTrg = 0; iTrg < kTrgLast; ++iTrg) {
178 Bool_t trgd = trgAnalysis.HasTriggered((AliTRDTriggerAnalysis::TRDTrigger_t) iTrg);
179 Bool_t fired = trgAnalysis.HasFired((AliTRDTriggerAnalysis::TRDTrigger_t) iTrg);
180 Bool_t cond = trgAnalysis.CheckCondition((AliTRDTriggerAnalysis::TRDTrigger_t) iTrg);
181 printf("trigger %i: %10s %10s %10s\n", iTrg,
182 trgd ? "triggered" : "",
183 fired ? "fired" : "",
184 cond ? "condition" : "");
185
186 if (trgd && fired && cond)
187 FillH2(kHistTrgStat, iTrg, kTriggeredFiredCondition);
188 else if (trgd && fired && !cond)
189 FillH2(kHistTrgStat, iTrg, kTriggeredFired);
190 else if (trgd && !fired && cond)
191 FillH2(kHistTrgStat, iTrg, kTriggeredCondition);
192 else if (trgd && !fired && !cond)
193 FillH2(kHistTrgStat, iTrg, kTriggered);
194 else if (!trgd && fired && cond)
195 FillH2(kHistTrgStat, iTrg, kFiredCondition);
196 else if (!trgd && fired && !cond)
197 FillH2(kHistTrgStat, iTrg, kFired);
198 else if (!trgd && !fired && cond)
199 FillH2(kHistTrgStat, iTrg, kCondition);
200 else if (!trgd && !fired && !cond)
201 FillH2(kHistTrgStat, iTrg, kNothing);
202
203 for (Int_t iStack = 0; iStack < 90; ++iStack) {
204 if (trgAnalysis.CheckCondition((AliTRDTriggerAnalysis::TRDTrigger_t) iTrg, iStack)) {
205 FillH2(kHistTrgStatStackCond, iTrg, iStack);
206 if (!fired)
207 FillH2(kHistTrgStatStackCondNotFired, iTrg, iStack);
208 }
209 }
210 }
211
212 PostData(1, fOutputList);
213}
214
215void AliAnalysisTaskTRDtriggerCheck::Terminate(const Option_t * /* option */)
216{
217 // actions at task termination
218}
219
220
221
222// ----- histogram management -----
223TH1* AliAnalysisTaskTRDtriggerCheck::AddHistogram(Hist_t hist, const char *hid, TString title,
224 Int_t xbins, Float_t xmin, Float_t xmax,
225 Int_t binType)
226{
227 TString hName;
228 hName.Form("%s_%s", fShortTaskId, hid);
229 hName.ToLower();
230 TH1 *h = 0x0;
231 if (binType == 0)
232 h = new TH1I(hName.Data(), title,
233 xbins, xmin, xmax);
234 else
235 h = new TH1F(hName.Data(), title,
236 xbins, xmin, xmax);
237 GetHistogram(hist) = h;
238 fOutputList->Add(h);
239 return h;
240}
241
242TH2* AliAnalysisTaskTRDtriggerCheck::AddHistogram(Hist_t hist, const char *hid, TString title,
243 Int_t xbins, Float_t xmin, Float_t xmax,
244 Int_t ybins, Float_t ymin, Float_t ymax,
245 Int_t binType)
246{
247 TString hName;
248 hName.Form("%s_%s", fShortTaskId, hid);
249 hName.ToLower();
250 TH1 *h = 0x0;
251 if (binType == 0)
252 h = GetHistogram(hist) = new TH2I(hName.Data(), title,
253 xbins, xmin, xmax,
254 ybins, ymin, ymax);
255 else
256 h = GetHistogram(hist) = new TH2F(hName.Data(), title,
257 xbins, xmin, xmax,
258 ybins, ymin, ymax);
259 fOutputList->Add(h);
260 return (TH2*) h;
261}
262
263TH3* AliAnalysisTaskTRDtriggerCheck::AddHistogram(Hist_t hist, const char *hid, TString title,
264 Int_t xbins, Float_t xmin, Float_t xmax,
265 Int_t ybins, Float_t ymin, Float_t ymax,
266 Int_t zbins, Float_t zmin, Float_t zmax,
267 Int_t binType)
268{
269 TString hName;
270 hName.Form("%s_%s", fShortTaskId, hid);
271 hName.ToLower();
272 TH1 *h = 0x0;
273 if (binType == 0)
274 h = GetHistogram(hist) = new TH3I(hName.Data(), title,
275 xbins, xmin, xmax,
276 ybins, ymin, ymax,
277 zbins, zmin, zmax);
278 else
279 h = GetHistogram(hist) = new TH3F(hName.Data(), title,
280 xbins, xmin, xmax,
281 ybins, ymin, ymax,
282 zbins, zmin, zmax);
283 fOutputList->Add(h);
284 return (TH3*) h;
285}