CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
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_
 

Detailed Description

Handles the cross sections for MuScleFit.
What counts in the fit is the ratio of the cross sections. However it depends on which resonances are used in the fit. If we are fitting only the Upsilon(1S), for example, we do not need to consider the cross section ratio, because the probability of the other resonances will be 0. This is useful when running on MC to test the algorithm.

The constructor receives the array of cross sections and the array of resfind that tells which of the resonances are considered in the fit.
It builds the relative cross section parameters for each of the resonance and it has a method that unlocks the parameter accordingly.
If for example only the Upsilon(1S) is fitted, the relative cross section will be 1 and it will remain fixed.
The relative cross sections are fitted only when a background fit is done.

Note that this handles only the initialization of the cross sections, so that it is consistent with the fitted resonances, and the fix/release of the cross section parameters.

This assumes that resfind is the same during all the processing (it is saved internally when received in the constructor).

Definition at line 24 of file CrossSectionHandler.h.

Constructor & Destructor Documentation

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

Definition at line 27 of file CrossSectionHandler.h.

References computeRelativeCrossSections(), imposeConstraint(), parNum_, and vars_.

27  :
28  parNum_(0),
29  numberOfResonances_(resfind.size())
30  {
31  // The number of parameters is the number of fitted resonances minus 1
32  std::vector<int>::const_iterator it = resfind.begin();
33  for( ; it != resfind.end(); ++it ) {
34  if( *it != 0 ) ++parNum_;
35  }
36  if( parNum_ > 0 ) parNum_ = parNum_ - 1;
37 
38  vars_.resize(parNum_);
39 
40  computeRelativeCrossSections(crossSection, resfind);
42  }
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

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

Inputs the vars in a vector.

Definition at line 45 of file CrossSectionHandler.h.

References vars_.

Referenced by MuScleFit::duringFastLoop().

46  {
47  std::vector<double>::const_iterator it = vars_.begin();
48  for( ; it != vars_.end(); ++it ) {
49  initpar.push_back(*it);
50  }
51  }
std::vector< double > vars_
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 160 of file CrossSectionHandler.h.

References ires, and relativeCrossSectionVec_.

Referenced by CrossSectionHandler(), and setParameters().

161  {
162  relativeCrossSectionVec_.clear();
163  double normalization = 0.;
164  for( unsigned int ires = 0; ires < resfind.size(); ++ires ) {
165  if( resfind[ires] ) {
166  normalization += crossSection[ires];
167  }
168  }
169  if( normalization != 0. ) {
170  for( unsigned int ires = 0; ires < resfind.size(); ++ires ) {
171  if( resfind[ires] ) {
172  relativeCrossSectionVec_.push_back(crossSection[ires]/normalization);
173  }
174  }
175  }
176  }
int ires[2]
std::vector< double > relativeCrossSectionVec_
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 179 of file CrossSectionHandler.h.

References parNum_, relativeCrossSectionVec_, and vars_.

Referenced by CrossSectionHandler(), and setParameters().

180  {
181  if( parNum_ > 0 ) {
182  for( unsigned int iVar = 0; iVar < parNum_; ++iVar ) {
184  }
185  }
186  }
std::vector< double > vars_
std::vector< double > relativeCrossSectionVec_
unsigned int CrossSectionHandler::parNum ( )
inline

Definition at line 109 of file CrossSectionHandler.h.

References parNum_.

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

110  {
111  return parNum_;
112  }
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 115 of file CrossSectionHandler.h.

References i, numberOfResonances_, parNum_, and relativeCrossSectionVec_.

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

