CMS 3D CMS Logo

Public Member Functions | Private Attributes

JetCombinatorics Class Reference

#include <JetCombinatorics.h>

List of all members.

Public Member Functions

void AnalyzeCombos ()
void ApplyFlavorCorrection (bool option=true)
void Clear ()
std::map< int, std::string > Combinatorics (int k, int max=6)
void FourJetsCombinations (std::vector< TLorentzVector > jets, std::vector< double > bdiscriminators)
Combo GetCombination (int n=0)
Combo GetCombinationSumEt (int n=0)
std::vector< TLorentzVector > GetComposites ()
int GetNumberOfCombos ()
 JetCombinatorics ()
std::map< int, std::string > NestedCombinatorics ()
void RemoveDuplicates (bool option)
void SetbTagPdf (TString name)
void SetFlavorCorrections (std::vector< double > vector)
void SetLeptonicW (TLorentzVector LepW)
void SetMaxMassHadW (double mass)
void SetMaxMassLepTop (double mass)
void SetMaxMassLepW (double mass)
void SetMaxNJets (int n)
void SetMinMassHadW (double mass)
void SetMinMassLepTop (double mass)
void SetMinMassLepW (double mass)
void SetSigmas (int type=0)
std::vector< TLorentzVector > ThreeCombos ()
std::vector< TLorentzVector > TwoCombos ()
void UsebTagging (bool option=true)
void UseMtopConstraint (bool option=true)
void Verbose ()
 ~JetCombinatorics ()

Private Attributes

std::map< Combo, int, minChi2allCombos_
std::map< Combo, int, maxSumEtallCombosSumEt_
TString bTagPdffilename_
std::vector< TLorentzVector > cand1_
std::vector< TLorentzVector > cand2_
std::vector< TLorentzVector > cand3_
double chi2_
std::vector< double > flavorCorrections_
double maxMassHadW_
double maxMassLepTop_
double maxMassLepW_
int maxNJets_
double minMassHadW_
double minMassLepTop_
double minMassLepW_
Double_t minPhi_
int ndf_
bool removeDuplicates_
int SigmasTypef
std::map< int, std::string > Template4jCombos_
std::map< int, std::string > Template5jCombos_
std::map< int, std::string > Template6jCombos_
std::map< int, std::string > Template7jCombos_
TLorentzVector theLepW_
bool UsebTagging_
bool UseFlv_
bool UseMtop_
bool verbosef

Detailed Description

Definition at line 272 of file JetCombinatorics.h.


Constructor & Destructor Documentation

JetCombinatorics::JetCombinatorics ( )

Definition at line 27 of file JetCombinatorics.cc.

References Clear(), Combinatorics(), maxMassHadW_, maxMassLepTop_, maxMassLepW_, maxNJets_, minMassHadW_, minMassLepTop_, minMassLepW_, minPhi_, NestedCombinatorics(), removeDuplicates_, SigmasTypef, Template4jCombos_, Template5jCombos_, Template6jCombos_, Template7jCombos_, UsebTagging_, UseFlv_, UseMtop_, and verbosef.

                                   {

        this->Clear();
                
        minMassLepW_ = -999999.;
        maxMassLepW_ = 999999.;
        minMassHadW_ = -999999.;
        maxMassHadW_ = 999999.;
        minMassLepTop_ = -999999.;
        maxMassLepTop_ = 999999.;
        
        minPhi_ = -1.;
        removeDuplicates_ = true;
        maxNJets_ = 9999;
        verbosef = false;
        UsebTagging_ = false;
        UseMtop_ = true;
        SigmasTypef = 0;
        UseFlv_ = false;
        
        Template4jCombos_ = NestedCombinatorics(); // 12 combinations
        Template5jCombos_ = Combinatorics(4,5); // 5 combinations of 4 combos
        Template6jCombos_ = Combinatorics(4,6); // 15 combinations of 4 combos
        Template7jCombos_ = Combinatorics(4,7); // xx combinations of 4 combos
        
}
JetCombinatorics::~JetCombinatorics ( )

Definition at line 55 of file JetCombinatorics.cc.

