Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:30

0001 /* Copyright 2008-2010, Technische Universitaet Muenchen,
0002    Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch
0003 
0004    This file is part of GENFIT.
0005 
0006    GENFIT is free software: you can redistribute it and/or modify
0007    it under the terms of the GNU Lesser General Public License as published
0008    by the Free Software Foundation, either version 3 of the License, or
0009    (at your option) any later version.
0010 
0011    GENFIT is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014    GNU Lesser General Public License for more details.
0015 
0016    You should have received a copy of the GNU Lesser General Public License
0017    along with GENFIT.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 #include "StepLimits.h"
0021 #include "IO.h"
0022 
0023 #include <algorithm>
0024 #include <assert.h>
0025 #include <limits>
0026 
0027 
0028 namespace genfit {
0029 
0030 const double StepLimits::maxLimit_ = 99.E99;
0031 
0032 
0033 StepLimits& StepLimits::operator=(const StepLimits& other) {
0034   for (unsigned int i=1; i<ENUM_NR_ITEMS; ++i) {
0035     limits_[i] = other.limits_[i];
0036   }
0037 
0038   stepSign_ = other.stepSign_;
0039 
0040   return *this;
0041 }
0042 
0043 
0044 std::pair<StepLimitType, double> StepLimits::getLowestLimit(double margin) const {
0045 
0046   double lowest(maxLimit_);
0047   unsigned int iLowest(0);
0048 
0049   for (unsigned int i=1; i<ENUM_NR_ITEMS; ++i) {
0050 
0051     // lowest hard limit may exceed lowest soft limit by up to #margin
0052     if (i == int(stp_sMaxArg))
0053       lowest *= (1+margin);
0054 
0055     if (limits_[i] < lowest) {
0056       lowest = limits_[i];
0057       iLowest = i;
0058     }
0059   }
0060 
0061   return std::pair<StepLimitType, double>(static_cast<StepLimitType>(iLowest), lowest);
0062 }
0063 
0064 
0065 double StepLimits::getLowestLimitVal(double margin) const {
0066 
0067   double lowest(maxLimit_);
0068 
0069   for (unsigned int i=1; i<ENUM_NR_ITEMS; ++i) {
0070 
0071     // lowest hard limit may exceed lowest soft limit by up to #margin
0072     if (i == int(stp_sMaxArg))
0073       lowest *= (1+margin);
0074 
0075     if (limits_[i] < lowest) {
0076       lowest = limits_[i];
0077     }
0078   }
0079 
0080   return lowest;
0081 }
0082 
0083 
0084 void StepLimits::reduceLimit(StepLimitType type, double value) {
0085   assert (type != stp_noLimit);
0086   value = fabs(value);
0087 
0088   if (limits_[type] > value)
0089     limits_[type] = value;
0090 }
0091 
0092 
0093 void StepLimits::setStepSign(char signedVal) {
0094   if (signedVal < 0)
0095     stepSign_ = -1;
0096   else
0097     stepSign_ = 1;
0098 }
0099 
0100 void StepLimits::setStepSign(double signedVal) {
0101   if (signedVal < 0.)
0102     stepSign_ = -1;
0103   else
0104     stepSign_ = 1;
0105 }
0106 
0107 
0108 void StepLimits::reset() {
0109   for (unsigned int i=1; i<ENUM_NR_ITEMS; ++i) {
0110     limits_[i] = maxLimit_;
0111   }
0112   stepSign_ = 1;
0113 }
0114 
0115 
0116 void StepLimits::Print() {
0117   for (unsigned int i=0; i<ENUM_NR_ITEMS; ++i) {
0118     if (limits_[i] >= maxLimit_)
0119       continue;
0120 
0121     printOut << "   | " << limits_[i] << " cm due to ";
0122     switch (static_cast<StepLimitType>(i)) {
0123     case stp_noLimit:
0124       break;
0125     case stp_fieldCurv:
0126       printOut << "stp_fieldCurv (medium limit): stepsize limited by curvature and magnetic field inhomogenities";
0127       break;
0128     case stp_momLoss:
0129       printOut << "stp_momLoss (medium limit): stepsize limited by stepper because maximum momLoss is reached";
0130       break;
0131     case stp_sMax:
0132       printOut << "stp_sMax (medium limit): stepsize limited by SMax defined in #estimateStep()";
0133       break;
0134     case stp_sMaxArg:
0135       printOut << "stp_sMaxArg (hard limit): stepsize limited by argument maxStepArg passed to #estimateStep()";
0136       break;
0137     case stp_boundary:
0138       printOut << "stp_boundary (hard limit): stepsize limited by stepper because material boundary is encountered";
0139       break;
0140     case stp_plane:
0141       printOut << "stp_plane (hard limit):  stepsize limited because destination plane is reached";
0142       break;
0143     case ENUM_NR_ITEMS:
0144       break;
0145     }
0146     printOut << "\n";
0147   }
0148   printOut << "\n";
0149 }
0150 
0151 } /* End of namespace genfit */