Various small fixes
[u/mrichter/AliRoot.git] / FMD / AliFMDPattern.cxx
CommitLineData
a9579262 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 **************************************************************************/
15/* $Id$ */
16/** @file AliFMDPattern.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:39:09 2006
19 @brief FMD 2D Event display
20*/
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//
9edefa04 31
f95a63c4 32// #include <iostream>
9edefa04 33
f95a63c4 34// #include <TApplication.h>
35// #include <TButton.h>
9edefa04 36#include <TCanvas.h>
37#include <TH2F.h>
38#include <TMath.h>
39#include <TPad.h>
40#include <TRandom.h>
f95a63c4 41// #include <TSlider.h>
9edefa04 42#include <TStyle.h>
f95a63c4 43// #include <TSystem.h>
9edefa04 44#include <TVector2.h>
f95a63c4 45// #include <TView.h>
46#include <TGraph.h>
a9579262 47#include "AliFMDPattern.h" // ALIFMDDISPLAY_H
48#include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
f95a63c4 49//#include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
a9579262 50#include "AliFMDRing.h"
f95a63c4 51// #include "AliFMDDetector.h"
a9579262 52#include "AliFMDHit.h"
f95a63c4 53// #include <AliLog.h>
54#include "AliFMDDebug.h" // Better debug macros
55class AliFMDDetector;
a9579262 56
57//____________________________________________________________________
58ClassImp(AliFMDPattern)
59#if 0
60 ; // This is here to keep Emacs for indenting the next line
61#endif
62
63//____________________________________________________________________
f95a63c4 64AliFMDPattern::AliFMDPatternDetector::AliFMDPatternDetector(UShort_t id)
a9579262 65 : fId(id),
66 fCounts(0),
67 fGraphs(0),
f38b1653 68 fFrame(0),
7af3df7f 69 fInners(10),
70 fOuters(id == 1 ? 0 : 20)
f95a63c4 71{
72 // CTOR
73 //
74 // Parameters:
75 //
76 // ID Identifier
77}
a9579262 78
79//____________________________________________________________________
f95a63c4 80AliFMDPattern::AliFMDPatternDetector::~AliFMDPatternDetector()
a9579262 81{
f95a63c4 82 // DTOR
83 // Destructor -
84 // deletes mother frame
a9579262 85 if (fFrame) delete fFrame;
86}
87
88//____________________________________________________________________
89void
f95a63c4 90AliFMDPattern::AliFMDPatternDetector::DrawShape(TObjArray& a)
a9579262 91{
f95a63c4 92 // Draw all shapes.
93 //
94 // Paramters
95 //
96 // a Array of shapes
97 //
a9579262 98 TIter next(&a);
99 TGraph* g = 0;
100 while ((g = static_cast<TGraph*>(next()))) {
101 g->DrawClone("f same");
102 g->DrawClone("l same");
103 }
104}
105
f38b1653 106//____________________________________________________________________
107void
108AliFMDPattern::AliFMDPatternDetector::CopyShapes(TObjArray& src,
109 TObjArray& dest,
110 Double_t ang,
111 Double_t fx,
112 Double_t fy)
113{
114 TIter next(&src);
115 TGraph* g = 0;
116 while ((g = static_cast<TGraph*>(next()))) {
117 TGraph* gg = new TGraph(*g);
118 Double_t* x = gg->GetX();
119 Double_t* y = gg->GetY();
120 for (Int_t i = 0; i < gg->GetN(); i++) {
121 Float_t xx = x[i] * TMath::Cos(ang) - y[i] * TMath::Sin(ang);
122 Float_t yy = x[i] * TMath::Sin(ang) + y[i] * TMath::Cos(ang);
123 gg->SetPoint(i, fx * xx, fy * yy);
124 }
125 gg->SetFillStyle(g->GetFillStyle());
126 gg->SetFillColor(g->GetFillColor());
127 gg->SetLineStyle(g->GetLineStyle());
128 gg->SetLineColor(g->GetLineColor());
129 gg->SetLineWidth(g->GetLineWidth());
130 gg->SetMarkerStyle(g->GetMarkerStyle());
131 gg->SetMarkerColor(g->GetMarkerColor());
132 gg->SetMarkerSize(g->GetMarkerSize());
133 TString name(g->GetName());
134 name.ReplaceAll("X", Form("%d",fId));
135 gg->SetName(name.Data());
136 TString title(g->GetTitle());
137 title.ReplaceAll("X", Form("%d",fId));
138 gg->SetTitle(title.Data());
139 dest.Add(gg);
140 }
141 dest.SetOwner();
142}
143
a9579262 144//____________________________________________________________________
145void
cf291b42 146AliFMDPattern::AliFMDPatternDetector::Begin(Int_t nlevel,
147 Double_t r,
148 TObjArray& inners,
149 TObjArray& outers)
a9579262 150{
f95a63c4 151 // Start of a run.
152 //
153 // Parameters
154 //
155 // nlevel Number of levels
156 // r Radius
157 // inners Array of inner shapes
158 // outers Array of outer shapes
159 //
160
161 // To make code-checker shut up
162 TStyle* style = gStyle;
163 if (nlevel < 1) nlevel = style->GetNumberOfColors();
a9579262 164 fCounts.Set(nlevel);
5cf05dbb 165 Double_t rr = 1.05 * r;
a9579262 166 if (!fFrame) {
f95a63c4 167 // The code-checker thinks this is not using the declaration of
168 // TH2F - what a morron!
a9579262 169 fFrame = new TH2F(Form("fmd%dFrame", fId), Form("FMD%d", fId),
5cf05dbb 170 100, -rr, rr, 100, -rr, rr);
a9579262 171 fFrame->SetStats(kFALSE);
172 fFrame->Draw();
173 }
f38b1653 174 Double_t ang = (fId == 1 ? -TMath::Pi() / 2 : 0);
175 Double_t fx = (fId == 3 ? -1 : 1); // Flip around Y
176 Double_t fy = (fId == 1 ? 1 : 1); // Flip around X
177
178 CopyShapes(inners, fInners, ang, fx, fy);
179 DrawShape(fInners);
180 if (fId != 1) {
181 CopyShapes(outers, fOuters, ang, fx, fy);
182 DrawShape(fOuters);
183 }
184
a9579262 185 for (Int_t i = 0; i < nlevel; i++) {
186 TGraph* g = new TGraph;
f95a63c4 187 Int_t idx = Int_t(Float_t(i) / nlevel * style->GetNumberOfColors());
188 Int_t col = style->GetColorPalette(idx);
a9579262 189 g->SetName(Form("FMD%d_L%02d", fId, i));
190 g->SetMarkerColor(col);
191 g->SetLineColor(col);
192 g->SetFillColor(col);
193 g->SetMarkerSize(i * .2 + .2);
194 g->SetMarkerStyle(2);
5cf05dbb 195 g->SetEditable(kFALSE);
a9579262 196 g->Draw("same p");
197 fGraphs.AddAtAndExpand(g, i);
198 }
cf291b42 199 // TIter next(&fGraphs);
a9579262 200}
201
202//____________________________________________________________________
203void
f95a63c4 204AliFMDPattern::AliFMDPatternDetector::Clear()
a9579262 205{
f95a63c4 206 // Clear this display.
207 // Simply reset counters to zero.
208 // Avoid deleting memory.
a9579262 209 fCounts.Reset(0);
210}
211
212//____________________________________________________________________
213void
f95a63c4 214AliFMDPattern::AliFMDPatternDetector::End()
a9579262 215{
f95a63c4 216 // Called when displaying the data.
217 // Simply resets number of points at each level to
218 // the seen number of hits at that level.
219 // Avoid deleting memory.
a9579262 220 TIter next(&fGraphs);
221 TGraph* g = 0;
222 Int_t i = 0;
5cf05dbb 223 while ((g = static_cast<TGraph*>(next()))) {
224 Int_t cnt = fCounts[i++];
225 if (cnt > 0) {
226 g->Set(cnt);
227 g->SetMarkerSize(i * .2 + .2);
228 }
229 else {
230 g->SetPoint(0,0,0);
231 g->SetMarkerSize(0);
232 }
233 }
234
a9579262 235}
236//____________________________________________________________________
237void
cf291b42 238AliFMDPattern::AliFMDPatternDetector::AddMarker(Double_t x,
239 Double_t y,
240 Float_t s,
241 Float_t max)
a9579262 242{
f95a63c4 243 // Add a marker at (X,Y,Z). The marker color and size is chosen
244 // relative to the MAX argument.
245 //
246 // Parameters
247 //
248 // X,Y,Z Coordiantes
249 // MAX Maximum value.
250 //
251 /** Sigh, for some odd reason, the code-checker does not recognise
252 this a usage of the TMath namespace declaration! Idiot */
253 Int_t i = TMath::Min(Int_t(fCounts.fN * s / max),
a9579262 254 Int_t(fGraphs.GetEntries()-1));
255 TGraph* g = static_cast<TGraph*>(fGraphs.At(i));
256 if (!g) return;
257 g->SetPoint(fCounts[i]++, x, y);
258}
259
260
261//____________________________________________________________________
262AliFMDPattern::AliFMDPattern(const char* gAliceFile)
263 : AliFMDDisplay(kTRUE, gAliceFile),
17e542eb 264 fInners(0),
265 fOuters(0),
a9579262 266 fInnerMax(0),
267 fOuterMax(0),
268 fFMD1Pad(0),
269 fFMD1(1),
270 fFMD2Pad(0),
271 fFMD2(2),
272 fFMD3Pad(0),
273 fFMD3(3),
17e542eb 274 fSummary(0),
a9579262 275 fEvent(.1, .8, "Event #"),
276 fFMD1Sum(.2, .7, "# in FMD1: "),
277 fFMD2Sum(.2, .6, "# in FMD2: "),
278 fFMD3Sum(.2, .5, "# in FMD3: "),
279 fLine(.15, .47, .85, .47),
280 fTotal(.2, .35, "Total: ")
281{
f95a63c4 282 // Constructor.
283 //
284 // Parameters
285 //
286 // gAliceFile The galice.root file to use - if any.
287 //
288
42f1b2f5 289 SetName("AliFMDPattern");
290 SetName("2D display of FMD data");
291
a9579262 292 // RemoveLoad(kGeometry);
293 fEvent.SetBit(TLatex::kTextNDC);
294 fFMD1Sum.SetBit(TLatex::kTextNDC);
295 fFMD2Sum.SetBit(TLatex::kTextNDC);
296 fFMD3Sum.SetBit(TLatex::kTextNDC);
297 fLine.SetBit(TLine::kLineNDC);
298 fTotal.SetBit(TLatex::kTextNDC);
299}
300
301//____________________________________________________________________
302AliFMDPattern::~AliFMDPattern()
303{
f95a63c4 304 // DTOR
305 // Free all allocated shapes.
306 // note, that most members are real objects, so we do not need to
307 // deal with them here.
a9579262 308 fInners.Delete();
309 fOuters.Delete();
310}
311
312
313//____________________________________________________________________
314Bool_t
315AliFMDPattern::Init()
316{
f95a63c4 317 // Initialize. Get transforms and such,
a9579262 318 if (!AliFMDInput::Init()) return kFALSE;
319 AliFMDGeometry* geom = AliFMDGeometry::Instance();
69893a66 320 if (!geom) return kFALSE;
a9579262 321 geom->Init();
322 geom->InitTransformations();
323
324 Char_t rs[] = { 'I' , 'O', '\0' };
325 Char_t *r = rs;
326 do {
327 AliFMDRing* ring = geom->GetRing(*r);
328 if (!ring) continue;
329 const TObjArray& vs = ring->GetVerticies();
330 TObjArray& gs = (*r == 'I' ? fInners : fOuters);
331 Float_t& mr = (*r == 'I' ? fInnerMax : fOuterMax);
332 Int_t nm = ring->GetNModules();
f38b1653 333 AliFMDDebug(1, ("Making %d modules for %c", nm, *r));
a9579262 334 for (Int_t m = 0; m < nm; m++) {
c6b36280 335 Int_t nv = 6; // vs.GetEntries();
a9579262 336 Double_t a = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
337 TGraph* g = new TGraph(nv+1);
338 Double_t x0 = 0, y0 = 0;
339 gs.AddAtAndExpand(g, m);
c6b36280 340 for (Int_t c = 1; c < 4; c++) {
a9579262 341 TVector2* v = static_cast<TVector2*>(vs.At(c));
342 mr = TMath::Max(mr, Float_t(v->Mod()));
343 TVector2 w(v->Rotate(a));
c6b36280 344 if (c == 1) { x0 = w.X(); y0 = w.Y(); }
345 g->SetPoint(c-1, w.X(), w.Y());
346 }
347 for (Int_t c = 3; c > 0; c--) {
348 TVector2* v = static_cast<TVector2*>(vs.At(c));
349 TVector2 u(-v->X(), v->Y());
350 mr = TMath::Max(mr, Float_t(u.Mod()));
351 TVector2 w(u.Rotate(a));
352 g->SetPoint(3+(3-c), w.X(), w.Y());
a9579262 353 }
f38b1653 354 g->SetName(Form("FMDX%c_%02d%02d", *r, 2*m,2*m+1));
355 g->SetTitle(Form("FMDX%c, sectors %d and %d", *r, 2*m,2*m+1));
a9579262 356 g->SetPoint(nv, x0, y0);
357 g->SetFillColor((*rs == 'I' ?
358 (m % 2 == 0 ? 18 : 17) :
359 (m % 2 == 0 ? 20 : 23)));
360 g->SetFillStyle(3001);
361 g->SetLineColor(1);
362 g->SetLineWidth(1);
363 g->SetLineStyle(2);
364 }
365 } while (*(++r));
366
367 return kTRUE;
368}
369
370//____________________________________________________________________
371Bool_t
372AliFMDPattern::Begin(Int_t event)
373{
f95a63c4 374 // Called at the begining of an event.
375 //
376 // Parameters
377 //
378 // EVENT The event number
379 //
97b4001e 380 MakeAux();
a9579262 381 if (!fCanvas) {
2eddac03 382 const char* which[] = { "Continue", "Start", "Pause", "Redisplay", 0 };
a9579262 383 MakeCanvas(which);
a9579262 384
385 AliFMDGeometry* geom = AliFMDGeometry::Instance();
f95a63c4 386 // AliFMDDetector* det;
387 if ((/* det = */ geom->GetDetector(1))) {
a9579262 388 fPad->cd();
389 fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
390 fFMD1Pad->Draw();
391 fFMD1Pad->cd();
97b4001e 392 fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
a9579262 393 }
f95a63c4 394 if ((/* det = */ geom->GetDetector(2))) {
a9579262 395 fPad->cd();
396 fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
397 fFMD2Pad->Draw();
398 fFMD2Pad->cd();
97b4001e 399 fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
a9579262 400 }
f95a63c4 401 if ((/* det = */ geom->GetDetector(3))) {
a9579262 402 fPad->cd();
403 fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
404 fFMD3Pad->Draw();
405 fFMD3Pad->cd();
97b4001e 406 fFMD3.Begin(-1, fOuterMax, fInners, fOuters);
a9579262 407 }
408 fPad->cd();
409 fSummary = new TPad("display", "Display", 0.5, 0.0, 1.0, 0.5, 0, 0);
410 fSummary->Draw();
411 fSummary->cd();
412 fEvent.Draw();
413 fFMD1Sum.Draw();
414 fFMD2Sum.Draw();
415 fFMD3Sum.Draw();
416 fLine.Draw();
417 fTotal.Draw();
418 }
419 fEvent.SetTitle(Form("Event # %6d", event));
420
421 fCanvas->Modified();
422 fCanvas->Update();
423 fCanvas->cd();
424 fFMD1.Clear();
425 fFMD2.Clear();
426 fFMD3.Clear();
427 return AliFMDInput::Begin(event);
428}
429
430//____________________________________________________________________
431void
432AliFMDPattern::Redisplay()
433{
f95a63c4 434 // Redraw the displayu
a9579262 435 fFMD1.Clear();
436 fFMD2.Clear();
437 fFMD3.Clear();
438 AliFMDDisplay::Redisplay();
439}
440
441//____________________________________________________________________
442void
443AliFMDPattern::AtEnd()
444{
f95a63c4 445 // Called at the end of an event.
a9579262 446 DrawAux();
447
448 Int_t total = 0;
449
450 fFMD1.End();
451 fFMD1Pad->Modified();
452 fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d", fFMD1.Total()));
453 total += fFMD1.Total();
454
455 fFMD2.End();
456 fFMD2Pad->Modified();
457 fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d", fFMD2.Total()));
458 total += fFMD2.Total();
459
460 fFMD3.End();
461 fFMD3Pad->Modified();
462 fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d", fFMD3.Total()));
463 total += fFMD3.Total();
464
465 fTotal.SetTitle(Form("Total: %5d/51200 (%3d%%)",
466 total, Int_t(100. / 51200 * total)));
467 fSummary->Modified();
468 fCanvas->Modified();
469 fCanvas->Update();
470 fCanvas->cd();
471}
472
473//____________________________________________________________________
474Bool_t
475AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*)
476{
f95a63c4 477 // Process a hit.
478 //
479 // Parameters
480 //
481 // HIT The hit to process.
482 //
483 // The TParticle argument is never used.
ef8e8623 484 static const Float_t rMin = fgkEdepRange.fLow;
485 static const Float_t rMax = fgkEdepRange.fHigh;
486
487 if (!hit) { AliError("No hit"); return kFALSE; }
488 // if (!p) { AliError("No track"); return kFALSE; }
489 Float_t edep = hit->Edep();
490
491 if (fHits) fHits->Add(hit);
492 if (fSpec) fSpec->Fill(edep);
493 if (InsideCut(edep, rMin, rMax) && fSpecCut) fSpecCut->Fill(edep);
494
a9579262 495 switch (hit->Detector()) {
ef8e8623 496 case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
497 case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
498 case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
a9579262 499 }
500 return kTRUE;
501}
502
503
504//____________________________________________________________________
505void
f95a63c4 506AliFMDPattern::AddMarker(UShort_t det, Char_t rng,
507 UShort_t sec, UShort_t str,
cf291b42 508 TObject*, Float_t s, Float_t /*min*/, Float_t max)
a9579262 509{
510 // Add a marker to the display
511 //
512 // det Detector
513 // rng Ring
514 // sec Sector
515 // str Strip
516 // o Object to refer to
517 // s Signal
518 // max Maximum of signal
519 //
f95a63c4 520 AliFMDPatternDetector* d = 0;
a9579262 521 switch (det) {
522 case 1: d = &fFMD1; break;
523 case 2: d = &fFMD2; break;
524 case 3: d = &fFMD3; break;
525 }
526 if (!d) return;
527 AliFMDGeometry* geom = AliFMDGeometry::Instance();
528 Double_t x, y, z;
529 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
f95a63c4 530 // Make code-checker shut the f**k up
531 TRandom* rand = gRandom;
f38b1653 532 if (false) {
a9579262 533 AliFMDRing* r = geom->GetRing(rng);
534 Double_t t = .9 * r->GetTheta() / 2;
f95a63c4 535 Double_t a = rand->Uniform(-t,t) * TMath::Pi() / 180;
a9579262 536 Double_t x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
537 Double_t y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
538 x = x1;
539 y = y1;
540 }
541 d->AddMarker(x, y, s, max);
542}
543
544//____________________________________________________________________
545//
546// EOF
547//