]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDPattern.cxx
moving FMD1 1.5 cm forward. Better eta coverage...
[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
32 #include <iostream>
33
34 // #include <TApplication.h>
35 // #include <TButton.h>
36 #include <TCanvas.h>
37 #include <TH2F.h>
38 #include <TMath.h>
39 #include <TPad.h>
40 #include <TRandom.h>
41 // #include <TSlider.h>
42 #include <TStyle.h>
43 // #include <TSystem.h>
44 #include <TVector2.h>
45 // #include <TView.h>
46 #include <TGraph.h>
47 #include "AliFMDPattern.h"      // ALIFMDDISPLAY_H
48 #include "AliFMDGeometry.h"     // ALIFMDGEOMETRY_H
49 //#include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
50 #include "AliFMDRing.h"
51 // #include "AliFMDDetector.h"
52 #include "AliFMDHit.h"
53 // #include <AliLog.h>
54 #include "AliFMDDebug.h" // Better debug macros
55 class AliFMDDetector;
56
57 //____________________________________________________________________
58 ClassImp(AliFMDPattern)
59 #if 0
60   ; // This is here to keep Emacs for indenting the next line
61 #endif
62
63 //____________________________________________________________________
64 AliFMDPattern::AliFMDPatternDetector::AliFMDPatternDetector(UShort_t id) 
65   : fId(id),
66     fCounts(0), 
67     fGraphs(0), 
68     fFrame(0), 
69     fInners(10), 
70     fOuters(id == 1 ? 0 : 20)
71 {
72   // CTOR 
73   // 
74   // Parameters: 
75   // 
76   //   ID       Identifier 
77 }
78
79 //____________________________________________________________________
80 AliFMDPattern::AliFMDPatternDetector::~AliFMDPatternDetector()
81 {
82   // DTOR 
83   // Destructor - 
84   // deletes mother frame 
85   if (fFrame) delete fFrame;
86 }
87
88 //____________________________________________________________________
89 void
90 AliFMDPattern::AliFMDPatternDetector::DrawShape(TObjArray& a) 
91 {
92   // Draw all shapes. 
93   // 
94   // Paramters 
95   // 
96   //    a       Array of shapes 
97   //
98   TIter next(&a);
99   TGraph* g = 0;
100   while ((g = static_cast<TGraph*>(next()))) {
101     g->DrawClone("f same");
102     g->DrawClone("l same");
103   }
104 }
105
106 //____________________________________________________________________
107 void
108 AliFMDPattern::AliFMDPatternDetector::CopyShapes(TObjArray& src, 
109                                                  TObjArray& dest, 
110                                                  Double_t ang, 
111                                                  Double_t fx, 
112                                                  Double_t fy)
113 {
114   TIter     next(&src);
115   TGraph*   g = 0;
116   while ((g = static_cast<TGraph*>(next()))) { 
117     TGraph* gg = new TGraph(*g);
118     Double_t* x  = gg->GetX();
119     Double_t* y  = gg->GetY();
120     for (Int_t i = 0; i < gg->GetN(); i++) { 
121       Float_t xx = x[i] * TMath::Cos(ang) - y[i] * TMath::Sin(ang);
122       Float_t yy = x[i] * TMath::Sin(ang) + y[i] * TMath::Cos(ang);
123       gg->SetPoint(i, fx * xx, fy * yy);
124     }
125     gg->SetFillStyle(g->GetFillStyle());
126     gg->SetFillColor(g->GetFillColor());
127     gg->SetLineStyle(g->GetLineStyle());
128     gg->SetLineColor(g->GetLineColor());
129     gg->SetLineWidth(g->GetLineWidth());
130     gg->SetMarkerStyle(g->GetMarkerStyle());
131     gg->SetMarkerColor(g->GetMarkerColor());
132     gg->SetMarkerSize(g->GetMarkerSize());
133     TString name(g->GetName());
134     name.ReplaceAll("X", Form("%d",fId));
135     gg->SetName(name.Data());
136     TString title(g->GetTitle());
137     title.ReplaceAll("X", Form("%d",fId));
138     gg->SetTitle(title.Data());
139     dest.Add(gg);
140   }
141   dest.SetOwner();
142 }
143
144 //____________________________________________________________________
145 void
146 AliFMDPattern::AliFMDPatternDetector::Begin(Int_t      nlevel, 
147                                             Double_t   r, 
148                                             TObjArray& inners, 
149                                             TObjArray& outers)
150 {
151   // Start of a run. 
152   // 
153   // Parameters 
154   // 
155   //    nlevel          Number of levels 
156   //    r               Radius 
157   //    inners          Array of inner shapes 
158   //    outers          Array of outer shapes 
159   //
160
161   // To make code-checker shut up
162   TStyle* style = gStyle;  
163   if (nlevel < 1) nlevel = style->GetNumberOfColors();
164   fCounts.Set(nlevel);
165   Double_t rr = 1.05 * r;
166   if (!fFrame) {
167     // The code-checker thinks this is not using the declaration of
168     // TH2F - what a morron!   
169     fFrame = new TH2F(Form("fmd%dFrame", fId), Form("FMD%d", fId), 
170                       100, -rr, rr, 100, -rr, rr);
171     fFrame->SetStats(kFALSE);
172     fFrame->Draw();
173   }
174   Double_t ang = (fId == 1 ? -TMath::Pi() / 2 : 0);
175   Double_t fx  = (fId == 3 ? -1               : 1); // Flip around Y
176   Double_t fy  = (fId == 1 ?  1               : 1); // Flip around X
177   
178   CopyShapes(inners, fInners, ang, fx, fy);
179   DrawShape(fInners);
180   if (fId != 1) { 
181     CopyShapes(outers, fOuters, ang, fx, fy);
182     DrawShape(fOuters);
183   }
184
185   for (Int_t i = 0; i < nlevel; i++) { 
186     TGraph* g = new TGraph;
187     Int_t idx = Int_t(Float_t(i) / nlevel * style->GetNumberOfColors());
188     Int_t col = style->GetColorPalette(idx);
189     g->SetName(Form("FMD%d_L%02d", fId, i));
190     g->SetMarkerColor(col);
191     g->SetLineColor(col);
192     g->SetFillColor(col);
193     g->SetMarkerSize(i * .2 + .2);
194     g->SetMarkerStyle(2);
195     g->SetEditable(kFALSE);
196     g->Draw("same p");
197     fGraphs.AddAtAndExpand(g, i);
198   }
199   // TIter   next(&fGraphs);
200 }
201
202 //____________________________________________________________________
203 void
204 AliFMDPattern::AliFMDPatternDetector::Clear() 
205 {
206   // Clear this display.  
207   // Simply reset counters to zero. 
208   // Avoid deleting memory. 
209   fCounts.Reset(0);
210 }
211
212 //____________________________________________________________________
213 void
214 AliFMDPattern::AliFMDPatternDetector::End()
215 {
216   // Called when displaying the data.  
217   // Simply resets number of points at each level to 
218   // the seen number of hits at that level. 
219   // Avoid deleting memory. 
220   TIter   next(&fGraphs);
221   TGraph* g = 0;
222   Int_t   i = 0;
223   while ((g = static_cast<TGraph*>(next()))) { 
224     Int_t cnt = fCounts[i++];
225     if (cnt > 0) { 
226       g->Set(cnt);
227       g->SetMarkerSize(i * .2 + .2);
228     }
229     else {
230       g->SetPoint(0,0,0);
231       g->SetMarkerSize(0);
232     }
233   }
234   
235 }
236 //____________________________________________________________________
237 void
238 AliFMDPattern::AliFMDPatternDetector::AddMarker(Double_t x, 
239                                                 Double_t y, 
240                                                 Float_t  s, 
241                                                 Float_t  max)
242 {
243   // Add a marker at (X,Y,Z).  The marker color and size is chosen
244   // relative to the MAX argument. 
245   // 
246   // Parameters 
247   // 
248   //    X,Y,Z           Coordiantes 
249   //    MAX             Maximum value. 
250   // 
251   /** Sigh, for some odd reason, the code-checker does not recognise
252       this a usage of the TMath namespace declaration! Idiot */
253   Int_t i = TMath::Min(Int_t(fCounts.fN * s / max),  
254                        Int_t(fGraphs.GetEntries()-1));
255   if (i < 0 || i >= fCounts.fN) { 
256     std::cerr << "Graph index " << i << " out of bounds [0," 
257               << fCounts.fN << ") - " 
258               << fCounts.fN << " * " << s << " / " << max << std::endl;
259     return;
260   }
261   TGraph* g = static_cast<TGraph*>(fGraphs.At(i));
262   if (!g) return;
263   g->SetPoint(fCounts[i]++, x, y);
264 }
265
266
267 //____________________________________________________________________
268 AliFMDPattern::AliFMDPattern(const char* gAliceFile)
269   : AliFMDDisplay(kTRUE, gAliceFile),
270     fInners(0), 
271     fOuters(0),
272     fInnerMax(0), 
273     fOuterMax(0),
274     fFMD1Pad(0),
275     fFMD1(1),
276     fFMD2Pad(0),
277     fFMD2(2),
278     fFMD3Pad(0),
279     fFMD3(3),
280     fSummary(0),
281     fEvent(.1, .8, "Event #"),
282     fFMD1Sum(.2, .7, "# in FMD1: "),
283     fFMD2Sum(.2, .6, "# in FMD2: "),
284     fFMD3Sum(.2, .5, "# in FMD3: "),
285     fLine(.15, .47, .85, .47),
286     fTotal(.2, .35, "Total:   "), 
287     fFMD1Area(0),
288     fFMD2Area(0),
289     fFMD3Area(0)
290 {
291   // Constructor. 
292   // 
293   // Parameters 
294   // 
295   //   gAliceFile       The galice.root file to use - if any. 
296   // 
297
298   SetName("AliFMDPattern");
299   SetName("2D display of FMD data");
300   
301   // RemoveLoad(kGeometry);
302   fEvent.SetBit(TLatex::kTextNDC);
303   fFMD1Sum.SetBit(TLatex::kTextNDC);
304   fFMD2Sum.SetBit(TLatex::kTextNDC);
305   fFMD3Sum.SetBit(TLatex::kTextNDC);
306   fLine.SetBit(TLine::kLineNDC);
307   fTotal.SetBit(TLatex::kTextNDC);
308 }
309
310 //____________________________________________________________________
311 AliFMDPattern::~AliFMDPattern()
312 {
313   // DTOR 
314   // Free all allocated shapes. 
315   // note, that most members are real objects, so we do not need to
316   // deal with them here. 
317   fInners.Delete();
318   fOuters.Delete();
319 }
320
321     
322 //____________________________________________________________________
323 Bool_t 
324 AliFMDPattern::Init()
325 {
326   // Initialize.  Get transforms and such, 
327   if (!AliFMDInput::Init()) return kFALSE;
328   AliFMDGeometry* geom = AliFMDGeometry::Instance();
329   if (!geom) return kFALSE;
330   geom->Init();
331   geom->InitTransformations();
332   
333   fFMD1Area = 0;
334   fFMD2Area = 0;
335   fFMD3Area = 0;
336
337   Double_t innerArea = 0;
338   Double_t outerArea = 0;
339
340   Char_t rs[] = { 'I' , 'O', '\0' };
341   Char_t *r   = rs;
342   do {
343     AliFMDRing* ring = geom->GetRing(*r);
344     if (!ring) continue;
345
346     Double_t rl   = ring->GetMinR();
347     Double_t rh   = ring->GetMaxR();
348     Double_t area = rh * rh * TMath::Pi() - rl * rl * TMath::Pi();
349     if (*r == 'I') innerArea = area;
350     else           outerArea = area;
351       
352
353     const TObjArray& vs = ring->GetVerticies();
354     TObjArray&       gs = (*r == 'I' ? fInners   : fOuters);
355     Float_t&         mr = (*r == 'I' ? fInnerMax : fOuterMax);
356     Int_t            nm = ring->GetNModules();
357     AliFMDDebug(1, ("Making %d modules for %c", nm, *r));
358     for (Int_t m = 0; m < nm; m++) {
359       Int_t          nv = 6; // vs.GetEntries();
360       Double_t       a  = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
361       TGraph*        g  = new TGraph(nv+1);
362       Double_t       x0 = 0, y0 = 0;
363       gs.AddAtAndExpand(g, m);
364       for (Int_t c = 1; c < 4; c++) {
365         TVector2* v = static_cast<TVector2*>(vs.At(c));
366         mr          = TMath::Max(mr, Float_t(v->Mod()));
367         TVector2  w(v->Rotate(a));
368         if (c == 1) { x0 = w.X(); y0 = w.Y(); }
369         g->SetPoint(c-1, w.X(), w.Y());
370       }
371       for (Int_t c = 3; c > 0; c--) {
372         TVector2* v = static_cast<TVector2*>(vs.At(c));
373         TVector2  u(-v->X(), v->Y());
374         mr          = TMath::Max(mr, Float_t(u.Mod()));
375         TVector2  w(u.Rotate(a));
376         g->SetPoint(3+(3-c), w.X(), w.Y());
377       }
378       g->SetName(Form("FMDX%c_%02d%02d", *r, 2*m,2*m+1));
379       g->SetTitle(Form("FMDX%c, sectors %d and %d", *r, 2*m,2*m+1));
380       g->SetPoint(nv, x0, y0);
381       g->SetFillColor((*rs == 'I' ? 
382                        (m % 2 == 0 ? 18 : 17) :
383                        (m % 2 == 0 ? 20 : 23)));
384       g->SetFillStyle(3001);
385       g->SetLineColor(1);
386       g->SetLineWidth(1);
387       g->SetLineStyle(2);
388     }
389   } while (*(++r));
390
391   fFMD1Area = innerArea;
392   fFMD2Area = innerArea + outerArea;
393   fFMD3Area = innerArea + outerArea;
394   
395   return kTRUE;
396 }
397
398 //____________________________________________________________________
399 Bool_t 
400 AliFMDPattern::Begin(Int_t event) 
401 {
402   // Called at the begining of an event. 
403   // 
404   // Parameters 
405   //
406   //    EVENT           The event number 
407   // 
408   MakeAux();
409   if (!fCanvas) {
410     const char* which[] = { "Continue", "Start", "Pause", "Redisplay", 0 };
411     MakeCanvas(which);
412     
413     AliFMDGeometry* geom = AliFMDGeometry::Instance();
414     // AliFMDDetector* det;
415     if ((/* det = */ geom->GetDetector(1))) {
416       fPad->cd();
417       fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
418       fFMD1Pad->Draw();
419       fFMD1Pad->cd();
420       fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
421     }
422     if ((/* det = */ geom->GetDetector(2))) {
423       fPad->cd();
424       fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
425       fFMD2Pad->Draw();
426       fFMD2Pad->cd();
427       fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
428     }
429     if ((/* det = */ geom->GetDetector(3))) {
430       fPad->cd();
431       fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
432       fFMD3Pad->Draw();
433       fFMD3Pad->cd();
434       fFMD3.Begin(-1, fOuterMax, fInners, fOuters);
435     }
436     fPad->cd();
437     fSummary = new TPad("display", "Display", 0.5, 0.0, 1.0, 0.5, 0, 0);
438     fSummary->Draw();
439     fSummary->cd();
440     fEvent.Draw();
441     fFMD1Sum.Draw();
442     fFMD2Sum.Draw();
443     fFMD3Sum.Draw();
444     fLine.Draw();
445     fTotal.Draw();
446   }
447   fEvent.SetTitle(Form("Event # %6d", event));
448
449   fCanvas->Modified();
450   fCanvas->Update();
451   fCanvas->cd();
452   fFMD1.Clear();
453   fFMD2.Clear();
454   fFMD3.Clear();
455   return AliFMDInput::Begin(event);
456 }
457
458 //____________________________________________________________________
459 void
460 AliFMDPattern::Redisplay()
461 {
462   // Redraw the displayu 
463   fFMD1.Clear();
464   fFMD2.Clear();
465   fFMD3.Clear();
466   AliFMDDisplay::Redisplay();
467 }
468
469 //____________________________________________________________________
470 void
471 AliFMDPattern::AtEnd()
472 {
473   // Called at the end of an event. 
474   DrawAux();
475   
476   Int_t total = 0;
477   
478   fFMD1.End();
479   fFMD1Pad->Modified();
480   fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d   (%4.2f /cm^{2})", 
481                          fFMD1.Total(), fFMD1.Total()/fFMD1Area));
482   total += fFMD1.Total();
483
484   fFMD2.End();
485   fFMD2Pad->Modified();
486   fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d   (%4.2f /cm^{2})", 
487                          fFMD2.Total(), fFMD2.Total()/fFMD2Area));
488   total += fFMD2.Total();
489
490   fFMD3.End();
491   fFMD3Pad->Modified();
492   fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d   (%4.2f /cm^{2})", 
493                          fFMD3.Total(), fFMD3.Total()/fFMD3Area));
494   total += fFMD3.Total();
495
496   fTotal.SetTitle(Form("Total:    %5d/51200 (%3d%%)", 
497                       total, Int_t(100. / 51200 * total)));
498   fSummary->Modified();
499   fCanvas->Modified();
500   fCanvas->Update();
501   fCanvas->cd();
502 }
503
504 //____________________________________________________________________
505 Bool_t 
506 AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*) 
507 {
508   // Process a hit. 
509   // 
510   // Parameters 
511   // 
512   //    HIT             The hit to process. 
513   // 
514   // The TParticle argument is never used. 
515   static const Float_t rMin  = fgkEdepRange.fLow;
516   static const Float_t rMax  = fgkEdepRange.fHigh;
517
518   if (!hit) { AliError("No hit");   return kFALSE; }
519   // if (!p)   { AliError("No track"); return kFALSE; }
520   Float_t  edep  = hit->Edep();
521
522   if (fHits)                        fHits->Add(hit);
523   if (fSpec)                        fSpec->Fill(edep);
524   if (InsideCut(edep, rMin, rMax) && fSpecCut) fSpecCut->Fill(edep);
525
526   switch (hit->Detector()) {
527   case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
528   case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
529   case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
530   }
531   return kTRUE;
532 }
533
534
535 //____________________________________________________________________
536 void
537 AliFMDPattern::AddMarker(UShort_t det, Char_t rng, 
538                          UShort_t sec, UShort_t str,
539                          TObject*, Float_t s, Float_t /*min*/, Float_t max)
540 {
541   // Add a marker to the display
542   //
543   //    det     Detector
544   //    rng     Ring
545   //    sec     Sector 
546   //    str     Strip
547   //    o       Object to refer to
548   //    s       Signal 
549   //    max     Maximum of signal 
550   //
551   AliFMDPatternDetector* d = 0;
552   switch (det) {
553   case 1: d = &fFMD1; break;
554   case 2: d = &fFMD2; break;
555   case 3: d = &fFMD3; break;
556   }
557   if (!d) return;
558   AliFMDGeometry*   geom = AliFMDGeometry::Instance();
559   Double_t x, y, z;
560   geom->Detector2XYZ(det, rng, sec, str, x, y, z);
561   // Make code-checker shut the f**k up 
562   TRandom* rand = gRandom;
563   if (false) {
564     AliFMDRing* r  = geom->GetRing(rng);
565     Double_t    t  = .9 * r->GetTheta() / 2;
566     Double_t    a  = rand->Uniform(-t,t) * TMath::Pi() / 180;
567     Double_t    x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
568     Double_t    y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
569     x = x1;
570     y = y1;
571   }
572   d->AddMarker(x, y, s, max);
573 }
574
575 //____________________________________________________________________
576 //
577 // EOF
578 //