]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerEfficiencyCells.cxx
Bug fix for loading the LUT for chambers 1 to 6. (Indra)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerEfficiencyCells.cxx
index 17b09649c653a2ce29d58c969d59d28d7f926068..652449d9f14f4ccc157d266cdcb5d80a4ed11665 100755 (executable)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+// $Id$
+
 #include "AliMUONTriggerEfficiencyCells.h"
 #include "AliMpConstants.h"
-#include "AliMpDEManager.h"
+
+// Classes for display
+#include "AliMUONTriggerDisplay.h"
+#include "AliCDBManager.h"
+#include "AliMpCDB.h"
+#include "AliMpDDLStore.h"
+#include "AliMpLocalBoard.h"
+#include "AliMpPad.h"
+#include "AliMpVSegmentation.h"
+#include "AliMpSegmentation.h"
 
 #include "AliLog.h"
 
@@ -27,6 +38,8 @@
 #include "TMath.h"
 
 #include "TH2F.h"
+#include "TH3F.h"
+#include "TF1.h"
 #include "TStyle.h"
 #include "TPaveLabel.h"
 #include "TCanvas.h"
 /// \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.
+/// Efficiency is stored per cathode on local boards
 ///
 /// The main method of this class is IsTriggered().
 ///
-/// $ALICE_ROOT/MUON/data/TriggerChamberefficiencyCells.dat contains efficiency 
+/// $ALICE_ROOT/MUON/data/efficiencyCells.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.
+/// 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
 //-----------------------------------------------------------------------------
@@ -87,7 +79,12 @@ AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
 :
 TObject(),
 fCountHistoList(0x0),
-fNoCountHistoList(0x0)
+fNoCountHistoList(0x0),
+fFiredStrips(0x0),
+fDisplayHistoList(0x0),
+fBoardLabelList(0x0),
+fFiredFitHistoList(0x0),
+fFiredDisplayHistoList(0x0)
 {
 ///  Default constructor.
   CheckConstants();
@@ -96,26 +93,39 @@ fNoCountHistoList(0x0)
 }
 
 //__________________________________________________________________________
-AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const char* filename)
+AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const Char_t* filename)
 :
 TObject(),
 fCountHistoList(0x0),
-fNoCountHistoList(0x0)
+fNoCountHistoList(0x0),
+fFiredStrips(0x0),
+fDisplayHistoList(0x0),
+fBoardLabelList(0x0),
+fFiredFitHistoList(0x0),
+fFiredDisplayHistoList(0x0)
 {
 ///  Constructor using an ASCII file.
   CheckConstants();
   Reset();
+  InitHistos();
   ReadFile(filename);
 }
 
+
+//__________________________________________________________________________
 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(TList *countHistoList,
                                                             TList *noCountHistoList)
 :
 TObject(),
 fCountHistoList(countHistoList),
-fNoCountHistoList(noCountHistoList)
+fNoCountHistoList(noCountHistoList),
+fFiredStrips(0x0),
+fDisplayHistoList(0x0),
+fBoardLabelList(0x0),
+fFiredFitHistoList(0x0),
+fFiredDisplayHistoList(0x0)
 {
-///  Constructor using an ASCII file.
+///  Constructor using a list of histograms with counts.
   CheckConstants();
   Reset();
   InitHistos();
@@ -127,16 +137,16 @@ AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const AliMUONTrigge
 :
 TObject(other),
 fCountHistoList(other.fCountHistoList),
-fNoCountHistoList(other.fNoCountHistoList)
+fNoCountHistoList(other.fNoCountHistoList),
+fFiredStrips(other.fFiredStrips),
+fDisplayHistoList(other.fDisplayHistoList),
+fBoardLabelList(other.fBoardLabelList),
+fFiredFitHistoList(other.fFiredFitHistoList),
+fFiredDisplayHistoList(other.fFiredDisplayHistoList)
 {
 /// Copy constructor
 
   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
-    for(Int_t slat=0; slat<fgkNslats; slat++){
-      fCellContent[chCath][slat] = other.fCellContent[chCath][slat];
-    }
-    fCellSize[chCath] = other.fCellSize[chCath];
-    fCellNumber[chCath] = other.fCellNumber[chCath];
     fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
     fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
   }
@@ -151,18 +161,19 @@ AliMUONTriggerEfficiencyCells& AliMUONTriggerEfficiencyCells::operator=(const Al
     return *this;
 
   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
-    for(Int_t slat=0; slat<fgkNslats; slat++){
-      fCellContent[chCath][slat] = other.fCellContent[chCath][slat];
-    }
-    fCellSize[chCath] = other.fCellSize[chCath];
-    fCellNumber[chCath] = other.fCellNumber[chCath];
     fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
     fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
   }
 
   fCountHistoList = other.fCountHistoList;
   fNoCountHistoList = other.fNoCountHistoList;
+  fFiredStrips = other.fFiredStrips;
 
+  fDisplayHistoList = other.fDisplayHistoList;
+  fBoardLabelList = other.fBoardLabelList;
+  fFiredFitHistoList = other.fFiredFitHistoList;
+  fFiredDisplayHistoList = other.fFiredDisplayHistoList;
+    
   return *this;
 }
 
