4a45498a729be374f6a05e670b88daba970f5afb
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveBeamsInfo.cxx
1 // $Id$
2 // Author: Stefano Carrazza 2010, CERN, stefano.carrazza@cern.ch
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"
16 #include "AliRawEventHeaderBase.h"
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"
24 #include "TTimeStamp.h"
25
26
27 //______________________________________________________________________________
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.
35 //
36
37 ClassImp(AliEveBeamsInfo)
38
39 //______________________________________________________________________________
40 AliEveBeamsInfo::AliEveBeamsInfo(const char* name) :
41   TEveElementList(name),
42   fAlpha(1.5),
43   fIsMC(kFALSE),
44   fEsd(0),
45   fShowEventsInfo(kTRUE),
46   fPhysicsSelection(0),
47   fEventNumber(0),
48   fCollisionCandidate(0),
49   fCollisionBoolean(0),
50   fBeam1(0),
51   fBeam1Boolean(0),
52   fBeam2(0),
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),
66   fAl(0),
67   fHisto2dv(0),
68   fEventSelector(0)
69 {
70   // Constructor.
71   gEve->AddToListTree(this,0);
72
73   // Get current ESD event
74   fEsd = AliEveEventManager::AssertESD();
75   fAl = AliEveMultiView::Instance();  
76   fEventSelector = AliEveEventManager::GetMaster()->GetEventSelector();
77
78   // AliPhysicsSelection
79   fPhysicsSelection = new AliPhysicsSelection();
80   fPhysicsSelection->SetAnalyzeMC(kFALSE);
81   fPhysicsSelection->Initialize(fEsd);
82
83   // Loading physics selection and triggers buttons
84   CreateEventPanel();
85   CreateRunPanel();
86
87   // Show beams info
88   ShowBeamsInfo(fShowEventsInfo, kFALSE);
89
90 }
91
92 //______________________________________________________________________________
93 AliEveBeamsInfo::~AliEveBeamsInfo()
94 {
95   // Deleting variables
96   delete fEsd;
97   delete fPhysicsSelection;
98   delete fEventNumber;
99   delete fCollisionCandidate;
100   delete fCollisionBoolean;
101   delete fBeam1;
102   delete fBeam1Boolean;
103   delete fBeam2;
104   delete fBeam2Boolean;
105   delete fRunNumber;
106   delete fPeriod;
107   delete fOrbit;
108   delete fBC;
109   delete fTimeStamp;
110   delete fMagnetField;
111   delete fTrigger;
112   delete fTriggerClassesPanel;  
113   delete fEventType;
114   delete fEventTypeLabel;
115   delete fAl;
116   delete fHisto2dv;
117   RemoveTriggerClasses();
118 }
119
120 //______________________________________________________________________________
121 void 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; 
128
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);
145 }
146
147 //______________________________________________________________________________
148 void 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 //______________________________________________________________________________
193 void AliEveBeamsInfo::ShowBeamsInfo(Bool_t show, Bool_t updateonly)
194 {
195   // Update & setup TGLOverlayButtons
196   fHisto2dv = (TEveViewer*) gEve->GetViewers()->FindChild("2D Lego Viewer");
197
198   if (!show)
199   {
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 {
221
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   }
245
246   TString fText;
247   fText.Form("Event #: %d", fEsd->GetEventNumberInFile());
248   fEventNumber->SetText(fText.Data());
249
250   fText.Form("Event type: %d",fEsd->GetEventType());
251   fEventType->SetText(fText.Data());
252
253   if(fEsd->GetEventType() == 0)
254   {
255     fText.Form("UNKNOW EVENT TYPE");
256   } else {
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());
276
277   if (fEsd->GetTriggerMask() > (ULong64_t) 100 && fIsMC == kFALSE)
278   {
279     fText.Form("Trigger: #");
280   } else {    
281     fText.Form("Trigger: %llx", fEsd->GetTriggerMask());
282   }
283   fTrigger->SetText(fText.Data());
284
285   UpdateTriggerClasses();
286
287   Bool_t ev = fPhysicsSelection->IsCollisionCandidate(fEsd);
288
289   if (ev == 1)
290   {
291      fCollisionBoolean->SetText("YES");
292      fCollisionBoolean->SetBackColor(0x00ff00);
293   } else {
294      fCollisionBoolean->SetText("NO");
295      fCollisionBoolean->SetBackColor(0xff0000);
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   {
304      fBeam1Boolean->SetText("YES");
305      fBeam1Boolean->SetBackColor(0x00ff00);
306   } else {
307      fBeam1Boolean->SetText("NO");
308      fBeam1Boolean->SetBackColor(0xff0000);
309   }
310
311   if (b2 == 1 || b12 == 1)
312   {
313      fBeam2Boolean->SetText("YES");
314      fBeam2Boolean->SetBackColor(0x00ff00);
315   } else {
316      fBeam2Boolean->SetText("NO");
317      fBeam2Boolean->SetBackColor(0xff0000);
318   }
319 }
320
321 gEve->Redraw3D(kTRUE);
322
323 }
324
325 //______________________________________________________________________________
326 void AliEveBeamsInfo::Update()
327 {
328   // Update beams information for current event
329   ShowBeamsInfo(fShowEventsInfo, kTRUE);
330 }
331
332 //______________________________________________________________________________
333 void AliEveBeamsInfo::AddOverlayButton(TGLOverlayButton *button)
334 {
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 //______________________________________________________________________________
345 void 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 }
353
354 //______________________________________________________________________________
355 void AliEveBeamsInfo::ShowEventSelection(Bool_t status)
356 {
357   // Activate/deactivate info box
358   fShowEventsInfo = status;
359   ShowBeamsInfo(fShowEventsInfo);
360 }
361
362 //______________________________________________________________________________
363 void AliEveBeamsInfo::SelectEventSelection(Int_t id)
364 {
365   // Show trigger information
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 //______________________________________________________________________________
378 void AliEveBeamsInfo::ShowPrevEvent()
379 {
380   // Go to the previous event
381   AliEveEventManager::GetMaster()->PrevEvent();
382 }
383
384 //______________________________________________________________________________
385 void AliEveBeamsInfo::ShowNextEvent()
386 {
387   // Go to the next event
388   AliEveEventManager::GetMaster()->NextEvent();
389 }
390
391 //______________________________________________________________________________
392 void 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);
403   fPhysicsSelection->Initialize(fEsd);
404   Update();
405 }
406
407 //______________________________________________________________________________
408 void 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 //______________________________________________________________________________
433 void 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 //______________________________________________________________________________
446 void AliEveBeamsInfo::UpdateTriggerClasses()
447 {
448   // Remove trigger information and update it
449   RemoveTriggerClasses();
450   AddTriggerClasses();
451 }
452
453 //______________________________________________________________________________
454 TString *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 //______________________________________________________________________________
493 void 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
505 /******************************************************************************/