From 0266d5f23af6928e5548caa38181893181dbafe2 Mon Sep 17 00:00:00 2001
From: Norbert Herrmann <n.herrmann@physi.uni-heidelberg.de>
Date: Sat, 10 Apr 2021 09:26:32 +0200
Subject: [PATCH] add DigiRate histograms

---
 macro/beamtime/mcbm2021/ana_trks.C            | 23 ++++++++++---------
 macro/beamtime/mcbm2021/gen_hits.sh           |  2 +-
 macro/beamtime/mcbm2021/init_cal_all.sh       |  6 ++---
 macro/beamtime/mcbm2021/iter_tracks.sh        |  2 +-
 macro/beamtime/mcbm2021/trk_cal_digi.sh       |  9 ++++----
 reco/detectors/tof/CbmTofEventClusterizer.cxx | 11 +++++++++
 reco/detectors/tof/CbmTofEventClusterizer.h   |  1 +
 reco/detectors/tof/CbmTofFindTracks.cxx       |  2 +-
 8 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/macro/beamtime/mcbm2021/ana_trks.C b/macro/beamtime/mcbm2021/ana_trks.C
index 4b82773a8e..16565aed72 100644
--- a/macro/beamtime/mcbm2021/ana_trks.C
+++ b/macro/beamtime/mcbm2021/ana_trks.C
@@ -163,8 +163,9 @@ void ana_trks(Int_t nEvents = 10000, Int_t iSel = 1, Int_t iGenCor = 1, TString
   //tofFindTracks->SetTtTarg(0.055);  // target value Nov2019 (triple stack run 831)
   //tofFindTracks->SetTtTarg(0.048);  // target value Nov2019 (double stack run 714)
   //tofFindTracks->SetTtTarg(0.047);  // target value Mar2020, after T0 fix (full run 600)
-  //  0.044);  // target value Mar2020, after T0 fix (double stack run 714)
-  tofFindTracks->SetTtTarg(0.035);             // target value for inverse velocity, > 0.033 ns/cm!
+    tofFindTracks->SetTtTarg(0.058);  // target value Mar2021, after T0 fix (double stack run 1058)
+  //tofFindTracks->SetTtTarg(0.038);  // target value Mar2021, after T0 fix (double stack run 1051)
+  //tofFindTracks->SetTtTarg(0.035);             // target value for inverse velocity, > 0.033 ns/cm!
   tofFindTracks->SetCalParFileName(cTrkFile);  // Tracker parameter value file name
   tofFindTracks->SetBeamCounter(5, 0, 0);      // default beam counter
   tofFindTracks->SetR0Lim(20.);
@@ -236,15 +237,15 @@ void ana_trks(Int_t nEvents = 10000, Int_t iSel = 1, Int_t iGenCor = 1, TString
       iMinNofHits   = 4;
       iNStations    = 9;
       iNReqStations = 5;
-      tofFindTracks->SetStation(0, 5, 0, 0);
-      tofFindTracks->SetStation(1, 0, 4, 1);
-      tofFindTracks->SetStation(2, 0, 3, 1);
-      tofFindTracks->SetStation(3, 0, 4, 0);
-      tofFindTracks->SetStation(4, 0, 3, 2);
-      tofFindTracks->SetStation(5, 9, 0, 0);
-      tofFindTracks->SetStation(6, 9, 1, 0);
-      tofFindTracks->SetStation(7, 9, 0, 1);
-      tofFindTracks->SetStation(8, 9, 1, 1);
+      tofFindTracks->SetStation(0, 0, 4, 1);
+      tofFindTracks->SetStation(1, 9, 0, 0);
+      tofFindTracks->SetStation(2, 9, 1, 0);
+      tofFindTracks->SetStation(3, 9, 0, 1);
+      tofFindTracks->SetStation(4, 9, 1, 1);
+      tofFindTracks->SetStation(5, 0, 3, 1);
+      tofFindTracks->SetStation(6, 0, 4, 0);
+      tofFindTracks->SetStation(7, 0, 3, 2);
+      tofFindTracks->SetStation(8, 5, 0, 0);
       break;
 
     case 2:
diff --git a/macro/beamtime/mcbm2021/gen_hits.sh b/macro/beamtime/mcbm2021/gen_hits.sh
index d2329381c2..be07761174 100755
--- a/macro/beamtime/mcbm2021/gen_hits.sh
+++ b/macro/beamtime/mcbm2021/gen_hits.sh
@@ -63,7 +63,7 @@ fi
 Nevt=$7
 if [[ ${Nevt} = "" ]]; then
     echo use all events
-    Nevt=-1
+    Nevt=500000
 fi
 
 echo gen_hits for $cRun with iDut=$iDut, iRef=$iRef, iSet=$iCalSet, iSel2=$iSel2, iBRef=$iBRef, Deadtime=$Deadtime, CalFile=$CalFile
diff --git a/macro/beamtime/mcbm2021/init_cal_all.sh b/macro/beamtime/mcbm2021/init_cal_all.sh
index 5338124cb4..2de32139df 100755
--- a/macro/beamtime/mcbm2021/init_cal_all.sh
+++ b/macro/beamtime/mcbm2021/init_cal_all.sh
@@ -56,9 +56,9 @@ cp .rootrc ${cRun}
 cd ${cRun}
 
 # Global variables, for for-loops
-iRestart=0   
-#iRestart=1  # use copied calibration file with walk corrections 
-#iRestart=33
+#iRestart=0   
+iRestart=1  # use copied calibration file with walk corrections 
+#iRestart=37
 iStep=0
 iStepLast=0
 iCalSel0=0
diff --git a/macro/beamtime/mcbm2021/iter_tracks.sh b/macro/beamtime/mcbm2021/iter_tracks.sh
index aad60160b0..a511c8ab02 100755
--- a/macro/beamtime/mcbm2021/iter_tracks.sh
+++ b/macro/beamtime/mcbm2021/iter_tracks.sh
@@ -123,7 +123,7 @@ fi
 
 # correction modes: 2 - TOff from Tt, 3 - Pull t, 4 - x, 5 - y, 6 - z, >10 - Pull t of individual stations 
 #for iCal in 3 2 10 11 12 13 14 15 4 5; do
-for iCal in 3 4 5; do
+for iCal in 2 3 4 5; do
 #for iCal in 3 2 4; do
 #for iCal in 3 2 ; do
 #for iCal in 2 ; do
diff --git a/macro/beamtime/mcbm2021/trk_cal_digi.sh b/macro/beamtime/mcbm2021/trk_cal_digi.sh
index 2e7e87c263..8efb9ebe22 100755
--- a/macro/beamtime/mcbm2021/trk_cal_digi.sh
+++ b/macro/beamtime/mcbm2021/trk_cal_digi.sh
@@ -108,7 +108,8 @@ if [[ $iShLev = "" ]]; then
   dDTRMSres=100000
   dL0DTRMSres=100000
 # get initial digi calibration 
-  cp -v  ./I*/${CalFile}  .
+# cp -v  ./I*/${CalFile}  .
+  cp -v ${CalFile}  IniTrk_${CalFile}
 # get latest tracker offsets
 # cp -v ../${cRun}_tofFindTracks.hst.root .
 else
@@ -159,7 +160,7 @@ while [[ $dDTres -gt 0 ]]; do
     cd $wdir/$cRun
     echo Current loop with Iter $iIter, CalAct $iCalAct and CalOpt $iCalOpt
     if [[ $iCalOpt = 1 ]] || [[ $iCalAct -gt 1 ]]; then 
-      root -b -q '../ana_digi_cal.C('$nEvt',93,1,'$iRef',1,"'$cRun'",'$iCalSet',1,'$iSel2','$Deadtime',"'$CalIdMode'") '
+      root -b -q '../ana_digi_cal_all.C('$nEvt',93,1,'$iRef',1,"'$cRun'",'$iCalSet',1,'$iSel2','$Deadtime',"'$CalIdMode'") '
       # update calibration parameter file, will only be active in next iteration 
       if [[ $iIter = -10 ]] && [[ $iCalOpt = 1 ]]; then  # exploratory option when iIter set to 0 
         echo Update Calibration file from ana_digi_cal
@@ -168,8 +169,8 @@ while [[ $dDTres -gt 0 ]]; do
         echo 20000 > TOffAvRMS.res
       else
         root -b -q '../ana_trks.C('$nEvt','$iSel','$iGenCor',"'$cRun'","'$cCalSet2'",'$iSel2','$iTraSetup','$fRange1','$fRange2','$Deadtime',"'$CalIdMode'",1,1,'$iCalSet','$iCalAct')'
-      #root -l 'ana_trksi.C(-1,10,1,"385.50.5.0","000014500_020",20,1,1.90,7.60,50,"385.50.5.0",1,1)'
-  
+        #root -l 'ana_trksi.C(-1,10,1,"385.50.5.0","000014500_020",20,1,1.90,7.60,50,"385.50.5.0",1,1)'
+        #exit 0 # for debugging
         cp -v New_${CalFile} ${CalFile}  
       fi
       (( iIter   += 1 ))
diff --git a/reco/detectors/tof/CbmTofEventClusterizer.cxx b/reco/detectors/tof/CbmTofEventClusterizer.cxx
index dd1b7ccac0..d9ed14db52 100644
--- a/reco/detectors/tof/CbmTofEventClusterizer.cxx
+++ b/reco/detectors/tof/CbmTofEventClusterizer.cxx
@@ -153,6 +153,7 @@ CbmTofEventClusterizer::CbmTofEventClusterizer(const char* name, Int_t verbose,
   , fhRpcDigiDTLD()
   , fhRpcDigiDTFD()
   , fhRpcDigiDTMul()
+  , fhRpcDigiRate()
   , fhRpcCluMul()
   , fhRpcCluRate()
   , fhRpcCluRate10s()
@@ -1177,6 +1178,7 @@ Bool_t CbmTofEventClusterizer::CreateHistos()
   fhRpcDigiDTLD.resize(iNbDet);
   fhRpcDigiDTFD.resize(iNbDet);
   fhRpcDigiDTMul.resize(iNbDet);
+  fhRpcDigiRate.resize(iNbDet);
   fhRpcCluMul.resize(iNbDet);
   fhRpcCluRate.resize(iNbDet);
   fhRpcCluRate10s.resize(iNbDet);
@@ -1268,6 +1270,10 @@ Bool_t CbmTofEventClusterizer::CreateHistos()
                                              iRpcId, iSmId, iSmType),
                                         fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 0,
                                         fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 20., 0.5, 20.5);
+    fhRpcDigiRate[iDetIndx] =
+      new TH1D(Form("cl_SmT%01d_sm%03d_rpc%03d_digirate", iSmType, iSmId, iRpcId),
+               Form("Digi rate of Rpc #%03d in Sm %03d of type %d; Time (s); Rate (Hz)", iRpcId, iSmId, iSmType), 36000.,
+               0., 3600.);
 
     fhRpcCluMul[iDetIndx] =
       new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_Mul", iSmType, iSmId, iRpcId),
@@ -4071,6 +4077,11 @@ Bool_t CbmTofEventClusterizer::BuildClusters()
         else
           break;
 
+        if (StartAnalysisTime > 0) {
+          Double_t dTimeAna = (pDigi->GetTime() - StartAnalysisTime) / 1.E9;
+          fhRpcDigiRate[iDetIndx]->Fill(dTimeAna, 1. / fhRpcDigiRate[iDetIndx]->GetBinWidth(1));
+        }
+
         size_t iDigiCh = pDigi->GetChannel() * 2 + pDigi->GetSide();
         if (iDigiCh < fvTimeLastDigi[iDetIndx].size()) {
           if (fvTimeLastDigi[iDetIndx][iDigiCh] > 0) {
diff --git a/reco/detectors/tof/CbmTofEventClusterizer.h b/reco/detectors/tof/CbmTofEventClusterizer.h
index a5dfd338e8..6e28173523 100644
--- a/reco/detectors/tof/CbmTofEventClusterizer.h
+++ b/reco/detectors/tof/CbmTofEventClusterizer.h
@@ -304,6 +304,7 @@ private:
   std::vector<TH2*> fhRpcDigiDTLD;                           //[nbDet]
   std::vector<TH2*> fhRpcDigiDTFD;                           //[nbDet]
   std::vector<TH2*> fhRpcDigiDTMul;                          //[nbDet]
+  std::vector<TH1*> fhRpcDigiRate;                            //[nbDet]
   std::vector<TH1*> fhRpcCluMul;                             //[nbDet]
   std::vector<TH1*> fhRpcCluRate;                            //[nbDet]
   std::vector<TH1*> fhRpcCluRate10s;                         //[nbDet]
diff --git a/reco/detectors/tof/CbmTofFindTracks.cxx b/reco/detectors/tof/CbmTofFindTracks.cxx
index 2e2cc4197b..daa187bdf6 100644
--- a/reco/detectors/tof/CbmTofFindTracks.cxx
+++ b/reco/detectors/tof/CbmTofFindTracks.cxx
@@ -1254,7 +1254,7 @@ void CbmTofFindTracks::CreateHistograms()
                          100, -DZ0MAX, DZ0MAX);
 
   fhTOff_Smt   = new TH2F(Form("hTOff_Smt"), Form("Tracklet TOff; RpcInd ; #DeltaTOff (ns)"), nSmt, 0, nSmt, 501,
-                        -fT0MAX * 20, fT0MAX * 20);
+                        -fT0MAX * 5, fT0MAX * 5);
   fhTOff_HMul2 = new TH2F(Form("hTOff_HMul2"), Form("Tracklet TOff(HMul2); RpcInd ; TOff (ns)"), nSmt, 0, nSmt, 500,
                           -fT0MAX, fT0MAX);
 
-- 
GitLab