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 unsigned 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 constexpr int MaxOrder = 6
 
static constexpr 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 20 of file GsfBetheHeitlerUpdator.h.

Member Enumeration Documentation

◆ CorrectionFlag

Constructor & Destructor Documentation

◆ GsfBetheHeitlerUpdator()

GsfBetheHeitlerUpdator::GsfBetheHeitlerUpdator ( const std::string  fileName,
const int  correctionFlag 
)

constructor with explicit filename and correction flag

Definition at line 53 of file GsfBetheHeitlerUpdator.cc.

References cms::cuda::assert(), MillePedeFileConverter_cfg::fileName, readParameters(), GsfMaterialEffectsUpdator::resize(), theCorrectionFlag, and theNrComponents.

Referenced by clone().

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

Member Function Documentation

◆ clone()

GsfBetheHeitlerUpdator* GsfBetheHeitlerUpdator::clone ( void  ) const
inlineoverridevirtual

Implements GsfMaterialEffectsUpdator.

Definition at line 55 of file GsfBetheHeitlerUpdator.h.

References GsfBetheHeitlerUpdator().

55 { return new GsfBetheHeitlerUpdator(*this); }
GsfBetheHeitlerUpdator(const std::string fileName, const int correctionFlag)
constructor with explicit filename and correction flag

◆ compute()

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

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

◆ correctedFirstMean()

float GsfBetheHeitlerUpdator::correctedFirstMean ( const float  rl,
const GSContainer mixture 
) const
private

Correction for mean of component 1.

Definition at line 207 of file GsfBetheHeitlerUpdator.cc.

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

Referenced by compute().

207  {
208  //
209  // calculate difference true mean - weighted sum
210  //
211  float mean = BetheHeitlerMean(rl);
212  for (int i = 1; i < theNrComponents; i++)
213  mean -= mixture.first[i] * mixture.second[i];
214  //
215  // return corrected mean for first component
216  //
217  return std::max(std::min(mean / mixture.first[0], 1.f), 0.f);
218 }

◆ correctedFirstVar()

float GsfBetheHeitlerUpdator::correctedFirstVar ( const float  rl,
const GSContainer mixture 
) const
private

Correction for variance of component 1.

Definition at line 222 of file GsfBetheHeitlerUpdator.cc.

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

Referenced by compute().

222  {
223  //
224  // calculate difference true variance - weighted sum
225  //
226  float var = BetheHeitlerVariance(rl) + BetheHeitlerMean(rl) * BetheHeitlerMean(rl) -
227  mixture.first[0] * mixture.second[0] * mixture.second[0];
228  for (int i = 1; i < theNrComponents; i++)
229  var -= mixture.first[i] * (mixture.second[i] * mixture.second[i] + mixture.third[i]);
230  //
231  // return corrected variance for first component
232  //
233  return std::max(var / mixture.first[0], 0.f);
234 }

◆ correctWeights()

void GsfBetheHeitlerUpdator::correctWeights ( GSContainer mixture) const
private

Correction for weight of component 1.

Definition at line 190 of file GsfBetheHeitlerUpdator.cc.

References GsfBetheHeitlerUpdator::GSContainer::first, cms::cuda::for(), mps_fire::i, and theNrComponents.

Referenced by compute().

190  {
191  //
192  // get sum of weights
193  //
194  float wsum(0);
195  for (int i = 0; i < theNrComponents; i++)
196  wsum += mixture.first[i];
197  //
198  // rescale to obtain 1
199  //
200  wsum = 1.f / wsum;
201  for (int i = 0; i < theNrComponents; i++)
202  mixture.first[i] *= wsum;
203 }
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)

◆ getMixtureParameters()

void GsfBetheHeitlerUpdator::getMixtureParameters ( const float  rl,
GSContainer mixture 
) const
private

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

Definition at line 165 of file GsfBetheHeitlerUpdator.cc.

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

Referenced by compute().

165  {
167  for (int i = 0; i < theNrComponents; i++) {
168  weight[i] = thePolyWeights[i](rl);
169  z[i] = thePolyMeans[i](rl);
170  vz[i] = thePolyVars[i](rl);
171  }
173  for (int i = 0; i < theNrComponents; i++) {
174  mixture.first[i] = logisticFunction(weight[i]);
175  mixture.second[i] = logisticFunction(z[i]);
176  mixture.third[i] = unsafe_expf<4>(vz[i]);
177  ;
178  }
179  else // theTransformationCode
180  for (int i = 0; i < theNrComponents; i++) {
181  mixture.first[i] = weight[i];
182  mixture.second[i] = z[i];
183  mixture.third[i] = vz[i] * vz[i];
184  }
185 }
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

