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
33 #include <TApplication.h>
36 #include <TGeoManager.h>
38 #include <TMarker3DBox.h>
43 #include <TVirtualX.h>
44 // #include <TArrayF.h>
45 // #include <TParticle.h>
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
53 #include <AliESDFMD.h> // ALIESDFMD_H
54 // #include <AliLog.h>
55 #include "AliFMDDebug.h" // Better debug macros
57 //____________________________________________________________________
58 ClassImp(AliFMDDisplay)
60 ; // This is here to keep Emacs for indenting the next line
63 //____________________________________________________________________
64 AliFMDDisplay* AliFMDDisplay::fgInstance = 0;
66 //____________________________________________________________________
68 AliFMDDisplay::Instance()
70 // Return static instance
74 //____________________________________________________________________
75 AliFMDDisplay::~AliFMDDisplay()
85 if (fPad) delete fPad;
87 if (fSlider) delete fSlider;
88 if (fCanvas) delete fCanvas;
91 //____________________________________________________________________
92 AliFMDDisplay::AliFMDDisplay(Bool_t onlyFMD, const char* gAliceFile)
93 : AliFMDInput(gAliceFile),
114 // Constructor of an FMD display object.
116 if (fgInstance) delete fgInstance;
118 SetMultiplicityCut();
122 //____________________________________________________________________
124 AliFMDDisplay::MakeCanvas(const char** which)
126 gStyle->SetPalette(1);
129 fCanvas = new TCanvas("display", "Display", w, Int_t(w / (1-y1)));
130 fCanvas->SetFillColor(1);
131 fCanvas->ToggleEventStatus();
133 fPad = new TPad("view", "3DView", 0.0, y1, 1.0, 1.0, 1, 0, 0);
138 if (TESTBIT(fTreeMask, kESD) ||
139 TESTBIT(fTreeMask, kDigits) ||
140 TESTBIT(fTreeMask, kRaw)) {
142 fSlider = new TSlider("multCut", "Multiplicity cut", 0, 0, 1, yb);
143 fSlider->SetMethod("AliFMDDisplay::Instance()->ChangeCut()");
145 fSlider->SetMinimum(TESTBIT(fTreeMask, kESD) ? fMultCut * 10 :
146 fPedestalFactor * 10);
148 const char** p = which;
153 AliInfo(Form("Got %d buttons", n));
157 while ((m = *(p++))) {
159 AliInfo(Form("Adding button %s", m));
160 TButton* b = new TButton(m, Form("AliFMDDisplay::Instance()->%s()", m),
161 x0, yb, x0 + dx, y1);
169 //____________________________________________________________________
171 AliFMDDisplay::ShowOnlyFMD()
173 if (!fGeoManager) return;
174 static bool once = false;
177 AliInfo("Will only show the FMD");
178 TGeoVolume* top = gGeoManager->GetTopVolume();
179 top->InvisibleAll(kTRUE);
180 TGeoIterator next(top);
183 Bool_t hasFMD1 = kFALSE;
184 Bool_t hasFMD2 = kFALSE;
185 Bool_t hasFMD3 = kFALSE;
187 while ((node = static_cast<TGeoNode*>(next()))) {
188 const char* name = node->GetName();
190 if (!(v = node->GetVolume())) continue;
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();
197 case 1: hasFMD1 = true; break;
198 case 2: hasFMD2 = true; break;
199 case 3: hasFMD3 = true; break;
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
209 v->SetVisibility(kFALSE);
210 v->SetVisDaughters(kFALSE);
211 v->InvisibleAll(kTRUE);
214 while ((v = static_cast<TGeoVolume*>(i()))) {
215 v->SetVisibility(kTRUE);
216 v->SetVisDaughters(kTRUE);
217 v->InvisibleAll(kFALSE);
222 //____________________________________________________________________
224 AliFMDDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
226 // AliInfo(Form("Event %d, at (%d,%d)", px, py));
227 if (px == 0 && py == 0) return;
228 if (!fZoomMode && fPad->GetView()) {
229 fPad->GetView()->ExecuteRotateView(event, px, py);
232 fPad->SetCursor(kCross);
235 fPad->TAttLine::Modify();
236 fX0 = fPad->AbsPixeltoX(px);
237 fY0 = fPad->AbsPixeltoY(py);
238 fXPixel = fOldXPixel = px;
239 fYPixel = fOldYPixel = py;
244 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
249 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
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);
265 //____________________________________________________________________
267 AliFMDDisplay::DistancetoPrimitive(Int_t px, Int_t)
269 // AliInfo(Form("@ (%d,%d)", px, py));
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);
278 //____________________________________________________________________
280 AliFMDDisplay::Init()
282 // Initialize. GEt transforms and such,
283 if (!AliFMDInput::Init()) return kFALSE;
284 AliFMDGeometry* geom = AliFMDGeometry::Instance();
286 geom->InitTransformations();
287 if (TESTBIT(fTreeMask, kDigits) || TESTBIT(fTreeMask, kRaw))
288 AliFMDParameters::Instance()->Init();
290 fMarkers = new TObjArray;
291 fHits = new TObjArray;
292 fMarkers->SetOwner(kTRUE);
293 fHits->SetOwner(kFALSE);
297 //____________________________________________________________________
299 AliFMDDisplay::MakeAux()
301 if ((TESTBIT(fTreeMask, kESD) ||
302 TESTBIT(fTreeMask, kDigits) ||
303 TESTBIT(fTreeMask, kRaw))) {
305 fAux = new TCanvas("aux", "Aux");
307 if (TESTBIT(fTreeMask, kESD))
308 fSpec = new TH1D("spec", "Mult spectra", 500, 0, 10);
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);
324 //____________________________________________________________________
326 AliFMDDisplay::DrawAux()
332 fSpecCut->Draw("same");
338 //____________________________________________________________________
340 AliFMDDisplay::Begin(Int_t event)
342 // Begin of event. Make canvas is not already done
344 const char* m[] = { "Continue", "Zoom", "Pick", "Redisplay", 0 };
349 // AliInfo("Clearing canvas");
352 Warning("End", "No geometry manager");
355 AliInfo("Drawing geometry");
357 fGeoManager->GetTopVolume()->Draw();
358 if (fOnlyFMD) ShowOnlyFMD();
359 AliInfo("Adjusting view");
361 if (fPad->GetView()) {
362 fPad->GetView()->SetView(-200, -40, 80, irep);
363 fPad->GetView()->Zoom();
367 return AliFMDInput::Begin(event);
370 //____________________________________________________________________
372 AliFMDDisplay::AtEnd()
382 //____________________________________________________________________
384 AliFMDDisplay::Idle()
388 gApplication->StartIdleing();
389 gSystem->InnerLoop();
390 gApplication->StopIdleing();
392 AliInfo("After idle loop");
393 if (fMarkers) fMarkers->Delete();
394 if (fHits) fHits->Clear();
395 AliInfo("After clearing caches");
398 //____________________________________________________________________
402 // End of event. Draw everything
405 return AliFMDInput::End();
408 //____________________________________________________________________
410 AliFMDDisplay::LookupColor(Float_t x, Float_t max) const
413 Int_t idx = Int_t(x / max * gStyle->GetNumberOfColors());
414 return gStyle->GetColorPalette(idx);
417 //____________________________________________________________________
419 AliFMDDisplay::ChangeCut()
421 fMultCut = fSlider->GetMinimum() * 10;
422 fPedestalFactor = fSlider->GetMinimum() * 10;
423 AliInfo(Form("Multiplicity cut: %7.5f, Pedestal factor: %7.4f (%6.5f)",
424 fMultCut, fPedestalFactor, fSlider->GetMinimum()));
428 //____________________________________________________________________
430 AliFMDDisplay::Redisplay()
432 if (fMarkers) fMarkers->Delete();
433 if (fHits) fHits->Clear();
434 if (fSpec) fSpec->Reset();
435 if (fSpecCut) fSpecCut->Reset();
440 //____________________________________________________________________
442 AliFMDDisplay::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
443 TObject* o, Float_t s, Float_t max)
445 // Add a marker to the display
451 // o Object to refer to
453 // max Maximum of signal
455 AliFMDGeometry* geom = AliFMDGeometry::Instance();
457 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
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);
471 //____________________________________________________________________
473 AliFMDDisplay::ProcessHit(AliFMDHit* hit, TParticle* /* p */)
476 if (!hit) { AliError("No hit"); return kFALSE; }
477 // if (!p) { AliError("No track"); return kFALSE; }
479 if (fHits) fHits->Add(hit);
481 Float_t zsize = TMath::Sqrt(hit->Edep() * 20);
482 Float_t z = hit->Z() + (hit->Z() < 0 ? 1 : -1) * zsize;
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());
486 TMarker3DBox* marker = new TMarker3DBox(hit->X(), hit->Y(), z,
487 size, size, zsize, theta, phi);
488 marker->SetLineColor(LookupColor(hit->Edep(), 1));
489 marker->SetRefObject(hit);
490 fMarkers->Add(marker);
494 //____________________________________________________________________
496 AliFMDDisplay::ProcessDigit(AliFMDDigit* digit)
499 if (!digit) { AliError("No digit"); return kFALSE; }
501 AliFMDParameters* parm = AliFMDParameters::Instance();
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);
508 Double_t threshold = ped + fPedestalFactor * pedW;
509 Float_t counts = digit->Counts();
510 AliFMDDebug(10, ("FMD%d%c[%2d,%3d] ADC: %d > %d (=%4.2f+%4.2f*%4.2f)",
511 digit->Detector(), digit->Ring(), digit->Sector(),
512 digit->Strip(), Int_t(counts), Int_t(threshold),
513 ped, fPedestalFactor, pedW));
514 if (fSpec) fSpec->Fill(counts);
515 if (counts < threshold) return kTRUE;
516 if (fHits) fHits->Add(digit);
517 if (fSpecCut) fSpecCut->Fill(counts);
519 AddMarker(det, ring, sec, str, digit, counts, 1024);
523 //____________________________________________________________________
525 AliFMDDisplay::ProcessRaw(AliFMDDigit* digit)
528 return ProcessDigit(digit);
531 //____________________________________________________________________
533 AliFMDDisplay::ProcessRecPoint(AliFMDRecPoint* recpoint)
535 // Process reconstructed point
536 if (!recpoint) { AliError("No recpoint"); return kFALSE; }
537 if (recpoint->Particles() < fMultCut) return kTRUE;
538 if (fHits) fHits->Add(recpoint);
539 AddMarker(recpoint->Detector(), recpoint->Ring(), recpoint->Sector(),
540 recpoint->Strip(), recpoint, recpoint->Particles(), 20);
544 //____________________________________________________________________
546 AliFMDDisplay::ProcessESD(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
547 Float_t, Float_t mult)
549 Double_t cmult = mult;
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);
557 //____________________________________________________________________