]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerElectronics.cxx
TDC added to monitor ZDC timing via DQM
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerElectronics.cxx
index bf407a3b00a50807e62799b00638f78bac4d6466..577d2696052981c325f149b8852737543fff06dc 100644 (file)
 
 /* $Id$ */
 
-//*-- Author: Rachid Guernane (LPCCFd)
-//*   Manager class for muon trigger electronics
-//*   Client of trigger board classes
-//*
-//*
+//-----------------------------------------------------------------------------
+// Class AliMUONTriggerElectronics
+//--------------------------------
+// Manager class for muon trigger electronics
+// Client of trigger board classes
+// Debugged by Ph. Crochet & Ch. Finck
+// Interfaced with new mapping Ch. Finck
+//
+// Author: Rachid Guernane (LPCCFd)
+//-----------------------------------------------------------------------------
 
 #include "AliLoader.h"
 #include "AliLog.h"
-#include "AliMUON.h" 
 #include "AliMUONCalibrationData.h"
 #include "AliMUONVDigit.h"
 #include "AliMUONVDigitStore.h"
 #include "AliMUONTriggerCrate.h"
 #include "AliMUONTriggerCrateStore.h"
 #include "AliMUONTriggerElectronics.h"
+#include "AliMUONTriggerCrateConfig.h"
+#include "AliMUONRegionalTriggerConfig.h"
+#include "AliMUONGlobalCrateConfig.h"
 #include "AliMUONVTriggerStore.h"
 #include "AliMUONVCalibParam.h"
 #include "AliMpCathodType.h"
+#include "AliMpCDB.h"
 #include "AliMpDEManager.h"
 #include "AliMpSegmentation.h"
 #include "AliMpVSegmentation.h"
 #include "AliMpCathodType.h"
-
-#include "AliMUONTriggerGUIboard.h"
+#include "AliMpTriggerCrate.h"
+#include "AliMpLocalBoard.h"
+#include "AliMpDDLStore.h"
+#include "AliMpExMap.h"
+#include "AliMpIntPair.h"
 
 #include "AliLog.h"
 #include "AliLoader.h"
@@ -52,6 +63,8 @@
 #include <TBits.h>
 #include <TSystem.h>
 
+#include "AliCodeTimer.h"
+
 
 /// \cond CLASSIMP
 ClassImp(AliMUONTriggerElectronics)
@@ -60,15 +73,29 @@ ClassImp(AliMUONTriggerElectronics)
 //___________________________________________
 AliMUONTriggerElectronics::AliMUONTriggerElectronics(AliMUONCalibrationData* calibData) 
 : TObject(),
-  fSourceFileName(),
   fCrates(new AliMUONTriggerCrateStore),
   fGlobalTriggerBoard(new AliMUONGlobalTriggerBoard)
 {
  /// CONSTRUCTOR
 ///
-  SetDataSource();
+
+  for (Int_t i = 0; i < 2; ++i) {
+    fCopyXInput[i] = new TList();
+    fCopyXInput[i]->SetOwner();
+    fCopyYInput[i] = new TList();
+    fCopyYInput[i]->SetOwner();
+  }
+
+  // force loading of mapping if not already done
+  if ( !AliMpDDLStore::Instance(kFALSE) )
+  {
+    AliMpCDB::LoadDDLStore();
+  }
+  
+  SetCopyInput();
+  
   Factory(calibData);
-  LoadMasks(calibData);
+  LoadMasks(calibData); 
 }
 
 //___________________________________________
@@ -78,6 +105,61 @@ AliMUONTriggerElectronics::~AliMUONTriggerElectronics()
 ///
   delete fGlobalTriggerBoard;
   delete fCrates;
+  for (Int_t i = 0; i < 2; ++i) {
+    delete fCopyXInput[i];
+    delete fCopyYInput[i];
+  }
+
+}
+
+//___________________________________________
+void AliMUONTriggerElectronics::SetCopyInput()
+{  
+  /// set list of copy input
+  
+    for (Int_t iDDL = 0; iDDL < 2; ++iDDL) { 
+    
+      for(Int_t iReg = 0; iReg < 8; ++iReg){   //reg loop
+      
+       AliMpTriggerCrate* crateMapping = AliMpDDLStore::Instance()->GetTriggerCrate(iDDL, iReg);
+      
+       for(Int_t iLocal = 0; iLocal < crateMapping->GetNofLocalBoards(); ++iLocal) { 
+        
+         Int_t localBoardFromId = crateMapping->GetLocalBoardId(iLocal);
+         if (!localBoardFromId) continue; //empty slot, should not happen
+        
+          AliMpLocalBoard* localBoardFrom = AliMpDDLStore::Instance()->GetLocalBoard(localBoardFromId);
+         Int_t localBoardToId;
+         if ((localBoardToId = localBoardFrom->GetInputXto())) {
+             AliMpLocalBoard* localBoardTo = AliMpDDLStore::Instance()->GetLocalBoard(localBoardToId);
+             TString crateFrom = localBoardFrom->GetCrate();
+             Int_t   slotFrom  = localBoardFrom->GetSlot();
+             TString crateTo   = localBoardTo->GetCrate();
+             Int_t   slotTo    = localBoardTo->GetSlot();
+          
+             fCopyXInput[0]->Add(new AliMpIntPair(AliMpExMap::GetIndex(crateFrom), slotFrom));
+             fCopyXInput[1]->Add(new AliMpIntPair(AliMpExMap::GetIndex(crateTo), slotTo));
+             AliDebug(3, Form("copy xInputs from local  %s_%d to %s_%d\n", crateFrom.Data(), slotFrom, 
+                              crateTo.Data(), slotTo));
+         }
+        
+         if ((localBoardToId = localBoardFrom->GetInputYto())) {
+             AliMpLocalBoard* localBoardTo = AliMpDDLStore::Instance()->GetLocalBoard(localBoardToId);
+             TString crateFrom = localBoardFrom->GetCrate();
+             Int_t   slotFrom  = localBoardFrom->GetSlot();
+             TString crateTo   = localBoardTo->GetCrate();
+             Int_t   slotTo    = localBoardTo->GetSlot();
+          
+             fCopyYInput[0]->Add(new AliMpIntPair(AliMpExMap::GetIndex(crateFrom), slotFrom));
+             fCopyYInput[1]->Add(new AliMpIntPair(AliMpExMap::GetIndex(crateTo), slotTo));
+             AliDebug(3, Form("copy yInputs from local  %s_%d to %s_%d\n", crateFrom.Data(), slotFrom, 
+                              crateTo.Data(), slotTo));
+          
+         }
+       }
+      }
+    }
 }
 
 //___________________________________________
