CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
GsfBetheHeitlerUpdator Class Reference

#include <GsfBetheHeitlerUpdator.h>

Inheritance diagram for GsfBetheHeitlerUpdator:
GsfMaterialEffectsUpdator

Classes

class  Polynomial
 

Public Types

enum  CorrectionFlag { NoCorrection =0, MeanCorrection =1, FullCorrection =2 }
 

Public Member Functions

virtual GsfBetheHeitlerUpdatorclone () const
 
 GsfBetheHeitlerUpdator (const std::string fileName, const int correctionFlag)
 constructor with explicit filename and correction flag More...
 
- Public Member Functions inherited from GsfMaterialEffectsUpdator
virtual std::vector
< AlgebraicSymMatrix55
deltaLocalErrors (const TrajectoryStateOnSurface &TSoS, const PropagationDirection propDir) const
 
virtual std::vector< double > deltaPs (const TrajectoryStateOnSurface &TSoS, const PropagationDirection propDir) const
 
 GsfMaterialEffectsUpdator (float mass)
 
float mass () const
 
virtual TrajectoryStateOnSurface updateState (const TrajectoryStateOnSurface &TSoS, const PropagationDirection propDir) const
 
virtual std::vector< double > weights (const TrajectoryStateOnSurface &TSoS, const PropagationDirection propDir) const
 
virtual ~GsfMaterialEffectsUpdator ()
 

Protected Member Functions

virtual bool newArguments (const TrajectoryStateOnSurface &, const PropagationDirection) const
 check of arguments for use with cached values More...
 
virtual void storeArguments (const TrajectoryStateOnSurface &, const PropagationDirection) const
 storage of arguments for later use of More...
 

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) More...
 
double BetheHeitlerVariance (const double rl) const
 Second moment of the Bethe-Heitler distribution (in z=E/E0) More...
 
virtual void compute (const TrajectoryStateOnSurface &, const PropagationDirection) const
 Computation: generates vectors of weights, means and standard deviations. More...
 
double correctedFirstMean (const double, const GSContainer &) const
 Correction for mean of component 1. More...
 
double correctedFirstVar (const double, const GSContainer &) const
 Correction for variance of component 1. More...
 
void correctWeights (GSContainer &) const
 Correction for weight of component 1. More...
 
void getMixtureParameters (const double, GSContainer &) const
 Filling of mixture (in terms of z=E/E0) More...
 
double logisticFunction (const double x) const
 Logistic function (needed for transformation of weight and mean) More...
 
void readParameters (const std::string)
 Read parametrization from file. More...
 
Polynomial readPolynomial (std::ifstream &, const int)
 Read coefficients of one polynomial from file. More...
 

Private Attributes

int theCorrectionFlag
 parametrisation of variance for each component More...
 
float theLastDz
 correction of 1st or 1st&2nd moments More...
 
float theLastP
 
PropagationDirection theLastPropDir
 
float theLastRadLength
 
int theNrComponents
 
std::vector< PolynomialthePolyMeans
 parametrisation of weight for each component More...
 
std::vector< PolynomialthePolyVars
 parametrisation of mean for each component More...
 
std::vector< PolynomialthePolyWeights
 values to be transformed by logistic / exp. function? More...
 
int theTransformationCode
 number of components used for parameterisation More...
 

Additional Inherited Members

- Protected Attributes inherited from GsfMaterialEffectsUpdator
std::vector< AlgebraicSymMatrix55theDeltaCovs
 
std::vector< double > theDeltaPs
 
std::vector< double > theWeights
 

Detailed Description

Description of electron energy loss according to Bethe-Heitler as a sum of Gaussian components. 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.

Member Typedef Documentation

typedef std::vector< Triplet<double,double,double> > GsfBetheHeitlerUpdator::GSContainer
private

Definition at line 59 of file GsfBetheHeitlerUpdator.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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().