References Clear().

                                    {
  this->Clear();
}

Member Function Documentation

void JetCombinatorics::AnalyzeCombos ( )
void JetCombinatorics::ApplyFlavorCorrection ( bool  option = true) [inline]

Definition at line 307 of file JetCombinatorics.h.

References UseFlv_.

{ UseFlv_ = option; }
void JetCombinatorics::Clear ( )
std::map< int, std::string > JetCombinatorics::Combinatorics ( int  k,
int  max = 6 
)

Definition at line 74 of file JetCombinatorics.cc.

References i, itoa(), j, gen::k, list(), m, max(), and n.

Referenced by JetCombinatorics().

                                                                       {

        // find a combinatorics template
        // This is a simple stupid function to make algebratic combinatorics

        int kcombos = n;
        int maxcombos = max;

        std::string list;

        for ( int m=0; m<maxcombos; m++) { list = list + (itoa(m));}

        std::string seed;
        for ( int m=0; m<kcombos; m++) { seed = seed + (itoa(m));}

        
        std::map< int, std::string > aTemplateCombos;
        aTemplateCombos.clear();
        
        aTemplateCombos[0] = seed;

        int i = 0;
        int totalmatches = seed.size();
        int totalIte = list.size();

        for ( int ite = 0; ite < ((int)totalIte); ite++) {

                //cout << "iteration " << ite << endl;
                //i = 0;
                //for ( Itevec = seed.begin(); Itevec != seed.end(); ++Itevec) {
                for ( i=0; i< (int) totalmatches; i++) {

                        std::string newseed = aTemplateCombos[ite];
                        std::string newseed2;
                        /*
                        cout << "newseed size= " << newseed.size() << " : ";
                        for (std::vector< std::string>::iterator iite = newseed.begin();
                                 iite != newseed.end(); ++iite) {

                                cout << *iite << " ";
                        }
                        cout << endl;
                        */
                        for ( int itemp=0; itemp<(int)newseed.size(); itemp++) {
                                if (itemp!=i) newseed2 = newseed2 + (newseed[itemp]);
                        }
                        /*
                        cout << "newseed2: ";
                        for (std::vector< std::string>::iterator iite = newseed2.begin();
                                 iite != newseed2.end(); ++iite) {

                                cout << *iite << " ";
                        }
                        cout << endl;
                        */
                        for ( int j=0; j<(int) list.size(); j++) {
                                //cout << " j = " << j << endl;
                                bool Isnewelement = true;
                                std::string newelement = "0";
                                //bool Isnewcombo = true;
                                for (int k=0; k< (int)newseed2.size(); k++) {
                                        if ( list[j] == newseed2[k] ) Isnewelement = false;
                                }
                                if (Isnewelement) {

                                        newelement = list[j];
                                        //cout << "new element: " << newelement << endl;

                                        std::string candseed = newseed2;
                                        candseed = candseed + newelement;

                                        bool IsnewCombo = true;
                                        for (int ic=0; ic<(int)aTemplateCombos.size(); ++ic ) {

                                                int nmatch = 0;
                                                for ( int ij=0; ij<(int)(aTemplateCombos[ic]).size(); ij++) {

                                                        for (int ik=0; ik<(int)candseed.size(); ik++) {
                                                                if ( candseed[ik] == aTemplateCombos[ic][ij] ) nmatch++;
                                                        }
                                                }
                                                if (nmatch == (int)totalmatches)
                                                        IsnewCombo = false;

                                        }
                                        if (IsnewCombo) {
                                                //cout << "new combo"<< " before combo size=" << aTemplateCombos.size() << endl;
                                                aTemplateCombos[(int)aTemplateCombos.size()] = candseed;
                                                //cout << " after size = " << aTemplateCombos.size() << endl;
                                        }
                                }

                        }
                }
        }//close iterations

        // debug info
        
        //std::cout << " build templates for total combos = " << aTemplateCombos.size() << std::endl;
        //std::cout << " template combos: " << std::endl;
        //for (size_t ic=0; ic != aTemplateCombos.size(); ++ic) {

        //std::cout << aTemplateCombos[ic] << std::endl;
        //}
        
        return aTemplateCombos;
        
        
        
}
void JetCombinatorics::FourJetsCombinations ( std::vector< TLorentzVector >  jets,
std::vector< double >  bdiscriminators 
)

