CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
CrossSectionHandler Class Reference

#include <CrossSectionHandler.h>

Public Member Functions

void addParameters (std::vector< double > &initpar)
 Inputs the vars in a vector. More...
 
 CrossSectionHandler (const std::vector< double > &crossSection, const std::vector< int > &resfind)
 
unsigned int parNum ()
 
std::vector< double > relativeCrossSections (const double *variables, const std::vector< int > &resfind)
 Perform a variable transformation from N-1 to relative cross sections. More...
 
bool releaseParameters (TMinuit &rmin, const std::vector< int > &resfind, const std::vector< int > &parfix, const int *ind, const int iorder, const unsigned int shift)
 Use the information in resfind, parorder and parfix to release the N-1 variables. More...
 
void setParameters (double *Start, double *Step, double *Mini, double *Maxi, int *ind, TString *parname, const std::vector< double > &parCrossSection, const std::vector< int > &parCrossSectionOrder, const std::vector< int > &resfind)
 Initializes the arrays needed by Minuit. More...
 

Protected Member Functions

void computeRelativeCrossSections (const std::vector< double > &crossSection, const std::vector< int > &resfind)
 
void imposeConstraint ()
 Change of variables so that we move from N to N-1 variables using the constraint that Sum(x_i) = 1. More...
 

Protected Attributes

unsigned int numberOfResonances_
 
unsigned int parNum_
 
std::vector< double > relativeCrossSectionVec_
 
std::vector< double > vars_
 

Friends

class TestCrossSectionHandler
 

Detailed Description

Definition at line 27 of file CrossSectionHandler.h.

Constructor & Destructor Documentation

◆ CrossSectionHandler()

CrossSectionHandler::CrossSectionHandler ( const std::vector< double > &  crossSection,
const std::vector< int > &  resfind 
)
inline

Definition at line 32 of file CrossSectionHandler.h.

References computeRelativeCrossSections(), DYToLL_TuneCH3_13TeV_herwig7_cff::crossSection, imposeConstraint(), parNum_, MuScleFitGenFilter_cfi::resfind, and vars_.

33  : parNum_(0), numberOfResonances_(resfind.size()) {
34  // The number of parameters is the number of fitted resonances minus 1
35  std::vector<int>::const_iterator it = resfind.begin();
36  for (; it != resfind.end(); ++it) {
37  if (*it != 0)
38  ++parNum_;
39  }
40  if (parNum_ > 0)
41  parNum_ = parNum_ - 1;
42 
43  vars_.resize(parNum_);
44 
47  }
void computeRelativeCrossSections(const std::vector< double > &crossSection, const std::vector< int > &resfind)
std::vector< double > vars_
unsigned int numberOfResonances_
void imposeConstraint()
Change of variables so that we move from N to N-1 variables using the constraint that Sum(x_i) = 1...

Member Function Documentation

◆ addParameters()

void CrossSectionHandler::addParameters ( std::vector< double > &  initpar)
inline

Inputs the vars in a vector.

Definition at line 50 of file CrossSectionHandler.h.

References vars_.

Referenced by MuScleFit::duringFastLoop().

50  {
51  std::vector<double>::const_iterator it = vars_.begin();
52  for (; it != vars_.end(); ++it) {
53  initpar.push_back(*it);
54  }
55  }
std::vector< double > vars_

◆ computeRelativeCrossSections()

void CrossSectionHandler::computeRelativeCrossSections ( const std::vector< double > &  crossSection,
const std::vector< int > &  resfind 
)
inlineprotected

Initializes the relative cross sections for the range of resonances in [minRes, maxRes]. (note that both minRes and maxRes are included).
Also sets the lock on resonances. If only one of the resonances in the range is fitted its relative cross section will be 1 and it will not be fitted. If there are more than one only those that are fitted will have the relative cross section parameters unlocked during the fit.

Definition at line 167 of file CrossSectionHandler.h.

References DYToLL_TuneCH3_13TeV_herwig7_cff::crossSection, PostProcessor_cff::normalization, relativeCrossSectionVec_, and MuScleFitGenFilter_cfi::resfind.

