]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerEfficiencyCells.cxx
No more misaligned_geometry
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerEfficiencyCells.cxx
index 12f29960c04490836380f4d71f495e4a88e7338a..7aec2542bcc6e7ce80fe5e39d9ac7f667a6a77a6 100755 (executable)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-#include <fstream>
-#include <TRandom.h>
-#include "Riostream.h"
-
 #include "AliMUONTriggerEfficiencyCells.h"
-#include "AliMUONConstants.h"
-#include "AliRun.h"
-#include "AliMpPad.h"
-#include "AliMUON.h"
-#include "AliMpVSegmentation.h"
-#include "AliMpTriggerSegmentation.h"
-#include "AliMpTrigger.h"
+#include "AliMpConstants.h"
+#include "AliMpDEManager.h"
+
 #include "AliLog.h"
 
-//
-// A class to store and give access to the trigger chamber efficiency.
-//
-// Efficiency is stored per cathode, on "cells" of a given size.
-//
-// The main method of this class is IsTriggered().
-//
-// $ALICE_ROOT/MUON/data/TriggerChamberefficiencyCells.dat contains efficiency 
-// for each chamber (i.e. DetElement). 
-// The efficiency cells goes from right to left and 
-// from bottom to top of the chamber, namely, the efficiencies tabulated in the 
-// file refers to the following reference frame:
-//
-//x
-//<----------------------------------|
-//                                   |
-//   ---------------------------     |
-//  | 0.97 | 0.97 | 0.97 | 0.97 |    |
-//   ---------------------------     |
-//  | 0.97 | 0.97 | 0.97 | 0.97 |    |
-//   ---------------------------     |
-//  | 0.97 | 0.97 | 0.97 | 0.97 |    |
-//   ---------------------------     |
-//                                   |
-//                                  \/ y
-//
-//  The file can be edited in order to change efficiency in a chosen region
-//  of the chamber.
-//
-// But please note that this object is also available from the CDB 
-// (generated using the MUONCDB.C macro)
-//
+#include "TRandom.h"
+#include "Riostream.h"
+#include "TSystem.h"
+#include "TFile.h"
+#include "TH1F.h"
+#include "TMatrixF.h"
+
+#include <fstream>
+#include <cassert>
+
+/// \class AliMUONTriggerEfficiencyCells
+/// A class to store and give access to the trigger chamber efficiency.
+///
+/// Efficiency is stored per cathode on local boards, or, alternatively,
+/// on "cells" of a given size.
+///
+/// The main method of this class is IsTriggered().
+///
+/// $ALICE_ROOT/MUON/data/TriggerChamberefficiencyCells.dat contains efficiency 
+/// for each chamber (i.e. DetElement). 
+///
+/// In the case of local boards, efficiency is stored from left to right
+/// per increasing board number (from 1 to 234)
+///
+/// Otherwise, he efficiency cells goes from right to left and 
+/// from bottom to top of the chamber, namely, the efficiencies tabulated in the 
+/// file refers to the following reference frame:
+///
+/// <pre>
+/// x
+/// <----------------------------------|
+///                                    |
+///    ---------------------------     |
+///   | 0.97 | 0.97 | 0.97 | 0.97 |    |
+///    ---------------------------     |
+///   | 0.97 | 0.97 | 0.97 | 0.97 |    |
+///    ---------------------------     |
+///   | 0.97 | 0.97 | 0.97 | 0.97 |    |
+///    ---------------------------     |
+///                                    |
+///                                   \/ y
+/// </pre>
+///
+///  In both cases, the file can be edited in order to change efficiency
+///  in a chosen local board/region of the chamber.
+///
+///
+/// But please note that this object is also available from the CDB 
+/// (generated using the MUONCDB.C macro)
+///
+/// \author Diego Stocco; INFN Torino
 
+/// \cond CLASSIMP
 ClassImp(AliMUONTriggerEfficiencyCells)
+/// \endcond
 
 //__________________________________________________________________________
 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
 :
 TObject()
 {
-  // Default ctor.
+///  Default constructor.
+  CheckConstants();
   Reset();
 }
 
@@ -76,7 +90,8 @@ AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const char* filenam
 :
 TObject()
 {
-  // Ctor using an ASCII file.
+///  Constructor using an ASCII file.
+  CheckConstants();
   Reset();
   ReadFile(filename);
 }