Definition at line 212 of file JetCombinatorics.cc.

References allCombos_, allCombosSumEt_, Combo::analyze(), Combo::ApplyFlavorCorrections(), bTagPdffilename_, gather_cfg::cout, flavorCorrections_, Combo::GetHadW(), Combo::GetLepTop(), Combo::GetLepW(), maxMassHadW_, maxMassLepTop_, maxMassLepW_, maxNJets_, minMassHadW_, minMassLepTop_, minMassLepW_, n, Combo::Print(), Combo::SetbDiscPdf(), Combo::SetFlvCorrHadb(), Combo::SetFlvCorrLepb(), Combo::SetFlvCorrWp(), Combo::SetFlvCorrWq(), Combo::SetHadb(), Combo::SetHadb_disc(), Combo::SetIdHadb(), Combo::SetIdLepb(), Combo::SetIdWp(), Combo::SetIdWq(), Combo::SetLepb(), Combo::SetLepb_disc(), Combo::SetLepW(), Combo::SetSigmas(), Combo::SetWp(), Combo::SetWp_disc(), Combo::SetWq(), Combo::SetWq_disc(), SigmasTypef, Template4jCombos_, Template5jCombos_, Template6jCombos_, Template7jCombos_, theLepW_, Combo::Usebtagging(), UsebTagging_, UseFlv_, UseMtop_, Combo::UseMtopConstraint(), and verbosef.

                                                                                                              {


        int n = 0; // total number of combos
        std::map< Combo, int, minChi2 > allCombos;
        std::map< Combo, int, maxSumEt > allCombosSumEt;
        
        std::map< int, std::string > aTemplateCombos;
        aTemplateCombos.clear();

        if ( jets.size() == 4 ) aTemplateCombos[0] = std::string("0123");
        if ( jets.size() == 5 ) aTemplateCombos = Template5jCombos_;
        if ( jets.size() == 6 ) aTemplateCombos = Template6jCombos_;
        if ( jets.size() == 7 ) aTemplateCombos = Template7jCombos_;    

        // force to use only 4 jets
        if ( maxNJets_ == 4 ) aTemplateCombos[0] = std::string("0123");
        
        if (verbosef) std::cout << "[JetCombinatorics] size of vector of jets = " << jets.size() << std::endl;
        
        for (size_t ic=0; ic != aTemplateCombos.size(); ++ic) {

                if (verbosef) std::cout << "[JetCombinatorics] get 4 jets from the list, cluster # " << ic << "/"<< aTemplateCombos.size()-1 << std::endl;
                
                // get a template
                std::string aTemplate = aTemplateCombos[ic];

                if (verbosef) std::cout << "[JetCombinatorics] template of 4 jets = " << aTemplate << std::endl;
                
                // make a list of 4 jets
                std::vector< TLorentzVector > the4jets;
                std::vector< int > the4Ids;
                std::vector< double > thebdisc;
                std::vector< double > theFlvCorr;
                //the4jets[0] = jets[0];
                
                for (int ij=0; ij<4; ij++) {
                        //std::cout << "ij= " << ij << std::endl;
                        //std::cout << "atoi = " << atoi((aTemplate.substr(0,1)).c_str()) << std::endl;
                        //std::cout << "jets[].Pt = " << jets[ij].Pt() << std::endl;
                        int tmpi = atoi((aTemplate.substr(ij,1)).c_str());
                        //std::cout << "tmpi= " << tmpi << std::endl;
                        the4jets.push_back(jets[tmpi]);
                        the4Ids.push_back(tmpi);
                        if ( UsebTagging_ ) thebdisc.push_back( bdiscriminators[tmpi] );
                        if ( UseFlv_ ) theFlvCorr.push_back( flavorCorrections_[tmpi] );
                }

                if (verbosef) std::cout<< "[JetCombinatorics] with these 4 jets, make 12 combinations: " <<std::endl;

                //std::cout << " the4jets[ij].size = " << the4jets.size() << std::endl;
                        
                for (size_t itemplate=0; itemplate!= Template4jCombos_.size(); ++itemplate) {
                        
                        std::string a4template = Template4jCombos_[itemplate];

                        if (verbosef) std::cout << "[JetCombinatorics] ==> combination: " << a4template << " is # " << itemplate << "/"<<  Template4jCombos_.size()-1 << std::endl;
                        
                        Combo acombo;
                        
                        acombo.SetWp( the4jets[atoi((a4template.substr(0,1)).c_str())] );
                        acombo.SetWq( the4jets[atoi((a4template.substr(1,1)).c_str())] );
                        acombo.SetHadb( the4jets[atoi((a4template.substr(2,1)).c_str())] );
                        acombo.SetLepb( the4jets[atoi((a4template.substr(3,1)).c_str())] );
                        acombo.SetLepW( theLepW_ );

                        acombo.SetIdWp( the4Ids[atoi((a4template.substr(0,1)).c_str())] );
                        acombo.SetIdWq( the4Ids[atoi((a4template.substr(1,1)).c_str())] );
                        acombo.SetIdHadb( the4Ids[atoi((a4template.substr(2,1)).c_str())] );
                        acombo.SetIdLepb( the4Ids[atoi((a4template.substr(3,1)).c_str())] );
                        //std::cout << " acombo setup" << std::endl;

                        if ( UseFlv_ ) {
                                acombo.SetFlvCorrWp( theFlvCorr[atoi((a4template.substr(0,1)).c_str())] );
                                acombo.SetFlvCorrWq( theFlvCorr[atoi((a4template.substr(1,1)).c_str())] );
                                acombo.SetFlvCorrHadb( theFlvCorr[atoi((a4template.substr(2,1)).c_str())] );
                                acombo.SetFlvCorrLepb( theFlvCorr[atoi((a4template.substr(3,1)).c_str())] );
                                acombo.ApplyFlavorCorrections();
                        }
                        if ( UsebTagging_ ) {

                                acombo.Usebtagging();
                                acombo.SetbDiscPdf(bTagPdffilename_);
                                acombo.SetWp_disc( thebdisc[atoi((a4template.substr(0,1)).c_str())] );
                                acombo.SetWq_disc( thebdisc[atoi((a4template.substr(1,1)).c_str())] );
                                acombo.SetHadb_disc( thebdisc[atoi((a4template.substr(2,1)).c_str())] );
                                acombo.SetLepb_disc( thebdisc[atoi((a4template.substr(3,1)).c_str())] );
                                
                        }

                        acombo.UseMtopConstraint(UseMtop_);
                        // choose value of sigmas
                        acombo.SetSigmas(SigmasTypef);

                        acombo.analyze();

                        if (verbosef) {

                          std::cout << "[JetCombinatorics] ==> combination done:" << std::endl;
                          acombo.Print();
                        }

                        // invariant mass cuts
                        TLorentzVector aHadWP4 = acombo.GetHadW();
                        TLorentzVector aLepWP4 = acombo.GetLepW();
                        TLorentzVector aLepTopP4=acombo.GetLepTop();
                        
                        if ( ( aHadWP4.M() > minMassHadW_ && aHadWP4.M() < maxMassHadW_ ) &&
                                 ( aLepWP4.M() > minMassLepW_ && aLepWP4.M() < maxMassLepW_ ) &&
                                 ( aLepTopP4.M() > minMassLepTop_ && aLepTopP4.M() < maxMassLepTop_) ) {
                        
                                allCombos[acombo] = n;
                                allCombosSumEt[acombo] = n;
                        
                                n++;
                        }
                
                }
        }

        allCombos_ = allCombos;
        allCombosSumEt_ = allCombosSumEt;
       
}
Combo JetCombinatorics::GetCombination ( int  n = 0)

