LCOV - code coverage report
Current view: top level - TRD/TRDbase - AliTRDtrapConfigHandler.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 154 308 50.0 %
Date: 2016-06-14 17:26:59 Functions: 11 17 64.7 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : ////////////////////////////////////////////////////////////////////////////
      17             : //                                                                        //
      18             : //  MCM configuraton handler                                              //
      19             : //                                                                        //
      20             : //  Author: U. Westerhoff                                                 //
      21             : //                                                                        //
      22             : ////////////////////////////////////////////////////////////////////////////
      23             : 
      24             : #include "AliTRDtrapConfigHandler.h"
      25             : 
      26             : #include <iostream>
      27             : #include <sstream>
      28             : #include <iomanip>
      29             : 
      30             : #include "AliLog.h"
      31             : 
      32             : #include "AliTRDfeeParam.h"
      33             : #include "AliTRDtrapConfig.h"
      34             : #include "AliTRDmcmSim.h"
      35             : #include "AliTRDgeometry.h"
      36             : #include "AliTRDcalibDB.h"
      37             : 
      38             : #include "TMath.h"
      39             : #include "TGeoMatrix.h"
      40             : #include "TGraph.h"
      41             : 
      42             : #include "AliTRDCalOnlineGainTable.h"
      43             : #include "AliTRDCalOnlineGainTableROC.h"
      44             : #include "AliTRDCalOnlineGainTableMCM.h"
      45             : 
      46             : using namespace std;
      47             : 
      48           1 : AliTRDtrapConfigHandler::AliTRDtrapConfigHandler(AliTRDtrapConfig *cfg) :
      49           1 :      ltuParam()
      50           1 :      , fRestrictiveMask((0x3ffff << 11) | (0x1f << 6) | 0x3f)
      51           1 :      , fTrapConfig(cfg)
      52           1 :      , fGtbl()
      53           5 : {
      54             : 
      55           2 : }
      56             : 
      57             : 
      58             : AliTRDtrapConfigHandler::~AliTRDtrapConfigHandler()
      59           4 : {
      60             : 
      61           2 : }
      62             : 
      63             : void AliTRDtrapConfigHandler::Init()
      64             : {
      65           2 :   if (!fTrapConfig) {
      66           0 :     AliError("No TRAPconfig given");
      67           0 :     return;
      68             :   }
      69             : 
      70             :   // setup of register allocation
      71             :   // I/O configuration which we don't care about
      72           1 :   fTrapConfig->SetTrapRegAlloc(AliTRDtrapConfig::kSEBDOU, AliTRDtrapConfig::kAllocNone);
      73             :   // position look-up table by layer
      74         258 :   for (Int_t iBin = 0; iBin < 128; iBin++)
      75         128 :     fTrapConfig->SetTrapRegAlloc((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), AliTRDtrapConfig::kAllocByLayer);
      76             :   // ... individual
      77           1 :   fTrapConfig->SetTrapRegAlloc(AliTRDtrapConfig::kC14CPUA, AliTRDtrapConfig::kAllocByMCM);
      78           1 :   fTrapConfig->SetTrapRegAlloc(AliTRDtrapConfig::kC15CPUA, AliTRDtrapConfig::kAllocByMCM);
      79             : 
      80             :   // setup of DMEM allocation
      81        2050 :   for(Int_t iAddr = AliTRDtrapConfig::fgkDmemStartAddress;
      82        2049 :             iAddr < (AliTRDtrapConfig::fgkDmemWords + AliTRDtrapConfig::fgkDmemStartAddress); iAddr++) {
      83             : 
      84        1024 :     if(iAddr == AliTRDmcmSim::fgkDmemAddrDeflCorr)
      85           1 :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCMinSM);
      86             : 
      87        1023 :     else if(iAddr == AliTRDmcmSim::fgkDmemAddrNdrift)
      88           1 :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByDetector);
      89             : 
      90        1022 :     else if((iAddr >= AliTRDmcmSim::fgkDmemAddrDeflCutStart) && (iAddr <= AliTRDmcmSim::fgkDmemAddrDeflCutEnd))
      91          38 :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCMinSM);
      92             : 
      93         984 :     else if((iAddr >= AliTRDmcmSim::fgkDmemAddrTrackletStart) && (iAddr <= AliTRDmcmSim::fgkDmemAddrTrackletEnd))
      94           4 :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCM);
      95             : 
      96         980 :     else if((iAddr >= AliTRDmcmSim::fgkDmemAddrLUTStart) && (iAddr <= AliTRDmcmSim::fgkDmemAddrLUTEnd))
      97         768 :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocGlobal);
      98             : 
      99         212 :     else if(iAddr == AliTRDmcmSim::fgkDmemAddrLUTcor0)
     100           1 :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCMinSM);
     101             : 
     102         422 :     else if(iAddr == AliTRDmcmSim::fgkDmemAddrLUTcor1)
     103         212 :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCMinSM);
     104             : 
     105             :     else if(iAddr == AliTRDmcmSim::fgkDmemAddrLUTnbins)
     106         210 :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocGlobal);
     107             : 
     108             :     else if(iAddr == AliTRDmcmSim::fgkDmemAddrLUTLength)
     109             :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocGlobal);
     110             : 
     111             :     else
     112             :       fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocGlobal);
     113             :   }
     114           1 : }
     115             : 
     116             : void AliTRDtrapConfigHandler::ResetMCMs()
     117             : {
     118             :    //
     119             :    // Reset all MCM registers and DMEM
     120             :    //
     121             : 
     122           0 :   if (!fTrapConfig) {
     123           0 :     AliError("No TRAPconfig given");
     124           0 :     return;
     125             :   }
     126             : 
     127           0 :    fTrapConfig->ResetRegs();
     128           0 :    fTrapConfig->ResetDmem();
     129           0 : }
     130             : 
     131             : 
     132             : Int_t AliTRDtrapConfigHandler::LoadConfig()
     133             : {
     134             :   // load a default configuration which is suitable for simulation
     135             :   // for a detailed description of the registers see the TRAP manual
     136             :   // if you want to resimulate tracklets on real data use the appropriate config instead
     137             : 
     138           2 :   if (!fTrapConfig) {
     139           0 :     AliError("No TRAPconfig given");
     140           0 :     return -1;
     141             :   }
     142             : 
     143             :   // prepare ltuParam
     144             :   // ndrift (+ 5 binary digits)
     145           1 :   ltuParam.SetNtimebins(20 << 5);
     146             :   // deflection + tilt correction
     147           1 :   ltuParam.SetRawOmegaTau(0.16133);
     148             :   // deflection range table
     149           1 :   ltuParam.SetRawPtMin(0.1);
     150             :   // magnetic field
     151           1 :   ltuParam.SetRawMagField(0.0);
     152             :   // scaling factors for q0, q1
     153           1 :   ltuParam.SetRawScaleQ0(0);
     154           1 :   ltuParam.SetRawScaleQ1(0);
     155             :   // disable length correction and tilting correction
     156           1 :   ltuParam.SetRawLengthCorrectionEnable(kFALSE);
     157           1 :   ltuParam.SetRawTiltCorrectionEnable(kFALSE);
     158             : 
     159        1082 :   for (Int_t iDet = 0; iDet < 540; iDet++) {
     160             :     // HC header configuration bits
     161         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC15CPUA, 0x2102, iDet); // zs, deh
     162             : 
     163             :     // no. of timebins
     164         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC13CPUA, 24, iDet);
     165             : 
     166             :     // pedestal filter
     167         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFPNP, 4*10, iDet);
     168         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFPTC, 0, iDet);
     169         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFPBY, 0, iDet); // bypassed!
     170             : 
     171             :     // gain filter
     172       22680 :     for (Int_t adc = 0; adc < 20; adc++) {
     173       10800 :       fTrapConfig->SetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGA0+adc), 40, iDet);
     174       10800 :       fTrapConfig->SetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGF0+adc), 15, iDet);
     175             :     }
     176         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFGTA, 20, iDet);
     177         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFGTB, 2060, iDet);
     178         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFGBY, 0, iDet);  // bypassed!
     179             : 
     180             :     // tail cancellation
     181         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFTAL, 200, iDet);
     182         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFTLL, 0, iDet);
     183         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFTLS, 200, iDet);
     184         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFTBY, 0, iDet);
     185             : 
     186             :     // tracklet calculation
     187         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPQS0, 5, iDet);
     188         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPQE0, 10, iDet);
     189         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPQS1, 11, iDet);
     190         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPQE1, 20, iDet);
     191         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPFS, 5, iDet);
     192         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPFE, 20, iDet);
     193         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPVBY, 0, iDet);
     194         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPVT, 10, iDet);
     195         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPHT, 150, iDet);
     196         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPFP, 40, iDet);
     197         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPCL, 1, iDet);
     198         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPCT, 10, iDet);
     199             : 
     200             :     // apply ltuParams
     201         540 :     ConfigureDyCorr(iDet);
     202         540 :     ConfigureDRange(iDet); // deflection range
     203         540 :     ConfigureNTimebins(iDet);  // timebins in the drift region
     204         540 :     ConfigurePIDcorr(iDet);  // scaling parameters for the PID
     205             : 
     206             :     // event buffer
     207         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBSF, 1, iDet);  // 0: store filtered; 1: store unfiltered
     208             : 
     209             :     // zs applied to data stored in event buffer (sel. by EBSF)
     210         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBIS, 15, iDet); // single indicator threshold (plus two digits)
     211         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBIT, 30, iDet); // sum indicator threshold (plus two digits)
     212         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBIL, 0xf0, iDet);   // lookup table
     213         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBIN, 0, iDet);      // neighbour sensitivity
     214             : 
     215             :     // raw data
     216         540 :     fTrapConfig->SetTrapReg(AliTRDtrapConfig::kNES, (0x0000 << 16) | 0x1000, iDet);
     217             :   }
     218             : 
     219             :   // ****** hit position LUT
     220             : 
     221             :   // now calculate it from PRF
     222           1 :   AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
     223             : 
     224           1 :   Double_t padResponse[3]; // pad response left, central, right
     225           1 :   Double_t padResponseR[3]; // pad response left, central, right
     226           1 :   Double_t padResponseL[3]; // pad response left, central, right
     227             : 
     228          14 :   for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
     229           6 :     TGraph gr(128);
     230        1548 :     for (Int_t iBin = 0; iBin < 256*0.5; iBin++) {
     231         768 :       cal->PadResponse(1., iBin*1./256.,    iLayer, padResponse);
     232         768 :       cal->PadResponse(1., iBin*1./256.-1., iLayer, padResponseR);
     233         768 :       cal->PadResponse(1., iBin*1./256.+1., iLayer, padResponseL);
     234         768 :       gr.SetPoint(iBin, (0.5 * (padResponseR[1] - padResponseL[1])/padResponse[1] * 256), iBin);
     235             :     }
     236        1548 :     for (Int_t iBin = 0; iBin < 128; iBin++) {
     237        1536 :       Int_t corr = (Int_t) (gr.Eval(iBin)) - iBin;
     238         768 :       if (corr < 0)
     239           0 :         corr = 0;
     240         768 :       else if (corr > 31)
     241           4 :         corr = 31;
     242      139776 :       for (Int_t iStack = 0; iStack < 540/6; iStack++) {
     243       69120 :         fTrapConfig->SetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), corr, 6*iStack + iLayer);
     244             :       }
     245             :     }
     246           6 :   }
     247             :   // ****** hit position LUT configuration end
     248             : 
     249             :   return 0;
     250           2 : }
     251             : 
     252             : 
     253             : Int_t AliTRDtrapConfigHandler::LoadConfig(TString filename)
     254             : {
     255             :    //
     256             :   // load a TRAP configuration from a file
     257             :    // The file format is the format created by the standalone
     258             :    // command coder scc / show_cfdat but without the running number
     259             :    // scc /show_cfdat adds as the first column
     260             :    // which are two tools to inspect/export configurations from wingDB
     261             :    //
     262             : 
     263           0 :   if (!fTrapConfig) {
     264           0 :     AliError("No TRAPconfig given");
     265           0 :     return -1;
     266             :   }
     267             : 
     268             :    Int_t ignoredLines=0;
     269             :    Int_t ignoredCmds=0;
     270             :    Int_t readLines=0;
     271             : 
     272             : 
     273           0 :    AliDebug(5, Form("Processing file %s", filename.Data()));
     274           0 :    std::ifstream infile;
     275           0 :    infile.open(filename.Data(), std::ifstream::in);
     276           0 :    if (!infile.is_open()) {
     277           0 :     AliError(Form("Can not open MCM configuration file %s", filename.Data()));
     278           0 :     return kFALSE;
     279             :    }
     280             : 
     281           0 :    UInt_t cmd;
     282           0 :    Int_t extali, addr, data;
     283             : 
     284             :    // reset restrictive mask
     285           0 :    fRestrictiveMask = (0x3ffff << 11) | (0x1f << 6) | 0x3f;
     286           0 :    char linebuffer[512];
     287           0 :    istringstream line;
     288             : 
     289           0 :    while(infile.getline(linebuffer, 512) && infile.good()) {
     290           0 :       line.clear();
     291           0 :       line.str(linebuffer);
     292           0 :       cmd=999;
     293           0 :       extali=-1;
     294           0 :       addr=-1;
     295           0 :       data=-1;
     296           0 :       line >> std::skipws >> cmd >> addr >> data >> extali;  // the lines read from config file can contain additional columns.
     297             :       // Therefore the detour via istringstream
     298             : 
     299           0 :       if(cmd!=999 && addr != -1 && data!= -1 && extali!=-1) {
     300             : 
     301           0 :          if(cmd==fgkScsnCmdWrite) {
     302           0 :             for(Int_t det=0; det<AliTRDgeometry::Ndet(); det++) {
     303           0 :                UInt_t rocpos = (1 << (AliTRDgeometry::GetSector(det)+11)) | (1 << (AliTRDgeometry::GetStack(det)+6)) | (1 << AliTRDgeometry::GetLayer(det));
     304           0 :                AliDebug(1, Form("checking restriction: mask=0x%08x, rocpos=0x%08x", fRestrictiveMask, rocpos));
     305           0 :                if ((fRestrictiveMask & rocpos) == rocpos) {
     306           0 :                  AliDebug(1, Form("match: %i %i %i %i", cmd, extali, addr, data));
     307           0 :                   AddValues(det, cmd, extali, addr, data);
     308             :                }
     309             :             }
     310           0 :          }
     311             : 
     312           0 :          else if(cmd == fgkScsnLTUparam) {
     313           0 :             ProcessLTUparam(extali, addr, data);
     314             :          }
     315             : 
     316           0 :          else if(cmd == fgkScsnCmdRestr) {
     317           0 :             fRestrictiveMask = data;
     318           0 :            AliDebug(1, Form("updated restrictive mask to 0x%08x", fRestrictiveMask));
     319             :          }
     320             : 
     321           0 :          else if((cmd == fgkScsnCmdReset) ||
     322           0 :                  (cmd == fgkScsnCmdRobReset)) {
     323           0 :            fTrapConfig->ResetRegs();
     324             :          }
     325             : 
     326           0 :          else if (cmd == fgkScsnCmdSetHC) {
     327           0 :            Int_t fullVersion = ((data & 0x7F00) >> 1) | (data & 0x7f);
     328             : 
     329           0 :            for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
     330           0 :              Int_t smls = (AliTRDgeometry::GetSector(iDet) << 6) | (AliTRDgeometry::GetLayer(iDet) << 3) | AliTRDgeometry::GetStack(iDet);
     331             : 
     332           0 :              for (Int_t iRob = 0; iRob < 8; iRob++) {
     333             :                // HC mergers
     334           0 :                fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC14CPUA, 0xc << 16, iDet, iRob, 17);
     335           0 :                fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC15CPUA, ((1<<29) | (fullVersion<<15) | (1<<12) | (smls<<1) | (iRob%2)), iDet, iRob, 17);
     336             : 
     337             :                // board mergers
     338           0 :                fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC14CPUA, 0, iDet, iRob, 16);
     339           0 :                fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC15CPUA, ((1<<29) | (fullVersion<<15) | (1<<12) | (smls<<1) | (iRob%2)), iDet, iRob, 16);
     340             : 
     341             :                // and now for the others
     342           0 :                for (Int_t iMcm = 0; iMcm < 16; iMcm++) {
     343           0 :                  fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC14CPUA, iMcm | (iRob << 4) | (3 << 16), iDet, iRob, iMcm);
     344           0 :                  fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC15CPUA, ((1<<29) | (fullVersion<<15) | (1<<12) | (smls<<1) | (iRob%2)), iDet, iRob, iMcm);
     345             :                }
     346             :              }
     347             :            }
     348           0 :          }
     349             : 
     350           0 :          else if((cmd == fgkScsnCmdRead) ||
     351           0 :                  (cmd == fgkScsnCmdPause) ||
     352           0 :                  (cmd == fgkScsnCmdPtrg) ||
     353           0 :                  (cmd == fgkScsnCmdHwPtrg) ||
     354           0 :                  (cmd == fgkScsnCmdRobPower) ||
     355           0 :                  (cmd == fgkScsnCmdTtcRx) ||
     356           0 :                  (cmd == fgkScsnCmdMcmTemp) ||
     357           0 :                  (cmd == fgkScsnCmdOri) ||
     358           0 :                  (cmd == fgkScsnCmdPM) ) {
     359           0 :            AliDebug(2, Form("ignored SCSN command: %i %i %i %i", cmd, addr, data, extali));
     360             :          }
     361             : 
     362             :          else {
     363           0 :             AliWarning(Form("unknown SCSN command: %i %i %i %i", cmd, addr, data, extali));
     364           0 :             ignoredCmds++;
     365             :          }
     366             : 
     367           0 :          readLines++;
     368           0 :       }
     369             : 
     370           0 :       else if(!infile.eof() && !infile.good()) {
     371           0 :          infile.clear();
     372           0 :          infile.ignore(256, '\n');
     373           0 :          ignoredLines++;
     374           0 :       }
     375             : 
     376           0 :       if(!infile.eof())
     377           0 :          infile.clear();
     378             :    }
     379             : 
     380           0 :    infile.close();
     381             : 
     382           0 :    AliDebug(5, Form("Ignored lines: %i, ignored cmds: %i", ignoredLines, ignoredCmds));
     383             : 
     384             : 
     385           0 :    if(ignoredLines>readLines)
     386           0 :       AliError(Form("More than 50 %% of the input file could not be processed. Perhaps you should check the input file %s", filename.Data()));
     387             : 
     388             : 
     389             :    return kTRUE;
     390           0 : }
     391             : 
     392             : 
     393             : 
     394             : Int_t AliTRDtrapConfigHandler::SetGaintable(AliTRDCalOnlineGainTable const &gtbl)
     395             : {
     396           0 :    fGtbl=gtbl;
     397           0 :    return 0;
     398             : }
     399             : 
     400             : 
     401             : void AliTRDtrapConfigHandler::ProcessLTUparam(Int_t dest, Int_t addr, UInt_t data)
     402             : {
     403             :    //
     404             :    // Process the LTU parameters and stores them in internal class variables
     405             :    // or transfer the stored values to AliTRDtrapConfig, depending on the dest parameter
     406             :    //
     407             : 
     408           0 :    switch (dest) {
     409             : 
     410             :    case 0: // set the parameters in AliTRDtrapConfig
     411           0 :       for(Int_t det=0; det<AliTRDgeometry::Ndet(); det++) {
     412           0 :          ConfigureDyCorr(det);
     413           0 :          ConfigureDRange(det); // deflection range
     414           0 :          ConfigureNTimebins(det);  // timebins in the drift region
     415           0 :          ConfigurePIDcorr(det);  // scaling parameters for the PID
     416             :       }
     417           0 :       break;
     418             : 
     419             :    case 1: // set variables
     420           0 :       switch (addr) {
     421             : 
     422           0 :       case 0: ltuParam.SetPtMin(data); break; // pt_min in GeV/c (*1000)
     423           0 :       case 1: ltuParam.SetMagField(data); break; // B in T (*1000)
     424           0 :       case 2: ltuParam.SetOmegaTau(data); break; // omega*tau
     425           0 :       case 3: ltuParam.SetNtimebins(data); break;
     426             :         // ntimbins: drift time (for 3 cm) in timebins (5 add. bin. digits)
     427           0 :       case 4: ltuParam.SetScaleQ0(data); break;
     428           0 :       case 5: ltuParam.SetScaleQ1(data); break;
     429           0 :       case 6: ltuParam.SetLengthCorrectionEnable(data); break;
     430           0 :       case 7: ltuParam.SetTiltCorrectionEnable(data); break;
     431             :       }
     432             :       break;
     433             : 
     434             :    default:
     435           0 :       AliError(Form("dest %i not implemented", dest));
     436           0 :    }
     437             : 
     438           0 : }
     439             : 
     440             : 
     441             : void AliTRDtrapConfigHandler::ConfigureNTimebins(Int_t det)
     442             : {
     443             :    //
     444             :    // Set timebins in the drift region
     445             :    //
     446             : 
     447        1080 :   if (!fTrapConfig) {
     448           0 :     AliError("No TRAPconfig given");
     449           0 :     return;
     450             :   }
     451             : 
     452         540 :   AddValues(det, fgkScsnCmdWrite, 127, AliTRDmcmSim::fgkDmemAddrNdrift, ltuParam.GetNtimebins());
     453        1080 : }
     454             : 
     455             : 
     456             : 
     457             : void AliTRDtrapConfigHandler::ConfigureDyCorr(Int_t det)
     458             : {
     459             :    //
     460             :    //  Deflection length correction
     461             :    //  due to Lorentz angle and tilted pad correction
     462             :    //  This correction is in units of padwidth / (256*32)
     463             :    //
     464             : 
     465        1080 :   if (!fTrapConfig) {
     466           0 :     AliError("No TRAPconfig given");
     467           0 :     return;
     468             :   }
     469             : 
     470         540 :    Int_t nRobs = AliTRDgeometry::GetStack(det) == 2 ? 6 : 8;
     471             : 
     472        9288 :   for (Int_t r = 0; r < nRobs; r++) {
     473      139536 :     for (Int_t m = 0; m < 16; m++) {
     474       65664 :       Int_t dest =  1<<10 | r<<7 | m;
     475       65664 :       Int_t dyCorrInt = ltuParam.GetDyCorrection(det, r, m);
     476       65664 :       AddValues(det, fgkScsnCmdWrite, dest, AliTRDmcmSim::fgkDmemAddrDeflCorr, dyCorrInt);
     477             :     }
     478             :   }
     479        1080 : }
     480             : 
     481             : 
     482             : 
     483             : 
     484             : 
     485             : void AliTRDtrapConfigHandler::ConfigureDRange(Int_t det)
     486             : {
     487             :    //
     488             :    // deflection range LUT
     489             :    // range calculated according to B-field (in T) and pt_min (in GeV/c)
     490             :    // if pt_min < 0.1 GeV/c the maximal allowed range for the tracklet
     491             :    // deflection (-64..63) is used
     492             :    //
     493             : 
     494        1080 :   if (!fTrapConfig) {
     495           0 :     AliError("No TRAPconfig given");
     496           0 :     return;
     497             :   }
     498             : 
     499         540 :   Int_t nRobs = AliTRDgeometry::GetStack(det) == 2 ? 6 : 8;
     500             : 
     501         540 :   Int_t dyMinInt;
     502         540 :   Int_t dyMaxInt;
     503             : 
     504        9288 :    for (Int_t r = 0; r < nRobs; r++) {
     505      139536 :       for (Int_t m = 0; m < 16; m++) {
     506     2495232 :          for (Int_t c = 0; c < 18; c++) {
     507             : 
     508             :            // cout << "maxdefl: " << maxDeflAngle << ", localPhi " << localPhi << endl;
     509             :            // cout << "r " << r << ", m" << m << ", c " << c << ", min angle: " << localPhi-maxDeflAngle << ", max: " << localPhi+maxDeflAngle
     510             :            //   << ", min int: " << dyMinInt << ", max int: " << dyMaxInt << endl;
     511     1181952 :            Int_t dest =  1<<10 | r<<7 | m;
     512     1181952 :            Int_t lutAddr = AliTRDmcmSim::fgkDmemAddrDeflCutStart + 2*c;
     513     1181952 :            ltuParam.GetDyRange(det, r, m, c, dyMinInt, dyMaxInt);
     514     1181952 :            AddValues(det, fgkScsnCmdWrite, dest, lutAddr+0, dyMinInt);
     515     1181952 :            AddValues(det, fgkScsnCmdWrite, dest, lutAddr+1, dyMaxInt);
     516             :          }
     517             :       }
     518             :    }
     519        1080 : }
     520             : 
     521             : void AliTRDtrapConfigHandler::PrintGeoTest()
     522             : {
     523             :    //
     524             :    // Prints some information about the geometry. Only for debugging
     525             :    //
     526             : 
     527             :    int sm=0;
     528             :    //   for(int sm=0; sm<6; sm++) {
     529           0 :    for(int stack=0; stack<5; stack++) {
     530           0 :       for(int layer=0; layer<6; layer++) {
     531             : 
     532           0 :          Int_t det = sm*30+stack*6+layer;
     533           0 :          for (Int_t r = 0; r < 6; r++) {
     534           0 :             for (Int_t m = 0; m < 16; m++) {
     535           0 :                for (Int_t c = 7; c < 8; c++) {
     536           0 :                  cout << stack << ";" << layer << ";" << r << ";" << m
     537           0 :                       << ";" << ltuParam.GetX(det, r, m)
     538           0 :                       << ";" << ltuParam.GetLocalY(det, r, m, c)
     539           0 :                       << ";" << ltuParam.GetLocalZ(det, r, m) << endl;
     540             :                }
     541             :             }
     542             :          }
     543             :       }
     544             :    }
     545             :    // }
     546           0 : }
     547             : 
     548             : 
     549             : void AliTRDtrapConfigHandler::ConfigurePIDcorr(Int_t det)
     550             : {
     551             :    //
     552             :    // Calculate the MCM individual correction factors for the PID
     553             :    // and transfer them to AliTRDtrapConfig
     554             :    //
     555             : 
     556        1080 :   if (!fTrapConfig) {
     557           0 :     AliError("No TRAPconfig given");
     558           0 :     return;
     559             :   }
     560             : 
     561             :    static const Int_t addrLUTcor0 = AliTRDmcmSim::fgkDmemAddrLUTcor0;
     562             :    static const Int_t addrLUTcor1 = AliTRDmcmSim::fgkDmemAddrLUTcor1;
     563             : 
     564         540 :    UInt_t cor0;
     565         540 :    UInt_t cor1;
     566             : 
     567         540 :    Int_t nRobs = AliTRDgeometry::GetStack(det) == 2 ? 6 : 8;
     568             : 
     569        9288 :    for (Int_t r=0; r<nRobs; r++) {
     570      139536 :       for(Int_t m=0; m<16; m++) {
     571       65664 :          Int_t dest =  1<<10 | r<<7 | m;
     572       65664 :          if(fGtbl.GetGainTableROC(det) && fGtbl.GetGainTableROC(det)->GetGainTableMCM(r, m))
     573           0 :             ltuParam.GetCorrectionFactors(det, r, m, 9, cor0, cor1, fGtbl.GetGainTableROC(det)->GetGainTableMCM(r, m)->GetMCMGain());
     574             :          else
     575       65664 :             ltuParam.GetCorrectionFactors(det, r, m, 9, cor0, cor1);
     576       65664 :          AddValues(det, fgkScsnCmdWrite, dest, addrLUTcor0, cor0);
     577       65664 :          AddValues(det, fgkScsnCmdWrite, dest, addrLUTcor1, cor1);
     578             :     }
     579             :   }
     580        1080 : }
     581             : 
     582             : 
     583             : Bool_t AliTRDtrapConfigHandler::AddValues(UInt_t det, UInt_t cmd, UInt_t extali, Int_t addr, UInt_t data)
     584             : {
     585             :    // transfer the informations provided by LoadConfig to the internal class variables
     586             : 
     587     5122872 :   if (!fTrapConfig) {
     588           0 :     AliError("No TRAPconfig given");
     589           0 :     return kFALSE;
     590             :   }
     591             : 
     592     2561436 :   if(cmd != fgkScsnCmdWrite) {
     593           0 :     AliError(Form("Invalid command received: %i", cmd));
     594           0 :     return kFALSE;
     595             :   }
     596             : 
     597     2561436 :   AliTRDtrapConfig::TrapReg_t mcmReg = fTrapConfig->GetRegByAddress(addr);
     598     2561436 :   Int_t rocType = AliTRDgeometry::GetStack(det) == 2 ? 0 : 1;
     599             : 
     600             :   static const int mcmListSize=40;  // 40 is more or less arbitrary
     601     2561436 :   Int_t mcmList[mcmListSize];
     602             : 
     603             :   // configuration registers
     604     2561436 :   if(mcmReg >= 0 && mcmReg < AliTRDtrapConfig::kLastReg) {
     605             : 
     606           0 :     for(Int_t linkPair=0; linkPair<fgkMaxLinkPairs; linkPair++) {
     607           0 :       if(AliTRDfeeParam::ExtAliToAli(extali, linkPair, rocType, mcmList, mcmListSize)!=0) {
     608             :         Int_t i=0;
     609           0 :         while((i < mcmListSize) && (mcmList[i] != -1)) {
     610           0 :           if(mcmList[i]==127) {
     611           0 :             AliDebug(1, Form("broadcast write to %s: 0x%08x",
     612             :                              fTrapConfig->GetRegName((AliTRDtrapConfig::TrapReg_t) mcmReg), data));
     613           0 :             fTrapConfig->SetTrapReg( (AliTRDtrapConfig::TrapReg_t) mcmReg, data, det);
     614           0 :           }
     615             :           else {
     616           0 :             AliDebug(1, Form("individual write to %s (%i, %i): 0x%08x",
     617             :                              fTrapConfig->GetRegName((AliTRDtrapConfig::TrapReg_t) mcmReg), (mcmList[i]>>7), (mcmList[i]&0x7F), data));
     618           0 :             fTrapConfig->SetTrapReg( (AliTRDtrapConfig::TrapReg_t) mcmReg, data, det, (mcmList[i]>>7)&0x7, (mcmList[i]&0x7F));
     619             :           }
     620           0 :           i++;
     621             :         }
     622           0 :       }
     623             :     }
     624           0 :     return kTRUE;
     625             :   }
     626             :   // DMEM
     627     5122872 :   else if ( (addr >= AliTRDtrapConfig::fgkDmemStartAddress) &&
     628     2561436 :             (addr < (AliTRDtrapConfig::fgkDmemStartAddress + AliTRDtrapConfig::fgkDmemWords))) {
     629    25614360 :     for(Int_t linkPair=0; linkPair<fgkMaxLinkPairs; linkPair++) {
     630    10245744 :       if(AliTRDfeeParam::ExtAliToAli(extali, linkPair, rocType, mcmList, mcmListSize)!=0) {
     631             :         Int_t i=0;
     632    10252224 :         while(mcmList[i] != -1 && i < mcmListSize) {
     633     5126112 :           if(mcmList[i] == 127)
     634     2565216 :              fTrapConfig->SetDmem(addr, data, det, 0, 127);
     635             :           else
     636     2560896 :              fTrapConfig->SetDmem(addr, data, det, mcmList[i] >> 7, mcmList[i] & 0x7f);
     637     2563056 :           i++;
     638             :         }
     639     2563056 :       }
     640             :     }
     641     2561436 :     return kTRUE;
     642             :   }
     643           0 :   else if ( (addr >= AliTRDtrapConfig::fgkImemStartAddress) &&
     644           0 :             (addr < (AliTRDtrapConfig::fgkImemStartAddress + AliTRDtrapConfig::fgkImemWords))) {
     645             :     // IMEM is ignored for now
     646           0 :     return kTRUE;
     647             :   }
     648           0 :   else if ( (addr >= AliTRDtrapConfig::fgkDbankStartAddress) &&
     649           0 :             (addr < (AliTRDtrapConfig::fgkDbankStartAddress + AliTRDtrapConfig::fgkImemWords))) {
     650             :     // DBANK is ignored for now
     651           0 :     return kTRUE;
     652             :   }
     653             :   else {
     654           0 :     AliError(Form("Writing to unhandled address 0x%04x", addr));
     655           0 :     return kFALSE;
     656             :   }
     657     5122872 : }

Generated by: LCOV version 1.11