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
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 "AliMultiplicity.h"
54 #include "AliESDEvent.h"
55 #include "AliESDVertex.h"
56 // #include <AliLog.h>
57 #include "AliFMDDebug.h" // Better debug macros
60 //____________________________________________________________________
61 ClassImp(AliFMDPattern)
63 ; // This is here to keep Emacs for indenting the next line
66 //____________________________________________________________________
67 AliFMDPattern::AliFMDPatternDetector::AliFMDPatternDetector(UShort_t id)
73 fOuters(id == 1 ? 0 : 20)
82 //____________________________________________________________________
83 AliFMDPattern::AliFMDPatternDetector::~AliFMDPatternDetector()
87 // deletes mother frame
88 if (fFrame) delete fFrame;
91 //____________________________________________________________________
93 AliFMDPattern::AliFMDPatternDetector::DrawShape(TObjArray& a)
103 while ((g = static_cast<TGraph*>(next()))) {
104 g->DrawClone("f same");
105 g->DrawClone("l same");
109 //____________________________________________________________________
111 AliFMDPattern::AliFMDPatternDetector::CopyShapes(TObjArray& src,
119 while ((g = static_cast<TGraph*>(next()))) {
120 TGraph* gg = new TGraph(*g);
121 Double_t* x = gg->GetX();
122 Double_t* y = gg->GetY();
123 for (Int_t i = 0; i < gg->GetN(); i++) {
124 Float_t xx = x[i] * TMath::Cos(ang) - y[i] * TMath::Sin(ang);
125 Float_t yy = x[i] * TMath::Sin(ang) + y[i] * TMath::Cos(ang);
126 gg->SetPoint(i, fx * xx, fy * yy);
128 gg->SetFillStyle(g->GetFillStyle());
129 gg->SetFillColor(g->GetFillColor());
130 gg->SetLineStyle(g->GetLineStyle());
131 gg->SetLineColor(g->GetLineColor());
132 gg->SetLineWidth(g->GetLineWidth());
133 gg->SetMarkerStyle(g->GetMarkerStyle());
134 gg->SetMarkerColor(g->GetMarkerColor());
135 gg->SetMarkerSize(g->GetMarkerSize());
136 TString name(g->GetName());
137 name.ReplaceAll("X", Form("%d",fId));
138 gg->SetName(name.Data());
139 TString title(g->GetTitle());
140 title.ReplaceAll("X", Form("%d",fId));
141 gg->SetTitle(title.Data());
147 //____________________________________________________________________
149 AliFMDPattern::AliFMDPatternDetector::Begin(Int_t nlevel,
158 // nlevel Number of levels
160 // inners Array of inner shapes
161 // outers Array of outer shapes
164 // To make code-checker shut up
165 TStyle* style = gStyle;
166 if (nlevel < 1) nlevel = style->GetNumberOfColors();
168 Double_t rr = 1.05 * r;
170 // The code-checker thinks this is not using the declaration of
171 // TH2F - what a morron!
172 fFrame = new TH2F(Form("fmd%dFrame", fId), Form("FMD%d", fId),
173 100, -rr, rr, 100, -rr, rr);
174 fFrame->SetStats(kFALSE);
177 Double_t ang = (fId == 1 ? -TMath::Pi() / 2 : 0);
178 Double_t fx = (fId == 3 ? -1 : 1); // Flip around Y
179 Double_t fy = (fId == 1 ? 1 : 1); // Flip around X
181 CopyShapes(inners, fInners, ang, fx, fy);
184 CopyShapes(outers, fOuters, ang, fx, fy);
188 for (Int_t i = 0; i < nlevel; i++) {
189 TGraph* g = new TGraph;
190 Int_t idx = Int_t(Float_t(i) / nlevel * style->GetNumberOfColors());
191 Int_t col = style->GetColorPalette(idx);
192 g->SetName(Form("FMD%d_L%02d", fId, i));
193 g->SetMarkerColor(col);
194 g->SetLineColor(col);
195 g->SetFillColor(col);
196 g->SetMarkerSize(i * .2 + .2);
197 g->SetMarkerStyle(2);
198 g->SetEditable(kFALSE);
200 fGraphs.AddAtAndExpand(g, i);
202 // TIter next(&fGraphs);
205 //____________________________________________________________________
207 AliFMDPattern::AliFMDPatternDetector::Clear()
209 // Clear this display.
210 // Simply reset counters to zero.
211 // Avoid deleting memory.
215 //____________________________________________________________________
217 AliFMDPattern::AliFMDPatternDetector::End()
219 // Called when displaying the data.
220 // Simply resets number of points at each level to
221 // the seen number of hits at that level.
222 // Avoid deleting memory.
225 TIter next(&fGraphs);
228 while ((g = static_cast<TGraph*>(next()))) {
229 Int_t cnt = fCounts[i++];
232 g->SetMarkerSize(i * .2 + .2);
241 //____________________________________________________________________
243 AliFMDPattern::AliFMDPatternDetector::AddMarker(Double_t x,
248 // Add a marker at (X,Y,Z). The marker color and size is chosen
249 // relative to the MAX argument.
254 // MAX Maximum value.
256 /** Sigh, for some odd reason, the code-checker does not recognise
257 this a usage of the TMath namespace declaration! Idiot */
258 Int_t i = TMath::Min(Int_t(fCounts.fN * s / max),
259 Int_t(fGraphs.GetEntries()-1));
260 if (i < 0 || i >= fCounts.fN) {
261 std::cerr << "Graph index " << i << " out of bounds [0,"
262 << fCounts.fN << ") - "
263 << fCounts.fN << " * " << s << " / " << max << std::endl;
266 TGraph* g = static_cast<TGraph*>(fGraphs.At(i));
268 g->SetPoint(fCounts[i]++, x, y);
272 //____________________________________________________________________
273 AliFMDPattern::AliFMDPattern(const char* gAliceFile)
274 : AliFMDDisplay(kTRUE, gAliceFile),
286 fEvent(.1, .8, "Event #"),
287 fFMD1Sum(.2, .7, "# in FMD1: "),
288 fFMD2Sum(.2, .6, "# in FMD2: "),
289 fFMD3Sum(.2, .5, "# in FMD3: "),
290 fLine(.15, .47, .85, .47),
291 fTotal(.2, .35, "Total: "),
300 // gAliceFile The galice.root file to use - if any.
303 SetName("AliFMDPattern");
304 SetName("2D display of FMD data");
305 fPhysicsSelection = new AliPhysicsSelection();
306 // RemoveLoad(kGeometry);
307 fEvent.SetBit(TLatex::kTextNDC);
308 fFMD1Sum.SetBit(TLatex::kTextNDC);
309 fFMD2Sum.SetBit(TLatex::kTextNDC);
310 fFMD3Sum.SetBit(TLatex::kTextNDC);
311 fLine.SetBit(TLine::kLineNDC);
312 fTotal.SetBit(TLatex::kTextNDC);
315 //____________________________________________________________________
316 AliFMDPattern::~AliFMDPattern()
319 // Free all allocated shapes.
320 // note, that most members are real objects, so we do not need to
321 // deal with them here.
327 //____________________________________________________________________
329 AliFMDPattern::Init()
331 // Initialize. Get transforms and such,
332 if (!AliFMDInput::Init()) return kFALSE;
333 AliFMDGeometry* geom = AliFMDGeometry::Instance();
334 if (!geom) return kFALSE;
336 geom->InitTransformations();
342 Double_t innerArea = 0;
343 Double_t outerArea = 0;
345 Char_t rs[] = { 'I' , 'O', '\0' };
348 AliFMDRing* ring = geom->GetRing(*r);
351 Double_t rl = ring->GetMinR();
352 Double_t rh = ring->GetMaxR();
353 Double_t area = rh * rh * TMath::Pi() - rl * rl * TMath::Pi();
354 if (*r == 'I') innerArea = area;
355 else outerArea = area;
358 const TObjArray& vs = ring->GetVerticies();
359 TObjArray& gs = (*r == 'I' ? fInners : fOuters);
360 Float_t& mr = (*r == 'I' ? fInnerMax : fOuterMax);
361 Int_t nm = ring->GetNModules();
362 AliFMDDebug(1, ("Making %d modules for %c", nm, *r));
363 for (Int_t m = 0; m < nm; m++) {
364 Int_t nv = 6; // vs.GetEntries();
365 Double_t a = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
366 TGraph* g = new TGraph(nv+1);
367 Double_t x0 = 0, y0 = 0;
368 gs.AddAtAndExpand(g, m);
369 for (Int_t c = 1; c < 4; c++) {
370 TVector2* v = static_cast<TVector2*>(vs.At(c));
371 mr = TMath::Max(mr, Float_t(v->Mod()));
372 TVector2 w(v->Rotate(a));
373 if (c == 1) { x0 = w.X(); y0 = w.Y(); }
374 g->SetPoint(c-1, w.X(), w.Y());
376 for (Int_t c = 3; c > 0; c--) {
377 TVector2* v = static_cast<TVector2*>(vs.At(c));
378 TVector2 u(-v->X(), v->Y());
379 mr = TMath::Max(mr, Float_t(u.Mod()));
380 TVector2 w(u.Rotate(a));
381 g->SetPoint(3+(3-c), w.X(), w.Y());
383 g->SetName(Form("FMDX%c_%02d%02d", *r, 2*m,2*m+1));
384 g->SetTitle(Form("FMDX%c, sectors %d and %d", *r, 2*m,2*m+1));
385 g->SetPoint(nv, x0, y0);
386 g->SetFillColor((*rs == 'I' ?
387 (m % 2 == 0 ? 18 : 17) :
388 (m % 2 == 0 ? 20 : 23)));
389 g->SetFillStyle(3001);
396 fFMD1Area = innerArea;
397 fFMD2Area = innerArea + outerArea;
398 fFMD3Area = innerArea + outerArea;
403 //____________________________________________________________________
405 AliFMDPattern::Begin(Int_t event)
407 // Called at the begining of an event.
411 // EVENT The event number
415 const char* which[] = { "Continue", "Start", "Pause", "Redisplay", 0 };
418 AliFMDGeometry* geom = AliFMDGeometry::Instance();
419 // AliFMDDetector* det;
420 if ((/* det = */ geom->GetDetector(1))) {
422 fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
425 fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
427 if ((/* det = */ geom->GetDetector(2))) {
429 fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
432 fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
434 if ((/* det = */ geom->GetDetector(3))) {
436 fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
439 fFMD3.Begin(-1, fOuterMax, fInners, fOuters);
442 fSummary = new TPad("display", "Display", 0.5, 0.0, 1.0, 0.5, 0, 0);
452 fEvent.SetTitle(Form("Event # %6d", event));
461 TString triggers = fESDEvent->GetFiredTriggerClasses();
462 const AliESDVertex* vertex = fESDEvent->GetPrimaryVertexSPD();
463 Double_t vertexXYZ[3];
464 vertex->GetXYZ(vertexXYZ);
465 const AliMultiplicity* mult = fESDEvent->GetMultiplicity();
466 Int_t nTrackLets = mult->GetNumberOfTracklets();
467 std::cout<<triggers.Data()<<" "<<fPhysicsSelection->IsCollisionCandidate(fESDEvent)<<" "<<nTrackLets<<" "<<vertexXYZ[0]<<" "<<vertexXYZ[1]<<" "<<vertexXYZ[2]<<std::endl;
470 return AliFMDInput::Begin(event);
473 //____________________________________________________________________
475 AliFMDPattern::Redisplay()
477 // Redraw the displayu
481 AliFMDDisplay::Redisplay();
484 //____________________________________________________________________
486 AliFMDPattern::AtEnd()
488 // Called at the end of an event.
494 fFMD1Pad->Modified();
495 fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d (%4.2f /cm^{2})",
496 fFMD1.Total(), fFMD1.Total()/fFMD1Area));
497 total += fFMD1.Total();
500 fFMD2Pad->Modified();
501 fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d (%4.2f /cm^{2})",
502 fFMD2.Total(), fFMD2.Total()/fFMD2Area));
503 total += fFMD2.Total();
506 fFMD3Pad->Modified();
507 fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d (%4.2f /cm^{2})",
508 fFMD3.Total(), fFMD3.Total()/fFMD3Area));
509 total += fFMD3.Total();
511 fTotal.SetTitle(Form("Total: %5d/51200 (%3d%%)",
512 total, Int_t(100. / 51200 * total)));
513 fSummary->Modified();
519 //____________________________________________________________________
521 AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*)
527 // HIT The hit to process.
529 // The TParticle argument is never used.
530 static const Float_t rMin = fgkEdepRange.fLow;
531 static const Float_t rMax = fgkEdepRange.fHigh;
533 if (!hit) { AliError("No hit"); return kFALSE; }
534 // if (!p) { AliError("No track"); return kFALSE; }
535 Float_t edep = hit->Edep();
537 if (fHits) fHits->Add(hit);
538 if (fSpec) fSpec->Fill(edep);
539 if (InsideCut(edep, rMin, rMax) && fSpecCut) fSpecCut->Fill(edep);
541 switch (hit->Detector()) {
542 case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
543 case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
544 case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
550 //____________________________________________________________________
552 AliFMDPattern::AddMarker(UShort_t det, Char_t rng,
553 UShort_t sec, UShort_t str,
554 TObject*, Float_t s, Float_t /*min*/, Float_t max)
556 // Add a marker to the display
562 // o Object to refer to
564 // max Maximum of signal
566 AliFMDPatternDetector* d = 0;
568 case 1: d = &fFMD1; break;
569 case 2: d = &fFMD2; break;
570 case 3: d = &fFMD3; break;
573 AliFMDGeometry* geom = AliFMDGeometry::Instance();
575 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
576 // Make code-checker shut the f**k up
577 TRandom* rand = gRandom;
579 AliFMDRing* r = geom->GetRing(rng);
580 Double_t t = .9 * r->GetTheta() / 2;
581 Double_t a = rand->Uniform(-t,t) * TMath::Pi() / 180;
582 Double_t x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
583 Double_t y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
587 d->AddMarker(x, y, s, max);
590 //____________________________________________________________________