From b9b885188fb51d5dabd6e8ae5246112e24b248bc Mon Sep 17 00:00:00 2001
From: Michael Deveaux <deveaux@physik.uni-frankfurt.de>
Date: Fri, 20 Jan 2023 16:35:42 +0100
Subject: [PATCH] First adaptations for a time based digitizer. Methods added
 but not used in CbmMvdDigitizerTask and CbmMvdDataSheet

---
 core/detectors/mvd/CbmMvdStationPar.cxx       |  4 +-
 .../mvd/SensorDataSheets/CbmMvdMimosis.cxx    |  1 +
 .../CbmMvdSensorDataSheet.cxx                 |  5 ++
 .../SensorDataSheets/CbmMvdSensorDataSheet.h  | 34 ++++++++---
 .../tasks/CbmMvdSensorDigitizerTask.cxx       | 58 ++++++++++++++++---
 .../plugins/tasks/CbmMvdSensorDigitizerTask.h |  9 ++-
 6 files changed, 92 insertions(+), 19 deletions(-)

diff --git a/core/detectors/mvd/CbmMvdStationPar.cxx b/core/detectors/mvd/CbmMvdStationPar.cxx
index 409b95b78d..3be56060a6 100644
--- a/core/detectors/mvd/CbmMvdStationPar.cxx
+++ b/core/detectors/mvd/CbmMvdStationPar.cxx
@@ -93,7 +93,7 @@ void CbmMvdStationPar::SetParameterMax(std::vector<Double_t>& parArray, Int_t iS
   if ((iStation < 0) || (iStation >= fStationCount)) { LOG(error) << "Station number out of Range "; }
   else {
     Double_t& v = parArray[iStation];
-    if (isnan(v) || (v < value)) { v = value; }
+    if (std::isnan(v) || (v < value)) { v = value; }
   }
 }
 // -------------------------------------------------------------------------
@@ -106,7 +106,7 @@ void CbmMvdStationPar::SetParameterMin(std::vector<Double_t>& parArray, Int_t iS
   if ((iStation < 0) || (iStation >= fStationCount)) { LOG(error) << "Station number out of Range "; }
   else {
     Double_t& v = parArray[iStation];
-    if (isnan(v) || (v > value)) { v = value; }
+    if (std::isnan(v) || (v > value)) { v = value; }
   }
 }
 // -------------------------------------------------------------------------
diff --git a/core/detectors/mvd/SensorDataSheets/CbmMvdMimosis.cxx b/core/detectors/mvd/SensorDataSheets/CbmMvdMimosis.cxx
index 86617fc742..c7d1acaf32 100644
--- a/core/detectors/mvd/SensorDataSheets/CbmMvdMimosis.cxx
+++ b/core/detectors/mvd/SensorDataSheets/CbmMvdMimosis.cxx
@@ -32,6 +32,7 @@ CbmMvdMimosis::CbmMvdMimosis()
   fEpiTh           = 18e-4;   // Thickness of the epitaxial layer
 
   fChargeThreshold = 1.;
+  fAnalogThreshold =150; //Threshold in electrons
 
   /** Description of the sensor for the digitizer //mesaured by melisa for Mimosa26AHR**/
   fNoise       = 13;
diff --git a/core/detectors/mvd/SensorDataSheets/CbmMvdSensorDataSheet.cxx b/core/detectors/mvd/SensorDataSheets/CbmMvdSensorDataSheet.cxx
index 6d424bd9e5..135afcdc3c 100644
--- a/core/detectors/mvd/SensorDataSheets/CbmMvdSensorDataSheet.cxx
+++ b/core/detectors/mvd/SensorDataSheets/CbmMvdSensorDataSheet.cxx
@@ -50,6 +50,11 @@ CbmMvdSensorDataSheet::CbmMvdSensorDataSheet()
   , fPixelsPerBank(0)
   , fAdcStepSize(fAdcDynamic / fAdcSteps)
   , fValidData(kFALSE)
+  , fSignalRiseTime(nan("NotSet"))
+  , fSignalFallTime(nan("NotSet"))
+  , fAnalogThreshold(-1)
+
+
 {
 }
 
diff --git a/core/detectors/mvd/SensorDataSheets/CbmMvdSensorDataSheet.h b/core/detectors/mvd/SensorDataSheets/CbmMvdSensorDataSheet.h
index 0d64bab7bf..787fe4c19a 100644
--- a/core/detectors/mvd/SensorDataSheets/CbmMvdSensorDataSheet.h
+++ b/core/detectors/mvd/SensorDataSheets/CbmMvdSensorDataSheet.h
@@ -58,6 +58,10 @@ protected:
   Double_t fEpiTh;            // Thickness of the epitaxial layer
 
   Double_t fChargeThreshold;