@@ -86,31 +168,7 @@ void AliMUONTriggerElectronics::Factory(AliMUONCalibrationData* calibData)
  /// BUILD ALL ELECTRONICS
  ///
 
-// get coinc44 from AliMUON (added 12/09/06)
-  AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
-  Int_t coinc44 = pMUON->GetTriggerCoinc44();
-  if (coinc44 != 0 && coinc44 != 1) {
-      AliFatal("Coinc 44 should be equal to 0 or 1");
-      return;
-  }
-
-  fCrates->ReadFromFile(gSystem->ExpandPathName(fSourceFileName.Data()));
-  
-  if ( !calibData ) return;
-  
-  AliMUONTriggerLut* lut = calibData->TriggerLut();
-  
-  if (!lut) return;
-  
-  AliMUONLocalTriggerBoard* localBoard;
-  
-  fCrates->FirstLocalBoard();
-  
-  while ( (localBoard=fCrates->NextLocalBoard()) )
-  {
-    localBoard->SetLUT(lut);
-    localBoard->SetCoinc44(coinc44);
-  }
+    fCrates->ReadFromFile(calibData);
 }
 
 //___________________________________________
@@ -118,6 +176,8 @@ void AliMUONTriggerElectronics::Feed(const AliMUONVDigitStore& digitStore)
 {
   /// FILL INPUTS
   ///
+
+  AliCodeTimerAuto("",0);
   
   TIter next(digitStore.CreateTriggerIterator());
   AliMUONVDigit* mdig;
@@ -136,30 +196,28 @@ void AliMUONTriggerElectronics::Feed(const AliMUONVDigitStore& digitStore)
     {
       Int_t detElemId  = mdig->DetElemId();
       Int_t cathode    = mdig->Cathode();
-      
-      const AliMpVSegmentation *seg = 
-        AliMpSegmentation::Instance()
-        ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
-      
+    
+      const AliMpVSegmentationseg = 
+         AliMpSegmentation::Instance()
+         ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
+  
       Int_t ix = mdig->PadX(), iy = mdig->PadY();
       
       AliDebug(3,Form("cathode %d ix %d iy %d ",cathode,ix,iy));
-      
-      AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
+
+      AliMpPad pad = seg->PadByIndices(ix,iy,kTRUE);
       
       for (Int_t i=0; i<pad.GetNofLocations(); i++) 
       {
-        AliMpIntPair location = pad.GetLocation(i);
+        Int_t nboard = pad.GetLocalBoardId(i);
         
-        Int_t nboard = location.GetFirst();
-        
-        Int_t ibitxy = location.GetSecond();
+        Int_t ibitxy = pad.GetLocalBoardChannel(i);
         
         AliMUONLocalTriggerBoard *b = fCrates->LocalBoard(nboard);
         
         if (b) 
         {
-          if (cathode && b->GetSwitch(6)) ibitxy += 8;
+          if (cathode && b->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) ibitxy += 8;
           
           b->SetbitM(ibitxy,cathode,ichamber-10);
         }
@@ -170,52 +228,76 @@ void AliMUONTriggerElectronics::Feed(const AliMUONVDigitStore& digitStore)
       }
     }          
   }
