From 76d85ffed94dee7356b0a3bf4935ae1d6b0c9ced Mon Sep 17 00:00:00 2001
From: Michael Deveaux <deveaux@physik.uni-frankfurt.de>
Date: Mon, 24 Jul 2023 16:54:41 +0200
Subject: [PATCH] Fix code after rebase

---
 .../tasks/CbmMvdSensorDigitizerTask.cxx       | 100 +++++-------------
 .../plugins/tasks/CbmMvdSensorDigitizerTask.h |   6 +-
 2 files changed, 27 insertions(+), 79 deletions(-)

diff --git a/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.cxx b/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.cxx
index df930f6ce9..ad68fbe76f 100644
--- a/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.cxx
+++ b/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.cxx
@@ -435,8 +435,8 @@ void CbmMvdSensorDigitizerTask::Exec()
       //The digitizer acts only on particles, which crossed the station.
       //Particles generated in the sensor or being absorbed in this sensor are ignored
       if (TMath::Abs(point->GetZOut() - point->GetZ()) < 0.9 * fEpiTh) {
-        LOG(debug) << "hit not on chip with thickness " << 0.9 * 2 * fSensor->GetDZ();
-        LOG(debug) << "hit not on chip with length " << TMath::Abs(point->GetZOut() - point->GetZ());
+        LOG(debug) << "hit not on chip with thickness " << fEpiTh*10000 << "µm";
+        LOG(debug) << "hit not on chip with length " << TMath::Abs(point->GetZOut() - point->GetZ())*10000 << "µm";
         continue;
       }
       // Reject for the time being light nuclei (no digitization modell yet)
@@ -447,60 +447,31 @@ void CbmMvdSensorDigitizerTask::Exec()
       ProducePixelCharge(point);
     }  //loop on MCpoints
 
-    Int_t nDigis = 0;
+    //Int_t nDigis = 0;
     GetEventInfo(fInputNr, fEventNr, fEventTime);
 
-    if (fproduceNoise) ProduceNoise();
-
-    for (Int_t i = 0; i < fPixelCharge->GetEntriesFast(); i++) {
-      CbmMvdPixelCharge* pixel = (CbmMvdPixelCharge*) fPixelCharge->At(i);
-
-      if (pixel->GetCharge() > fChargeThreshold) {
-        nDigis = fDigis->GetEntriesFast();
-
-        new ((*fDigis)[nDigis])
-          CbmMvdDigi(fSensor->GetSensorNr(), pixel->GetX(), pixel->GetY(), pixel->GetCharge(), fPixelSizeX, fPixelSizeY,
-                     fEventTime + pixel->GetPixelTime(), pixel->GetFrame());
-
-
-        new ((*fOutputBuffer)[nDigis])
-          CbmMvdDigi(fSensor->GetSensorNr(), pixel->GetX(), pixel->GetY(), pixel->GetCharge(), fPixelSizeX, fPixelSizeY,
-                     fEventTime + pixel->GetPixelTime(), pixel->GetFrame());
+    ProduceDigis();
+    CleanPixelChargeList();
 
-        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], fEventNr, fInputNr);
-          else
-            match->AddLink((Double_t) pixel->GetPointWeight()[iLink], pixel->GetPointID()[iLink]);
-        }
-      }
-      else {
-        //LOG(debug) << "charge under threshold, digi rejected";
-      }
     /* Clean pixel charges, which do not reach threshold.
      * This avoids that the first entries in the pixelCharge objects contain information about hits, which are insufficient
      * for creating a hit. Having first entries below threshold complicates defining the hit time.
      * Draw back: The charge of tracks from different events does not add.
      */
-/*
-    ProduceDigis();
-    CleanPixelChargeList();
-
-
 
 
 
     if (fproduceNoise) ProduceNoise();
 
-*/
+
     }
 
   else {
     //LOG(debug)<< "No input found on Sensor " << fSensor->GetSensorNr() << " from " << fInputPoints->GetEntriesFast()<< " McPoints";
   }
 