+  Double_t fSignalRiseTime;
+  Double_t fSignalFallTime;
+
+
 
   /** Description of the sensor for the digitizer **/
   Double_t fNoise;        // Noise of the sensor
@@ -68,17 +72,24 @@ protected:
   Double_t fLorentzPar1;  // Lorentz for digitizer
   Double_t fLorentzPar2;  // Lorentz for digitizer
 
-  /** ADC description **/
+  /** ADC description, relevant for sensors with analog readout (not present in the CbmMvd) **/
 
   Int_t fAdcDynamic;
   Int_t fAdcOffset;
   Int_t fAdcBits;
   Int_t fAdcSteps;
+  Float_t fAdcStepSize;
+
+  /** Sensor substructure, relevant for MIMOSA-26 (Prototype of the CbmMvd) **/
   Int_t fStatesPerBank;
   Int_t fStatesPerLine;
   Int_t fStatesPerFrame;
   Int_t fPixelsPerBank;
-  Float_t fAdcStepSize;
+
+  /** Threshold of the in-pixel discriminator. Relevant for MIMOSIS **/
+  Int_t fAnalogThreshold;
+
+
 
   /** Self-organizsation **/
 
@@ -89,15 +100,19 @@ public:
   virtual TString* GetSensorName() { return &fMimosaName; };
   virtual Double_t GetPixelPitchX() { return fPixelPitchX; };
   virtual Double_t GetPixelPitchY() { return fPixelPitchY; };
-  virtual Int_t GetNPixelsX() { return fNPixelsX; };
-  virtual Int_t GetNPixelsY() { return fNPixelsY; };
-  virtual Int_t GetNPixels() { return fNPixels; };
-  virtual Int_t GetPixelSignX() { return fPixelSignX; };
-  virtual Int_t GetPixelSignY() { return fPixelSignY; };
-  virtual Int_t GetShutterSign() { return fShutterSign; };
+  virtual Int_t    GetNPixelsX() { return fNPixelsX; };
+  virtual Int_t    GetNPixelsY() { return fNPixelsY; };
+  virtual Int_t    GetNPixels() { return fNPixels; };
+  virtual Int_t    GetPixelSignX() { return fPixelSignX; };
+  virtual Int_t    GetPixelSignY() { return fPixelSignY; };
+  virtual Int_t    GetShutterSign() { return fShutterSign; };
   virtual Double_t GetIntegrationTime() { return fIntegrationTime; };
   virtual Double_t GetEpiThickness() { return fEpiTh; }
   virtual Double_t GetNoise() { return fNoise; };
+  virtual Double_t GetSignalRiseTime (){ return fSignalRiseTime;};
+  virtual Double_t GetSignalFallTime (){ return fSignalFallTime;};
+
+
 
   /** Description of the sensor for the digitizer **/
   virtual Double_t GetLandauMPV() { return fLandauMPV; };      // Landau for digitizer
@@ -109,6 +124,9 @@ public:
 
 
   virtual Double_t GetChargeThreshold() { return fChargeThreshold; };
+  virtual Int_t GetAnalogThreshold () {return fAnalogThreshold;};
+
+
 
   /** ADC description **/
 
diff --git a/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.cxx b/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.cxx
index e9d03cb7c2..9d597b6aa8 100644
--- a/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.cxx
+++ b/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.cxx
@@ -443,12 +443,8 @@ void CbmMvdSensorDigitizerTask::Exec()
       ProducePixelCharge(point);
     }  //loop on MCpoints
 
-
-    Int_t inputNr      = 0;
-    Int_t eventNr      = 0;
-    Double_t eventTime = .0;
     Int_t nDigis       = 0;
-    GetEventInfo(inputNr, eventNr, eventTime);
+    GetEventInfo(fInputNr, fEventNr, fEventTime);
 
     if (fproduceNoise) ProduceNoise();
 
