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