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
55 //____________________________________________________________________
56 ClassImp(AliFMDDisplay)
58 ; // This is here to keep Emacs for indenting the next line
61 //____________________________________________________________________
62 AliFMDDisplay* AliFMDDisplay::fgInstance = 0;
64 //____________________________________________________________________
66 AliFMDDisplay::Instance()
68 // Return static instance
72 //____________________________________________________________________
73 AliFMDDisplay::~AliFMDDisplay()
83 if (fPad) delete fPad;
85 if (fSlider) delete fSlider;
86 if (fCanvas) delete fCanvas;
89 //____________________________________________________________________
90 AliFMDDisplay::AliFMDDisplay(Bool_t onlyFMD, const char* gAliceFile)
91 : AliFMDInput(gAliceFile),
112 // Constructor of an FMD display object.
114 if (fgInstance) delete fgInstance;
116 SetMultiplicityCut();
120 //____________________________________________________________________
122 AliFMDDisplay::MakeCanvas(const char** which)
124 gStyle->SetPalette(1);
127 fCanvas = new TCanvas("display", "Display", w, Int_t(w / (1-y1)));
128 fCanvas->SetFillColor(1);
129 fCanvas->ToggleEventStatus();
131 fPad = new TPad("view", "3DView", 0.0, y1, 1.0, 1.0, 1, 0, 0);
136 if (TESTBIT(fTreeMask, kESD) ||
137 TESTBIT(fTreeMask, kDigits) ||
138 TESTBIT(fTreeMask, kRaw)) {
140 fSlider = new TSlider("multCut", "Multiplicity cut", 0, 0, 1, yb);
141 fSlider->SetMethod("AliFMDDisplay::Instance()->ChangeCut()");
143 fSlider->SetMinimum(TESTBIT(fTreeMask, kESD) ? fMultCut * 10 :
144 fPedestalFactor * 10);
146 const char** p = which;
151 AliInfo(Form("Got %d buttons", n));
155 while ((m = *(p++))) {
157 AliInfo(Form("Adding button %s", m));
158 TButton* b = new TButton(m, Form("AliFMDDisplay::Instance()->%s()", m),
159 x0, yb, x0 + dx, y1);
167 //____________________________________________________________________
169 AliFMDDisplay::ShowOnlyFMD()
171 if (!fGeoManager) return;
172 static bool once = false;
175 AliInfo("Will only show the FMD");
176 TGeoVolume* top = gGeoManager->GetTopVolume();
177 top->InvisibleAll(kTRUE);
178 TGeoIterator next(top);
181 Bool_t hasFMD1 = kFALSE;
182 Bool_t hasFMD2 = kFALSE;
183 Bool_t hasFMD3 = kFALSE;
185 while ((node = static_cast<TGeoNode*>(next()))) {
186 const char* name = node->GetName();
188 if (!(v = node->GetVolume())) continue;
190 if (name[0] == 'F') {
191 if (name[2] == 'M' && (name[3] == 'T' || name[3] == 'B')) {
192 // Virtual Master half-ring volume - top-level
193 Int_t det = node->GetNumber();
195 case 1: hasFMD1 = true; break;
196 case 2: hasFMD2 = true; break;
197 case 3: hasFMD3 = true; break;
202 else if (name[3] == 'V' && (name[2] == 'T' || name[2] == 'B'))
203 toshow.Add(v); // Virtual Half-ring, bare detectors
204 // else if (name[3] == 'H' && (name[2] == 'F' || name[2] == 'B'))
205 // toshow.Add(v); // Virtual Hybrid container
207 v->SetVisibility(kFALSE);
208 v->SetVisDaughters(kFALSE);
209 v->InvisibleAll(kTRUE);
212 while ((v = static_cast<TGeoVolume*>(i()))) {
213 v->SetVisibility(kTRUE);
214 v->SetVisDaughters(kTRUE);
215 v->InvisibleAll(kFALSE);
220 //____________________________________________________________________
222 AliFMDDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
224 // AliInfo(Form("Event %d, at (%d,%d)", px, py));
225 if (px == 0 && py == 0) return;
226 if (!fZoomMode && fPad->GetView()) {
227 fPad->GetView()->ExecuteRotateView(event, px, py);
230 fPad->SetCursor(kCross);
233 fPad->TAttLine::Modify();
234 fX0 = fPad->AbsPixeltoX(px);
235 fY0 = fPad->AbsPixeltoY(py);
236 fXPixel = fOldXPixel = px;
237 fYPixel = fOldYPixel = py;
242 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
247 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
251 fPad->GetCanvas()->FeedbackMode(kFALSE);
252 if (px == fXPixel || py == fYPixel) return;
253 fX1 = fPad->AbsPixeltoX(px);
254 fY1 = fPad->AbsPixeltoY(py);
255 if (fX1 < fX0) std::swap(fX0, fX1);
256 if (fY1 < fY0) std::swap(fY0, fY1);
257 fPad->Range(fX0, fY0, fX1, fY1);
263 //____________________________________________________________________
265 AliFMDDisplay::DistancetoPrimitive(Int_t px, Int_t)
267 // AliInfo(Form("@ (%d,%d)", px, py));
268 fPad->SetCursor(kCross);
269 Float_t xmin = fPad->GetX1();
270 Float_t xmax = fPad->GetX2();
271 Float_t dx = .02 * (xmax - xmin);
272 Float_t x = fPad->AbsPixeltoX(px);
273 if (x < xmin + dx || x > xmax - dx) return 9999;
274 return (fZoomMode ? 0 : 7);
276 //____________________________________________________________________
278 AliFMDDisplay::Init()
280 // Initialize. GEt transforms and such,
281 if (!AliFMDInput::Init()) return kFALSE;
282 AliFMDGeometry* geom = AliFMDGeometry::Instance();
284 geom->InitTransformations();
285 if (TESTBIT(fTreeMask, kDigits) || TESTBIT(fTreeMask, kRaw))
286 AliFMDParameters::Instance()->Init();
288 fMarkers = new TObjArray;
289 fHits = new TObjArray;
290 fMarkers->SetOwner(kTRUE);
291 fHits->SetOwner(kFALSE);
295 //____________________________________________________________________
297 AliFMDDisplay::MakeAux()
299 if ((TESTBIT(fTreeMask, kESD) ||
300 TESTBIT(fTreeMask, kDigits) ||
301 TESTBIT(fTreeMask, kRaw))) {
303 fAux = new TCanvas("aux", "Aux");
305 if (TESTBIT(fTreeMask, kESD))
306 fSpec = new TH1D("spec", "Mult spectra", 500, 0, 10);
308 fSpec = new TH1D("spec", "Adc spectra", 1024, -.5, 1023.5);
309 fSpecCut = static_cast<TH1*>(fSpec->Clone("specCut"));
310 fSpec->SetFillColor(2);
311 fSpec->SetFillStyle(3001);
312 fSpecCut->SetFillColor(4);
313 fSpecCut->SetFillStyle(3001);
322 //____________________________________________________________________
324 AliFMDDisplay::DrawAux()
330 fSpecCut->Draw("same");
336 //____________________________________________________________________
338 AliFMDDisplay::Begin(Int_t event)
340 // Begin of event. Make canvas is not already done
342 const char* m[] = { "Continue", "Zoom", "Pick", "Redisplay", 0 };
347 // AliInfo("Clearing canvas");
350 Warning("End", "No geometry manager");
353 AliInfo("Drawing geometry");
355 fGeoManager->GetTopVolume()->Draw();
356 if (fOnlyFMD) ShowOnlyFMD();
357 AliInfo("Adjusting view");
359 if (fPad->GetView()) {
360 fPad->GetView()->SetView(-200, -40, 80, irep);
361 fPad->GetView()->Zoom();
365 return AliFMDInput::Begin(event);
368 //____________________________________________________________________
370 AliFMDDisplay::AtEnd()
380 //____________________________________________________________________
382 AliFMDDisplay::Idle()
386 gApplication->StartIdleing();
387 gSystem->InnerLoop();
388 gApplication->StopIdleing();
390 AliInfo("After idle loop");
391 if (fMarkers) fMarkers->Delete();
392 if (fHits) fHits->Clear();
393 AliInfo("After clearing caches");
396 //____________________________________________________________________
400 // End of event. Draw everything
403 return AliFMDInput::End();
406 //____________________________________________________________________
408 AliFMDDisplay::LookupColor(Float_t x, Float_t max) const
411 Int_t idx = Int_t(x / max * gStyle->GetNumberOfColors());
412 return gStyle->GetColorPalette(idx);
415 //____________________________________________________________________
417 AliFMDDisplay::ChangeCut()
419 fMultCut = fSlider->GetMinimum() * 10;
420 fPedestalFactor = fSlider->GetMinimum() * 10;
421 AliInfo(Form("Multiplicity cut: %7.5f, Pedestal factor: %7.4f (%6.5f)",
422 fMultCut, fPedestalFactor, fSlider->GetMinimum()));
426 //____________________________________________________________________
428 AliFMDDisplay::Redisplay()
430 if (fMarkers) fMarkers->Delete();
431 if (fHits) fHits->Clear();
432 if (fSpec) fSpec->Reset();
433 if (fSpecCut) fSpecCut->Reset();
438 //____________________________________________________________________
440 AliFMDDisplay::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
441 TObject* o, Float_t s, Float_t max)
443 // Add a marker to the display
449 // o Object to refer to
451 // max Maximum of signal
453 AliFMDGeometry* geom = AliFMDGeometry::Instance();
455 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
457 Float_t zsize = s / max * 10;
458 Float_t r = TMath::Sqrt(x * x + y * y);
459 Float_t theta = TMath::ATan2(r, z);
460 Float_t phi = TMath::ATan2(y, x);
461 Float_t rz = z + (z < 0 ? 1 : -1) * zsize;
462 TMarker3DBox* marker = new TMarker3DBox(x,y,rz,size,size,zsize,theta,phi);
463 if (o) marker->SetRefObject(o);
464 marker->SetLineColor(LookupColor(s, max));
465 fMarkers->Add(marker);
469 //____________________________________________________________________
471 AliFMDDisplay::ProcessHit(AliFMDHit* hit, TParticle* /* p */)
474 if (!hit) { AliError("No hit"); return kFALSE; }
475 // if (!p) { AliError("No track"); return kFALSE; }
477 if (fHits) fHits->Add(hit);
479 Float_t zsize = TMath::Sqrt(hit->Edep() * 20);
480 Float_t z = hit->Z() + (hit->Z() < 0 ? 1 : -1) * zsize;
481 Float_t pt = TMath::Sqrt(hit->Py()*hit->Py()+hit->Px()*hit->Px());
482 Float_t theta = TMath::ATan2(pt, hit->Pz());
483 Float_t phi = TMath::ATan2(hit->Py(), hit->Px());
484 TMarker3DBox* marker = new TMarker3DBox(hit->X(), hit->Y(), z,
485 size, size, zsize, theta, phi);
486 marker->SetLineColor(LookupColor(hit->Edep(), 1));
487 marker->SetRefObject(hit);
488 fMarkers->Add(marker);
492 //____________________________________________________________________
494 AliFMDDisplay::ProcessDigit(AliFMDDigit* digit)
497 if (!digit) { AliError("No digit"); return kFALSE; }
499 AliFMDParameters* parm = AliFMDParameters::Instance();
500 UShort_t det = digit->Detector();
501 Char_t ring = digit->Ring();
502 UShort_t sec = digit->Sector();
503 UShort_t str = digit->Strip();
504 Double_t ped = parm->GetPedestal(det,ring, sec, str);
505 Double_t pedW = parm->GetPedestalWidth(det,ring, sec, str);
506 Double_t threshold = ped + fPedestalFactor * pedW;
507 Float_t counts = digit->Counts();
508 AliDebug(10, Form("FMD%d%c[%2d,%3d] ADC: %d > %d (=%4.2f+%4.2f*%4.2f)",
509 digit->Detector(), digit->Ring(), digit->Sector(),
510 digit->Strip(), Int_t(counts), Int_t(threshold),
511 ped, fPedestalFactor, pedW));
512 if (fSpec) fSpec->Fill(counts);
513 if (counts < threshold) return kTRUE;
514 if (fHits) fHits->Add(digit);
515 if (fSpecCut) fSpecCut->Fill(counts);
517 AddMarker(det, ring, sec, str, digit, counts, 1024);
521 //____________________________________________________________________
523 AliFMDDisplay::ProcessRaw(AliFMDDigit* digit)
526 return ProcessDigit(digit);
529 //____________________________________________________________________
531 AliFMDDisplay::ProcessRecPoint(AliFMDRecPoint* recpoint)
533 // Process reconstructed point
534 if (!recpoint) { AliError("No recpoint"); return kFALSE; }
535 if (recpoint->Particles() < fMultCut) return kTRUE;
536 if (fHits) fHits->Add(recpoint);
537 AddMarker(recpoint->Detector(), recpoint->Ring(), recpoint->Sector(),
538 recpoint->Strip(), recpoint, recpoint->Particles(), 20);
542 //____________________________________________________________________
544 AliFMDDisplay::ProcessESD(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
545 Float_t, Float_t mult)
547 Double_t cmult = mult;
548 if (fSpec) fSpec->Fill(cmult);
549 if (cmult < fMultCut || cmult == AliESDFMD::kInvalidMult) return kTRUE;
550 AddMarker(det,rng,sec,str, 0, cmult, 20);
551 if (fSpecCut) fSpecCut->Fill(cmult);
555 //____________________________________________________________________