#include <TrackingTools/GsfTracking/interface/GsfBetheHeitlerUpdator.h>
Public Types | |
enum | CorrectionFlag { NoCorrection = 0, MeanCorrection = 1, FullCorrection = 2 } |
Public Member Functions | |
virtual GsfBetheHeitlerUpdator * | clone () const |
GsfBetheHeitlerUpdator (const std::string fileName, const int correctionFlag) | |
constructor with explicit filename and correction flag | |
Protected Member Functions | |
virtual bool | newArguments (const TrajectoryStateOnSurface &, const PropagationDirection) const |
check of arguments for use with cached values | |
virtual void | storeArguments (const TrajectoryStateOnSurface &, const PropagationDirection) const |
storage of arguments for later use of | |
Private Types | |
typedef std::vector< Triplet < double, double, double > > | GSContainer |
Private Member Functions | |
double | BetheHeitlerMean (const double rl) const |
First moment of the Bethe-Heitler distribution (in z=E/E0). | |
double | BetheHeitlerVariance (const double rl) const |
Second moment of the Bethe-Heitler distribution (in z=E/E0). | |
virtual void | compute (const TrajectoryStateOnSurface &, const PropagationDirection) const |
Computation: generates vectors of weights, means and standard deviations. | |
double | correctedFirstMean (const double, const GSContainer &) const |
Correction for mean of component 1. | |
double | correctedFirstVar (const double, const GSContainer &) const |
Correction for variance of component 1. | |
void | correctWeights (GSContainer &) const |
Correction for weight of component 1. | |
void | getMixtureParameters (const double, GSContainer &) const |
Filling of mixture (in terms of z=E/E0). | |
double | logisticFunction (const double x) const |
Logistic function (needed for transformation of weight and mean). | |
void | readParameters (const std::string) |
Read parametrization from file. | |
Polynomial | readPolynomial (std::ifstream &, const int) |
Read coefficients of one polynomial from file. | |
Private Attributes | |
int | theCorrectionFlag |
parametrisation of variance for each component | |
float | theLastDz |
correction of 1st or 1st&2nd moments | |
float | theLastP |
PropagationDirection | theLastPropDir |
float | theLastRadLength |
int | theNrComponents |
std::vector< Polynomial > | thePolyMeans |
parametrisation of weight for each component | |
std::vector< Polynomial > | thePolyVars |
parametrisation of mean for each component | |
std::vector< Polynomial > | thePolyWeights |
values to be transformed by logistic / exp. function? | |
int | theTransformationCode |
number of components used for parameterisation | |
Classes | |
class | Polynomial |
Helper class for construction & evaluation of a polynomial. More... |
The weights and parameters of the Gaussians as a function of x/X0 are parametrized as polynomials. The coefficients of these polynomials are read from a file at construction time.
Definition at line 19 of file GsfBetheHeitlerUpdator.h.
typedef std::vector< Triplet<double,double,double> > GsfBetheHeitlerUpdator::GSContainer [private] |
Definition at line 59 of file GsfBetheHeitlerUpdator.h.
Definition at line 45 of file GsfBetheHeitlerUpdator.h.
00045 { NoCorrection=0, MeanCorrection=1, FullCorrection=2 };
GsfBetheHeitlerUpdator::GsfBetheHeitlerUpdator | ( | const std::string | fileName, | |
const int | correctionFlag | |||
) |
constructor with explicit filename and correction flag
Definition at line 11 of file GsfBetheHeitlerUpdator.cc.
References readParameters(), and theCorrectionFlag.
Referenced by clone().
00012 : 00013 // const CorrectionFlag correctionFlag) : 00014 GsfMaterialEffectsUpdator(0.000511), 00015 theNrComponents(0), 00016 theCorrectionFlag(correctionFlag), 00017 theLastDz(0.), 00018 theLastP(-1.), 00019 theLastPropDir(alongMomentum), 00020 theLastRadLength(-1.) 00021 { 00022 if ( theCorrectionFlag==1 ) 00023 edm::LogInfo("GsfBetheHeitlerUpdator") << "1st moment of mixture will be corrected"; 00024 if ( theCorrectionFlag>=2 ) 00025 edm::LogInfo("GsfBetheHeitlerUpdator") 00026 << "1st and 2nd moments of mixture will be corrected"; 00027 00028 readParameters(fileName); 00029 }
double GsfBetheHeitlerUpdator::BetheHeitlerMean | ( | const double | rl | ) | const [inline, private] |
First moment of the Bethe-Heitler distribution (in z=E/E0).
Definition at line 71 of file GsfBetheHeitlerUpdator.h.
References funct::exp().
Referenced by correctedFirstMean(), and correctedFirstVar().
00072 { 00073 return exp(-rl); 00074 }
double GsfBetheHeitlerUpdator::BetheHeitlerVariance | ( | const double | rl | ) | const [inline, private] |
Second moment of the Bethe-Heitler distribution (in z=E/E0).
Definition at line 76 of file GsfBetheHeitlerUpdator.h.
References funct::exp(), and funct::log().
Referenced by correctedFirstVar().
virtual GsfBetheHeitlerUpdator* GsfBetheHeitlerUpdator::clone | ( | void | ) | const [inline, virtual] |
Implements GsfMaterialEffectsUpdator.
Definition at line 48 of file GsfBetheHeitlerUpdator.h.
References GsfBetheHeitlerUpdator().
00049 { 00050 return new GsfBetheHeitlerUpdator(*this); 00051 }
void GsfBetheHeitlerUpdator::compute | ( | const TrajectoryStateOnSurface & | TSoS, | |
const | PropagationDirection | |||
) | const [private, virtual] |
Computation: generates vectors of weights, means and standard deviations.
Implements GsfMaterialEffectsUpdator.
Definition at line 62 of file GsfBetheHeitlerUpdator.cc.
References alongMomentum, correctedFirstMean(), correctedFirstVar(), correctWeights(), HLT_VtxMuL3::errors, f, first, getMixtureParameters(), i, TrajectoryStateOnSurface::localMomentum(), PV3DBase< T, PVType, FrameType >::mag(), Surface::mediumProperties(), p, MediumProperties::radLen(), edm::second(), storeArguments(), TrajectoryStateOnSurface::surface(), theCorrectionFlag, GsfMaterialEffectsUpdator::theDeltaCovs, GsfMaterialEffectsUpdator::theDeltaPs, theNrComponents, GsfMaterialEffectsUpdator::theWeights, and PV3DBase< T, PVType, FrameType >::z().
00064 { 00065 // 00066 // clear cache 00067 // 00068 theWeights.clear(); 00069 theDeltaPs.clear(); 00070 theDeltaCovs.clear(); 00071 // 00072 // Get surface and check presence of medium properties 00073 // 00074 const Surface& surface = TSoS.surface(); 00075 // 00076 // calculate components: first check associated material constants 00077 // 00078 double rl(0.); 00079 double p(0.); 00080 if ( surface.mediumProperties() ) { 00081 LocalVector pvec = TSoS.localMomentum(); 00082 p = pvec.mag(); 00083 rl = surface.mediumProperties()->radLen()/fabs(pvec.z())*p; 00084 } 00085 // 00086 // produce multi-state only in case of x/X0>0 00087 // 00088 if ( rl>0.0001 ) { 00089 // 00090 // limit x/x0 to valid range for parametrisation 00091 // should be done in a more elegant way ... 00092 // 00093 if ( rl<0.01 ) rl = 0.01; 00094 if ( rl>0.20 ) rl = 0.20; 00095 00096 GSContainer mixture; 00097 getMixtureParameters(rl,mixture); 00098 correctWeights(mixture); 00099 if ( theCorrectionFlag>=1 ) 00100 mixture[0].second = correctedFirstMean(rl,mixture); 00101 if ( theCorrectionFlag>=2 ) 00102 mixture[0].third = correctedFirstVar(rl,mixture); 00103 00104 for ( int i=0; i<theNrComponents; i++ ) { 00105 double varPinv; 00106 theWeights.push_back(mixture[i].first); 00107 if ( propDir==alongMomentum ) { 00108 // 00109 // for forward propagation: calculate in p (linear in 1/z=p_inside/p_outside), 00110 // then convert sig(p) to sig(1/p). 00111 // 00112 theDeltaPs.push_back(p*(mixture[i].second-1)); 00113 // double f = 1./p/mixture[i].second/mixture[i].second; 00114 // patch to ensure consistency between for- and backward propagation 00115 double f = 1./p/mixture[i].second; 00116 varPinv = f*f*mixture[i].third; 00117 } 00118 else { 00119 // 00120 // for backward propagation: delta(1/p) is linear in z=p_outside/p_inside 00121 // convert to obtain equivalent delta(p) 00122 // 00123 theDeltaPs.push_back(p*(1/mixture[i].second-1)); 00124 varPinv = mixture[i].third/p/p; 00125 } 00126 AlgebraicSymMatrix55 errors; 00127 errors(0,0) = varPinv; 00128 theDeltaCovs.push_back(errors); 00129 } 00130 } 00131 else { 00132 theWeights.push_back(1.); 00133 theDeltaPs.push_back(0.); 00134 theDeltaCovs.push_back(AlgebraicSymMatrix55()); 00135 } 00136 // 00137 // Save arguments to avoid duplication of computation 00138 // 00139 storeArguments(TSoS,propDir); 00140 }
double GsfBetheHeitlerUpdator::correctedFirstMean | ( | const | double, | |
const GSContainer & | mixture | |||
) | const [private] |
Correction for mean of component 1.
Definition at line 190 of file GsfBetheHeitlerUpdator.cc.
References BetheHeitlerMean(), i, max, mean(), and min.
Referenced by compute().
00192 { 00193 if ( mixture.empty() ) return 0.; 00194 // 00195 // calculate difference true mean - weighted sum 00196 // 00197 double mean = BetheHeitlerMean(rl); 00198 for ( GSContainer::const_iterator i=mixture.begin()+1; 00199 i!=mixture.end(); i++ ) mean -= (*i).first*(*i).second; 00200 // 00201 // return corrected mean for first component 00202 // 00203 return std::max(std::min(mean/mixture[0].first,1.),0.); 00204 }
double GsfBetheHeitlerUpdator::correctedFirstVar | ( | const | double, | |
const GSContainer & | mixture | |||
) | const [private] |
Correction for variance of component 1.
Definition at line 209 of file GsfBetheHeitlerUpdator.cc.
References BetheHeitlerMean(), BetheHeitlerVariance(), first, i, and max.
Referenced by compute().
00211 { 00212 if ( mixture.empty() ) return 0.; 00213 // 00214 // calculate difference true variance - weighted sum 00215 // 00216 double var = BetheHeitlerVariance(rl) + 00217 BetheHeitlerMean(rl)*BetheHeitlerMean(rl) - 00218 mixture[0].first*mixture[0].second*mixture[0].second; 00219 for ( GSContainer::const_iterator i=mixture.begin()+1; 00220 i!=mixture.end(); i++ ) 00221 var -= (*i).first*((*i).second*(*i).second+(*i).third); 00222 // 00223 // return corrected variance for first component 00224 // 00225 return std::max(var/mixture[0].first,0.); 00226 }
void GsfBetheHeitlerUpdator::correctWeights | ( | GSContainer & | mixture | ) | const [private] |
Correction for weight of component 1.
Definition at line 171 of file GsfBetheHeitlerUpdator.cc.
References i.
Referenced by compute().
00172 { 00173 if ( mixture.empty() ) return; 00174 // 00175 // get sum of weights 00176 // 00177 double wsum(0); 00178 for ( GSContainer::const_iterator i=mixture.begin(); 00179 i!=mixture.end(); i++ ) wsum += (*i).first; 00180 // 00181 // rescale to obtain 1 00182 // 00183 for ( GSContainer::iterator i=mixture.begin(); 00184 i!=mixture.end(); i++ ) (*i).first /= wsum; 00185 }
void GsfBetheHeitlerUpdator::getMixtureParameters | ( | const | double, | |
GSContainer & | mixture | |||
) | const [private] |
Filling of mixture (in terms of z=E/E0).
Definition at line 145 of file GsfBetheHeitlerUpdator.cc.
References funct::exp(), i, logisticFunction(), theNrComponents, thePolyMeans, thePolyVars, thePolyWeights, theTransformationCode, weight, and z.
Referenced by compute().
00147 { 00148 mixture.clear(); 00149 mixture.reserve(theNrComponents); 00150 00151 for ( int i=0; i<theNrComponents; i++ ) { 00152 00153 double weight = thePolyWeights[i](rl); 00154 if ( theTransformationCode ) weight = logisticFunction(weight); 00155 00156 double z = thePolyMeans[i](rl); 00157 if ( theTransformationCode ) z = logisticFunction(z); 00158 00159 double vz = thePolyVars[i](rl); 00160 if ( theTransformationCode ) vz = exp(vz); 00161 else vz = vz*vz; 00162 00163 mixture.push_back(Triplet<double,double,double>(weight,z,vz)); 00164 } 00165 }
double GsfBetheHeitlerUpdator::logisticFunction | ( | const double | x | ) | const [inline, private] |
Logistic function (needed for transformation of weight and mean).
Definition at line 69 of file GsfBetheHeitlerUpdator.h.
References funct::exp().
Referenced by getMixtureParameters().
bool GsfBetheHeitlerUpdator::newArguments | ( | const TrajectoryStateOnSurface & | TSoS, | |
const | PropagationDirection | |||
) | const [protected, virtual] |
check of arguments for use with cached values
Reimplemented from GsfMaterialEffectsUpdator.
Definition at line 232 of file GsfBetheHeitlerUpdator.cc.
References TrajectoryStateOnSurface::localMomentum(), PV3DBase< T, PVType, FrameType >::mag(), Surface::mediumProperties(), MediumProperties::radLen(), TrajectoryStateOnSurface::surface(), theLastDz, theLastP, theLastPropDir, theLastRadLength, Vector3DBase< T, FrameTag >::unit(), and PV3DBase< T, PVType, FrameType >::z().
00233 { 00234 return TSoS.localMomentum().unit().z()!=theLastDz || 00235 TSoS.localMomentum().mag()!=theLastP || propDir!=theLastPropDir || 00236 TSoS.surface().mediumProperties()->radLen()!=theLastRadLength; 00237 }
void GsfBetheHeitlerUpdator::readParameters | ( | const std::string | fileName | ) | [private] |
Read parametrization from file.
Definition at line 31 of file GsfBetheHeitlerUpdator.cc.
References edm::FileInPath::fullPath(), name, readPolynomial(), theNrComponents, thePolyMeans, thePolyVars, thePolyWeights, and theTransformationCode.
Referenced by GsfBetheHeitlerUpdator().
00032 { 00033 std::string name = "TrackingTools/GsfTracking/data/"; 00034 name += fileName; 00035 00036 edm::FileInPath parFile(name); 00037 edm::LogInfo("GsfBetheHeitlerUpdator") << "Reading GSF parameterization " 00038 << "of Bethe-Heitler energy loss from " 00039 << parFile.fullPath(); 00040 std::ifstream ifs(parFile.fullPath().c_str()); 00041 00042 ifs >> theNrComponents; 00043 int orderP; 00044 ifs >> orderP; 00045 ifs >> theTransformationCode; 00046 for ( int ic=0; ic<theNrComponents; ic++ ) { 00047 thePolyWeights.push_back(readPolynomial(ifs,orderP)); 00048 thePolyMeans.push_back(readPolynomial(ifs,orderP)); 00049 thePolyVars.push_back(readPolynomial(ifs,orderP)); 00050 } 00051 }
GsfBetheHeitlerUpdator::Polynomial GsfBetheHeitlerUpdator::readPolynomial | ( | std::ifstream & | aStream, | |
const | int | |||
) | [private] |
Read coefficients of one polynomial from file.
Definition at line 54 of file GsfBetheHeitlerUpdator.cc.
Referenced by readParameters().
00055 { 00056 std::vector<double> coeffs(order+1); 00057 for ( int i=0; i<(order+1); i++ ) aStream >> coeffs[i]; 00058 return Polynomial(coeffs); 00059 }
void GsfBetheHeitlerUpdator::storeArguments | ( | const TrajectoryStateOnSurface & | TSoS, | |
const | PropagationDirection | |||
) | const [protected, virtual] |
storage of arguments for later use of
Reimplemented from GsfMaterialEffectsUpdator.
Definition at line 241 of file GsfBetheHeitlerUpdator.cc.
References TrajectoryStateOnSurface::localMomentum(), PV3DBase< T, PVType, FrameType >::mag(), Surface::mediumProperties(), MediumProperties::radLen(), TrajectoryStateOnSurface::surface(), theLastDz, theLastP, theLastPropDir, theLastRadLength, Vector3DBase< T, FrameTag >::unit(), and PV3DBase< T, PVType, FrameType >::z().
Referenced by compute().
00242 { 00243 theLastDz = TSoS.localMomentum().unit().z(); 00244 theLastP = TSoS.localMomentum().mag(); 00245 theLastPropDir = propDir; 00246 theLastRadLength = TSoS.surface().mediumProperties()->radLen(); 00247 }
int GsfBetheHeitlerUpdator::theCorrectionFlag [private] |
parametrisation of variance for each component
Definition at line 102 of file GsfBetheHeitlerUpdator.h.
Referenced by compute(), and GsfBetheHeitlerUpdator().
float GsfBetheHeitlerUpdator::theLastDz [mutable, private] |
correction of 1st or 1st&2nd moments
Definition at line 104 of file GsfBetheHeitlerUpdator.h.
Referenced by newArguments(), and storeArguments().
float GsfBetheHeitlerUpdator::theLastP [mutable, private] |
Definition at line 105 of file GsfBetheHeitlerUpdator.h.
Referenced by newArguments(), and storeArguments().
PropagationDirection GsfBetheHeitlerUpdator::theLastPropDir [mutable, private] |
Definition at line 106 of file GsfBetheHeitlerUpdator.h.
Referenced by newArguments(), and storeArguments().
float GsfBetheHeitlerUpdator::theLastRadLength [mutable, private] |
Definition at line 107 of file GsfBetheHeitlerUpdator.h.
Referenced by newArguments(), and storeArguments().
int GsfBetheHeitlerUpdator::theNrComponents [private] |
Definition at line 96 of file GsfBetheHeitlerUpdator.h.
Referenced by compute(), getMixtureParameters(), and readParameters().
std::vector<Polynomial> GsfBetheHeitlerUpdator::thePolyMeans [private] |
parametrisation of weight for each component
Definition at line 99 of file GsfBetheHeitlerUpdator.h.
Referenced by getMixtureParameters(), and readParameters().
std::vector<Polynomial> GsfBetheHeitlerUpdator::thePolyVars [private] |
parametrisation of mean for each component
Definition at line 100 of file GsfBetheHeitlerUpdator.h.
Referenced by getMixtureParameters(), and readParameters().
std::vector<Polynomial> GsfBetheHeitlerUpdator::thePolyWeights [private] |
values to be transformed by logistic / exp. function?
Definition at line 98 of file GsfBetheHeitlerUpdator.h.
Referenced by getMixtureParameters(), and readParameters().
number of components used for parameterisation
Definition at line 97 of file GsfBetheHeitlerUpdator.h.
Referenced by getMixtureParameters(), and readParameters().