Coverity
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveBeamsInfo.cxx
CommitLineData
6e994a7b 1// $Id$
cce980ec 2// Author: Stefano Carrazza 2010, CERN, stefano.carrazza@cern.ch
6e994a7b 3
4/**************************************************************************
5 * Copyright(c) 1998-2009, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
9
10#include "AliEveBeamsInfo.h"
11#include "AliPhysicsSelection.h"
12#include "AliESDEvent.h"
13#include "AliEveEventManager.h"
14#include "AliEveEventSelector.h"
15#include "AliEveMultiView.h"
cce980ec 16#include "AliRawEventHeaderBase.h"
6e994a7b 17
18#include "TEveWindow.h"
19#include "TEveManager.h"
20#include "TEveBrowser.h"
21#include "TEveViewer.h"
22#include "TEveScene.h"
23#include "TGLOverlayButton.h"
cce980ec 24#include "TTimeStamp.h"
6e994a7b 25
26
27//______________________________________________________________________________
cce980ec 28// This class provides:
29//
30// 1) Run and event information from ESD as TGLOverlayButtons.
31//
32// 2) Determine for real and MC data if the event is collision candidate or not.
33//
34// 3) Possibility to filter events per type.
6e994a7b 35//
36
37ClassImp(AliEveBeamsInfo)
38
39//______________________________________________________________________________
40AliEveBeamsInfo::AliEveBeamsInfo(const char* name) :
41 TEveElementList(name),
cce980ec 42 fAlpha(1.5),
43 fIsMC(kFALSE),
6e994a7b 44 fEsd(0),
45 fShowEventsInfo(kTRUE),
46 fPhysicsSelection(0),
cce980ec 47 fEventNumber(0),
6e994a7b 48 fCollisionCandidate(0),
cce980ec 49 fCollisionBoolean(0),
6e994a7b 50 fBeam1(0),
cce980ec 51 fBeam1Boolean(0),
6e994a7b 52 fBeam2(0),
cce980ec 53 fBeam2Boolean(0),
54 fRunNumber(0),
55 fEventType(0),
56 fEventTypeLabel(0),
57 fPeriod(0),
58 fOrbit(0),
59 fBC(0),
60 fTimeStamp(0),
61 fMagnetField(0),
62 fTrigger(0),
63 fTriggerClassesPanel(0),
64 fNumberOfActiveTriggerClasses(0),
65 fTriggerClasses(0),
6e994a7b 66 fAl(0),
67 fHisto2dv(0),
68 fEventSelector(0)
69{
70 // Constructor.
71 gEve->AddToListTree(this,0);
72
cce980ec 73 // Get current ESD event
6e994a7b 74 fEsd = AliEveEventManager::AssertESD();
75 fAl = AliEveMultiView::Instance();
76 fEventSelector = AliEveEventManager::GetMaster()->GetEventSelector();
77
78 // AliPhysicsSelection
79 fPhysicsSelection = new AliPhysicsSelection();
80 fPhysicsSelection->SetAnalyzeMC(kFALSE);
1107e2ce 81 fPhysicsSelection->Initialize(fEsd);
6e994a7b 82
cce980ec 83 // Loading physics selection and triggers buttons
84 CreateEventPanel();
85 CreateRunPanel();
6e994a7b 86
cce980ec 87 // Show beams info
6e994a7b 88 ShowBeamsInfo(fShowEventsInfo, kFALSE);
89
90}
91
92//______________________________________________________________________________
93AliEveBeamsInfo::~AliEveBeamsInfo()
94{
cce980ec 95 // Deleting variables
d9c35666 96 RemoveTriggerClasses();
6e994a7b 97 delete fEsd;
98 delete fPhysicsSelection;
cce980ec 99 delete fEventNumber;
6e994a7b 100 delete fCollisionCandidate;
cce980ec 101 delete fCollisionBoolean;
6e994a7b 102 delete fBeam1;
cce980ec 103 delete fBeam1Boolean;
6e994a7b 104 delete fBeam2;
cce980ec 105 delete fBeam2Boolean;
106 delete fRunNumber;
107 delete fPeriod;
108 delete fOrbit;
109 delete fBC;
110 delete fTimeStamp;
111 delete fMagnetField;
112 delete fTrigger;
113 delete fTriggerClassesPanel;
114 delete fEventType;
115 delete fEventTypeLabel;
6e994a7b 116 delete fAl;
117 delete fHisto2dv;
cce980ec 118}
119
120//______________________________________________________________________________
121void AliEveBeamsInfo::CreateEventPanel()
122{
123 // Create vertical panel
124 Double_t fPosx = 10.0;
125 Double_t fPosy = -10.0;
126 Double_t fXlengh = 220.0;
127 Double_t fStep = 20.0;
6e994a7b 128
cce980ec 129 fEventNumber = new TGLOverlayButton(0 , "", fPosx, fPosy, fXlengh, fStep);
130 fPosy-=fStep;
131
132 fCollisionCandidate = new TGLOverlayButton(0, "Collision:", fPosx, fPosy, fXlengh-fXlengh/2.0, fStep);
133 fCollisionBoolean = new TGLOverlayButton(0, "", fPosx+fXlengh/2.0, fPosy, fXlengh/2.0, fStep);
134 fPosy-=fStep;
135
136 fBeam1 = new TGLOverlayButton(0, "Beam 1:", fPosx, fPosy, fXlengh-fXlengh/2.0, fStep);
137 fBeam1Boolean = new TGLOverlayButton(0, "", fPosx+fXlengh/2.0, fPosy, fXlengh/2.0, fStep);
138 fPosy-=fStep;
139
140 fBeam2 = new TGLOverlayButton(0, "Beam 2:", fPosx, fPosy, fXlengh-fXlengh/2.0, fStep);
141 fBeam2Boolean = new TGLOverlayButton(0, "", fPosx+fXlengh/2.0, fPosy, fXlengh/2.0, fStep);
142
143 fPosy-=2*fStep;
144 fTriggerClassesPanel = new TGLOverlayButton(0, "Active trigger classes:", fPosx, fPosy, fXlengh, fStep);
6e994a7b 145}
146
cce980ec 147//______________________________________________________________________________
148void AliEveBeamsInfo::CreateRunPanel()
149{
150 // Create horizontal panel
151 Double_t fPosy = -10.0;
152 Double_t fPosx = 250.0;
153 Double_t fStep = 20.0;
154 Double_t fXlengh = 120.0;
155 TString fText;
156
157 fText.Form("Run #: %d",fEsd->GetRunNumber());
158 fRunNumber = new TGLOverlayButton(0, fText.Data(), fPosx, fPosy, fXlengh, fStep);
159 fPosx+=fXlengh;
160
161 fEventType = new TGLOverlayButton(0, "", fPosx, fPosy , fXlengh, fStep);
162 fPosx+=fXlengh;
163
164 fEventTypeLabel = new TGLOverlayButton(0, "", fPosx, fPosy, 2*fXlengh, fStep);
165
166 // New line
167 fPosx = 250.0;
168 fPosy = -30.0;
169
170 fPeriod = new TGLOverlayButton(0, "", fPosx, fPosy, fXlengh, fStep);
171 fPosx+=fXlengh;
172
173 fOrbit = new TGLOverlayButton(0, "", fPosx, fPosy, fXlengh, fStep);
174 fPosx+=fXlengh;
175
176 fBC = new TGLOverlayButton(0, "", fPosx, fPosy, fXlengh, fStep);
177 fPosx+=fXlengh;
178
179 fTrigger = new TGLOverlayButton(0, "", fPosx, fPosy, fXlengh, fStep);
180
181 // New line
182 fPosx = 250.0;
183 fPosy = -50.0;
184
185 fTimeStamp = new TGLOverlayButton(0, "", fPosx, fPosy, 2*fXlengh, fStep);
186 fPosx+=2*fXlengh;
187
188 fMagnetField = new TGLOverlayButton(0, "", fPosx, fPosy, 2*fXlengh, fStep);
189 fPosx+=2*fXlengh;
190}
191
192//______________________________________________________________________________
6e994a7b 193void AliEveBeamsInfo::ShowBeamsInfo(Bool_t show, Bool_t updateonly)
194{
cce980ec 195 // Update & setup TGLOverlayButtons
6e994a7b 196 fHisto2dv = (TEveViewer*) gEve->GetViewers()->FindChild("2D Lego Viewer");
197
cce980ec 198 if (!show)
6e994a7b 199 {
cce980ec 200 RemoveOverlayButton(fEventNumber);
201 RemoveOverlayButton(fCollisionCandidate);
202 RemoveOverlayButton(fCollisionBoolean);
203 RemoveOverlayButton(fBeam1);
204 RemoveOverlayButton(fBeam1Boolean);
205 RemoveOverlayButton(fBeam2);
206 RemoveOverlayButton(fBeam2Boolean);
207
208 RemoveOverlayButton(fRunNumber);
209 RemoveOverlayButton(fEventType);
210 RemoveOverlayButton(fEventTypeLabel);
211 RemoveOverlayButton(fPeriod);
212 RemoveOverlayButton(fOrbit);
213 RemoveOverlayButton(fBC);
214 RemoveOverlayButton(fTimeStamp);
215 RemoveOverlayButton(fMagnetField);
216 RemoveOverlayButton(fTrigger);
217
218 RemoveOverlayButton(fTriggerClassesPanel);
219 RemoveTriggerClasses();
220 } else {
6e994a7b 221
cce980ec 222 if (!updateonly)
223 {
224 AddOverlayButton(fEventNumber);
225 AddOverlayButton(fCollisionCandidate);
226 AddOverlayButton(fCollisionBoolean);
227 AddOverlayButton(fBeam1);
228 AddOverlayButton(fBeam1Boolean);
229 AddOverlayButton(fBeam2);
230 AddOverlayButton(fBeam2Boolean);
231
232 AddOverlayButton(fRunNumber);
233 AddOverlayButton(fEventType);
234 AddOverlayButton(fEventTypeLabel);
235 AddOverlayButton(fPeriod);
236 AddOverlayButton(fOrbit);
237 AddOverlayButton(fBC);
238 AddOverlayButton(fTimeStamp);
239 AddOverlayButton(fMagnetField);
240 AddOverlayButton(fTrigger);
241
242 AddOverlayButton(fTriggerClassesPanel);
243 AddTriggerClasses();
244 }
6e994a7b 245
cce980ec 246 TString fText;
247 fText.Form("Event #: %d", fEsd->GetEventNumberInFile());
248 fEventNumber->SetText(fText.Data());
6e994a7b 249
cce980ec 250 fText.Form("Event type: %d",fEsd->GetEventType());
251 fEventType->SetText(fText.Data());
6e994a7b 252
cce980ec 253 if(fEsd->GetEventType() == 0)
254 {
255 fText.Form("UNKNOW EVENT TYPE");
6e994a7b 256 } else {
cce980ec 257 fText.Form("%s", AliRawEventHeaderBase::GetTypeName(fEsd->GetEventType()));
258 }
259 fEventTypeLabel->SetText(fText.Data());
260
261 fText.Form("Period: %x", fEsd->GetPeriodNumber());
262 fPeriod->SetText(fText.Data());
263
264 fText.Form("Orbit: %x", fEsd->GetOrbitNumber());
265 fOrbit->SetText(fText.Data());
266
267 fText.Form("BC: %x", fEsd->GetBunchCrossNumber());
268 fBC->SetText(fText.Data());
269
270 TTimeStamp ts(fEsd->GetTimeStamp());
271 fText.Form("Timestamp: %s",ts.AsString("s"));
272 fTimeStamp->SetText(fText.Data());
273
274 fText.Form("Magnetic field: %.2e kG", fEsd->GetMagneticField());
275 fMagnetField->SetText(fText.Data());
6e994a7b 276
cce980ec 277 if (fEsd->GetTriggerMask() > (ULong64_t) 100 && fIsMC == kFALSE)
278 {
279 fText.Form("Trigger: #");
280 } else {
281 fText.Form("Trigger: %llx", fEsd->GetTriggerMask());
6e994a7b 282 }
cce980ec 283 fTrigger->SetText(fText.Data());
284
285 UpdateTriggerClasses();
6e994a7b 286
287 Bool_t ev = fPhysicsSelection->IsCollisionCandidate(fEsd);
288
289 if (ev == 1)
290 {
cce980ec 291 fCollisionBoolean->SetText("YES");
292 fCollisionBoolean->SetBackColor(0x00ff00);
6e994a7b 293 } else {
cce980ec 294 fCollisionBoolean->SetText("NO");
295 fCollisionBoolean->SetBackColor(0xff0000);
6e994a7b 296 }
297
298 Bool_t b1 = fEsd->IsTriggerClassFired("CINT1A-ABCE-NOPF-ALL");
299 Bool_t b2 = fEsd->IsTriggerClassFired("CINT1C-ABCE-NOPF-ALL");
300 Bool_t b12 = fEsd->IsTriggerClassFired("CINT1B-ABCE-NOPF-ALL");
301
302 if (b1 == 1 || b12 == 1)
303 {
cce980ec 304 fBeam1Boolean->SetText("YES");
305 fBeam1Boolean->SetBackColor(0x00ff00);
6e994a7b 306 } else {
cce980ec 307 fBeam1Boolean->SetText("NO");
308 fBeam1Boolean->SetBackColor(0xff0000);
6e994a7b 309 }
310
311 if (b2 == 1 || b12 == 1)
312 {
cce980ec 313 fBeam2Boolean->SetText("YES");
314 fBeam2Boolean->SetBackColor(0x00ff00);
6e994a7b 315 } else {
cce980ec 316 fBeam2Boolean->SetText("NO");
317 fBeam2Boolean->SetBackColor(0xff0000);
6e994a7b 318 }
319}
320
321gEve->Redraw3D(kTRUE);
322
323}
324
325//______________________________________________________________________________
326void AliEveBeamsInfo::Update()
327{
cce980ec 328 // Update beams information for current event
6e994a7b 329 ShowBeamsInfo(fShowEventsInfo, kTRUE);
330}
331
332//______________________________________________________________________________
cce980ec 333void AliEveBeamsInfo::AddOverlayButton(TGLOverlayButton *button)
6e994a7b 334{
cce980ec 335 // Add buttons to viewers
336 button->SetAlphaValues(fAlpha, fAlpha);
337
338 gEve->GetDefaultGLViewer()->AddOverlayElement(button);
339 fAl->Get3DView()->GetGLViewer()->AddOverlayElement(button);
340 if(fHisto2dv)
341 fHisto2dv->GetGLViewer()->AddOverlayElement(button);
342}
343
344//______________________________________________________________________________
345void AliEveBeamsInfo::RemoveOverlayButton(TGLOverlayButton *button)
346{
347 // Remove buttons to viewers
348 gEve->GetDefaultGLViewer()->RemoveOverlayElement(button);
349 fAl->Get3DView()->GetGLViewer()->RemoveOverlayElement(button);
350 if(fHisto2dv)
351 fHisto2dv->GetGLViewer()->RemoveOverlayElement(button);
352}
6e994a7b 353
cce980ec 354//______________________________________________________________________________
355void AliEveBeamsInfo::ShowEventSelection(Bool_t status)
356{
357 // Activate/deactivate info box
358 fShowEventsInfo = status;
6e994a7b 359 ShowBeamsInfo(fShowEventsInfo);
360}
361
362//______________________________________________________________________________
363void AliEveBeamsInfo::SelectEventSelection(Int_t id)
364{
cce980ec 365 // Show trigger information
6e994a7b 366 if (id == 0)
367 {
368 fEventSelector->SetSelectOnTriggerType(kFALSE);
369 } else {
370 if (id == 1) fEventSelector->SetTriggerType("CINT1A-ABCE-NOPF-ALL");
371 if (id == 2) fEventSelector->SetTriggerType("CINT1C-ABCE-NOPF-ALL");
372 if (id == 3) fEventSelector->SetTriggerType("CINT1B-ABCE-NOPF-ALL");
373 fEventSelector->SetSelectOnTriggerType(kTRUE);
374 }
375}
376
377//______________________________________________________________________________
378void AliEveBeamsInfo::ShowPrevEvent()
379{
cce980ec 380 // Go to the previous event
6e994a7b 381 AliEveEventManager::GetMaster()->PrevEvent();
382}
383
384//______________________________________________________________________________
385void AliEveBeamsInfo::ShowNextEvent()
386{
cce980ec 387 // Go to the next event
6e994a7b 388 AliEveEventManager::GetMaster()->NextEvent();
389}
390
cce980ec 391//______________________________________________________________________________
392void AliEveBeamsInfo::SwitchDataType(Bool_t status)
393{
394 // Activate/deactivate MC / real data type
395 fIsMC = status;
396
397 // Removing defaul physics selection
398 delete fPhysicsSelection;
399 fPhysicsSelection = NULL;
400
401 fPhysicsSelection = new AliPhysicsSelection();
402 fPhysicsSelection->SetAnalyzeMC(fIsMC);
1107e2ce 403 fPhysicsSelection->Initialize(fEsd);
cce980ec 404 Update();
405}
406
407//______________________________________________________________________________
408void AliEveBeamsInfo::AddTriggerClasses()
409{
410 // Add trigger classes
411 if (!fTriggerClasses){
412
413 TString fTriggerNameString = fEsd->GetESDRun()->GetActiveTriggerClasses();
414 TString *fTriggerName = SepareTriggerClasses(fNumberOfActiveTriggerClasses, fTriggerNameString);
415
416 fTriggerClasses = new TGLOverlayButton*[fNumberOfActiveTriggerClasses];
417
418 Double_t fPosy = -130.0;
419 Double_t fStep = 20.0;
420 for (Int_t i = 0; i < fNumberOfActiveTriggerClasses; i++)
421 {
422 fTriggerClasses[i] = new TGLOverlayButton(0, fTriggerName[i].Data(), 10, fPosy, 220.0, 20);
423 fTriggerClasses[i]->SetBackColor(0xce970a);
424 fTriggerClasses[i]->SetAlphaValues(fAlpha, fAlpha);
425 fPosy-=fStep;
426
427 AddOverlayButton(fTriggerClasses[i]);
428 }
429 }
430}
431
432//______________________________________________________________________________
433void AliEveBeamsInfo::RemoveTriggerClasses()
434{
435 // Remove overlay buttons
436 for(Int_t i = 0; i < fNumberOfActiveTriggerClasses; i++)
437 {
438 RemoveOverlayButton(fTriggerClasses[i]);
439 }
440
441 delete[] fTriggerClasses;
442 fTriggerClasses = 0;
443}
444
445//______________________________________________________________________________
446void AliEveBeamsInfo::UpdateTriggerClasses()
447{
448 // Remove trigger information and update it
449 RemoveTriggerClasses();
450 AddTriggerClasses();
451}
452
453//______________________________________________________________________________
454TString *AliEveBeamsInfo::SepareTriggerClasses(Int_t &fNumberOfClasses, TString fTriggerSource)
455{
456 // Get trigger string and separe triggers into TString's
457 Int_t fStringLength = fTriggerSource.Length();
458 fNumberOfClasses = 0;
459
460 for (Int_t i = 1; i < fStringLength; i++)
461 {
462 TString fString = fTriggerSource(i,2);
463 if (fString == " "){
464 fNumberOfClasses++;
465 }
466 }
467 fNumberOfClasses++;
468
469 TString *fTriggerResult = new TString[fNumberOfClasses];
470
471 Int_t fIndex = 1;
472 Int_t fLastIndex = 0;
473 Int_t fFirstIndex = 1;
474 Int_t fClassNumber = 0;
475 for(;;)
476 {
477 if(fIndex >= fStringLength) break;
478 TString fString = fTriggerSource(fIndex,1);
479 fIndex++;
480 fLastIndex++;
481 if (fString == " "){
482 fTriggerResult[fClassNumber] = fTriggerSource(fFirstIndex, fLastIndex-1);
483 fFirstIndex = fIndex+1;
484 fLastIndex = 0;
485 fIndex++;
486 fClassNumber++;
487 }
488 }
489 return fTriggerResult;
490}
491
492//______________________________________________________________________________
493void AliEveBeamsInfo::SetAlpha(Double_t val)
494{
495 // Set the new alpha value for TGLOverlayButton
496 fAlpha = val;
497
498 // First remove all buttons from viewers
499 ShowBeamsInfo(kFALSE);
500
501 // Then replot everything with the next alpha value
502 ShowBeamsInfo(kTRUE);
503}
504
6e994a7b 505/******************************************************************************/