Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:32

0001 //
0002 //
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "AnalysisDataFormats/TopObjects/interface/TtSemiEvtSolution.h"
0006 #include "DataFormats/Candidate/interface/ShallowClonePtrCandidate.h"
0007 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
0008 
0009 TtSemiEvtSolution::TtSemiEvtSolution()
0010     : mcHyp_("ttSemiEvtMCHyp"), recoHyp_("ttSemiEvtRecoHyp"), fitHyp_("ttSemiEvtFitHyp") {
0011   jetCorrScheme_ = 0;
0012   sumAnglejp_ = -999.;
0013   angleHadp_ = -999.;
0014   angleHadq_ = -999.;
0015   angleHadb_ = -999.;
0016   angleLepb_ = -999.;
0017   changeWQ_ = -999;
0018   probChi2_ = -999.;
0019   mcBestJetComb_ = -999;
0020   simpleBestJetComb_ = -999;
0021   lrBestJetComb_ = -999;
0022   lrJetCombLRval_ = -999.;
0023   lrJetCombProb_ = -999.;
0024   lrSignalEvtLRval_ = -999.;
0025   lrSignalEvtProb_ = -999.;
0026 }
0027 
0028 TtSemiEvtSolution::~TtSemiEvtSolution() {}
0029 
0030 //-------------------------------------------
0031 // get calibrated base objects
0032 //-------------------------------------------
0033 pat::Jet TtSemiEvtSolution::getHadb() const {
0034   // WARNING this is obsolete and only
0035   // kept for backwards compatibility
0036   if (jetCorrScheme_ == 1)
0037     return hadb_->correctedJet("HAD", "B");  // calibrate jets according to MC truth
0038   else if (jetCorrScheme_ == 2)
0039     return hadb_->correctedJet("HAD", "B");
0040   else
0041     return *hadb_;
0042 }
0043 
0044 pat::Jet TtSemiEvtSolution::getHadp() const {
0045   // WARNING this is obsolete and only
0046   // kept for backwards compatibility
0047   if (jetCorrScheme_ == 1)
0048     return hadp_->correctedJet("HAD", "UDS");  // calibrate jets according to MC truth
0049   else if (jetCorrScheme_ == 2)
0050     return hadp_->correctedJet("HAD", "UDS");
0051   else
0052     return *hadp_;
0053 }
0054 
0055 pat::Jet TtSemiEvtSolution::getHadq() const {
0056   // WARNING this is obsolete and only
0057   // kept for backwards compatibility
0058   if (jetCorrScheme_ == 1)
0059     return hadq_->correctedJet("HAD", "UDS");  // calibrate jets according to MC truth
0060   else if (jetCorrScheme_ == 2)
0061     return hadq_->correctedJet("HAD", "UDS");
0062   else
0063     return *hadq_;
0064 }
0065 
0066 pat::Jet TtSemiEvtSolution::getLepb() const {
0067   // WARNING this is obsolete and only
0068   // kept for backwards compatibility
0069   if (jetCorrScheme_ == 1)
0070     return lepb_->correctedJet("HAD", "B");  // calibrate jets according to MC truth
0071   else if (jetCorrScheme_ == 2)
0072     return lepb_->correctedJet("HAD", "B");
0073   else
0074     return *lepb_;
0075 }
0076 
0077 //-------------------------------------------
0078 // get (un-)/calibrated reco objects
0079 //-------------------------------------------
0080 reco::Particle TtSemiEvtSolution::getRecHadt() const {
0081   // FIXME: the charge from the genevent
0082   return reco::Particle(0, this->getRecHadp().p4() + this->getRecHadq().p4() + this->getRecHadb().p4());
0083 }
0084 
0085 reco::Particle TtSemiEvtSolution::getRecHadW() const {
0086   // FIXME: the charge from the genevent
0087   return reco::Particle(0, this->getRecHadp().p4() + this->getRecHadq().p4());
0088 }
0089 
0090 reco::Particle TtSemiEvtSolution::getRecLept() const {
0091   // FIXME: the charge from the genevent
0092   reco::Particle p;
0093   if (this->getDecay() == "muon")
0094     p = reco::Particle(0, this->getRecLepm().p4() + this->getRecLepn().p4() + this->getRecLepb().p4());
0095   if (this->getDecay() == "electron")
0096     p = reco::Particle(0, this->getRecLepe().p4() + this->getRecLepn().p4() + this->getRecLepb().p4());
0097   return p;
0098 }
0099 
0100 reco::Particle TtSemiEvtSolution::getRecLepW() const {
0101   // FIXME: the charge from the genevent
0102   reco::Particle p;
0103   if (this->getDecay() == "muon")
0104     p = reco::Particle(0, this->getRecLepm().p4() + this->getRecLepn().p4());
0105   if (this->getDecay() == "electron")
0106     p = reco::Particle(0, this->getRecLepe().p4() + this->getRecLepn().p4());
0107   return p;
0108 }
0109 
0110 // FIXME: Why these functions??? Not needed!
0111 // methods to get calibrated objects
0112 reco::Particle TtSemiEvtSolution::getCalHadt() const {
0113   return reco::Particle(0, this->getCalHadp().p4() + this->getCalHadq().p4() + this->getCalHadb().p4());
0114 }
0115 
0116 reco::Particle TtSemiEvtSolution::getCalHadW() const {
0117   return reco::Particle(0, this->getCalHadp().p4() + this->getCalHadq().p4());
0118 }
0119 
0120 reco::Particle TtSemiEvtSolution::getCalLept() const {
0121   reco::Particle p;
0122   if (this->getDecay() == "muon")
0123     p = reco::Particle(0, this->getRecLepm().p4() + this->getRecLepn().p4() + this->getCalLepb().p4());
0124   if (this->getDecay() == "electron")
0125     p = reco::Particle(0, this->getRecLepe().p4() + this->getRecLepn().p4() + this->getCalLepb().p4());
0126   return p;
0127 }
0128 
0129 reco::Particle TtSemiEvtSolution::getCalLepW() const {
0130   reco::Particle p;
0131   if (this->getDecay() == "muon")
0132     p = reco::Particle(0, this->getRecLepm().p4() + this->getRecLepn().p4());
0133   if (this->getDecay() == "electron")
0134     p = reco::Particle(0, this->getRecLepe().p4() + this->getRecLepn().p4());
0135   return p;
0136 }
0137 
0138 //-------------------------------------------
0139 // get objects from kinematic fit
0140 //-------------------------------------------
0141 reco::Particle TtSemiEvtSolution::getFitHadt() const {
0142   // FIXME: provide the correct charge from generated event
0143   return reco::Particle(0, this->getFitHadp().p4() + this->getFitHadq().p4() + this->getFitHadb().p4());
0144 }
0145 
0146 reco::Particle TtSemiEvtSolution::getFitHadW() const {
0147   // FIXME: provide the correct charge from generated event
0148   return reco::Particle(0, this->getFitHadp().p4() + this->getFitHadq().p4());
0149 }
0150 
0151 reco::Particle TtSemiEvtSolution::getFitLept() const {
0152   // FIXME: provide the correct charge from generated event
0153   return reco::Particle(0, this->getFitLepl().p4() + this->getFitLepn().p4() + this->getFitLepb().p4());
0154 }
0155 
0156 reco::Particle TtSemiEvtSolution::getFitLepW() const {
0157   // FIXME: provide the correct charge from generated event
0158   return reco::Particle(0, this->getFitLepl().p4() + this->getFitLepn().p4());
0159 }
0160 
0161 //-------------------------------------------
0162 // get info on the outcome of the signal
0163 // selection LR
0164 //-------------------------------------------
0165 double TtSemiEvtSolution::getLRSignalEvtObsVal(unsigned int selObs) const {
0166   double val = -999.;
0167   for (size_t o = 0; o < lrSignalEvtVarVal_.size(); o++) {
0168     if (lrSignalEvtVarVal_[o].first == selObs)
0169       val = lrSignalEvtVarVal_[o].second;
0170   }
0171   return val;
0172 }
0173 
0174 //-------------------------------------------
0175 // get info on the outcome of the different
0176 // jet combination methods
0177 //-------------------------------------------
0178 double TtSemiEvtSolution::getLRJetCombObsVal(unsigned int selObs) const {
0179   double val = -999.;
0180   for (size_t o = 0; o < lrJetCombVarVal_.size(); o++) {
0181     if (lrJetCombVarVal_[o].first == selObs)
0182       val = lrJetCombVarVal_[o].second;
0183   }
0184   return val;
0185 }
0186 
0187 //-------------------------------------------
0188 // set the generated event
0189 //-------------------------------------------
0190 void TtSemiEvtSolution::setGenEvt(const edm::Handle<TtGenEvent>& aGenEvt) {
0191   if (!aGenEvt->isSemiLeptonic()) {
0192     edm::LogWarning("TtGenEventNotFilled") << "genEvt is not semi-leptonic; TtGenEvent is not filled";
0193     return;
0194   }
0195   theGenEvt_ = edm::RefProd<TtGenEvent>(aGenEvt);
0196 }
0197 
0198 //-------------------------------------------
0199 // set the outcome of the different jet
0200 // combination methods
0201 //-------------------------------------------
0202 void TtSemiEvtSolution::setLRJetCombObservables(const std::vector<std::pair<unsigned int, double> >& varval) {
0203   lrJetCombVarVal_.clear();
0204   for (size_t ijc = 0; ijc < varval.size(); ijc++)
0205     lrJetCombVarVal_.push_back(varval[ijc]);
0206 }
0207 
0208 //-------------------------------------------
0209 // set the outcome of the signal selection LR
0210 //-------------------------------------------
0211 void TtSemiEvtSolution::setLRSignalEvtObservables(const std::vector<std::pair<unsigned int, double> >& varval) {
0212   lrSignalEvtVarVal_.clear();
0213   for (size_t ise = 0; ise < varval.size(); ise++)
0214     lrSignalEvtVarVal_.push_back(varval[ise]);
0215 }
0216 
0217 void TtSemiEvtSolution::setupHyp() {
0218   AddFourMomenta addFourMomenta;
0219 
0220   recoHyp_.clearDaughters();
0221   recoHyp_.clearRoles();
0222 
0223   // Setup transient references
0224   reco::CompositeCandidate recHadt;
0225   reco::CompositeCandidate recLept;
0226   reco::CompositeCandidate recHadW;
0227   reco::CompositeCandidate recLepW;
0228 
0229   // Get refs to leaf nodes
0230   reco::ShallowClonePtrCandidate hadp(hadp_, hadp_->charge(), hadp_->p4(), hadp_->vertex());
0231   reco::ShallowClonePtrCandidate hadq(hadq_, hadq_->charge(), hadq_->p4(), hadq_->vertex());
0232   reco::ShallowClonePtrCandidate hadb(hadb_, hadb_->charge(), hadb_->p4(), hadb_->vertex());
0233   reco::ShallowClonePtrCandidate lepb(lepb_, lepb_->charge(), lepb_->p4(), lepb_->vertex());
0234 
0235   reco::ShallowClonePtrCandidate neutrino(neutrino_, neutrino_->charge(), neutrino_->p4(), neutrino_->vertex());
0236 
0237   //   JetCandRef hadp( hadp_->p4(), hadp_->charge(), hadp_->vertex());  hadp.setRef( hadp_ );
0238   //   JetCandRef hadq( hadq_->p4(), hadq_->charge(), hadq_->vertex());  hadq.setRef( hadq_ );
0239   //   JetCandRef hadb( hadb_->p4(), hadb_->charge(), hadb_->vertex());  hadb.setRef( hadb_ );
0240   //   JetCandRef lepb( lepb_->p4(), lepb_->charge(), lepb_->vertex());  lepb.setRef( lepb_ );
0241 
0242   //   METCandRef neutrino  ( neutrino_->p4(), neutrino_->charge(), neutrino_->vertex() ); neutrino.setRef( neutrino_ );
0243 
0244   recHadW.addDaughter(hadp, "hadp");
0245   recHadW.addDaughter(hadq, "hadq");
0246 
0247   addFourMomenta.set(recHadW);
0248 
0249   recHadt.addDaughter(hadb, "hadb");
0250   recHadt.addDaughter(recHadW, "hadW");
0251 
0252   addFourMomenta.set(recHadt);
0253 
0254   recLepW.addDaughter(neutrino, "neutrino");
0255   if (getDecay() == "electron") {
0256     reco::ShallowClonePtrCandidate electron(electron_, electron_->charge(), electron_->p4(), electron_->vertex());
0257     //     ElectronCandRef electron ( electron_->p4(), electron_->charge(), electron_->vertex() ); electron.setRef( electron_ );
0258     recLepW.addDaughter(electron, "electron");
0259   } else if (getDecay() == "muon") {
0260     reco::ShallowClonePtrCandidate muon(muon_, muon_->charge(), muon_->p4(), muon_->vertex());
0261     //     MuonCandRef muon ( muon_->p4(), muon_->charge(), muon_->vertex() ); muon.setRef( muon_ );
0262     recLepW.addDaughter(muon, "muon");
0263   }
0264 
0265   addFourMomenta.set(recLepW);
0266 
0267   recLept.addDaughter(lepb, "lepb");
0268   recLept.addDaughter(recLepW, "lepW");
0269 
0270   addFourMomenta.set(recLept);
0271 
0272   recoHyp_.addDaughter(recHadt, "hadt");
0273   recoHyp_.addDaughter(recLept, "lept");
0274 
0275   addFourMomenta.set(recoHyp_);
0276 
0277   //   // Setup transient references
0278   //   reco::CompositeCandidate fitHadt;
0279   //   reco::CompositeCandidate fitLept;
0280   //   reco::CompositeCandidate fitHadW;
0281   //   reco::CompositeCandidate fitLepW;
0282 
0283   //   // Get refs to leaf nodes
0284   //   pat::Particle afitHadp = getFitHadp();
0285   //   pat::Particle afitHadq = getFitHadq();
0286   //   pat::Particle afitHadb = getFitHadb();
0287   //   pat::Particle afitLepb = getFitLepb();
0288   //   reco::ShallowClonePtrCandidate fitHadp( hadp_, afitHadp.charge(), afitHadp.p4(), afitHadp.vertex());
0289   //   reco::ShallowClonePtrCandidate fitHadq( hadq_, afitHadq.charge(), afitHadq.p4(), afitHadq.vertex());
0290   //   reco::ShallowClonePtrCandidate fitHadb( hadb_, afitHadb.charge(), afitHadb.p4(), afitHadb.vertex());
0291   //   reco::ShallowClonePtrCandidate fitLepb( lepb_, afitLepb.charge(), afitLepb.p4(), afitLepb.vertex());
0292 
0293   //   reco::ShallowClonePtrCandidate fitNeutrino  ( neutrino_, fitLepn_.charge(),  fitLepn_.p4(),  fitLepn_.vertex() );
0294 
0295   //   fitHadW.addDaughter( fitHadp,    "hadp" );
0296   //   fitHadW.addDaughter( fitHadq,    "hadq" );
0297   //   fitHadt.addDaughter( fitHadb,    "hadb" );
0298   //   fitHadt.addDaughter( fitHadW,    "hadW" );
0299 
0300   //   fitLepW.addDaughter( fitNeutrino,"neutrino" );
0301 
0302   //   if ( getDecay() == "electron" ) {
0303   //     reco::ShallowClonePtrCandidate fitElectron ( electron_, electron_.charge(),  electron_.p4(), electron_.vertex() );
0304   //     fitLepW.addDaughter ( fitElectron, "electron" );
0305   //   } else if ( getDecay() == "muon" ) {
0306   //     reco::ShallowClonePtrCandidate fitMuon ( muon_, muon_.charge(),  muon_.p4(), muon_.vertex() );
0307   //     fitLepW.addDaughter ( fitMuon, "muon" );
0308   //   }
0309   //   fitLept.addDaughter( fitLepb,    "lepb" );
0310   //   fitLept.addDaughter( fitLepW,    "lepW" );
0311 
0312   //   fitHyp_.addDaughter( fitHadt,   "hadt" );
0313   //   fitHyp_.addDaughter( fitLept,   "lept" );
0314 }