CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
GsfBetheHeitlerUpdator Class Referencefinal

#include <GsfBetheHeitlerUpdator.h>

Inheritance diagram for GsfBetheHeitlerUpdator:
GsfMaterialEffectsUpdator

Classes

struct  GSContainer
 
class  Polynomial
 

Public Types

enum  CorrectionFlag { NoCorrection =0, MeanCorrection =1, FullCorrection =2 }
 
- Public Types inherited from GsfMaterialEffectsUpdator
typedef materialEffect::Covariance Covariance
 
typedef materialEffect::CovIndex CovIndex
 
typedef materialEffect::Effect Effect
 

Public Member Functions

GsfBetheHeitlerUpdatorclone () const override
 
 GsfBetheHeitlerUpdator (const std::string fileName, const int correctionFlag)
 constructor with explicit filename and correction flag More...
 
- Public Member Functions inherited from GsfMaterialEffectsUpdator
 GsfMaterialEffectsUpdator (float mass, uint32_t is)
 
float mass () const
 
size_t size () const
 
virtual TrajectoryStateOnSurface updateState (const TrajectoryStateOnSurface &TSoS, const PropagationDirection propDir) const
 
virtual ~GsfMaterialEffectsUpdator ()
 

Private Member Functions

void compute (const TrajectoryStateOnSurface &, const PropagationDirection, Effect[]) const override
 Computation: generates vectors of weights, means and standard deviations. More...
 
float correctedFirstMean (const float, const GSContainer &) const
 Correction for mean of component 1. More...
 
float correctedFirstVar (const float, const GSContainer &) const
 Correction for variance of component 1. More...
 
void correctWeights (GSContainer &) const
 Correction for weight of component 1. More...
 
void getMixtureParameters (const float, GSContainer &) const
 Filling of mixture (in terms of z=E/E0) 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
 values to be transformed by logistic / exp. function? More...
 
int theNrComponents
 
Polynomial thePolyMeans [MaxSize]
 parametrisation of weight for each component More...
 
Polynomial thePolyVars [MaxSize]
 parametrisation of mean for each componentP More...
 
Polynomial thePolyWeights [MaxSize]
 correction of 1st or 1st&2nd moments More...
 
int theTransformationCode
 number of components used for parameterisation More...
 

Static Private Attributes

static int MaxOrder =6
 
static int MaxSize =6
 

Additional Inherited Members

- Protected Member Functions inherited from GsfMaterialEffectsUpdator
void resize (size_t is)
 

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 22 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 56 of file GsfBetheHeitlerUpdator.cc.

References readParameters(), GsfMaterialEffectsUpdator::resize(), theCorrectionFlag, and theNrComponents.

Referenced by clone().

57  :
58  GsfMaterialEffectsUpdator(0.000511,6),
59  theNrComponents(0),
60  theCorrectionFlag(correctionFlag)
61 {
62  if ( theCorrectionFlag==1 )
63  edm::LogInfo("GsfBetheHeitlerUpdator") << "1st moment of mixture will be corrected";
64  if ( theCorrectionFlag>=2 )
65  edm::LogInfo("GsfBetheHeitlerUpdator")
66  << "1st and 2nd moments of mixture will be corrected";
67 
69  assert(theNrComponents<=6);
71 }
GsfMaterialEffectsUpdator(float mass, uint32_t is)
int theCorrectionFlag
values to be transformed by logistic / exp. function?
void readParameters(const std::string)
Read parametrization from file.

Member Function Documentation

GsfBetheHeitlerUpdator* GsfBetheHeitlerUpdator::clone ( void  ) const
inlineoverridevirtual

Implements GsfMaterialEffectsUpdator.

Definition at line 58 of file GsfBetheHeitlerUpdator.h.

References MillePedeFileConverter_cfg::fileName, GsfBetheHeitlerUpdator(), and AlCaHLTBitMon_QueryRunRegistry::string.

59  {
60  return new GsfBetheHeitlerUpdator(*this);
61  }
GsfBetheHeitlerUpdator(const std::string fileName, const int correctionFlag)
constructor with explicit filename and correction flag
void GsfBetheHeitlerUpdator::compute ( const TrajectoryStateOnSurface TSoS,
const PropagationDirection  propDir,
Effect  effects[] 
) const
overrideprivatevirtual

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

