]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDAltroMapping.cxx
Correction to match with the new AliTagAnalysis
[u/mrichter/AliRoot.git] / FMD / AliFMDAltroMapping.cxx
index d474d3c7e5fd56ee63a075f67f3f68ad6cebe8a8..11048dc3af0ece927292cdb650b655fb4c7eacb5 100644 (file)
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
-
 /* $Id$ */
-
+/** @file    AliFMDAltroMapping.cxx
+    @author  Christian Holm Christensen <cholm@nbi.dk>
+    @date    Sun Mar 26 18:27:56 2006
+    @brief   Map HW to detector 
+*/
 //____________________________________________________________________
 //                                                                          
 // Mapping of ALTRO hardware channel to detector coordinates 
 //
+// The hardware address consist of a DDL number and 12bits of ALTRO
+// addresses.  The ALTRO address are formatted as follows. 
+//
+//    12              7         4            0
+//    |---------------|---------|------------|
+//    | Board #       | ALTRO # | Channel #  |
+//    +---------------+---------+------------+
+//
+// The mapping is done purely by calculations.  In the future,
+// however, we may need some hard-coded stuff, or an external file to
+// read from.  
+//
 #include "AliFMDAltroMapping.h"                // ALIFMDALTROMAPPING_H
 #include "AliFMDParameters.h"
 #include "AliLog.h"