Referenced by CrossSectionHandler(), and setParameters().

167  {
168  relativeCrossSectionVec_.clear();
169  double normalization = 0.;
170  for (unsigned int ires = 0; ires < resfind.size(); ++ires) {
171  if (resfind[ires]) {
172  normalization += crossSection[ires];
173  }
174  }
175  if (normalization != 0.) {
176  for (unsigned int ires = 0; ires < resfind.size(); ++ires) {
177  if (resfind[ires]) {
179  }
180  }
181  }
182  }
std::vector< double > relativeCrossSectionVec_

◆ imposeConstraint()

void CrossSectionHandler::imposeConstraint ( )
inlineprotected

Change of variables so that we move from N to N-1 variables using the constraint that Sum(x_i) = 1.

Definition at line 185 of file CrossSectionHandler.h.

References parNum_, relativeCrossSectionVec_, and vars_.

Referenced by CrossSectionHandler(), and setParameters().

185  {
186  if (parNum_ > 0) {
187  for (unsigned int iVar = 0; iVar < parNum_; ++iVar) {
188  vars_[iVar] = relativeCrossSectionVec_[iVar + 1] / relativeCrossSectionVec_[iVar];
189  }
190  }
191  }
std::vector< double > vars_
std::vector< double > relativeCrossSectionVec_

◆ parNum()

unsigned int CrossSectionHandler::parNum ( )
inline

Definition at line 121 of file CrossSectionHandler.h.

References parNum_.

Referenced by MuScleFitUtils::massProb(), and MuScleFitUtils::minimizeLikelihood().

121 { return parNum_; }

◆ relativeCrossSections()

std::vector<double> CrossSectionHandler::relativeCrossSections ( const double *  variables,
const std::vector< int > &  resfind 
)
inline

Perform a variable transformation from N-1 to relative cross sections.

Definition at line 124 of file CrossSectionHandler.h.

References mps_fire::i, numberOfResonances_, parNum_, relativeCrossSectionVec_, MuScleFitGenFilter_cfi::resfind, and hcalRecHitTable_cff::variables.

Referenced by MuScleFitUtils::massProb(), and MuScleFitUtils::minimizeLikelihood().

124  {
125  // parNum_ is 0 in two cases:
126  // 1) if only one resonance is being fitted, in which case the relative cross section is
127  // fixed to one and there is no need to recompute it
128  // 2) if no resonance is being fitted, in which case all the relative cross sections will
129  // be set to 0.
130  // In both cases there is no need to make the transformation of variables.
131  if (parNum_ != 0) {
132  double* partialProduct = new double[numberOfResonances_];
133  double norm = 0.;
134  // Loop on all relative cross sections (that are parNum_+1)
135  for (unsigned int i = 0; i < parNum_ + 1; ++i) {
136  partialProduct[i] = std::accumulate(variables, variables + i, 1., std::multiplies<double>());
137  norm += partialProduct[i];
138  }
139  for (unsigned int i = 0; i < parNum_ + 1; ++i) {
140  relativeCrossSectionVec_[i] = partialProduct[i] / norm;
141  }
142  delete[] partialProduct;
143  }
144 
145  std::vector<double> allRelativeCrossSections;
146  std::vector<int>::const_iterator it = resfind.begin();
147  int smallerVectorIndex = 0;
148  for (; it != resfind.end(); ++it) {
149  if (*it == 0) {
150  allRelativeCrossSections.push_back(0.);
151  } else {
152  allRelativeCrossSections.push_back(relativeCrossSectionVec_[smallerVectorIndex]);
153  ++smallerVectorIndex;
154  }
155  }
156 
157  return allRelativeCrossSections;
158  }
std::vector< double > relativeCrossSectionVec_
unsigned int numberOfResonances_

◆ releaseParameters()

bool CrossSectionHandler::releaseParameters ( TMinuit &  rmin,
const std::vector< int > &  resfind,
const std::vector< int > &  parfix,
const int *  ind,
const int  iorder,
const unsigned int  shift 
)
inline

