From 8a622994a97a7df7502e7f429040325b58ecf59d Mon Sep 17 00:00:00 2001
From: Alexandru Bercuci <abercuci@niham.nipne.ro>
Date: Sun, 1 May 2022 21:01:45 +0300
Subject: [PATCH] generate the default asic parameters according to the new
 scheme (only for FASP)

---
 core/detectors/trd/CbmTrdParFasp.cxx    |  2 +-
 core/detectors/trd/CbmTrdParFasp.h      |  2 +-
 core/detectors/trd/CbmTrdParSetAsic.cxx | 17 +++++++++--------
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/core/detectors/trd/CbmTrdParFasp.cxx b/core/detectors/trd/CbmTrdParFasp.cxx
index 00611d5380..aff68e2723 100644
--- a/core/detectors/trd/CbmTrdParFasp.cxx
+++ b/core/detectors/trd/CbmTrdParFasp.cxx
@@ -113,7 +113,7 @@ void CbmTrdParFasp::Print(Option_t* opt) const
   CbmTrdParAsic::Print("TrdParFasp");
   printf("  Nchannels[%2d]\n", (Int_t) fChannelAddresses.size());
   for (Int_t ich(0); ich < TMath::Min((Int_t) GetNchannels(), (Int_t) fChannelAddresses.size()); ich++) {
-    printf("  %2d pad_addr[%4d]", ich, GetChannelAddress(ich));
+    printf("  %2d pad_addr[%4d]", ich, GetPadAddress(ich));
     fCalib[ich].Print(opt);
   }
 }
diff --git a/core/detectors/trd/CbmTrdParFasp.h b/core/detectors/trd/CbmTrdParFasp.h
index 8648992d7b..4d45169864 100644
--- a/core/detectors/trd/CbmTrdParFasp.h
+++ b/core/detectors/trd/CbmTrdParFasp.h
@@ -74,7 +74,7 @@ public:
   const CbmTrdParFaspChannel* GetChannel(Int_t ch_address) const;
   virtual Int_t GetNchannels() const { return NFASPCH; };
 
-  Int_t GetChannelAddress(Int_t ich) const
+  Int_t GetPadAddress(Int_t ich) const
   {
     return ((ich < 0 || ich >= GetNchannels()) ? 0 : 0.5 * fChannelAddresses[ich]);
   }
diff --git a/core/detectors/trd/CbmTrdParSetAsic.cxx b/core/detectors/trd/CbmTrdParSetAsic.cxx
index b65e02c9f3..033aa06fe7 100644
--- a/core/detectors/trd/CbmTrdParSetAsic.cxx
+++ b/core/detectors/trd/CbmTrdParSetAsic.cxx
@@ -56,7 +56,7 @@ void CbmTrdParSetAsic::addParam(CbmTrdParMod* mod)
 //_______________________________________________________________________________
 Bool_t CbmTrdParSetAsic::getParams(FairParamList* l)
 {
-  //LOG(info) << GetName() << "::getParams(FairParamList*)";
+  // LOG(info) << GetName() << "::getParams(FairParamList*)";
   if (!l) return kFALSE;
   if (!l->fill("NrOfModules", &fNrOfModules)) return kFALSE;
   TArrayI moduleId(fNrOfModules);
@@ -121,7 +121,7 @@ Bool_t CbmTrdParSetAsic::getParams(FairParamList* l)
 void CbmTrdParSetAsic::putParams(FairParamList* l)
 {
   if (!l) return;
-  //LOG(info) << GetName() << "::putParams(FairParamList*)";
+  // LOG(info) << GetName() << "::putParams(FairParamList*)";
 
   Int_t idx(0);
   TArrayI moduleId(fNrOfModules), nAsic(fNrOfModules), typeAsic(fNrOfModules);
@@ -186,20 +186,21 @@ void CbmTrdParSetAsic::putParams(FairParamList* l)
       for (auto iModuleIt : mod->fModuleMap) {
         int offset       = iAsicNr * sizePerFasp;
         asicInfo[offset] = iModuleIt.first;
-        Int_t nchannels(((CbmTrdParAsic*) iModuleIt.second)->GetNchannels());
-        CbmTrdParFasp* fasp = (CbmTrdParFasp*) iModuleIt.second;
 
-        for (Int_t ich(0); ich < nchannels; ich++) {
-          Int_t faspAddress              = fasp->GetChannelAddress(ich);
-          asicInfo[offset + 1 + ich]     = faspAddress;
+        CbmTrdParFasp* fasp = (CbmTrdParFasp*) iModuleIt.second;
+        Int_t ich(0);
+        for (auto chAddress : fasp->GetChannelAddresses()) {
+          asicInfo[offset + 1 + ich]     = chAddress;
           const CbmTrdParFaspChannel* ch = fasp->GetChannel(ich);
           if (!ch) {
-            LOG(info) << "Missing calib for Fasp[" << offset << "] pad " << faspAddress;
+            LOG(info) << "Missing calib for Fasp[" << offset << "] pad " << chAddress;
+            ich++;
             continue;
           }
           asicInfo[offset + 1 + (1 * NFASPCH) + ich] = ch->GetPileUpTime();
           asicInfo[offset + 1 + (2 * NFASPCH) + ich] = ch->GetThreshold();
           asicInfo[offset + 1 + (3 * NFASPCH) + ich] = ch->GetMinDelaySignal();
+          ich++;
         }
         iAsicNr++;
       }
-- 
GitLab