116  {
117  // parNum_ is 0 in two cases:
118  // 1) if only one resonance is being fitted, in which case the relative cross section is
119  // fixed to one and there is no need to recompute it
120  // 2) if no resonance is being fitted, in which case all the relative cross sections will
121  // be set to 0.
122  // In both cases there is no need to make the transformation of variables.
123  if( parNum_ != 0 ) {
124  double * partialProduct = new double[numberOfResonances_];
125  double norm = 0.;
126  // Loop on all relative cross sections (that are parNum_+1)
127  for( unsigned int i=0; i<parNum_+1; ++i ) {
128  partialProduct[i] = std::accumulate(variables, variables + i, 1., std::multiplies<double>());
129  norm += partialProduct[i];
130  }
131  for( unsigned int i=0; i<parNum_+1; ++i ) {
132  relativeCrossSectionVec_[i] = partialProduct[i]/norm;
133  }
134  delete[] partialProduct;
135  }
136 
137  std::vector<double> allRelativeCrossSections;
138  std::vector<int>::const_iterator it = resfind.begin();
139  int smallerVectorIndex = 0;
140  for( ; it != resfind.end(); ++it ) {
141  if( *it == 0 ) {
142  allRelativeCrossSections.push_back(0.);
143  }
144  else {
145  allRelativeCrossSections.push_back(relativeCrossSectionVec_[smallerVectorIndex]);
146  ++smallerVectorIndex;
147  }
148  }
149 
150  return allRelativeCrossSections;
151  }
int i
Definition: DBlmapReader.cc:9
std::vector< double > relativeCrossSectionVec_
unsigned int numberOfResonances_
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 88 of file CrossSectionHandler.h.

References i, and numberOfResonances_.

Referenced by MuScleFitUtils::minimizeLikelihood().

90  {
91  // Find the number of free cross section parameters in this iteration
92  unsigned int freeParNum = 0;
93  for( unsigned int ipar=0; ipar<numberOfResonances_; ++ipar ) {
94  if( (parfix[shift+ipar]==0) && (ind[shift+ipar]<=iorder) && (resfind[ipar] == 1) ) {
95  ++freeParNum;
96  }
97  }
98  if( freeParNum > 0 ) {
99  freeParNum = freeParNum - 1;
100  // Free only the first (freeParNum-1) of the N-1 variables
101  for( unsigned int i=0; i<freeParNum; ++i ) {
102  rmin.Release( shift+i );
103  }
104  return true;
105  }
106  return false;
107  }
int i
Definition: DBlmapReader.cc:9
unsigned int numberOfResonances_
int iorder
static unsigned int const shift
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 54 of file CrossSectionHandler.h.

References computeRelativeCrossSections(), imposeConstraint(), numberOfResonances_, parNum_, and vars_.

Referenced by MuScleFitUtils::minimizeLikelihood().

57  {
58  computeRelativeCrossSections(parCrossSection, resfind);
60 
61  double thisStep[] = {0.001, 0.001, 0.001, 0.001, 0.001};
62  TString thisParName[] = {"cross section var 1",
63  "cross section var 2",
64  "cross section var 3",
65  "cross section var 4",
66  "cross section var 5"};
67  double thisMini[] = {0., 0., 0., 0., 0.};
68  double thisMaxi[] = {1000., 1000., 1000., 1000., 1000.};
69 
70  // This is used to unlock the parameters in a given order. It is not
71  // a TMinuit parameter, but a MuScleFit parameter.
72  for( unsigned int iPar=0; iPar<numberOfResonances_; ++iPar ) {
73  ind[iPar] = parCrossSectionOrder[iPar];
74  }
75 
76  if( parNum_ > 0 ) {
77  for( unsigned int iPar=0; iPar<parNum_; ++iPar ) {
78  Start[iPar] = vars_[iPar];
79  Step[iPar] = thisStep[iPar];
80  Mini[iPar] = thisMini[iPar];
81  Maxi[iPar] = thisMaxi[iPar];
82  parname[iPar] = thisParName[iPar];
83  }
84  }
85  }
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 Data Documentation

unsigned int CrossSectionHandler::numberOfResonances_
protected

Definition at line 192 of file CrossSectionHandler.h.

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

unsigned int CrossSectionHandler::parNum_
protected
std::vector<double> CrossSectionHandler::relativeCrossSectionVec_
protected
std::vector<double> CrossSectionHandler::vars_
protected