]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDDisplay.cxx
- Adapted comments for Doxygen
[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//
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
15b17c89 37#include <AliESDFMD.h> // ALIESDFMD_H
bf000c32 38#include <AliLog.h>
39#include <TStyle.h>
02a27b50 40// #include <TArrayF.h>
bf000c32 41#include <TMarker3DBox.h>
42#include <TGeoManager.h>
02a27b50 43// #include <TMath.h>
bf000c32 44#include <TApplication.h>
45#include <TButton.h>
02a27b50 46// #include <TParticle.h>
bf000c32 47#include <TCanvas.h>
48#include <TView.h>
49#include <TVirtualX.h>
50
51//____________________________________________________________________
52ClassImp(AliFMDDisplay)
53#if 0
54 ; // This is here to keep Emacs for indenting the next line
55#endif
56
57//____________________________________________________________________
58AliFMDDisplay* AliFMDDisplay::fgInstance = 0;
59
60//____________________________________________________________________
61AliFMDDisplay*
62AliFMDDisplay::Instance()
63{
02a27b50 64 // Return static instance
bf000c32 65 return fgInstance;
66}
67
68//____________________________________________________________________
69AliFMDDisplay::AliFMDDisplay(const char* gAliceFile)
70 : AliFMDInput(gAliceFile),
71 fWait(kFALSE),
72 fCanvas(0),
73 fPad(0),
74 fButton(0),
75 fZoom(0),
76 fPick(0),
77 fZoomMode(kFALSE)
78{
79 // Constructor of an FMD display object.
80 AddLoad(kGeometry);
81 fMarkers = new TObjArray;
82 fHits = new TObjArray;
83 fMarkers->SetOwner(kTRUE);
84 fHits->SetOwner(kFALSE);
85 fgInstance = this;
15b17c89 86 SetMultiplicityCut();
87 SetPedestalFactor();
bf000c32 88}
89
90//____________________________________________________________________
1e8f773e 91void
bf000c32 92AliFMDDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
93{
1e8f773e 94 // AliInfo(Form("Event %d, at (%d,%d)", px, py));
bf000c32 95 if (px == 0 && py == 0) return;
96 if (!fZoomMode && fPad->GetView()) {
97 fPad->GetView()->ExecuteRotateView(event, px, py);
98 return;
99 }
100 fPad->SetCursor(kCross);
101 switch (event) {
102 case kButton1Down:
103 fPad->TAttLine::Modify();
104 fX0 = fPad->AbsPixeltoX(px);
105 fY0 = fPad->AbsPixeltoY(py);
106 fXPixel = fOldXPixel = px;
107 fYPixel = fOldYPixel = py;
108 fLineDrawn = kFALSE;
109 return;
110 case kButton1Motion:
111 if (fLineDrawn)
112 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
113 TVirtualX::kHollow);
114 fOldXPixel = px;
115 fOldYPixel = py;
116 fLineDrawn = kTRUE;
117 gVirtualX->DrawBox(fXPixel, fYPixel, fOldXPixel, fOldYPixel,
118 TVirtualX::kHollow);
119 return;
120 case kButton1Up:
121 fPad->GetCanvas()->FeedbackMode(kFALSE);
122 if (px == fXPixel || py == fYPixel) return;
123 fX1 = fPad->AbsPixeltoX(px);
124 fY1 = fPad->AbsPixeltoY(py);
125 if (fX1 < fX0) std::swap(fX0, fX1);
126 if (fY1 < fY0) std::swap(fY0, fY1);
127 fPad->Range(fX0, fY0, fX1, fY1);
128 fPad->Modified();
129 return;
130 }
131}
132
133//____________________________________________________________________
1e8f773e 134Int_t
135AliFMDDisplay::DistancetoPrimitive(Int_t px, Int_t)
bf000c32 136{
1e8f773e 137 // AliInfo(Form("@ (%d,%d)", px, py));
bf000c32 138 fPad->SetCursor(kCross);
139 Float_t xmin = fPad->GetX1();
140 Float_t xmax = fPad->GetX2();
141 Float_t dx = .02 * (xmax - xmin);
142 Float_t x = fPad->AbsPixeltoX(px);
143 if (x < xmin + dx || x > xmax - dx) return 9999;
144 return (fZoomMode ? 0 : 7);
145}
146//____________________________________________________________________
147Bool_t
148AliFMDDisplay::Init()
149{
02a27b50 150 // Initialize. GEt transforms and such,
bf000c32 151 if (!AliFMDInput::Init()) return kFALSE;
152 AliFMDGeometry* geom = AliFMDGeometry::Instance();
153 geom->Init();
154 geom->InitTransformations();
155 // AliFMDParameters* parm = AliFMDParameters::Instance();
156 // parm->Init();
157 return kTRUE;
158}
159//____________________________________________________________________
160Bool_t
161AliFMDDisplay::Begin(Int_t event)
162{
02a27b50 163 // Begin of event. Make canvas is not already done
bf000c32 164 if (!fCanvas) {
165 gStyle->SetPalette(1);
166 fCanvas = new TCanvas("display", "Display", 700, 700);
167 fCanvas->SetFillColor(1);
168 fCanvas->ToggleEventStatus();
169 fPad = new TPad("view3D", "3DView", 0.0, 0.05, 1.0, 1.0, 1, 0, 0);
170 fCanvas->cd();
171 fPad->Draw();
172 }
173 if (!fButton) {
174 fCanvas->cd();
175 fButton = new TButton("Continue", "AliFMDDisplay::Instance()->Continue()",
176 0, 0, .5, .05);
177 fButton->Draw();
178 fZoom = new TButton("Zoom", "AliFMDDisplay::Instance()->Zoom()",
179 .5, 0, .75, .05);
180 fZoom->Draw();
181 fPick = new TButton("Pick", "AliFMDDisplay::Instance()->Pick()",
182 .75, 0, 1, .05);
183 fPick->Draw();
184 }
185 AliInfo("Clearing canvas");
186 // fCanvas->Clear();
187 if (!fGeoManager) {
188 Warning("End", "No geometry manager");
189 return kFALSE;
190 }
191 AliInfo("Drawing geometry");
192 fPad->cd();
193 fGeoManager->GetTopVolume()->Draw();
194 AliInfo("Adjusting view");
195 Int_t irep;
196 if (fPad->GetView()) {
197 fPad->GetView()->SetView(-200, -40, 80, irep);
198 fPad->GetView()->Zoom();
199 fPad->Modified();
200 fPad->cd();
201 }
202 return AliFMDInput::Begin(event);
203}
204
205//____________________________________________________________________
206Bool_t
207AliFMDDisplay::End()
208{
02a27b50 209 // End of event. Draw everything
bf000c32 210 fPad->cd();
211 fMarkers->Draw();
1e8f773e 212 fPad->cd();
bf000c32 213 AppendPad();
1e8f773e 214 // fPad->Update();
bf000c32 215 fPad->cd();
1e8f773e 216 // fCanvas->Modified(kTRUE);
217 //fCanvas->Update();
218 // fCanvas->cd();
219 // fPad->cd();
bf000c32 220 fWait = kTRUE;
221 while (fWait) {
222 gApplication->StartIdleing();
223 gSystem->InnerLoop();
224 gApplication->StopIdleing();
225 }
226 AliInfo("After idle loop");
227 fMarkers->Delete();
228 fHits->Clear();
229 AliInfo("After clearing caches");
230 return AliFMDInput::End();
231}
232
233//____________________________________________________________________
234Int_t
235AliFMDDisplay::LookupColor(Float_t x, Float_t max) const
236{
02a27b50 237 // Look-up color
bf000c32 238 Int_t idx = Int_t(x / max * gStyle->GetNumberOfColors());
239 return gStyle->GetColorPalette(idx);
240}
241
15b17c89 242//____________________________________________________________________
243void
244AliFMDDisplay::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
245 TObject* o, Float_t s, Float_t max)
246{
247 // Add a marker to the display
248 //
249 // det Detector
250 // rng Ring
251 // sec Sector
252 // str Strip
253 // o Object to refer to
254 // s Signal
255 // max Maximum of signal
256 //
257 AliFMDGeometry* geom = AliFMDGeometry::Instance();
258 Double_t x, y, z;
259 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
260 Float_t size = .1;
261 Float_t zsize = s / max * 10;
262 Float_t r = TMath::Sqrt(x * x + y * y);
263 Float_t theta = TMath::ATan2(r, z);
264 Float_t phi = TMath::ATan2(y, x);
265 Float_t rz = z + (z < 0 ? 1 : -1) * zsize;
266 TMarker3DBox* marker = new TMarker3DBox(x,y,rz,size,size,zsize,theta,phi);
267 if (o) marker->SetRefObject(o);
268 marker->SetLineColor(LookupColor(s, max));
269 fMarkers->Add(marker);
270}
271
bf000c32 272
273//____________________________________________________________________
274Bool_t
275AliFMDDisplay::ProcessHit(AliFMDHit* hit, TParticle* p)
276{
02a27b50 277 // Process a hit
bf000c32 278 if (!hit) { AliError("No hit"); return kFALSE; }
279 if (!p) { AliError("No track"); return kFALSE; }
280
281 fHits->Add(hit);
282 Float_t size = .1;
15b17c89 283 Float_t zsize = hit->Edep() * 10;
284 Float_t z = hit->Z() + (hit->Z() < 0 ? 1 : -1) * zsize;
bf000c32 285 Float_t pt = TMath::Sqrt(hit->Py()*hit->Py()+hit->Px()*hit->Px());
286 Float_t theta = TMath::ATan2(pt, hit->Pz());
287 Float_t phi = TMath::ATan2(hit->Py(), hit->Px());
15b17c89 288 TMarker3DBox* marker = new TMarker3DBox(hit->X(), hit->Y(), z,
289 size, size, zsize, theta, phi);
bf000c32 290 marker->SetLineColor(LookupColor(hit->Edep(), 1));
291 marker->SetRefObject(hit);
292 fMarkers->Add(marker);
293 return kTRUE;
294}
295
296//____________________________________________________________________
297Bool_t
298AliFMDDisplay::ProcessDigit(AliFMDDigit* digit)
299{
02a27b50 300 // Process a digit
bf000c32 301 if (!digit) { AliError("No digit"); return kFALSE; }
302
bf000c32 303 AliFMDParameters* parm = AliFMDParameters::Instance();
15b17c89 304 UShort_t det = digit->Detector();
305 Char_t ring = digit->Ring();
306 UShort_t sec = digit->Sector();
307 UShort_t str = digit->Strip();
308 Double_t ped = parm->GetPedestal(det,ring, sec, str);
309 Double_t pedW = parm->GetPedestalWidth(det,ring, sec, str);
310 Double_t threshold = ped * fPedestalFactor * pedW;
311 Float_t counts = digit->Counts();
312 if (counts < threshold) return kTRUE;
bf000c32 313 fHits->Add(digit);
15b17c89 314
315 AddMarker(det, ring, sec, str, digit, counts, 1024);
bf000c32 316 return kTRUE;
317}
318
d760ea03 319//____________________________________________________________________
320Bool_t
321AliFMDDisplay::ProcessRaw(AliFMDDigit* digit)
322{
02a27b50 323 // PRocess raw data
d760ea03 324 return ProcessDigit(digit);
325}
326
bf000c32 327//____________________________________________________________________
328Bool_t
329AliFMDDisplay::ProcessRecPoint(AliFMDRecPoint* recpoint)
330{
02a27b50 331 // Process reconstructed point
bf000c32 332 if (!recpoint) { AliError("No recpoint"); return kFALSE; }
15b17c89 333 if (recpoint->Particles() < fMultCut) return kTRUE;
bf000c32 334 fHits->Add(recpoint);
15b17c89 335 AddMarker(recpoint->Detector(), recpoint->Ring(), recpoint->Sector(),
336 recpoint->Strip(), recpoint, recpoint->Particles(), 20);
337 return kTRUE;
338}
bf000c32 339
15b17c89 340//____________________________________________________________________
341Bool_t
342AliFMDDisplay::ProcessESD(AliESDFMD* esd)
343{
344 // Process event summary data
345 for (UShort_t det = 1; det <= 3; det++) {
346 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
347 for (Char_t* rng = rings; *rng != '\0'; rng++) {
348 UShort_t nsec = (*rng == 'I' ? 20 : 40);
349 UShort_t nstr = (*rng == 'O' ? 512 : 256);
350 for (UShort_t sec = 0; sec < nsec; sec++) {
351 for (UShort_t str = 0; str < nstr; str++) {
352 Float_t mult = esd->Multiplicity(det,*rng,sec,str);
353 if (mult < fMultCut) continue;
354 AddMarker(det,*rng,sec,str, 0, mult, 20);
355 }
356 }
357 }
358 }
bf000c32 359 return kTRUE;
360}
361
362//____________________________________________________________________
363//
364// EOF
365//