-  
+
+  FeedCopyNeighbours();
+}
+
+
+//___________________________________________
+void AliMUONTriggerElectronics::FeedCopyNeighbours()
+{
+  //
+  /// Feed the local copies
+  /// and complete the feed with the information of neighbours
+  //
+
   // Particular case of the columns with 22 local boards (2R(L) 3R(L))   
+  // fill copy input from mapping instead of hardcoded valued (Ch.F)
   AliMUONTriggerCrate *crate = 0x0; TObjArray *bs = 0x0;
-  
-  char *scratess[4] = {  "2R",   "2L",   "3L",   "3R"}; 
-  char *scratesd[4] = {"2-3R", "2-3L", "2-3L", "2-3R"}; 
-  Int_t    slotf[4] = {     2,      2,     10,     10}; 
-  Int_t    slotd[4] = {     1,      1,      9,      9}; 
-  
-  for (Int_t i = 0; i < 4; i++)
+
+  for (Int_t i = 0; i < fCopyXInput[0]->GetEntries(); ++i) 
   {
-    crate = fCrates->Crate(scratess[i]); 
+    AliMpIntPair* pair = (AliMpIntPair*)fCopyXInput[0]->At(i);
+    TString crateFrom  =  AliMpExMap::GetString(pair->GetFirst());
+    Int_t   slotFrom   =  pair->GetSecond();
+
+    pair = (AliMpIntPair*)fCopyXInput[1]->At(i);
+    TString crateTo  =  AliMpExMap::GetString(pair->GetFirst());
+    Int_t   slotTo   =  pair->GetSecond();
+
+    AliDebug(3, Form("copy xInputs from local  %s_%d to %s_%d\n", crateFrom.Data(), slotFrom, 
+                    crateTo.Data(), slotTo));
+
+    UShort_t cX[2];
+    crate = fCrates->Crate(crateFrom); 
     bs = crate->Boards();
-    AliMUONLocalTriggerBoard *desybb = (AliMUONLocalTriggerBoard*)bs->At(14);
-    AliMUONLocalTriggerBoard *fromcb = (AliMUONLocalTriggerBoard*)bs->At(15);
-    AliMUONLocalTriggerBoard *desxbb = (AliMUONLocalTriggerBoard*)bs->At(16);
-    
-    crate = fCrates->Crate(scratesd[i]); 
+    AliMUONLocalTriggerBoard *fromxb = (AliMUONLocalTriggerBoard*)bs->At(slotFrom);
+    crate = fCrates->Crate(crateTo); 
     bs = crate->Boards();
-    AliMUONLocalTriggerBoard *frombb = (AliMUONLocalTriggerBoard*)bs->At(slotf[i]);
-    AliMUONLocalTriggerBoard *desycb = (AliMUONLocalTriggerBoard*)bs->At(slotd[i]);
-    
-    UShort_t cX[2];
-    
-    //    COPY X3-4 FROM BOARD  2 OF CRATE 2-3 TO BOARD 16 OF CRATE 2
-    //    COPY X3-4 FROM BOARD 10 OF CRATE 2-3 TO BOARD 16 OF CRATE 3
-    frombb->GetX34(cX); desxbb->SetX34(cX);
-    
-    //    COPY X3-4 FROM BOARD 15 OF CRATE 2 TO BOARD 1 OF CRATE 2-3
-    //    COPY X3-4 FROM BOARD 15 OF CRATE 3 TO BOARD 9 OF CRATE 2-3
-    fromcb->GetX34(cX); desycb->SetX34(cX);
-    
+    AliMUONLocalTriggerBoard *desxb = (AliMUONLocalTriggerBoard*)bs->At(slotTo);
+    fromxb->GetX34(cX); desxb->SetX34(cX);
+
+
+  }
+
+  for (Int_t i = 0; i < fCopyYInput[0]->GetEntries(); ++i) 
+  {
+    AliMpIntPair* pair = (AliMpIntPair*)fCopyYInput[0]->At(i);
+    TString crateFrom  =  AliMpExMap::GetString(pair->GetFirst());
+    Int_t   slotFrom   =  pair->GetSecond();
+
+    pair = (AliMpIntPair*)fCopyYInput[1]->At(i);
+    TString crateTo  =  AliMpExMap::GetString(pair->GetFirst());
+    Int_t   slotTo   =  pair->GetSecond();
+
+    AliDebug(3, Form("copy yInputs from local  %s_%d to %s_%d\n", crateFrom.Data(), slotFrom, 
+                    crateTo.Data(), slotTo));
+
     UShort_t cY[4];
-    
-    desybb->GetY(cY); frombb->SetY(cY);
-    
-    frombb->GetY(cY); desxbb->SetY(cY);
-    fromcb->GetY(cY); desycb->SetY(cY);
+    crate = fCrates->Crate(crateFrom); 
+    bs = crate->Boards();
+    AliMUONLocalTriggerBoard *fromyb = (AliMUONLocalTriggerBoard*)bs->At(slotFrom);
+    crate = fCrates->Crate(crateTo); 
+    bs = crate->Boards();
+    AliMUONLocalTriggerBoard *desyb = (AliMUONLocalTriggerBoard*)bs->At(slotTo);
+    fromyb->GetY(cY); desyb->SetY(cY);
   }
   
   // FILL UP/DOWN OF CURRENT BOARD (DONE VIA J3 BUS IN REAL LIFE)
   AliMUONTriggerCrate* cr;
+  TIter next2(fCrates->CreateCrateIterator());
   
-  fCrates->FirstCrate();
-  
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next2()) ) )
   {            
     TObjArray *boards = cr->Boards();
     
@@ -245,6 +327,7 @@ void AliMUONTriggerElectronics::Feed(const AliMUONVDigitStore& digitStore)
       }
     }
   }
 }
 
 
@@ -254,10 +337,9 @@ void AliMUONTriggerElectronics::Feed(UShort_t pattern[2][4])
   /// FILL INPUTS
   ///
   AliMUONTriggerCrate* cr;
