]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONGlobalTriggerBoard.cxx
In AliMUONPairLight, AliMUONTrackLight:
[u/mrichter/AliRoot.git] / MUON / AliMUONGlobalTriggerBoard.cxx
index 4a120f9f9204bba0256d1bbc7dc23a0e6c3dfa4f..ba237679a1eae2bd01fe2ab7b6c128062f4e4e36 100644 (file)
@@ -43,6 +43,7 @@ AliMUONGlobalTriggerBoard::AliMUONGlobalTriggerBoard(): AliMUONTriggerBoard()
 
    for (Int_t i=0;i<16;i++) fRegionalResponse[i] = 0;
    for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
+   for (Int_t i=0;i< 4;i++) fMask[i] = 0xffffffff;
 }
 
 //___________________________________________
@@ -52,6 +53,7 @@ AliMUONGlobalTriggerBoard::AliMUONGlobalTriggerBoard(const char *name, Int_t a)
 
    for (Int_t i=0;i<16;i++) fRegionalResponse[i] = 0;
    for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
+   for (Int_t i=0;i< 4;i++) fMask[i] = 0xffffffff;
 }
 
 //___________________________________________
@@ -87,7 +89,7 @@ void AliMUONGlobalTriggerBoard::Response()
    Int_t t[16];
 
    BuildGlobalInput();
-   MaskRegionalInput();
+   MaskGlobalInput();
 
    for (Int_t i = 0; i < 16; ++i) 
    {
@@ -122,11 +124,14 @@ void AliMUONGlobalTriggerBoard::Response()
    usLpt = ((t[0] & 0x2 ) != 0);
    usHpt = ((t[0] & 0x20) != 0);
 
-   sHpt  <<= 1;
-   lsLpt <<= 2;
-   lsHpt <<= 3;
-   usLpt <<= 4;
-   usHpt <<= 5;
+   // LSB is zero (trigger choice to send to CTP: sLpt or sHpt)
+
+   sLpt  <<= 1;
+   sHpt  <<= 2;
+   lsLpt <<= 3;
+   lsHpt <<= 4;
+   usLpt <<= 5;
+   usHpt <<= 6;
 
    fResponse = sLpt | sHpt | lsLpt | lsHpt | usLpt |usHpt;
    
@@ -134,7 +139,7 @@ void AliMUONGlobalTriggerBoard::Response()
 }
 
 //___________________________________________
-UShort_t AliMUONGlobalTriggerBoard::Algo(UShort_t i, UShort_t j, char *thres)
+UShort_t AliMUONGlobalTriggerBoard::Algo(UShort_t i, UShort_t j, const char *thres)
 {
 /// global trigger algorithm
 ///   a ,b = reg  response  =  Hpt (+|-|us|ls) |  Lpt (+|-|us|ls)  
@@ -158,15 +163,11 @@ UShort_t AliMUONGlobalTriggerBoard::Algo(UShort_t i, UShort_t j, char *thres)
 
    if (!strcmp(thres,"LPT"))
    {
-      //trgLS1[0] = a[1]; trgUS1[0] = a[0]; 
-      //trgLS2[0] = b[1]; trgUS2[0] = b[0];
       trgLS1[0] = a[0]; trgUS1[0] = a[1]; 
       trgLS2[0] = b[0]; trgUS2[0] = b[1];
    }
    else
    {
-      //trgLS1[0] = a[5]; trgUS1[0] = a[4]; 
-      //trgLS2[0] = b[5]; trgUS2[0] = b[4];         
       trgLS1[0] = a[4]; trgUS1[0] = a[5]; 
       trgLS2[0] = b[4]; trgUS2[0] = b[5];         
    }
@@ -179,8 +180,6 @@ UShort_t AliMUONGlobalTriggerBoard::Algo(UShort_t i, UShort_t j, char *thres)
    
    TBits v(4);
    
-   //v[0] = trgUS[0];
-   //v[1] = trgLS[0];
    v[0] = trgLS[0];
    v[1] = trgUS[0];
    v[2] = trg[0];
@@ -201,17 +200,21 @@ void AliMUONGlobalTriggerBoard::BuildGlobalInput()
 
   for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
 
+  UShort_t regRespInv;
   for (Int_t iReg = 0; iReg < 16; iReg++) {
+
+    regRespInv = InvertPairBits(iReg);
+
     if (iReg < 8) {    // right
       // Lpt word
-      fGlobalInput[0] |=  (fRegionalResponse[iReg] & 0x0F)       << (4*iReg);
+      fGlobalInput[0] |=  (regRespInv & 0x0F)       << (4*iReg);
       // Hpt word
-      fGlobalInput[2] |= ((fRegionalResponse[iReg] & 0xF0) >> 4) << (4*iReg);
+      fGlobalInput[2] |= ((regRespInv & 0xF0) >> 4) << (4*iReg);
     } else {           // left
       // Lpt word
-      fGlobalInput[1] |=  (fRegionalResponse[iReg] & 0x0F)       << (4*(iReg-8));
+      fGlobalInput[1] |=  (regRespInv & 0x0F)       << (4*(iReg-8));
       // Hpt word
-      fGlobalInput[3] |= ((fRegionalResponse[iReg] & 0xF0) >> 4) << (4*(iReg-8));
+      fGlobalInput[3] |= ((regRespInv & 0xF0) >> 4) << (4*(iReg-8));
     }
 
   }
@@ -219,19 +222,27 @@ void AliMUONGlobalTriggerBoard::BuildGlobalInput()
 }
 
 //___________________________________________
