diff --git a/sim/detectors/much/CbmMuchDigitizeGem.cxx b/sim/detectors/much/CbmMuchDigitizeGem.cxx index 853b8b923a91b55fe9f5bbdc57d073bc5a47fdfe..b537f78bef64801a3cdad6a9b7619607b20d0f21 100644 --- a/sim/detectors/much/CbmMuchDigitizeGem.cxx +++ b/sim/detectors/much/CbmMuchDigitizeGem.cxx @@ -1,6 +1,6 @@ /* Copyright (C) 2009-2021 St. Petersburg Polytechnic University, St. Petersburg SPDX-License-Identifier: GPL-3.0-only - Authors: Vikas Singhal, Ekata Nandy, Volker Friese, Evgeny Kryshen [committer] */ + Authors: Apar Agarwal, Vikas Singhal, Ekata Nandy, Volker Friese, Evgeny Kryshen [committer] */ /** CbmMuchDigitizeGem.cxx *@author Vikas Singhal <vikas@vecc.gov.in> @@ -1145,15 +1145,45 @@ Double_t CbmMuchDigitizeGem::GetNPrimaryElectronsPerCm(const CbmMuchPoint* point } // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- -Bool_t CbmMuchDigitizeGem::AddCharge(CbmMuchSectorRadial* s, UInt_t ne, Int_t /*iPoint*/, Double_t /*time*/, - Double_t /*driftTime*/, Double_t phi1, Double_t phi2) -{ - CbmMuchPadRadial* pad1 = s->GetPadByPhi(phi1); - if (!pad1) return kFALSE; - //assert(pad1); has to check if any pad address is NULL - CbmMuchPadRadial* pad2 = s->GetPadByPhi(phi2); - if (!pad2) return kFALSE; - //assert(pad2); has to check if any pad address is NULL +Bool_t CbmMuchDigitizeGem::AddCharge(CbmMuchSectorRadial *s, UInt_t ne, + Int_t /*iPoint*/, Double_t /*time*/, + Double_t /*driftTime*/, Double_t phi1, + Double_t phi2) { + CbmMuchPadRadial *pad1 = s->GetPadByPhi(phi1); + if (!pad1) + pad1 = s->GetPadByPhi( + (phi1 + phi2) / 2.0); // This condition helps us deal with boundary pads + else // Special case if pad size is smaller than spot radius + { + for (Double_t phi = phi1; phi < (phi1 + phi2) / 2.0; + phi += 0.1) // This may potentially slow down the code + { + pad1 = s->GetPadByPhi(phi); + if (pad1) + break; + } + } + if (!pad1) + return kFALSE; + // assert(pad1); has to check if any pad address is NULL + CbmMuchPadRadial *pad2 = s->GetPadByPhi(phi2); + if (!pad2) + pad2 = s->GetPadByPhi( + (phi1 + phi2) / 2.0); // This condition helps us deal with boundary pads + else // Special case if pad size is smaller than spot radius + { + for (Double_t phi = phi2; phi > (phi1 + phi2) / 2.0; + phi -= 0.1) // This may potentially slow down the code + { + pad2 = s->GetPadByPhi(phi); + if (pad2) + break; + } + } + + if (!pad2) + return kFALSE; + // assert(pad2); has to check if any pad address is NULL if (pad1 == pad2) { UInt_t address = pad1->GetAddress(); //Finding that if for the same address if already charge stored then add the charge.