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 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
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
35 #include <TApplication.h>
36 // #include <TButton.h>
44 // #include <TStyle.h>
49 #include "AliFMDDetector.h"
50 #include "AliFMDFancy.h" // ALIFMDDISPLAY_H
51 #include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
52 #include "AliFMDHit.h"
53 // #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
54 #include "AliFMDRing.h"
56 //____________________________________________________________________
59 ; // This is here to keep Emacs for indenting the next line
62 //____________________________________________________________________
63 AliFMDFancy::AliFMDFancy(const char* gAliceFile)
64 : AliFMDDisplay(kTRUE, gAliceFile),
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: ")
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);
92 //____________________________________________________________________
93 AliFMDFancy::AliFancyDetector::AliFancyDetector(UShort_t id)
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);
116 //____________________________________________________________________
117 AliFMDFancy::AliFancyDetector::~AliFancyDetector()
121 if (fFrame) delete fFrame;
124 //____________________________________________________________________
125 AliFMDFancy::~AliFMDFancy()
130 //____________________________________________________________________
132 AliFMDFancy::AliFancyDetector::AddHistogram(TGraph2D& g, const char* opt)
135 TH2* h = g.GetHistogram(opt);
137 // Code checker doesn't think this using the TH2 interface -
139 h->SetBins(1, -fMaxR, fMaxR, 1, -fMaxR, fMaxR);
140 h->GetZaxis()->SetRangeUser(fMinZ, fMaxZ);
145 //____________________________________________________________________
147 AliFMDFancy::AliFancyDetector::Init()
150 AliFMDGeometry* geom = AliFMDGeometry::Instance();
151 AliFMDDetector* det = geom->GetDetector(fId);
153 Char_t rs[] = { 'I' , 'O', '\0' };
157 Double_t minZ = 10000;
158 Double_t maxZ = -10000;
160 while ((r = *(rp++))) {
161 AliFMDRing* ring = det->GetRing(r);
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);
171 // Double_t x0 = 0, y0 = 0, z0 = 0;
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));
181 // if (c == 0) { x0 = w.X(); y0 = w.Y(); z0 = z; }
182 g->SetPoint(c, w.X(), w.Y(), z);
183 maxR = TMath::Max(maxR, v->Mod());
185 //g->SetPoint(nv, x0, y0, z0);
187 g->SetFillStyle(3002);
193 fMinZ = (minZ > 0 ? 0.95 * minZ : 1.05 * minZ);
194 fMaxZ = (maxZ > 0 ? 1.05 * maxZ : 0.95 * maxZ);
196 TIter next(&fShapes);
198 while ((g = static_cast<TGraph2D*>(next()))) AddHistogram(*g);
199 if (det->GetInner()) AddHistogram(fInnerHits);
200 if (det->GetOuter()) AddHistogram(fOuterHits);
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);
212 //____________________________________________________________________
216 // Initialize. GEt transforms and such,
217 if (!AliFMDInput::Init()) return kFALSE;
218 AliFMDGeometry* geom = AliFMDGeometry::Instance();
220 geom->InitTransformations();
228 //____________________________________________________________________
230 AliFMDFancy::AliFancyDetector::Begin(Int_t /* event */)
232 // Called at the begining of an event.
233 TIter next(&fShapes);
235 fFrame->Draw("surf fb");
236 fFrame->GetZaxis()->SetRangeUser(fMinZ, fMaxZ);
237 while ((g = static_cast<TGraph2D*>(next()))) g->Draw("tri2 FB same");
240 //____________________________________________________________________
242 AliFMDFancy::AliFancyDetector::Clear(Int_t /* event */)
250 //____________________________________________________________________
252 AliFMDFancy::Begin(Int_t event)
254 // Called at the begining of an event
256 const char* which[] = { "Continue", "Redisplay", 0 };
259 AliFMDGeometry* geom = AliFMDGeometry::Instance();
260 // AliFMDDetector* det;
261 if ((/*det =*/ geom->GetDetector(1))) {
263 fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
268 if ((/*det =*/ geom->GetDetector(2))) {
270 fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
275 if ((/*det =*/ geom->GetDetector(3))) {
277 fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.05, .5, .5, 0, 0);
283 fSummary = new TPad("display", "Display", 0.5, 0.05, 1.0, 0.5, 0, 0);
295 fEvent.SetTitle(Form("Event # %6d", event));
303 return AliFMDInput::Begin(event);
306 //____________________________________________________________________
308 AliFMDFancy::AliFancyDetector::End()
310 // Called at the end of an event
311 Char_t rs[] = { 'I', 'O', '\0' };
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);
320 // The code checker thinks this is not using declarations from
321 // iostram and iomanip - that's just silly.
322 std::cout << g.GetName() << " has " << std::setw(4) << n << "/"
323 << std::setw(5) << m << " points" << std::endl;
325 AddHistogram(g, "empty");
329 //____________________________________________________________________
333 // Called at the end of an event
334 AliFMDGeometry* geom = AliFMDGeometry::Instance();
335 // AliFMDDetector* det;
337 if ((/*det =*/ geom->GetDetector(1))) {
340 fFMD1Pad->Modified();
341 fFMD1IHits.SetTitle(Form("# hits in FMD1I: %5d", fFMD1.GetNInnerHits()));
342 total += fFMD1.GetNInnerHits();
344 if ((/*det =*/ geom->GetDetector(2))) {
347 fFMD2Pad->Modified();
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();
353 if ((/*det =*/ geom->GetDetector(3))) {
356 fFMD3Pad->Modified();
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();
362 fTotal.SetTitle(Form("Total: %5d/51200 (%3d%%)",
363 total, Int_t(100. / 51200 * total)));
364 fSummary->Modified();
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;
379 return AliFMDInput::End();
382 //____________________________________________________________________
384 AliFMDFancy::ProcessHit(AliFMDHit* hit, TParticle*)
387 AddMarker(hit->Detector(), hit->Ring(), hit->Sector(), hit->Strip(),
388 hit, hit->Edep(), 0, 20);
391 //____________________________________________________________________
393 AliFMDFancy::AliFancyDetector::AddMarker(Char_t rng, UShort_t sec,
394 UShort_t str, Float_t, Float_t)
396 // Add a marker to the display
397 AliFMDGeometry* geom = AliFMDGeometry::Instance();
399 geom->Detector2XYZ(fId, rng, sec, str, x, y, z);
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;
405 AliFMDRing* r = geom->GetRing(rng);
406 Double_t t = .9 * r->GetTheta() / 2;
407 Double_t a = rand->Uniform(-t,t) * TMath::Pi() / 180;
408 Double_t x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
409 Double_t y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
415 case 'i': fInnerHits.SetPoint(fNInnerHits++, x, y, z); break;
417 case 'o': fOuterHits.SetPoint(fNOuterHits++, x, y, z); break;
424 //____________________________________________________________________
426 AliFMDFancy::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
427 TObject*, Float_t, Float_t, Float_t)
429 // Add a marker to the display
435 // o Object to refer to
437 // max Maximum of signal
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;
446 //____________________________________________________________________