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