@@ -170,24 +181,10 @@ AliMUONTriggerEfficiencyCells& AliMUONTriggerEfficiencyCells::operator=(const Al
 AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
 {
 ///  Destructor.
-}
-
 
-//__________________________________________________________________________
-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 cathodes at a given location (x,y)
-
-  Int_t chamber = FindChamberIndex(detElemId);
-  Int_t slat = FindSlatIndex(detElemId);
-  TArrayI cell = CellByCoord(detElemId,x,y);
-  eff1 = 0.0;
-  eff2 = 0.0;
-  if(cell.At(0)>=0 && cell.At(1)>=0)
-  {
-    eff1 = fCellContent[chamber][slat][cell.At(0)][cell.At(1)];
-    eff2 = fCellContent[fgkNchambers+chamber][slat][cell.At(0)][cell.At(1)];
-  }
+  delete [] fBoardEfficiency;
+  delete [] fSlatEfficiency;
+  Reset();
 }
 
 
@@ -203,22 +200,6 @@ void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t loc
 }
 
 
-//__________________________________________________________________________
-void 
-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.
-
-  Float_t eff1 = 0.0;
-  Float_t eff2 = 0.0;
-  GetCellEfficiency(detElemId, x, y, eff1, eff2);
-  trig1 = kTRUE; 
-  trig2 = kTRUE;
-  if(gRandom->Rndm()>eff1)trig1 = kFALSE;
-  if(gRandom->Rndm()>eff2)trig2 = kFALSE;
-}
-
-
 //__________________________________________________________________________
 void 
 AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t localBoard, Bool_t &trig1, Bool_t &trig2) const
@@ -234,26 +215,9 @@ AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t localBoard, Bo
   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.
-
-  Int_t chamber = FindChamberIndex(detElemId);
-  Int_t slat = FindSlatIndex(detElemId);
-  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]);
-    cell[1] = (Int_t)(y/fCellSize[fgkNchambers+chamber][slat]);
-  }
-  return TArrayI(fgkNcathodes,cell);
-}
 
 //__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadFile(const char* filename)
+void AliMUONTriggerEfficiencyCells::ReadFile(const Char_t* filename)
 {
 ///  Reads a file containing the efficiency map.
 
@@ -263,73 +227,32 @@ void AliMUONTriggerEfficiencyCells::ReadFile(const char* filename)
       return;
   }
 
-  InitHistos();
   ifstream file(fileName.Data());