Implements GsfMaterialEffectsUpdator.

Definition at line 107 of file GsfBetheHeitlerUpdator.cc.

References alongMomentum, correctedFirstMean(), correctedFirstVar(), correctWeights(), materialEffect::Effect::deltaCov, materialEffect::Effect::deltaP, materialEffect::elos, f, getMixtureParameters(), mps_fire::i, MediumProperties::isValid(), TrajectoryStateOnSurface::localMomentum(), PV3DBase< T, PVType, FrameType >::mag(), Surface::mediumProperties(), AlCaHLTBitMon_ParallelJobs::p, MediumProperties::radLen(), TrajectoryStateOnSurface::surface(), theCorrectionFlag, theNrComponents, materialEffect::Effect::weight, and PV3DBase< T, PVType, FrameType >::z().

109 {
110  //
111  // Get surface and check presence of medium properties
112  //
113  const Surface& surface = TSoS.surface();
114  //
115  // calculate components: first check associated material constants
116  //
117  float rl(0.f);
118  float p(0.f);
119  if ( surface.mediumProperties().isValid() ) {
120  LocalVector pvec = TSoS.localMomentum();
121  p = pvec.mag();
122  rl = surface.mediumProperties().radLen()/fabs(pvec.z())*p;
123  }
124  //
125  // produce multi-state only in case of x/X0>0
126  //
127  if ( rl>0.0001f ) {
128  //
129  // limit x/x0 to valid range for parametrisation
130  // should be done in a more elegant way ...
131  //
132  if ( rl<0.01f ) rl = 0.01f;
133  if ( rl>0.20f ) rl = 0.20f;
134 
135  float mixtureData[3][theNrComponents];
136  GSContainer mixture{mixtureData[0],mixtureData[1],mixtureData[2]};
137 
138  getMixtureParameters(rl,mixture);
139  correctWeights(mixture);
140  if ( theCorrectionFlag>=1 )
141  mixture.second[0] = correctedFirstMean(rl,mixture);
142  if ( theCorrectionFlag>=2 )
143  mixture.third[0] = correctedFirstVar(rl,mixture);
144 
145  for ( int i=0; i<theNrComponents; i++ ) {
146  float varPinv;
147  effects[i].weight*=mixture.first[i];
148  if ( propDir==alongMomentum ) {
149  //
150  // for forward propagation: calculate in p (linear in 1/z=p_inside/p_outside),
151  // then convert sig(p) to sig(1/p).
152  //
153  effects[i].deltaP += p*(mixture.second[i]-1.f);
154  // float f = 1./p/mixture.second[i]/mixture.second[i];
155  // patch to ensure consistency between for- and backward propagation
156  float f = 1.f/(p*mixture.second[i]);
157  varPinv = f*f*mixture.third[i];
158  }
159  else {
160  //
161  // for backward propagation: delta(1/p) is linear in z=p_outside/p_inside
162  // convert to obtain equivalent delta(p)
163  //
164  effects[i].deltaP += p*(1.f/mixture.second[i]-1.f);
165  varPinv = mixture.third[i]/(p*p);
166  }
167  using namespace materialEffect;
168  effects[i].deltaCov[elos] += varPinv;
169  }
170  }
171 }
float radLen() const
void correctWeights(GSContainer &) const
Correction for weight of component 1.
void getMixtureParameters(const float, GSContainer &) const
Filling of mixture (in terms of z=E/E0)
LocalVector localMomentum() const
const SurfaceType & surface() const
T mag() const
Definition: PV3DBase.h:67
T z() const
Definition: PV3DBase.h:64
double f[11][100]
int theCorrectionFlag
values to be transformed by logistic / exp. function?
float correctedFirstVar(const float, const GSContainer &) const
Correction for variance of component 1.
bool isValid() const
const MediumProperties & mediumProperties() const
Definition: Surface.h:112
float correctedFirstMean(const float, const GSContainer &) const
Correction for mean of component 1.
float GsfBetheHeitlerUpdator::correctedFirstMean ( const float  rl,
const GSContainer mixture 
) const
private

Correction for mean of component 1.