Definition at line 337 of file JetCombinatorics.cc.

References a, allCombos_, and j.

                                            {

        int j = 0;
        Combo a;
        for ( std::map<Combo,int,minChi2>::const_iterator ite=allCombos_.begin();
                  ite!=allCombos_.end(); ++ite) {
                
                if (j == n) a = ite->first;
                j++;
        }

        return a;

        
}
Combo JetCombinatorics::GetCombinationSumEt ( int  n = 0)

Definition at line 353 of file JetCombinatorics.cc.

References a, allCombosSumEt_, and j.

                                                 {

        int j = 0;
        Combo a;
        for ( std::map<Combo,int,maxSumEt>::const_iterator ite=allCombosSumEt_.begin();
                  ite!=allCombosSumEt_.end(); ++ite) {
                
                if (j == n) a = ite->first;
                j++;
        }

        return a;

        
}
std::vector< TLorentzVector > JetCombinatorics::GetComposites ( )
int JetCombinatorics::GetNumberOfCombos ( ) [inline]

Definition at line 291 of file JetCombinatorics.h.

References allCombos_.

{ return ( (int)allCombos_.size() ); } 
std::map< int, std::string > JetCombinatorics::NestedCombinatorics ( )

Definition at line 187 of file JetCombinatorics.cc.

