Go to the documentation of this file.00001 #include "AnalysisDataFormats/TopObjects/interface/TtSemiLepEvtPartons.h"
00002 #include "TopQuarkAnalysis/TopJetCombination/plugins/TtSemiLepHypMaxSumPtWMass.h"
00003
00004 TtSemiLepHypMaxSumPtWMass::TtSemiLepHypMaxSumPtWMass(const edm::ParameterSet& cfg):
00005 TtSemiLepHypothesis( cfg ),
00006 maxNJets_ (cfg.getParameter<int> ("maxNJets" )),
00007 wMass_ (cfg.getParameter<double> ("wMass" )),
00008 useBTagging_ (cfg.getParameter<bool> ("useBTagging" )),
00009 bTagAlgorithm_ (cfg.getParameter<std::string>("bTagAlgorithm" )),
00010 minBDiscBJets_ (cfg.getParameter<double> ("minBDiscBJets" )),
00011 maxBDiscLightJets_ (cfg.getParameter<double> ("maxBDiscLightJets" )),
00012 neutrinoSolutionType_(cfg.getParameter<int> ("neutrinoSolutionType"))
00013 {
00014 if(maxNJets_<4 && maxNJets_!=-1)
00015 throw cms::Exception("WrongConfig")
00016 << "Parameter maxNJets can not be set to " << maxNJets_ << ". \n"
00017 << "It has to be larger than 4 or can be set to -1 to take all jets.";
00018 }
00019
00020 TtSemiLepHypMaxSumPtWMass::~TtSemiLepHypMaxSumPtWMass() { }
00021
00022 void
00023 TtSemiLepHypMaxSumPtWMass::buildHypo(edm::Event& evt,
00024 const edm::Handle<edm::View<reco::RecoCandidate> >& leps,
00025 const edm::Handle<std::vector<pat::MET> >& mets,
00026 const edm::Handle<std::vector<pat::Jet> >& jets,
00027 std::vector<int>& match, const unsigned int iComb)
00028 {
00029 if(leps->empty() || mets->empty() || jets->size()<4){
00030
00031 return;
00032 }
00033
00034 int maxNJets = maxNJets_;
00035 if(maxNJets_ == -1 || (int)jets->size() < maxNJets_) maxNJets = jets->size();
00036
00037 std::vector<bool> isBJet;
00038 std::vector<bool> isLJet;
00039 int cntBJets = 0;
00040 if(useBTagging_) {
00041 for(int idx=0; idx<maxNJets; ++idx) {
00042 isBJet.push_back( ((*jets)[idx].bDiscriminator(bTagAlgorithm_) > minBDiscBJets_ ) );
00043 isLJet.push_back( ((*jets)[idx].bDiscriminator(bTagAlgorithm_) < maxBDiscLightJets_) );
00044 if((*jets)[idx].bDiscriminator(bTagAlgorithm_) > minBDiscBJets_ )cntBJets++;
00045 }
00046 }
00047
00048 match.clear();
00049 for(int i=0; i<5; ++i)
00050 match.push_back(-1);
00051
00052
00053
00054
00055
00056 double maxPt=-1.;
00057 std::vector<int> maxPtIndices;
00058 maxPtIndices.push_back(-1);
00059 maxPtIndices.push_back(-1);
00060 maxPtIndices.push_back(-1);
00061 for(int idx=0; idx<maxNJets; ++idx){
00062 if(useBTagging_ && (!isLJet[idx] || (cntBJets<=2 && isBJet[idx]))) continue;
00063 for(int jdx=(idx+1); jdx<maxNJets; ++jdx){
00064 if(jdx==idx || (useBTagging_ && (!isLJet[jdx] || (cntBJets<=2 && isBJet[jdx]) || (cntBJets==3 && isBJet[idx] && isBJet[jdx])))) continue;
00065 for(int kdx=0; kdx<maxNJets; ++kdx){
00066 if(kdx==idx || kdx==jdx || (useBTagging_ && !isBJet[kdx])) continue;
00067 reco::Particle::LorentzVector sum =
00068 (*jets)[idx].p4()+
00069 (*jets)[jdx].p4()+
00070 (*jets)[kdx].p4();
00071 if( maxPt<0. || maxPt<sum.pt() ){
00072 maxPt=sum.pt();
00073 maxPtIndices.clear();
00074 maxPtIndices.push_back(idx);
00075 maxPtIndices.push_back(jdx);
00076 maxPtIndices.push_back(kdx);
00077 }
00078 }
00079 }
00080 }
00081
00082
00083
00084
00085
00086 double wDist =-1.;
00087 std::vector<int> closestToWMassIndices;
00088 closestToWMassIndices.push_back(-1);
00089 closestToWMassIndices.push_back(-1);
00090 if( isValid(maxPtIndices[0], jets) && isValid(maxPtIndices[1], jets) && isValid(maxPtIndices[2], jets)) {
00091 for(unsigned idx=0; idx<maxPtIndices.size(); ++idx){
00092 for(unsigned jdx=0; jdx<maxPtIndices.size(); ++jdx){
00093 if( jdx==idx || maxPtIndices[idx]>maxPtIndices[jdx] || (useBTagging_ && (!isLJet[maxPtIndices[idx]] || !isLJet[maxPtIndices[jdx]] || (cntBJets<=2 && isBJet[maxPtIndices[idx]]) || (cntBJets<=2 && isBJet[maxPtIndices[jdx]]) || (cntBJets==3 && isBJet[maxPtIndices[idx]] && isBJet[maxPtIndices[jdx]])))) continue;
00094 reco::Particle::LorentzVector sum =
00095 (*jets)[maxPtIndices[idx]].p4()+
00096 (*jets)[maxPtIndices[jdx]].p4();
00097 if( wDist<0. || wDist>fabs(sum.mass()-wMass_) ){
00098 wDist=fabs(sum.mass()-wMass_);
00099 closestToWMassIndices.clear();
00100 closestToWMassIndices.push_back(maxPtIndices[idx]);
00101 closestToWMassIndices.push_back(maxPtIndices[jdx]);
00102 }
00103 }
00104 }
00105 }
00106
00107
00108
00109
00110
00111
00112 maxPt=-1.;
00113 int lepB=-1;
00114 for(int idx=0; idx<maxNJets; ++idx){
00115 if(useBTagging_ && !isBJet[idx]) continue;
00116
00117 if( std::find(maxPtIndices.begin(), maxPtIndices.end(), idx) == maxPtIndices.end() ){
00118 reco::Particle::LorentzVector sum =
00119 (*jets)[idx].p4()+(*leps)[ 0 ].p4();
00120 if( maxPt<0. || maxPt<sum.pt() ){
00121 maxPt=sum.pt();
00122 lepB=idx;
00123 }
00124 }
00125 }
00126
00127
00128
00129
00130 if( isValid(closestToWMassIndices[0], jets) ){
00131 setCandidate(jets, closestToWMassIndices[0], lightQ_, jetCorrectionLevel("wQuarkMix"));
00132 match[TtSemiLepEvtPartons::LightQ] = closestToWMassIndices[0];
00133 }
00134
00135 if( isValid(closestToWMassIndices[1], jets) ){
00136 setCandidate(jets, closestToWMassIndices[1], lightQBar_, jetCorrectionLevel("wQuarkMix"));
00137 match[TtSemiLepEvtPartons::LightQBar] = closestToWMassIndices[1];
00138 }
00139
00140 for(unsigned idx=0; idx<maxPtIndices.size(); ++idx){
00141
00142 if( std::find( closestToWMassIndices.begin(), closestToWMassIndices.end(), maxPtIndices[idx]) == closestToWMassIndices.end() ){
00143
00144 if( isValid(maxPtIndices[idx], jets) ){
00145 setCandidate(jets, maxPtIndices[idx], hadronicB_, jetCorrectionLevel("bQuark"));
00146 match[TtSemiLepEvtPartons::HadB] = maxPtIndices[idx];
00147 break;
00148 }
00149 }
00150 }
00151
00152 if( isValid(lepB, jets) ){
00153 setCandidate(jets, lepB, leptonicB_, jetCorrectionLevel("bQuark"));
00154 match[TtSemiLepEvtPartons::LepB] = lepB;
00155 }
00156
00157
00158
00159
00160 setCandidate(leps, 0, lepton_);
00161 match[TtSemiLepEvtPartons::Lepton] = 0;
00162
00163
00164
00165
00166 if(neutrinoSolutionType_ == -1)
00167 setCandidate(mets, 0, neutrino_);
00168 else
00169 setNeutrino(mets, leps, 0, neutrinoSolutionType_);
00170 }