Definition at line 223 of file GsfBetheHeitlerUpdator.cc.

References GsfBetheHeitlerUpdator::GSContainer::first, mps_fire::i, SiStripPI::max, SiStripPI::mean, min(), GsfBetheHeitlerUpdator::GSContainer::second, and theNrComponents.

Referenced by compute().

225 {
226  //
227  // calculate difference true mean - weighted sum
228  //
229  float mean = BetheHeitlerMean(rl);
230  for ( int i=1; i<theNrComponents; i++ )
231  mean -= mixture.first[i]*mixture.second[i];
232  //
233  // return corrected mean for first component
234  //
235  return std::max(std::min(mean/mixture.first[0],1.f),0.f);
236 }
T min(T a, T b)
Definition: MathUtil.h:58
float GsfBetheHeitlerUpdator::correctedFirstVar ( const float  rl,
const GSContainer mixture 
) const
private

Correction for variance of component 1.

Definition at line 241 of file GsfBetheHeitlerUpdator.cc.

References GsfBetheHeitlerUpdator::GSContainer::first, mps_fire::i, SiStripPI::max, GsfBetheHeitlerUpdator::GSContainer::second, theNrComponents, GsfBetheHeitlerUpdator::GSContainer::third, and JetChargeProducer_cfi::var.

Referenced by compute().

243 {
244  //
245  // calculate difference true variance - weighted sum
246  //
247  float var = BetheHeitlerVariance(rl) +
248  BetheHeitlerMean(rl)*BetheHeitlerMean(rl) -
249  mixture.first[0]*mixture.second[0]*mixture.second[0];
250  for ( int i=1; i<theNrComponents; i++ )
251  var -= mixture.first[i]*(mixture.second[i]*mixture.second[i]+mixture.third[i]);
252  //
253  // return corrected variance for first component
254  //
255  return std::max(var/mixture.first[0],0.f);
256 }
void GsfBetheHeitlerUpdator::correctWeights ( GSContainer mixture) const
private

Correction for weight of component 1.

Definition at line 204 of file GsfBetheHeitlerUpdator.cc.

References GsfBetheHeitlerUpdator::GSContainer::first, mps_fire::i, and theNrComponents.

Referenced by compute().

205 {
206  //
207  // get sum of weights
208  //
209  float wsum(0);
210  for ( int i=0; i<theNrComponents; i++ )
211  wsum += mixture.first[i];
212  //
213  // rescale to obtain 1
214  //
215  wsum = 1.f/wsum;
216  for ( int i=0; i<theNrComponents; i++ )
217  mixture.first[i] *= wsum;
218 }
void GsfBetheHeitlerUpdator::getMixtureParameters ( const float  rl,
GSContainer mixture 
) const
private

Filling of mixture (in terms of z=E/E0)

Definition at line 176 of file GsfBetheHeitlerUpdator.cc.

References GsfBetheHeitlerUpdator::GSContainer::first, mps_fire::i, GsfBetheHeitlerUpdator::GSContainer::second, theNrComponents, thePolyMeans, thePolyVars, thePolyWeights, theTransformationCode, GsfBetheHeitlerUpdator::GSContainer::third, and z.

Referenced by compute().

178 {
179 
181  for ( int i=0; i<theNrComponents; i++ ) {
182  weight[i] = thePolyWeights[i](rl);
183  z[i] = thePolyMeans[i](rl);
184  vz[i] = thePolyVars[i](rl);
185  }
186  if ( theTransformationCode )
187  for ( int i=0; i<theNrComponents; i++ ) {
188  mixture.first[i]=logisticFunction(weight[i]);
189  mixture.second[i]=logisticFunction(z[i]);
190  mixture.third[i]=unsafe_expf<4>(vz[i]);;
191  }
192  else // theTransformationCode
193  for ( int i=0; i<theNrComponents; i++ ) {
194  mixture.first[i]=weight[i];
195  mixture.second[i]=z[i];
196  mixture.third[i]=vz[i]*vz[i];
197  }
198 }
Definition: weight.py:1
Polynomial thePolyWeights[MaxSize]
correction of 1st or 1st&2nd moments
int theTransformationCode
number of components used for parameterisation
Polynomial thePolyVars[MaxSize]
parametrisation of mean for each componentP
Polynomial thePolyMeans[MaxSize]
parametrisation of weight for each component
void GsfBetheHeitlerUpdator::readParameters ( const std::string  fileName)
private