12  :
13  // const CorrectionFlag correctionFlag) :
14  GsfMaterialEffectsUpdator(0.000511),
15  theNrComponents(0),
16  theCorrectionFlag(correctionFlag),
17  theLastDz(0.),
18  theLastP(-1.),
20  theLastRadLength(-1.)
21 {
22  if ( theCorrectionFlag==1 )
23  edm::LogInfo("GsfBetheHeitlerUpdator") << "1st moment of mixture will be corrected";
24  if ( theCorrectionFlag>=2 )
25  edm::LogInfo("GsfBetheHeitlerUpdator")
26  << "1st and 2nd moments of mixture will be corrected";
27 
29 }
float theLastDz
correction of 1st or 1st&amp;2nd moments
PropagationDirection theLastPropDir
int theCorrectionFlag
parametrisation of variance for each component
void readParameters(const std::string)
Read parametrization from file.

Member Function Documentation

double GsfBetheHeitlerUpdator::BetheHeitlerMean ( const double  rl) const
inlineprivate

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().

72  {
73  return exp(-rl);
74  }
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
double GsfBetheHeitlerUpdator::BetheHeitlerVariance ( const double  rl) const
inlineprivate

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().

77  {
78  return exp(-rl*log(3.)/log(2.)) - exp(-2*rl);
79  }
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
Log< T >::type log(const T &t)
Definition: Log.h:22
virtual GsfBetheHeitlerUpdator* GsfBetheHeitlerUpdator::clone ( void  ) const
inlinevirtual

Implements GsfMaterialEffectsUpdator.

Definition at line 48 of file GsfBetheHeitlerUpdator.h.

References GsfBetheHeitlerUpdator().

49  {
50  return new GsfBetheHeitlerUpdator(*this);
51  }
GsfBetheHeitlerUpdator(const std::string fileName, const int correctionFlag)
constructor with explicit filename and correction flag
void GsfBetheHeitlerUpdator::compute ( const TrajectoryStateOnSurface TSoS,
const PropagationDirection  propDir 
) const
privatevirtual

Computation: generates vectors of weights, means and standard deviations.

Implements GsfMaterialEffectsUpdator.

Definition at line 62 of file GsfBetheHeitlerUpdator.cc.

References alongMomentum, correctedFirstMean(), correctedFirstVar(), correctWeights(), ExpressReco_HICollisions_FallBack::errors, f, first, getMixtureParameters(), i, TrajectoryStateOnSurface::localMomentum(), PV3DBase< T, PVType, FrameType >::mag(), Surface::mediumProperties(), L1TEmulatorMonitor_cff::p, MediumProperties::radLen(), edm::second(), storeArguments(), TrajectoryStateOnSurface::surface(), theCorrectionFlag, GsfMaterialEffectsUpdator::theDeltaCovs, GsfMaterialEffectsUpdator::theDeltaPs, theNrComponents, GsfMaterialEffectsUpdator::theWeights, and PV3DBase< T, PVType, FrameType >::z().

