From 98d1d1d5cfb5364be2217187f775f76b5c916cb0 Mon Sep 17 00:00:00 2001 From: ehrlich-uva Date: Thu, 12 Nov 2026 14:37:49 -0600 Subject: [PATCH 1/2] Increased speed for CRV simulation --- CRVResponse/inc/MakeCrvPhotons.hh | 8 +- CRVResponse/inc/MakeCrvSiPMCharges.hh | 23 ++- CRVResponse/src/CrvPhotonGenerator_module.cc | 6 +- .../src/CrvSiPMChargeGenerator_module.cc | 34 ++-- CRVResponse/src/MakeCrvPhotons.cc | 150 +++++++++++------- CRVResponse/src/MakeCrvSiPMCharges.cc | 129 ++++++++------- 6 files changed, 208 insertions(+), 142 deletions(-) diff --git a/CRVResponse/inc/MakeCrvPhotons.hh b/CRVResponse/inc/MakeCrvPhotons.hh index 42c9fc8de4..4b49d08ebf 100644 --- a/CRVResponse/inc/MakeCrvPhotons.hh +++ b/CRVResponse/inc/MakeCrvPhotons.hh @@ -94,10 +94,10 @@ class MakeCrvPhotons public: static const int _nSiPMs=4; - MakeCrvPhotons(CLHEP::RandFlat &randFlat, CLHEP::RandGaussQ &randGaussQ, CLHEP::RandPoissonQ &randPoissonQ) : - _randFlat(randFlat), _randGaussQ(randGaussQ), _randPoissonQ(randPoissonQ) + MakeCrvPhotons(CLHEP::RandFlat &randFlat, CLHEP::RandGaussQ &randGaussQ, CLHEP::RandPoissonQ &randPoissonQ, CLHEP::RandBinomial &randBinomial) : + _randFlat(randFlat), _randGaussQ(randGaussQ), _randPoissonQ(randPoissonQ), _randBinomial(randBinomial) { - _scintillationYield=39400; + _scintillationYield=0; for(int i=0; i<_nSiPMs; ++i) _photonYieldDeviation[i]=1.0; } @@ -113,6 +113,7 @@ class MakeCrvPhotons double visibleEnergyDeposited, double trueStepLength, int reflector=0); + void ProcessPhotons(const LookupBin *theBin, int nPhotons, double photonStartTime, int SiPM, int reflector); int GetNumberOfPhotons(int SiPM); const std::vector &GetArrivalTimes(int SiPM); void SetScintillationYield(double yield) {_scintillationYield=yield;} @@ -135,6 +136,7 @@ class MakeCrvPhotons CLHEP::RandFlat &_randFlat; CLHEP::RandGaussQ &_randGaussQ; CLHEP::RandPoissonQ &_randPoissonQ; + CLHEP::RandBinomial &_randBinomial; bool IsInsideScintillator(const CLHEP::Hep3Vector &p); bool IsInsideFiber(const CLHEP::Hep3Vector &p, const CLHEP::Hep3Vector &dir, double &r, double &phi); diff --git a/CRVResponse/inc/MakeCrvSiPMCharges.hh b/CRVResponse/inc/MakeCrvSiPMCharges.hh index e9d1ab03bf..e35eabf2d4 100644 --- a/CRVResponse/inc/MakeCrvSiPMCharges.hh +++ b/CRVResponse/inc/MakeCrvSiPMCharges.hh @@ -7,8 +7,7 @@ Based on Paul Rubinov's C# code #define MakeCrvSiPMCharges_hh #include -#include -#include +#include #include #include #include "CLHEP/Random/Randomize.h" @@ -21,9 +20,11 @@ namespace mu2eCrv struct Pixel { + bool _inactive; bool _discharged; double _t; //time of last discharge (if _discharged is true), or 0 (if _discharged is false) - Pixel() : _discharged(false), _t(0) {} + long _counter; //see explanation below. old counter values count as dischared + Pixel() : _inactive(false), _discharged(false), _t(0), _counter(0) {} }; struct SiPMresponse @@ -45,10 +46,6 @@ namespace mu2eCrv bool _darkNoise; //this charge is dark noise and was not created by an "outside photon" ScheduledCharge(const std::pair &pixelId, double time, size_t photonIndex, bool darkNoise) : _pixelId(pixelId), _time(time), _photonIndex(photonIndex), _darkNoise(darkNoise) {} - bool operator<(const ScheduledCharge &r) const - { - return _time < r._time; - }; private: ScheduledCharge(); }; @@ -76,15 +73,16 @@ namespace mu2eCrv private: ProbabilitiesStruct _probabilities; - std::vector > _inactivePixels; - std::map,Pixel> _pixels; - std::multiset _scheduledCharges; + long _counter{0}; //the value of this counter gets increased for every call to Simulate() and pixel discharges get this number attached. + //when encountering a pixel with an old counter value, it indicates that it is from a previous Simulate() + //and can be considered fully charged. this removes the need to reset all pixels after every event. + std::vector _pixels; //the pixel index corresponds to x*_nPixelsY+y + std::vector _scheduledCharges; + size_t _currentChargeIndex{0}; - std::vector > FindCrossTalkPixelIds(const std::pair &pixelId); std::pair FindThermalNoisePixelId(); std::pair FindFiberPhotonsPixelId(); - bool IsInactivePixelId(const std::pair &pixelId); double GetAvalancheProbability(double v); double GenerateAvalanche(Pixel &pixel, const std::pair &pixelId, double time, size_t photonIndex, bool darkNoise); @@ -94,6 +92,7 @@ namespace mu2eCrv CLHEP::RandFlat &_randFlat; CLHEP::RandPoissonQ &_randPoissonQ; double _avalancheProbFullyChargedPixel; + double _crossTalkProbabilitySinglePixel; TFile *_photonMapFile; TH2F *_photonMap; diff --git a/CRVResponse/src/CrvPhotonGenerator_module.cc b/CRVResponse/src/CrvPhotonGenerator_module.cc index e21dd1c8f3..5a1cfeae49 100644 --- a/CRVResponse/src/CrvPhotonGenerator_module.cc +++ b/CRVResponse/src/CrvPhotonGenerator_module.cc @@ -149,6 +149,7 @@ namespace mu2e CLHEP::RandFlat _randFlat; CLHEP::RandGaussQ _randGaussQ; CLHEP::RandPoissonQ _randPoissonQ; + CLHEP::RandBinomial _randBinomial; }; CrvPhotonGenerator::CrvPhotonGenerator(const Parameters& conf) : @@ -173,7 +174,8 @@ namespace mu2e _engine{createEngine(art::ServiceHandle()->getSeed())}, _randFlat(_engine), _randGaussQ(_engine), - _randPoissonQ(_engine) + _randPoissonQ(_engine), + _randBinomial(_engine) { //if(_moduleLabels.size()==0) throw std::logic_error("ERROR: a list of crvSteps module labels needs to be provided"); if(_moduleLabels.size()!=_processNames.size()) throw std::logic_error("ERROR: mismatch between specified selectors (crvStepModuleLabels/crvStepProcessNames)"); @@ -211,7 +213,7 @@ namespace mu2e } if(tableLoaded) continue; - _makeCrvPhotons.emplace_back(boost::shared_ptr(new mu2eCrv::MakeCrvPhotons(_randFlat, _randGaussQ, _randPoissonQ))); + _makeCrvPhotons.emplace_back(boost::shared_ptr(new mu2eCrv::MakeCrvPhotons(_randFlat, _randGaussQ, _randPoissonQ, _randBinomial))); boost::shared_ptr &photonMaker=_makeCrvPhotons.back(); if(_localLookupTables) { diff --git a/CRVResponse/src/CrvSiPMChargeGenerator_module.cc b/CRVResponse/src/CrvSiPMChargeGenerator_module.cc index a94c39e10c..feceee4b47 100644 --- a/CRVResponse/src/CrvSiPMChargeGenerator_module.cc +++ b/CRVResponse/src/CrvSiPMChargeGenerator_module.cc @@ -30,6 +30,7 @@ #include "fhiclcpp/ParameterSet.h" #include "CLHEP/Units/GlobalSystemOfUnits.h" #include "CLHEP/Random/Randomize.h" +#include "messagefacility/MessageLogger/MessageLogger.h" #include #include @@ -194,6 +195,17 @@ namespace mu2e GeomHandle CRS; const std::vector > &counters = CRS->getAllCRSScintillatorBars(); + + //put all photon collections into a vector with indices corresponding to the channel number + //so that the photon collections can be found easily later in the code + std::vector photonsOfChannel(counters.size()*CRVId::nChanPerBar, crvPhotonsCollection->end()); + for(CrvPhotonsCollection::const_iterator p=crvPhotonsCollection->begin(); p!=crvPhotonsCollection->end(); ++p) + { + size_t channel = p->GetScintillatorBarIndex().asUint()*CRVId::nChanPerBar + p->GetSiPMNumber(); + if(photonsOfChannel.at(channel)==crvPhotonsCollection->end()) photonsOfChannel[channel]=p; //there haven't been photons for this channel yet (as it should be) + else mf::LogError("CrvSiPMChargeGenerator") << "Found more than one entry in the CrvPhotonsCollection for channel " << channel << "."; + } + std::vector >::const_iterator iter; for(iter=counters.begin(); iter!=counters.end(); iter++) { @@ -206,29 +218,25 @@ namespace mu2e //0 ... negative side //1 ... positive side + size_t channel = barIndex.asUint()*CRVId::nChanPerBar + SiPM; if(_useSipmStatusDB) { - size_t channel = barIndex.asUint()*CRVId::nChanPerBar + SiPM; std::bitset<16> status(sipmStatus.status(channel)); if(status.test(CRVStatus::Flags::notConnected) || status.test(CRVStatus::Flags::noData)) continue; //SiPM not connected (bit 0) or no data (bit 2) } //time wrapping happened in the photon generator std::vector > photonTimesNew; //pair of photon time and index in the original photon vector - CrvPhotonsCollection::const_iterator crvPhotons; //after this loop, it will point to the correct index in the photon collection, if barIndex and SiPM is found - //otherwise it will be crvPhotonsCollection->end() - for(crvPhotons=crvPhotonsCollection->begin(); crvPhotons!=crvPhotonsCollection->end(); crvPhotons++) + CrvPhotonsCollection::const_iterator crvPhotons=photonsOfChannel.at(channel); //will be crvPhotonsCollection->end(), if there were no photons at this channel + if(crvPhotons!=crvPhotonsCollection->end()) { - if(crvPhotons->GetScintillatorBarIndex()==barIndex && crvPhotons->GetSiPMNumber()==(int)SiPM) + const std::vector &photonTimes = crvPhotons->GetPhotons(); + photonTimesNew.reserve(photonTimes.size()); + for(size_t iphoton=0; iphoton &photonTimes = crvPhotons->GetPhotons(); - for(size_t iphoton=0; iphoton &v, const double &x, bool ¬Found) { - for(size_t i=1; i=x) return(i-1); + notFound=true; + return(-1); } - notFound=true; - return(-1); + return(std::lower_bound(v.begin()+1,v.end(),x)-v.begin()-1); } int LookupBinDefinitions::findScintillatorScintillationBin(double x, double y, double z) { @@ -347,10 +347,14 @@ void MakeCrvPhotons::MakePhotons(const CLHEP::Hep3Vector &stepStartTmp, //they int nPhotonsCerenkovInScintillatorPerStep = GetNumberOfPhotonsFromAverage(avgNPhotonsCerenkovInScintillator,nSteps); int nPhotonsCerenkovInFiberPerStep = GetNumberOfPhotonsFromAverage(avgNPhotonsCerenkovInFiber,nSteps); + //first find all bin numbers, so that repeated bin numbers can be merged + std::vector binNumbers0, binNumbers1, binNumbers2; + binNumbers0.reserve(nSteps); + binNumbers1.reserve(nSteps); + binNumbers2.reserve(nSteps); for(int step=0; step=0) - { - scintillationBin = &_bins[0][binNumberS]; //lookup table number for scintillation in scintillator is 0 - nPhotonsScintillation = nPhotonsScintillationPerStep; - } - int binNumberC=_LBD.findScintillatorCerenkovBin(fabs(p.x()),p.y(),p.z(),beta); //use only positive x values due to symmetry in x - if(binNumberC>=0) - { - cerenkovBin = &_bins[1][binNumberC]; //lookup table number for cerenkov in scintillator is 1 - nPhotonsCerenkov = nPhotonsCerenkovInScintillatorPerStep; - } + binNumber0=_LBD.findScintillatorScintillationBin(fabs(p.x()),p.y(),p.z()); //use only positive x values due to symmetry in x + binNumber1=_LBD.findScintillatorCerenkovBin(fabs(p.x()),p.y(),p.z(),beta); //use only positive x values due to symmetry in x } else if(isInFiber) { - int binNumber=_LBD.findFiberCerenkovBin(beta,theta,phi,r,p.z()); - if(binNumber>=0) - { - cerenkovBin = &_bins[2][binNumber]; //lookup table number for cerenkov in fiber is 2 - nPhotonsCerenkov = nPhotonsCerenkovInFiberPerStep; - } + binNumber2=_LBD.findFiberCerenkovBin(beta,theta,phi,r,p.z()); } + binNumbers0.push_back(binNumber0); + binNumbers1.push_back(binNumber1); + binNumbers2.push_back(binNumber2); + } + + for(int step=0; steparrivalProbability; - probability*=_photonYieldDeviation[SiPM]; //channel-specific deviation from nominal, e.g. due to scintillator variations or SiPM misalignments - if(_randFlat.fire()<=probability) //a photon arrives at the SiPM --> calculate arrival time - { - //start time of photons - double arrivalTime = t; - - //add fiber decay times depending on the number of emissions - int nEmissions = GetRandomFiberEmissions(theBin); - for(int iEmission=0; iEmission=0) ProcessPhotons(&_bins[0][binNumber0], nPhotonsScintillationPerStep*repeatedBins, photonStartTime, SiPM, reflector); + if(binNumber1>=0) ProcessPhotons(&_bins[1][binNumber1], nPhotonsCerenkovInScintillatorPerStep*repeatedBins, photonStartTime, SiPM, reflector); + if(binNumber2>=0) ProcessPhotons(&_bins[2][binNumber2], nPhotonsCerenkovInFiberPerStep*repeatedBins, photonStartTime, SiPM, reflector); }//loop over all steps along the track }//loop over all SiPMs } +void MakeCrvPhotons::ProcessPhotons(const LookupBin *theBin, int nPhotons, double photonStartTime, int SiPM, int reflector) +{ + if(theBin==NULL || nPhotons<=0) return; + + //photon arrival probability at SiPM + double probability = theBin->arrivalProbability; + probability*=_photonYieldDeviation[SiPM]; //channel-specific deviation from nominal, e.g. due to scintillator variations or SiPM misalignments + + //number of photons arriving at the SiPM - calculated from a binomial distribution + int nPhotonsArrived=0; + //special CLHEP::RandBinomial cases: probability equal to 0 or 1 results in -1. (also when nPhotons equal to 0, but this case is checked above.) + if(probability>=1.0) nPhotonsArrived=nPhotons; + else if(probability>0.0) + { + //CLHEP::RandBinomial returns 0 for n*p<~0.01 and returns values that are too low up to n*p~0.03. + //So it should be used only for large n*p, where it returns the correct results and is faster than the inversion. + if(nPhotons*probability>15.0) nPhotonsArrived=static_cast(_randBinomial.fire(nPhotons,probability)); + else //inverse transform sampling. takes more time for large n*p + { + double logq = std::log1p(-probability); + double pk = std::exp(nPhotons*logq); //P(0)=q^n //the n*p>15.0 cut prevents this from ever being zero (which could happen for very negative arguments) + double cdf = pk; //if pk was 0, the while loop wouldn't be entered + double r = probability/(1.0-probability); //(to prevent it from getting stuck, because pk would remain at 0 in the loop). + double u = _randFlat.fire(); + while(u>cdf && nPhotonsArrived0.0) + { + pk *= r*(nPhotons-nPhotonsArrived)/(nPhotonsArrived+1.0); //P(k+1)=P(k)*(n-k)/(k+1)*p/q + cdf += pk; + ++nPhotonsArrived; + } + } + } + + //calculate arrival time for each photon + for(long iPhoton=0; iPhoton=_LC.halfThickness) return false; diff --git a/CRVResponse/src/MakeCrvSiPMCharges.cc b/CRVResponse/src/MakeCrvSiPMCharges.cc index 7e0069a9f1..268e09ca6d 100644 --- a/CRVResponse/src/MakeCrvSiPMCharges.cc +++ b/CRVResponse/src/MakeCrvSiPMCharges.cc @@ -24,16 +24,6 @@ double MakeCrvSiPMCharges::GetAvalancheProbability(double v) return avalancheProbability; } -std::vector > MakeCrvSiPMCharges::FindCrossTalkPixelIds(const std::pair &pixelId) -{ - std::vector > toReturn; - if(pixelId.first>0) toReturn.push_back(std::pair(pixelId.first-1,pixelId.second)); - if(pixelId.first+1<_nPixelsX) toReturn.push_back(std::pair(pixelId.first+1,pixelId.second)); - if(pixelId.second>0) toReturn.push_back(std::pair(pixelId.first, pixelId.second-1)); - if(pixelId.second+1<_nPixelsY) toReturn.push_back(std::pair(pixelId.first, pixelId.second+1)); - return toReturn; -} - std::pair MakeCrvSiPMCharges::FindThermalNoisePixelId() { int x=_randFlat.fire(_nPixelsX); @@ -48,15 +38,6 @@ std::pair MakeCrvSiPMCharges::FindFiberPhotonsPixelId() return std::pair(static_cast(x),static_cast(y)); } -bool MakeCrvSiPMCharges::IsInactivePixelId(const std::pair &pixelId) -{ - for(size_t i=0; i<_inactivePixels.size(); i++) - { - if(pixelId==_inactivePixels[i]) return true; - } - return false; -} - double MakeCrvSiPMCharges::GenerateAvalanche(Pixel &pixel, const std::pair &pixelId, double time, size_t photonIndex, bool darkNoise) { double v = GetVoltage(pixel,time); @@ -72,41 +53,49 @@ double MakeCrvSiPMCharges::GenerateAvalanche(Pixel &pixel, const std::pair > crossTalkPixelIds = FindCrossTalkPixelIds(pixelId); - double probabilityNoCrossTalk = 1.0-_probabilities._crossTalkProb; //prob that cross talk does not occur = 1 - prob that cross talk occurs - double probabilityNoCrossTalkSinglePixel = pow(probabilityNoCrossTalk,1.0/4.0); //prob that cross talk does not occur at any of the 4 neighboring pixels - //=pow(prob that cross talk does not occur at a pixel,4) - double crossTalkProbabilitySinglePixel = 1.0-probabilityNoCrossTalkSinglePixel; - - //the crossTalkProbabilitySinglePixel is the measured probability (based on the _crossTalkProb from the Hamamatsu specs), - //however the actually production probability is higher, but is reduced by the avalanche probability - //(measured probability = production probability * avalanche probability) - //the production probability is needed here - crossTalkProbabilitySinglePixel /= _avalancheProbFullyChargedPixel; - for(size_t i=0; i0) + { + if(_randFlat.fire() < _crossTalkProbabilitySinglePixel) + _scheduledCharges.emplace(_scheduledCharges.begin()+_currentChargeIndex,std::pair(pixelId.first-1,pixelId.second),time,photonIndex,darkNoise); + } + if(pixelId.first+1<_nPixelsX) + { + if(_randFlat.fire() < _crossTalkProbabilitySinglePixel) + _scheduledCharges.emplace(_scheduledCharges.begin()+_currentChargeIndex,std::pair(pixelId.first+1,pixelId.second),time,photonIndex,darkNoise); + } + if(pixelId.second>0) { - if(_randFlat.fire() < crossTalkProbabilitySinglePixel) - { - _scheduledCharges.emplace_hint(_scheduledCharges.begin(),crossTalkPixelIds[i],time,photonIndex,darkNoise); - } + if(_randFlat.fire() < _crossTalkProbabilitySinglePixel) + _scheduledCharges.emplace(_scheduledCharges.begin()+_currentChargeIndex,std::pair(pixelId.first,pixelId.second-1),time,photonIndex,darkNoise); + } + if(pixelId.second+1<_nPixelsY) + { + if(_randFlat.fire() < _crossTalkProbabilitySinglePixel) + _scheduledCharges.emplace(_scheduledCharges.begin()+_currentChargeIndex,std::pair(pixelId.first,pixelId.second+1),time,photonIndex,darkNoise); } //the pixel's overvoltage becomes 0, i.e. the pixel's voltage gets reduced to the breakdown voltage //the time when this happens gets recorded in the pixel variable pixel._discharged=true; pixel._t=time; + pixel._counter=_counter; //explanation for _counter is in header file double outputCharge = _capacitance*v; //output charge = capacitance (of one pixel) * overvoltage //gain = outputCharge / elementary charge @@ -117,7 +106,8 @@ double MakeCrvSiPMCharges::GenerateAvalanche(Pixel &pixel, const std::pair > &photons, double startTime, double endTime) @@ -145,7 +153,8 @@ void MakeCrvSiPMCharges::FillQueue(const std::vector > for(size_t i=0; i pixelId = FindFiberPhotonsPixelId(); //only pixels at fiber - _scheduledCharges.emplace(pixelId, photons[i].first, photons[i].second, false); + if(pixelId.first<0 || pixelId.second<0 || pixelId.first>=_nPixelsX || pixelId.second>=_nPixelsY) throw std::logic_error("Used pixel outside of SiPM."); + _scheduledCharges.emplace_back(pixelId, photons[i].first, photons[i].second, false); } //schedule random thermal charges @@ -164,38 +173,44 @@ void MakeCrvSiPMCharges::FillQueue(const std::vector > { std::pair pixelId = FindThermalNoisePixelId(); //all pixels double time = startTime + timeWindow * _randFlat.fire(); - _scheduledCharges.emplace(pixelId, time, 0, true); + _scheduledCharges.emplace_back(pixelId, time, 0, true); } } void MakeCrvSiPMCharges::Simulate(const std::vector > &photons, //pair of photon time and index in the original photon vector std::vector &SiPMresponseVector, double startTime, double endTime) { - _pixels.clear(); + ++_counter; //see header file for explanation + _scheduledCharges.clear(); FillQueue(photons, startTime, endTime); + //sort the charges by time, all charges that get inserted later (cross-talk, after pulses) need to be inserted into the correct location + std::stable_sort(_scheduledCharges.begin(), _scheduledCharges.end(), + [](const ScheduledCharge& a, const ScheduledCharge& b) {return a._time < b._time;}); + + _currentChargeIndex=0; + while(1) { - std::multiset::iterator currentCharge = _scheduledCharges.begin(); - if(currentCharge==_scheduledCharges.end()) break; //no more scheduled charges + if(_currentChargeIndex>=_scheduledCharges.size()) break; //no more scheduled charges - std::pair pixelId = currentCharge->_pixelId; - double time = currentCharge->_time; - size_t photonIndex = currentCharge->_photonIndex; - bool darkNoise = currentCharge->_darkNoise; - _scheduledCharges.erase(currentCharge); + //find the first charge + const ScheduledCharge ¤tCharge = _scheduledCharges[_currentChargeIndex]; - if(IsInactivePixelId(pixelId)) continue; + std::pair pixelId = currentCharge._pixelId; + int pixelIndex = pixelId.first*_nPixelsY+pixelId.second; - if(time>endTime) continue; //this is relevant for afterpulses + double time = currentCharge._time; + size_t photonIndex = currentCharge._photonIndex; + bool darkNoise = currentCharge._darkNoise; + ++_currentChargeIndex; + + if(_pixels.at(pixelIndex)._inactive) continue; - //find pixel with pixelId, create a fully charged pixel if it doesn't exist - std::map,Pixel>::iterator p = _pixels.find(pixelId); - if(p==_pixels.end()) p=_pixels.emplace(pixelId, Pixel()).first; - // .first returns the iterator to the new pixel + if(time>endTime) continue; //this is relevant for afterpulses - Pixel &pixel = p->second; + Pixel &pixel = _pixels.at(pixelIndex); double outputCharge = GenerateAvalanche(pixel, pixelId, time, photonIndex, darkNoise); //the output charge (in Coulomb) of the pixel due to the avalanche double outputChargeInPEs = (outputCharge/_capacitance)/_overvoltage; //the output charge in units of single PEs of a fully charges pixel From 045c1cbef30eae512498694586d5b1c0aea6bb99 Mon Sep 17 00:00:00 2001 From: ehrlich-uva Date: Thu, 12 Nov 2026 17:05:42 -0600 Subject: [PATCH 2/2] small changes in comments and throw messages --- CRVResponse/inc/MakeCrvPhotons.hh | 2 +- CRVResponse/inc/MakeCrvSiPMCharges.hh | 2 +- CRVResponse/src/CrvSiPMChargeGenerator_module.cc | 2 +- CRVResponse/src/MakeCrvPhotons.cc | 2 +- CRVResponse/src/MakeCrvSiPMCharges.cc | 5 ++++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CRVResponse/inc/MakeCrvPhotons.hh b/CRVResponse/inc/MakeCrvPhotons.hh index 4b49d08ebf..164576ef5d 100644 --- a/CRVResponse/inc/MakeCrvPhotons.hh +++ b/CRVResponse/inc/MakeCrvPhotons.hh @@ -113,7 +113,6 @@ class MakeCrvPhotons double visibleEnergyDeposited, double trueStepLength, int reflector=0); - void ProcessPhotons(const LookupBin *theBin, int nPhotons, double photonStartTime, int SiPM, int reflector); int GetNumberOfPhotons(int SiPM); const std::vector &GetArrivalTimes(int SiPM); void SetScintillationYield(double yield) {_scintillationYield=yield;} @@ -138,6 +137,7 @@ class MakeCrvPhotons CLHEP::RandPoissonQ &_randPoissonQ; CLHEP::RandBinomial &_randBinomial; + void ProcessPhotons(const LookupBin *theBin, int nPhotons, double photonStartTime, int SiPM, int reflector); bool IsInsideScintillator(const CLHEP::Hep3Vector &p); bool IsInsideFiber(const CLHEP::Hep3Vector &p, const CLHEP::Hep3Vector &dir, double &r, double &phi); double GetRandomTime(const LookupBin *theBin); diff --git a/CRVResponse/inc/MakeCrvSiPMCharges.hh b/CRVResponse/inc/MakeCrvSiPMCharges.hh index e35eabf2d4..0f4820615d 100644 --- a/CRVResponse/inc/MakeCrvSiPMCharges.hh +++ b/CRVResponse/inc/MakeCrvSiPMCharges.hh @@ -23,7 +23,7 @@ namespace mu2eCrv bool _inactive; bool _discharged; double _t; //time of last discharge (if _discharged is true), or 0 (if _discharged is false) - long _counter; //see explanation below. old counter values count as dischared + long _counter; //see explanation below. old counter values count as fully recharged Pixel() : _inactive(false), _discharged(false), _t(0), _counter(0) {} }; diff --git a/CRVResponse/src/CrvSiPMChargeGenerator_module.cc b/CRVResponse/src/CrvSiPMChargeGenerator_module.cc index feceee4b47..f4f3386250 100644 --- a/CRVResponse/src/CrvSiPMChargeGenerator_module.cc +++ b/CRVResponse/src/CrvSiPMChargeGenerator_module.cc @@ -203,7 +203,7 @@ namespace mu2e { size_t channel = p->GetScintillatorBarIndex().asUint()*CRVId::nChanPerBar + p->GetSiPMNumber(); if(photonsOfChannel.at(channel)==crvPhotonsCollection->end()) photonsOfChannel[channel]=p; //there haven't been photons for this channel yet (as it should be) - else mf::LogError("CrvSiPMChargeGenerator") << "Found more than one entry in the CrvPhotonsCollection for channel " << channel << "."; + else throw cet::exception("CrvSiPMChargeGenerator") << "Found more than one entry in the CrvPhotonsCollection for channel " << channel << "."; } std::vector >::const_iterator iter; diff --git a/CRVResponse/src/MakeCrvPhotons.cc b/CRVResponse/src/MakeCrvPhotons.cc index 75b869beae..13c19e47de 100644 --- a/CRVResponse/src/MakeCrvPhotons.cc +++ b/CRVResponse/src/MakeCrvPhotons.cc @@ -424,7 +424,7 @@ void MakeCrvPhotons::ProcessPhotons(const LookupBin *theBin, int nPhotons, doubl if(probability>=1.0) nPhotonsArrived=nPhotons; else if(probability>0.0) { - //CLHEP::RandBinomial returns 0 for n*p<~0.01 and returns values that are too low up to n*p~0.03. + //CLHEP::RandBinomial returns values that are too low (or even zero) for small value of n*p. //So it should be used only for large n*p, where it returns the correct results and is faster than the inversion. if(nPhotons*probability>15.0) nPhotonsArrived=static_cast(_randBinomial.fire(nPhotons,probability)); else //inverse transform sampling. takes more time for large n*p diff --git a/CRVResponse/src/MakeCrvSiPMCharges.cc b/CRVResponse/src/MakeCrvSiPMCharges.cc index 268e09ca6d..c01a246602 100644 --- a/CRVResponse/src/MakeCrvSiPMCharges.cc +++ b/CRVResponse/src/MakeCrvSiPMCharges.cc @@ -5,6 +5,8 @@ Based on Paul Rubinov's C# code #include "Offline/CRVResponse/inc/MakeCrvSiPMCharges.hh" +#include "cetlib_except/exception.h" + #include #include #include @@ -153,7 +155,8 @@ void MakeCrvSiPMCharges::FillQueue(const std::vector > for(size_t i=0; i pixelId = FindFiberPhotonsPixelId(); //only pixels at fiber - if(pixelId.first<0 || pixelId.second<0 || pixelId.first>=_nPixelsX || pixelId.second>=_nPixelsY) throw std::logic_error("Used pixel outside of SiPM."); + if(pixelId.first<0 || pixelId.second<0 || pixelId.first>=_nPixelsX || pixelId.second>=_nPixelsY) + throw cet::exception("MakeCrvSiPMCharges") << "Used pixel outside of SiPM."; _scheduledCharges.emplace_back(pixelId, photons[i].first, photons[i].second, false); }