Read parametrization from file.

Definition at line 73 of file GsfBetheHeitlerUpdator.cc.

References MillePedeFileConverter_cfg::fileName, edm::FileInPath::fullPath(), MaxOrder, dataset::name, readPolynomial(), AlCaHLTBitMon_QueryRunRegistry::string, theNrComponents, thePolyMeans, thePolyVars, thePolyWeights, and theTransformationCode.

Referenced by GsfBetheHeitlerUpdator().

74 {
75  std::string name = "TrackingTools/GsfTracking/data/";
76  name += fileName;
77 
78  edm::FileInPath parFile(name);
79  edm::LogInfo("GsfBetheHeitlerUpdator") << "Reading GSF parameterization "
80  << "of Bethe-Heitler energy loss from "
81  << parFile.fullPath();
82  std::ifstream ifs(parFile.fullPath().c_str());
83 
84  ifs >> theNrComponents;
85  int orderP;
86  ifs >> orderP;
87  ifs >> theTransformationCode;
88 
89  assert(orderP<MaxOrder);
90 
91  for ( int ic=0; ic!=theNrComponents; ++ic ) {
92  thePolyWeights[ic]=readPolynomial(ifs,orderP);
93  thePolyMeans[ic]=readPolynomial(ifs,orderP);
94  thePolyVars[ic]=readPolynomial(ifs,orderP);
95  }
96 }
Polynomial readPolynomial(std::ifstream &, const int)
Read coefficients of one polynomial from file.
Polynomial thePolyWeights[MaxSize]
correction of 1st or 1st&2nd moments
int theTransformationCode
number of components used for parameterisation
Polynomial thePolyVars[MaxSize]
parametrisation of mean for each componentP
Polynomial thePolyMeans[MaxSize]
parametrisation of weight for each component
GsfBetheHeitlerUpdator::Polynomial GsfBetheHeitlerUpdator::readPolynomial ( std::ifstream &  aStream,
const int  order 
)
private

Read coefficients of one polynomial from file.

Definition at line 99 of file GsfBetheHeitlerUpdator.cc.

References mps_fire::i.

Referenced by readParameters().

100  {
101  float coeffs[order+1];
102  for ( int i=0; i<(order+1); ++i ) aStream >> coeffs[i];
103  return Polynomial(coeffs,order+1);
104 }

Member Data Documentation

int GsfBetheHeitlerUpdator::MaxOrder =6
staticprivate

Definition at line 26 of file GsfBetheHeitlerUpdator.h.

Referenced by readParameters().

int GsfBetheHeitlerUpdator::MaxSize =6
staticprivate

Definition at line 25 of file GsfBetheHeitlerUpdator.h.

int GsfBetheHeitlerUpdator::theCorrectionFlag
private

values to be transformed by logistic / exp. function?

Definition at line 94 of file GsfBetheHeitlerUpdator.h.

Referenced by compute(), and GsfBetheHeitlerUpdator().

int GsfBetheHeitlerUpdator::theNrComponents
private
Polynomial GsfBetheHeitlerUpdator::thePolyMeans[MaxSize]
private

parametrisation of weight for each component

Definition at line 97 of file GsfBetheHeitlerUpdator.h.

Referenced by getMixtureParameters(), and readParameters().

Polynomial GsfBetheHeitlerUpdator::thePolyVars[MaxSize]
private

parametrisation of mean for each componentP

Definition at line 98 of file GsfBetheHeitlerUpdator.h.

Referenced by getMixtureParameters(), and readParameters().

Polynomial GsfBetheHeitlerUpdator::thePolyWeights[MaxSize]
private

correction of 1st or 1st&2nd moments

Definition at line 96 of file GsfBetheHeitlerUpdator.h.

Referenced by getMixtureParameters(), and readParameters().

int GsfBetheHeitlerUpdator::theTransformationCode
private

number of components used for parameterisation

Definition at line 93 of file GsfBetheHeitlerUpdator.h.

Referenced by getMixtureParameters(), and readParameters().