1 #ifndef BackgroundHandler_cc 2 #define BackgroundHandler_cc 12 const std::vector<double> & leftWindowBorders,
13 const std::vector<double> & rightWindowBorders,
14 const double * ResMass,
15 const double * massWindowHalfWidth )
38 for(
unsigned int i=0;
i<6; ++
i ) {
39 double mass = ResMass[
i];
40 double lowerLimit = mass - massWindowHalfWidth[
i];
41 double upperLimit = mass + massWindowHalfWidth[
i];
43 std::vector<unsigned int>(1,
i),
52 double resMassForRegion[3];
53 resMassForRegion[0] = ResMass[0];
54 resMassForRegion[1] = (ResMass[1]+ResMass[2]+ResMass[3])/3;
55 resMassForRegion[2] = (ResMass[4]+ResMass[5])/2;
58 std::vector<std::vector<unsigned int> > indexes;
59 indexes.push_back(std::vector<unsigned int>(1,0));
60 indexes.push_back(std::vector<unsigned int>());
61 for(
int i=1;
i<=3; ++
i ) { indexes[1].push_back(
i); }
62 indexes.push_back(std::vector<unsigned int>());
63 for(
int i=4;
i<=5; ++
i ) { indexes[2].push_back(
i); }
66 typedef std::vector<unsigned int> indexVec;
67 for(
auto const&
index : indexes) {
97 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)
99 std::vector<double>::const_iterator parBgrIt = parBgr.begin();
100 std::vector<int>::const_iterator parBgrOrderIt = parBgrOrder.begin();
102 for(
int iReg = 0; iReg < 3; ++iReg ) {
104 backgroundWindow_[iReg].backgroundFunction()->setParameters( &(Start[shift]), &(Step[shift]), &(Mini[shift]),
105 &(Maxi[shift]), &(ind[shift]), &(parname[shift]),
106 parBgrIt+shift, parBgrOrderIt+shift, muonType );
108 for(
int iRes = 0; iRes < 6; ++iRes ) {
111 resonanceWindow_[iRes].backgroundFunction()->setParameters( &(Start[shift]), &(Step[shift]), &(Mini[shift]),
112 &(Maxi[shift]), &(ind[shift]), &(parname[shift]),
113 parBgrIt+shift, parBgrOrderIt+shift, muonType );
147 if( doBackgroundFit ) {
160 if( doBackgroundFit ) {
171 const std::vector<std::pair<reco::Particle::LorentzVector,reco::Particle::LorentzVector> > & muonPairs,
178 unsigned int iRegion = 0;
182 std::vector<double>::const_iterator parBgrIt = (parBgr.begin()+
parNumsRegions_[iRegion]);
183 TF1 * backgroundFunctionForIntegral = backgroundWindow.backgroundFunction()->functionForIntegral(parBgrIt);
185 double kOld = *parBgrIt;
186 double Nbw = backgroundWindow.events();
187 double Ibw = backgroundFunctionForIntegral->Integral(backgroundWindow.lowerBound(),
188 backgroundWindow.upperBound());
191 for(
unsigned int index : *(backgroundWindow.indexes()) )
204 else parBgr[parNumsResonances_[
index]] = 0.;
207 if( parBgr[parNumsResonances_[
index]] > 1. ) parBgr[parNumsResonances_[
index]] = 1.;
209 double kNew = parBgr[parNumsResonances_[
index]];
211 std::cout <<
"backgroundWindow.lowerBound = " << backgroundWindow.lowerBound() << std::endl;
212 std::cout <<
"backgroundWindow.upperBound = " << backgroundWindow.upperBound() << std::endl;
213 std::cout <<
"parNumsResonances_["<<
index<<
"] = " << parNumsResonances_[
index] << std::endl;
214 std::cout <<
"Nbw = " << Nbw <<
", Ibw = " << Ibw << std::endl;
215 std::cout <<
"Nrw = " << Nrw <<
", Irw = " << Irw << std::endl;
216 std::cout <<
"k = " << kOld <<
", k' = " << parBgr[parNumsResonances_[
index]] << std::endl;
217 std::cout <<
"background fraction in background window = Nbw*k = " << Nbw*kOld << std::endl;
218 std::cout <<
"background fraction in resonance window = Nrw*k' = " << Nrw*kNew << std::endl;
221 delete backgroundFunctionForIntegral;
226 const double * parval,
const int resTotNum,
const int ires,
227 const bool * resConsidered,
const double * ResMass,
const double ResHalfWidth[],
228 const int MuonType,
const double &
mass,
229 const double & eta1,
const double & eta2 )
231 if( doBackgroundFit ) {
252 resonanceWindow.resetCounter();
256 backgroundWindow.resetCounter();
260 std::pair<lorentzVector,lorentzVector> muonPair;
261 for(
auto const& muonPair : muonPairs) {
263 for(
auto& resonanceWindow : resonanceWindow_) {
264 resonanceWindow.count((muonPair.first + muonPair.second).mass(),
weight);
267 for(
auto& backgroundWindow : backgroundWindow_) {
268 backgroundWindow.count((muonPair.first + muonPair.second).mass(),
weight);
274 const std::vector<double> & leftWindowBorders,
275 const std::vector<double> & rightWindowBorders)
const noexcept(
false)
277 if( leftWindowBorders.size() != rightWindowBorders.size() ) {
278 throw cms::Exception(
"Configuration") <<
"BackgroundHandler::BackgroundHandler: leftWindowBorders.size() = " << leftWindowBorders.size()
279 <<
" != rightWindowBorders.size() = " << rightWindowBorders.size() << std::endl;
281 if( leftWindowBorders.size() != 3 ) {
282 throw cms::Exception(
"Configuration") <<
"BackgroundHandler::BackgroundHandler: leftWindowBorders.size() = rightWindowBorders.size() = " 283 << leftWindowBorders.size() <<
" != 3" << std::endl;
285 if( identifiers.size() != 3 ) {
286 throw cms::Exception(
"Configuration") <<
"BackgroundHandler::BackgroundHandler: identifiers must match the number of regions = 3" << std::endl;
290 #endif // BackgroundHandler_cc
std::vector< MassWindow > backgroundWindow_
std::vector< MassWindow > resonanceWindow_
void consistencyCheck(const std::vector< int > &identifiers, const std::vector< double > &leftWindowBorders, const std::vector< double > &rightWindowBorders) const (false)
Used to check the consistency of passed parameters.
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 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 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.
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.