]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDPattern.cxx
Fix for Coverity warning 16208
[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
e064ab4a 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"
693d8c21 53#include "AliMultiplicity.h"
54#include "AliESDEvent.h"
55#include "AliESDVertex.h"
f95a63c4 56// #include <AliLog.h>
57#include "AliFMDDebug.h" // Better debug macros
58class AliFMDDetector;
a9579262 59
60//____________________________________________________________________
61ClassImp(AliFMDPattern)
62#if 0
63 ; // This is here to keep Emacs for indenting the next line
64#endif
65
66//____________________________________________________________________
f95a63c4 67AliFMDPattern::AliFMDPatternDetector::AliFMDPatternDetector(UShort_t id)
a9579262 68 : fId(id),
69 fCounts(0),
70 fGraphs(0),
f38b1653 71 fFrame(0),
7af3df7f 72 fInners(10),
73 fOuters(id == 1 ? 0 : 20)
f95a63c4 74{
75 // CTOR
76 //
77 // Parameters:
78 //
79 // ID Identifier
80}
a9579262 81
82//____________________________________________________________________
f95a63c4 83AliFMDPattern::AliFMDPatternDetector::~AliFMDPatternDetector()
a9579262 84{
f95a63c4 85 // DTOR
86 // Destructor -
87 // deletes mother frame
a9579262 88 if (fFrame) delete fFrame;
89}
90
91//____________________________________________________________________
92void
f95a63c4 93AliFMDPattern::AliFMDPatternDetector::DrawShape(TObjArray& a)
a9579262 94{
f95a63c4 95 // Draw all shapes.
96 //
97 // Paramters
98 //
99 // a Array of shapes
100 //
a9579262 101 TIter next(&a);
102 TGraph* g = 0;
103 while ((g = static_cast<TGraph*>(next()))) {
104 g->DrawClone("f same");
105 g->DrawClone("l same");
106 }
107}
108
f38b1653 109//____________________________________________________________________
110void
111AliFMDPattern::AliFMDPatternDetector::CopyShapes(TObjArray& src,
112 TObjArray& dest,
113 Double_t ang,
114 Double_t fx,
115 Double_t fy)
116{
117 TIter next(&src);
118 TGraph* g = 0;
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);
127 }
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());
142 dest.Add(gg);
143 }
144 dest.SetOwner();
145}
146
a9579262 147//____________________________________________________________________
148void
cf291b42 149AliFMDPattern::AliFMDPatternDetector::Begin(Int_t nlevel,
150 Double_t r,
151 TObjArray& inners,
152 TObjArray& outers)
a9579262 153{
f95a63c4 154 // Start of a run.
155 //
156 // Parameters
157 //
158 // nlevel Number of levels
159 // r Radius
160 // inners Array of inner shapes
161 // outers Array of outer shapes
162 //
163
164 // To make code-checker shut up
165 TStyle* style = gStyle;
166 if (nlevel < 1) nlevel = style->GetNumberOfColors();
a9579262 167 fCounts.Set(nlevel);
5cf05dbb 168 Double_t rr = 1.05 * r;
a9579262 169 if (!fFrame) {
f95a63c4 170 // The code-checker thinks this is not using the declaration of
171 // TH2F - what a morron!
a9579262 172 fFrame = new TH2F(Form("fmd%dFrame", fId), Form("FMD%d", fId),
5cf05dbb 173 100, -rr, rr, 100, -rr, rr);
a9579262 174 fFrame->SetStats(kFALSE);
175 fFrame->Draw();
176 }
f38b1653 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
180
181 CopyShapes(inners, fInners, ang, fx, fy);
182 DrawShape(fInners);
183 if (fId != 1) {
184 CopyShapes(outers, fOuters, ang, fx, fy);
185 DrawShape(fOuters);
186 }
187
a9579262 188 for (Int_t i = 0; i < nlevel; i++) {
189 TGraph* g = new TGraph;
f95a63c4 190 Int_t idx = Int_t(Float_t(i) / nlevel * style->GetNumberOfColors());
191 Int_t col = style->GetColorPalette(idx);
a9579262 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);
5cf05dbb 198 g->SetEditable(kFALSE);
a9579262 199 g->Draw("same p");
200 fGraphs.AddAtAndExpand(g, i);
201 }
cf291b42 202 // TIter next(&fGraphs);
a9579262 203}
204
205//____________________________________________________________________
206void
f95a63c4 207AliFMDPattern::AliFMDPatternDetector::Clear()
a9579262 208{
f95a63c4 209 // Clear this display.
210 // Simply reset counters to zero.
211 // Avoid deleting memory.
a9579262 212 fCounts.Reset(0);
213}
214
215//____________________________________________________________________
216void
f95a63c4 217AliFMDPattern::AliFMDPatternDetector::End()
a9579262 218{
f95a63c4 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.
693d8c21 223
224
a9579262 225 TIter next(&fGraphs);
226 TGraph* g = 0;
227 Int_t i = 0;
5cf05dbb 228 while ((g = static_cast<TGraph*>(next()))) {
229 Int_t cnt = fCounts[i++];
230 if (cnt > 0) {
231 g->Set(cnt);
232 g->SetMarkerSize(i * .2 + .2);
233 }
234 else {
235 g->SetPoint(0,0,0);
236 g->SetMarkerSize(0);
237 }
238 }
239
a9579262 240}
241//____________________________________________________________________
242void
cf291b42 243AliFMDPattern::AliFMDPatternDetector::AddMarker(Double_t x,
244 Double_t y,
245 Float_t s,
246 Float_t max)
a9579262 247{
f95a63c4 248 // Add a marker at (X,Y,Z). The marker color and size is chosen
249 // relative to the MAX argument.
250 //
251 // Parameters
252 //
253 // X,Y,Z Coordiantes
254 // MAX Maximum value.
255 //
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),
a9579262 259 Int_t(fGraphs.GetEntries()-1));
e064ab4a 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;
264 return;
265 }
a9579262 266 TGraph* g = static_cast<TGraph*>(fGraphs.At(i));
267 if (!g) return;
268 g->SetPoint(fCounts[i]++, x, y);
269}
270
271
272//____________________________________________________________________
273AliFMDPattern::AliFMDPattern(const char* gAliceFile)
274 : AliFMDDisplay(kTRUE, gAliceFile),
17e542eb 275 fInners(0),
276 fOuters(0),
a9579262 277 fInnerMax(0),
278 fOuterMax(0),
279 fFMD1Pad(0),
280 fFMD1(1),
281 fFMD2Pad(0),
282 fFMD2(2),
283 fFMD3Pad(0),
284 fFMD3(3),
17e542eb 285 fSummary(0),
a9579262 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),
e064ab4a 291 fTotal(.2, .35, "Total: "),
292 fFMD1Area(0),
293 fFMD2Area(0),
dbac3484 294 fFMD3Area(0),
295 fPhysicsSelection(0)
a9579262 296{
f95a63c4 297 // Constructor.
298 //
299 // Parameters
300 //
301 // gAliceFile The galice.root file to use - if any.
302 //
303
42f1b2f5 304 SetName("AliFMDPattern");
305 SetName("2D display of FMD data");
693d8c21 306 fPhysicsSelection = new AliPhysicsSelection();
a9579262 307 // RemoveLoad(kGeometry);
308 fEvent.SetBit(TLatex::kTextNDC);
309 fFMD1Sum.SetBit(TLatex::kTextNDC);
310 fFMD2Sum.SetBit(TLatex::kTextNDC);
311 fFMD3Sum.SetBit(TLatex::kTextNDC);
312 fLine.SetBit(TLine::kLineNDC);
313 fTotal.SetBit(TLatex::kTextNDC);
314}
315
316//____________________________________________________________________
317AliFMDPattern::~AliFMDPattern()
318{
f95a63c4 319 // DTOR
320 // Free all allocated shapes.
321 // note, that most members are real objects, so we do not need to
322 // deal with them here.
a9579262 323 fInners.Delete();
324 fOuters.Delete();
325}
326
327
328//____________________________________________________________________
329Bool_t
330AliFMDPattern::Init()
331{
f95a63c4 332 // Initialize. Get transforms and such,
a9579262 333 if (!AliFMDInput::Init()) return kFALSE;
334 AliFMDGeometry* geom = AliFMDGeometry::Instance();
69893a66 335 if (!geom) return kFALSE;
a9579262 336 geom->Init();
337 geom->InitTransformations();
338
e064ab4a 339 fFMD1Area = 0;
340 fFMD2Area = 0;
341 fFMD3Area = 0;
342
343 Double_t innerArea = 0;
344 Double_t outerArea = 0;
345
a9579262 346 Char_t rs[] = { 'I' , 'O', '\0' };
347 Char_t *r = rs;
348 do {
349 AliFMDRing* ring = geom->GetRing(*r);
350 if (!ring) continue;
e064ab4a 351
352 Double_t rl = ring->GetMinR();
353 Double_t rh = ring->GetMaxR();
354 Double_t area = rh * rh * TMath::Pi() - rl * rl * TMath::Pi();
355 if (*r == 'I') innerArea = area;
356 else outerArea = area;
357
358
a9579262 359 const TObjArray& vs = ring->GetVerticies();
360 TObjArray& gs = (*r == 'I' ? fInners : fOuters);
361 Float_t& mr = (*r == 'I' ? fInnerMax : fOuterMax);
362 Int_t nm = ring->GetNModules();
f38b1653 363 AliFMDDebug(1, ("Making %d modules for %c", nm, *r));
a9579262 364 for (Int_t m = 0; m < nm; m++) {
c6b36280 365 Int_t nv = 6; // vs.GetEntries();
a9579262 366 Double_t a = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
367 TGraph* g = new TGraph(nv+1);
368 Double_t x0 = 0, y0 = 0;
369 gs.AddAtAndExpand(g, m);
c6b36280 370 for (Int_t c = 1; c < 4; c++) {
a9579262 371 TVector2* v = static_cast<TVector2*>(vs.At(c));
372 mr = TMath::Max(mr, Float_t(v->Mod()));
373 TVector2 w(v->Rotate(a));
c6b36280 374 if (c == 1) { x0 = w.X(); y0 = w.Y(); }
375 g->SetPoint(c-1, w.X(), w.Y());
376 }
377 for (Int_t c = 3; c > 0; c--) {
378 TVector2* v = static_cast<TVector2*>(vs.At(c));
379 TVector2 u(-v->X(), v->Y());
380 mr = TMath::Max(mr, Float_t(u.Mod()));
381 TVector2 w(u.Rotate(a));
382 g->SetPoint(3+(3-c), w.X(), w.Y());
a9579262 383 }
f38b1653 384 g->SetName(Form("FMDX%c_%02d%02d", *r, 2*m,2*m+1));
385 g->SetTitle(Form("FMDX%c, sectors %d and %d", *r, 2*m,2*m+1));
a9579262 386 g->SetPoint(nv, x0, y0);
387 g->SetFillColor((*rs == 'I' ?
388 (m % 2 == 0 ? 18 : 17) :
389 (m % 2 == 0 ? 20 : 23)));
390 g->SetFillStyle(3001);
391 g->SetLineColor(1);
392 g->SetLineWidth(1);
393 g->SetLineStyle(2);
394 }
395 } while (*(++r));
e064ab4a 396
397 fFMD1Area = innerArea;
398 fFMD2Area = innerArea + outerArea;
399 fFMD3Area = innerArea + outerArea;
400
a9579262 401 return kTRUE;
402}
403
404//____________________________________________________________________
405Bool_t
406AliFMDPattern::Begin(Int_t event)
407{
f95a63c4 408 // Called at the begining of an event.
409 //
410 // Parameters
411 //
412 // EVENT The event number
413 //
97b4001e 414 MakeAux();
a9579262 415 if (!fCanvas) {
2eddac03 416 const char* which[] = { "Continue", "Start", "Pause", "Redisplay", 0 };
a9579262 417 MakeCanvas(which);
a9579262 418
419 AliFMDGeometry* geom = AliFMDGeometry::Instance();
f95a63c4 420 // AliFMDDetector* det;
421 if ((/* det = */ geom->GetDetector(1))) {
a9579262 422 fPad->cd();
423 fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
424 fFMD1Pad->Draw();
425 fFMD1Pad->cd();
97b4001e 426 fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
a9579262 427 }
f95a63c4 428 if ((/* det = */ geom->GetDetector(2))) {
a9579262 429 fPad->cd();
430 fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
431 fFMD2Pad->Draw();
432 fFMD2Pad->cd();
97b4001e 433 fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
a9579262 434 }
f95a63c4 435 if ((/* det = */ geom->GetDetector(3))) {
a9579262 436 fPad->cd();
437 fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
438 fFMD3Pad->Draw();
439 fFMD3Pad->cd();
97b4001e 440 fFMD3.Begin(-1, fOuterMax, fInners, fOuters);
a9579262 441 }
442 fPad->cd();
443 fSummary = new TPad("display", "Display", 0.5, 0.0, 1.0, 0.5, 0, 0);
444 fSummary->Draw();
445 fSummary->cd();
446 fEvent.Draw();
447 fFMD1Sum.Draw();
448 fFMD2Sum.Draw();
449 fFMD3Sum.Draw();
450 fLine.Draw();
451 fTotal.Draw();
452 }
453 fEvent.SetTitle(Form("Event # %6d", event));
454
455 fCanvas->Modified();
456 fCanvas->Update();
457 fCanvas->cd();
458 fFMD1.Clear();
459 fFMD2.Clear();
460 fFMD3.Clear();
693d8c21 461
462 TString triggers = fESDEvent->GetFiredTriggerClasses();
463 const AliESDVertex* vertex = fESDEvent->GetPrimaryVertexSPD();
464 Double_t vertexXYZ[3];
465 vertex->GetXYZ(vertexXYZ);
466 const AliMultiplicity* mult = fESDEvent->GetMultiplicity();
467 Int_t nTrackLets = mult->GetNumberOfTracklets();
468 std::cout<<triggers.Data()<<" "<<fPhysicsSelection->IsCollisionCandidate(fESDEvent)<<" "<<nTrackLets<<" "<<vertexXYZ[0]<<" "<<vertexXYZ[1]<<" "<<vertexXYZ[2]<<std::endl;
469
470
a9579262 471 return AliFMDInput::Begin(event);
472}
473
474//____________________________________________________________________
475void
476AliFMDPattern::Redisplay()
477{
f95a63c4 478 // Redraw the displayu
a9579262 479 fFMD1.Clear();
480 fFMD2.Clear();
481 fFMD3.Clear();
482 AliFMDDisplay::Redisplay();
483}
484
485//____________________________________________________________________
486void
487AliFMDPattern::AtEnd()
488{
f95a63c4 489 // Called at the end of an event.
a9579262 490 DrawAux();
491
492 Int_t total = 0;
493
494 fFMD1.End();
495 fFMD1Pad->Modified();
e1a9aea4 496 fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d (%4.2f /cm^{2})",
e064ab4a 497 fFMD1.Total(), fFMD1.Total()/fFMD1Area));
a9579262 498 total += fFMD1.Total();
499
500 fFMD2.End();
501 fFMD2Pad->Modified();
e1a9aea4 502 fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d (%4.2f /cm^{2})",
e064ab4a 503 fFMD2.Total(), fFMD2.Total()/fFMD2Area));
a9579262 504 total += fFMD2.Total();
505
506 fFMD3.End();
507 fFMD3Pad->Modified();
e1a9aea4 508 fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d (%4.2f /cm^{2})",
e064ab4a 509 fFMD3.Total(), fFMD3.Total()/fFMD3Area));
a9579262 510 total += fFMD3.Total();
511
512 fTotal.SetTitle(Form("Total: %5d/51200 (%3d%%)",
513 total, Int_t(100. / 51200 * total)));
514 fSummary->Modified();
515 fCanvas->Modified();
516 fCanvas->Update();
517 fCanvas->cd();
518}
519
520//____________________________________________________________________
521Bool_t
522AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*)
523{
f95a63c4 524 // Process a hit.
525 //
526 // Parameters
527 //
528 // HIT The hit to process.
529 //
530 // The TParticle argument is never used.
ef8e8623 531 static const Float_t rMin = fgkEdepRange.fLow;
532 static const Float_t rMax = fgkEdepRange.fHigh;
533
534 if (!hit) { AliError("No hit"); return kFALSE; }
535 // if (!p) { AliError("No track"); return kFALSE; }
536 Float_t edep = hit->Edep();
537
538 if (fHits) fHits->Add(hit);
539 if (fSpec) fSpec->Fill(edep);
540 if (InsideCut(edep, rMin, rMax) && fSpecCut) fSpecCut->Fill(edep);
541
a9579262 542 switch (hit->Detector()) {
ef8e8623 543 case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
544 case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
545 case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
a9579262 546 }
547 return kTRUE;
548}
549
550
551//____________________________________________________________________
552void
f95a63c4 553AliFMDPattern::AddMarker(UShort_t det, Char_t rng,
554 UShort_t sec, UShort_t str,
cf291b42 555 TObject*, Float_t s, Float_t /*min*/, Float_t max)
a9579262 556{
557 // Add a marker to the display
558 //
559 // det Detector
560 // rng Ring
561 // sec Sector
562 // str Strip
563 // o Object to refer to
564 // s Signal
565 // max Maximum of signal
566 //
f95a63c4 567 AliFMDPatternDetector* d = 0;
a9579262 568 switch (det) {
569 case 1: d = &fFMD1; break;
570 case 2: d = &fFMD2; break;
571 case 3: d = &fFMD3; break;
572 }
573 if (!d) return;
574 AliFMDGeometry* geom = AliFMDGeometry::Instance();
575 Double_t x, y, z;
576 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
f95a63c4 577 // Make code-checker shut the f**k up
578 TRandom* rand = gRandom;
f38b1653 579 if (false) {
a9579262 580 AliFMDRing* r = geom->GetRing(rng);
581 Double_t t = .9 * r->GetTheta() / 2;
f95a63c4 582 Double_t a = rand->Uniform(-t,t) * TMath::Pi() / 180;
a9579262 583 Double_t x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
584 Double_t y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
585 x = x1;
586 y = y1;
587 }
588 d->AddMarker(x, y, s, max);
589}
590
591//____________________________________________________________________
592//
593// EOF
594//