-  char dat[50];
+  Char_t dat[50];
   if (file.good()){
       file >> dat;
       if(!strcmp(dat,"localBoards"))ReadFileBoards(file);
-      else ReadFileXY(file);
+      else AliWarning("File .dat in wrong format");
       file.close();
   } else {
-      AliWarning(Form("Can't read file %s",fileName.Data()));
+    AliError(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, bin=0;
     Float_t datFloat=0.0;
-    char dat[50];
+    Char_t dat[50];
 
     while (file >> dat) {
            file >> detEl;
            chamber = FindChamberIndex(detEl);
-           //rpc = FindSlatIndex(detEl);
            for(Int_t cath=0; cath<fgkNcathodes; cath++){
-               chCath = fgkNchambers*cath + chamber;
+               chCath = GetPlane(chamber, cath);
                file >> dat;
                file >> datInt;
                for(Int_t board=1; board<=AliMpConstants::NofLocalBoards(); board++){
@@ -343,28 +266,58 @@ void AliMUONTriggerEfficiencyCells::ReadFileBoards(ifstream &file)
 
 
 //__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadHistoBoards(const char *filename)
+void AliMUONTriggerEfficiencyCells::ReadHistoBoards(const Char_t *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;
+    if(!file || !file->IsOpen()) {
+      AliError(Form("Can't read file %s",filename));
+      return;
     }
-    char histoName[30];
-    char *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
-
-    for(Int_t ch=0; ch<fgkNchambers; ch++){
-       for(Int_t cath=0; cath<fgkNcathodes; cath++){
-           sprintf(histoName, "%sBoardEffChamber%i", cathCode[cath], 11+ch);
-           if(!(TH1F *)file->Get(histoName)) {
-               AliWarning(Form("Can't find histo %s in file %s",histoName, filename));
-               continue;
-           }
-           Int_t chCath = fgkNchambers*cath + ch;
-           fBoardEfficiency[chCath] = (TH1F *)file->Get(histoName);
+
+    TString histoName;
+    TString cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
+    enum {kAllChEff, kChNonEff, kNumOfHistoTypes};
+    TString histoTypeName[2] = {"CountInCh", "NonCountInCh"};
+
+    if(!fCountHistoList) fCountHistoList = new TList();
+    else fCountHistoList->Delete();
+    if(!fNoCountHistoList) fNoCountHistoList = new TList();
+    else fNoCountHistoList->Delete();
+
+    TList *currList[2] = {fCountHistoList, fNoCountHistoList};
+
+    TH1F *histo = 0x0;
+    
+    for(Int_t cath=0; cath<fgkNcathodes; cath++){
+      for(Int_t hType=0; hType<kNumOfHistoTypes; hType++){
+       histoName = Form("%sChamber%s", cathCode[cath].Data(), histoTypeName[hType].Data());
+       histo = (TH1F*)file->Get(histoName.Data());
+       currList[hType]->Add(histo);
+      }
+    }
+
+    for(Int_t cath=0; cath<fgkNcathodes; cath++){
+      for(Int_t ch=0; ch<fgkNchambers; ch++){
+       for(Int_t hType=0; hType<kNumOfHistoTypes; hType++){
+         histoName = Form("%sSlat%s%i", cathCode[cath].Data(), histoTypeName[hType].Data(), 11+ch);
+         histo = (TH1F*)file->Get(histoName.Data());
+         currList[hType]->Add(histo);
+       }
+      }
+    }
+
+    for(Int_t cath=0; cath<fgkNcathodes; cath++){
+      for(Int_t ch=0; ch<fgkNchambers; ch++){
+       for(Int_t hType=0; hType<kNumOfHistoTypes; hType++){
+         histoName = Form("%sBoard%s%i", cathCode[cath].Data(), histoTypeName[hType].Data(), 11+ch);
+         histo = (TH1F*)file->Get(histoName.Data());
+         currList[hType]->Add(histo);
        }
+      }
     }
+
+    FillHistosFromList();
 }
 
 
@@ -383,58 +336,46 @@ void AliMUONTriggerEfficiencyCells::CheckConstants() const
 Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId) const
 {
 ///  From detElemId to chamber number
-  Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
+
+  // Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
+  Int_t iChamber = detElemId/100 - 1;
   Int_t chamber = iChamber-AliMpConstants::NofTrackingChambers();
   return chamber;
 }
 
 
-//__________________________________________________________________________
-Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId) const
-{
-///  From detElemId to slat index.
-  Int_t slat = detElemId%100;
-  return slat;
-}
-
-
-//__________________________________________________________________________
-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)
-
-    Float_t x1 = x0-x;//reflection of axis
-    Float_t y1 = y+y0;
-    return TVector2(x1,y1);
-}
-
 //__________________________________________________________________________
 void
-AliMUONTriggerEfficiencyCells::Reset()
+AliMUONTriggerEfficiencyCells::Reset(Bool_t resetAll)
 {
 ///  Sets our internal array contents to zero.
 
+  if ( resetAll ){
     for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
-       fCellSize[chCath].Set(fgkNslats);
-       fCellNumber[chCath].Set(fgkNslats);
-       for(Int_t slat=0; slat<fgkNslats; slat++){
-           fCellContent[chCath][slat].ResizeTo(fgkNcells,fgkNcells);
-       }
+      if ( fBoardEfficiency[chCath] ) {
+       fBoardEfficiency[chCath] = 0x0;
+      }
+      if ( fSlatEfficiency[chCath] ) {
+       fSlatEfficiency[chCath] = 0x0;
+      }
     }
 
-    for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
-       fCellSize[chCath].Reset();
-       fCellNumber[chCath].Reset();
-       for(Int_t slat=0; slat<fgkNslats; slat++){
-           fCellContent[chCath][slat].Zero();
-       }
-    }
+    if ( fCountHistoList )
+      delete fCountHistoList;
+    if ( fNoCountHistoList )
+      delete fNoCountHistoList;
+  }
 
-    for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
-      fBoardEfficiency[chCath] = 0x0;
-      fSlatEfficiency[chCath] = 0x0;
-    }
-    
+  if ( fFiredStrips )
+    delete fFiredStrips;
+  if ( fDisplayHistoList )
+    delete fDisplayHistoList;
+  if ( fBoardLabelList )
+    delete fBoardLabelList;
+  if ( fFiredFitHistoList )
+    delete fFiredFitHistoList;
+  if ( fFiredDisplayHistoList )
+    delete fFiredDisplayHistoList;
 }
 
 
@@ -445,18 +386,19 @@ AliMUONTriggerEfficiencyCells::InitHistos()
 ///  Sets our internal array contents to zero.
 
   const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
+  const Int_t kNslats = 18;
   Int_t chCath=0;
-  Char_t histoName[40];
+  TString histoName;
 
-  Char_t *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
+  TString cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
 
   for(Int_t ch=0; ch<fgkNchambers; ch++){
     for(Int_t cath=0; cath<fgkNcathodes; cath++){
-      chCath = fgkNchambers*cath + ch;
-      sprintf(histoName, "%sBoardEffChamber%i", cathCode[cath], 11+ch);
-      fBoardEfficiency[chCath] = new TH1F(histoName, histoName, kNumOfBoards, 1-0.5, kNumOfBoards+1.-0.5);
-      sprintf(histoName, "%sSlatEffChamber%i", cathCode[cath], 11+ch);
-      fSlatEfficiency[chCath] = new TH1F(histoName, histoName, fgkNslats, 0-0.5, fgkNslats-0.5);
+      chCath = GetPlane(ch, cath);
+      histoName = Form("%sBoardEffChamber%i", cathCode[cath].Data(), 11+ch);
+      fBoardEfficiency[chCath] = new TH1F(histoName.Data(), histoName.Data(), kNumOfBoards, 1-0.5, kNumOfBoards+1.-0.5);
+      histoName = Form("%sSlatEffChamber%i", cathCode[cath].Data(), 11+ch);
+      fSlatEfficiency[chCath] = new TH1F(histoName.Data(), histoName.Data(), kNslats, 0-0.5, kNslats-0.5);
     }
   }
 }
