]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerDisplay.cxx
Fixes for #86059: Install data when ALICE_ROOT does not point to source (Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerDisplay.cxx
index 97aa40c5c1d28b7db2a6bc74d807fac033680688..19269b7a3e704f3d15cd0ac14684bdc8fde67a08 100644 (file)
@@ -32,6 +32,7 @@
 // --- ROOT system ---
 #include <TH1.h> 
 #include <TH2.h>
+#include <TGraph.h>
 
 //-----------------------------------------------------------------------------
 /// \class AliMUONTriggerDisplay
@@ -126,6 +127,23 @@ TH2* AliMUONTriggerDisplay::GetDisplayHistogram(TH1* inputHisto, TString display
   return displayHisto;
 }
 
+//____________________________________________________________________________ 
+TH2* AliMUONTriggerDisplay::GetDisplayHistogram(TGraph* inputGraph, TString displayHistoName,
+                                               EDisplayType displayType, Int_t cathode,
+                                               Int_t chamber, TString displayHistoTitle,
+                                               EDisplayOption displayOpt)
+{
+  //
+  /// Get histogram displaying the information contained in the input graph
+  //
+  TH2* displayHisto = GetEmptyDisplayHisto(displayHistoName, displayType,
+                                          cathode, chamber, displayHistoTitle);
+
+  FillDisplayHistogram(inputGraph, displayHisto, displayType, cathode, chamber, displayOpt);
+
+  return displayHisto;
+}
+
 //____________________________________________________________________________ 
 Bool_t AliMUONTriggerDisplay::FillDisplayHistogram(TH1* inputHisto, TH2* displayHisto,
                                                   EDisplayType displayType, Int_t cathode,
@@ -141,7 +159,21 @@ Bool_t AliMUONTriggerDisplay::FillDisplayHistogram(TH1* inputHisto, TH2* display
 }
 
 //____________________________________________________________________________ 
-Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* displayHisto,
+Bool_t AliMUONTriggerDisplay::FillDisplayHistogram(TGraph* inputGraph, TH2* displayHisto,
+                                                  EDisplayType displayType, Int_t cathode,
+                                                  Int_t chamber, EDisplayOption displayOpt)
+{
+  //
+  /// Fill a previously initialized display histogram 
+  /// with the information contained in inputGraph.
+  /// To get initialized display, please use GetEmptyDisplayHisto method
+  //
+  return InitOrDisplayTriggerInfo(inputGraph, displayHisto, displayType,
+                                 cathode, chamber, "", "",displayOpt);
+}
+
+//____________________________________________________________________________ 
+Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TObject* inputObject, TH2* displayHisto,
                                                       EDisplayType displayType,
                                                       Int_t cathode, Int_t chamber,
                                                       TString displayHistoName, TString displayHistoTitle,
@@ -175,7 +207,7 @@ Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* dis
 
   const Float_t kResetValue=1234567.;
 
-  if(!inputHisto){
+  if(!inputObject){
     xAxisBoard.Set(55);
     xAxisBoard.Reset(kResetValue);
     yAxisBoard.Set(50);
@@ -190,6 +222,26 @@ Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* dis
       AliWarning("Display histogram not initialized. Please initialize it first!");
       return kFALSE;
   }
+  else {
+    TH1* inputHisto = dynamic_cast<TH1*>(inputObject);    
+    if ( inputHisto ) {
+      if ( inputHisto->GetEntries() == 0 ) {
+       return kTRUE;
+      }
+    }
+    else {
+      TGraph* inputGraph = dynamic_cast<TGraph*>(inputObject);
+      if ( inputGraph ) {
+        if ( inputGraph->GetN() == 0 ){
+         return kTRUE;
+        }
+      }  
+      else {
+        AliWarning("The object should inherit from TH1 or TGraph!");
+        return kFALSE;
+      }
+    }
+  }
 
   Float_t xWidth, yWidth, yWidthSlat=0., xWidthCol=0.;
   Float_t x1,x2,y1,y2;
@@ -240,6 +292,8 @@ Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* dis
       sign = -1.;
     }
     yOffsetLine = (Float_t)(line - 4) * 2. * yWidthSlat;
+         
+    Int_t nLocations = 1;
 
     for(Int_t cath=0; cath<AliMpConstants::NofCathodes(); cath++){
       // Loop on cathodes: 
@@ -247,21 +301,27 @@ Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* dis
       // board info is read only from cathode 0
 
       // loop over strips
-      for (Int_t iStrip = 0; iStrip < 16; ++iStrip) {
+      for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
        // get pad from electronics
 
        Int_t offset = 0;
-       if (cath && localBoard->GetSwitch(6)) offset = -8;
+       if (cath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
 
-       AliMpPad pad = seg[cath]->PadByLocation(iBoard,iStrip+offset,kFALSE);
+       AliMpPad pad = seg[cath]->PadByLocation(iBoard,ibitxy+offset,kFALSE);
 
        if (!pad.IsValid()) continue;
+        
+  // For non-bending plane fill only the first board covered by the strip
+  // i.e. avoide filling many times the same information
+  if ( cath == 1 && pad.GetLocalBoardId(0) != iBoard ) continue;
 
        xWidth = pad.GetDimensionX();
        yWidth = pad.GetDimensionY();
        xcPad = sign * (pad.GetPositionX() + xOffsetLine);
        if(line==4) xcPad += 0.75 * sign * xWidthCol;
        ycPad = pad.GetPositionY() + yOffsetLine;
+       nLocations = pad.GetNofLocations();
+       Int_t iStrip = pad.GetLocalBoardChannel(0);
 
        if(cath==iCath){
          x1 = xcPad - xWidth + kShiftX;
@@ -269,7 +329,7 @@ Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* dis
          x2 = xcPad + xWidth - kShiftX;
          y2 = ycPad + yWidth - kShiftY;
 
-         if(!inputHisto){
+         if(!inputObject){
            AddSortedPoint(x1, xAxisStrip, kResetValue);
            AddSortedPoint(x2, xAxisStrip, kResetValue);
 
@@ -277,17 +337,18 @@ Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* dis
            AddSortedPoint(y2, yAxisStrip, kResetValue);
          }
          else if(displayType==kDisplayStrips) 
-           FillBins(inputHisto, displayHisto, iBoard, iStrip, x1, x2, y1, y2, kShiftX, kShiftY, displayOpt);
+           FillBins(inputObject, displayHisto, iBoard, iStrip, x1, x2, y1, y2, kShiftX, kShiftY, displayOpt);
        }
 
        if(cath==0){
-         if(iStrip+offset==0) {
+         if(iStrip==0) {
            x1b = xcPad - xWidth + kShiftEl;
            y1b = ycPad - yWidth + kShiftEl;
          }
          x2b = xcPad + xWidth - kShiftEl;
          y2b = ycPad + yWidth - kShiftEl;
        }
+
       } // loop on strips
 
       // if iCath==0 strip info and board info are both filled -> break!
@@ -295,7 +356,7 @@ Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* dis
       if(iCath==0) break;
     } // loop on cathodes
 
-    if(!inputHisto){
+    if(!inputObject){
       // Per board
       AddSortedPoint(x1b, xAxisBoard, kResetValue);
       AddSortedPoint(x2b, xAxisBoard, kResetValue);
@@ -304,12 +365,12 @@ Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* dis
       AddSortedPoint(y2b, yAxisBoard, kResetValue);
     }
     else if(displayType==kDisplayBoards) 
-      FillBins(inputHisto, displayHisto, iBoard, -1, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
+      FillBins(inputObject, displayHisto, iBoard, -nLocations, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
     else if(displayType==kDisplaySlats) 
-      FillBins(inputHisto, displayHisto, slat, -1, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
+      FillBins(inputObject, displayHisto, slat, -1, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
   } // loop on local boards
 
-  if(inputHisto) return kTRUE;
+  if ( inputObject ) return kTRUE;
 
   displayHisto->Reset();
 
@@ -382,7 +443,7 @@ Bool_t AliMUONTriggerDisplay::AddSortedPoint(Float_t currVal, TArrayD& position,
 
 
 //____________________________________________________________________________ 
-void AliMUONTriggerDisplay::FillBins(TH1* inputHisto, TH2* displayHisto,
+void AliMUONTriggerDisplay::FillBins(TObject* inputObject, TH2* displayHisto,
                                     Int_t iElement1, Int_t iElement2,
                                     Float_t x1, Float_t x2, Float_t y1, Float_t y2,
                                     const Float_t kShiftX, const Float_t kShiftY,
@@ -392,15 +453,31 @@ void AliMUONTriggerDisplay::FillBins(TH1* inputHisto, TH2* displayHisto,
   /// Given the bin in inputHisto, search the corresponding bins
   /// in display histo and fill it.
   //
-  TString className = inputHisto->ClassName();
   Int_t binY=0;
   Float_t binContent=0;
-  Int_t binX = inputHisto->GetXaxis()->FindBin(iElement1);
-  if(className.Contains("2")) {
-    binY = inputHisto->GetYaxis()->FindBin(iElement2);
-    binContent = inputHisto->GetBinContent(binX, binY);
+  TH1* inputHisto = dynamic_cast<TH1*>(inputObject);
+  if ( inputHisto ) {
+    Int_t binX = inputHisto->GetXaxis()->FindBin(iElement1);
+    if ( inputObject->IsA()->InheritsFrom("TH2") ) {
+      binY = inputHisto->GetYaxis()->FindBin(iElement2);
+      binContent = inputHisto->GetBinContent(binX, binY);
+    }
+    else binContent = inputHisto->GetBinContent(binX);
   }
-  else binContent = inputHisto->GetBinContent(binX);
+  else {
+    TGraph* inputGraph = dynamic_cast<TGraph*>(inputObject);
+    if ( inputGraph ) {
+      Double_t xpt, ypt;
+      for ( Int_t ipt=0; ipt<inputGraph->GetN(); ipt++){
+        inputGraph->GetPoint(ipt, xpt, ypt);
+        if ( TMath::Abs(xpt - iElement1) < 0.1 ) {
+         binContent = ypt;
+         break;
+        }
+      }
+    }
+    else return;
+  }  
 
   if(binContent==0) {
     if(displayOpt==kShowZeroes) binContent = 1e-5;
@@ -422,9 +499,26 @@ void AliMUONTriggerDisplay::FillBins(TH1* inputHisto, TH2* displayHisto,
     binY2 = meanBin;
   }
 
+  Float_t elementArea = 1.;
+  if(displayOpt == kNormalizeToArea) {
+    elementArea = (x2 - x1 + 2*kShiftX) * 
+      (y2 - y1 + 2*kShiftY); // In InitOrDisplayTriggerInfo: 
+                             // x2 = x_c + xHalfWidth - kShiftX
+                             // x1 = x_c - xHalfWidth + kShiftX
+                             // so x2 - x1 + 2*kShiftX returns the element width.
+         
+         // If iElement2 is less than 0, then its meaning is the 
+         // number of boards covered by one strip
+         // the area has therefore to be multiplied accordingly
+         // This fixes the problem when filling the trigger rate per boards in non-bending plane
+         // which is overestimated since the segmentation is always given by the bending-plane
+         if ( iElement2 < 0 ) elementArea *= -(Double_t)iElement2;
+
+  }
+
   for(Int_t ibinx=binX1; ibinx<=binX2; ibinx++){
     for(Int_t ibiny=binY1; ibiny<=binY2; ibiny++){
-      displayHisto->SetBinContent(ibinx,ibiny,binContent);
+      displayHisto->SetBinContent(ibinx,ibiny,binContent/elementArea);
     }
   }
 }