@@ -60,7 +75,7 @@ AliFMDAltroMapping::Hardware2Detector(UInt_t    ddl, UInt_t    addr,
   // Translate a hardware address to detector coordinates. 
   // The detector is simply 
   // 
-  //    ddl - kBaseDDL + 1
+  //    ddl + 1
   // 
   // The ring number, sector, and strip number is given by the addr
   // argument.  The address argument, has the following format 
@@ -71,8 +86,8 @@ AliFMDAltroMapping::Hardware2Detector(UInt_t    ddl, UInt_t    addr,
   //   +-------------+----------+----------+
   // 
   // The board number identifier among other things the ring.  There's
-  // up to 4 boards per DDL, and the two first (0 and 1) corresponds
-  // to the inner rings, while the two last (2 and 3) corresponds to
+  // up to 4 boards per DDL, and the two first (0 and 16) corresponds
+  // to the inner rings, while the two last (1 and 17) corresponds to
   // the outer rings. 
   // 
   // The board number and ALTRO number together identifies the sensor,
@@ -126,28 +141,25 @@ AliFMDAltroMapping::Hardware2Detector(UInt_t    ddl, UInt_t    addr,
   // us detector coordinates, unique at least up a 128 strips.  We
   // return the first strip in the given range. 
   //
-  det          =  (ddl - AliFMDParameters::kBaseDDL) + 1;
+  det          =  ddl + 1;
   UInt_t board =  (addr >> 7) & 0x1F;
   UInt_t altro =  (addr >> 4) & 0x7;
   UInt_t chan  =  (addr & 0xf);
-  if (board > 3) {
-    AliError(Form("Invalid board address %d for the FMD", board));
-    return kFALSE;
-  }
-  if (altro > 2) {
-    AliError(Form("Invalid ALTRO address %d for the FMD digitizer %d", 
-                 altro, board));
-    return kFALSE;
+  ring         =  (board % 2) == 0 ? 'I' : 'O';
+  switch (ring) {
+  case 'i':
+  case 'I':
+    sec = ((board / 16) * 10 + (altro < 1 ? 0 : altro < 2 ? 4 : 6) 
+          + 2 * (chan / 8) + chan % 2);
+    str = ((chan % 8) / 2) * 128;
+    break;
+  case 'o':
+  case 'O': 
+    sec = ((board / 16) * 20 + (altro < 1 ? 0 : altro < 2 ? 8 : 12) 
+          + 2 * (chan / 4) + chan % 2);
+    str = ((chan % 4) / 2) * 128;
+    break;
   }
-  ring         =  (board > 1 ? 'O' : 'I');
-  UInt_t nsen  =  (ring == 'I' ? 10 : 20);
-  UInt_t nsa   =  (ring == 'I' ? 2 : 4);   // Sensors per ALTRO
-  UInt_t ncs   =  (ring == 'I' ? 8 : 4);   // Channels per sensor 
-  UInt_t sen   =  (board % 2) * nsen / 2;  // Base for half-ring
-  sen          += chan / ncs + (altro == 0 ? 0   : 
-                               altro == 1 ? nsa : UInt_t(1.5 * nsa));
-  sec          =  2 * sen + (chan % 2);
-  str          =  (chan % ncs) / 2 * 128;
   return kTRUE;
 }
 
@@ -160,7 +172,7 @@ AliFMDAltroMapping::Detector2Hardware(UShort_t  det, Char_t    ring,
   // Translate detector coordinates to a hardware address.
   // The ddl is simply 
   // 
-  //    kBaseDDL + (det - 1)
+  //    (det - 1)
   // 
   // The ring number, sector, and strip number must be encoded into a
   // hardware address.  The address argument, will have the following
@@ -172,13 +184,13 @@ AliFMDAltroMapping::Detector2Hardware(UShort_t  det, Char_t    ring,
   //   +-------------+----------+----------+
   // 
   // The board number is given by the ring and sector.  The inner
-  // rings board 0 and 1, while the outer are 2 and 3.  Which of these
+  // rings board 0 and 16, while the outer are 1 and 17.  Which of these
   // depends on the sector.  The map is 
   // 
   //    Ring I, sector  0- 9       ->   board 0 
-  //    Ring I, sector 10-19       ->   board 1
-  //    Ring O, sector  0-19       ->   board 2 
-  //    Ring O, sector 20-39       ->   board 3
+  //    Ring I, sector 10-19       ->   board 16
+  //    Ring O, sector  0-19       ->   board 1 
+  //    Ring O, sector 20-39       ->   board 17
   // 
   // There are 3 ALTRO's per board.  The ALTRO number is given by the
   // sector number.  For the inner rings, these are given by
@@ -237,22 +249,27 @@ AliFMDAltroMapping::Detector2Hardware(UShort_t  det, Char_t    ring,
   // With this information, we can decode the detector coordinates to
   // give us a unique hardware address 
   //
-  ddl          =  AliFMDParameters::kBaseDDL + (det - 1);
-  UInt_t nsen  =  (ring == 'I' ? 10 : 20);
-  UInt_t nsa   =  (ring == 'I' ? 2 : 4);   // Sensors per ALTRO
-  UInt_t ncs   =  (ring == 'I' ? 8 : 4);   // Channels per sensor 
-  UInt_t bbase =  (ring == 'I' ? 0 : 2);
-  UInt_t board =  bbase + sec / nsen;
-  UInt_t lsec  =  (sec - (board - bbase) * nsen); // Local sec in half-ring
-  UInt_t altro =  (lsec < 2 * nsa ? 0 : (lsec < 3 * nsa ? 1       : 2));
-  UInt_t sbase =  (altro == 0     ? 0 : altro == 1      ? 2 * nsa : 3 * nsa);
-  UInt_t chan  =  (sec % 2) + (lsec-sbase) / 2 * ncs + 2 * (str / 128);
-  AliDebug(40, Form("\n"
-                   "  chan = (%d %% 2) + (%d-%d) / %d * %d + 2 * %d / 128\n"
-                   "       = %d + %d + %d = %d", 
-                   sec, lsec, sbase, 2, ncs, str, 
-                   (sec % 2), (lsec - sbase) / 2 * ncs, 
-                   2 * (str / 128), chan));
+  ddl          =  (det - 1);
+  UInt_t board = 0;
+  UInt_t altro = 0;
+  UInt_t chan  = 0;
+  UInt_t tmp   = 0;
+  switch (ring) {
+  case 'I':
+  case 'i':
+    board += (sec / 10) * 16;
+    altro =  (sec % 10) < 4 ? 0 : (sec % 10) < 6 ? 1 : 2;
+    tmp   =  (sec % 10) - (altro == 0 ? 0 : altro == 1 ? 4 : 6);
+    chan  =  2  * (str / 128) + (sec % 2) + ((tmp / 2) % 2) * 8;
+    break;
+  case 'O':
+  case 'o':
+    board += (sec / 20) * 20 + 1;
+    altro =  (sec % 20) < 8 ? 0 : (sec % 20) < 12 ? 1 : 2;
+    tmp   =  (sec % 20) - (altro == 0 ? 0 : altro == 1 ? 8 : 12);
+    chan  =  2 * (str / 128) + (sec % 2) + ((tmp / 2) % 4) * 4;
+    break;
+  }
   addr         =  chan + (altro << 4) + (board << 7);
   
   return kTRUE;
@@ -295,7 +312,7 @@ AliFMDAltroMapping::GetPadRow(Int_t hwaddr) const
   Char_t   ring;
   UShort_t sec;
   UShort_t str;
-  Int_t    ddl = AliFMDParameters::kBaseDDL;
+  Int_t    ddl = 0;
   if (!Hardware2Detector(ddl, hwaddr, det, ring, sec, str)) return -1;
   return Int_t(sec);
 }
@@ -317,7 +334,7 @@ AliFMDAltroMapping::GetPad(Int_t hwaddr) const
   Char_t   ring;
   UShort_t sec;
   UShort_t str;
-  Int_t    ddl = AliFMDParameters::kBaseDDL;
+  Int_t    ddl = 0;
   if (!Hardware2Detector(ddl, hwaddr, det, ring, sec, str)) return -1;
   return Int_t(str);
 }
@@ -339,7 +356,7 @@ AliFMDAltroMapping::GetSector(Int_t hwaddr) const
   Char_t   ring;
   UShort_t sec;
   UShort_t str;
-  Int_t    ddl = AliFMDParameters::kBaseDDL;
+  Int_t    ddl = 0;
   if (!Hardware2Detector(ddl, hwaddr, det, ring, sec, str)) return -1;
   return Int_t(ring);
 }