]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDPattern.cxx
EMCAL geometry can be created independently form anything now
[u/mrichter/AliRoot.git] / FMD / AliFMDPattern.cxx
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 //
31 #include "AliFMDPattern.h"      // ALIFMDDISPLAY_H
32 #include "AliFMDGeometry.h"     // ALIFMDGEOMETRY_H
33 #include "AliFMDParameters.h"   // ALIFMDPARAMETERS_H
34 #include "AliFMDRing.h"
35 #include "AliFMDDetector.h"
36 #include "AliFMDHit.h"
37 #include <AliLog.h>
38 #include <TStyle.h>
39 #include <TApplication.h>
40 #include <TButton.h>
41 #include <TCanvas.h>
42 #include <TView.h>
43 #include <TH2F.h>
44 #include <TSystem.h>
45 #include <TVector2.h>
46 #include <TRandom.h>
47 #include <TSlider.h>
48 #include <TPad.h>
49 #include <iostream>
50
51 //____________________________________________________________________
52 ClassImp(AliFMDPattern)
53 #if 0
54   ; // This is here to keep Emacs for indenting the next line
55 #endif
56
57 //____________________________________________________________________
58 AliFMDPattern::Detector::Detector(UShort_t id) 
59   : fId(id),
60     fCounts(0), 
61     fGraphs(0), 
62     fFrame(0)
63 {}
64
65 //____________________________________________________________________
66 AliFMDPattern::Detector::~Detector()
67 {
68   if (fFrame) delete fFrame;
69 }
70
71 //____________________________________________________________________
72 void
73 AliFMDPattern::Detector::DrawShape(TObjArray& a) 
74 {
75   TIter next(&a);
76   TGraph* g = 0;
77   while ((g = static_cast<TGraph*>(next()))) {
78     g->DrawClone("f same");
79     g->DrawClone("l same");
80   }
81 }
82
83 //____________________________________________________________________
84 void
85 AliFMDPattern::Detector::Begin(Int_t nlevel, Double_t r, 
86                                TObjArray& inners, TObjArray& outers)
87 {
88   if (nlevel < 1) nlevel = gStyle->GetNumberOfColors();
89   fCounts.Set(nlevel);
90   if (!fFrame) {
91     fFrame = new TH2F(Form("fmd%dFrame", fId), Form("FMD%d", fId), 
92                       10, -r, r, 10, -r, r);
93     fFrame->SetStats(kFALSE);
94     fFrame->Draw();
95   }
96   DrawShape(inners);
97   if (fId != 1) DrawShape(outers);
98   for (Int_t i = 0; i < nlevel; i++) { 
99     TGraph* g = new TGraph;
100     Int_t idx = Int_t(Float_t(i) / nlevel * gStyle->GetNumberOfColors());
101     Int_t col = gStyle->GetColorPalette(idx);
102     g->SetName(Form("FMD%d_L%02d", fId, i));
103     g->SetMarkerColor(col);
104     g->SetLineColor(col);
105     g->SetFillColor(col);
106     g->SetMarkerSize(i * .2 + .2);
107     g->SetMarkerStyle(2);
108     g->Draw("same p");
109     fGraphs.AddAtAndExpand(g, i);
110   }
111   TIter   next(&fGraphs);
112 }
113
114 //____________________________________________________________________
115 void
116 AliFMDPattern::Detector::Clear() 
117 {
118   fCounts.Reset(0);
119 }
120
121 //____________________________________________________________________
122 void
123 AliFMDPattern::Detector::End()
124 {
125   TIter   next(&fGraphs);
126   TGraph* g = 0;
127   Int_t   i = 0;
128   while ((g = static_cast<TGraph*>(next()))) g->Set(fCounts[i++]);
129 }
130 //____________________________________________________________________
131 void
132 AliFMDPattern::Detector::AddMarker(Double_t x, Double_t y, Float_t s, 
133                                    Float_t max)
134 {
135   Int_t i = TMath::Min(Int_t(fCounts.fN * s / max), 
136                        Int_t(fGraphs.GetEntries()-1));
137   TGraph* g = static_cast<TGraph*>(fGraphs.At(i));
138   if (!g) return;
139   g->SetPoint(fCounts[i]++, x, y);
140 }
141
142
143 //____________________________________________________________________
144 AliFMDPattern::AliFMDPattern(const char* gAliceFile)
145   : AliFMDDisplay(kTRUE, gAliceFile),
146     fInnerMax(0), 
147     fOuterMax(0),
148     fFMD1Pad(0),
149     fFMD1(1),
150     fFMD2Pad(0),
151     fFMD2(2),
152     fFMD3Pad(0),
153     fFMD3(3),
154     fEvent(.1, .8, "Event #"),
155     fFMD1Sum(.2, .7, "# in FMD1: "),
156     fFMD2Sum(.2, .6, "# in FMD2: "),
157     fFMD3Sum(.2, .5, "# in FMD3: "),
158     fLine(.15, .47, .85, .47),
159     fTotal(.2, .35, "Total:   ")
160 {
161   // RemoveLoad(kGeometry);
162   fEvent.SetBit(TLatex::kTextNDC);
163   fFMD1Sum.SetBit(TLatex::kTextNDC);
164   fFMD2Sum.SetBit(TLatex::kTextNDC);
165   fFMD3Sum.SetBit(TLatex::kTextNDC);
166   fLine.SetBit(TLine::kLineNDC);
167   fTotal.SetBit(TLatex::kTextNDC);
168 }
169
170 //____________________________________________________________________
171 AliFMDPattern::~AliFMDPattern()
172 {
173   fInners.Delete();
174   fOuters.Delete();
175 }
176
177     
178 //____________________________________________________________________
179 Bool_t 
180 AliFMDPattern::Init()
181 {
182   // Initialize.  GEt transforms and such, 
183   if (!AliFMDInput::Init()) return kFALSE;
184   AliFMDGeometry* geom = AliFMDGeometry::Instance();
185   geom->Init();
186   geom->InitTransformations();
187   
188   Char_t rs[] = { 'I' , 'O', '\0' };
189   Char_t *r   = rs;
190   do {
191     AliFMDRing* ring = geom->GetRing(*r);
192     if (!ring) continue;
193     const TObjArray& vs = ring->GetVerticies();
194     TObjArray&       gs = (*r == 'I' ? fInners   : fOuters);
195     Float_t&         mr = (*r == 'I' ? fInnerMax : fOuterMax);
196     Int_t            nm = ring->GetNModules();
197     AliInfo(Form("Making %d modules for %c", nm, *r));
198     for (Int_t m = 0; m < nm; m++) {
199       Int_t          nv = vs.GetEntries();
200       Double_t       a  = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
201       TGraph*        g  = new TGraph(nv+1);
202       Double_t       x0 = 0, y0 = 0;
203       gs.AddAtAndExpand(g, m);
204       for (Int_t c = 0; c < nv; c++) {
205         TVector2* v = static_cast<TVector2*>(vs.At(c));
206         mr          = TMath::Max(mr, Float_t(v->Mod()));
207         TVector2  w(v->Rotate(a));
208         if (c == 0) { x0 = w.X(); y0 = w.Y(); }
209         g->SetPoint(c, w.X(), w.Y());
210       }
211       g->SetName(Form("FMDX%c_%02d", *r, m));
212       g->SetPoint(nv, x0, y0);
213       g->SetFillColor((*rs == 'I' ? 
214                        (m % 2 == 0 ? 18 : 17) :
215                        (m % 2 == 0 ? 20 : 23)));
216       g->SetFillStyle(3001);
217       g->SetLineColor(1);
218       g->SetLineWidth(1);
219       g->SetLineStyle(2);
220     }
221   } while (*(++r));
222     
223   return kTRUE;
224 }
225
226 //____________________________________________________________________
227 Bool_t 
228 AliFMDPattern::Begin(Int_t event) 
229 {
230   MakeAux();
231   if (!fCanvas) {
232     const char* which[] = { "Continue", "Redisplay", 0 };
233     MakeCanvas(which);
234     
235     AliFMDGeometry* geom = AliFMDGeometry::Instance();
236     AliFMDDetector* det;
237     if ((det = geom->GetDetector(1))) {
238       fPad->cd();
239       fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
240       fFMD1Pad->Draw();
241       fFMD1Pad->cd();
242       fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
243     }
244     if ((det = geom->GetDetector(2))) {
245       fPad->cd();
246       fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
247       fFMD2Pad->Draw();
248       fFMD2Pad->cd();
249       fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
250     }
251     if ((det = geom->GetDetector(3))) {
252       fPad->cd();
253       fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
254       fFMD3Pad->Draw();
255       fFMD3Pad->cd();
256       fFMD3.Begin(-1, fOuterMax, fInners, fOuters);
257     }
258     fPad->cd();
259     fSummary = new TPad("display", "Display", 0.5, 0.0, 1.0, 0.5, 0, 0);
260     fSummary->Draw();
261     fSummary->cd();
262     fEvent.Draw();
263     fFMD1Sum.Draw();
264     fFMD2Sum.Draw();
265     fFMD3Sum.Draw();
266     fLine.Draw();
267     fTotal.Draw();
268   }
269   fEvent.SetTitle(Form("Event # %6d", event));
270
271   fCanvas->Modified();
272   fCanvas->Update();
273   fCanvas->cd();
274   fFMD1.Clear();
275   fFMD2.Clear();
276   fFMD3.Clear();
277   return AliFMDInput::Begin(event);
278 }
279
280 //____________________________________________________________________
281 void
282 AliFMDPattern::Redisplay()
283 {
284   fFMD1.Clear();
285   fFMD2.Clear();
286   fFMD3.Clear();
287   AliFMDDisplay::Redisplay();
288 }
289
290 //____________________________________________________________________
291 void
292 AliFMDPattern::AtEnd()
293 {
294   DrawAux();
295   
296   Int_t total = 0;
297   
298   fFMD1.End();
299   fFMD1Pad->Modified();
300   fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d", fFMD1.Total()));
301   total += fFMD1.Total();
302
303   fFMD2.End();
304   fFMD2Pad->Modified();
305   fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d", fFMD2.Total()));
306   total += fFMD2.Total();
307
308   fFMD3.End();
309   fFMD3Pad->Modified();
310   fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d", fFMD3.Total()));
311   total += fFMD3.Total();
312
313   fTotal.SetTitle(Form("Total:    %5d/51200 (%3d%%)", 
314                       total, Int_t(100. / 51200 * total)));
315   fSummary->Modified();
316   fCanvas->Modified();
317   fCanvas->Update();
318   fCanvas->cd();
319 }
320
321 //____________________________________________________________________
322 Bool_t 
323 AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*) 
324 {
325   switch (hit->Detector()) {
326   case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), 1); break;
327   case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), 1); break;
328   case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), 1); break;
329   }
330   return kTRUE;
331 }
332
333
334 //____________________________________________________________________
335 void
336 AliFMDPattern::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
337                          TObject*, Float_t s, Float_t max)
338 {
339   // Add a marker to the display
340   //
341   //    det     Detector
342   //    rng     Ring
343   //    sec     Sector 
344   //    str     Strip
345   //    o       Object to refer to
346   //    s       Signal 
347   //    max     Maximum of signal 
348   //
349   Detector* d = 0;
350   switch (det) {
351   case 1: d = &fFMD1; break;
352   case 2: d = &fFMD2; break;
353   case 3: d = &fFMD3; break;
354   }
355   if (!d) return;
356   AliFMDGeometry*   geom = AliFMDGeometry::Instance();
357   Double_t x, y, z;
358   geom->Detector2XYZ(det, rng, sec, str, x, y, z);
359   if (true) {
360     AliFMDRing* r  = geom->GetRing(rng);
361     Double_t    t  = .9 * r->GetTheta() / 2;
362     Double_t    a  = gRandom->Uniform(-t,t) * TMath::Pi() / 180;
363     Double_t    x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
364     Double_t    y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
365     x = x1;
366     y = y1;
367   }
368   d->AddMarker(x, y, s, max);
369 }
370
371 //____________________________________________________________________
372 //
373 // EOF
374 //