1 #ifndef BackgroundHandler_cc
2 #define BackgroundHandler_cc
8 #include <boost/foreach.hpp>
13 const std::vector<double> & leftWindowBorders,
14 const std::vector<double> & rightWindowBorders,
15 const double * ResMass,
16 const double * massWindowHalfWidth )
39 for(
unsigned int i=0;
i<6; ++
i ) {
40 double mass = ResMass[
i];
41 double lowerLimit = mass - massWindowHalfWidth[
i];
42 double upperLimit = mass + massWindowHalfWidth[
i];
44 std::vector<unsigned int>(1,
i),
53 double resMassForRegion[3];
54 resMassForRegion[0] = ResMass[0];
55 resMassForRegion[1] = (ResMass[1]+ResMass[2]+ResMass[3])/3;
56 resMassForRegion[2] = (ResMass[4]+ResMass[5])/2;
59 std::vector<std::vector<unsigned int> > indexes;
60 indexes.push_back(std::vector<unsigned int>(1,0));
61 indexes.push_back(std::vector<unsigned int>());
62 for(
int i=1;
i<=3; ++
i ) { indexes[1].push_back(
i); }
63 indexes.push_back(std::vector<unsigned int>());
64 for(
int i=4;
i<=5; ++
i ) { indexes[2].push_back(
i); }
67 typedef std::vector<unsigned int> indexVec;
68 BOOST_FOREACH(
const indexVec &
index, indexes) {
98 void BackgroundHandler::setParameters(
double* Start,
double*
Step,
double* Mini,
double* Maxi,
int* ind, TString* parname,
const std::vector<double> & parBgr,
const std::vector<int> & parBgrOrder,
const int muonType)
100 std::vector<double>::const_iterator parBgrIt = parBgr.begin();
101 std::vector<int>::const_iterator parBgrOrderIt = parBgrOrder.begin();
103 for(
int iReg = 0; iReg < 3; ++iReg ) {
105 backgroundWindow_[iReg].backgroundFunction()->setParameters( &(Start[shift]), &(Step[shift]), &(Mini[shift]),
106 &(Maxi[shift]), &(ind[shift]), &(parname[shift]),
107 parBgrIt+shift, parBgrOrderIt+shift, muonType );
109 for(
int iRes = 0; iRes < 6; ++iRes ) {
112 resonanceWindow_[iRes].backgroundFunction()->setParameters( &(Start[shift]), &(Step[shift]), &(Mini[shift]),
113 &(Maxi[shift]), &(ind[shift]), &(parname[shift]),
114 parBgrIt+shift, parBgrOrderIt+shift, muonType );
148 if( doBackgroundFit ) {
161 if( doBackgroundFit ) {
172 const std::vector<std::pair<reco::Particle::LorentzVector,reco::Particle::LorentzVector> > & muonPairs,
179 unsigned int iRegion = 0;
183 std::vector<double>::const_iterator parBgrIt = (parBgr.begin()+
parNumsRegions_[iRegion]);
186 double kOld = *parBgrIt;
187 double Nbw = backgroundWindow.
events();
188 double Ibw = backgroundFunctionForIntegral->Integral(backgroundWindow.
lowerBound(),
192 BOOST_FOREACH(
unsigned int index, *(backgroundWindow.
indexes()) )
199 double Irw = backgroundFunctionForIntegral->Integral(
resonanceWindow_[index].lowerBound(),
205 else parBgr[parNumsResonances_[
index]] = 0.;
208 if( parBgr[parNumsResonances_[index]] > 1. ) parBgr[parNumsResonances_[
index]] = 1.;
210 double kNew = parBgr[parNumsResonances_[
index]];
211 std::cout <<
"For resonance = " << index << std::endl;
212 std::cout <<
"backgroundWindow.lowerBound = " << backgroundWindow.
lowerBound() << std::endl;
213 std::cout <<
"backgroundWindow.upperBound = " << backgroundWindow.
upperBound() << std::endl;
214 std::cout <<
"parNumsResonances_["<<index<<
"] = " << parNumsResonances_[
index] << std::endl;
215 std::cout <<
"Nbw = " << Nbw <<
", Ibw = " << Ibw << std::endl;
216 std::cout <<
"Nrw = " << Nrw <<
", Irw = " << Irw << std::endl;
217 std::cout <<
"k = " << kOld <<
", k' = " << parBgr[parNumsResonances_[
index]] << std::endl;
218 std::cout <<
"background fraction in background window = Nbw*k = " << Nbw*kOld << std::endl;
219 std::cout <<
"background fraction in resonance window = Nrw*k' = " << Nrw*kNew << std::endl;
222 delete backgroundFunctionForIntegral;
227 const double * parval,
const int resTotNum,
const int ires,
228 const bool * resConsidered,
const double * ResMass,
const double ResHalfWidth[],
229 const int MuonType,
const double &
mass,
230 const double & eta1,
const double & eta2 )
232 if( doBackgroundFit ) {
261 std::pair<lorentzVector,lorentzVector> muonPair;
262 BOOST_FOREACH(muonPair, muonPairs) {
265 resonanceWindow.
count((muonPair.first + muonPair.second).mass(),
weight);
269 backgroundWindow.
count((muonPair.first + muonPair.second).mass(),
weight);
275 const std::vector<double> & leftWindowBorders,
276 const std::vector<double> & rightWindowBorders)
const throw(
cms::Exception)
278 if( leftWindowBorders.size() != rightWindowBorders.size() ) {
279 throw cms::Exception(
"Configuration") <<
"BackgroundHandler::BackgroundHandler: leftWindowBorders.size() = " << leftWindowBorders.size()
280 <<
" != rightWindowBorders.size() = " << rightWindowBorders.size() << std::endl;
282 if( leftWindowBorders.size() != 3 ) {
283 throw cms::Exception(
"Configuration") <<
"BackgroundHandler::BackgroundHandler: leftWindowBorders.size() = rightWindowBorders.size() = "
284 << leftWindowBorders.size() <<
" != 3" << std::endl;
286 if( identifiers.size() != 3 ) {
287 throw cms::Exception(
"Configuration") <<
"BackgroundHandler::BackgroundHandler: identifiers must match the number of regions = 3" << std::endl;
291 #endif // BackgroundHandler_cc
std::vector< MassWindow > backgroundWindow_
virtual TF1 * functionForIntegral(const std::vector< double >::const_iterator &parBgrIt) const
std::vector< MassWindow > resonanceWindow_
double upperBound() const
std::pair< double, double > backgroundFunction(const bool doBackgroundFit, const double *parval, const int resTotNum, const int ires, const bool *resConsidered, const double *ResMass, const double ResHalfWidth[], const int MuonType, const double &mass, const double &eta1, const double &eta2)
reco::Particle::LorentzVector lorentzVector
void count(const double &mass, const double &weight=1.)
double lowerBound() const
void rescale(std::vector< double > &parBgr, const double *ResMass, const double *massWindowHalfWidth, const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &muonPairs, const double &weight=1.)
double resMass(const bool doBackgroundFit, const int ires)
void consistencyCheck(const std::vector< int > &identifiers, const std::vector< double > &leftWindowBorders, const std::vector< double > &rightWindowBorders) const
Used to check the consistency of passed parameters.
void setParameters(double *Start, double *Step, double *Mini, double *Maxi, int *ind, TString *parname, const std::vector< double > &parBgr, const std::vector< int > &parBgrOrder, const int muonType)
Sets initial parameters for all the functions.
const std::vector< unsigned int > * indexes() const
backgroundFunctionBase * backgroundFunction() const
std::pair< double, double > windowBorders(const bool doBackgroundFit, const int ires)
Returns the appropriate window borders depending on whether the background is being fitted and on the...
bool unlockParameter(const std::vector< int > &resfind, const unsigned int ipar)
returns true if the parameter is to be unlocked
void countEventsInAllWindows(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &muonPairs, const double &weight)
static unsigned int const shift
int parNumsResonances_[6]
BackgroundHandler(const std::vector< int > &identifiers, const std::vector< double > &leftWindowBorders, const std::vector< double > &rightWindowBorders, const double *ResMass, const double *massWindowHalfWidth)
backgroundFunctionBase * backgroundFunctionService(const int identifier, const double &lowerLimit, const double &upperLimit)
Service to build the background functor corresponding to the passed identifier.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
void initializeParNums()
Initialize the parNums to be used in the shifts of parval.