+  TIter next(fCrates->CreateCrateIterator());
    
-   fCrates->FirstCrate();
-   
-   while ( ( cr = fCrates->NextCrate() ) )
+   while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
    {                 
      TObjArray *boards = cr->Boards();
      
@@ -288,16 +370,15 @@ void AliMUONTriggerElectronics::DumpOS()
 }
 
 //___________________________________________
-void AliMUONTriggerElectronics::Scan(Option_t *option)
+void AliMUONTriggerElectronics::Scan(const Option_t *option)
 {
   /// SCAN
   ///
 
   AliMUONTriggerCrate* cr;
+  TIter next(fCrates->CreateCrateIterator());  
   
-  fCrates->FirstCrate();
-  
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
   {                
     TObjArray *boards = cr->Boards();
     
@@ -329,10 +410,8 @@ void AliMUONTriggerElectronics::Reset()
   ///
   
    AliMUONTriggerCrate* cr;
-   
-   fCrates->FirstCrate();
-   
-   while ( ( cr = fCrates->NextCrate() ) )
+  TIter next(fCrates->CreateCrateIterator());
+   while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
    {            
       TObjArray *boards = cr->Boards();
             
@@ -345,35 +424,42 @@ void AliMUONTriggerElectronics::Reset()
    }
 }
 
+
 //_______________________________________________________________________
 void AliMUONTriggerElectronics::LoadMasks(AliMUONCalibrationData* calibData)
 {
-  /// LOAD MASKS FROM CDB
+  /// Load mask from config in CDB 
   
+  // Set mask
+  
+  AliMUONRegionalTriggerConfig* regionalConfig = calibData->RegionalTriggerConfig();
+  if (!regionalConfig)
+     AliWarning("No valid regional trigger configuration in CDB");
 
-  // SET MASKS
   
   AliMUONTriggerCrate* cr;
-  
-  fCrates->FirstCrate();
+  TIter next(fCrates->CreateCrateIterator());
   
   Int_t irb(0);
   
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
   {            
     TObjArray *boards = cr->Boards();
     
-    AliMUONRegionalTriggerBoard *regb =
-      (AliMUONRegionalTriggerBoard*)boards->At(0);
+    AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
 
-    AliMUONVCalibParam* regionalBoardMasks = calibData->RegionalTriggerBoardMasks(irb);
+    AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(cr->GetName());
     
-    for ( Int_t i = 0; i < regionalBoardMasks->Size(); ++i )
+    if (!crateConfig)
     {
-      UShort_t rmask = static_cast<UShort_t>(regionalBoardMasks->ValueAsInt(i) & 0x3F);
-      regb->Mask(i,rmask);
+      AliError(Form("Crate %s not present in configuration !!!", cr->GetName()));
+      return;
     }
     
+    UShort_t rmask= crateConfig->GetMask();
+
+    regb->Mask(rmask);
+    
     for (Int_t j = 1; j < boards->GetEntries(); j++)
     {
       AliMUONLocalTriggerBoard *b = (AliMUONLocalTriggerBoard*)boards->At(j);
@@ -393,32 +479,37 @@ void AliMUONTriggerElectronics::LoadMasks(AliMUONCalibrationData* calibData)
     ++irb;
   }
   
-  AliMUONVCalibParam* globalBoardMasks = calibData->GlobalTriggerBoardMasks();
-  for ( Int_t i = 0; i < globalBoardMasks->Size(); ++i )
-  {
-    UShort_t gmask = static_cast<UShort_t>(globalBoardMasks->ValueAsInt(i) & 0xFFF);
-    fGlobalTriggerBoard->Mask(i,gmask);
-  }
-}
+   AliMUONGlobalCrateConfig * globalConfig = calibData->GlobalTriggerCrateConfig();
+  if (!globalConfig)
+     AliWarning("No valid trigger crate configuration in CDB");
 
+    UInt_t gmask = 0;
+    for (Int_t i = 0; i < 4; i++) {
+      gmask = globalConfig->GetGlobalMask(i);
+      fGlobalTriggerBoard->Mask(i,gmask);
+    }
+}
 
 //___________________________________________
 void AliMUONTriggerElectronics::LocalResponse()
 {
-/// \todo add comment
+/// Compute the response for local cards
+
+  AliCodeTimerAuto("",0);
        
   AliMUONTriggerCrate* cr;
+  TIter next(fCrates->CreateCrateIterator());
+
+  UShort_t thisl[16];
   
-  fCrates->FirstCrate();
-  
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
   {            
     
     TObjArray *boards = cr->Boards();
     
     AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
     
-    UShort_t thisl[16]; for (Int_t j=0; j<16; j++) thisl[j] = 0;
+    for (Int_t j=0; j<16; ++j) thisl[j] = 0;
   
     for (Int_t j = 1; j < boards->GetEntries(); j++)
     {     
@@ -427,26 +518,23 @@ void AliMUONTriggerElectronics::LocalResponse()
        if (!o) break;
       
        AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
-      
-       if (board) // check if empty slot
-       {
-         board->Response();
-                               
-         UShort_t response = board->GetResponse();            
-        
-         // CRATE CONTAINING INTERFACE BOARD
-         if (board->GetNumber() == 0) // copy boards
-         {
-           if ( response != 0 ) 
-             AliWarning(Form("Interface board %s in slot %d of crate %s has a non zero response",
-                                         board->GetName(),j,cr->GetName()));
-           AliDebug(1, Form("local slot %d, number %d in crate %s\n", j, board->GetNumber(), cr->GetName()));
 
-         }
+       board->Response();
+                               
+       UShort_t response = board->GetResponse();            
         
-         thisl[j-1] = response;
+       // CRATE CONTAINING INTERFACE BOARD
+       if (board->GetNumber() == 0) // copy boards
+       {
+         if ( response != 0 ) 
+           AliWarning(Form("Interface board %s in slot %d of crate %s has a non zero response",
+                           board->GetName(),j,cr->GetName()));
+         AliDebug(1, Form("local slot %d, number %d in crate %s\n", j, board->GetNumber(), cr->GetName()));
+         
        }
-      }
+        
+       thisl[j-1] = response;
+    }
     
     regb->SetLocalResponse(thisl);
   }
@@ -456,20 +544,20 @@ void AliMUONTriggerElectronics::LocalResponse()
 void AliMUONTriggerElectronics::RegionalResponse()
 {
   /// Compute the response for all regional cards.
+
+  AliCodeTimerAuto("",0);
+
   AliMUONTriggerCrate* cr;
+  TIter next(fCrates->CreateCrateIterator());
   
-  fCrates->FirstCrate();
-  
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
   {            
       TObjArray *boards = cr->Boards();
 
       AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
-      
-      if (regb) 
-      {
-         regb->Response();
-      }  
+
+      regb->Response();
+
    }
 }
 
@@ -478,11 +566,11 @@ void AliMUONTriggerElectronics::GlobalResponse()
 {
   /// Compute the global response
 
+  AliCodeTimerAuto("",0);
+
   UShort_t regional[16];
   
   AliMUONTriggerCrate* cr;
-  
-  fCrates->FirstCrate();
   Int_t irb(0);
   
   if ( !fCrates->NumberOfCrates() >= 16 ) 
@@ -490,15 +578,23 @@ void AliMUONTriggerElectronics::GlobalResponse()
     AliFatal(Form("Something is wrong : too many crates %d",
                   fCrates->NumberOfCrates()));
   }
+
+  // send regional responses to the global trigger in right order
+  // do not used iterator order
   
-  while ( ( cr = fCrates->NextCrate() ) )
+  for (Int_t iSide = 0; iSide < 2; iSide++) // right & left side
   {            
-    AliMUONTriggerBoard* rb = 
-      static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0));
-    regional[irb] = rb->GetResponse();
-    ++irb;
+    for (Int_t iReg = 0; iReg < 8; iReg++) // 8 crates/regional boards for each side.
+    {
+      cr = fCrates->Crate(iSide, iReg);     
+
+      AliMUONTriggerBoard* rb = 
+       static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0));
+      regional[irb] = rb->GetResponse();
+      ++irb;
+    }
   }
