]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDPattern.cxx
Fixed warnings pointed out by FC
[u/mrichter/AliRoot.git] / FMD / AliFMDPattern.cxx
index 8c6071bf44773350d7f720222b0a09cf0f60ecee..800ee2b66f61c0a41e463aa1da7ce6748ba1ff1c 100644 (file)
 
 #include <iostream>
 
-#include <TApplication.h>
-#include <TButton.h>
+// #include <TApplication.h>
+// #include <TButton.h>
 #include <TCanvas.h>
 #include <TH2F.h>
 #include <TMath.h>
 #include <TPad.h>
 #include <TRandom.h>
-#include <TSlider.h>
+// #include <TSlider.h>
 #include <TStyle.h>
-#include <TSystem.h>
+// #include <TSystem.h>
 #include <TVector2.h>
-#include <TView.h>
-
+// #include <TView.h>
+#include <TGraph.h>
 #include "AliFMDPattern.h"     // ALIFMDDISPLAY_H
 #include "AliFMDGeometry.h"    // ALIFMDGEOMETRY_H
-#include "AliFMDParameters.h"  // ALIFMDPARAMETERS_H
+//#include "AliFMDParameters.h"        // ALIFMDPARAMETERS_H
 #include "AliFMDRing.h"
-#include "AliFMDDetector.h"
+// #include "AliFMDDetector.h"
 #include "AliFMDHit.h"
-#include <AliLog.h>
+// #include <AliLog.h>
+#include "AliFMDDebug.h" // Better debug macros
+class AliFMDDetector;
 
 //____________________________________________________________________
 ClassImp(AliFMDPattern)
@@ -59,23 +61,40 @@ ClassImp(AliFMDPattern)
 #endif
 
 //____________________________________________________________________
-AliFMDPattern::Detector::Detector(UShort_t id) 
+AliFMDPattern::AliFMDPatternDetector::AliFMDPatternDetector(UShort_t id) 
   : fId(id),
     fCounts(0), 
     fGraphs(0), 
-    fFrame(0)
-{}
+    fFrame(0), 
+    fInners(10), 
+    fOuters(id == 1 ? 0 : 20)
+{
+  // CTOR 
+  // 
+  // Parameters: 
+  // 
+  //   ID      Identifier 
+}
 
 //____________________________________________________________________
-AliFMDPattern::Detector::~Detector()
+AliFMDPattern::AliFMDPatternDetector::~AliFMDPatternDetector()
 {
+  // DTOR 
+  // Destructor - 
+  // deletes mother frame 
   if (fFrame) delete fFrame;
 }
 
 //____________________________________________________________________
 void