64 {
65  //
66  // clear cache
67  //
68  theWeights.clear();
69  theDeltaPs.clear();
70  theDeltaCovs.clear();
71  //
72  // Get surface and check presence of medium properties
73  //
74  const Surface& surface = TSoS.surface();
75  //
76  // calculate components: first check associated material constants
77  //
78  double rl(0.);
79  double p(0.);
80  if ( surface.mediumProperties() ) {
81  LocalVector pvec = TSoS.localMomentum();
82  p = pvec.mag();
83  rl = surface.mediumProperties()->radLen()/fabs(pvec.z())*p;
84  }
85  //
86  // produce multi-state only in case of x/X0>0
87  //
88  if ( rl>0.0001 ) {
89  //
90  // limit x/x0 to valid range for parametrisation
91  // should be done in a more elegant way ...
92  //
93  if ( rl<0.01 ) rl = 0.01;
94  if ( rl>0.20 ) rl = 0.20;
95 
96  GSContainer mixture;
97  getMixtureParameters(rl,mixture);
98  correctWeights(mixture);
99  if ( theCorrectionFlag>=1 )
100  mixture[0].second = correctedFirstMean(rl,mixture);
101  if ( theCorrectionFlag>=2 )
102  mixture[0].third = correctedFirstVar(rl,mixture);
103 
104  for ( int i=0; i<theNrComponents; i++ ) {
105  double varPinv;
106  theWeights.push_back(mixture[i].first);
107  if ( propDir==alongMomentum ) {
108  //
109  // for forward propagation: calculate in p (linear in 1/z=p_inside/p_outside),
110  // then convert sig(p) to sig(1/p).
111  //
112  theDeltaPs.push_back(p*(mixture[i].second-1));
113  // double f = 1./p/mixture[i].second/mixture[i].second;
114  // patch to ensure consistency between for- and backward propagation
115  double f = 1./p/mixture[i].second;
116  varPinv = f*f*mixture[i].third;
117  }
118  else {
119  //
120  // for backward propagation: delta(1/p) is linear in z=p_outside/p_inside
121  // convert to obtain equivalent delta(p)
122  //
123  theDeltaPs.push_back(p*(1/mixture[i].second-1));
124  varPinv = mixture[i].third/p/p;
125  }
127  errors(0,0) = varPinv;
128  theDeltaCovs.push_back(errors);
129  }
130  }
131  else {
132  theWeights.push_back(1.);
133  theDeltaPs.push_back(0.);
134  theDeltaCovs.push_back(AlgebraicSymMatrix55());
135  }
136  //
137  // Save arguments to avoid duplication of computation
138  //
139  storeArguments(TSoS,propDir);
140 }
virtual void storeArguments(const TrajectoryStateOnSurface &, const PropagationDirection) const
storage of arguments for later use of
int i
Definition: DBlmapReader.cc:9
float radLen() const
std::vector< AlgebraicSymMatrix55 > theDeltaCovs
void correctWeights(GSContainer &) const
Correction for weight of component 1.
double correctedFirstVar(const double, const GSContainer &) const
Correction for variance of component 1.
void getMixtureParameters(const double, GSContainer &) const
Filling of mixture (in terms of z=E/E0)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const MediumProperties * mediumProperties() const
Definition: Surface.h:93
LocalVector localMomentum() const
U second(std::pair< T, U > const &p)
T mag() const
Definition: PV3DBase.h:61
std::vector< Triplet< double, double, double > > GSContainer
T z() const
Definition: PV3DBase.h:58
double f[11][100]
bool first
Definition: L1TdeRCT.cc:79
int theCorrectionFlag
parametrisation of variance for each component
double correctedFirstMean(const double, const GSContainer &) const
Correction for mean of component 1.
const Surface & surface() const
double GsfBetheHeitlerUpdator::correctedFirstMean ( const double  rl,
const GSContainer mixture 
) const
private

Correction for mean of component 1.

Definition at line 190 of file GsfBetheHeitlerUpdator.cc.

References BetheHeitlerMean(), i, max(), plotscripts::mean(), and min.

Referenced by compute().

