]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDPattern.cxx
Simple scripts to run various steps.
[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),
68 fFrame(0)
f95a63c4 69{
70 // CTOR
71 //
72 // Parameters:
73 //
74 // ID Identifier
75}
a9579262 76
77//____________________________________________________________________
f95a63c4 78AliFMDPattern::AliFMDPatternDetector::~AliFMDPatternDetector()
a9579262 79{
f95a63c4 80 // DTOR
81 // Destructor -
82 // deletes mother frame
a9579262 83 if (fFrame) delete fFrame;
84}
85
86//____________________________________________________________________
87void
f95a63c4 88AliFMDPattern::AliFMDPatternDetector::DrawShape(TObjArray& a)
a9579262 89{
f95a63c4 90 // Draw all shapes.
91 //
92 // Paramters
93 //
94 // a Array of shapes
95 //
a9579262 96 TIter next(&a);
97 TGraph* g = 0;
98 while ((g = static_cast<TGraph*>(next()))) {
99 g->DrawClone("f same");
100 g->DrawClone("l same");
101 }
102}
103
104//____________________________________________________________________
105void
cf291b42 106AliFMDPattern::AliFMDPatternDetector::Begin(Int_t nlevel,
107 Double_t r,
108 TObjArray& inners,
109 TObjArray& outers)
a9579262 110{
f95a63c4 111 // Start of a run.
112 //
113 // Parameters
114 //
115 // nlevel Number of levels
116 // r Radius
117 // inners Array of inner shapes
118 // outers Array of outer shapes
119 //
120
121 // To make code-checker shut up
122 TStyle* style = gStyle;
123 if (nlevel < 1) nlevel = style->GetNumberOfColors();
a9579262 124 fCounts.Set(nlevel);
125 if (!fFrame) {
f95a63c4 126 // The code-checker thinks this is not using the declaration of
127 // TH2F - what a morron!
a9579262 128 fFrame = new TH2F(Form("fmd%dFrame", fId), Form("FMD%d", fId),
129 10, -r, r, 10, -r, r);
130 fFrame->SetStats(kFALSE);
131 fFrame->Draw();
132 }
133 DrawShape(inners);
134 if (fId != 1) DrawShape(outers);
135 for (Int_t i = 0; i < nlevel; i++) {
136 TGraph* g = new TGraph;
f95a63c4 137 Int_t idx = Int_t(Float_t(i) / nlevel * style->GetNumberOfColors());
138 Int_t col = style->GetColorPalette(idx);
a9579262 139 g->SetName(Form("FMD%d_L%02d", fId, i));
140 g->SetMarkerColor(col);
141 g->SetLineColor(col);
142 g->SetFillColor(col);
143 g->SetMarkerSize(i * .2 + .2);
144 g->SetMarkerStyle(2);
145 g->Draw("same p");
146 fGraphs.AddAtAndExpand(g, i);
147 }
cf291b42 148 // TIter next(&fGraphs);
a9579262 149}
150
151//____________________________________________________________________
152void
f95a63c4 153AliFMDPattern::AliFMDPatternDetector::Clear()
a9579262 154{
f95a63c4 155 // Clear this display.
156 // Simply reset counters to zero.
157 // Avoid deleting memory.
a9579262 158 fCounts.Reset(0);
159}
160
161//____________________________________________________________________
162void
f95a63c4 163AliFMDPattern::AliFMDPatternDetector::End()
a9579262 164{
f95a63c4 165 // Called when displaying the data.
166 // Simply resets number of points at each level to
167 // the seen number of hits at that level.
168 // Avoid deleting memory.
a9579262 169 TIter next(&fGraphs);
170 TGraph* g = 0;
171 Int_t i = 0;
172 while ((g = static_cast<TGraph*>(next()))) g->Set(fCounts[i++]);
173}
174//____________________________________________________________________
175void
cf291b42 176AliFMDPattern::AliFMDPatternDetector::AddMarker(Double_t x,
177 Double_t y,
178 Float_t s,
179 Float_t max)
a9579262 180{
f95a63c4 181 // Add a marker at (X,Y,Z). The marker color and size is chosen
182 // relative to the MAX argument.
183 //
184 // Parameters
185 //
186 // X,Y,Z Coordiantes
187 // MAX Maximum value.
188 //
189 /** Sigh, for some odd reason, the code-checker does not recognise
190 this a usage of the TMath namespace declaration! Idiot */
191 Int_t i = TMath::Min(Int_t(fCounts.fN * s / max),
a9579262 192 Int_t(fGraphs.GetEntries()-1));
193 TGraph* g = static_cast<TGraph*>(fGraphs.At(i));
194 if (!g) return;
195 g->SetPoint(fCounts[i]++, x, y);
196}
197
198
199//____________________________________________________________________
200AliFMDPattern::AliFMDPattern(const char* gAliceFile)
201 : AliFMDDisplay(kTRUE, gAliceFile),
17e542eb 202 fInners(0),
203 fOuters(0),
a9579262 204 fInnerMax(0),
205 fOuterMax(0),
206 fFMD1Pad(0),
207 fFMD1(1),
208 fFMD2Pad(0),
209 fFMD2(2),
210 fFMD3Pad(0),
211 fFMD3(3),
17e542eb 212 fSummary(0),
a9579262 213 fEvent(.1, .8, "Event #"),
214 fFMD1Sum(.2, .7, "# in FMD1: "),
215 fFMD2Sum(.2, .6, "# in FMD2: "),
216 fFMD3Sum(.2, .5, "# in FMD3: "),
217 fLine(.15, .47, .85, .47),
218 fTotal(.2, .35, "Total: ")
219{
f95a63c4 220 // Constructor.
221 //
222 // Parameters
223 //
224 // gAliceFile The galice.root file to use - if any.
225 //
226
42f1b2f5 227 SetName("AliFMDPattern");
228 SetName("2D display of FMD data");
229
a9579262 230 // RemoveLoad(kGeometry);
231 fEvent.SetBit(TLatex::kTextNDC);
232 fFMD1Sum.SetBit(TLatex::kTextNDC);
233 fFMD2Sum.SetBit(TLatex::kTextNDC);
234 fFMD3Sum.SetBit(TLatex::kTextNDC);
235 fLine.SetBit(TLine::kLineNDC);
236 fTotal.SetBit(TLatex::kTextNDC);
237}
238
239//____________________________________________________________________
240AliFMDPattern::~AliFMDPattern()
241{
f95a63c4 242 // DTOR
243 // Free all allocated shapes.
244 // note, that most members are real objects, so we do not need to
245 // deal with them here.
a9579262 246 fInners.Delete();
247 fOuters.Delete();
248}
249
250
251//____________________________________________________________________
252Bool_t
253AliFMDPattern::Init()
254{
f95a63c4 255 // Initialize. Get transforms and such,
a9579262 256 if (!AliFMDInput::Init()) return kFALSE;
257 AliFMDGeometry* geom = AliFMDGeometry::Instance();
69893a66 258 if (!geom) return kFALSE;
a9579262 259 geom->Init();
260 geom->InitTransformations();
261
262 Char_t rs[] = { 'I' , 'O', '\0' };
263 Char_t *r = rs;
264 do {
265 AliFMDRing* ring = geom->GetRing(*r);
266 if (!ring) continue;
267 const TObjArray& vs = ring->GetVerticies();
268 TObjArray& gs = (*r == 'I' ? fInners : fOuters);
269 Float_t& mr = (*r == 'I' ? fInnerMax : fOuterMax);
270 Int_t nm = ring->GetNModules();
271 AliInfo(Form("Making %d modules for %c", nm, *r));
272 for (Int_t m = 0; m < nm; m++) {
273 Int_t nv = vs.GetEntries();
274 Double_t a = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
275 TGraph* g = new TGraph(nv+1);
276 Double_t x0 = 0, y0 = 0;
277 gs.AddAtAndExpand(g, m);
278 for (Int_t c = 0; c < nv; c++) {
279 TVector2* v = static_cast<TVector2*>(vs.At(c));
280 mr = TMath::Max(mr, Float_t(v->Mod()));
281 TVector2 w(v->Rotate(a));
282 if (c == 0) { x0 = w.X(); y0 = w.Y(); }
283 g->SetPoint(c, w.X(), w.Y());
284 }
285 g->SetName(Form("FMDX%c_%02d", *r, m));
286 g->SetPoint(nv, x0, y0);
287 g->SetFillColor((*rs == 'I' ?
288 (m % 2 == 0 ? 18 : 17) :
289 (m % 2 == 0 ? 20 : 23)));
290 g->SetFillStyle(3001);
291 g->SetLineColor(1);
292 g->SetLineWidth(1);
293 g->SetLineStyle(2);
294 }
295 } while (*(++r));
296
297 return kTRUE;
298}
299
300//____________________________________________________________________
301Bool_t
302AliFMDPattern::Begin(Int_t event)
303{
f95a63c4 304 // Called at the begining of an event.
305 //
306 // Parameters
307 //
308 // EVENT The event number
309 //
97b4001e 310 MakeAux();
a9579262 311 if (!fCanvas) {
312 const char* which[] = { "Continue", "Redisplay", 0 };
313 MakeCanvas(which);
a9579262 314
315 AliFMDGeometry* geom = AliFMDGeometry::Instance();
f95a63c4 316 // AliFMDDetector* det;
317 if ((/* det = */ geom->GetDetector(1))) {
a9579262 318 fPad->cd();
319 fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
320 fFMD1Pad->Draw();
321 fFMD1Pad->cd();
97b4001e 322 fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
a9579262 323 }
f95a63c4 324 if ((/* det = */ geom->GetDetector(2))) {
a9579262 325 fPad->cd();
326 fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
327 fFMD2Pad->Draw();
328 fFMD2Pad->cd();
97b4001e 329 fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
a9579262 330 }
f95a63c4 331 if ((/* det = */ geom->GetDetector(3))) {
a9579262 332 fPad->cd();
333 fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
334 fFMD3Pad->Draw();
335 fFMD3Pad->cd();
97b4001e 336 fFMD3.Begin(-1, fOuterMax, fInners, fOuters);
a9579262 337 }
338 fPad->cd();
339 fSummary = new TPad("display", "Display", 0.5, 0.0, 1.0, 0.5, 0, 0);
340 fSummary->Draw();
341 fSummary->cd();
342 fEvent.Draw();
343 fFMD1Sum.Draw();
344 fFMD2Sum.Draw();
345 fFMD3Sum.Draw();
346 fLine.Draw();
347 fTotal.Draw();
348 }
349 fEvent.SetTitle(Form("Event # %6d", event));
350
351 fCanvas->Modified();
352 fCanvas->Update();
353 fCanvas->cd();
354 fFMD1.Clear();
355 fFMD2.Clear();
356 fFMD3.Clear();
357 return AliFMDInput::Begin(event);
358}
359
360//____________________________________________________________________
361void
362AliFMDPattern::Redisplay()
363{
f95a63c4 364 // Redraw the displayu
a9579262 365 fFMD1.Clear();
366 fFMD2.Clear();
367 fFMD3.Clear();
368 AliFMDDisplay::Redisplay();
369}
370
371//____________________________________________________________________
372void
373AliFMDPattern::AtEnd()
374{
f95a63c4 375 // Called at the end of an event.
a9579262 376 DrawAux();
377
378 Int_t total = 0;
379
380 fFMD1.End();
381 fFMD1Pad->Modified();
382 fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d", fFMD1.Total()));
383 total += fFMD1.Total();
384
385 fFMD2.End();
386 fFMD2Pad->Modified();
387 fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d", fFMD2.Total()));
388 total += fFMD2.Total();
389
390 fFMD3.End();
391 fFMD3Pad->Modified();
392 fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d", fFMD3.Total()));
393 total += fFMD3.Total();
394
395 fTotal.SetTitle(Form("Total: %5d/51200 (%3d%%)",
396 total, Int_t(100. / 51200 * total)));
397 fSummary->Modified();
398 fCanvas->Modified();
399 fCanvas->Update();
400 fCanvas->cd();
401}
402
403//____________________________________________________________________
404Bool_t
405AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*)
406{
f95a63c4 407 // Process a hit.
408 //
409 // Parameters
410 //
411 // HIT The hit to process.
412 //
413 // The TParticle argument is never used.
ef8e8623 414 static const Float_t rMin = fgkEdepRange.fLow;
415 static const Float_t rMax = fgkEdepRange.fHigh;
416
417 if (!hit) { AliError("No hit"); return kFALSE; }
418 // if (!p) { AliError("No track"); return kFALSE; }
419 Float_t edep = hit->Edep();
420
421 if (fHits) fHits->Add(hit);
422 if (fSpec) fSpec->Fill(edep);
423 if (InsideCut(edep, rMin, rMax) && fSpecCut) fSpecCut->Fill(edep);
424
a9579262 425 switch (hit->Detector()) {
ef8e8623 426 case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
427 case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
428 case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
a9579262 429 }
430 return kTRUE;
431}
432
433
434//____________________________________________________________________
435void
f95a63c4 436AliFMDPattern::AddMarker(UShort_t det, Char_t rng,
437 UShort_t sec, UShort_t str,
cf291b42 438 TObject*, Float_t s, Float_t /*min*/, Float_t max)
a9579262 439{
440 // Add a marker to the display
441 //
442 // det Detector
443 // rng Ring
444 // sec Sector
445 // str Strip
446 // o Object to refer to
447 // s Signal
448 // max Maximum of signal
449 //
f95a63c4 450 AliFMDPatternDetector* d = 0;
a9579262 451 switch (det) {
452 case 1: d = &fFMD1; break;
453 case 2: d = &fFMD2; break;
454 case 3: d = &fFMD3; break;
455 }
456 if (!d) return;
457 AliFMDGeometry* geom = AliFMDGeometry::Instance();
458 Double_t x, y, z;
459 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
f95a63c4 460 // Make code-checker shut the f**k up
461 TRandom* rand = gRandom;
a9579262 462 if (true) {
463 AliFMDRing* r = geom->GetRing(rng);
464 Double_t t = .9 * r->GetTheta() / 2;
f95a63c4 465 Double_t a = rand->Uniform(-t,t) * TMath::Pi() / 180;
a9579262 466 Double_t x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
467 Double_t y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
468 x = x1;
469 y = y1;
470 }
471 d->AddMarker(x, y, s, max);
472}
473
474//____________________________________________________________________
475//
476// EOF
477//