Referenced by JetCombinatorics().

                                                               {

        // build by hand 12 combinations for semileptonic top decays

        std::map< int, std::string > aTemplateCombos;
        aTemplateCombos.clear();
        
        aTemplateCombos[0] = "0123";
        aTemplateCombos[1] = "0132";
        aTemplateCombos[2] = "0213";
        aTemplateCombos[3] = "0231";
        aTemplateCombos[4] = "0312";
        aTemplateCombos[5] = "0321";
        aTemplateCombos[6] = "1203";
        aTemplateCombos[7] = "1230";
        aTemplateCombos[8] = "1302";
        aTemplateCombos[9] = "1320";
        aTemplateCombos[10] = "2301";
        aTemplateCombos[11] = "2310";
                
        return aTemplateCombos;

}
void JetCombinatorics::RemoveDuplicates ( bool  option) [inline]

Definition at line 315 of file JetCombinatorics.h.

References removeDuplicates_.

{ removeDuplicates_ = option; }
void JetCombinatorics::SetbTagPdf ( TString  name) [inline]
void JetCombinatorics::SetFlavorCorrections ( std::vector< double >  vector) [inline]

Definition at line 287 of file JetCombinatorics.h.

References flavorCorrections_.

{ flavorCorrections_ = vector; }
void JetCombinatorics::SetLeptonicW ( TLorentzVector  LepW) [inline]

Definition at line 297 of file JetCombinatorics.h.

References TtSemiLepDaughter::LepW, and theLepW_.

{ theLepW_ = LepW; }
void JetCombinatorics::SetMaxMassHadW ( double  mass) [inline]

Definition at line 302 of file JetCombinatorics.h.

References scaleCards::mass, and maxMassHadW_.

void JetCombinatorics::SetMaxMassLepTop ( double  mass) [inline]

Definition at line 304 of file JetCombinatorics.h.

References scaleCards::mass, and maxMassLepTop_.

void JetCombinatorics::SetMaxMassLepW ( double  mass) [inline]

Definition at line 300 of file JetCombinatorics.h.

References scaleCards::mass, and maxMassLepW_.

void JetCombinatorics::SetMaxNJets ( int  n) [inline]

Definition at line 288 of file JetCombinatorics.h.

References maxNJets_, and n.

{ maxNJets_ = n; }
void JetCombinatorics::SetMinMassHadW ( double  mass) [inline]

Definition at line 301 of file JetCombinatorics.h.

References scaleCards::mass, and minMassHadW_.

void JetCombinatorics::SetMinMassLepTop ( double  mass) [inline]

Definition at line 303 of file JetCombinatorics.h.

References scaleCards::mass, and minMassLepTop_.

void JetCombinatorics::SetMinMassLepW ( double  mass) [inline]

Definition at line 299 of file JetCombinatorics.h.

References scaleCards::mass, and minMassLepW_.

void JetCombinatorics::SetSigmas ( int  type = 0) [inline]

Definition at line 294 of file JetCombinatorics.h.

