From 2ff519de7700ee5583985d565c8e76de67fd65ad Mon Sep 17 00:00:00 2001
From: Alexandru Bercuci <abercuci@niham.nipne.ro>
Date: Wed, 27 Apr 2022 16:41:27 +0200
Subject: [PATCH] add temporary DAQ time calibration for FASP

---
 macro/beamtime/mcbm2022/check_timing_any.C       | 16 ++++++++--------
 .../trd/unpack/CbmTrdUnpackFaspAlgo.cxx          |  7 +++++--
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/macro/beamtime/mcbm2022/check_timing_any.C b/macro/beamtime/mcbm2022/check_timing_any.C
index 7535424412..3d79b1defc 100644
--- a/macro/beamtime/mcbm2022/check_timing_any.C
+++ b/macro/beamtime/mcbm2022/check_timing_any.C
@@ -36,11 +36,10 @@ void check_timing_any(TString fileName, UInt_t uRunId = 0, Int_t nEvents = 0, TS
   CbmMcbmCheckTimingTask* timeChecker = new CbmMcbmCheckTimingTask();
   /// Default is using T0 as reference
   /// With Pulser rejection
-  /*
   timeChecker->SetReferenceDetector( ECbmModuleId::kT0, "T0",
                                      -1000., 1000., 320.,
                                      182, 190 );
-*/
+
   /// With pulser selection
   /*
   timeChecker->SetReferenceDetector( ECbmModuleId::kT0, "T0",
@@ -48,9 +47,9 @@ void check_timing_any(TString fileName, UInt_t uRunId = 0, Int_t nEvents = 0, TS
                                      190, 182 );
 */
   /// Here swapping with TOF
-  timeChecker->SetReferenceDetector(ECbmModuleId::kTof, "Tof", -3000, 3000, 3000);
-  timeChecker->RemoveCheckDetector(ECbmModuleId::kTof);
-  //timeChecker->AddCheckDetector(ECbmModuleId::kT0, "T0");
+  //   timeChecker->SetReferenceDetector(ECbmModuleId::kTof, "Tof", -3000, 3000, 3000);
+  //   timeChecker->RemoveCheckDetector(ECbmModuleId::kTof);
+  //   timeChecker->AddCheckDetector(ECbmModuleId::kT0, "T0");
 
   /// Here swapping with MUCH
   /*
@@ -60,7 +59,7 @@ void check_timing_any(TString fileName, UInt_t uRunId = 0, Int_t nEvents = 0, TS
   */
 
   /// Remove detectors not present in 2021
-  timeChecker->RemoveCheckDetector(ECbmModuleId::kT0);
+  //timeChecker->RemoveCheckDetector(ECbmModuleId::kT0);
   timeChecker->RemoveCheckDetector(ECbmModuleId::kMuch);
   //timeChecker->SetReferenceDetector(ECbmModuleId::kPsd, "Psd", -300000, 300000, 320 * 300);
   timeChecker->RemoveCheckDetector(ECbmModuleId::kPsd);
@@ -77,9 +76,10 @@ void check_timing_any(TString fileName, UInt_t uRunId = 0, Int_t nEvents = 0, TS
   */
 
   /// Add extra differential analysis on specific detectors
-  timeChecker->AddCheckDetector(ECbmModuleId::kSts, "Sts", -200., 200., 4000);
+  timeChecker->AddCheckDetector(ECbmModuleId::kSts, "Sts", -100., 100., 4000);
   timeChecker->AddCheckDetector(ECbmModuleId::kRich, "Rich", -100., 100., 4000);
-  timeChecker->AddCheckDetector(ECbmModuleId::kTrd, "Trd", -500.5, 500.5, 1001);
+  timeChecker->AddCheckDetector(ECbmModuleId::kTrd, "Trd", -500., 500., 250);
+  timeChecker->AddCheckDetector(ECbmModuleId::kTof, "Tof", -100, 100, 4000);
   timeChecker->SetDetectorDifferential(ECbmModuleId::kTrd, {"5", "21", "37", "53"});
 
   TString outFileName = fileName(0, fileName.Index(".digi.root"));
diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx
index a09c8070a8..d245ff7670 100644
--- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx
+++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx
@@ -205,7 +205,7 @@ bool CbmTrdUnpackFaspAlgo::pushDigis(std::vector<CbmTrdUnpackFaspAlgo::CbmTrdFas
   UShort_t lchR, lchT;
   Double_t r, t;
   Int_t dt, dtime, ch, pad, row;
-  ULong64_t tlab;
+  ULong64_t tlab, tdaqOffset(0);
   CbmTrdParFasp* faspPar(nullptr);
   const CbmTrdParFaspChannel* chCalib(nullptr);
   CbmTrdParModDigi* digiPar(nullptr);
@@ -228,6 +228,7 @@ bool CbmTrdUnpackFaspAlgo::pushDigis(std::vector<CbmTrdUnpackFaspAlgo::CbmTrdFas
       chCalib = faspPar->GetChannel(imess->ch);
       ch      = 2 * pad + chCalib->HasPairingR();
       row     = digiPar->GetPadRow(pad);
+      if (row % 2) tdaqOffset = 3;
       if (VERBOSE)
         printf("fasp[%2d] ch[%4d / %2d] pad[%4d] row[%2d] col[%2d] tilt[%d]\n", lFasp, ch, imess->ch, pad, row,
                digiPar->GetPadColumn(pad), chCalib->HasPairingT());
@@ -274,7 +275,9 @@ bool CbmTrdUnpackFaspAlgo::pushDigis(std::vector<CbmTrdUnpackFaspAlgo::CbmTrdFas
 
   // push finalized digits to the next level
   for (vector<CbmTrdDigi*>::iterator id = digis.begin(); id != digis.end(); id++) {
-    (*id)->SetTimeDAQ(fTime[0] + (*id)->GetTimeDAQ());
+    // TODO temporary add DAQ time calibration for FASPRO.
+    // Should be absorbed in the ASIC parameter definition
+    (*id)->SetTimeDAQ(fTime[0] + (*id)->GetTimeDAQ() + tdaqOffset);
     fOutputVec.emplace_back(*std::move(*id));
     if (fMonitor) fMonitor->FillHistos((*id));
     if (VERBOSE) cout << (*id)->ToString();
-- 
GitLab