@@ -85,30 +100,15 @@ TObject()
 //__________________________________________________________________________
 AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
 {
-  // dtor. Does nothing ;-)
-}
-    
-//__________________________________________________________________________
-Float_t AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t cathode, Float_t x, Float_t y)
-{
-  // Get the efficiency at a given position (x,y) for a given cathode
-  
-  Int_t chamber = FindChamberIndex(detElemId);
-  Int_t slat = FindSlatIndex(detElemId);
-  TArrayI cell = CellByCoord(detElemId,x,y);
-  Float_t efficiency = 0.0;
-  if (cell.At(0)>=0 && cell.At(1)>=0)
-  {
-    efficiency = fCellContent[chamber][slat][cathode][cell.At(0)][cell.At(1)];
-  }
-  return efficiency;
+///  Destructor. Does nothing ;-)
 }
 
 
 //__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Float_t x, Float_t y, Float_t &eff1, Float_t &eff2)
+void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Float_t x, Float_t y, Float_t &eff1, Float_t &eff2) const
 {
-  // Get the efficiencies of the 2 cathode at a given location (x,y)
+///  Get the efficiencies of the 2 cathodes at a given location (x,y)
+
   Int_t chamber = FindChamberIndex(detElemId);
   Int_t slat = FindSlatIndex(detElemId);
   TArrayI cell = CellByCoord(detElemId,x,y);
@@ -116,32 +116,29 @@ void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Float_t x
   eff2 = 0.0;
   if(cell.At(0)>=0 && cell.At(1)>=0)
   {
-    eff1 = fCellContent[chamber][slat][0][cell.At(0)][cell.At(1)];
-    eff2 = fCellContent[chamber][slat][1][cell.At(0)][cell.At(1)];
+    eff1 = fCellContent[chamber][slat][cell.At(0)][cell.At(1)];
+    eff2 = fCellContent[fgkNchambers+chamber][slat][cell.At(0)][cell.At(1)];
   }
 }
 
 
 //__________________________________________________________________________
-Bool_t 
-AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t cathode, Float_t x, Float_t y)
+void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t localBoard, Float_t &eff1, Float_t &eff2) const
 {
-  // Random decision of whether a given "location" (x,y) trigs or not.
-  Float_t efficiency = GetCellEfficiency(detElemId, cathode, x, y);
-  Bool_t trigger = kTRUE;
-  if(gRandom->Rndm()>efficiency)
-  {
-    trigger = kFALSE;
-  }
-  return trigger;
+///  Get the efficiencies of the 2 cathodes at a given local board
+
+  Int_t chamber = FindChamberIndex(detElemId);
+  eff1 = fBoardContent[chamber][localBoard-1];
+  eff2 = fBoardContent[fgkNchambers+chamber][localBoard-1];
 }
 
 
 //__________________________________________________________________________
 void 
-AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Float_t x, Float_t y, Bool_t &trig1, Bool_t &trig2)
+AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Float_t x, Float_t y, Bool_t &trig1, Bool_t &trig2) const
 {
-  // Whether or not a given location (x,y) has a chance to trig, on each cathode.
+///  Whether or not a given location (x,y) has a chance to trig, on each cathode.
+
   Float_t eff1 = 0.0;
   Float_t eff2 = 0.0;
   GetCellEfficiency(detElemId, x, y, eff1, eff2);
@@ -153,82 +150,182 @@ AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Float_t x, Float_t y
 
 
 //__________________________________________________________________________
-TArrayI AliMUONTriggerEfficiencyCells::CellByCoord(Int_t detElemId, Float_t x, Float_t y)
+void 
+AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t localBoard, Bool_t &trig1, Bool_t &trig2) const
+{
+///  Whether or not a given local board has a chance to trig, on each cathode.
+
+  Float_t eff1 = 0.0;
+  Float_t eff2 = 0.0;
+  GetCellEfficiency(detElemId, localBoard, eff1, eff2);
+  trig1 = kTRUE; 
+  trig2 = kTRUE;
+  if(gRandom->Rndm()>eff1)trig1 = kFALSE;
+  if(gRandom->Rndm()>eff2)trig2 = kFALSE;
+}
+
+//__________________________________________________________________________
+TArrayI AliMUONTriggerEfficiencyCells::CellByCoord(Int_t detElemId, Float_t x, Float_t y) const
 {
-  // Get the efficiencies at a given location.
+///  Get the efficiencies at a given location.
+
   Int_t chamber = FindChamberIndex(detElemId);
   Int_t slat = FindSlatIndex(detElemId);
-  Int_t cell[2]={-1,-1};
-  Float_t maxX = fCellSize[chamber][slat][0]*((Float_t)fCellNumber[chamber][slat][0]);
-  Float_t maxY = fCellSize[chamber][slat][1]*((Float_t)fCellNumber[chamber][slat][1]);
+  Int_t cell[fgkNcathodes]={-1,-1};
+  Float_t maxX = fCellSize[chamber][slat]*((Float_t)fCellNumber[chamber][slat]);
+  Float_t maxY = fCellSize[fgkNchambers+chamber][slat]*((Float_t)fCellNumber[fgkNchambers+chamber][slat]);
   if(x>=0 & x<maxX & y>=0 & y<maxY)
   {
-    cell[0] = (Int_t)(x/fCellSize[chamber][slat][0]);
-    cell[1] = (Int_t)(y/fCellSize[chamber][slat][1]);
+    cell[0] = (Int_t)(x/fCellSize[chamber][slat]);
+    cell[1] = (Int_t)(y/fCellSize[fgkNchambers+chamber][slat]);
   }
-  return TArrayI(2,cell);
+  return TArrayI(fgkNcathodes,cell);
 }
 
 //__________________________________________________________________________
 void AliMUONTriggerEfficiencyCells::ReadFile(const char* filename)
 {
-  // Reads a file containing the efficiency map.
+///  Reads a file containing the efficiency map.
+
   TString fileName = gSystem->ExpandPathName(filename);
+  if(fileName.EndsWith(".root")){
+      ReadHistoBoards(fileName.Data());
+      return;
+  }
+
   ifstream file(fileName.Data());
-  Int_t datInt=0, detEl=0, chamber=0, rpc=0;
-  Float_t datFloat=0.0;
   char dat[50];
   if (file.good()){
+      file >> dat;
+      if(!strcmp(dat,"localBoards"))ReadFileBoards(file);
+      else ReadFileXY(file);
+      file.close();
+  } else {
+      AliWarning(Form("Can't read file %s",fileName.Data()));
+  }
+}
+
+
+//__________________________________________________________________________
+void AliMUONTriggerEfficiencyCells::ReadFileXY(ifstream &file)
+{
+///  Structure of file (.dat) containing geometrical efficency
+    Int_t datInt=0, detEl=0, chamber=0, rpc=0, chCath=0;
+    Float_t datFloat=0.0;
+    char dat[50];
+
+    while (file >> dat) {
+       file >> detEl;
+       chamber = FindChamberIndex(detEl);
+       rpc = FindSlatIndex(detEl);
+       file >> dat;
+       for(Int_t i=0; i<fgkNcathodes; i++){
+           chCath = fgkNchambers*i + chamber;
+           file >> datInt;
+           fCellNumber[chCath][rpc] = datInt;
+           file >> dat;
+       }
+       for(Int_t i=0; i<fgkNcathodes; i++){
+           chCath = fgkNchambers*i + chamber;
+           file >> datFloat;
+           fCellSize[chCath][rpc] = datFloat;
+           if(i==0)file >> dat;
+       }
+       for(Int_t cath=0; cath<fgkNcathodes; cath++){
+           chCath = fgkNchambers*cath + chamber;
+           file >> dat;
+           file >> datInt;
+           for(Int_t iy=0; iy<fCellNumber[fgkNchambers+chamber][rpc]; iy++){
+               for(Int_t ix=0; ix<fCellNumber[chamber][rpc]; ix++){
+                   file >> datFloat;
+                   fCellContent[chCath][rpc][ix][iy] = datFloat;
+               }
+           }
+       }
+    }
+}
+
+//__________________________________________________________________________
+void AliMUONTriggerEfficiencyCells::ReadFileBoards(ifstream &file)
+{
+///  Structure of file (.dat) containing local board efficency
+    Int_t datInt=0, detEl=0, chamber=0, chCath=0;
+    Float_t datFloat=0.0;
+    char dat[50];
+
     while (file >> dat) {
            file >> detEl;
            chamber = FindChamberIndex(detEl);
-           rpc = FindSlatIndex(detEl);
-           file >> dat;
-           for(Int_t i=0; i<2; i++){
-        file >> datInt;
-        fCellNumber[chamber][rpc][i] = datInt;
-        file >> dat;
+           //rpc = FindSlatIndex(detEl);
+           for(Int_t cath=0; cath<fgkNcathodes; cath++){
+               chCath = fgkNchambers*cath + chamber;
+               file >> dat;
+               file >> datInt;
+               for(Int_t board=0; board<AliMpConstants::NofLocalBoards(); board++){
+                   file >> datFloat;
+                   fBoardContent[chCath][board] = datFloat;
+               }
            }
-           for(Int_t i=0; i<2; i++){
-        file >> datFloat;
-        fCellSize[chamber][rpc][i] = datFloat;
-        if(i==0)file >> dat;
+    }
+}
+
+
+//__________________________________________________________________________
+void AliMUONTriggerEfficiencyCells::ReadHistoBoards(const char *filename)
+{
+///  Structure of file (.root) containing local board efficency
+    TFile *file = new TFile(filename, "read");
+    if(!file) {
+       AliWarning(Form("Can't read file %s",filename));
+       return;
+    }
+    char histoName[30];
+    char *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
+    TH1F *histo = 0x0;
+    for(Int_t ch=0; ch<fgkNchambers; ch++){
+       for(Int_t cath=0; cath<fgkNcathodes; cath++){
+           sprintf(histoName, "%sBoardEffChamber%i", cathCode[cath], 11+ch);
+           histo = (TH1F *)file->Get(histoName);
+           if(!(TH1F *)file->Get(histoName)) {
+               AliWarning(Form("Can't find histo %s in file %s",histoName, filename));
+               continue;
            }
-           for(Int_t cath=0; cath<2; cath++){
-        file >> dat;
-        file >> datInt;
-        for(Int_t iy=0; iy<fCellNumber[chamber][rpc][1]; iy++){
-          for(Int_t ix=0; ix<fCellNumber[chamber][rpc][0]; ix++){
-            file >> datFloat;
-            fCellContent[chamber][rpc][cath][ix][iy] = datFloat;
-          }
-        }
+           Int_t chCath = fgkNchambers*cath + ch;
+           for(Int_t board=0; board<AliMpConstants::NofLocalBoards(); board++){
+               Int_t bin = histo->FindBin(board+1);
+               fBoardContent[chCath][board] = histo->GetBinContent(bin);
            }
+       }
     }
-    file.close();
-  } else {
-    AliWarning(Form("Can't read file %s",fileName.Data()));
-  }
+}
+
+
+//_____________________________________________________________________________
+void AliMUONTriggerEfficiencyCells::CheckConstants() const
+{
+/// Check consistence of redefined constants 
+
+  assert(fgkNcathodes == AliMpConstants::NofCathodes());    
+  assert(fgkNchambers == AliMpConstants::NofTriggerChambers());    
+  assert(fgkNplanes == AliMpConstants::NofTriggerChambers() * fgkNcathodes);    
 }
 
 
 //__________________________________________________________________________
-Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId)
+Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId) const
 {
-  // From detElemId to chamber number
-  Int_t offset = 100*(AliMUONConstants::NTrackingCh()+1);
-  Int_t chamber = (detElemId-offset)/100;
+///  From detElemId to chamber number
+  Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
+  Int_t chamber = iChamber-AliMpConstants::NofTrackingChambers();
   return chamber;
 }
 
 
 //__________________________________________________________________________
-Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId)
+Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId) const
 {
-  // From detElemId to slat index.
-  Int_t offset = 100*(AliMUONConstants::NTrackingCh()+1);
-  Int_t chamber = FindChamberIndex(detElemId);
-  Int_t slat = detElemId-offset-(chamber*100);
+///  From detElemId to slat index.
+  Int_t slat = detElemId%100;
   return slat;
 }
 
@@ -236,7 +333,8 @@ Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId)
 //__________________________________________________________________________
 TVector2 AliMUONTriggerEfficiencyCells::ChangeReferenceFrame(Float_t x, Float_t y, Float_t x0, Float_t y0)
 {
-    //(x0,y0) position of the local reference frame (center of the chamber)
+/// (x0,y0) position of the local reference frame (center of the chamber)
+
     Float_t x1 = x0-x;//reflection of axis
     Float_t y1 = y+y0;
     return TVector2(x1,y1);
@@ -246,26 +344,25 @@ TVector2 AliMUONTriggerEfficiencyCells::ChangeReferenceFrame(Float_t x, Float_t
 void
 AliMUONTriggerEfficiencyCells::Reset()
 {
-  //
-  // Sets our internal array contents to zero.
-  //
-  for(Int_t chamber=0; chamber<4; chamber++)
-  {
-    for(Int_t slat=0; slat<18; slat++)
-    {
-           for(Int_t cath=0; cath<2; cath++)
-      {
-        fCellSize[chamber][slat][cath]=0.0;
-        fCellNumber[chamber][slat][cath]=0;
-        for(Int_t ix=0; ix<fgkNofCells; ix++)
-        {
-          for(Int_t iy=0; iy<fgkNofCells; iy++)
-          {
-            fCellContent[chamber][slat][cath][ix][iy]=0.0;
-          }
-        }
-           }
+///  Sets our internal array contents to zero.
+
+    for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+       fBoardContent[chCath].Set(AliMpConstants::NofLocalBoards());
+       fCellSize[chCath].Set(fgkNslats);
+       fCellNumber[chCath].Set(fgkNslats);
+       for(Int_t slat=0; slat<fgkNslats; slat++){
+           fCellContent[chCath][slat].ResizeTo(fgkNcells,fgkNcells);
+       }
+    }
+
+    for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+       fBoardContent[chCath].Reset();
+       fCellSize[chCath].Reset();
+       fCellNumber[chCath].Reset();
+       for(Int_t slat=0; slat<fgkNslats; slat++){
+           fCellContent[chCath][slat].Zero();
+       }
     }
-  }
 }
 
+