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 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
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 <iostream>
34 // #include <TApplication.h>
35 // #include <TButton.h>
41 // #include <TSlider.h>
43 // #include <TSystem.h>
47 #include "AliFMDPattern.h" // ALIFMDDISPLAY_H
48 #include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
49 //#include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
50 #include "AliFMDRing.h"
51 // #include "AliFMDDetector.h"
52 #include "AliFMDHit.h"
53 // #include <AliLog.h>
54 #include "AliFMDDebug.h" // Better debug macros
57 //____________________________________________________________________
58 ClassImp(AliFMDPattern)
60 ; // This is here to keep Emacs for indenting the next line
63 //____________________________________________________________________
64 AliFMDPattern::AliFMDPatternDetector::AliFMDPatternDetector(UShort_t id)
70 fOuters(id == 1 ? 0 : 20)
79 //____________________________________________________________________
80 AliFMDPattern::AliFMDPatternDetector::~AliFMDPatternDetector()
84 // deletes mother frame
85 if (fFrame) delete fFrame;
88 //____________________________________________________________________
90 AliFMDPattern::AliFMDPatternDetector::DrawShape(TObjArray& a)
100 while ((g = static_cast<TGraph*>(next()))) {
101 g->DrawClone("f same");
102 g->DrawClone("l same");
106 //____________________________________________________________________
108 AliFMDPattern::AliFMDPatternDetector::CopyShapes(TObjArray& src,
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);
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());
144 //____________________________________________________________________
146 AliFMDPattern::AliFMDPatternDetector::Begin(Int_t nlevel,
155 // nlevel Number of levels
157 // inners Array of inner shapes
158 // outers Array of outer shapes
161 // To make code-checker shut up
162 TStyle* style = gStyle;
163 if (nlevel < 1) nlevel = style->GetNumberOfColors();
165 Double_t rr = 1.05 * r;
167 // The code-checker thinks this is not using the declaration of
168 // TH2F - what a morron!
169 fFrame = new TH2F(Form("fmd%dFrame", fId), Form("FMD%d", fId),
170 100, -rr, rr, 100, -rr, rr);
171 fFrame->SetStats(kFALSE);
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
178 CopyShapes(inners, fInners, ang, fx, fy);
181 CopyShapes(outers, fOuters, ang, fx, fy);
185 for (Int_t i = 0; i < nlevel; i++) {
186 TGraph* g = new TGraph;
187 Int_t idx = Int_t(Float_t(i) / nlevel * style->GetNumberOfColors());
188 Int_t col = style->GetColorPalette(idx);
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);
195 g->SetEditable(kFALSE);
197 fGraphs.AddAtAndExpand(g, i);
199 // TIter next(&fGraphs);
202 //____________________________________________________________________
204 AliFMDPattern::AliFMDPatternDetector::Clear()
206 // Clear this display.
207 // Simply reset counters to zero.
208 // Avoid deleting memory.
212 //____________________________________________________________________
214 AliFMDPattern::AliFMDPatternDetector::End()
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.
220 TIter next(&fGraphs);
223 while ((g = static_cast<TGraph*>(next()))) {
224 Int_t cnt = fCounts[i++];
227 g->SetMarkerSize(i * .2 + .2);
236 //____________________________________________________________________
238 AliFMDPattern::AliFMDPatternDetector::AddMarker(Double_t x,
243 // Add a marker at (X,Y,Z). The marker color and size is chosen
244 // relative to the MAX argument.
249 // MAX Maximum value.
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),
254 Int_t(fGraphs.GetEntries()-1));
255 TGraph* g = static_cast<TGraph*>(fGraphs.At(i));
257 g->SetPoint(fCounts[i]++, x, y);
261 //____________________________________________________________________
262 AliFMDPattern::AliFMDPattern(const char* gAliceFile)
263 : AliFMDDisplay(kTRUE, gAliceFile),
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: ")
286 // gAliceFile The galice.root file to use - if any.
289 SetName("AliFMDPattern");
290 SetName("2D display of FMD data");
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);
301 //____________________________________________________________________
302 AliFMDPattern::~AliFMDPattern()
305 // Free all allocated shapes.
306 // note, that most members are real objects, so we do not need to
307 // deal with them here.
313 //____________________________________________________________________
315 AliFMDPattern::Init()
317 // Initialize. Get transforms and such,
318 if (!AliFMDInput::Init()) return kFALSE;
319 AliFMDGeometry* geom = AliFMDGeometry::Instance();
320 if (!geom) return kFALSE;
322 geom->InitTransformations();
324 Char_t rs[] = { 'I' , 'O', '\0' };
327 AliFMDRing* ring = geom->GetRing(*r);
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();
333 AliFMDDebug(1, ("Making %d modules for %c", nm, *r));
334 for (Int_t m = 0; m < nm; m++) {
335 Int_t nv = vs.GetEntries();
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);
340 for (Int_t c = 0; c < nv; c++) {
341 TVector2* v = static_cast<TVector2*>(vs.At(c));
342 mr = TMath::Max(mr, Float_t(v->Mod()));
343 TVector2 w(v->Rotate(a));
344 if (c == 0) { x0 = w.X(); y0 = w.Y(); }
345 g->SetPoint(c, w.X(), w.Y());
347 g->SetName(Form("FMDX%c_%02d%02d", *r, 2*m,2*m+1));
348 g->SetTitle(Form("FMDX%c, sectors %d and %d", *r, 2*m,2*m+1));
349 g->SetPoint(nv, x0, y0);
350 g->SetFillColor((*rs == 'I' ?
351 (m % 2 == 0 ? 18 : 17) :
352 (m % 2 == 0 ? 20 : 23)));
353 g->SetFillStyle(3001);
363 //____________________________________________________________________
365 AliFMDPattern::Begin(Int_t event)
367 // Called at the begining of an event.
371 // EVENT The event number
375 const char* which[] = { "Continue", "Start", "Pause", "Redisplay", 0 };
378 AliFMDGeometry* geom = AliFMDGeometry::Instance();
379 // AliFMDDetector* det;
380 if ((/* det = */ geom->GetDetector(1))) {
382 fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
385 fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
387 if ((/* det = */ geom->GetDetector(2))) {
389 fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
392 fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
394 if ((/* det = */ geom->GetDetector(3))) {
396 fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
399 fFMD3.Begin(-1, fOuterMax, fInners, fOuters);
402 fSummary = new TPad("display", "Display", 0.5, 0.0, 1.0, 0.5, 0, 0);
412 fEvent.SetTitle(Form("Event # %6d", event));
420 return AliFMDInput::Begin(event);
423 //____________________________________________________________________
425 AliFMDPattern::Redisplay()
427 // Redraw the displayu
431 AliFMDDisplay::Redisplay();
434 //____________________________________________________________________
436 AliFMDPattern::AtEnd()
438 // Called at the end of an event.
444 fFMD1Pad->Modified();
445 fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d", fFMD1.Total()));
446 total += fFMD1.Total();
449 fFMD2Pad->Modified();
450 fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d", fFMD2.Total()));
451 total += fFMD2.Total();
454 fFMD3Pad->Modified();
455 fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d", fFMD3.Total()));
456 total += fFMD3.Total();
458 fTotal.SetTitle(Form("Total: %5d/51200 (%3d%%)",
459 total, Int_t(100. / 51200 * total)));
460 fSummary->Modified();
466 //____________________________________________________________________
468 AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*)
474 // HIT The hit to process.
476 // The TParticle argument is never used.
477 static const Float_t rMin = fgkEdepRange.fLow;
478 static const Float_t rMax = fgkEdepRange.fHigh;
480 if (!hit) { AliError("No hit"); return kFALSE; }
481 // if (!p) { AliError("No track"); return kFALSE; }
482 Float_t edep = hit->Edep();
484 if (fHits) fHits->Add(hit);
485 if (fSpec) fSpec->Fill(edep);
486 if (InsideCut(edep, rMin, rMax) && fSpecCut) fSpecCut->Fill(edep);
488 switch (hit->Detector()) {
489 case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
490 case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
491 case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
497 //____________________________________________________________________
499 AliFMDPattern::AddMarker(UShort_t det, Char_t rng,
500 UShort_t sec, UShort_t str,
501 TObject*, Float_t s, Float_t /*min*/, Float_t max)
503 // Add a marker to the display
509 // o Object to refer to
511 // max Maximum of signal
513 AliFMDPatternDetector* d = 0;
515 case 1: d = &fFMD1; break;
516 case 2: d = &fFMD2; break;
517 case 3: d = &fFMD3; break;
520 AliFMDGeometry* geom = AliFMDGeometry::Instance();
522 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
523 // Make code-checker shut the f**k up
524 TRandom* rand = gRandom;
526 AliFMDRing* r = geom->GetRing(rng);
527 Double_t t = .9 * r->GetTheta() / 2;
528 Double_t a = rand->Uniform(-t,t) * TMath::Pi() / 180;
529 Double_t x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
530 Double_t y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
534 d->AddMarker(x, y, s, max);
537 //____________________________________________________________________