192 {
193  if ( mixture.empty() ) return 0.;
194  //
195  // calculate difference true mean - weighted sum
196  //
197  double mean = BetheHeitlerMean(rl);
198  for ( GSContainer::const_iterator i=mixture.begin()+1;
199  i!=mixture.end(); i++ ) mean -= (*i).first*(*i).second;
200  //
201  // return corrected mean for first component
202  //
203  return std::max(std::min(mean/mixture[0].first,1.),0.);
204 }
int i
Definition: DBlmapReader.cc:9
#define min(a, b)
Definition: mlp_lapack.h:161
double BetheHeitlerMean(const double rl) const
First moment of the Bethe-Heitler distribution (in z=E/E0)
const T & max(const T &a, const T &b)
double GsfBetheHeitlerUpdator::correctedFirstVar ( const double  rl,
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().

211 {
212  if ( mixture.empty() ) return 0.;
213  //
214  // calculate difference true variance - weighted sum
215  //
216  double var = BetheHeitlerVariance(rl) +
218  mixture[0].first*mixture[0].second*mixture[0].second;
219  for ( GSContainer::const_iterator i=mixture.begin()+1;
220  i!=mixture.end(); i++ )
221  var -= (*i).first*((*i).second*(*i).second+(*i).third);
222  //
223  // return corrected variance for first component
224  //
225  return std::max(var/mixture[0].first,0.);
226 }
int i
Definition: DBlmapReader.cc:9
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)
const T & max(const T &a, const T &b)
bool first
Definition: L1TdeRCT.cc:79
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().