◆ readParameters()

void GsfBetheHeitlerUpdator::readParameters ( const std::string  fileName)
private

Read parametrization from file.

Definition at line 65 of file GsfBetheHeitlerUpdator.cc.

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

Referenced by GsfBetheHeitlerUpdator().

65  {
66  std::string name = "TrackingTools/GsfTracking/data/";
67  name += fileName;
68 
69  edm::FileInPath parFile(name);
70  edm::LogInfo("GsfBetheHeitlerUpdator") << "Reading GSF parameterization "
71  << "of Bethe-Heitler energy loss from " << parFile.fullPath();
72  std::ifstream ifs(parFile.fullPath().c_str());
73 
74  ifs >> theNrComponents;
75  int orderP;
76  ifs >> orderP;
77  ifs >> theTransformationCode;
78 
79  assert(orderP < MaxOrder);
80 
81  for (int ic = 0; ic != theNrComponents; ++ic) {
82  thePolyWeights[ic] = readPolynomial(ifs, orderP);
83  thePolyMeans[ic] = readPolynomial(ifs, orderP);
84  thePolyVars[ic] = readPolynomial(ifs, orderP);
85  }
86 }
assert(be >=bs)
Polynomial thePolyWeights[MaxSize]
correction of 1st or 1st&2nd moments
int theTransformationCode
number of components used for parameterisation
Log< level::Info, false > LogInfo
Polynomial readPolynomial(std::ifstream &, const unsigned int)
Read coefficients of one polynomial from file.
Polynomial thePolyVars[MaxSize]
parametrisation of mean for each componentP
static constexpr int MaxOrder
Polynomial thePolyMeans[MaxSize]
parametrisation of weight for each component

◆ readPolynomial()

GsfBetheHeitlerUpdator::Polynomial GsfBetheHeitlerUpdator::readPolynomial ( std::ifstream &  aStream,
const unsigned int  order 
)
private

Read coefficients of one polynomial from file.

Definition at line 88 of file GsfBetheHeitlerUpdator.cc.

References mps_fire::i, and eventshapeDQM_cfi::order.

Referenced by readParameters().

89  {
90  float coeffs[order + 1];
91  for (unsigned int i = 0; i < (order + 1); ++i)
92  aStream >> coeffs[i];
93  return Polynomial(coeffs, order + 1);
94 }

Member Data Documentation

◆ MaxOrder

constexpr int GsfBetheHeitlerUpdator::MaxOrder = 6
staticprivate

Definition at line 23 of file GsfBetheHeitlerUpdator.h.

Referenced by readParameters().

◆ MaxSize

constexpr int GsfBetheHeitlerUpdator::MaxSize = 6
staticprivate

Definition at line 22 of file GsfBetheHeitlerUpdator.h.

◆ theCorrectionFlag

int GsfBetheHeitlerUpdator::theCorrectionFlag
private

values to be transformed by logistic / exp. function?

Definition at line 87 of file GsfBetheHeitlerUpdator.h.

Referenced by compute(), and GsfBetheHeitlerUpdator().

◆ theNrComponents

int GsfBetheHeitlerUpdator::theNrComponents
private

◆ thePolyMeans

Polynomial GsfBetheHeitlerUpdator::thePolyMeans[MaxSize]
private

parametrisation of weight for each component

Definition at line 90 of file GsfBetheHeitlerUpdator.h.

Referenced by getMixtureParameters(), and readParameters().

◆ thePolyVars

Polynomial GsfBetheHeitlerUpdator::thePolyVars[MaxSize]
private

parametrisation of mean for each componentP

Definition at line 91 of file GsfBetheHeitlerUpdator.h.

Referenced by getMixtureParameters(), and readParameters().

◆ thePolyWeights

Polynomial GsfBetheHeitlerUpdator::thePolyWeights[MaxSize]
private

correction of 1st or 1st&2nd moments

Definition at line 89 of file GsfBetheHeitlerUpdator.h.

Referenced by getMixtureParameters(), and readParameters().

◆ theTransformationCode

int GsfBetheHeitlerUpdator::theTransformationCode
private

number of components used for parameterisation

Definition at line 86 of file GsfBetheHeitlerUpdator.h.

Referenced by getMixtureParameters(), and readParameters().