]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDPattern.cxx
Removed generated files@
[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 {
296   // Constructor. 
297   // 
298   // Parameters 
299   // 
300   //   gAliceFile       The galice.root file to use - if any. 
301   // 
302
303   SetName("AliFMDPattern");
304   SetName("2D display of FMD data");
305   fPhysicsSelection = new AliPhysicsSelection();
306   // RemoveLoad(kGeometry);
307   fEvent.SetBit(TLatex::kTextNDC);
308   fFMD1Sum.SetBit(TLatex::kTextNDC);
309   fFMD2Sum.SetBit(TLatex::kTextNDC);
310   fFMD3Sum.SetBit(TLatex::kTextNDC);
311   fLine.SetBit(TLine::kLineNDC);
312   fTotal.SetBit(TLatex::kTextNDC);
313 }
314
315 //____________________________________________________________________
316 AliFMDPattern::~AliFMDPattern()
317 {
318   // DTOR 
319   // Free all allocated shapes. 
320   // note, that most members are real objects, so we do not need to
321   // deal with them here. 
322   fInners.Delete();
323   fOuters.Delete();
324 }
325
326     
327 //____________________________________________________________________
328 Bool_t 
329 AliFMDPattern::Init()
330 {
331   // Initialize.  Get transforms and such, 
332   if (!AliFMDInput::Init()) return kFALSE;
333   AliFMDGeometry* geom = AliFMDGeometry::Instance();
334   if (!geom) return kFALSE;
335   geom->Init();
336   geom->InitTransformations();
337   
338   fFMD1Area = 0;
339   fFMD2Area = 0;
340   fFMD3Area = 0;
341
342   Double_t innerArea = 0;
343   Double_t outerArea = 0;
344
345   Char_t rs[] = { 'I' , 'O', '\0' };
346   Char_t *r   = rs;
347   do {
348     AliFMDRing* ring = geom->GetRing(*r);
349     if (!ring) continue;
350
351     Double_t rl   = ring->GetMinR();
352     Double_t rh   = ring->GetMaxR();
353     Double_t area = rh * rh * TMath::Pi() - rl * rl * TMath::Pi();
354     if (*r == 'I') innerArea = area;
355     else           outerArea = area;
356       
357
358     const TObjArray& vs = ring->GetVerticies();
359     TObjArray&       gs = (*r == 'I' ? fInners   : fOuters);
360     Float_t&         mr = (*r == 'I' ? fInnerMax : fOuterMax);
361     Int_t            nm = ring->GetNModules();
362     AliFMDDebug(1, ("Making %d modules for %c", nm, *r));
363     for (Int_t m = 0; m < nm; m++) {
364       Int_t          nv = 6; // vs.GetEntries();
365       Double_t       a  = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
366       TGraph*        g  = new TGraph(nv+1);
367       Double_t       x0 = 0, y0 = 0;
368       gs.AddAtAndExpand(g, m);
369       for (Int_t c = 1; c < 4; c++) {
370         TVector2* v = static_cast<TVector2*>(vs.At(c));
371         mr          = TMath::Max(mr, Float_t(v->Mod()));
372         TVector2  w(v->Rotate(a));
373         if (c == 1) { x0 = w.X(); y0 = w.Y(); }
374         g->SetPoint(c-1, w.X(), w.Y());
375       }
376       for (Int_t c = 3; c > 0; c--) {
377         TVector2* v = static_cast<TVector2*>(vs.At(c));
378         TVector2  u(-v->X(), v->Y());
379         mr          = TMath::Max(mr, Float_t(u.Mod()));
380         TVector2  w(u.Rotate(a));
381         g->SetPoint(3+(3-c), w.X(), w.Y());
382       }
383       g->SetName(Form("FMDX%c_%02d%02d", *r, 2*m,2*m+1));
384       g->SetTitle(Form("FMDX%c, sectors %d and %d", *r, 2*m,2*m+1));
385       g->SetPoint(nv, x0, y0);
386       g->SetFillColor((*rs == 'I' ? 
387                        (m % 2 == 0 ? 18 : 17) :
388                        (m % 2 == 0 ? 20 : 23)));
389       g->SetFillStyle(3001);
390       g->SetLineColor(1);
391       g->SetLineWidth(1);
392       g->SetLineStyle(2);
393     }
394   } while (*(++r));
395
396   fFMD1Area = innerArea;
397   fFMD2Area = innerArea + outerArea;
398   fFMD3Area = innerArea + outerArea;
399   
400   return kTRUE;
401 }
402
403 //____________________________________________________________________
404 Bool_t 
405 AliFMDPattern::Begin(Int_t event) 
406 {
407   // Called at the begining of an event. 
408   // 
409   // Parameters 
410   //
411   //    EVENT           The event number 
412   // 
413   MakeAux();
414   if (!fCanvas) {
415     const char* which[] = { "Continue", "Start", "Pause", "Redisplay", 0 };
416     MakeCanvas(which);
417     
418     AliFMDGeometry* geom = AliFMDGeometry::Instance();
419     // AliFMDDetector* det;
420     if ((/* det = */ geom->GetDetector(1))) {
421       fPad->cd();
422       fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
423       fFMD1Pad->Draw();
424       fFMD1Pad->cd();
425       fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
426     }
427     if ((/* det = */ geom->GetDetector(2))) {
428       fPad->cd();
429       fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
430       fFMD2Pad->Draw();
431       fFMD2Pad->cd();
432       fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
433     }
434     if ((/* det = */ geom->GetDetector(3))) {
435       fPad->cd();
436       fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
437       fFMD3Pad->Draw();
438       fFMD3Pad->cd();
439       fFMD3.Begin(-1, fOuterMax, fInners, fOuters);
440     }
441     fPad->cd();
442     fSummary = new TPad("display", "Display", 0.5, 0.0, 1.0, 0.5, 0, 0);
443     fSummary->Draw();
444     fSummary->cd();
445     fEvent.Draw();
446     fFMD1Sum.Draw();
447     fFMD2Sum.Draw();
448     fFMD3Sum.Draw();
449     fLine.Draw();
450     fTotal.Draw();
451   }
452   fEvent.SetTitle(Form("Event # %6d", event));
453
454   fCanvas->Modified();
455   fCanvas->Update();
456   fCanvas->cd();
457   fFMD1.Clear();
458   fFMD2.Clear();
459   fFMD3.Clear();
460   
461   TString triggers = fESDEvent->GetFiredTriggerClasses();
462   const AliESDVertex* vertex = fESDEvent->GetPrimaryVertexSPD();
463   Double_t vertexXYZ[3];
464   vertex->GetXYZ(vertexXYZ);
465   const AliMultiplicity* mult = fESDEvent->GetMultiplicity();
466   Int_t nTrackLets = mult->GetNumberOfTracklets();
467   std::cout<<triggers.Data()<<"  "<<fPhysicsSelection->IsCollisionCandidate(fESDEvent)<<"    "<<nTrackLets<<"   "<<vertexXYZ[0]<<"   "<<vertexXYZ[1]<<"   "<<vertexXYZ[2]<<std::endl;
468   
469   
470   return AliFMDInput::Begin(event);
471 }
472
473 //____________________________________________________________________
474 void
475 AliFMDPattern::Redisplay()
476 {
477   // Redraw the displayu 
478   fFMD1.Clear();
479   fFMD2.Clear();
480   fFMD3.Clear();
481   AliFMDDisplay::Redisplay();
482 }
483
484 //____________________________________________________________________
485 void
486 AliFMDPattern::AtEnd()
487 {
488   // Called at the end of an event. 
489   DrawAux();
490   
491   Int_t total = 0;
492   
493   fFMD1.End();
494   fFMD1Pad->Modified();
495   fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d   (%4.2f /cm^{2})", 
496                          fFMD1.Total(), fFMD1.Total()/fFMD1Area));
497   total += fFMD1.Total();
498
499   fFMD2.End();
500   fFMD2Pad->Modified();
501   fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d   (%4.2f /cm^{2})", 
502                          fFMD2.Total(), fFMD2.Total()/fFMD2Area));
503   total += fFMD2.Total();
504
505   fFMD3.End();
506   fFMD3Pad->Modified();
507   fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d   (%4.2f /cm^{2})", 
508                          fFMD3.Total(), fFMD3.Total()/fFMD3Area));
509   total += fFMD3.Total();
510
511   fTotal.SetTitle(Form("Total:    %5d/51200 (%3d%%)", 
512                       total, Int_t(100. / 51200 * total)));
513   fSummary->Modified();
514   fCanvas->Modified();
515   fCanvas->Update();
516   fCanvas->cd();
517 }
518
519 //____________________________________________________________________
520 Bool_t 
521 AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*) 
522 {
523   // Process a hit. 
524   // 
525   // Parameters 
526   // 
527   //    HIT             The hit to process. 
528   // 
529   // The TParticle argument is never used. 
530   static const Float_t rMin  = fgkEdepRange.fLow;
531   static const Float_t rMax  = fgkEdepRange.fHigh;
532
533   if (!hit) { AliError("No hit");   return kFALSE; }
534   // if (!p)   { AliError("No track"); return kFALSE; }
535   Float_t  edep  = hit->Edep();
536
537   if (fHits)                        fHits->Add(hit);
538   if (fSpec)                        fSpec->Fill(edep);
539   if (InsideCut(edep, rMin, rMax) && fSpecCut) fSpecCut->Fill(edep);
540
541   switch (hit->Detector()) {
542   case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
543   case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
544   case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
545   }
546   return kTRUE;
547 }
548
549
550 //____________________________________________________________________
551 void
552 AliFMDPattern::AddMarker(UShort_t det, Char_t rng, 
553                          UShort_t sec, UShort_t str,
554                          TObject*, Float_t s, Float_t /*min*/, Float_t max)
555 {
556   // Add a marker to the display
557   //
558   //    det     Detector
559   //    rng     Ring
560   //    sec     Sector 
561   //    str     Strip
562   //    o       Object to refer to
563   //    s       Signal 
564   //    max     Maximum of signal 
565   //
566   AliFMDPatternDetector* d = 0;
567   switch (det) {
568   case 1: d = &fFMD1; break;
569   case 2: d = &fFMD2; break;
570   case 3: d = &fFMD3; break;
571   }
572   if (!d) return;
573   AliFMDGeometry*   geom = AliFMDGeometry::Instance();
574   Double_t x, y, z;
575   geom->Detector2XYZ(det, rng, sec, str, x, y, z);
576   // Make code-checker shut the f**k up 
577   TRandom* rand = gRandom;
578   if (false) {
579     AliFMDRing* r  = geom->GetRing(rng);
580     Double_t    t  = .9 * r->GetTheta() / 2;
581     Double_t    a  = rand->Uniform(-t,t) * TMath::Pi() / 180;
582     Double_t    x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
583     Double_t    y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
584     x = x1;
585     y = y1;
586   }
587   d->AddMarker(x, y, s, max);
588 }
589
590 //____________________________________________________________________
591 //
592 // EOF
593 //