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