-  
+
   fGlobalTriggerBoard->SetRegionalResponse(regional);
   fGlobalTriggerBoard->Response();
 }
@@ -507,10 +603,15 @@ void AliMUONTriggerElectronics::GlobalResponse()
 void AliMUONTriggerElectronics::Digits2Trigger(const AliMUONVDigitStore& digitStore,
                                                AliMUONVTriggerStore& triggerStore)
 {
+  AliCodeTimerAuto("",0);
+
   /// Main method to go from digits to trigger decision
   AliMUONRegionalTrigger pRegTrig;
   
   triggerStore.Clear();
+
+  // NOW RESET ELECTRONICS
+  Reset();
   
   // RUN THE FULL BEE CHAIN
   Feed(digitStore);
@@ -605,331 +706,132 @@ void AliMUONTriggerElectronics::Digits2Trigger(const AliMUONVDigitStore& digitSt
   
   // GLOBAL TRIGGER INFORMATION
   UShort_t global = fGlobalTriggerBoard->GetResponse();
-  
+  UInt_t *globalInput = fGlobalTriggerBoard->GetGlobalInput();  
+
   AliMUONGlobalTrigger globalTrigger;
   
   globalTrigger.SetFromGlobalResponse(global);
+  globalTrigger.SetFromGlobalInput(globalInput);
   // ADD A LOCAL TRIGGER IN THE LIST 
   triggerStore.SetGlobal(globalTrigger);
-  
-  // NOW RESET ELECTRONICS
-  Reset();
+
 }
 
-//_______________________________________________________________________
-void AliMUONTriggerElectronics::FeedBoardsGUI(TObjArray *guibs)
+//___________________________________________
+void AliMUONTriggerElectronics::Feed(const AliMUONVTriggerStore& triggerStore)
 {
-  /// feed digits from board objects from the TriggerGUI, with values
-  /// read from a file or set interactively in the GUI
-  /// 
-
-  // adaptated from FeedM()
-
-  AliMUONTriggerGUIboard* board;
-  Int_t cathode, nstripX, nstripY, ix, iy, detElemId0, detElemId, charge;
-  Int_t iX1, iY1, schg, tchg;
-  Bool_t triggerBgn;
-
-  for (Int_t ib = 0; ib < 234; ib++) {
-
-    board = (AliMUONTriggerGUIboard*)guibs->At(ib);
-    if (board == 0) continue;
-
-    detElemId0 = board->GetDetElemId();
-
-    nstripX = board->GetNStripX();
-    nstripY = board->GetNStripY();
-
-    for (Int_t ichamber = 11; ichamber <= 14; ichamber++) {
-  
-      detElemId = ichamber * 100 + detElemId0;
-
-      // x strips
-      cathode = 0;
-      for (Int_t isx = 0; isx < nstripX; isx++) {
-
-       charge = (Int_t)board->GetXDig(ichamber-11,isx);
-       if (charge) {
-
-         triggerBgn = kFALSE;
-         schg = (Int_t)(charge + 0.5);
-         // APPLY CONDITION ON SOFT BACKGROUND 
-         tchg = schg - (Int_t(schg/10))*10;    
-         if (schg<=10 || tchg>0) {
-           triggerBgn = kFALSE;
-         } else {
-           triggerBgn = kTRUE;
-         }
-         if (triggerBgn) continue;
-
-         //printf("MT %2d SX %2d \n",ichamber,isx);
-
-         ix  = board->GetXSix();
-         iY1 = board->GetXSiy1();
-         iy  = isx + iY1;
-
-         //printf("X: CH %1d B %3d ID %4d ix %2d iy %2d \n",ichamber,ib,detElemId,ix,iy);
-         
-         const AliMpVSegmentation* seg = 
-           AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
-
-         AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
-
-         if (!pad.IsValid()) printf("Invalid pad! \n");
-
-         for (Int_t i=0; i<pad.GetNofLocations(); i++) {
-
-           AliMpIntPair location = pad.GetLocation(i);
-           Int_t nboard = location.GetFirst();
-           if (nboard != board->GetIdCircuit()) continue;
-           Int_t ibitxy = location.GetSecond();
-           
-           //printf("FeedGUI x (%2d): ix %d iy %d detElemId %d \n",ichamber,ix,iy,detElemId);
-
-           AliMUONLocalTriggerBoard *b = fCrates->LocalBoard(nboard);
-           
-           if (b) {
-             if (cathode && b->GetSwitch(6)) ibitxy += 8;
-             
-             //printf("Feed x-digits in board: %d cha %d s %d \n",nboard,ichamber,isx);
-             b->SetbitM(ibitxy,cathode,ichamber-11);
-             
-           } else {
-             AliError(Form("Could not get local board number %d",b->GetNumber()));
-           }         
-           
-         }
-
-       }
-
+  //
+  /// Fill inputs from reconstructed local trigger store
+  //
+  AliMUONLocalTrigger* locTrg;
+  TIter next(triggerStore.CreateLocalIterator());
+  TArrayS xyPattern[2];
+  UShort_t xy[2][4];
+  Int_t loCircuit;
+  while ( ( locTrg = static_cast<AliMUONLocalTrigger*>( next() )) != NULL ){
+    locTrg->GetXPattern(xyPattern[0]);
+    locTrg->GetYPattern(xyPattern[1]);
+    loCircuit = locTrg->LoCircuit();
+    AliMUONLocalTriggerBoard* localBoard = fCrates->LocalBoard(loCircuit);
+    for (Int_t icath = 0; icath<2; ++icath){
+      for (Int_t ich = 0; ich < 4; ++ich){
+       xy[icath][ich] = xyPattern[icath][ich];
       }
-
-      // y strips
-      cathode = 1;
-      for (Int_t isy = 0; isy < nstripY; isy++) {
-
-       charge = board->GetYDig(ichamber-11,isy);
-       if (charge) {
-
-         triggerBgn = kFALSE;
-         schg = (Int_t)(charge + 0.5);
-         // APPLY CONDITION ON SOFT BACKGROUND 
-         tchg = schg - (Int_t(schg/10))*10;    
-         if (schg<=10 || tchg>0) {
-           triggerBgn = kFALSE;
-         } else {
-           triggerBgn = kTRUE;
-         }
-         if (triggerBgn) continue;
-
-         //printf("MT %2d SY %2d \n",ichamber,isy);
-
-         iX1 = board->GetYSix1();
-         ix  = isy + iX1;
-         iy  = board->GetYSiy();
-
-         //printf("Y: CH %1d B %3d ID %4d ix %2d iy %2d \n",ichamber,ib,detElemId,ix,iy);
-         
-         const AliMpVSegmentation* seg = 
-           AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
-
-         AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
-
-         if (!pad.IsValid()) printf("Invalid pad! \n");;
-
-         for (Int_t i=0; i<pad.GetNofLocations(); i++) {
-
-           AliMpIntPair location = pad.GetLocation(i);
-           Int_t nboard = location.GetFirst();
-           if (nboard != board->GetIdCircuit()) continue;
-           Int_t ibitxy = location.GetSecond();
-           
-           //printf("FeedGUI y (%2d): ix %d iy %d detElemId %d \n",ichamber,ix,iy,detElemId);
-
-           AliMUONLocalTriggerBoard *b = fCrates->LocalBoard(nboard);
-           
-           if (b) {
-             if (cathode && b->GetSwitch(6)) ibitxy += 8;
-             
-             //printf("Feed y-digits in board: %d cha %d s %d \n",nboard,ichamber,isy);
-             b->SetbitM(ibitxy,cathode,ichamber-11);
-             
-           } else {
-             AliError(Form("Could not get local board number %d",b->GetNumber()));
-           }
-
-         }
-
-       }
-
-      }
-
     }
-    
+    localBoard->SetXY(xy);
   }
 
-  // ... the rest from FeedM()
+  FeedCopyNeighbours();
+}
 
-  // Particular case of the columns with 22 local boards (2R(L) 3R(L))   
-  AliMUONTriggerCrate *crate = 0x0; TObjArray *bs = 0x0;
+//_______________________________________________________________________
+Bool_t AliMUONTriggerElectronics::ModifiedLocalResponse(Int_t loCircuit,
+                                                       Bool_t& bendingPlaneResp,
+                                                       Bool_t& nonBendingPlaneResp,
+                                                       Bool_t isCoinc44,
+                                                       Int_t removeChamber)
+{
+  //
+  /// Re-compute the local trigger response
+  /// with some modifications (i.e. setting coinc44 or after removing one chamber)
+  //
 
-  char *scratess[4] = {  "2R",   "2L",   "3L",   "3R"}; 
-  char *scratesd[4] = {"2-3R", "2-3L", "2-3L", "2-3R"}; 
-  Int_t    slotf[4] = {     2,      2,     10,     10}; 
-  Int_t    slotd[4] = {     1,      1,      9,      9}; 
+  bendingPlaneResp = kFALSE;
+  nonBendingPlaneResp = kFALSE;
 
-  for (Int_t i = 0; i < 4; i++)
-  {
-      crate = fCrates->Crate(scratess[i]); 
-      bs = crate->Boards();
-      AliMUONLocalTriggerBoard *desybb = (AliMUONLocalTriggerBoard*)bs->At(14);
-      AliMUONLocalTriggerBoard *fromcb = (AliMUONLocalTriggerBoard*)bs->At(15);
-      AliMUONLocalTriggerBoard *desxbb = (AliMUONLocalTriggerBoard*)bs->At(16);
+  Bool_t isTriggered = kFALSE;
 
-      crate = fCrates->Crate(scratesd[i]); 
-      bs = crate->Boards();
-      AliMUONLocalTriggerBoard *frombb = (AliMUONLocalTriggerBoard*)bs->At(slotf[i]);
-      AliMUONLocalTriggerBoard *desycb = (AliMUONLocalTriggerBoard*)bs->At(slotd[i]);
+  AliMUONLocalTriggerBoard* currBoard = fCrates->LocalBoard(loCircuit);
 
-      UShort_t cX[2];
+  if ( ! currBoard ) return isTriggered;
 
-      //    COPY X3-4 FROM BOARD  2 OF CRATE 2-3 TO BOARD 16 OF CRATE 2
-      //    COPY X3-4 FROM BOARD 10 OF CRATE 2-3 TO BOARD 16 OF CRATE 3
-      frombb->GetX34(cX); desxbb->SetX34(cX);
+  AliMUONLocalTriggerBoard localBoard (*currBoard);
 
-      //    COPY X3-4 FROM BOARD 15 OF CRATE 2 TO BOARD 1 OF CRATE 2-3
-      //    COPY X3-4 FROM BOARD 15 OF CRATE 3 TO BOARD 9 OF CRATE 2-3
-      fromcb->GetX34(cX); desycb->SetX34(cX);
+  if (removeChamber>=0 && removeChamber<=3){
 
-      UShort_t cY[4];
+    // Set the bit pattern of selected chamber to 0
+    UShort_t xy[2][4];
+    UShort_t xyu[2][4];
+    UShort_t xyd[2][4];
 
-      desybb->GetY(cY); frombb->SetY(cY);
+    localBoard.GetXY(xy);
+    localBoard.GetXYU(xyu);
+    localBoard.GetXYD(xyd);
 
-      frombb->GetY(cY); desxbb->SetY(cY);
-      fromcb->GetY(cY); desycb->SetY(cY);
-  }
+    for(Int_t icath=0; icath<2; icath++){
+      xy[icath][removeChamber] = 0;
+      xyu[icath][removeChamber] = 0;
+      xyd[icath][removeChamber] = 0;
+    }
 
-  // FILL UP/DOWN OF CURRENT BOARD (DONE VIA J3 BUS IN REAL LIFE)
-  AliMUONTriggerCrate* cr;
-  fCrates->FirstCrate();
-  while ( ( cr = fCrates->NextCrate() ) )
-  {            
-      TObjArray *boards = cr->Boards();
-               
-      for (Int_t j = 1; j < boards->GetEntries()-1; j++)
-      {
-         TObject *o = boards->At(j);
-                       
-         if (!o) break;
-                       
-         AliMUONLocalTriggerBoard *currboard = (AliMUONLocalTriggerBoard*)o;
-                       
-         AliMUONLocalTriggerBoard *neighbour = (AliMUONLocalTriggerBoard*)boards->At(j+1);
-                       
-         UShort_t cXY[2][4];
-                       
-         if (j==1) {neighbour->GetXY(cXY); currboard->SetXYU(cXY);}
-                       
-         //       LAST BOARD IN THE CRATE HAS NO UP EXCEPT FOR CRATES 2 & 3
-         if (j < boards->GetEntries()-2)  
-         {
-             AliMUONLocalTriggerBoard *nextboard = (AliMUONLocalTriggerBoard*)boards->At(j+2);
-                               
-             currboard->GetXY(cXY); neighbour->SetXYD(cXY);
-             nextboard->GetXY(cXY); neighbour->SetXYU(cXY);
-                               
-             if (j==boards->GetEntries()-3) {neighbour->GetXY(cXY); nextboard->SetXYD(cXY);}
-         }
-      }
+    localBoard.SetXY(xy);
+    localBoard.SetXYU(xyu);
+    localBoard.SetXYD(xyd);
   }
-}
 
-//_______________________________________________________________________
-Int_t AliMUONTriggerElectronics::TriggerGUI(Int_t *trigInfo, Bool_t patt)
-{
-  /// trigger with digits from TriggerGUI and return local trigger information
-  /// and optionally the strips pattern
-  /// 
+  localBoard.ResetResponse();
 
-  Int_t nlo = 0;
+  localBoard.SetCoinc44((Int_t)isCoinc44);
+  localBoard.Response();
 
-  LocalResponse();
-  RegionalResponse();      
-  GlobalResponse();
+  bendingPlaneResp = localBoard.IsTrigX();
+  nonBendingPlaneResp = localBoard.IsTrigY();
+  isTriggered = localBoard.Triggered();
 
-  AliMUONTriggerCrate* cr;
-  // stored in right order
-  // do not used iterator order
+  return isTriggered;
+}
 
-  for (Int_t iSide = 0; iSide < 2; iSide++) // right & left side
-  {            
-    for (Int_t iReg = 0; iReg < 8; iReg++) // 8 crates/regional boards for each side.
-    {
-      cr = fCrates->Crate(iSide, iReg);     
-      TObjArray *boards = cr->Boards();
 
-      for (Int_t j = 1; j < boards->GetEntries(); j++)
-      {     
-       TObject *o = boards->At(j);
-      
-       if (!o) break;
-      
-       AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
-      
-       if (board) 
-       {
-         //          L0 TRIGGER
-         if (board->Triggered())
-         {
-          
-           if (patt) {
-             cout << "                                   " << endl;
-             cout << "Local trigger board P A T T E R N :" << endl;
-             cout << "-----------------------------------" << endl;
-             cout << "                                   " << endl;
-             board->Pattern();
-             board->Scan("RESPF");
-           }
-
-           Int_t icirc    = board->GetNumber();
-           Int_t loStripX = board->GetStripX11();
-           Int_t loStripY = board->GetStripY11();
-           Int_t loDev    = board->GetDev();
-
-           UShort_t response = board->GetResponse();
-           Int_t loHpt = (response & 12) >> 2;
-           Int_t loLpt = response &  3;
-           /*
-           cout << "TriggerGUI done!" << endl;
-
-           cout << "Circuit = "  << icirc    << endl;
-           cout << "LoStripX = " << loStripX << endl;
-           cout << "LoStripY = " << loStripY << endl;
-           cout << "LoDev = "    << loDev    << endl;
-           cout                              << endl;
-           */
-           trigInfo[6*nlo+0] = icirc;
-           trigInfo[6*nlo+1] = loStripX;
-           trigInfo[6*nlo+2] = loStripY;
-           trigInfo[6*nlo+3] = loDev;
-
-           trigInfo[6*nlo+4] = loLpt;
-           trigInfo[6*nlo+5] = loHpt;
-
-           nlo++;
+//_______________________________________________________________________
+void AliMUONTriggerElectronics::ResponseRemovingChambers(AliMUONVTriggerStore& triggerStore)
+{
+  /// Update local board information with the trigger response after removing each chamber
 
-         }
-       }
-      }
-    }
-  }
+  AliCodeTimerAuto("", 0);
 
   Reset();
-
-  return nlo;
-          
+  Feed(triggerStore);
+
+  AliMUONLocalTrigger* locTrg;
+  TIter next(triggerStore.CreateLocalIterator());
+  Int_t loCircuit;
+  Bool_t planeResp[2], isTrig44;
+  Bool_t bendPlaneRespNoCh, nonBendPlaneRespNoCh, isTrigWithoutCh;
+  while ( ( locTrg = static_cast<AliMUONLocalTrigger*>( next() )) != NULL ){
+    if ( ! ( locTrg->IsTrigX() && locTrg->IsTrigY() ) ) continue;
+    loCircuit = locTrg->LoCircuit();
+    isTrig44 = ModifiedLocalResponse(loCircuit, planeResp[0], planeResp[1], kTRUE);
+    for (Int_t ich=0; ich<4; ++ich){
+      if ( ! isTrig44 ){
+       isTrigWithoutCh = ModifiedLocalResponse(loCircuit, bendPlaneRespNoCh, nonBendPlaneRespNoCh, kFALSE, ich);
+       if ( ! isTrigWithoutCh ) continue;
+       for (Int_t icath=0; icath<2; icath++){
+         if ( ! planeResp[icath] )
+           locTrg->SetNoHitInPlane(icath, ich);
+       } // loop on cathodes
+      }
+      locTrg->SetTriggerWithoutChamber(ich);
+    } // loop on chambers
+    AliDebug(1, Form("Is44 %i  triggers %i  pattern %i", isTrig44, locTrg->GetTriggerWithoutChamber(), locTrg->GetHitPatternFromResponse()));
+  }
 }
-