+
+  // fixme - This seems too much deleting
   fPixelCharge->Delete();
   fChargeMap.clear();
   fInputPoints->Delete();
@@ -514,44 +485,19 @@ void CbmMvdSensorDigitizerTask::ProduceDigis(){
     Int_t nDigis       = 0;
     CbmMvdPixelCharge* pixel;
     GetEventInfo(fInputNr, fEventNr, fEventTime);
-
-
-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
-/* =======
-
+    LOG(debug)<< "CbmMvdSensorDigitizerTask::ProduceDigis() - NumberOfPixelCharge =  " << fPixelCharge->GetEntriesFast();
     for (Int_t i = 0; i < fPixelCharge->GetEntriesFast(); i++) {
       pixel = (CbmMvdPixelCharge*) fPixelCharge->At(i);
 
+      LOG(debug)<< "CbmMvdSensorDigitizerTask::ProduceDigis() - Working on PixelCharge " << i;
+      LOG(debug)<< "CbmMvdSensorDigitizerTask::ProduceDigis() - PixelChargeTime =  " << pixel->GetEndOfBusyTime();
+      LOG(debug)<< "CbmMvdSensorDigitizerTask::ProduceDigis() - EventTime =  " << fEventTime;
+
       if (pixel->GetEndOfBusyTime()>fEventTime){continue;}
       /* The digi is only generated once the busy-time has passed. This is an easy way to avoid double counting of hits.
        * If no digi is formed, the initial hit information remains stored in the CbmMvdPixelCharge
        */
-
+      LOG(debug)<< "CbmMvdSensorDigitizerTask::ProduceDigis() - Working on PixelCharge " << i;
       Int_t numberOfContributorCausingHit=CheckForHit(pixel);
 
       if (numberOfContributorCausingHit==-1){
@@ -634,7 +580,7 @@ Int_t CbmMvdSensorDigitizerTask::CheckForHit(CbmMvdPixelCharge* pixel){
   /* Intended to spot the number of contributors to the pixel charge, which fired the pixel.
    * The number of the contributor is returned
    */
-  if (!fSensorDataSheet) {cout << " - E - CbmMvdSensorDigitizerTask::CheckForHit : Missing Datasheet." << endl;}
+  if (!fSensorDataSheet) {std::cout << " - E - CbmMvdSensorDigitizerTask::CheckForHit : Missing Datasheet." << std::endl;}
   if (pixel->GetEarliestHitCharge() > fSensorDataSheet->GetAnalogThreshold()) {return 0;}
   /* The pixel fired immedeately, easiest case.else ...
    * Else: Check if a later impact fired the pixel
@@ -695,7 +641,7 @@ Bool_t CbmMvdSensorDigitizerTask::GetSignalAboveThreshold(CbmMvdPixelCharge* myP
   //  CbmMvdSensor* mySensor; // not used FU 12.05.23
 
 
-  return (GetPixelCharge(myPixel, readoutTime) > fsensorDataSheet->GetAnalogThreshold());
+  return (GetPixelCharge(myPixel, readoutTime) > fSensorDataSheet->GetAnalogThreshold());
 }
 /*
 Bool_t CbmMvdSensorDigitizerTask::GetPixelIsBusy(CbmMvdPixelCharge* myPixel, Double_t readoutTime) {}
@@ -1081,7 +1027,7 @@ void CbmMvdSensorDigitizerTask::ProducePixelCharge(CbmMvdPoint* point)
           if (fChargeMapIt == fChargeMap.end()) {
             pixel = new ((*fPixelCharge)[fPixelCharge->GetEntriesFast()]) CbmMvdPixelCharge(
               totCharge, ix, iy, point->GetPointId(), point->GetTrackID(), (point->GetX() + point->GetXOut()) / 2,
-              (point->GetY() + point->GetXOut()) / 2, point->GetTime(), point->GetFrame());
+              (point->GetY() + point->GetYOut()) / 2, point->GetTime(), point->GetFrame());
             //LOG(debug) << "new charched pixel with charge " << totCharge << " at " << ix << " " << iy;
             //  					  fPixelChargeShort.push_back(pixel);
             // 				LOG(debug) << "added pixel to ChargeShort vector ";
@@ -1124,9 +1070,8 @@ void CbmMvdSensorDigitizerTask::ProducePixelCharge(CbmMvdPoint* point)
       pixelCharge->DigestCharge(((float) (point->GetX() + point->GetXOut()) / 2),
                                 ((float) (point->GetY() + point->GetYOut()) / 2), fEventTime + point->GetTime(),
                                 point->GetPointId(), point->GetTrackID());
-/* =======
-                                ((float) (point->GetY() + point->GetYOut()) / 2), fEventTime + point->GetTime(),point->GetPointId(),
-                                point->GetTrackID());
+
+
 
       // So far, the charge created by this MC-hit in a given pixel was added up in the Pixel charge objects.
       // Digest charge closes the summing and adds the MC information related to the hit. The MC information will be forwarded to the digi links later.
@@ -1134,7 +1079,10 @@ void CbmMvdSensorDigitizerTask::ProducePixelCharge(CbmMvdPoint* point)
 
       Float_t   latestHitCharge=pixelCharge->GetLatestHitCharge();
       Double_t  endOfBusyTime= fSensor->ComputeEndOfBusyTime(fEventTime + point->GetTime(), latestHitCharge, pixelCharge->GetY());
-      if (endOfBusyTime > pixelCharge->GetEndOfBusyTime()) {pixel->SetEndOfBusyTime(endOfBusyTime);}
+      LOG(debug) << "CbmMvdSensorDigitizerTask::ProducePixelCharge() - latestHitCharge =  "<< latestHitCharge;
+      LOG(debug) << "CbmMvdSensorDigitizerTask::ProducePixelCharge() - MCTime =  "<< fEventTime + point->GetTime();
+      LOG(debug) << "CbmMvdSensorDigitizerTask::ProducePixelCharge() - EndOfBusyTime =  "<< endOfBusyTime;
+      if (endOfBusyTime > pixelCharge->GetEndOfBusyTime()) {pixelCharge->SetEndOfBusyTime(endOfBusyTime);}
 
       /* Next, the pixelChargeObject is combined with a time information on the endOfBusyTime of the pixelChargeObject.
        * This end of busy is reached once the related channel is ready for receiving new hit information.
@@ -1143,7 +1091,7 @@ void CbmMvdSensorDigitizerTask::ProducePixelCharge(CbmMvdPoint* point)
        */
 
 
-*/
+
     }
     else {
       LOG(warning) << "Warning working on broken pixel ";
diff --git a/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.h b/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.h
index 3c0396a908..e6e813fc1e 100644
--- a/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.h
+++ b/sim/detectors/mvd/plugins/tasks/CbmMvdSensorDigitizerTask.h
@@ -77,13 +77,13 @@ public:
   void ProduceNoise();
   Bool_t GetSignalAboveThreshold(CbmMvdPixelCharge* myPixel, Double_t readoutTime);
   Int_t GetPixelCharge(CbmMvdPixelCharge* myPixel, Double_t readoutTime);
-/*
+
   void ProduceDigis();
   void CleanPixelChargeList();
   // Bool_t  GetSignalAboveThreshold (CbmMvdPixelCharge* myPixel, Double_t readoutTime);
-  Int_t GetPixelCharge(CbmMvdPixelCharge* myPixel, Double_t readoutTime);
+  //Int_t GetPixelCharge(CbmMvdPixelCharge* myPixel, Double_t readoutTime);
   Int_t CheckForHit(CbmMvdPixelCharge* pixel);
-*/
+
 
   void SetProduceNoise() { fproduceNoise = kTRUE; };
 
-- 
GitLab