References SigmasTypef.

                                     {
          SigmasTypef = type;
        }
std::vector< TLorentzVector > JetCombinatorics::ThreeCombos ( )
std::vector< TLorentzVector > JetCombinatorics::TwoCombos ( )
void JetCombinatorics::UsebTagging ( bool  option = true) [inline]

Definition at line 306 of file JetCombinatorics.h.

References UsebTagging_.

{ UsebTagging_ = option; }
void JetCombinatorics::UseMtopConstraint ( bool  option = true) [inline]

Definition at line 308 of file JetCombinatorics.h.

References UseMtop_.

{ UseMtop_ = option; }
void JetCombinatorics::Verbose ( ) [inline]

Definition at line 279 of file JetCombinatorics.h.

References verbosef.

                       {
          verbosef = true;
        }

Member Data Documentation

std::map< Combo, int, minChi2 > JetCombinatorics::allCombos_ [private]

Definition at line 348 of file JetCombinatorics.h.

Referenced by Clear(), FourJetsCombinations(), GetCombination(), and GetNumberOfCombos().

std::map< Combo, int, maxSumEt > JetCombinatorics::allCombosSumEt_ [private]

Definition at line 349 of file JetCombinatorics.h.

Referenced by Clear(), FourJetsCombinations(), and GetCombinationSumEt().

Definition at line 336 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), and SetbTagPdf().

std::vector< TLorentzVector > JetCombinatorics::cand1_ [private]

Definition at line 356 of file JetCombinatorics.h.

Referenced by Clear().

std::vector< TLorentzVector > JetCombinatorics::cand2_ [private]

Definition at line 357 of file JetCombinatorics.h.

std::vector< TLorentzVector > JetCombinatorics::cand3_ [private]

Definition at line 358 of file JetCombinatorics.h.

double JetCombinatorics::chi2_ [private]

Definition at line 352 of file JetCombinatorics.h.

std::vector< double > JetCombinatorics::flavorCorrections_ [private]

Definition at line 332 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), and SetFlavorCorrections().

Definition at line 344 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and SetMaxMassHadW().

Definition at line 346 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and SetMaxMassLepTop().

Definition at line 342 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and SetMaxMassLepW().

Definition at line 333 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and SetMaxNJets().

Definition at line 343 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and SetMinMassHadW().

Definition at line 345 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and SetMinMassLepTop().

Definition at line 341 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and SetMinMassLepW().

Double_t JetCombinatorics::minPhi_ [private]

Definition at line 351 of file JetCombinatorics.h.

Referenced by JetCombinatorics().

int JetCombinatorics::ndf_ [private]

Definition at line 353 of file JetCombinatorics.h.

Definition at line 354 of file JetCombinatorics.h.

Referenced by JetCombinatorics(), and RemoveDuplicates().

Definition at line 325 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and SetSigmas().

std::map< int, std::string > JetCombinatorics::Template4jCombos_ [private]

Definition at line 327 of file JetCombinatorics.h.

Referenced by Clear(), FourJetsCombinations(), and JetCombinatorics().

std::map< int, std::string > JetCombinatorics::Template5jCombos_ [private]

Definition at line 328 of file JetCombinatorics.h.

Referenced by Clear(), FourJetsCombinations(), and JetCombinatorics().

std::map< int, std::string > JetCombinatorics::Template6jCombos_ [private]

Definition at line 329 of file JetCombinatorics.h.

Referenced by Clear(), FourJetsCombinations(), and JetCombinatorics().

std::map< int, std::string > JetCombinatorics::Template7jCombos_ [private]

Definition at line 330 of file JetCombinatorics.h.

Referenced by Clear(), FourJetsCombinations(), and JetCombinatorics().

TLorentzVector JetCombinatorics::theLepW_ [private]

Definition at line 339 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), and SetLeptonicW().

Definition at line 334 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and UsebTagging().

bool JetCombinatorics::UseFlv_ [private]

Definition at line 335 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and UseMtopConstraint().

Definition at line 326 of file JetCombinatorics.h.

Referenced by FourJetsCombinations(), JetCombinatorics(), and Verbose().