]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDPattern.cxx
Update the mult corr histograms
[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),
294 fFMD3Area(0)
a9579262 295{
f95a63c4 296 // Constructor.
297 //
298 // Parameters
299 //
300 // gAliceFile The galice.root file to use - if any.
301 //
302
42f1b2f5 303 SetName("AliFMDPattern");
304 SetName("2D display of FMD data");
693d8c21 305 fPhysicsSelection = new AliPhysicsSelection();
a9579262 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);
313}
314
315//____________________________________________________________________
316AliFMDPattern::~AliFMDPattern()
317{
f95a63c4 318 // DTOR
319 // Free all allocated shapes.
320 // note, that most members are real objects, so we do not need to
321 // deal with them here.
a9579262 322 fInners.Delete();
323 fOuters.Delete();
324}
325
326
327//____________________________________________________________________
328Bool_t
329AliFMDPattern::Init()
330{
f95a63c4 331 // Initialize. Get transforms and such,
a9579262 332 if (!AliFMDInput::Init()) return kFALSE;
333 AliFMDGeometry* geom = AliFMDGeometry::Instance();
69893a66 334 if (!geom) return kFALSE;
a9579262 335 geom->Init();
336 geom->InitTransformations();
337
e064ab4a 338 fFMD1Area = 0;
339 fFMD2Area = 0;
340 fFMD3Area = 0;
341
342 Double_t innerArea = 0;
343 Double_t outerArea = 0;
344
a9579262 345 Char_t rs[] = { 'I' , 'O', '\0' };
346 Char_t *r = rs;
347 do {
348 AliFMDRing* ring = geom->GetRing(*r);
349 if (!ring) continue;
e064ab4a 350
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;
356
357
a9579262 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();
f38b1653 362 AliFMDDebug(1, ("Making %d modules for %c", nm, *r));
a9579262 363 for (Int_t m = 0; m < nm; m++) {
c6b36280 364 Int_t nv = 6; // vs.GetEntries();
a9579262 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);
c6b36280 369 for (Int_t c = 1; c < 4; c++) {
a9579262 370 TVector2* v = static_cast<TVector2*>(vs.At(c));
371 mr = TMath::Max(mr, Float_t(v->Mod()));
372 TVector2 w(v->Rotate(a));
c6b36280 373 if (c == 1) { x0 = w.X(); y0 = w.Y(); }
374 g->SetPoint(c-1, w.X(), w.Y());
375 }
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());
a9579262 382 }
f38b1653 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));
a9579262 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);
390 g->SetLineColor(1);
391 g->SetLineWidth(1);
392 g->SetLineStyle(2);
393 }
394 } while (*(++r));
e064ab4a 395
396 fFMD1Area = innerArea;
397 fFMD2Area = innerArea + outerArea;
398 fFMD3Area = innerArea + outerArea;
399
a9579262 400 return kTRUE;
401}
402
403//____________________________________________________________________
404Bool_t
405AliFMDPattern::Begin(Int_t event)
406{
f95a63c4 407 // Called at the begining of an event.
408 //
409 // Parameters
410 //
411 // EVENT The event number
412 //
97b4001e 413 MakeAux();
a9579262 414 if (!fCanvas) {
2eddac03 415 const char* which[] = { "Continue", "Start", "Pause", "Redisplay", 0 };
a9579262 416 MakeCanvas(which);
a9579262 417
418 AliFMDGeometry* geom = AliFMDGeometry::Instance();
f95a63c4 419 // AliFMDDetector* det;
420 if ((/* det = */ geom->GetDetector(1))) {
a9579262 421 fPad->cd();
422 fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
423 fFMD1Pad->Draw();
424 fFMD1Pad->cd();
97b4001e 425 fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
a9579262 426 }
f95a63c4 427 if ((/* det = */ geom->GetDetector(2))) {
a9579262 428 fPad->cd();
429 fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
430 fFMD2Pad->Draw();
431 fFMD2Pad->cd();
97b4001e 432 fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
a9579262 433 }
f95a63c4 434 if ((/* det = */ geom->GetDetector(3))) {
a9579262 435 fPad->cd();
436 fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
437 fFMD3Pad->Draw();
438 fFMD3Pad->cd();
97b4001e 439 fFMD3.Begin(-1, fOuterMax, fInners, fOuters);
a9579262 440 }
441 fPad->cd();
442 fSummary = new TPad("display", "Display", 0.5, 0.0, 1.0, 0.5, 0, 0);
443 fSummary->Draw();
444 fSummary->cd();
445 fEvent.Draw();
446 fFMD1Sum.Draw();
447 fFMD2Sum.Draw();
448 fFMD3Sum.Draw();
449 fLine.Draw();
450 fTotal.Draw();
451 }
452 fEvent.SetTitle(Form("Event # %6d", event));
453
454 fCanvas->Modified();
455 fCanvas->Update();
456 fCanvas->cd();
457 fFMD1.Clear();
458 fFMD2.Clear();
459 fFMD3.Clear();
693d8c21 460
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;
468
469
a9579262 470 return AliFMDInput::Begin(event);
471}
472
473//____________________________________________________________________
474void
475AliFMDPattern::Redisplay()
476{
f95a63c4 477 // Redraw the displayu
a9579262 478 fFMD1.Clear();
479 fFMD2.Clear();
480 fFMD3.Clear();
481 AliFMDDisplay::Redisplay();
482}
483
484//____________________________________________________________________
485void
486AliFMDPattern::AtEnd()
487{
f95a63c4 488 // Called at the end of an event.
a9579262 489 DrawAux();
490
491 Int_t total = 0;
492
493 fFMD1.End();
494 fFMD1Pad->Modified();
e1a9aea4 495 fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d (%4.2f /cm^{2})",
e064ab4a 496 fFMD1.Total(), fFMD1.Total()/fFMD1Area));
a9579262 497 total += fFMD1.Total();
498
499 fFMD2.End();
500 fFMD2Pad->Modified();
e1a9aea4 501 fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d (%4.2f /cm^{2})",
e064ab4a 502 fFMD2.Total(), fFMD2.Total()/fFMD2Area));
a9579262 503 total += fFMD2.Total();
504
505 fFMD3.End();
506 fFMD3Pad->Modified();
e1a9aea4 507 fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d (%4.2f /cm^{2})",
e064ab4a 508 fFMD3.Total(), fFMD3.Total()/fFMD3Area));
a9579262 509 total += fFMD3.Total();
510
511 fTotal.SetTitle(Form("Total: %5d/51200 (%3d%%)",
512 total, Int_t(100. / 51200 * total)));
513 fSummary->Modified();
514 fCanvas->Modified();
515 fCanvas->Update();
516 fCanvas->cd();
517}
518
519//____________________________________________________________________
520Bool_t
521AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*)
522{
f95a63c4 523 // Process a hit.
524 //
525 // Parameters
526 //
527 // HIT The hit to process.
528 //
529 // The TParticle argument is never used.
ef8e8623 530 static const Float_t rMin = fgkEdepRange.fLow;
531 static const Float_t rMax = fgkEdepRange.fHigh;
532
533 if (!hit) { AliError("No hit"); return kFALSE; }
534 // if (!p) { AliError("No track"); return kFALSE; }
535 Float_t edep = hit->Edep();
536
537 if (fHits) fHits->Add(hit);
538 if (fSpec) fSpec->Fill(edep);
539 if (InsideCut(edep, rMin, rMax) && fSpecCut) fSpecCut->Fill(edep);
540
a9579262 541 switch (hit->Detector()) {
ef8e8623 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;
a9579262 545 }
546 return kTRUE;
547}
548
549
550//____________________________________________________________________
551void
f95a63c4 552AliFMDPattern::AddMarker(UShort_t det, Char_t rng,
553 UShort_t sec, UShort_t str,
cf291b42 554 TObject*, Float_t s, Float_t /*min*/, Float_t max)
a9579262 555{
556 // Add a marker to the display
557 //
558 // det Detector
559 // rng Ring
560 // sec Sector
561 // str Strip
562 // o Object to refer to
563 // s Signal
564 // max Maximum of signal
565 //
f95a63c4 566 AliFMDPatternDetector* d = 0;
a9579262 567 switch (det) {
568 case 1: d = &fFMD1; break;
569 case 2: d = &fFMD2; break;
570 case 3: d = &fFMD3; break;
571 }
572 if (!d) return;
573 AliFMDGeometry* geom = AliFMDGeometry::Instance();
574 Double_t x, y, z;
575 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
f95a63c4 576 // Make code-checker shut the f**k up
577 TRandom* rand = gRandom;
f38b1653 578 if (false) {
a9579262 579 AliFMDRing* r = geom->GetRing(rng);
580 Double_t t = .9 * r->GetTheta() / 2;
f95a63c4 581 Double_t a = rand->Uniform(-t,t) * TMath::Pi() / 180;
a9579262 582 Double_t x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
583 Double_t y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
584 x = x1;
585 y = y1;
586 }
587 d->AddMarker(x, y, s, max);
588}
589
590//____________________________________________________________________
591//
592// EOF
593//