-AliFMDPattern::Detector::DrawShape(TObjArray& a) 
+AliFMDPattern::AliFMDPatternDetector::DrawShape(TObjArray& a) 
 {
+  // Draw all shapes. 
+  // 
+  // Paramters 
+  // 
+  //   a       Array of shapes 
+  //
   TIter next(&a);
   TGraph* g = 0;
   while ((g = static_cast<TGraph*>(next()))) {
@@ -86,58 +105,159 @@ AliFMDPattern::Detector::DrawShape(TObjArray& a)
 
 //____________________________________________________________________
 void
-AliFMDPattern::Detector::Begin(Int_t nlevel, Double_t r, 
-                              TObjArray& inners, TObjArray& outers)
+AliFMDPattern::AliFMDPatternDetector::CopyShapes(TObjArray& src, 
+                                                TObjArray& dest, 
+                                                Double_t ang, 
+                                                Double_t fx, 
+                                                Double_t fy)
 {
-  if (nlevel < 1) nlevel = gStyle->GetNumberOfColors();
+  TIter     next(&src);
+  TGraph*   g = 0;
+  while ((g = static_cast<TGraph*>(next()))) { 
+    TGraph* gg = new TGraph(*g);
+    Double_t* x  = gg->GetX();
+    Double_t* y  = gg->GetY();
+    for (Int_t i = 0; i < gg->GetN(); i++) { 
+      Float_t xx = x[i] * TMath::Cos(ang) - y[i] * TMath::Sin(ang);
+      Float_t yy = x[i] * TMath::Sin(ang) + y[i] * TMath::Cos(ang);
+      gg->SetPoint(i, fx * xx, fy * yy);
+    }
+    gg->SetFillStyle(g->GetFillStyle());
+    gg->SetFillColor(g->GetFillColor());
+    gg->SetLineStyle(g->GetLineStyle());
+    gg->SetLineColor(g->GetLineColor());
+    gg->SetLineWidth(g->GetLineWidth());
+    gg->SetMarkerStyle(g->GetMarkerStyle());
+    gg->SetMarkerColor(g->GetMarkerColor());
+    gg->SetMarkerSize(g->GetMarkerSize());
+    TString name(g->GetName());
+    name.ReplaceAll("X", Form("%d",fId));
+    gg->SetName(name.Data());
+    TString title(g->GetTitle());
+    title.ReplaceAll("X", Form("%d",fId));
+    gg->SetTitle(title.Data());
+    dest.Add(gg);
+  }
+  dest.SetOwner();
+}
+
+//____________________________________________________________________
+void
+AliFMDPattern::AliFMDPatternDetector::Begin(Int_t      nlevel, 
+                                           Double_t   r, 
+                                           TObjArray& inners, 
+                                           TObjArray& outers)
+{
+  // Start of a run. 
+  // 
+  // Parameters 
+  // 
+  //   nlevel          Number of levels 
+  //    r              Radius 
+  //   inners          Array of inner shapes 
+  //   outers          Array of outer shapes 
+  //
+
+  // To make code-checker shut up
+  TStyle* style = gStyle;  
+  if (nlevel < 1) nlevel = style->GetNumberOfColors();
   fCounts.Set(nlevel);
+  Double_t rr = 1.05 * r;
   if (!fFrame) {
+    // The code-checker thinks this is not using the declaration of
+    // TH2F - what a morron!   
     fFrame = new TH2F(Form("fmd%dFrame", fId), Form("FMD%d", fId), 
-                     10, -r, r, 10, -r, r);
+                     100, -rr, rr, 100, -rr, rr);
     fFrame->SetStats(kFALSE);
     fFrame->Draw();
   }
-  DrawShape(inners);
-  if (fId != 1) DrawShape(outers);
+  Double_t ang = (fId == 1 ? -TMath::Pi() / 2 : 0);
+  Double_t fx  = (fId == 3 ? -1               : 1); // Flip around Y
+  Double_t fy  = (fId == 1 ?  1               : 1); // Flip around X
+  
+  CopyShapes(inners, fInners, ang, fx, fy);
+  DrawShape(fInners);
+  if (fId != 1) { 
+    CopyShapes(outers, fOuters, ang, fx, fy);
+    DrawShape(fOuters);
+  }
+
   for (Int_t i = 0; i < nlevel; i++) { 
     TGraph* g = new TGraph;
-    Int_t idx = Int_t(Float_t(i) / nlevel * gStyle->GetNumberOfColors());
-    Int_t col = gStyle->GetColorPalette(idx);
+    Int_t idx = Int_t(Float_t(i) / nlevel * style->GetNumberOfColors());
+    Int_t col = style->GetColorPalette(idx);
     g->SetName(Form("FMD%d_L%02d", fId, i));
     g->SetMarkerColor(col);
     g->SetLineColor(col);
     g->SetFillColor(col);
     g->SetMarkerSize(i * .2 + .2);
     g->SetMarkerStyle(2);
+    g->SetEditable(kFALSE);
     g->Draw("same p");
     fGraphs.AddAtAndExpand(g, i);
   }
-  TIter   next(&fGraphs);
+  // TIter   next(&fGraphs);
 }
 
 //____________________________________________________________________
 void
-AliFMDPattern::Detector::Clear() 
+AliFMDPattern::AliFMDPatternDetector::Clear() 
 {
+  // Clear this display.  
+  // Simply reset counters to zero. 
+  // Avoid deleting memory. 
   fCounts.Reset(0);
 }
 
 //____________________________________________________________________
 void
-AliFMDPattern::Detector::End()
+AliFMDPattern::AliFMDPatternDetector::End()
 {
+  // Called when displaying the data.  
+  // Simply resets number of points at each level to 
+  // the seen number of hits at that level. 
+  // Avoid deleting memory. 
   TIter   next(&fGraphs);
   TGraph* g = 0;
   Int_t   i = 0;
-  while ((g = static_cast<TGraph*>(next()))) g->Set(fCounts[i++]);
+  while ((g = static_cast<TGraph*>(next()))) { 
+    Int_t cnt = fCounts[i++];
+    if (cnt > 0) { 
+      g->Set(cnt);
+      g->SetMarkerSize(i * .2 + .2);
+    }
+    else {
+      g->SetPoint(0,0,0);
+      g->SetMarkerSize(0);
+    }
+  }
+  
 }
 //____________________________________________________________________
 void
-AliFMDPattern::Detector::AddMarker(Double_t x, Double_t y, Float_t s, 
-                                  Float_t max)
+AliFMDPattern::AliFMDPatternDetector::AddMarker(Double_t x, 
+                                               Double_t y, 
+                                               Float_t  s, 
+                                               Float_t  max)
 {
-  Int_t i = TMath::Min(Int_t(fCounts.fN * s / max), 
+  // Add a marker at (X,Y,Z).  The marker color and size is chosen
+  // relative to the MAX argument. 
+  // 
+  // Parameters 
+  // 
+  //   X,Y,Z           Coordiantes 
+  //   MAX             Maximum value. 
+  // 
+  /** Sigh, for some odd reason, the code-checker does not recognise
+      this a usage of the TMath namespace declaration! Idiot */
+  Int_t i = TMath::Min(Int_t(fCounts.fN * s / max),  
                       Int_t(fGraphs.GetEntries()-1));
+  if (i < 0 || i >= fCounts.fN) { 
+    std::cerr << "Graph index " << i << " out of bounds [0," 
+             << fCounts.fN << ") - " 
+             << fCounts.fN << " * " << s << " / " << max << std::endl;
+    return;
+  }
   TGraph* g = static_cast<TGraph*>(fGraphs.At(i));
   if (!g) return;
   g->SetPoint(fCounts[i]++, x, y);
@@ -147,6 +267,8 @@ AliFMDPattern::Detector::AddMarker(Double_t x, Double_t y, Float_t s,
 //____________________________________________________________________
 AliFMDPattern::AliFMDPattern(const char* gAliceFile)
   : AliFMDDisplay(kTRUE, gAliceFile),
+    fInners(0), 
+    fOuters(0),
     fInnerMax(0), 
     fOuterMax(0),
     fFMD1Pad(0),
@@ -155,13 +277,27 @@ AliFMDPattern::AliFMDPattern(const char* gAliceFile)
     fFMD2(2),
     fFMD3Pad(0),
     fFMD3(3),
+    fSummary(0),
     fEvent(.1, .8, "Event #"),
     fFMD1Sum(.2, .7, "# in FMD1: "),
     fFMD2Sum(.2, .6, "# in FMD2: "),
     fFMD3Sum(.2, .5, "# in FMD3: "),
     fLine(.15, .47, .85, .47),
-    fTotal(.2, .35, "Total:   ")
+    fTotal(.2, .35, "Total:   "), 
+    fFMD1Area(0),
+    fFMD2Area(0),
+    fFMD3Area(0)
 {
+  // Constructor. 
+  // 
+  // Parameters 
+  // 
+  //   gAliceFile      The galice.root file to use - if any. 
+  // 
+
+  SetName("AliFMDPattern");
+  SetName("2D display of FMD data");
+  
   // RemoveLoad(kGeometry);
   fEvent.SetBit(TLatex::kTextNDC);
   fFMD1Sum.SetBit(TLatex::kTextNDC);
@@ -174,6 +310,10 @@ AliFMDPattern::AliFMDPattern(const char* gAliceFile)
 //____________________________________________________________________
 AliFMDPattern::~AliFMDPattern()
 {
+  // DTOR 
+  // Free all allocated shapes. 
+  // note, that most members are real objects, so we do not need to
+  // deal with them here. 
   fInners.Delete();
   fOuters.Delete();
 }
@@ -183,36 +323,60 @@ AliFMDPattern::~AliFMDPattern()
 Bool_t 
 AliFMDPattern::Init()
 {
-  // Initialize.  GEt transforms and such, 
+  // Initialize.  Get transforms and such, 
   if (!AliFMDInput::Init()) return kFALSE;
   AliFMDGeometry* geom = AliFMDGeometry::Instance();
+  if (!geom) return kFALSE;
   geom->Init();
   geom->InitTransformations();
   
+  fFMD1Area = 0;
+  fFMD2Area = 0;
+  fFMD3Area = 0;
+
+  Double_t innerArea = 0;
+  Double_t outerArea = 0;
+
   Char_t rs[] = { 'I' , 'O', '\0' };
   Char_t *r   = rs;
   do {
     AliFMDRing* ring = geom->GetRing(*r);
     if (!ring) continue;
+
+    Double_t rl   = ring->GetMinR();
+    Double_t rh   = ring->GetMaxR();
+    Double_t area = rh * rh * TMath::Pi() - rl * rl * TMath::Pi();
+    if (*r == 'I') innerArea = area;
+    else           outerArea = area;
+      
+
     const TObjArray& vs = ring->GetVerticies();
     TObjArray&       gs = (*r == 'I' ? fInners   : fOuters);
     Float_t&         mr = (*r == 'I' ? fInnerMax : fOuterMax);
     Int_t            nm = ring->GetNModules();
-    AliInfo(Form("Making %d modules for %c", nm, *r));
+    AliFMDDebug(1, ("Making %d modules for %c", nm, *r));
     for (Int_t m = 0; m < nm; m++) {
-      Int_t          nv = vs.GetEntries();
+      Int_t          nv = 6; // vs.GetEntries();
       Double_t       a  = TMath::Pi() / 180 * (m * 2 + 1) * ring->GetTheta();
       TGraph*        g  = new TGraph(nv+1);
       Double_t       x0 = 0, y0 = 0;
       gs.AddAtAndExpand(g, m);
-      for (Int_t c = 0; c < nv; c++) {
+      for (Int_t c = 1; c < 4; c++) {
        TVector2* v = static_cast<TVector2*>(vs.At(c));
        mr          = TMath::Max(mr, Float_t(v->Mod()));
        TVector2  w(v->Rotate(a));
-       if (c == 0) { x0 = w.X(); y0 = w.Y(); }
-       g->SetPoint(c, w.X(), w.Y());
+       if (c == 1) { x0 = w.X(); y0 = w.Y(); }
+       g->SetPoint(c-1, w.X(), w.Y());
       }
-      g->SetName(Form("FMDX%c_%02d", *r, m));
+      for (Int_t c = 3; c > 0; c--) {
+       TVector2* v = static_cast<TVector2*>(vs.At(c));
+       TVector2  u(-v->X(), v->Y());
+       mr          = TMath::Max(mr, Float_t(u.Mod()));
+       TVector2  w(u.Rotate(a));
+       g->SetPoint(3+(3-c), w.X(), w.Y());
+      }
+      g->SetName(Form("FMDX%c_%02d%02d", *r, 2*m,2*m+1));
+      g->SetTitle(Form("FMDX%c, sectors %d and %d", *r, 2*m,2*m+1));
       g->SetPoint(nv, x0, y0);
       g->SetFillColor((*rs == 'I' ? 
                       (m % 2 == 0 ? 18 : 17) :
@@ -223,7 +387,11 @@ AliFMDPattern::Init()
       g->SetLineStyle(2);
     }
   } while (*(++r));
-    
+
+  fFMD1Area = innerArea;
+  fFMD2Area = innerArea + outerArea;
+  fFMD3Area = innerArea + outerArea;
+  
   return kTRUE;
 }
 
@@ -231,28 +399,34 @@ AliFMDPattern::Init()
 Bool_t 
 AliFMDPattern::Begin(Int_t event) 
 {
+  // Called at the begining of an event. 
+  // 
+  // Parameters 
+  //
+  //   EVENT           The event number 
+  // 
   MakeAux();
   if (!fCanvas) {
-    const char* which[] = { "Continue", "Redisplay", 0 };
+    const char* which[] = { "Continue", "Start", "Pause", "Redisplay", 0 };
     MakeCanvas(which);
     
     AliFMDGeometry* geom = AliFMDGeometry::Instance();
-    AliFMDDetector* det;
-    if ((det = geom->GetDetector(1))) {
+    // AliFMDDetector* det;
+    if ((/* det = */ geom->GetDetector(1))) {
       fPad->cd();
       fFMD1Pad = new TPad("FMD1", "FMD1", 0.0, 0.50, 0.5, 1.0, 0, 0);
       fFMD1Pad->Draw();
       fFMD1Pad->cd();
       fFMD1.Begin(-1, fInnerMax, fInners, fOuters);
     }
-    if ((det = geom->GetDetector(2))) {
+    if ((/* det = */ geom->GetDetector(2))) {
       fPad->cd();
       fFMD2Pad = new TPad("FMD2", "FMD2", 0.5, 0.50, 1.0, 1.0, 0, 0);
       fFMD2Pad->Draw();
       fFMD2Pad->cd();
       fFMD2.Begin(-1, fOuterMax, fInners, fOuters);
     }
-    if ((det = geom->GetDetector(3))) {
+    if ((/* det = */ geom->GetDetector(3))) {
       fPad->cd();
       fFMD3Pad = new TPad("FMD3", "FMD3", 0.0, 0.0, .5, .5, 0, 0);
       fFMD3Pad->Draw();
@@ -285,6 +459,7 @@ AliFMDPattern::Begin(Int_t event)
 void
 AliFMDPattern::Redisplay()
 {
+  // Redraw the displayu 
   fFMD1.Clear();
   fFMD2.Clear();
   fFMD3.Clear();
@@ -295,23 +470,27 @@ AliFMDPattern::Redisplay()
 void
 AliFMDPattern::AtEnd()
 {
+  // Called at the end of an event. 
   DrawAux();
   
   Int_t total = 0;
   
   fFMD1.End();
   fFMD1Pad->Modified();
-  fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d", fFMD1.Total()));
+  fFMD1Sum.SetTitle(Form("# hits in FMD1: %5d   (%4.2f /cm^{2})", 
+                        fFMD1.Total(), fFMD1.Total()/fFMD1Area));
   total += fFMD1.Total();
 
   fFMD2.End();
   fFMD2Pad->Modified();
-  fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d", fFMD2.Total()));
+  fFMD2Sum.SetTitle(Form("# hits in FMD2: %5d   (%4.2f /cm^{2})", 
+                        fFMD2.Total(), fFMD2.Total()/fFMD2Area));
   total += fFMD2.Total();
 
   fFMD3.End();
   fFMD3Pad->Modified();
-  fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d", fFMD3.Total()));
+  fFMD3Sum.SetTitle(Form("# hits in FMD3: %5d   (%4.2f /cm^{2})", 
+                        fFMD3.Total(), fFMD3.Total()/fFMD3Area));
   total += fFMD3.Total();
 
   fTotal.SetTitle(Form("Total:    %5d/51200 (%3d%%)", 
@@ -326,10 +505,28 @@ AliFMDPattern::AtEnd()
 Bool_t 
 AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*) 
 {
+  // Process a hit. 
+  // 
+  // Parameters 
+  // 
+  //   HIT             The hit to process. 
+  // 
+  // The TParticle argument is never used. 
+  static const Float_t rMin  = fgkEdepRange.fLow;
+  static const Float_t rMax  = fgkEdepRange.fHigh;
+
+  if (!hit) { AliError("No hit");   return kFALSE; }
+  // if (!p)   { AliError("No track"); return kFALSE; }
+  Float_t  edep  = hit->Edep();
+
+  if (fHits)                        fHits->Add(hit);
+  if (fSpec)                        fSpec->Fill(edep);
+  if (InsideCut(edep, rMin, rMax) && fSpecCut) fSpecCut->Fill(edep);
+
   switch (hit->Detector()) {
-  case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), 1); break;
-  case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), 1); break;
-  case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), 1); break;
+  case 1: fFMD1.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
+  case 2: fFMD2.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
+  case 3: fFMD3.AddMarker(hit->X(), hit->Y(), hit->Edep(), rMax); break;
   }
   return kTRUE;
 }
@@ -337,8 +534,9 @@ AliFMDPattern::ProcessHit(AliFMDHit* hit, TParticle*)
 
 //____________________________________________________________________
 void
-AliFMDPattern::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
-                        TObject*, Float_t s, Float_t max)
+AliFMDPattern::AddMarker(UShort_t det, Char_t rng, 
+                        UShort_t sec, UShort_t str,
+                        TObject*, Float_t s, Float_t /*min*/, Float_t max)
 {
   // Add a marker to the display
   //
@@ -350,7 +548,7 @@ AliFMDPattern::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
   //    s      Signal 
   //    max    Maximum of signal 
   //
-  Detector* d = 0;
+  AliFMDPatternDetector* d = 0;
   switch (det) {
   case 1: d = &fFMD1; break;
   case 2: d = &fFMD2; break;
@@ -360,10 +558,12 @@ AliFMDPattern::AddMarker(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
   AliFMDGeometry*   geom = AliFMDGeometry::Instance();
   Double_t x, y, z;
   geom->Detector2XYZ(det, rng, sec, str, x, y, z);
-  if (true) {
+  // Make code-checker shut the f**k up 
+  TRandom* rand = gRandom;
+  if (false) {
     AliFMDRing* r  = geom->GetRing(rng);
     Double_t    t  = .9 * r->GetTheta() / 2;
-    Double_t    a  = gRandom->Uniform(-t,t) * TMath::Pi() / 180;
+    Double_t    a  = rand->Uniform(-t,t) * TMath::Pi() / 180;
     Double_t    x1 = x * TMath::Cos(a) - y * TMath::Sin(a);
     Double_t    y1 = x * TMath::Sin(a) + y * TMath::Cos(a);
     x = x1;