]>
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), | |
26 | fNTriggers(0), | |
27 | fTriggerList(0), | |
28 | fStats(0) | |
29 | { | |
30 | // | |
31 | // Constructor. Initialization of pointers | |
32 | // | |
33 | ||
34 | // Define input and output slots here | |
35 | DefineInput(0, TChain::Class()); | |
36 | DefineOutput(0, TList::Class()); | |
37 | ||
38 | fNTriggers = 6; | |
39 | ||
40 | static AliPWG0Helper::Trigger triggerList[] = { AliPWG0Helper::kMB1, AliPWG0Helper::kMB2, AliPWG0Helper::kMB3, AliPWG0Helper::kSPDGFO, AliPWG0Helper::kV0A, AliPWG0Helper::kV0C }; | |
41 | fTriggerList = triggerList; | |
42 | ||
43 | fStats = new TH1*[fNTriggers]; | |
44 | ||
45 | AliLog::SetClassDebugLevel("AliTriggerTask", AliLog::kWarning); | |
46 | } | |
47 | ||
48 | AliTriggerTask::~AliTriggerTask() | |
49 | { | |
50 | // | |
51 | // Destructor | |
52 | // | |
53 | ||
54 | // histograms are in the output list and deleted when the output | |
55 | // list is deleted by the TSelector dtor | |
56 | ||
57 | if (fOutput) { | |
58 | delete fOutput; | |
59 | fOutput = 0; | |
60 | } | |
61 | } | |
62 | ||
63 | //________________________________________________________________________ | |
64 | void AliTriggerTask::ConnectInputData(Option_t *) | |
65 | { | |
66 | // Connect ESD | |
67 | // Called once | |
68 | ||
69 | Printf("AliTriggerTask::ConnectInputData called"); | |
70 | ||
71 | AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()); | |
72 | ||
73 | if (!esdH) { | |
74 | Printf("ERROR: Could not get ESDInputHandler"); | |
75 | } else { | |
76 | fESD = esdH->GetEvent(); | |
77 | ||
78 | TString branches("AliESDHeader Vertex AliMultiplicity ALIESDVZERO ALIESDZDC FMD"); | |
79 | ||
80 | // Enable only the needed branches | |
81 | esdH->SetActiveBranches(branches); | |
82 | } | |
83 | } | |
84 | ||
85 | void AliTriggerTask::CreateOutputObjects() | |
86 | { | |
87 | // create result objects and add to output list | |
88 | ||
89 | Printf("AliTriggerTask::CreateOutputObjects"); | |
90 | ||
91 | fOutput = new TList; | |
92 | fOutput->SetOwner(); | |
93 | ||
94 | for (Int_t i=0; i<fNTriggers; i++) | |
95 | { | |
96 | fStats[i] = new TH1F(Form("fStats_%d", i), Form("%s;time;counts", AliPWG0Helper::GetTriggerName(fTriggerList[i])), 100, 0, 0); | |
97 | fOutput->Add(fStats[i]); | |
98 | } | |
99 | } | |
100 | ||
101 | void AliTriggerTask::Exec(Option_t*) | |
102 | { | |
103 | // process the event | |
104 | ||
105 | // post the data already here | |
106 | PostData(0, fOutput); | |
107 | ||
108 | if (!fESD) | |
109 | { | |
110 | AliError("ESD branch not available"); | |
111 | return; | |
112 | } | |
113 | ||
114 | // check event type (should be PHYSICS = 7) | |
115 | AliESDHeader* esdHeader = fESD->GetHeader(); | |
116 | if (!esdHeader) | |
117 | { | |
118 | Printf("ERROR: esdHeader could not be retrieved"); | |
119 | return; | |
120 | } | |
121 | ||
122 | UInt_t eventType = esdHeader->GetEventType(); | |
123 | if (eventType != 7) | |
124 | { | |
125 | Printf("Skipping event because it is of type %d", eventType); | |
126 | return; | |
127 | } | |
128 | ||
129 | //Printf("Trigger classes: %s:", fESD->GetFiredTriggerClasses().Data()); | |
130 | ||
131 | UInt_t timeStamp = fESD->GetTimeStamp() - 1257961181; | |
132 | //Printf("%d", timeStamp); | |
133 | ||
134 | for (Int_t i = 0; i < fNTriggers; i++) | |
135 | { | |
136 | Bool_t triggered = AliPWG0Helper::IsEventTriggered(fESD, (AliPWG0Helper::Trigger) (fTriggerList[i] | AliPWG0Helper::kOfflineFlag)); | |
137 | if (triggered) | |
138 | fStats[i]->Fill(timeStamp); | |
139 | //Printf("%s: %d", AliPWG0Helper::GetTriggerName(fTriggerList[i]), triggered); | |
140 | } | |
141 | } | |
142 | ||
143 | void AliTriggerTask::Terminate(Option_t *) | |
144 | { | |
145 | // The Terminate() function is the last function to be called during | |
146 | // a query. It always runs on the client, it can be used to present | |
147 | // the results graphically or save the results to file. | |
148 | ||
149 | fOutput = dynamic_cast<TList*> (GetOutputData(0)); | |
150 | if (!fOutput) | |
151 | Printf("ERROR: fOutput not available"); | |
152 | ||
153 | if (fOutput) | |
154 | { | |
155 | for (Int_t i=0; i<fNTriggers; i++) | |
156 | fStats[i] = dynamic_cast<TH1*> (fOutput->FindObject(Form("fStats_%d", i))); | |
157 | } | |
158 | ||
159 | TFile* fout = new TFile("trigger.root", "RECREATE"); | |
160 | ||
161 | for (Int_t i=0; i<fNTriggers; i++) | |
162 | if (fStats[i]) | |
163 | fStats[i]->Write(); | |
164 | ||
165 | fout->Write(); | |
166 | fout->Close(); | |
167 | ||
168 | TCanvas* c = new TCanvas("c", "c", 800, 800); | |
169 | c->Divide((Int_t) TMath::Sqrt(fNTriggers) + 1, (Int_t) TMath::Sqrt(fNTriggers)); | |
170 | ||
171 | for (Int_t i=0; i<fNTriggers; i++) | |
172 | if (fStats[i]) | |
173 | { | |
174 | c->cd(i+1); | |
175 | fStats[i]->Draw(); | |
176 | } | |
177 | ||
178 | Printf("Writting result to trigger.root"); | |
179 | } |