Use the information in resfind, parorder and parfix to release the N-1 variables.

Definition at line 97 of file CrossSectionHandler.h.

References mps_fire::i, numberOfResonances_, MuScleFitGenFilter_cfi::resfind, and edm::shift.

Referenced by MuScleFitUtils::minimizeLikelihood().

102  {
103  // Find the number of free cross section parameters in this iteration
104  unsigned int freeParNum = 0;
105  for (unsigned int ipar = 0; ipar < numberOfResonances_; ++ipar) {
106  if ((parfix[shift + ipar] == 0) && (ind[shift + ipar] <= iorder) && (resfind[ipar] == 1)) {
107  ++freeParNum;
108  }
109  }
110  if (freeParNum > 0) {
111  freeParNum = freeParNum - 1;
112  // Free only the first (freeParNum-1) of the N-1 variables
113  for (unsigned int i = 0; i < freeParNum; ++i) {
114  rmin.Release(shift + i);
115  }
116  return true;
117  }
118  return false;
119  }
unsigned int numberOfResonances_
static unsigned int const shift

◆ setParameters()

void CrossSectionHandler::setParameters ( double *  Start,
double *  Step,
double *  Mini,
double *  Maxi,
int *  ind,
TString *  parname,
const std::vector< double > &  parCrossSection,
const std::vector< int > &  parCrossSectionOrder,
const std::vector< int > &  resfind 
)
inline

Initializes the arrays needed by Minuit.

Definition at line 58 of file CrossSectionHandler.h.

References computeRelativeCrossSections(), imposeConstraint(), numberOfResonances_, parNum_, MuScleFitGenFilter_cfi::resfind, and vars_.

Referenced by MuScleFitUtils::minimizeLikelihood().

66  {
67  computeRelativeCrossSections(parCrossSection, resfind);
69 
70  double thisStep[] = {0.001, 0.001, 0.001, 0.001, 0.001};
71  TString thisParName[] = {"cross section var 1",
72  "cross section var 2",
73  "cross section var 3",
74  "cross section var 4",
75  "cross section var 5"};
76  double thisMini[] = {0., 0., 0., 0., 0.};
77  double thisMaxi[] = {1000., 1000., 1000., 1000., 1000.};
78 
79  // This is used to unlock the parameters in a given order. It is not
80  // a TMinuit parameter, but a MuScleFit parameter.
81  for (unsigned int iPar = 0; iPar < numberOfResonances_; ++iPar) {
82  ind[iPar] = parCrossSectionOrder[iPar];
83  }
84 
85  if (parNum_ > 0) {
86  for (unsigned int iPar = 0; iPar < parNum_; ++iPar) {
87  Start[iPar] = vars_[iPar];
88  Step[iPar] = thisStep[iPar];
89  Mini[iPar] = thisMini[iPar];
90  Maxi[iPar] = thisMaxi[iPar];
91  parname[iPar] = thisParName[iPar];
92  }
93  }
94  }
void computeRelativeCrossSections(const std::vector< double > &crossSection, const std::vector< int > &resfind)
std::vector< double > vars_
unsigned int numberOfResonances_
void imposeConstraint()
Change of variables so that we move from N to N-1 variables using the constraint that Sum(x_i) = 1...

Friends And Related Function Documentation

◆ TestCrossSectionHandler

friend class TestCrossSectionHandler
friend

Definition at line 29 of file CrossSectionHandler.h.

Member Data Documentation

◆ numberOfResonances_

unsigned int CrossSectionHandler::numberOfResonances_
protected

Definition at line 197 of file CrossSectionHandler.h.

Referenced by relativeCrossSections(), releaseParameters(), and setParameters().

◆ parNum_

unsigned int CrossSectionHandler::parNum_
protected

◆ relativeCrossSectionVec_

std::vector<double> CrossSectionHandler::relativeCrossSectionVec_
protected

◆ vars_

std::vector<double> CrossSectionHandler::vars_
protected