-void AliMUONGlobalTriggerBoard::MaskRegionalInput()
+void AliMUONGlobalTriggerBoard::MaskGlobalInput()
 {
   /// Apply masks to global input and recalculate regional inputs before
   /// applying the global response
 
-  // temporary global inputs with masks applied
   UInt_t gitmp[4];
-
   for (Int_t i = 0; i < 4; i++) {
+    fGlobalInput[i] &= fMask[i];
     gitmp[i] = fGlobalInput[i];
-    gitmp[i] &= fMask[i];
   }
 
+  RecomputeRegional(gitmp);
+}
+
+
+//___________________________________________
+void AliMUONGlobalTriggerBoard::RecomputeRegional(UInt_t gitmp[4])
+{
+  //
+  /// Recomput regional response from global input
+  //
   for (Int_t iReg = 0; iReg < 16; iReg++) {
     fRegionalResponse[iReg] = 0;
     if (iReg < 8) {    // right
@@ -245,15 +256,16 @@ void AliMUONGlobalTriggerBoard::MaskRegionalInput()
       // Hpt
       fRegionalResponse[iReg] |= ((gitmp[3] >> (4*(iReg-8))) & 0xF) << 4;
     }
-  }
 
+    fRegionalResponse[iReg] = InvertPairBits(iReg);
+  }
 }
 
 //___________________________________________
 void AliMUONGlobalTriggerBoard::Scan(Option_t*) const
 {
   /// print global trigger output 
-  TBits w(6); w.Set(6,&fResponse);
+  TBits w(7); w.Set(7,&fResponse);
 
 // TRG[1:0]
 // 00 noth
@@ -263,11 +275,11 @@ void AliMUONGlobalTriggerBoard::Scan(Option_t*) const
 
    Int_t iS[2] = {0,0};
 
-   iS[0] = (Int_t)w.TestBitNumber(0);
-   iS[1] = (Int_t)w.TestBitNumber(1);
+   iS[0] = (Int_t)w.TestBitNumber(1);
+   iS[1] = (Int_t)w.TestBitNumber(2);
 
-   Int_t iPU[2] = {w[4],w[5]};
-   Int_t iPL[2] = {w[2],w[3]};
+   Int_t iPU[2] = {w[5],w[6]};
+   Int_t iPL[2] = {w[3],w[4]};
 
    printf("============================================\n");
    printf(" Global Trigger output       Low pt  High pt\n");
@@ -284,3 +296,26 @@ void AliMUONGlobalTriggerBoard::Scan(Option_t*) const
    printf("\n");
 }
 
+
+//___________________________________________
+UShort_t AliMUONGlobalTriggerBoard::InvertPairBits(Int_t iReg)
+{
+  //
+  /// invert "pair" bits in regional response
+  /// [+, -, US, LS] becomes [+, -, LS, US]
+  //
+  TBits rs(8), rsi(8);
+  rs.Set(8,&fRegionalResponse[iReg]);
+    for (Int_t i = 0; i < 4; i++) {
+      if (i%2 == 0) {
+       rsi[2*i]   = rs[2*i+1];
+       rsi[2*i+1] = rs[2*i];
+      } else {
+       rsi[2*i]   = rs[2*i];
+       rsi[2*i+1] = rs[2*i+1];
+      }
+    }
+    UShort_t regRespInv = 0;
+    rsi.Get(&regRespInv);
+    return regRespInv;
+}