@@ -464,18 +406,21 @@ AliMUONTriggerEfficiencyCells::InitHistos()
 
 //__________________________________________________________________________
 void
-AliMUONTriggerEfficiencyCells::FillHistosFromList()
+AliMUONTriggerEfficiencyCells::FillHistosFromList(Bool_t useMeanValues)
 {
-///  Sets our internal array contents to zero.
+///  Fills internal histos from list.
 
   Int_t nHistoBins=0;
   TH1F *histoNum = 0x0, *histoDen=0x0, *currHisto = 0x0;
-  TString slatName = "Slat", boardName = "Board", histoName;
-  Int_t iHistoBoard = -1, iHistoSlat = -1;
+  TString slatName = "SLAT", boardName = "BOARD", histoName;
   Float_t efficiency, efficiencyError;
+  TString chName;
 
   Int_t nentries = fCountHistoList->GetEntries();
 
+  if ( useMeanValues )
+    AliInfo("Boards filled with the average efficiency of the RPC");
+
   for(Int_t iEntry=0; iEntry<nentries; iEntry++){
     histoNum = (TH1F*)fCountHistoList->At(iEntry);
     histoDen = (TH1F*)fNoCountHistoList->At(iEntry);
@@ -490,17 +435,31 @@ AliMUONTriggerEfficiencyCells::FillHistosFromList()
     }
 
     histoName = histoNum->GetName();
+    histoName.ToUpper();
     nHistoBins = histoNum->GetNbinsX();
 
+
+    Int_t currCh = 0;
+    for(Int_t ich = 11; ich<=14; ich++){
+      chName = Form("%i", ich);
+      if ( histoName.Contains(chName.Data())){
+       currCh = ich-11;
+       break;
+      }
+    }
+    Int_t currCath = ( histoName.Contains("NONBEND") ) ? 1 : 0;
+
+    Int_t chCath = GetPlane(currCh, currCath);
+
     if(histoName.Contains(boardName)){
-      iHistoBoard++;
-      currHisto = fBoardEfficiency[iHistoBoard];
+      if ( useMeanValues ) continue;
+      currHisto = fBoardEfficiency[chCath];
     }
     else if(histoName.Contains(slatName)){
-      iHistoSlat++;
-      currHisto = fSlatEfficiency[iHistoSlat];
+      currHisto = fSlatEfficiency[chCath];
     }
-    else continue;
+    else
+      continue;
 
     for(Int_t iBin=1; iBin<=nHistoBins; iBin++){
       CalculateEfficiency((Int_t)histoNum->GetBinContent(iBin), (Int_t)histoNum->GetBinContent(iBin) + (Int_t)histoDen->GetBinContent(iBin), efficiency, efficiencyError, kFALSE);
@@ -508,11 +467,25 @@ AliMUONTriggerEfficiencyCells::FillHistosFromList()
       currHisto->SetBinContent(iBin, efficiency);
       currHisto->SetBinError(iBin, efficiencyError);
     }
+
+    if ( useMeanValues ){
+      currHisto = fBoardEfficiency[chCath];
+      Int_t nBinsBoards = currHisto->GetNbinsX();
+      Int_t currChamber = currCh + AliMpConstants::NofTrackingChambers();
+      for ( Int_t iBinBoard = 1; iBinBoard<= nBinsBoards; iBinBoard++){
+       Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(iBinBoard, currChamber);
+       Int_t iBin = histoNum->FindBin(detElemId%100);
+
+       CalculateEfficiency((Int_t)histoNum->GetBinContent(iBin), (Int_t)histoNum->GetBinContent(iBin) + (Int_t)histoDen->GetBinContent(iBin), efficiency, efficiencyError, kFALSE);
+
+       currHisto->SetBinContent(iBinBoard, efficiency);
+       currHisto->SetBinError(iBinBoard, efficiencyError);
+      }
+    }
   }
 }
 
 
