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
31 #include "AliFMDDisplay.h" // ALIFMDDISPLAY_H
32 #include "AliFMDHit.h" // ALIFMDHIT_H
33 #include "AliFMDDigit.h" // ALIFMDDIGIT_H
34 #include "AliFMDRecPoint.h" // ALIFMDRECPOINT_H
35 #include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
36 #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
37 #include <AliESDFMD.h> // ALIESDFMD_H
40 // #include <TArrayF.h>
41 #include <TMarker3DBox.h>
42 #include <TGeoManager.h>
44 #include <TApplication.h>
46 // #include <TParticle.h>
49 #include <TVirtualX.h>
53 //____________________________________________________________________
54 ClassImp(AliFMDDisplay)
56 ; // This is here to keep Emacs for indenting the next line
59 //____________________________________________________________________
60 AliFMDDisplay* AliFMDDisplay::fgInstance = 0;
62 //____________________________________________________________________
64 AliFMDDisplay::Instance()
66 // Return static instance
70 //____________________________________________________________________
71 AliFMDDisplay::~AliFMDDisplay()
81 if (fPad) delete fPad;
83 if (fSlider) delete fSlider;
84 if (fCanvas) delete fCanvas;
87 //____________________________________________________________________
88 AliFMDDisplay::AliFMDDisplay(Bool_t onlyFMD, const char* gAliceFile)
89 : AliFMDInput(gAliceFile),
110 // Constructor of an FMD display object.
112 if (fgInstance) delete fgInstance;
114 SetMultiplicityCut();
118 //____________________________________________________________________
120 AliFMDDisplay::MakeCanvas(const char** which)
122 gStyle->SetPalette(1);
125 fCanvas = new TCanvas("display", "Display", w, Int_t(w / (1-y1)));
126 fCanvas->SetFillColor(1);
127 fCanvas->ToggleEventStatus();
129 fPad = new TPad("view", "3DView", 0.0, y1, 1.0, 1.0, 1, 0, 0);
134 if (TESTBIT(fTreeMask, kESD) ||
135 TESTBIT(fTreeMask, kDigits) ||
136 TESTBIT(fTreeMask, kRaw)) {
138 fSlider = new TSlider("multCut", "Multiplicity cut", 0, 0, 1, yb);
139 fSlider->SetMethod("AliFMDDisplay::Instance()->ChangeCut()");
140 fSlider->SetMinimum(TESTBIT(fTreeMask, kESD) ? fMultCut :
141 fPedestalFactor * 10);
144 const char** p = which;
149 AliInfo(Form("Got %d buttons", n));
153 while ((m = *(p++))) {
155 AliInfo(Form("Adding button %s", m));
156 TButton* b = new TButton(m, Form("AliFMDDisplay::Instance()->%s()", m),
157 x0, yb, x0 + dx, y1);
165 //____________________________________________________________________
167 AliFMDDisplay::ShowOnlyFMD()
169 if (!fGeoManager) return;
170 static bool once = false;
173 AliInfo("Will only show the FMD");
174 TGeoVolume* top = gGeoManager->GetTopVolume();
175 top->InvisibleAll(kTRUE);
176 TGeoIterator next(top);
179 Bool_t hasFMD1 = kFALSE;
180 Bool_t hasFMD2 = kFALSE;
181 Bool_t hasFMD3 = kFALSE;
183 while ((node = static_cast<TGeoNode*>(next()))) {
184 const char* name = node->GetName();
186 if (!(v = node->GetVolume())) continue;
188 if (name[0] == 'F') {
189 if (name[2] == 'M' && (name[3] == 'T' || name[3] == 'B')) {
190 // Virtual Master half-ring volume - top-level
191 Int_t det = node->GetNumber();
193 case 1: hasFMD1 = true; break;
194 case 2: hasFMD2 = true; break;
195 case 3: hasFMD3 = true; break;
200 else if (name[3] == 'V' && (name[2] == 'T' || name[2] == 'B'))
201 toshow.Add(v); // Virtual Half-ring, bare detectors
202 // else if (name[3] == 'H' && (name[2] == 'F' || name[2] == 'B'))
203 // toshow.Add(v); // Virtual Hybrid container
205 v->SetVisibility(kFALSE);
206 v->SetVisDaughters(kFALSE);
207 v->InvisibleAll(kTRUE);
210 while ((v = static_cast<TGeoVolume*>(i()))) {
211 v->SetVisibility(kTRUE);
212 v->SetVisDaughters(kTRUE);
213 v->InvisibleAll(kFALSE);
218 //____________________________________________________________________
220 AliFMDDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
222 // AliInfo(Form("Event %d, at (%d,%d)", px, py));
223 if (px == 0 && py == 0) return;
224 if (!fZoomMode && fPad->GetView()) {
225 fPad->GetView()->ExecuteRotateView(event, px, py);
228 fPad->SetCursor(kCross);
231 fPad->TAttLine::Modify();
232 fX0 = fPad->AbsPixeltoX(px);
233 fY0 = fPad->AbsPixeltoY(py);
234 fXPixel = fOldXPixel = px;
235 fYPixel = fOldYPixel = py;
240 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
245 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
249 fPad->GetCanvas()->FeedbackMode(kFALSE);
250 if (px == fXPixel || py == fYPixel) return;
251 fX1 = fPad->AbsPixeltoX(px);
252 fY1 = fPad->AbsPixeltoY(py);
253 if (fX1 < fX0) std::swap(fX0, fX1);
254 if (fY1 < fY0) std::swap(fY0, fY1);
255 fPad->Range(fX0, fY0, fX1, fY1);
261 //____________________________________________________________________
263 AliFMDDisplay::DistancetoPrimitive(Int_t px, Int_t)
265 // AliInfo(Form("@ (%d,%d)", px, py));
266 fPad->SetCursor(kCross);
267 Float_t xmin = fPad->GetX1();
268 Float_t xmax = fPad->GetX2();
269 Float_t dx = .02 * (xmax - xmin);
270 Float_t x = fPad->AbsPixeltoX(px);
271 if (x < xmin + dx || x > xmax - dx) return 9999;
272 return (fZoomMode ? 0 : 7);
274 //____________________________________________________________________
276 AliFMDDisplay::Init()
278 // Initialize. GEt transforms and such,
279 if (!AliFMDInput::Init()) return kFALSE;
280 AliFMDGeometry* geom = AliFMDGeometry::Instance();
282 geom->InitTransformations();
283 fMarkers = new TObjArray;
284 fHits = new TObjArray;
285 fMarkers->SetOwner(kTRUE);
286 fHits->SetOwner(kFALSE);
290 //____________________________________________________________________
292 AliFMDDisplay::MakeAux()
294 if ((TESTBIT(fTreeMask, kESD) ||
295 TESTBIT(fTreeMask, kDigits) ||
296 TESTBIT(fTreeMask, kRaw))) {
298 fAux = new TCanvas("aux", "Aux");
300 if (TESTBIT(fTreeMask, kESD))
301 fSpec = new TH1D("spec", "Mult spectra", 150, 0, 3);
303 fSpec = new TH1D("spec", "Adc spectra", 1024, -.5, 1023.5);
304 fSpecCut = static_cast<TH1*>(fSpec->Clone("specCut"));
305 fSpec->SetFillColor(2);
306 fSpec->SetFillStyle(3001);
307 fSpecCut->SetFillColor(4);
308 fSpecCut->SetFillStyle(3001);
317 //____________________________________________________________________
319 AliFMDDisplay::DrawAux()
325 fSpecCut->Draw("same");
331 //____________________________________________________________________
333 AliFMDDisplay::Begin(Int_t event)
335 // Begin of event. Make canvas is not already done
337 const char* m[] = { "Continue", "Zoom", "Pick", "Redisplay", 0 };
341 // AliInfo("Clearing canvas");
344 Warning("End", "No geometry manager");
347 AliInfo("Drawing geometry");
349 fGeoManager->GetTopVolume()->Draw();
350 if (fOnlyFMD) ShowOnlyFMD();
351 AliInfo("Adjusting view");
353 if (fPad->GetView()) {
354 fPad->GetView()->SetView(-200, -40, 80, irep);
355 fPad->GetView()->Zoom();
359 return AliFMDInput::Begin(event);
362 //____________________________________________________________________
364 AliFMDDisplay::AtEnd()
374 //____________________________________________________________________
376 AliFMDDisplay::Idle()
380 gApplication->StartIdleing();
381 gSystem->InnerLoop();
382 gApplication->StopIdleing();
384 AliInfo("After idle loop");
385 if (fMarkers) fMarkers->Delete();
386 if (fHits) fHits->Clear();
387 AliInfo("After clearing caches");
390 //____________________________________________________________________
394 // End of event. Draw everything
397 return AliFMDInput::End();
400 //____________________________________________________________________
402 AliFMDDisplay::LookupColor(Float_t x, Float_t max) const
405 Int_t idx = Int_t(x / max * gStyle->GetNumberOfColors());
406 return gStyle->GetColorPalette(idx);
409 //____________________________________________________________________
411 AliFMDDisplay::ChangeCut()
413 fMultCut = fSlider->GetMinimum();
414 fPedestalFactor = fSlider->GetMinimum() * 10;
415 AliInfo(Form("Multiplicity cut: %7.5f, Pedestal factor: %7.4f (%6.5f)",
416 fMultCut, fPedestalFactor, fSlider->GetMinimum()));
420 //____________________________________________________________________
422 AliFMDDisplay::Redisplay()
424 if (fMarkers) fMarkers->Delete();
425 if (fHits) fHits->Clear();
426 if (fSpec) fSpec->Reset();
427 if (fSpecCut) fSpecCut->Reset();
432 //____________________________________________________________________
434 AliFMDDisplay::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
435 TObject* o, Float_t s, Float_t max)
437 // Add a marker to the display
443 // o Object to refer to
445 // max Maximum of signal
447 AliFMDGeometry* geom = AliFMDGeometry::Instance();
449 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
451 Float_t zsize = s / max * 10;
452 Float_t r = TMath::Sqrt(x * x + y * y);
453 Float_t theta = TMath::ATan2(r, z);
454 Float_t phi = TMath::ATan2(y, x);
455 Float_t rz = z + (z < 0 ? 1 : -1) * zsize;
456 TMarker3DBox* marker = new TMarker3DBox(x,y,rz,size,size,zsize,theta,phi);
457 if (o) marker->SetRefObject(o);
458 marker->SetLineColor(LookupColor(s, max));
459 fMarkers->Add(marker);
463 //____________________________________________________________________
465 AliFMDDisplay::ProcessHit(AliFMDHit* hit, TParticle* /* p */)
468 if (!hit) { AliError("No hit"); return kFALSE; }
469 // if (!p) { AliError("No track"); return kFALSE; }
471 if (fHits) fHits->Add(hit);
473 Float_t zsize = TMath::Sqrt(hit->Edep() * 20);
474 Float_t z = hit->Z() + (hit->Z() < 0 ? 1 : -1) * zsize;
475 Float_t pt = TMath::Sqrt(hit->Py()*hit->Py()+hit->Px()*hit->Px());
476 Float_t theta = TMath::ATan2(pt, hit->Pz());
477 Float_t phi = TMath::ATan2(hit->Py(), hit->Px());
478 TMarker3DBox* marker = new TMarker3DBox(hit->X(), hit->Y(), z,
479 size, size, zsize, theta, phi);
480 marker->SetLineColor(LookupColor(hit->Edep(), 1));
481 marker->SetRefObject(hit);
482 fMarkers->Add(marker);
486 //____________________________________________________________________
488 AliFMDDisplay::ProcessDigit(AliFMDDigit* digit)
491 if (!digit) { AliError("No digit"); return kFALSE; }
493 AliFMDParameters* parm = AliFMDParameters::Instance();
494 UShort_t det = digit->Detector();
495 Char_t ring = digit->Ring();
496 UShort_t sec = digit->Sector();
497 UShort_t str = digit->Strip();
498 Double_t ped = parm->GetPedestal(det,ring, sec, str);
499 Double_t pedW = parm->GetPedestalWidth(det,ring, sec, str);
500 Double_t threshold = ped * fPedestalFactor * pedW;
501 Float_t counts = digit->Counts();
502 if (fSpec) fSpec->Fill(counts);
503 if (counts < threshold) return kTRUE;
504 if (fHits) fHits->Add(digit);
505 if (fSpecCut) fSpecCut->Fill(counts);
507 AddMarker(det, ring, sec, str, digit, counts, 1024);
511 //____________________________________________________________________
513 AliFMDDisplay::ProcessRaw(AliFMDDigit* digit)
516 return ProcessDigit(digit);
519 //____________________________________________________________________
521 AliFMDDisplay::ProcessRecPoint(AliFMDRecPoint* recpoint)
523 // Process reconstructed point
524 if (!recpoint) { AliError("No recpoint"); return kFALSE; }
525 if (recpoint->Particles() < fMultCut) return kTRUE;
526 if (fHits) fHits->Add(recpoint);
527 AddMarker(recpoint->Detector(), recpoint->Ring(), recpoint->Sector(),
528 recpoint->Strip(), recpoint, recpoint->Particles(), 20);
532 //____________________________________________________________________
534 AliFMDDisplay::ProcessESD(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
535 Float_t eta, Float_t mult)
537 Double_t cmult = (mult *
538 TMath::Abs(TMath::Cos(2.*TMath::ATan(TMath::Exp(-eta)))));
539 if (fSpec) fSpec->Fill(cmult);
540 if (cmult < fMultCut || cmult == AliESDFMD::kInvalidMult) return kTRUE;
541 AddMarker(det,rng,sec,str, 0, cmult, 20);
542 if (fSpecCut) fSpecCut->Fill(cmult);
546 //____________________________________________________________________