61899827 |
1 | /* $Id: AliPhysicsSelection.cxx 35782 2009-10-22 11:54:31Z jgrosseo $ */ |
2 | |
3 | /************************************************************************** |
4 | * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. * |
5 | * * |
6 | * Author: The ALICE Off-line Project. * |
7 | * Contributors are mentioned in the code where appropriate. * |
8 | * * |
9 | * Permission to use, copy, modify and distribute this software and its * |
10 | * documentation strictly for non-commercial purposes is hereby granted * |
11 | * without fee, provided that the above copyright notice appears in all * |
12 | * copies and that both the copyright notice and this permission notice * |
13 | * appear in the supporting documentation. The authors make no claims * |
14 | * about the suitability of this software for any purpose. It is * |
15 | * provided "as is" without express or implied warranty. * |
16 | **************************************************************************/ |
17 | |
18 | //------------------------------------------------------------------------- |
19 | // Implementation of Class AliPhysicsSelection |
20 | // This class provides function to check if events have been triggered based on the data in the ESD |
21 | // The trigger bits, trigger class inputs and only the data (offline trigger) can be used |
22 | // Origin: Jan Fiete Grosse-Oetringhaus, CERN |
23 | //------------------------------------------------------------------------- |
24 | |
25 | #include <Riostream.h> |
26 | #include <TH1F.h> |
27 | #include <TH2F.h> |
28 | #include <TList.h> |
29 | #include <TIterator.h> |
30 | #include <TDirectory.h> |
31 | |
32 | #include <AliPhysicsSelection.h> |
33 | |
34 | #include <AliTriggerAnalysis.h> |
35 | #include <AliLog.h> |
36 | |
37 | #include <AliESDEvent.h> |
38 | |
39 | ClassImp(AliPhysicsSelection) |
40 | |
41 | AliPhysicsSelection::AliPhysicsSelection() : |
42 | fTriggerAnalysis(0), |
43 | fHistStatistics(0), |
44 | fHistBunchCrossing(0) |
45 | { |
46 | // constructor |
47 | |
48 | AliLog::SetClassDebugLevel("AliPhysicsSelection", AliLog::kWarning); |
49 | } |
50 | |
51 | AliPhysicsSelection::~AliPhysicsSelection() |
52 | { |
53 | // destructor |
54 | |
55 | if (fTriggerAnalysis) |
56 | { |
57 | delete fTriggerAnalysis; |
58 | fTriggerAnalysis = 0; |
59 | } |
60 | |
61 | if (fHistStatistics) |
62 | { |
63 | delete fHistStatistics; |
64 | fHistStatistics = 0; |
65 | } |
66 | |
67 | if (fHistBunchCrossing) |
68 | { |
69 | delete fHistBunchCrossing; |
70 | fHistBunchCrossing = 0; |
71 | } |
72 | } |
73 | |
74 | Bool_t AliPhysicsSelection::IsCollisionCandidate(const AliESDEvent* aEsd) |
75 | { |
76 | // checks if the given event is a collision candidate |
77 | |
78 | if (!fTriggerAnalysis) |
79 | AliFatal("Not initialized!"); |
80 | |
81 | const AliESDHeader* esdHeader = aEsd->GetHeader(); |
82 | if (!esdHeader) |
83 | { |
84 | AliError("ESD Header could not be retrieved"); |
85 | return kFALSE; |
86 | } |
87 | |
88 | // check event type (should be PHYSICS = 7) |
89 | if (esdHeader->GetEventType() != 7) |
90 | return kFALSE; |
91 | |
92 | fHistStatistics->Fill(1); |
93 | |
94 | fTriggerAnalysis->FillTriggerClasses(aEsd); |
95 | |
96 | for (Int_t i=0; i < fRequTrigClasses.GetEntries(); i++) |
97 | { |
98 | const char* triggerClass = ((TObjString*) fRequTrigClasses.At(i))->String(); |
99 | if (!aEsd->IsTriggerClassFired(triggerClass)) |
100 | { |
101 | AliDebug(AliLog::kDebug, Form("Rejecting event because trigger class %s is not present", triggerClass)); |
102 | return kFALSE; |
103 | } |
104 | } |
105 | |
106 | for (Int_t i=0; i < fRejTrigClasses.GetEntries(); i++) |
107 | { |
108 | const char* triggerClass = ((TObjString*) fRejTrigClasses.At(i))->String(); |
109 | if (aEsd->IsTriggerClassFired(triggerClass)) |
110 | { |
111 | AliDebug(AliLog::kDebug, Form("Rejecting event because trigger class %s is present", triggerClass)); |
112 | return kFALSE; |
113 | } |
114 | } |
115 | |
116 | fTriggerAnalysis->FillHistograms(aEsd); |
117 | |
118 | fHistStatistics->Fill(2); |
119 | |
120 | Bool_t fastOR = fTriggerAnalysis->IsOfflineTriggerFired(aEsd, AliTriggerAnalysis::kSPDGFO); |
121 | Bool_t v0BB = fTriggerAnalysis->IsOfflineTriggerFired(aEsd, AliTriggerAnalysis::kV0A) || fTriggerAnalysis->IsOfflineTriggerFired(aEsd, AliTriggerAnalysis::kV0C); |
122 | Bool_t v0BG = fTriggerAnalysis->IsOfflineTriggerFired(aEsd, AliTriggerAnalysis::kV0ABG) || fTriggerAnalysis->IsOfflineTriggerFired(aEsd, AliTriggerAnalysis::kV0CBG); |
123 | |
124 | if (fastOR) |
125 | fHistStatistics->Fill(3); |
126 | if (v0BB) |
127 | fHistStatistics->Fill(4); |
128 | if (v0BG) |
129 | fHistStatistics->Fill(5); |
130 | |
131 | if (fastOR || v0BB) |
132 | fHistStatistics->Fill(6); |
133 | |
134 | if (!fastOR && !v0BB) |
135 | { |
136 | AliDebug(AliLog::kDebug, "Rejecting event because neither FO nor V0 has triggered"); |
137 | return kFALSE; |
138 | } |
139 | |
140 | if (v0BG) |
141 | { |
142 | AliDebug(AliLog::kDebug, "Rejecting event because of V0 BG flag"); |
143 | return kFALSE; |
144 | } |
145 | |
146 | fHistStatistics->Fill(7); |
147 | |
148 | // TODO additional background identification |
149 | |
150 | fHistStatistics->Fill(9); |
151 | |
152 | fHistBunchCrossing->Fill(aEsd->GetBunchCrossNumber()); |
153 | |
154 | AliDebug(AliLog::kDebug, "Accepted event"); |
155 | |
156 | return kTRUE; |
157 | } |
158 | |
159 | Bool_t AliPhysicsSelection::Initialize(UInt_t runNumber) |
160 | { |
161 | // initializes the object for the given run |
162 | // TODO having the run number here and parameters hardcoded is clearly temporary, a way needs to be found to have a CDB-like configuration also for analysis |
163 | |
164 | AliInfo(Form("Initializing for run %d", runNumber)); |
165 | |
166 | fRequTrigClasses.Clear(); |
167 | fRejTrigClasses.Clear(); |
168 | |
169 | fRequTrigClasses.Add(new TObjString("CINT1B-ABCE-NOPF-ALL")); |
170 | |
171 | if (!fTriggerAnalysis) |
172 | { |
173 | fTriggerAnalysis = new AliTriggerAnalysis; |
174 | fTriggerAnalysis->EnableHistograms(); |
175 | } |
176 | |
177 | fTriggerAnalysis->SetSPDGFOThreshhold(1); |
178 | fTriggerAnalysis->SetV0TimeOffset(0); |
179 | |
180 | if (runNumber == 104321) |
181 | fTriggerAnalysis->SetV0TimeOffset(7.5); |
182 | |
183 | if (fHistStatistics) |
184 | { |
185 | fHistStatistics->Reset(); |
186 | } |
187 | else |
188 | { |
189 | fHistStatistics = new TH1F("fHistStatistics", "fHistStatistics;;event count", 10, 0.5, 10.5); |
190 | |
191 | Int_t n = 1; |
192 | fHistStatistics->GetXaxis()->SetBinLabel(n++, "Total"); |
193 | fHistStatistics->GetXaxis()->SetBinLabel(n++, "Correct trigger class(es)"); |
194 | fHistStatistics->GetXaxis()->SetBinLabel(n++, "FO"); |
195 | fHistStatistics->GetXaxis()->SetBinLabel(n++, "V0 BB"); |
196 | fHistStatistics->GetXaxis()->SetBinLabel(n++, "V0 BG"); |
197 | fHistStatistics->GetXaxis()->SetBinLabel(n++, "FO | V0 BB"); |
198 | fHistStatistics->GetXaxis()->SetBinLabel(n++, "(FO | V0 BB) & !V0 BG"); |
199 | fHistStatistics->GetXaxis()->SetBinLabel(n++, "Background identification"); |
200 | fHistStatistics->GetXaxis()->SetBinLabel(n++, "Accepted"); |
201 | } |
202 | |
203 | if (fHistBunchCrossing) |
204 | { |
205 | fHistBunchCrossing->Reset(); |
206 | } |
207 | else |
208 | fHistBunchCrossing = new TH1F("fHistBunchCrossing", "fHistBunchCrossing;bunch crossing number;accepted events", 4000, -0.5, 3999.5); |
209 | |
210 | return kTRUE; |
211 | } |
212 | |
213 | void AliPhysicsSelection::Print(Option_t* /* option */) const |
214 | { |
215 | // print the configuration |
216 | |
217 | AliInfo("Initialized with:"); |
218 | |
219 | TString str("Required trigger classes: "); |
220 | for (Int_t i=0; i < fRequTrigClasses.GetEntries(); i++) |
221 | str += ((TObjString*) fRequTrigClasses.At(i))->String() + " "; |
222 | AliInfo(str); |
223 | |
224 | str = "Rejected trigger classes: "; |
225 | for (Int_t i=0; i < fRejTrigClasses.GetEntries(); i++) |
226 | str += ((TObjString*) fRejTrigClasses.At(i))->String() + " "; |
227 | AliInfo(str); |
228 | |
229 | AliInfo(Form("Requiring %d FO chips (offline) or V0A or V0C and no V0 BG flag", fTriggerAnalysis->GetSPDGFOThreshhold())); |
230 | |
231 | if (fTriggerAnalysis->GetV0TimeOffset() > 0) |
232 | AliInfo(Form("V0 time offset active: %.2f ns", fTriggerAnalysis->GetV0TimeOffset())); |
233 | |
234 | fTriggerAnalysis->PrintTriggerClasses(); |
235 | } |
236 | |
237 | Long64_t AliPhysicsSelection::Merge(TCollection* list) |
238 | { |
239 | // Merge a list of AliMultiplicityCorrection objects with this (needed for |
240 | // PROOF). |
241 | // Returns the number of merged objects (including this). |
242 | |
243 | if (!list) |
244 | return 0; |
245 | |
246 | if (list->IsEmpty()) |
247 | return 1; |
248 | |
249 | TIterator* iter = list->MakeIterator(); |
250 | TObject* obj; |
251 | |
252 | // collections of all histograms |
253 | const Int_t nHists = 9; |
254 | TList collections[nHists]; |
255 | |
256 | Int_t count = 0; |
257 | while ((obj = iter->Next())) { |
258 | |
259 | AliPhysicsSelection* entry = dynamic_cast<AliPhysicsSelection*> (obj); |
260 | if (entry == 0) |
261 | continue; |
262 | |
263 | Int_t n = 0; |
264 | collections[n++].Add(entry->fTriggerAnalysis); |
265 | collections[n++].Add(entry->fHistStatistics); |
266 | collections[n++].Add(entry->fHistBunchCrossing); |
267 | |
268 | count++; |
269 | } |
270 | |
271 | Int_t n = 0; |
272 | fTriggerAnalysis->Merge(&collections[n++]); |
273 | fHistStatistics->Merge(&collections[n++]); |
274 | fHistBunchCrossing->Merge(&collections[n++]); |
275 | |
276 | delete iter; |
277 | |
278 | return count+1; |
279 | } |
280 | |
281 | void AliPhysicsSelection::SaveHistograms(const char* folder) const |
282 | { |
283 | // write histograms to current directory |
284 | |
285 | if (!fHistStatistics) |
286 | return; |
287 | |
288 | if (folder) |
289 | { |
290 | gDirectory->mkdir(folder); |
291 | gDirectory->cd(folder); |
292 | } |
293 | |
294 | fHistStatistics->Write(); |
295 | fHistBunchCrossing->Write(); |
296 | |
297 | gDirectory->mkdir("trigger_histograms"); |
298 | gDirectory->cd("trigger_histograms"); |
299 | |
300 | fTriggerAnalysis->SaveHistograms(); |
301 | |
302 | gDirectory->cd(".."); |
303 | |
304 | if (folder) |
305 | gDirectory->cd(".."); |
306 | } |