172 {
173  if ( mixture.empty() ) return;
174  //
175  // get sum of weights
176  //
177  double wsum(0);
178  for ( GSContainer::const_iterator i=mixture.begin();
179  i!=mixture.end(); i++ ) wsum += (*i).first;
180  //
181  // rescale to obtain 1
182  //
183  for ( GSContainer::iterator i=mixture.begin();
184  i!=mixture.end(); i++ ) (*i).first /= wsum;
185 }
int i
Definition: DBlmapReader.cc:9
void GsfBetheHeitlerUpdator::getMixtureParameters ( const double  rl,
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, CommonMethods::weight(), and z.

Referenced by compute().

147 {
148  mixture.clear();
149  mixture.reserve(theNrComponents);
150 
151  for ( int i=0; i<theNrComponents; i++ ) {
152 
153  double weight = thePolyWeights[i](rl);
154  if ( theTransformationCode ) weight = logisticFunction(weight);
155 
156  double z = thePolyMeans[i](rl);
158 
159  double vz = thePolyVars[i](rl);
160  if ( theTransformationCode ) vz = exp(vz);
161  else vz = vz*vz;
162 
163  mixture.push_back(Triplet<double,double,double>(weight,z,vz));
164  }
165 }
int i
Definition: DBlmapReader.cc:9
std::vector< Polynomial > thePolyVars
parametrisation of mean for each component
std::vector< Polynomial > thePolyMeans
parametrisation of weight for each component
std::vector< Polynomial > thePolyWeights
values to be transformed by logistic / exp. function?
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
Definition: Triplet.h:9
Definition: DDAxes.h:10
double logisticFunction(const double x) const
Logistic function (needed for transformation of weight and mean)
int theTransformationCode
number of components used for parameterisation
double GsfBetheHeitlerUpdator::logisticFunction ( const double  x) const
inlineprivate

Logistic function (needed for transformation of weight and mean)

Definition at line 69 of file GsfBetheHeitlerUpdator.h.

References funct::exp().

Referenced by getMixtureParameters().

69 {return 1./(1.+exp(-x));}
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
bool GsfBetheHeitlerUpdator::newArguments ( const TrajectoryStateOnSurface TSoS,
const PropagationDirection  propDir 
) const
protectedvirtual

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().

233  {
234  return TSoS.localMomentum().unit().z()!=theLastDz ||
235  TSoS.localMomentum().mag()!=theLastP || propDir!=theLastPropDir ||
237 }
float radLen() const
float theLastDz
correction of 1st or 1st&amp;2nd moments
const MediumProperties * mediumProperties() const
Definition: Surface.h:93
LocalVector localMomentum() const
T mag() const
Definition: PV3DBase.h:61
T z() const
Definition: PV3DBase.h:58
PropagationDirection theLastPropDir
Vector3DBase unit() const
Definition: Vector3DBase.h:57
const Surface & surface() const
void GsfBetheHeitlerUpdator::readParameters ( const std::string  fileName)
private

Read parametrization from file.

Definition at line 31 of file GsfBetheHeitlerUpdator.cc.

References convertXMLtoSQLite_cfg::fileName, edm::FileInPath::fullPath(), AlCaRecoCosmics_cfg::name, readPolynomial(), theNrComponents, thePolyMeans, thePolyVars, thePolyWeights, and theTransformationCode.

Referenced by GsfBetheHeitlerUpdator().

32 {
33  std::string name = "TrackingTools/GsfTracking/data/";
34  name += fileName;
35 
36  edm::FileInPath parFile(name);
37  edm::LogInfo("GsfBetheHeitlerUpdator") << "Reading GSF parameterization "
38  << "of Bethe-Heitler energy loss from "
39  << parFile.fullPath();
40  std::ifstream ifs(parFile.fullPath().c_str());
41 
42  ifs >> theNrComponents;
43  int orderP;
44  ifs >> orderP;
45  ifs >> theTransformationCode;
46  for ( int ic=0; ic<theNrComponents; ic++ ) {
47  thePolyWeights.push_back(readPolynomial(ifs,orderP));
48  thePolyMeans.push_back(readPolynomial(ifs,orderP));
49  thePolyVars.push_back(readPolynomial(ifs,orderP));
50  }
51 }
std::vector< Polynomial > thePolyVars
parametrisation of mean for each component
std::vector< Polynomial > thePolyMeans
parametrisation of weight for each component
Polynomial readPolynomial(std::ifstream &, const int)
Read coefficients of one polynomial from file.
std::vector< Polynomial > thePolyWeights
values to be transformed by logistic / exp. function?
int theTransformationCode
number of components used for parameterisation
GsfBetheHeitlerUpdator::Polynomial GsfBetheHeitlerUpdator::readPolynomial ( std::ifstream &  aStream,
const int  order 
)
private

Read coefficients of one polynomial from file.

Definition at line 54 of file GsfBetheHeitlerUpdator.cc.

References i.

Referenced by readParameters().

55  {
56  std::vector<double> coeffs(order+1);
57  for ( int i=0; i<(order+1); i++ ) aStream >> coeffs[i];
58  return Polynomial(coeffs);
59 }
int i
Definition: DBlmapReader.cc:9
void GsfBetheHeitlerUpdator::storeArguments ( const TrajectoryStateOnSurface TSoS,
const PropagationDirection  propDir 
) const
protectedvirtual

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().

242  {
243  theLastDz = TSoS.localMomentum().unit().z();
244  theLastP = TSoS.localMomentum().mag();
245  theLastPropDir = propDir;
247 }
float radLen() const
float theLastDz
correction of 1st or 1st&amp;2nd moments
const MediumProperties * mediumProperties() const
Definition: Surface.h:93
LocalVector localMomentum() const
T mag() const
Definition: PV3DBase.h:61
T z() const
Definition: PV3DBase.h:58
PropagationDirection theLastPropDir
Vector3DBase unit() const
Definition: Vector3DBase.h:57
const Surface & surface() const

Member Data Documentation

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
mutableprivate

correction of 1st or 1st&2nd moments

Definition at line 104 of file GsfBetheHeitlerUpdator.h.

Referenced by newArguments(), and storeArguments().

float GsfBetheHeitlerUpdator::theLastP
mutableprivate

Definition at line 105 of file GsfBetheHeitlerUpdator.h.

Referenced by newArguments(), and storeArguments().

PropagationDirection GsfBetheHeitlerUpdator::theLastPropDir
mutableprivate

Definition at line 106 of file GsfBetheHeitlerUpdator.h.

Referenced by newArguments(), and storeArguments().

float GsfBetheHeitlerUpdator::theLastRadLength
mutableprivate

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().

int GsfBetheHeitlerUpdator::theTransformationCode
private

number of components used for parameterisation

Definition at line 97 of file GsfBetheHeitlerUpdator.h.

Referenced by getMixtureParameters(), and readParameters().