Fixed coding conventions
[u/mrichter/AliRoot.git] / FMD / AliFMDDisplay.cxx
CommitLineData
bf000c32 1/**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
bf000c32 15/* $Id$ */
c2fc1258 16/** @file AliFMDDisplay.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:39:09 2006
19 @brief FMD Event display
20*/
bf000c32 21//___________________________________________________________________
22//
23// The classes defined here, are utility classes for reading in data
24// for the FMD. They are put in a seperate library to not polute the
25// normal libraries. The classes are intended to be used as base
26// classes for customized class that do some sort of analysis on the
27// various types of data produced by the FMD.
28//
29// Latest changes by Christian Holm Christensen
30//
9edefa04 31
d1ddc9bd 32#include <TSystem.h>
9edefa04 33#include <TApplication.h>
34#include <TButton.h>
35#include <TCanvas.h>
36#include <TGeoManager.h>
37#include <TH1D.h>
38#include <TMarker3DBox.h>
39#include <TMath.h>
40#include <TSlider.h>
41#include <TStyle.h>
42#include <TView.h>
43#include <TVirtualX.h>
44// #include <TArrayF.h>
45// #include <TParticle.h>
46
bf000c32 47#include "AliFMDDisplay.h" // ALIFMDDISPLAY_H
48#include "AliFMDHit.h" // ALIFMDHIT_H
49#include "AliFMDDigit.h" // ALIFMDDIGIT_H
50#include "AliFMDRecPoint.h" // ALIFMDRECPOINT_H
51#include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
52#include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
15b17c89 53#include <AliESDFMD.h> // ALIESDFMD_H
f95a63c4 54// #include <AliLog.h>
55#include "AliFMDDebug.h" // Better debug macros
bf000c32 56
57//____________________________________________________________________
58ClassImp(AliFMDDisplay)
59#if 0
60 ; // This is here to keep Emacs for indenting the next line
61#endif
62
63//____________________________________________________________________
64AliFMDDisplay* AliFMDDisplay::fgInstance = 0;
65
66//____________________________________________________________________
67AliFMDDisplay*
68AliFMDDisplay::Instance()
69{
02a27b50 70 // Return static instance
bf000c32 71 return fgInstance;
72}
73
74//____________________________________________________________________
a9579262 75AliFMDDisplay::~AliFMDDisplay()
76{
77 if (fMarkers) {
78 fMarkers->Delete();
79 delete fMarkers;
80 }
81 if (fHits) {
82 fHits->Clear();
83 delete fHits;
84 }
85 if (fPad) delete fPad;
86 fButtons.Delete();
87 if (fSlider) delete fSlider;
88 if (fCanvas) delete fCanvas;
89}
90
91//____________________________________________________________________
92AliFMDDisplay::AliFMDDisplay(Bool_t onlyFMD, const char* gAliceFile)
bf000c32 93 : AliFMDInput(gAliceFile),
94 fWait(kFALSE),
b5ee4425 95 fMarkers(0),
96 fHits(0),
bf000c32 97 fCanvas(0),
98 fPad(0),
a9579262 99 fSlider(0),
b5ee4425 100 fZoomMode(kFALSE),
101 fX0(0),
102 fY0(0),
103 fX1(0),
104 fY1(0),
105 fMultCut(0),
106 fPedestalFactor(0),
107 fXPixel(0),
108 fYPixel(0),
109 fOldXPixel(0),
110 fOldYPixel(0),
a9579262 111 fLineDrawn(0),
112 fOnlyFMD(onlyFMD)
bf000c32 113{
114 // Constructor of an FMD display object.
115 AddLoad(kGeometry);
a9579262 116 if (fgInstance) delete fgInstance;
bf000c32 117 fgInstance = this;
15b17c89 118 SetMultiplicityCut();
119 SetPedestalFactor();
bf000c32 120}
121
122//____________________________________________________________________
1e8f773e 123void
a9579262 124AliFMDDisplay::MakeCanvas(const char** which)
125{
126 gStyle->SetPalette(1);
127 Double_t y1 = .10;
128 Int_t w = 700;
129 fCanvas = new TCanvas("display", "Display", w, Int_t(w / (1-y1)));
130 fCanvas->SetFillColor(1);
131 fCanvas->ToggleEventStatus();
132 fCanvas->cd();
133 fPad = new TPad("view", "3DView", 0.0, y1, 1.0, 1.0, 1, 0, 0);
134 fPad->Draw();
135
136 Double_t yb = 0;
137 fCanvas->cd();
138 if (TESTBIT(fTreeMask, kESD) ||
139 TESTBIT(fTreeMask, kDigits) ||
140 TESTBIT(fTreeMask, kRaw)) {
141 yb = .05;
142 fSlider = new TSlider("multCut", "Multiplicity cut", 0, 0, 1, yb);
143 fSlider->SetMethod("AliFMDDisplay::Instance()->ChangeCut()");
a9579262 144 fSlider->Draw();
97b4001e 145 fSlider->SetMinimum(TESTBIT(fTreeMask, kESD) ? fMultCut * 10 :
146 fPedestalFactor * 10);
a9579262 147 }
148 const char** p = which;
149 const char* m;
150 Int_t n = 0;
151 Int_t j = 0;
152 while (*(p++)) n++;
153 AliInfo(Form("Got %d buttons", n));
154 Float_t x0 = 0;
155 Float_t dx = 1. / n;
156 p = which;
157 while ((m = *(p++))) {
158 fCanvas->cd();
159 AliInfo(Form("Adding button %s", m));
160 TButton* b = new TButton(m, Form("AliFMDDisplay::Instance()->%s()", m),
161 x0, yb, x0 + dx, y1);
162 b->Draw();
163 fButtons.Add(b);
164 x0 += dx;
165 j++;
166 }
167}
168
169//____________________________________________________________________
170void
171AliFMDDisplay::ShowOnlyFMD()
172{
173 if (!fGeoManager) return;
174 static bool once = false;
175 if (once) return;
176 once = true;
177 AliInfo("Will only show the FMD");
178 TGeoVolume* top = gGeoManager->GetTopVolume();
179 top->InvisibleAll(kTRUE);
180 TGeoIterator next(top);
181 TGeoNode* node;
182 TGeoVolume* v = 0;
183 Bool_t hasFMD1 = kFALSE;
184 Bool_t hasFMD2 = kFALSE;
185 Bool_t hasFMD3 = kFALSE;
186 TObjArray toshow;
187 while ((node = static_cast<TGeoNode*>(next()))) {
188 const char* name = node->GetName();
189 if (!name) continue;
190 if (!(v = node->GetVolume())) continue;
191
192 if (name[0] == 'F') {
193 if (name[2] == 'M' && (name[3] == 'T' || name[3] == 'B')) {
194 // Virtual Master half-ring volume - top-level
195 Int_t det = node->GetNumber();
196 switch (det) {
197 case 1: hasFMD1 = true; break;
198 case 2: hasFMD2 = true; break;
199 case 3: hasFMD3 = true; break;
200 default: continue;
201 }
202 toshow.Add(v);
203 }
204 else if (name[3] == 'V' && (name[2] == 'T' || name[2] == 'B'))
205 toshow.Add(v); // Virtual Half-ring, bare detectors
206 // else if (name[3] == 'H' && (name[2] == 'F' || name[2] == 'B'))
207 // toshow.Add(v); // Virtual Hybrid container
208 }
209 v->SetVisibility(kFALSE);
210 v->SetVisDaughters(kFALSE);
211 v->InvisibleAll(kTRUE);
212 }
213 TIter i(&toshow);
214 while ((v = static_cast<TGeoVolume*>(i()))) {
215 v->SetVisibility(kTRUE);
216 v->SetVisDaughters(kTRUE);
217 v->InvisibleAll(kFALSE);
218 }
219}
220
221
222//____________________________________________________________________
223void
bf000c32 224AliFMDDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
225{
1e8f773e 226 // AliInfo(Form("Event %d, at (%d,%d)", px, py));
bf000c32 227 if (px == 0 && py == 0) return;
228 if (!fZoomMode && fPad->GetView()) {
229 fPad->GetView()->ExecuteRotateView(event, px, py);
230 return;
231 }
232 fPad->SetCursor(kCross);
233 switch (event) {
234 case kButton1Down:
235 fPad->TAttLine::Modify();
236 fX0 = fPad->AbsPixeltoX(px);
237 fY0 = fPad->AbsPixeltoY(py);
238 fXPixel = fOldXPixel = px;
239 fYPixel = fOldYPixel = py;
240 fLineDrawn = kFALSE;
241 return;
242 case kButton1Motion:
243 if (fLineDrawn)
244 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
245 TVirtualX::kHollow);
246 fOldXPixel = px;
247 fOldYPixel = py;
248 fLineDrawn = kTRUE;
249 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
250 TVirtualX::kHollow);
251 return;
252 case kButton1Up:
253 fPad->GetCanvas()->FeedbackMode(kFALSE);
254 if (px == fXPixel || py == fYPixel) return;
255 fX1 = fPad->AbsPixeltoX(px);
256 fY1 = fPad->AbsPixeltoY(py);
257 if (fX1 < fX0) std::swap(fX0, fX1);
258 if (fY1 < fY0) std::swap(fY0, fY1);
259 fPad->Range(fX0, fY0, fX1, fY1);
260 fPad->Modified();
261 return;
262 }
263}
264
265//____________________________________________________________________
1e8f773e 266Int_t
267AliFMDDisplay::DistancetoPrimitive(Int_t px, Int_t)
bf000c32 268{
1e8f773e 269 // AliInfo(Form("@ (%d,%d)", px, py));
bf000c32 270 fPad->SetCursor(kCross);
271 Float_t xmin = fPad->GetX1();
272 Float_t xmax = fPad->GetX2();
273 Float_t dx = .02 * (xmax - xmin);
274 Float_t x = fPad->AbsPixeltoX(px);
275 if (x < xmin + dx || x > xmax - dx) return 9999;
276 return (fZoomMode ? 0 : 7);
277}
278//____________________________________________________________________
279Bool_t
280AliFMDDisplay::Init()
281{
02a27b50 282 // Initialize. GEt transforms and such,
bf000c32 283 if (!AliFMDInput::Init()) return kFALSE;
284 AliFMDGeometry* geom = AliFMDGeometry::Instance();
285 geom->Init();
286 geom->InitTransformations();
97b4001e 287 if (TESTBIT(fTreeMask, kDigits) || TESTBIT(fTreeMask, kRaw))
288 AliFMDParameters::Instance()->Init();
289
a9579262 290 fMarkers = new TObjArray;
291 fHits = new TObjArray;
292 fMarkers->SetOwner(kTRUE);
293 fHits->SetOwner(kFALSE);
bf000c32 294 return kTRUE;
295}
a9579262 296
297//____________________________________________________________________
298void
299AliFMDDisplay::MakeAux()
300{
301 if ((TESTBIT(fTreeMask, kESD) ||
302 TESTBIT(fTreeMask, kDigits) ||
303 TESTBIT(fTreeMask, kRaw))) {
304 if (!fAux) {
305 fAux = new TCanvas("aux", "Aux");
306 fAux->SetLogy();
307 if (TESTBIT(fTreeMask, kESD))
97b4001e 308 fSpec = new TH1D("spec", "Mult spectra", 500, 0, 10);
a9579262 309 else
310 fSpec = new TH1D("spec", "Adc spectra", 1024, -.5, 1023.5);
311 fSpecCut = static_cast<TH1*>(fSpec->Clone("specCut"));
312 fSpec->SetFillColor(2);
313 fSpec->SetFillStyle(3001);
314 fSpecCut->SetFillColor(4);
315 fSpecCut->SetFillStyle(3001);
316 }
317 else {
318 fSpec->Reset();
319 fSpecCut->Reset();
320 }
321 }
322}
323
324//____________________________________________________________________
325void
326AliFMDDisplay::DrawAux()
327{
328 if (!fAux) return;
329 fAux->cd();
330 fAux->Clear();
331 fSpec->Draw();
332 fSpecCut->Draw("same");
333 fAux->Modified();
334 fAux->Update();
335 fAux->cd();
336}
337
bf000c32 338//____________________________________________________________________
339Bool_t
340AliFMDDisplay::Begin(Int_t event)
341{
02a27b50 342 // Begin of event. Make canvas is not already done
bf000c32 343 if (!fCanvas) {
a9579262 344 const char* m[] = { "Continue", "Zoom", "Pick", "Redisplay", 0 };
345 MakeCanvas(m);
bf000c32 346 }
97b4001e 347 MakeAux();
348
a9579262 349 // AliInfo("Clearing canvas");
bf000c32 350 // fCanvas->Clear();
351 if (!fGeoManager) {
352 Warning("End", "No geometry manager");
353 return kFALSE;
354 }
355 AliInfo("Drawing geometry");
356 fPad->cd();
357 fGeoManager->GetTopVolume()->Draw();
a9579262 358 if (fOnlyFMD) ShowOnlyFMD();
bf000c32 359 AliInfo("Adjusting view");
360 Int_t irep;
361 if (fPad->GetView()) {
362 fPad->GetView()->SetView(-200, -40, 80, irep);
363 fPad->GetView()->Zoom();
364 fPad->Modified();
365 fPad->cd();
366 }
367 return AliFMDInput::Begin(event);
368}
369
370//____________________________________________________________________
a9579262 371void
372AliFMDDisplay::AtEnd()
bf000c32 373{
374 fPad->cd();
375 fMarkers->Draw();
1e8f773e 376 fPad->cd();
bf000c32 377 AppendPad();
bf000c32 378 fPad->cd();
a9579262 379 DrawAux();
380}
381
382//____________________________________________________________________
383void
384AliFMDDisplay::Idle()
385{
bf000c32 386 fWait = kTRUE;
387 while (fWait) {
388 gApplication->StartIdleing();
389 gSystem->InnerLoop();
390 gApplication->StopIdleing();
391 }
392 AliInfo("After idle loop");
a9579262 393 if (fMarkers) fMarkers->Delete();
394 if (fHits) fHits->Clear();
bf000c32 395 AliInfo("After clearing caches");
a9579262 396}
397
398//____________________________________________________________________
399Bool_t
400AliFMDDisplay::End()
401{
402 // End of event. Draw everything
403 AtEnd();
404 Idle();
bf000c32 405 return AliFMDInput::End();
406}
407
408//____________________________________________________________________
409Int_t
410AliFMDDisplay::LookupColor(Float_t x, Float_t max) const
411{
02a27b50 412 // Look-up color
bf000c32 413 Int_t idx = Int_t(x / max * gStyle->GetNumberOfColors());
414 return gStyle->GetColorPalette(idx);
415}
416
15b17c89 417//____________________________________________________________________
418void
a9579262 419AliFMDDisplay::ChangeCut()
420{
97b4001e 421 fMultCut = fSlider->GetMinimum() * 10;
a9579262 422 fPedestalFactor = fSlider->GetMinimum() * 10;
423 AliInfo(Form("Multiplicity cut: %7.5f, Pedestal factor: %7.4f (%6.5f)",
424 fMultCut, fPedestalFactor, fSlider->GetMinimum()));
425 Redisplay();
426}
427
428//____________________________________________________________________
429void
430AliFMDDisplay::Redisplay()
431{
432 if (fMarkers) fMarkers->Delete();
433 if (fHits) fHits->Clear();
434 if (fSpec) fSpec->Reset();
435 if (fSpecCut) fSpecCut->Reset();
436 Event();
437 AtEnd();
438}
439
440//____________________________________________________________________
441void
15b17c89 442AliFMDDisplay::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
443 TObject* o, Float_t s, Float_t max)
444{
445 // Add a marker to the display
446 //
447 // det Detector
448 // rng Ring
449 // sec Sector
450 // str Strip
451 // o Object to refer to
452 // s Signal
453 // max Maximum of signal
454 //
455 AliFMDGeometry* geom = AliFMDGeometry::Instance();
456 Double_t x, y, z;
457 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
458 Float_t size = .1;
459 Float_t zsize = s / max * 10;
460 Float_t r = TMath::Sqrt(x * x + y * y);
461 Float_t theta = TMath::ATan2(r, z);
462 Float_t phi = TMath::ATan2(y, x);
463 Float_t rz = z + (z < 0 ? 1 : -1) * zsize;
464 TMarker3DBox* marker = new TMarker3DBox(x,y,rz,size,size,zsize,theta,phi);
465 if (o) marker->SetRefObject(o);
466 marker->SetLineColor(LookupColor(s, max));
467 fMarkers->Add(marker);
468}
469
bf000c32 470
471//____________________________________________________________________
472Bool_t
a9579262 473AliFMDDisplay::ProcessHit(AliFMDHit* hit, TParticle* /* p */)
bf000c32 474{
02a27b50 475 // Process a hit
bf000c32 476 if (!hit) { AliError("No hit"); return kFALSE; }
a9579262 477 // if (!p) { AliError("No track"); return kFALSE; }
bf000c32 478
a9579262 479 if (fHits) fHits->Add(hit);
bf000c32 480 Float_t size = .1;
a9579262 481 Float_t zsize = TMath::Sqrt(hit->Edep() * 20);
15b17c89 482 Float_t z = hit->Z() + (hit->Z() < 0 ? 1 : -1) * zsize;
bf000c32 483 Float_t pt = TMath::Sqrt(hit->Py()*hit->Py()+hit->Px()*hit->Px());
484 Float_t theta = TMath::ATan2(pt, hit->Pz());
485 Float_t phi = TMath::ATan2(hit->Py(), hit->Px());
15b17c89 486 TMarker3DBox* marker = new TMarker3DBox(hit->X(), hit->Y(), z,
487 size, size, zsize, theta, phi);
bf000c32 488 marker->SetLineColor(LookupColor(hit->Edep(), 1));
489 marker->SetRefObject(hit);
490 fMarkers->Add(marker);
491 return kTRUE;
492}
493
494//____________________________________________________________________
495Bool_t
496AliFMDDisplay::ProcessDigit(AliFMDDigit* digit)
497{
02a27b50 498 // Process a digit
bf000c32 499 if (!digit) { AliError("No digit"); return kFALSE; }
500
bf000c32 501 AliFMDParameters* parm = AliFMDParameters::Instance();
15b17c89 502 UShort_t det = digit->Detector();
503 Char_t ring = digit->Ring();
504 UShort_t sec = digit->Sector();
505 UShort_t str = digit->Strip();
506 Double_t ped = parm->GetPedestal(det,ring, sec, str);
507 Double_t pedW = parm->GetPedestalWidth(det,ring, sec, str);
97b4001e 508 Double_t threshold = ped + fPedestalFactor * pedW;
509 Float_t counts = digit->Counts();
f95a63c4 510 AliFMDDebug(10, ("FMD%d%c[%2d,%3d] ADC: %d > %d (=%4.2f+%4.2f*%4.2f)",
97b4001e 511 digit->Detector(), digit->Ring(), digit->Sector(),
512 digit->Strip(), Int_t(counts), Int_t(threshold),
513 ped, fPedestalFactor, pedW));
a9579262 514 if (fSpec) fSpec->Fill(counts);
15b17c89 515 if (counts < threshold) return kTRUE;
a9579262 516 if (fHits) fHits->Add(digit);
517 if (fSpecCut) fSpecCut->Fill(counts);
15b17c89 518
519 AddMarker(det, ring, sec, str, digit, counts, 1024);
bf000c32 520 return kTRUE;
521}
522
523//____________________________________________________________________
524Bool_t
d760ea03 525AliFMDDisplay::ProcessRaw(AliFMDDigit* digit)
526{
02a27b50 527 // PRocess raw data
d760ea03 528 return ProcessDigit(digit);
529}
530
531//____________________________________________________________________
532Bool_t
bf000c32 533AliFMDDisplay::ProcessRecPoint(AliFMDRecPoint* recpoint)
534{
02a27b50 535 // Process reconstructed point
bf000c32 536 if (!recpoint) { AliError("No recpoint"); return kFALSE; }
15b17c89 537 if (recpoint->Particles() < fMultCut) return kTRUE;
a9579262 538 if (fHits) fHits->Add(recpoint);
15b17c89 539 AddMarker(recpoint->Detector(), recpoint->Ring(), recpoint->Sector(),
540 recpoint->Strip(), recpoint, recpoint->Particles(), 20);
541 return kTRUE;
542}
bf000c32 543
15b17c89 544//____________________________________________________________________
545Bool_t
a9579262 546AliFMDDisplay::ProcessESD(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
97b4001e 547 Float_t, Float_t mult)
15b17c89 548{
97b4001e 549 Double_t cmult = mult;
a9579262 550 if (fSpec) fSpec->Fill(cmult);
551 if (cmult < fMultCut || cmult == AliESDFMD::kInvalidMult) return kTRUE;
552 AddMarker(det,rng,sec,str, 0, cmult, 20);
553 if (fSpecCut) fSpecCut->Fill(cmult);
bf000c32 554 return kTRUE;
555}
556
557//____________________________________________________________________
558//
559// EOF
560//