-
 //_____________________________________________________________________________
 void AliMUONTriggerEfficiencyCells::CalculateEfficiency(Int_t trigger44, Int_t trigger34,
                                                        Float_t &efficiency, Float_t &error,
@@ -533,6 +506,60 @@ void AliMUONTriggerEfficiencyCells::CalculateEfficiency(Int_t trigger44, Int_t t
     else error = TMath::Sqrt(efficiency*q/((Double_t)trigger34));
 }
 
+
+//_____________________________________________________________________________
+void AliMUONTriggerEfficiencyCells::CheckFiredStrips()
+{
+  //
+  /// Check for fired strips participating to efficiency
+  /// calculation (when available).
+  /// Strips inside a local board should be quite homogeneously hit
+  /// If not, this could be a problem of electronics (i.e. ADULT board off).
+  //
+
+  if(!fFiredStrips) {
+    AliWarning("List of fired pads not present. Check not performable.");
+    return;
+  }
+
+  GetListsForCheck();
+
+  TString histoName;
+
+  // Check fired pads (when available)
+  if(fFiredFitHistoList){
+    TH1F *histo1D = 0x0;
+    TF1 *fitFunc = 0x0;
+    TCanvas *histoFiredCan[20];
+    Int_t nEntries = fFiredFitHistoList->GetEntries();
+    for(Int_t iEntry=0; iEntry<nEntries; iEntry++){
+      histo1D = (TH1F*)fFiredFitHistoList->At(iEntry);
+      printf("Problems found in %s\n", histo1D->GetTitle());
+    }
+    Int_t nPrintCan = nEntries;
+    if(nPrintCan>20) {
+      AliWarning("Too many boards with problems: only 20 will be shown");
+      nPrintCan = 20;
+    }
+    for(Int_t iCan=0; iCan<nPrintCan; iCan++){
+      histo1D = (TH1F*)fFiredFitHistoList->At(iCan);
+      histoName = histo1D->GetName();
+      histoName.Append("Can");
+      histoFiredCan[iCan] = new TCanvas(histoName.Data(), histoName.Data(), 100+10*iCan, 10*iCan, 700, 700);
+      histoFiredCan[iCan]->SetRightMargin(0.14);
+      histoFiredCan[iCan]->SetLeftMargin(0.12);
+      histo1D->Draw("E");
+      fitFunc = histo1D->GetFunction("pol0");
+      fitFunc->SetLineColor(2);
+      fitFunc->Draw("same");
+    }
+    if(nEntries==0){
+      printf("\nAll local boards seem ok!!\n\n");
+    }
+  }
+}
+
+
 //_____________________________________________________________________________
 void AliMUONTriggerEfficiencyCells::DisplayEfficiency(Bool_t perSlat)
 {
@@ -540,8 +567,6 @@ void AliMUONTriggerEfficiencyCells::DisplayEfficiency(Bool_t perSlat)
   /// Display calculated efficiency.
   //
 
-  const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
-
   Bool_t isInitSlat = kFALSE, isInitBoard = kFALSE;
   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
     if(fBoardEfficiency[chCath]->GetEntries()>0) isInitBoard = kTRUE;
@@ -549,157 +574,210 @@ void AliMUONTriggerEfficiencyCells::DisplayEfficiency(Bool_t perSlat)
   }
 
   if(!isInitBoard){
-    printf("Trigger efficiency not initialized per board.\nDisplay not yet implemented.\n");
+    AliWarning("Trigger efficiency not initialized per board.\nDisplay not yet implemented.");
     return;
   }
   if(!isInitSlat && perSlat){
-    printf("Trigger efficiency not initialized for slat.\nPlease try option kFALSE.\n");
+    AliWarning("Trigger efficiency not initialized for slat.\nPlease try option kFALSE.");
     return;
   }
-
-  Int_t side, col, line, nbx, slat;
-  Float_t xCenter, yCenter, zCenter, xWidth, yWidth;
-  Float_t x1Label, x2Label, y1Label, y2Label;
-  Int_t x1, y1, x2, y2, board=0;
-  Char_t name[8], text[200];
-
-  gStyle->SetPalette(1);
-
-  Char_t *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
-
-  Float_t boardsX = 257.00;  // cm
-  Float_t boardsY = 307.00;  // cm
-
-  TH2F *histo[fgkNplanes];
-  TPaveLabel *boardLabel[fgkNplanes][234];
-  assert(kNumOfBoards==234);    
-  TArrayI boardsPerColumn[9];
-  for(Int_t iLine=0; iLine<9; iLine++){
-    boardsPerColumn[iLine].Set(7);
-    boardsPerColumn[iLine].Reset();
+  if ( !AliCDBManager::Instance()->GetDefaultStorage() ){
+    AliWarning("Please set default CDB storage (needed for mapping).");
+    return;
+  }
+  if ( AliCDBManager::Instance()->GetRun() < 0 ){
+    AliWarning("Please set CDB run number (needed for mapping).");
+    return;
   }
+  
+  GetListsForCheck();
 
-  Char_t histoName[40], histoTitle[90], labelTxt[5];
+  //const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
 
-  Float_t efficiency, efficiencyError;
+  TH2F *histo = 0x0;
+  TString histoName, histoTitle;
 
-  for(Int_t cath=0; cath<fgkNcathodes; cath++){
-    for(Int_t ch=0; ch<fgkNchambers; ch++){
-      Int_t chCath = fgkNchambers*cath + ch;
-      sprintf(histoName, "%sChamber%i", cathCode[cath], 11+ch);
-      sprintf(histoTitle, "Chamber %i: efficiency %s", 11+ch, cathCode[cath]);
-      histo[chCath] = new TH2F(histoName, histoTitle, (Int_t)boardsX, -boardsX, boardsX, (Int_t)boardsY, -boardsY, boardsY);
-      histo[chCath]->SetXTitle("X (cm)");
-      histo[chCath]->SetYTitle("Y (cm)");
+  // Plot fired strips (when available)
+  if(fFiredDisplayHistoList){
+    TCanvas *displayFiredCan[fgkNplanes];
+    for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+      histo = (TH2F*)fFiredDisplayHistoList->At(chCath);
+      histoName = Form("%sCan", histo->GetName());
+      histoTitle = Form("%s", histo->GetTitle());
+      displayFiredCan[chCath] = new TCanvas(histoName.Data(), histoTitle.Data(), 100+10*chCath, 10*chCath, 700, 700);
+      displayFiredCan[chCath]->SetRightMargin(0.14);
+      displayFiredCan[chCath]->SetLeftMargin(0.12);
+      histo->GetYaxis()->SetTitleOffset(1.4);
+      histo->SetStats(kFALSE);
+      histo->Draw("COLZ");
     }
   }
 
-  TString mapspath = gSystem->Getenv("ALICE_ROOT");
-  mapspath.Append("/MUON/data");
-
-  sprintf(text,"%s/guimapp11.txt",mapspath.Data());
-
-  FileStat_t fs;
-  if(gSystem->GetPathInfo(text,fs)){
-    AliWarning(Form("Map file %s not found. Nothing done",text));
-    return;
+  // Plot efficiency
+  if(fDisplayHistoList){
+    TCanvas *can[fgkNplanes];
+    for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+      Int_t currChCath = chCath;
+      if(perSlat==kTRUE) currChCath += fgkNplanes;
+      histo = (TH2F*)fDisplayHistoList->At(currChCath);
+      histoName = Form("%sCan", histo->GetName());
+      histoTitle = Form("%s", histo->GetTitle());
+      can[chCath] = new TCanvas(histoName.Data(), histoTitle.Data(), 100+10*chCath, 10*chCath, 700, 700);
+      can[chCath]->SetRightMargin(0.14);
+      can[chCath]->SetLeftMargin(0.12);
+      histo->GetZaxis()->SetRangeUser(0.,1.);
+      histo->GetYaxis()->SetTitleOffset(1.4);
+      histo->SetStats(kFALSE);
+      histo->Draw("COLZ");
+      if(perSlat==kTRUE) continue;
+      histo = (TH2F*)fBoardLabelList->At(currChCath);
+      histo->Draw("textsame");
+    }
   }
+}
 
-  FILE *fmap = fopen(text,"r");
 
-  for (Int_t ib = 0; ib < kNumOfBoards; ib++) {
-    fscanf(fmap,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
-    if(side==0) continue;
-    boardsPerColumn[line-1][col-1]++;
+//__________________________________________________________________________
+Bool_t AliMUONTriggerEfficiencyCells::GetListsForCheck()
+{
+  //
+  /// Getting histograms for efficiency, 
+  /// map of fired strips entering efficiency calculations,
+  /// fits for checking switched-off elements in chambers.
+  //
+  const Float_t kChi2RedMax = 1.5;
+  const Float_t kDummyFired = 1e-5;
+
+  Reset(kFALSE);
+
+  fDisplayHistoList = new TList();
+  fDisplayHistoList->SetOwner();
+  fBoardLabelList = new TList();
+  fBoardLabelList->SetOwner();
+  if ( fFiredStrips ){
+    fFiredFitHistoList = new TList();
+    fFiredFitHistoList->SetOwner();
+    fFiredDisplayHistoList = new TList();
+    fFiredDisplayHistoList->SetOwner();
   }
 
-  rewind(fmap);
-
-  for (Int_t ib = 0; ib < kNumOfBoards; ib++) {
-    fscanf(fmap,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
-
-    board=0;
-    for(Int_t iCol=1; iCol<=col; iCol++){
-      Int_t lastLine = 9;
-      if(iCol==col) lastLine = line-1;
-      for(Int_t iLine=1; iLine<=lastLine; iLine++){
-       board += boardsPerColumn[iLine-1][iCol-1];
-      }
+  TH3F* padFired = 0x0;
+  TH2F* displayHisto = 0x0;
+  TH1F* histoFired[fgkNplanes][234];
+  TF1* fitFunc = 0x0;
+  Bool_t isStripOffInBoard[fgkNplanes][234];
+  Int_t bin=0;
+  TString histoName, histoTitle;
+  TString cathName[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
+
+  AliMUONTriggerDisplay triggerDisplay;
+  // Book histos
+  for(Int_t iCath=0; iCath<fgkNcathodes; iCath++){
+    if(fFiredStrips) padFired = (TH3F*)fFiredStrips->At(iCath);
+    for(Int_t iCh=0; iCh<fgkNchambers; iCh++){
+      Int_t chCath = GetPlane(iCh, iCath);
+      Int_t currCh = 11 + iCh;
+      histoName = Form("%sChamber%i", cathName[iCath].Data(), currCh);
+      histoTitle = Form("Chamber %i: efficiency %s", currCh, cathName[iCath].Data());
+      displayHisto = 
+       (TH2F*)triggerDisplay.GetDisplayHistogram(fBoardEfficiency[chCath], histoName,
+                                                 AliMUONTriggerDisplay::kDisplayBoards,
+                                                 iCath,currCh,histoTitle,
+                                                 AliMUONTriggerDisplay::kShowZeroes);
+      fDisplayHistoList->Add(displayHisto);
+
+      histoName = Form("labels%sChamber%i", cathName[iCath].Data(), currCh);
+      displayHisto = 
+       (TH2F*)triggerDisplay.GetBoardNumberHisto(histoName,currCh);
+      fBoardLabelList->Add(displayHisto);
+
+      if(!fFiredStrips) continue;
+      histoName = Form("firedPads%sChamber%i", cathName[iCath].Data(), currCh);
+      histoTitle = Form("Chamber %i: Fired pads %s", currCh, cathName[iCath].Data());
+      bin = padFired->GetXaxis()->FindBin(currCh);
+      padFired->GetXaxis()->SetRange(bin,bin);
+      displayHisto = 
+       (TH2F*)triggerDisplay.GetDisplayHistogram(padFired->Project3D("zy"),histoName,
+                                                 AliMUONTriggerDisplay::kDisplayStrips,
+                                                 iCath,currCh,histoTitle);
+      fFiredDisplayHistoList->Add(displayHisto);
+      
+      for(Int_t ib=0; ib<AliMpConstants::NofLocalBoards(); ib++){
+       histoName = Form("%sChamber%iBoard%i", cathName[iCath].Data(), currCh, ib+1);
+       histoTitle = Form("Chamber %i: fired pads %s board = %i", currCh, cathName[iCath].Data(), ib+1);
+       histoFired[chCath][ib] = new TH1F(histoName.Data(), histoTitle.Data(), 16, -0.5, 15.5);
+       histoFired[chCath][ib]->SetXTitle("board");
+       isStripOffInBoard[chCath][ib] = kFALSE;
+      } // loop on board
+    } // loop on chamber
+  } // loop on cathode
+
+  for(Int_t iCath=0; iCath<fgkNcathodes; iCath++){
+    for(Int_t iCh=0; iCh<fgkNchambers; iCh++){
+      Int_t chCath = GetPlane(iCh, iCath);
+      Int_t currCh = 11+iCh;
+      histoName = Form("%sChamber%iSlatEff", cathName[iCath].Data(), currCh);
+      histoTitle = Form("Chamber %i: efficiency %s per slat", currCh, cathName[iCath].Data());
+      displayHisto = 
+       (TH2F*)triggerDisplay.GetDisplayHistogram(fSlatEfficiency[chCath], histoName,
+                                                 AliMUONTriggerDisplay::kDisplaySlats,
+                                                 iCath,currCh,histoTitle);
+      fDisplayHistoList->Add(displayHisto);
     }
-    if(side==0) board += kNumOfBoards/2;
-    board += nbx - 1;
-
-    slat = (line+13)%fgkNslats;
-    if(side==0) slat = 14-line;
+  }
 
-    for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
-      x1 = histo[chCath]->GetXaxis()->FindBin(xCenter-xWidth/2.)+1;
-      y1 = histo[chCath]->GetYaxis()->FindBin(yCenter-yWidth/2.)+1;
-      x2 = histo[chCath]->GetXaxis()->FindBin(xCenter+xWidth/2.)-1;
-      y2 = histo[chCath]->GetYaxis()->FindBin(yCenter+yWidth/2.)-1;
-
-      x1Label = xCenter-xWidth/2.;
-      y1Label = yCenter-yWidth/2.;
-      x2Label = xCenter+xWidth/2.;
-      y2Label =  yCenter+yWidth/2.;
-      sprintf(labelTxt,"%3d", board+1);
-      if(perSlat){
-       x1Label = 140.;
-       x2Label = x1Label + 40.;
-       y1Label = -285. + ((Float_t)(line - 1)) * 68;
-       y2Label = y1Label + 34.;
-       if(side==0){
-         x1Label = -x2Label;
-         x2Label = x1Label + 40.;
+  if(!fFiredStrips) return kTRUE;
+
+  AliMpCDB::LoadDDLStore();
+
+  // Check fired pads (when available)
+  for(Int_t iLoc = 0; iLoc < AliMpConstants::NofLocalBoards(); iLoc++) {  
+    Int_t iBoard = iLoc+1;
+    for(Int_t iCh=0; iCh<AliMpConstants::NofChambers(); iCh++){
+      Int_t iChamber = iCh + AliMpConstants::NofTrackingChambers();
+
+      Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(iBoard, iChamber);
+
+      if (!detElemId) continue;
+
+      AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(iBoard, kFALSE);
+
+      // skip copy cards
+      if( !localBoard->IsNotified()) 
+       continue;
+      
+      for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
+       Int_t chCath = GetPlane(iCh, iCath);
+       // loop over strips
+       const AliMpVSegmentation* seg = 
+         AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
+       Int_t nStrips=0;
+       for (Int_t iStrip = 0; iStrip < 16; ++iStrip) {
+         AliMpPad pad = seg->PadByLocation(iBoard,iStrip,kFALSE);
+         if (!pad.IsValid()) continue;
+         nStrips++;
+         padFired = (TH3F*)fFiredStrips->At(iCath);
+         Float_t nFired = padFired->GetBinContent(11+iCh, iBoard, iStrip);
+         if(nFired==0.) nFired = kDummyFired;
+         histoFired[chCath][iLoc]->Fill(iStrip, nFired);
        }
-       sprintf(labelTxt,"%2d", slat);
-      }
-    
-      boardLabel[chCath][board] = new TPaveLabel(x1Label, y1Label, x2Label, y2Label, labelTxt);
-      boardLabel[chCath][board]->SetFillStyle(0);
-      boardLabel[chCath][board]->SetBorderSize(0);
-
-      Int_t histoBin = board+1;
-      if(perSlat) histoBin = slat+1;
-
-      if(!perSlat){
-       efficiency = fBoardEfficiency[chCath]->GetBinContent(histoBin);
-       efficiencyError = fBoardEfficiency[chCath]->GetBinError(histoBin);
-      }
-      else {
-       efficiency = fSlatEfficiency[chCath]->GetBinContent(histoBin);
-       efficiencyError = fSlatEfficiency[chCath]->GetBinError(histoBin);
-      }
 
-      for(Int_t binX=x1; binX<=x2; binX++){
-       for(Int_t binY=y1; binY<=y2; binY++){
-         histo[chCath]->SetBinContent(binX, binY, efficiency);
-         histo[chCath]->SetBinError(binX, binY, efficiencyError);
+       histoFired[chCath][iLoc]->Fit("pol0","Q0R","",0., (Float_t)nStrips-1.);
+       fitFunc = histoFired[chCath][iLoc]->GetFunction("pol0");
+       Float_t chi2 = fitFunc->GetChisquare();
+       Float_t ndf = (Float_t)fitFunc->GetNDF();
+       Float_t reducedChi2 = chi2/ndf;
+       if(reducedChi2>kChi2RedMax) {
+         isStripOffInBoard[chCath][iLoc] = kTRUE;
+         fFiredFitHistoList->Add(histoFired[chCath][iLoc]);
        }
-      }
-    }
-  }
-
-  fclose(fmap);
+      } // loop on cathodes
+    } // loop on chambers
+  } // loop on local boards 
 
-  TCanvas *can[8];
-  for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
-    sprintf(histoName, "%sCan", histo[chCath]->GetName());
-    sprintf(histoTitle, "%s", histo[chCath]->GetTitle());
-    can[chCath] = new TCanvas(histoName, histoTitle, 100+10*chCath, 10*chCath, 700, 700);
-    can[chCath]->SetRightMargin(0.14);
-    can[chCath]->SetLeftMargin(0.12);
-    histo[chCath]->GetZaxis()->SetRangeUser(0.,1.);
-    histo[chCath]->GetYaxis()->SetTitleOffset(1.4);
-    histo[chCath]->SetStats(kFALSE);
-    histo[chCath]->Draw("COLZ");
-    for (Int_t board = 0; board < kNumOfBoards; board++) {
-      boardLabel[chCath][board]->Draw("same");
-    }
-  }
+  return kTRUE;
 }
 
-
 //__________________________________________________________________________
 Bool_t AliMUONTriggerEfficiencyCells::SumRunEfficiency(const AliMUONTriggerEfficiencyCells &other)
 {
@@ -726,5 +804,57 @@ Bool_t AliMUONTriggerEfficiencyCells::SumRunEfficiency(const AliMUONTriggerEffic
   }
 
   FillHistosFromList();
+
+  if(!fFiredStrips) {
+    AliWarning("Histograms for fired region check not implemented in object");
+    return kFALSE;
+  }
+  if(!other.fFiredStrips) {
+    AliWarning("Histograms for fired region check not implemented in object passed as argument");
+    return kFALSE;
+  }
+  
+  TH3F *currFired = 0x0, *otherFired = 0x0;
+  nentries = fFiredStrips->GetEntries();
+  for(Int_t iEntry=0; iEntry<nentries; iEntry++){
+    currFired  = (TH3F*)fFiredStrips->At(iEntry);
+    otherFired = (TH3F*)fFiredStrips->At(iEntry);
+    currFired->Add(otherFired);
+  }
+    
+  return kTRUE;
+}
+
+
+//__________________________________________________________________________
+Bool_t AliMUONTriggerEfficiencyCells::LowStatisticsSettings(Bool_t useMeanValues)
+{
+  //
+  /// In case of low statistics, fill the local board efficiency with
+  /// the average value of the RPC
+  //
+
+  if ( ! fCountHistoList ){
+    AliWarning("Cannot find histograms for RPC efficiency calculation. Nothing done!");
+    return kFALSE;
+  }
+  if ( !AliCDBManager::Instance()->GetDefaultStorage() ){
+    AliWarning("Please set default CDB storage (needed for mapping).");
+    return kFALSE;
+  }
+  if ( AliCDBManager::Instance()->GetRun() < 0 ){
+    AliWarning("Please set CDB run number (needed for mapping).");
+    return kFALSE;
+  }
+
+  AliMpCDB::LoadDDLStore();
+  
+  for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+    fBoardEfficiency[chCath]->Reset();
+    fSlatEfficiency[chCath]->Reset();
+  }
+
+  FillHistosFromList(useMeanValues);
+
   return kTRUE;
 }