Overlaps corrected, new shape of sectors
[u/mrichter/AliRoot.git] / FMD / FMDutil / AliFMDFancy.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 AliFMDFancy.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
32#include <iomanip>
33#include <iostream>
34
a9579262 35#include <TApplication.h>
f95a63c4 36// #include <TButton.h>
a9579262 37#include <TCanvas.h>
a9579262 38#include <TH2F.h>
f95a63c4 39// #include <TH3F.h>
9edefa04 40#include <TLatex.h>
41#include <TLine.h>
42#include <TMath.h>
43#include <TRandom.h>
f95a63c4 44// #include <TStyle.h>
a9579262 45#include <TSystem.h>
46#include <TVector2.h>
f95a63c4 47// #include <TView.h>
9edefa04 48
a9579262 49#include "AliFMDDetector.h"
9edefa04 50#include "AliFMDFancy.h" // ALIFMDDISPLAY_H
51#include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
a9579262 52#include "AliFMDHit.h"
f95a63c4 53// #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
9edefa04 54#include "AliFMDRing.h"
a9579262 55
56//____________________________________________________________________
57ClassImp(AliFMDFancy)
58#if 0
59 ; // This is here to keep Emacs for indenting the next line
60#endif
61
62//____________________________________________________________________
63AliFMDFancy::AliFMDFancy(const char* gAliceFile)
64 : AliFMDDisplay(kTRUE, gAliceFile),
65 fFMD1Pad(0),
66 fFMD1(1),
67 fFMD2Pad(0),
68 fFMD2(2),
69 fFMD3Pad(0),
70 fFMD3(3),
17e542eb 71 fSummary(0),
a9579262 72 fEvent(.1, .8, "Event #"),
73 fFMD1IHits(.2, .7, "# in FMD1I: "),
74 fFMD2IHits(.2, .6, "# in FMD2I: "),
75 fFMD2OHits(.2, .5, "# in FMD2O: "),
76 fFMD3IHits(.2, .4, "# in FMD3I: "),
77 fFMD3OHits(.2, .3, "# in FMD3O: "),
78 fLine(.15, .27, .85, .27),
79 fTotal(.2, .15, "Total: ")
80{
f95a63c4 81 // CTOR
a9579262 82 fEvent.SetBit(TLatex::kTextNDC);
83 fFMD1IHits.SetBit(TLatex::kTextNDC);
84 fFMD2IHits.SetBit(TLatex::kTextNDC);
85 fFMD2OHits.SetBit(TLatex::kTextNDC);
86 fFMD3IHits.SetBit(TLatex::kTextNDC);
87 fFMD3OHits.SetBit(TLatex::kTextNDC);
88 fLine.SetBit(TLine::kLineNDC);
89 fTotal.SetBit(TLatex::kTextNDC);
90}
91
92//____________________________________________________________________
f95a63c4 93AliFMDFancy::AliFancyDetector::AliFancyDetector(UShort_t id)
17e542eb 94 : fFrame(0),
95 fId(id),
96 fShapes(0),
97 fNInnerHits(0),
98 fInnerHits(0),
99 fNOuterHits(0),
100 fOuterHits(0),
101 fMaxR(0),
102 fMinZ(0),
103 fMaxZ(0)
a9579262 104{
f95a63c4 105 // CTOR
a9579262 106 fInnerHits.SetName(Form("FMD%dI", id));
107 fInnerHits.SetMarkerStyle(1); // 20);
108 fInnerHits.SetMarkerSize(.2);
109 fInnerHits.SetMarkerColor(50); // 12);
110 fOuterHits.SetName(Form("FMD%dO", id));
111 fOuterHits.SetMarkerStyle(1); // 20);
112 fOuterHits.SetMarkerSize(.2);
113 fOuterHits.SetMarkerColor(50); // 12);
114}
115
116//____________________________________________________________________
f95a63c4 117AliFMDFancy::AliFancyDetector::~AliFancyDetector()
a9579262 118{
f95a63c4 119 // DTOR
a9579262 120 fShapes.Delete();
121 if (fFrame) delete fFrame;
122}
123
124//____________________________________________________________________
125AliFMDFancy::~AliFMDFancy()
f95a63c4 126{
127 // DTOR
128}
a9579262 129
130//____________________________________________________________________
131void
f95a63c4 132AliFMDFancy::AliFancyDetector::AddHistogram(TGraph2D& g, const char* opt)
a9579262 133{
f95a63c4 134 // CTOR
a9579262 135 TH2* h = g.GetHistogram(opt);
136 if (!h) return;
f95a63c4 137 // Code checker doesn't think this using the TH2 interface -
138 // ridiculous.
a9579262 139 h->SetBins(1, -fMaxR, fMaxR, 1, -fMaxR, fMaxR);
140 h->GetZaxis()->SetRangeUser(fMinZ, fMaxZ);
141}
142
143
144
145//____________________________________________________________________
146void
f95a63c4 147AliFMDFancy::AliFancyDetector::Init()
a9579262 148{
f95a63c4 149 // Initialise
a9579262 150 AliFMDGeometry* geom = AliFMDGeometry::Instance();
151 AliFMDDetector* det = geom->GetDetector(fId);
152 if (!det) return;
153 Char_t rs[] = { 'I' , 'O', '\0' };
154 Char_t* rp = rs;
155 Char_t r;
156 Double_t maxR = 0;
157 Double_t minZ = 10000;
158 Double_t maxZ = -10000;
159 Int_t ns = 0;
160 while ((r = *(rp++))) {
161 AliFMDRing* ring = det->GetRing(r);
162 if (!ring) continue;
163 // if (r == 'O') continue;
164 const TObjArray& vs = ring->GetVerticies();
165 Int_t nm = ring->GetNModules();
166 Double_t zd = (r == 'I' ? det->GetInnerZ() : det->GetOuterZ());
167 for (Int_t m = 0; m < nm; m++) {
168 Int_t nv = vs.GetEntries();
169 Double_t a = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
170 TGraph2D* g = new TGraph2D(nv);
ab5a8e9c 171 // Double_t x0 = 0, y0 = 0, z0 = 0;
a9579262 172 Double_t z = zd + (m % 2==0 ? 0 :
173 TMath::Sign(ring->GetModuleSpacing(), zd));
174 minZ = TMath::Min(minZ, z);
175 maxZ = TMath::Max(maxZ, z);
176 g->SetName(Form("FMD%d%cM%02d", fId, r, m));
177 fShapes.AddAtAndExpand(g, ns++);
178 for (Int_t c = 0; c < nv; c++) {
179 TVector2* v = static_cast<TVector2*>(vs.At(nv - 1 - c));
180 TVector2 w(v->Rotate(a));
ab5a8e9c 181 // if (c == 0) { x0 = w.X(); y0 = w.Y(); z0 = z; }
a9579262 182 g->SetPoint(c, w.X(), w.Y(), z);
183 maxR = TMath::Max(maxR, v->Mod());
184 }
185 //g->SetPoint(nv, x0, y0, z0);
186 g->SetFillColor(2);
187 g->SetFillStyle(3002);
188 g->SetLineColor(2);
189 g->SetLineWidth(1);
190 }
191 }
192 fMaxR = 1.05 * maxR;
193 fMinZ = (minZ > 0 ? 0.95 * minZ : 1.05 * minZ);
194 fMaxZ = (maxZ > 0 ? 1.05 * maxZ : 0.95 * maxZ);
195
196 TIter next(&fShapes);
197 TGraph2D* g = 0;
198 while ((g = static_cast<TGraph2D*>(next()))) AddHistogram(*g);
199 if (det->GetInner()) AddHistogram(fInnerHits);
200 if (det->GetOuter()) AddHistogram(fOuterHits);
201
202 fFrame = new TH2F(Form("FMD%d", fId), Form("FMD%d", fId),
203 1, -fMaxR, fMaxR, 1, -fMaxR, fMaxR);
204 fFrame->SetStats(kFALSE);
205 fFrame->GetXaxis()->SetTitle("x [cm]");
206 fFrame->GetYaxis()->SetTitle("y [cm]");
207 fFrame->GetZaxis()->SetTitle("z [cm]");
208 fFrame->SetDirectory(0);
209}
210
211
212//____________________________________________________________________
213Bool_t
214AliFMDFancy::Init()
215{
216 // Initialize. GEt transforms and such,
217 if (!AliFMDInput::Init()) return kFALSE;
218 AliFMDGeometry* geom = AliFMDGeometry::Instance();
219 geom->Init();
220 geom->InitTransformations();
221
222 fFMD1.Init();
223 fFMD2.Init();
224 fFMD3.Init();
225 return kTRUE;
226}
227
228//____________________________________________________________________
229void
f95a63c4 230AliFMDFancy::AliFancyDetector::Begin(Int_t /* event */)
a9579262 231{
f95a63c4 232 // Called at the begining of an event.
a9579262 233 TIter next(&fShapes);
234 TGraph2D* g = 0;
235 fFrame->Draw("surf fb");
236 fFrame->GetZaxis()->SetRangeUser(fMinZ, fMaxZ);
237 while ((g = static_cast<TGraph2D*>(next()))) g->Draw("tri2 FB same");
238}
239
240//____________________________________________________________________
241void
f95a63c4 242AliFMDFancy::AliFancyDetector::Clear(Int_t /* event */)
a9579262 243{
f95a63c4 244 // Clear
a9579262 245 fNInnerHits = 0;
246 fNOuterHits = 0;
247}
248
249
250//____________________________________________________________________
251Bool_t
252AliFMDFancy::Begin(Int_t event)
253{
f95a63c4 254 // Called at the begining of an event
a9579262 255 if (!fCanvas) {
256 const char* which[] = { "Continue", "Redisplay", 0 };
257 MakeCanvas(which);
258
259 AliFMDGeometry* geom = AliFMDGeometry::Instance();
133f1578 260 // AliFMDDetector* det;
261 if ((/*det =*/ geom->GetDetector(1))) {
a9579262 262 fPad->cd();
263 fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
264 fFMD1Pad->Draw();
265 fFMD1Pad->cd();
266 fFMD1.Begin(event);
267 }
133f1578 268 if ((/*det =*/ geom->GetDetector(2))) {
a9579262 269 fPad->cd();
270 fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
271 fFMD2Pad->Draw();
272 fFMD2Pad->cd();
273 fFMD2.Begin(event);
274 }
133f1578 275 if ((/*det =*/ geom->GetDetector(3))) {
a9579262 276 fPad->cd();
277 fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.05, .5, .5, 0, 0);
278 fFMD3Pad->Draw();
279 fFMD3Pad->cd();
280 fFMD3.Begin(event);
281 }
282 fPad->cd();
283 fSummary = new TPad("display", "Display", 0.5, 0.05, 1.0, 0.5, 0, 0);
284 fSummary->Draw();
285 fSummary->cd();
286 fEvent.Draw();
287 fFMD1IHits.Draw();
288 fFMD2IHits.Draw();
289 fFMD2OHits.Draw();
290 fFMD3IHits.Draw();
291 fFMD3OHits.Draw();
292 fLine.Draw();
293 fTotal.Draw();
294 }
295 fEvent.SetTitle(Form("Event # %6d", event));
296 // fEvent.Modify();
297 fCanvas->Modified();
298 fCanvas->Update();
299 fCanvas->cd();
300 fFMD1.Clear(event);
301 fFMD2.Clear(event);
302 fFMD3.Clear(event);
303 return AliFMDInput::Begin(event);
304}
305
306//____________________________________________________________________
307void
f95a63c4 308AliFMDFancy::AliFancyDetector::End()
a9579262 309{
f95a63c4 310 // Called at the end of an event
a9579262 311 Char_t rs[] = { 'I', 'O', '\0' };
312 Char_t* rp = rs;
313 Char_t r;
314 while ((r = *(rp++))) {
315 TGraph2D& g = (r == 'I' ? fInnerHits : fOuterHits);
316 Int_t& n = (r == 'I' ? fNInnerHits : fNOuterHits);
317 Int_t m = (r == 'I' ? 512 * 10 * 2 : 256 * 20 * 2);
318 if (n == 0) continue;
319 for (Int_t i = n; i < g.GetN(); i++) g.RemovePoint(i);
f95a63c4 320 // The code checker thinks this is not using declarations from
321 // iostram and iomanip - that's just silly.
a9579262 322 std::cout << g.GetName() << " has " << std::setw(4) << n << "/"
323 << std::setw(5) << m << " points" << std::endl;
324 g.Draw("same fb p");
325 AddHistogram(g, "empty");
326 }
327}
328
329//____________________________________________________________________
330Bool_t
331AliFMDFancy::End()
332{
f95a63c4 333 // Called at the end of an event
a9579262 334 AliFMDGeometry* geom = AliFMDGeometry::Instance();
133f1578 335 // AliFMDDetector* det;
a9579262 336 Int_t total = 0;
133f1578 337 if ((/*det =*/ geom->GetDetector(1))) {
a9579262 338 fFMD1Pad->cd();
339 fFMD1.End();
340 fFMD1Pad->Modified();
09b6c804 341 fFMD1IHits.SetTitle(Form("# hits in FMD1I: %5d", fFMD1.GetNInnerHits()));
342 total += fFMD1.GetNInnerHits();
a9579262 343 }
133f1578 344 if ((/*det =*/ geom->GetDetector(2))) {
a9579262 345 fFMD2Pad->cd();
346 fFMD2.End();
347 fFMD2Pad->Modified();
09b6c804 348 fFMD2IHits.SetTitle(Form("# hits in FMD2I: %5d", fFMD2.GetNInnerHits()));
349 fFMD2OHits.SetTitle(Form("# hits in FMD2O: %5d", fFMD2.GetNOuterHits()));
350 total += fFMD2.GetNInnerHits();
351 total += fFMD2.GetNOuterHits();
a9579262 352 }
133f1578 353 if ((/*det =*/ geom->GetDetector(3))) {
a9579262 354 fFMD3Pad->cd();
355 fFMD3.End();
356 fFMD3Pad->Modified();
09b6c804 357 fFMD3IHits.SetTitle(Form("# hits in FMD3I: %5d", fFMD3.GetNInnerHits()));
358 fFMD3OHits.SetTitle(Form("# hits in FMD3O: %5d", fFMD3.GetNOuterHits()));
359 total += fFMD3.GetNInnerHits();
360 total += fFMD3.GetNOuterHits();
a9579262 361 }
362 fTotal.SetTitle(Form("Total: %5d/51200 (%3d%%)",
363 total, Int_t(100. / 51200 * total)));
364 fSummary->Modified();
365 fCanvas->Modified();
366 fCanvas->Update();
367 fCanvas->cd();
368 fWait = kTRUE;
369 while (fWait) {
f95a63c4 370 // Hmm - code checker doesn't believe this is using the
371 // TApplication or TSystem declaration - morron. Thank God for
372 // optimising compilers.
373 TApplication* a = gApplication;
374 TSystem* s = gSystem;
375 a->StartIdleing();
376 s->InnerLoop();
377 a->StopIdleing();
a9579262 378 }
379 return AliFMDInput::End();
380}
381
382//____________________________________________________________________
383Bool_t
384AliFMDFancy::ProcessHit(AliFMDHit* hit, TParticle*)
385{
f95a63c4 386 // Process a hit.
a9579262 387 AddMarker(hit->Detector(), hit->Ring(), hit->Sector(), hit->Strip(),
d98fbfa5 388 hit, hit->Edep(), 0, 20);
a9579262 389 return kTRUE;
390}
391//____________________________________________________________________
392void
f95a63c4 393AliFMDFancy::AliFancyDetector::AddMarker(Char_t rng, UShort_t sec,
394 UShort_t str, Float_t, Float_t)
a9579262 395{
f95a63c4 396 // Add a marker to the display
a9579262 397 AliFMDGeometry* geom = AliFMDGeometry::Instance();
398 Double_t x, y, z;
399 geom->Detector2XYZ(fId, rng, sec, str, x, y, z);
f95a63c4 400 // Trick the code-checker to think that we're using the TRandom
401 // interface. The silly code checker also thinks that TMath is a
402 // class and not a namespace - sigh!
403 TRandom* rand = gRandom;
a9579262 404 if (true) {
405 AliFMDRing* r = geom->GetRing(rng);
406 Double_t t = .9 * r->GetTheta() / 2;
f95a63c4 407 Double_t a = rand->Uniform(-t,t) * TMath::Pi() / 180;
a9579262 408 Double_t x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
409 Double_t y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
410 x = x1;
411 y = y1;
412 }
413 switch (rng) {
414 case 'I':
415 case 'i': fInnerHits.SetPoint(fNInnerHits++, x, y, z); break;
416 case 'O':
417 case 'o': fOuterHits.SetPoint(fNOuterHits++, x, y, z); break;
418 default: return;
419 }
420}
421
422
423
424//____________________________________________________________________
425void
426AliFMDFancy::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
d98fbfa5 427 TObject*, Float_t, Float_t, Float_t)
a9579262 428{
429 // Add a marker to the display
430 //
431 // det Detector
432 // rng Ring
433 // sec Sector
434 // str Strip
435 // o Object to refer to
436 // s Signal
437 // max Maximum of signal
438 //
439 switch (det) {
440 case 1: fFMD1.AddMarker(rng,sec,str,0,0); break;
441 case 2: fFMD2.AddMarker(rng,sec,str,0,0); break;
442 case 3: fFMD3.AddMarker(rng,sec,str,0,0); break;
443 }
444}
445
446//____________________________________________________________________
447//
448// EOF
449//