@@ -459,18 +455,18 @@ void CbmMvdSensorDigitizerTask::Exec()
         nDigis = fDigis->GetEntriesFast();
 
         new ((*fDigis)[nDigis]) CbmMvdDigi(fSensor->GetSensorNr(), pixel->GetX(), pixel->GetY(), pixel->GetCharge(),
-                                           fPixelSizeX, fPixelSizeY, pixel->GetTime(), pixel->GetFrame());
+                                           fPixelSizeX, fPixelSizeY, fEventTime+ pixel->GetTime(), pixel->GetFrame());
 
 
         new ((*fOutputBuffer)[nDigis])
           CbmMvdDigi(fSensor->GetSensorNr(), pixel->GetX(), pixel->GetY(), pixel->GetCharge(), fPixelSizeX, fPixelSizeY,
-                     pixel->GetTime(), pixel->GetFrame());
+                     fEventTime+pixel->GetTime(), pixel->GetFrame());
 
         new ((*fDigiMatch)[nDigis]) CbmMatch();
         CbmMatch* match = (CbmMatch*) fDigiMatch->At(nDigis);
         for (Int_t iLink = 0; iLink < pixel->GetNContributors(); iLink++) {
           if (pixel->GetTrackID()[iLink] > -1)
-            match->AddLink((Double_t) pixel->GetPointWeight()[iLink], pixel->GetPointID()[iLink], eventNr, inputNr);
+            match->AddLink((Double_t) pixel->GetPointWeight()[iLink], pixel->GetPointID()[iLink], fEventNr, fInputNr);
           else
             match->AddLink((Double_t) pixel->GetPointWeight()[iLink], pixel->GetPointID()[iLink]);
         }
@@ -495,6 +491,50 @@ void CbmMvdSensorDigitizerTask::Exec()
 
 // -------------------------------------------------------------------------
 
+
+
+Int_t CbmMvdSensorDigitizerTask::GetPixelCharge(CbmMvdPixelCharge* myPixel, Double_t readoutTime) {
+
+/**
+ * Get the analog signal created by each signal. Assumption: Signal rise and signal fall follows exponential. Contributions of the individual hits add up.
+ **/
+
+ Int_t pixelCharge=0;
+ Double_t pixelSignalRiseTime=fsensorDataSheet->GetSignalRiseTime();
+ Double_t pixelSignalFallTime=fsensorDataSheet->GetSignalFallTime();
+ Int_t nHits=0; //=myPixel->GetNHits();
+
+  for(Int_t hitNr=0; hitNr<nHits; hitNr++){
+    Int_t hitCharge=0; //=pixel->GetHitCharge(hitNr);
+    Int_t hitTime=0; //=pixel->GetHitTime(hitNr);
+
+    pixelCharge=pixelCharge + hitCharge * (1- TMath::Exp(-(readoutTime-hitTime)/pixelSignalRiseTime)); //exponential signal rise of the analog charge
+    pixelCharge=pixelCharge - hitCharge * (1- TMath::Exp(-(readoutTime-hitTime)/pixelSignalFallTime)); //exponential signal fall of the analog charge
+  }
+
+  return pixelCharge;
+
+}
+
+// ------------------------------------------------------------------------------
+
+
+Bool_t CbmMvdSensorDigitizerTask::GetSignalAboveThreshold (CbmMvdPixelCharge* myPixel, Double_t readoutTime) {
+  /**
+   * Checks if pixel is above threshold.
+   **/
+
+  CbmMvdSensor* mySensor;
+
+
+
+  return (GetPixelCharge(myPixel, readoutTime)>fsensorDataSheet->GetAnalogThreshold ());
+
+}
+
+// ------------------------------------------------------------------------------
+
+
 // -------------------------------------------------------------------------
 void CbmMvdSensorDigitizerTask::GetEventInfo(Int_t& inputNr, Int_t& eventNr, Double_t& eventTime)
 {
@@ -848,6 +888,8 @@ void CbmMvdSensorDigitizerTask::ProducePixelCharge(CbmMvdPoint* point)
                                                       + 0.25 * fPar1 * fPar1)
                              + fPar2);
 
+
+
         if (totCharge < 1) {
 
           // 			 cout << endl << "charge is " << totCharge << " < 1 electron thus charge is negligible" << endl;
diff --git a/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.h b/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.h
index a689bc9f12..074a4bd00d 100644
--- a/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.h
+++ b/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.h
@@ -75,6 +75,8 @@ public:
   void ProduceIonisationPoints(CbmMvdPoint* point);
   void ProducePixelCharge(CbmMvdPoint* point);
   void ProduceNoise();
+  Bool_t  GetSignalAboveThreshold (CbmMvdPixelCharge* myPixel, Double_t readoutTime);
+  Int_t   GetPixelCharge(CbmMvdPixelCharge* myPixel, Double_t readoutTime);
 
   void SetProduceNoise() { fproduceNoise = kTRUE; };
 
@@ -93,8 +95,13 @@ public:
 public:
   // ----------   Protected data members  ------------------------------------
 
-  Int_t fcurrentFrameNumber;
+  // Information about event and sensor status
+  Int_t         fcurrentFrameNumber;
+  Int_t         fEventNr;
+  Int_t         fInputNr;
+  Double_t      fEventTime;
 
+  // Information about sensor
   Double_t fEpiTh;
   Double_t fSegmentLength;
 
-- 
GitLab