]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDFancy.cxx
bug fix of bug fix
[u/mrichter/AliRoot.git] / FMD / AliFMDFancy.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    AliFMDFancy.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
32 #include <iomanip>
33 #include <iostream>
34
35 #include <TApplication.h>
36 // #include <TButton.h>
37 #include <TCanvas.h>
38 #include <TH2F.h>
39 // #include <TH3F.h>
40 #include <TLatex.h>
41 #include <TLine.h>
42 #include <TMath.h>
43 #include <TRandom.h>
44 // #include <TStyle.h>
45 #include <TSystem.h>
46 #include <TVector2.h>
47 // #include <TView.h>
48
49 #include "AliFMDDetector.h"
50 #include "AliFMDFancy.h"        // ALIFMDDISPLAY_H
51 #include "AliFMDGeometry.h"     // ALIFMDGEOMETRY_H
52 #include "AliFMDHit.h"
53 // #include "AliFMDParameters.h"        // ALIFMDPARAMETERS_H
54 #include "AliFMDRing.h"
55
56 //____________________________________________________________________
57 ClassImp(AliFMDFancy)
58 #if 0
59   ; // This is here to keep Emacs for indenting the next line
60 #endif
61
62 //____________________________________________________________________
63 AliFMDFancy::AliFMDFancy(const char* gAliceFile)
64   : AliFMDDisplay(kTRUE, gAliceFile),
65     fFMD1Pad(0),
66     fFMD1(1),
67     fFMD2Pad(0),
68     fFMD2(2),
69     fFMD3Pad(0),
70     fFMD3(3),
71     fSummary(0),
72     fEvent(.1, .8, "Event #"),
73     fFMD1IHits(.2, .7, "# in FMD1I: "),
74     fFMD2IHits(.2, .6, "# in FMD2I: "),
75     fFMD2OHits(.2, .5, "# in FMD2O: "),
76     fFMD3IHits(.2, .4, "# in FMD3I: "),
77     fFMD3OHits(.2, .3, "# in FMD3O: "),
78     fLine(.15, .27, .85, .27),
79     fTotal(.2, .15, "Total:   ")
80 {
81   // CTOR 
82   fEvent.SetBit(TLatex::kTextNDC);
83   fFMD1IHits.SetBit(TLatex::kTextNDC);
84   fFMD2IHits.SetBit(TLatex::kTextNDC);
85   fFMD2OHits.SetBit(TLatex::kTextNDC);
86   fFMD3IHits.SetBit(TLatex::kTextNDC);
87   fFMD3OHits.SetBit(TLatex::kTextNDC);
88   fLine.SetBit(TLine::kLineNDC);
89   fTotal.SetBit(TLatex::kTextNDC);
90 }
91
92 //____________________________________________________________________
93 AliFMDFancy::AliFancyDetector::AliFancyDetector(UShort_t id)
94   : fFrame(0),
95     fId(id), 
96     fShapes(0),
97     fNInnerHits(0), 
98     fInnerHits(0),
99     fNOuterHits(0), 
100     fOuterHits(0),
101     fMaxR(0), 
102     fMinZ(0), 
103     fMaxZ(0)
104 {
105   // CTOR 
106   fInnerHits.SetName(Form("FMD%dI", id));
107   fInnerHits.SetMarkerStyle(1); // 20);
108   fInnerHits.SetMarkerSize(.2);
109   fInnerHits.SetMarkerColor(50); // 12);
110   fOuterHits.SetName(Form("FMD%dO", id));
111   fOuterHits.SetMarkerStyle(1); // 20);
112   fOuterHits.SetMarkerSize(.2);
113   fOuterHits.SetMarkerColor(50); // 12);
114 }
115
116 //____________________________________________________________________
117 AliFMDFancy::AliFancyDetector::~AliFancyDetector()
118 {
119   // DTOR 
120   fShapes.Delete();
121   if (fFrame) delete fFrame;
122 }
123
124 //____________________________________________________________________
125 AliFMDFancy::~AliFMDFancy()
126 {
127   // DTOR 
128 }
129
130 //____________________________________________________________________
131 void
132 AliFMDFancy::AliFancyDetector::AddHistogram(TGraph2D& g, const char* opt)
133 {
134   // CTOR 
135   TH2* h = g.GetHistogram(opt);
136   if (!h) return;
137   // Code checker doesn't think this using the TH2 interface -
138   // ridiculous. 
139   h->SetBins(1, -fMaxR, fMaxR, 1, -fMaxR, fMaxR);
140   h->GetZaxis()->SetRangeUser(fMinZ, fMaxZ);
141 }
142
143   
144
145 //____________________________________________________________________
146 void
147 AliFMDFancy::AliFancyDetector::Init()
148 {
149   // Initialise 
150   AliFMDGeometry* geom = AliFMDGeometry::Instance();
151   AliFMDDetector* det  = geom->GetDetector(fId);
152   if (!det) return;
153   Char_t   rs[]   = { 'I' , 'O', '\0' };
154   Char_t*  rp     = rs;
155   Char_t   r;
156   Double_t maxR = 0;
157   Double_t minZ = 10000;
158   Double_t maxZ = -10000;
159   Int_t    ns   = 0;
160   while ((r = *(rp++))) {
161     AliFMDRing* ring = det->GetRing(r);
162     if (!ring) continue;
163     // if (r == 'O') continue;
164     const TObjArray& vs = ring->GetVerticies();
165     Int_t            nm = ring->GetNModules();
166     Double_t         zd = (r == 'I' ? det->GetInnerZ() : det->GetOuterZ());
167     for (Int_t m = 0; m < nm; m++) {
168       Int_t          nv = vs.GetEntries();
169       Double_t       a  = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
170       TGraph2D*      g  = new TGraph2D(nv);
171       Double_t       x0 = 0, y0 = 0, z0 = 0;
172       Double_t       z  = zd + (m % 2==0 ? 0 : 
173                                 TMath::Sign(ring->GetModuleSpacing(), zd));
174       minZ              = TMath::Min(minZ, z);
175       maxZ              = TMath::Max(maxZ, z);
176       g->SetName(Form("FMD%d%cM%02d", fId, r, m));
177       fShapes.AddAtAndExpand(g, ns++);
178       for (Int_t c = 0; c < nv; c++) {
179         TVector2* v = static_cast<TVector2*>(vs.At(nv - 1 - c));
180         TVector2  w(v->Rotate(a));
181         if (c == 0) { x0 = w.X(); y0 = w.Y(); z0 = z; }
182         g->SetPoint(c, w.X(), w.Y(), z);
183         maxR        = TMath::Max(maxR, v->Mod());
184       }
185       //g->SetPoint(nv, x0, y0, z0);
186       g->SetFillColor(2);
187       g->SetFillStyle(3002);
188       g->SetLineColor(2);
189       g->SetLineWidth(1);
190     }
191   }
192   fMaxR = 1.05 * maxR;
193   fMinZ = (minZ  > 0 ? 0.95 * minZ : 1.05 * minZ);
194   fMaxZ = (maxZ  > 0 ? 1.05 * maxZ : 0.95 * maxZ);
195
196   TIter next(&fShapes);
197   TGraph2D* g = 0;
198   while ((g = static_cast<TGraph2D*>(next()))) AddHistogram(*g);
199   if (det->GetInner()) AddHistogram(fInnerHits);
200   if (det->GetOuter()) AddHistogram(fOuterHits);
201
202   fFrame = new TH2F(Form("FMD%d", fId), Form("FMD%d", fId), 
203                     1, -fMaxR, fMaxR, 1, -fMaxR, fMaxR);
204   fFrame->SetStats(kFALSE);
205   fFrame->GetXaxis()->SetTitle("x [cm]");
206   fFrame->GetYaxis()->SetTitle("y [cm]");
207   fFrame->GetZaxis()->SetTitle("z [cm]");
208   fFrame->SetDirectory(0);
209 }
210
211   
212 //____________________________________________________________________
213 Bool_t 
214 AliFMDFancy::Init()
215 {
216   // Initialize.  GEt transforms and such, 
217   if (!AliFMDInput::Init()) return kFALSE;
218   AliFMDGeometry* geom = AliFMDGeometry::Instance();
219   geom->Init();
220   geom->InitTransformations();
221   
222   fFMD1.Init();
223   fFMD2.Init();
224   fFMD3.Init();
225   return kTRUE;
226 }
227
228 //____________________________________________________________________
229 void
230 AliFMDFancy::AliFancyDetector::Begin(Int_t /* event */)
231 {
232   // Called at the begining of an event. 
233   TIter next(&fShapes);
234   TGraph2D* g = 0;
235   fFrame->Draw("surf fb");
236   fFrame->GetZaxis()->SetRangeUser(fMinZ, fMaxZ);
237   while ((g = static_cast<TGraph2D*>(next()))) g->Draw("tri2 FB same");
238 }
239
240 //____________________________________________________________________
241 void
242 AliFMDFancy::AliFancyDetector::Clear(Int_t /* event */)
243 {
244   // Clear 
245   fNInnerHits = 0;
246   fNOuterHits = 0;
247 }
248
249   
250 //____________________________________________________________________
251 Bool_t 
252 AliFMDFancy::Begin(Int_t event) 
253 {
254   // Called at the begining of an event 
255   if (!fCanvas) {
256     const char* which[] = { "Continue", "Redisplay", 0 };
257     MakeCanvas(which);
258
259     AliFMDGeometry* geom = AliFMDGeometry::Instance();
260     AliFMDDetector* det;
261     if ((det = geom->GetDetector(1))) {
262       fPad->cd();
263       fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
264       fFMD1Pad->Draw();
265       fFMD1Pad->cd();
266       fFMD1.Begin(event);
267     }
268     if ((det = geom->GetDetector(2))) {
269       fPad->cd();
270       fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
271       fFMD2Pad->Draw();
272       fFMD2Pad->cd();
273       fFMD2.Begin(event);
274     }
275     if ((det = geom->GetDetector(3))) {
276       fPad->cd();
277       fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.05, .5, .5, 0, 0);
278       fFMD3Pad->Draw();
279       fFMD3Pad->cd();
280       fFMD3.Begin(event);
281     }
282     fPad->cd();
283     fSummary = new TPad("display", "Display", 0.5, 0.05, 1.0, 0.5, 0, 0);
284     fSummary->Draw();
285     fSummary->cd();
286     fEvent.Draw();
287     fFMD1IHits.Draw();
288     fFMD2IHits.Draw();
289     fFMD2OHits.Draw();
290     fFMD3IHits.Draw();
291     fFMD3OHits.Draw();
292     fLine.Draw();
293     fTotal.Draw();
294   }
295   fEvent.SetTitle(Form("Event # %6d", event));
296   // fEvent.Modify();
297   fCanvas->Modified();
298   fCanvas->Update();
299   fCanvas->cd();
300   fFMD1.Clear(event);
301   fFMD2.Clear(event);
302   fFMD3.Clear(event);
303   return AliFMDInput::Begin(event);
304 }
305
306 //____________________________________________________________________
307 void
308 AliFMDFancy::AliFancyDetector::End()
309 {
310   // Called at the end of an event 
311   Char_t  rs[] = { 'I', 'O', '\0' };
312   Char_t* rp   = rs;
313   Char_t  r;
314   while ((r = *(rp++))) {
315     TGraph2D& g = (r == 'I' ? fInnerHits : fOuterHits);
316     Int_t&    n = (r == 'I' ? fNInnerHits : fNOuterHits);
317     Int_t     m = (r == 'I' ? 512 * 10 * 2 : 256 * 20 * 2);
318     if (n == 0) continue;
319     for (Int_t i = n; i < g.GetN(); i++)  g.RemovePoint(i);
320     // The code checker thinks this is not using declarations from
321     // iostram and iomanip - that's just silly. 
322     std::cout << g.GetName() << " has " << std::setw(4) << n << "/" 
323               << std::setw(5) << m << " points" << std::endl;
324     g.Draw("same fb p");
325     AddHistogram(g, "empty");
326   }
327 }
328
329 //____________________________________________________________________
330 Bool_t 
331 AliFMDFancy::End() 
332 {
333   // Called at the end of an event 
334   AliFMDGeometry* geom = AliFMDGeometry::Instance();
335   AliFMDDetector* det;
336   Int_t total = 0;
337   if ((det = geom->GetDetector(1))) {
338     fFMD1Pad->cd();
339     fFMD1.End();
340     fFMD1Pad->Modified();
341     fFMD1IHits.SetTitle(Form("# hits in FMD1I:  %5d", fFMD1.fNInnerHits));
342     total += fFMD1.fNInnerHits;
343   }
344   if ((det = geom->GetDetector(2))) {
345     fFMD2Pad->cd();
346     fFMD2.End();
347     fFMD2Pad->Modified();
348     fFMD2IHits.SetTitle(Form("# hits in FMD2I:  %5d", fFMD2.fNInnerHits));
349     fFMD2OHits.SetTitle(Form("# hits in FMD2O: %5d", fFMD2.fNOuterHits));
350     total += fFMD2.fNInnerHits;
351     total += fFMD2.fNOuterHits;    
352   }
353   if ((det = geom->GetDetector(3))) {
354     fFMD3Pad->cd();
355     fFMD3.End();
356     fFMD3Pad->Modified();
357     fFMD3IHits.SetTitle(Form("# hits in FMD3I:  %5d", fFMD3.fNInnerHits));
358     fFMD3OHits.SetTitle(Form("# hits in FMD3O: %5d", fFMD3.fNOuterHits));
359     total += fFMD3.fNInnerHits;
360     total += fFMD3.fNOuterHits;    
361   }
362   fTotal.SetTitle(Form("Total:    %5d/51200 (%3d%%)", 
363                       total, Int_t(100. / 51200 * total)));
364   fSummary->Modified();
365   fCanvas->Modified();
366   fCanvas->Update();
367   fCanvas->cd();
368   fWait = kTRUE;
369   while (fWait) {
370     // Hmm - code checker doesn't believe this is using the
371     // TApplication or TSystem declaration - morron.  Thank God for
372     // optimising compilers. 
373     TApplication* a = gApplication;
374     TSystem*      s = gSystem;
375     a->StartIdleing();
376     s->InnerLoop();
377     a->StopIdleing();
378   }
379   return AliFMDInput::End();
380 }
381
382 //____________________________________________________________________
383 Bool_t 
384 AliFMDFancy::ProcessHit(AliFMDHit* hit, TParticle*) 
385 {
386   // Process a hit. 
387   AddMarker(hit->Detector(), hit->Ring(), hit->Sector(), hit->Strip(), 
388             hit, hit->Edep(), 0, 20);
389   return kTRUE;
390 }
391 //____________________________________________________________________
392 void
393 AliFMDFancy::AliFancyDetector::AddMarker(Char_t rng, UShort_t sec,
394                                          UShort_t str, Float_t, Float_t)
395 {
396   // Add a marker to the display 
397   AliFMDGeometry*   geom = AliFMDGeometry::Instance();
398   Double_t x, y, z;
399   geom->Detector2XYZ(fId, rng, sec, str, x, y, z);
400   // Trick the code-checker to think that we're using the TRandom
401   // interface.  The silly code checker also thinks that TMath is a
402   // class and not a namespace - sigh!
403   TRandom* rand = gRandom;
404   if (true) {
405     AliFMDRing* r  = geom->GetRing(rng);
406     Double_t    t  = .9 * r->GetTheta() / 2;
407     Double_t    a  = rand->Uniform(-t,t) * TMath::Pi() / 180;
408     Double_t    x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
409     Double_t    y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
410     x = x1;
411     y = y1;
412   }
413   switch (rng) {
414   case 'I':
415   case 'i': fInnerHits.SetPoint(fNInnerHits++, x, y, z); break;
416   case 'O': 
417   case 'o': fOuterHits.SetPoint(fNOuterHits++, x, y, z); break;
418   default:  return;
419   }
420 }
421
422     
423
424 //____________________________________________________________________
425 void
426 AliFMDFancy::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
427                        TObject*, Float_t, Float_t, Float_t)
428 {
429   // Add a marker to the display
430   //
431   //    det     Detector
432   //    rng     Ring
433   //    sec     Sector 
434   //    str     Strip
435   //    o       Object to refer to
436   //    s       Signal 
437   //    max     Maximum of signal 
438   //
439   switch (det) {
440   case 1: fFMD1.AddMarker(rng,sec,str,0,0); break;
441   case 2: fFMD2.AddMarker(rng,sec,str,0,0); break;
442   case 3: fFMD3.AddMarker(rng,sec,str,0,0); break;
443   }
444 }
445
446 //____________________________________________________________________
447 //
448 // EOF
449 //