1 /**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
21 //___________________________________________________________________
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.
29 // Latest changes by Christian Holm Christensen
32 #include <TApplication.h>
35 #include <TGeoManager.h>
37 #include <TMarker3DBox.h>
42 #include <TVirtualX.h>
43 // #include <TArrayF.h>
44 // #include <TParticle.h>
46 #include "AliFMDDisplay.h" // ALIFMDDISPLAY_H
47 #include "AliFMDHit.h" // ALIFMDHIT_H
48 #include "AliFMDDigit.h" // ALIFMDDIGIT_H
49 #include "AliFMDRecPoint.h" // ALIFMDRECPOINT_H
50 #include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
51 #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
52 #include <AliESDFMD.h> // ALIESDFMD_H
53 // #include <AliLog.h>
54 #include "AliFMDDebug.h" // Better debug macros
56 //____________________________________________________________________
57 ClassImp(AliFMDDisplay)
59 ; // This is here to keep Emacs for indenting the next line
62 //____________________________________________________________________
63 AliFMDDisplay* AliFMDDisplay::fgInstance = 0;
65 //____________________________________________________________________
67 AliFMDDisplay::Instance()
69 // Return static instance
73 //____________________________________________________________________
74 AliFMDDisplay::~AliFMDDisplay()
84 if (fPad) delete fPad;
86 if (fSlider) delete fSlider;
87 if (fCanvas) delete fCanvas;
90 //____________________________________________________________________
91 AliFMDDisplay::AliFMDDisplay(Bool_t onlyFMD, const char* gAliceFile)
92 : AliFMDInput(gAliceFile),
113 // Constructor of an FMD display object.
115 if (fgInstance) delete fgInstance;
117 SetMultiplicityCut();
121 //____________________________________________________________________
123 AliFMDDisplay::MakeCanvas(const char** which)
125 gStyle->SetPalette(1);
128 fCanvas = new TCanvas("display", "Display", w, Int_t(w / (1-y1)));
129 fCanvas->SetFillColor(1);
130 fCanvas->ToggleEventStatus();
132 fPad = new TPad("view", "3DView", 0.0, y1, 1.0, 1.0, 1, 0, 0);
137 if (TESTBIT(fTreeMask, kESD) ||
138 TESTBIT(fTreeMask, kDigits) ||
139 TESTBIT(fTreeMask, kRaw)) {
141 fSlider = new TSlider("multCut", "Multiplicity cut", 0, 0, 1, yb);
142 fSlider->SetMethod("AliFMDDisplay::Instance()->ChangeCut()");
144 fSlider->SetMinimum(TESTBIT(fTreeMask, kESD) ? fMultCut * 10 :
145 fPedestalFactor * 10);
147 const char** p = which;
152 AliInfo(Form("Got %d buttons", n));
156 while ((m = *(p++))) {
158 AliInfo(Form("Adding button %s", m));
159 TButton* b = new TButton(m, Form("AliFMDDisplay::Instance()->%s()", m),
160 x0, yb, x0 + dx, y1);
168 //____________________________________________________________________
170 AliFMDDisplay::ShowOnlyFMD()
172 if (!fGeoManager) return;
173 static bool once = false;
176 AliInfo("Will only show the FMD");
177 TGeoVolume* top = gGeoManager->GetTopVolume();
178 top->InvisibleAll(kTRUE);
179 TGeoIterator next(top);
182 Bool_t hasFMD1 = kFALSE;
183 Bool_t hasFMD2 = kFALSE;
184 Bool_t hasFMD3 = kFALSE;
186 while ((node = static_cast<TGeoNode*>(next()))) {
187 const char* name = node->GetName();
189 if (!(v = node->GetVolume())) continue;
191 if (name[0] == 'F') {
192 if (name[2] == 'M' && (name[3] == 'T' || name[3] == 'B')) {
193 // Virtual Master half-ring volume - top-level
194 Int_t det = node->GetNumber();
196 case 1: hasFMD1 = true; break;
197 case 2: hasFMD2 = true; break;
198 case 3: hasFMD3 = true; break;
203 else if (name[3] == 'V' && (name[2] == 'T' || name[2] == 'B'))
204 toshow.Add(v); // Virtual Half-ring, bare detectors
205 // else if (name[3] == 'H' && (name[2] == 'F' || name[2] == 'B'))
206 // toshow.Add(v); // Virtual Hybrid container
208 v->SetVisibility(kFALSE);
209 v->SetVisDaughters(kFALSE);
210 v->InvisibleAll(kTRUE);
213 while ((v = static_cast<TGeoVolume*>(i()))) {
214 v->SetVisibility(kTRUE);
215 v->SetVisDaughters(kTRUE);
216 v->InvisibleAll(kFALSE);
221 //____________________________________________________________________
223 AliFMDDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
225 // AliInfo(Form("Event %d, at (%d,%d)", px, py));
226 if (px == 0 && py == 0) return;
227 if (!fZoomMode && fPad->GetView()) {
228 fPad->GetView()->ExecuteRotateView(event, px, py);
231 fPad->SetCursor(kCross);
234 fPad->TAttLine::Modify();
235 fX0 = fPad->AbsPixeltoX(px);
236 fY0 = fPad->AbsPixeltoY(py);
237 fXPixel = fOldXPixel = px;
238 fYPixel = fOldYPixel = py;
243 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
248 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
252 fPad->GetCanvas()->FeedbackMode(kFALSE);
253 if (px == fXPixel || py == fYPixel) return;
254 fX1 = fPad->AbsPixeltoX(px);
255 fY1 = fPad->AbsPixeltoY(py);
256 if (fX1 < fX0) std::swap(fX0, fX1);
257 if (fY1 < fY0) std::swap(fY0, fY1);
258 fPad->Range(fX0, fY0, fX1, fY1);
264 //____________________________________________________________________
266 AliFMDDisplay::DistancetoPrimitive(Int_t px, Int_t)
268 // AliInfo(Form("@ (%d,%d)", px, py));
269 fPad->SetCursor(kCross);
270 Float_t xmin = fPad->GetX1();
271 Float_t xmax = fPad->GetX2();
272 Float_t dx = .02 * (xmax - xmin);
273 Float_t x = fPad->AbsPixeltoX(px);
274 if (x < xmin + dx || x > xmax - dx) return 9999;
275 return (fZoomMode ? 0 : 7);
277 //____________________________________________________________________
279 AliFMDDisplay::Init()
281 // Initialize. GEt transforms and such,
282 if (!AliFMDInput::Init()) return kFALSE;
283 AliFMDGeometry* geom = AliFMDGeometry::Instance();
285 geom->InitTransformations();
286 if (TESTBIT(fTreeMask, kDigits) || TESTBIT(fTreeMask, kRaw))
287 AliFMDParameters::Instance()->Init();
289 fMarkers = new TObjArray;
290 fHits = new TObjArray;
291 fMarkers->SetOwner(kTRUE);
292 fHits->SetOwner(kFALSE);
296 //____________________________________________________________________
298 AliFMDDisplay::MakeAux()
300 if ((TESTBIT(fTreeMask, kESD) ||
301 TESTBIT(fTreeMask, kDigits) ||
302 TESTBIT(fTreeMask, kRaw))) {
304 fAux = new TCanvas("aux", "Aux");
306 if (TESTBIT(fTreeMask, kESD))
307 fSpec = new TH1D("spec", "Mult spectra", 500, 0, 10);
309 fSpec = new TH1D("spec", "Adc spectra", 1024, -.5, 1023.5);
310 fSpecCut = static_cast<TH1*>(fSpec->Clone("specCut"));
311 fSpec->SetFillColor(2);
312 fSpec->SetFillStyle(3001);
313 fSpecCut->SetFillColor(4);
314 fSpecCut->SetFillStyle(3001);
323 //____________________________________________________________________
325 AliFMDDisplay::DrawAux()
331 fSpecCut->Draw("same");
337 //____________________________________________________________________
339 AliFMDDisplay::Begin(Int_t event)
341 // Begin of event. Make canvas is not already done
343 const char* m[] = { "Continue", "Zoom", "Pick", "Redisplay", 0 };
348 // AliInfo("Clearing canvas");
351 Warning("End", "No geometry manager");
354 AliInfo("Drawing geometry");
356 fGeoManager->GetTopVolume()->Draw();
357 if (fOnlyFMD) ShowOnlyFMD();
358 AliInfo("Adjusting view");
360 if (fPad->GetView()) {
361 fPad->GetView()->SetView(-200, -40, 80, irep);
362 fPad->GetView()->Zoom();
366 return AliFMDInput::Begin(event);
369 //____________________________________________________________________
371 AliFMDDisplay::AtEnd()
381 //____________________________________________________________________
383 AliFMDDisplay::Idle()
387 gApplication->StartIdleing();
388 gSystem->InnerLoop();
389 gApplication->StopIdleing();
391 AliInfo("After idle loop");
392 if (fMarkers) fMarkers->Delete();
393 if (fHits) fHits->Clear();
394 AliInfo("After clearing caches");
397 //____________________________________________________________________
401 // End of event. Draw everything
404 return AliFMDInput::End();
407 //____________________________________________________________________
409 AliFMDDisplay::LookupColor(Float_t x, Float_t max) const
412 Int_t idx = Int_t(x / max * gStyle->GetNumberOfColors());
413 return gStyle->GetColorPalette(idx);
416 //____________________________________________________________________
418 AliFMDDisplay::ChangeCut()
420 fMultCut = fSlider->GetMinimum() * 10;
421 fPedestalFactor = fSlider->GetMinimum() * 10;
422 AliInfo(Form("Multiplicity cut: %7.5f, Pedestal factor: %7.4f (%6.5f)",
423 fMultCut, fPedestalFactor, fSlider->GetMinimum()));
427 //____________________________________________________________________
429 AliFMDDisplay::Redisplay()
431 if (fMarkers) fMarkers->Delete();
432 if (fHits) fHits->Clear();
433 if (fSpec) fSpec->Reset();
434 if (fSpecCut) fSpecCut->Reset();
439 //____________________________________________________________________
441 AliFMDDisplay::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
442 TObject* o, Float_t s, Float_t max)
444 // Add a marker to the display
450 // o Object to refer to
452 // max Maximum of signal
454 AliFMDGeometry* geom = AliFMDGeometry::Instance();
456 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
458 Float_t zsize = s / max * 10;
459 Float_t r = TMath::Sqrt(x * x + y * y);
460 Float_t theta = TMath::ATan2(r, z);
461 Float_t phi = TMath::ATan2(y, x);
462 Float_t rz = z + (z < 0 ? 1 : -1) * zsize;
463 TMarker3DBox* marker = new TMarker3DBox(x,y,rz,size,size,zsize,theta,phi);
464 if (o) marker->SetRefObject(o);
465 marker->SetLineColor(LookupColor(s, max));
466 fMarkers->Add(marker);
470 //____________________________________________________________________
472 AliFMDDisplay::ProcessHit(AliFMDHit* hit, TParticle* /* p */)
475 if (!hit) { AliError("No hit"); return kFALSE; }
476 // if (!p) { AliError("No track"); return kFALSE; }
478 if (fHits) fHits->Add(hit);
480 Float_t zsize = TMath::Sqrt(hit->Edep() * 20);
481 Float_t z = hit->Z() + (hit->Z() < 0 ? 1 : -1) * zsize;
482 Float_t pt = TMath::Sqrt(hit->Py()*hit->Py()+hit->Px()*hit->Px());
483 Float_t theta = TMath::ATan2(pt, hit->Pz());
484 Float_t phi = TMath::ATan2(hit->Py(), hit->Px());
485 TMarker3DBox* marker = new TMarker3DBox(hit->X(), hit->Y(), z,
486 size, size, zsize, theta, phi);
487 marker->SetLineColor(LookupColor(hit->Edep(), 1));
488 marker->SetRefObject(hit);
489 fMarkers->Add(marker);
493 //____________________________________________________________________
495 AliFMDDisplay::ProcessDigit(AliFMDDigit* digit)
498 if (!digit) { AliError("No digit"); return kFALSE; }
500 AliFMDParameters* parm = AliFMDParameters::Instance();
501 UShort_t det = digit->Detector();
502 Char_t ring = digit->Ring();
503 UShort_t sec = digit->Sector();
504 UShort_t str = digit->Strip();
505 Double_t ped = parm->GetPedestal(det,ring, sec, str);
506 Double_t pedW = parm->GetPedestalWidth(det,ring, sec, str);
507 Double_t threshold = ped + fPedestalFactor * pedW;
508 Float_t counts = digit->Counts();
509 AliFMDDebug(10, ("FMD%d%c[%2d,%3d] ADC: %d > %d (=%4.2f+%4.2f*%4.2f)",
510 digit->Detector(), digit->Ring(), digit->Sector(),
511 digit->Strip(), Int_t(counts), Int_t(threshold),
512 ped, fPedestalFactor, pedW));
513 if (fSpec) fSpec->Fill(counts);
514 if (counts < threshold) return kTRUE;
515 if (fHits) fHits->Add(digit);
516 if (fSpecCut) fSpecCut->Fill(counts);
518 AddMarker(det, ring, sec, str, digit, counts, 1024);
522 //____________________________________________________________________
524 AliFMDDisplay::ProcessRaw(AliFMDDigit* digit)
527 return ProcessDigit(digit);
530 //____________________________________________________________________
532 AliFMDDisplay::ProcessRecPoint(AliFMDRecPoint* recpoint)
534 // Process reconstructed point
535 if (!recpoint) { AliError("No recpoint"); return kFALSE; }
536 if (recpoint->Particles() < fMultCut) return kTRUE;
537 if (fHits) fHits->Add(recpoint);
538 AddMarker(recpoint->Detector(), recpoint->Ring(), recpoint->Sector(),
539 recpoint->Strip(), recpoint, recpoint->Particles(), 20);
543 //____________________________________________________________________
545 AliFMDDisplay::ProcessESD(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
546 Float_t, Float_t mult)
548 Double_t cmult = mult;
549 if (fSpec) fSpec->Fill(cmult);
550 if (cmult < fMultCut || cmult == AliESDFMD::kInvalidMult) return kTRUE;
551 AddMarker(det,rng,sec,str, 0, cmult, 20);
552 if (fSpecCut) fSpecCut->Fill(cmult);
556 //____________________________________________________________________