Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
//
//

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "AnalysisDataFormats/TopObjects/interface/TtSemiEvtSolution.h"
#include "DataFormats/Candidate/interface/ShallowClonePtrCandidate.h"
#include "CommonTools/CandUtils/interface/AddFourMomenta.h"

TtSemiEvtSolution::TtSemiEvtSolution()
    : mcHyp_("ttSemiEvtMCHyp"), recoHyp_("ttSemiEvtRecoHyp"), fitHyp_("ttSemiEvtFitHyp") {
  jetCorrScheme_ = 0;
  sumAnglejp_ = -999.;
  angleHadp_ = -999.;
  angleHadq_ = -999.;
  angleHadb_ = -999.;
  angleLepb_ = -999.;
  changeWQ_ = -999;
  probChi2_ = -999.;
  mcBestJetComb_ = -999;
  simpleBestJetComb_ = -999;
  lrBestJetComb_ = -999;
  lrJetCombLRval_ = -999.;
  lrJetCombProb_ = -999.;
  lrSignalEvtLRval_ = -999.;
  lrSignalEvtProb_ = -999.;
}

TtSemiEvtSolution::~TtSemiEvtSolution() {}

//-------------------------------------------
// get calibrated base objects
//-------------------------------------------
pat::Jet TtSemiEvtSolution::getHadb() const {
  // WARNING this is obsolete and only
  // kept for backwards compatibility
  if (jetCorrScheme_ == 1)
    return hadb_->correctedJet("HAD", "B");  // calibrate jets according to MC truth
  else if (jetCorrScheme_ == 2)
    return hadb_->correctedJet("HAD", "B");
  else
    return *hadb_;
}

pat::Jet TtSemiEvtSolution::getHadp() const {
  // WARNING this is obsolete and only
  // kept for backwards compatibility
  if (jetCorrScheme_ == 1)
    return hadp_->correctedJet("HAD", "UDS");  // calibrate jets according to MC truth
  else if (jetCorrScheme_ == 2)
    return hadp_->correctedJet("HAD", "UDS");
  else
    return *hadp_;
}

pat::Jet TtSemiEvtSolution::getHadq() const {
  // WARNING this is obsolete and only
  // kept for backwards compatibility
  if (jetCorrScheme_ == 1)
    return hadq_->correctedJet("HAD", "UDS");  // calibrate jets according to MC truth
  else if (jetCorrScheme_ == 2)
    return hadq_->correctedJet("HAD", "UDS");
  else
    return *hadq_;
}

pat::Jet TtSemiEvtSolution::getLepb() const {
  // WARNING this is obsolete and only
  // kept for backwards compatibility
  if (jetCorrScheme_ == 1)
    return lepb_->correctedJet("HAD", "B");  // calibrate jets according to MC truth
  else if (jetCorrScheme_ == 2)
    return lepb_->correctedJet("HAD", "B");
  else
    return *lepb_;
}

//-------------------------------------------
// get (un-)/calibrated reco objects
//-------------------------------------------
reco::Particle TtSemiEvtSolution::getRecHadt() const {
  // FIXME: the charge from the genevent
  return reco::Particle(0, this->getRecHadp().p4() + this->getRecHadq().p4() + this->getRecHadb().p4());
}

reco::Particle TtSemiEvtSolution::getRecHadW() const {
  // FIXME: the charge from the genevent
  return reco::Particle(0, this->getRecHadp().p4() + this->getRecHadq().p4());
}

reco::Particle TtSemiEvtSolution::getRecLept() const {
  // FIXME: the charge from the genevent
  reco::Particle p;
  if (this->getDecay() == "muon")
    p = reco::Particle(0, this->getRecLepm().p4() + this->getRecLepn().p4() + this->getRecLepb().p4());
  if (this->getDecay() == "electron")
    p = reco::Particle(0, this->getRecLepe().p4() + this->getRecLepn().p4() + this->getRecLepb().p4());
  return p;
}

reco::Particle TtSemiEvtSolution::getRecLepW() const {
  // FIXME: the charge from the genevent
  reco::Particle p;
  if (this->getDecay() == "muon")
    p = reco::Particle(0, this->getRecLepm().p4() + this->getRecLepn().p4());
  if (this->getDecay() == "electron")
    p = reco::Particle(0, this->getRecLepe().p4() + this->getRecLepn().p4());
  return p;
}

// FIXME: Why these functions??? Not needed!
// methods to get calibrated objects
reco::Particle TtSemiEvtSolution::getCalHadt() const {
  return reco::Particle(0, this->getCalHadp().p4() + this->getCalHadq().p4() + this->getCalHadb().p4());
}

reco::Particle TtSemiEvtSolution::getCalHadW() const {
  return reco::Particle(0, this->getCalHadp().p4() + this->getCalHadq().p4());
}

reco::Particle TtSemiEvtSolution::getCalLept() const {
  reco::Particle p;
  if (this->getDecay() == "muon")
    p = reco::Particle(0, this->getRecLepm().p4() + this->getRecLepn().p4() + this->getCalLepb().p4());
  if (this->getDecay() == "electron")
    p = reco::Particle(0, this->getRecLepe().p4() + this->getRecLepn().p4() + this->getCalLepb().p4());
  return p;
}

reco::Particle TtSemiEvtSolution::getCalLepW() const {
  reco::Particle p;
  if (this->getDecay() == "muon")
    p = reco::Particle(0, this->getRecLepm().p4() + this->getRecLepn().p4());
  if (this->getDecay() == "electron")
    p = reco::Particle(0, this->getRecLepe().p4() + this->getRecLepn().p4());
  return p;
}

//-------------------------------------------
// get objects from kinematic fit
//-------------------------------------------
reco::Particle TtSemiEvtSolution::getFitHadt() const {
  // FIXME: provide the correct charge from generated event
  return reco::Particle(0, this->getFitHadp().p4() + this->getFitHadq().p4() + this->getFitHadb().p4());
}

reco::Particle TtSemiEvtSolution::getFitHadW() const {
  // FIXME: provide the correct charge from generated event
  return reco::Particle(0, this->getFitHadp().p4() + this->getFitHadq().p4());
}

reco::Particle TtSemiEvtSolution::getFitLept() const {
  // FIXME: provide the correct charge from generated event
  return reco::Particle(0, this->getFitLepl().p4() + this->getFitLepn().p4() + this->getFitLepb().p4());
}

reco::Particle TtSemiEvtSolution::getFitLepW() const {
  // FIXME: provide the correct charge from generated event
  return reco::Particle(0, this->getFitLepl().p4() + this->getFitLepn().p4());
}

//-------------------------------------------
// get info on the outcome of the signal
// selection LR
//-------------------------------------------
double TtSemiEvtSolution::getLRSignalEvtObsVal(unsigned int selObs) const {
  double val = -999.;
  for (size_t o = 0; o < lrSignalEvtVarVal_.size(); o++) {
    if (lrSignalEvtVarVal_[o].first == selObs)
      val = lrSignalEvtVarVal_[o].second;
  }
  return val;
}

//-------------------------------------------
// get info on the outcome of the different
// jet combination methods
//-------------------------------------------
double TtSemiEvtSolution::getLRJetCombObsVal(unsigned int selObs) const {
  double val = -999.;
  for (size_t o = 0; o < lrJetCombVarVal_.size(); o++) {
    if (lrJetCombVarVal_[o].first == selObs)
      val = lrJetCombVarVal_[o].second;
  }
  return val;
}

//-------------------------------------------
// set the generated event
//-------------------------------------------
void TtSemiEvtSolution::setGenEvt(const edm::Handle<TtGenEvent>& aGenEvt) {
  if (!aGenEvt->isSemiLeptonic()) {
    edm::LogWarning("TtGenEventNotFilled") << "genEvt is not semi-leptonic; TtGenEvent is not filled";
    return;
  }
  theGenEvt_ = edm::RefProd<TtGenEvent>(aGenEvt);
}

//-------------------------------------------
// set the outcome of the different jet
// combination methods
//-------------------------------------------
void TtSemiEvtSolution::setLRJetCombObservables(const std::vector<std::pair<unsigned int, double> >& varval) {
  lrJetCombVarVal_.clear();
  for (size_t ijc = 0; ijc < varval.size(); ijc++)
    lrJetCombVarVal_.push_back(varval[ijc]);
}

//-------------------------------------------
// set the outcome of the signal selection LR
//-------------------------------------------
void TtSemiEvtSolution::setLRSignalEvtObservables(const std::vector<std::pair<unsigned int, double> >& varval) {
  lrSignalEvtVarVal_.clear();
  for (size_t ise = 0; ise < varval.size(); ise++)
    lrSignalEvtVarVal_.push_back(varval[ise]);
}

void TtSemiEvtSolution::setupHyp() {
  AddFourMomenta addFourMomenta;

  recoHyp_.clearDaughters();
  recoHyp_.clearRoles();

  // Setup transient references
  reco::CompositeCandidate recHadt;
  reco::CompositeCandidate recLept;
  reco::CompositeCandidate recHadW;
  reco::CompositeCandidate recLepW;

  // Get refs to leaf nodes
  reco::ShallowClonePtrCandidate hadp(hadp_, hadp_->charge(), hadp_->p4(), hadp_->vertex());
  reco::ShallowClonePtrCandidate hadq(hadq_, hadq_->charge(), hadq_->p4(), hadq_->vertex());
  reco::ShallowClonePtrCandidate hadb(hadb_, hadb_->charge(), hadb_->p4(), hadb_->vertex());
  reco::ShallowClonePtrCandidate lepb(lepb_, lepb_->charge(), lepb_->p4(), lepb_->vertex());

  reco::ShallowClonePtrCandidate neutrino(neutrino_, neutrino_->charge(), neutrino_->p4(), neutrino_->vertex());

  //   JetCandRef hadp( hadp_->p4(), hadp_->charge(), hadp_->vertex());  hadp.setRef( hadp_ );
  //   JetCandRef hadq( hadq_->p4(), hadq_->charge(), hadq_->vertex());  hadq.setRef( hadq_ );
  //   JetCandRef hadb( hadb_->p4(), hadb_->charge(), hadb_->vertex());  hadb.setRef( hadb_ );
  //   JetCandRef lepb( lepb_->p4(), lepb_->charge(), lepb_->vertex());  lepb.setRef( lepb_ );

  //   METCandRef neutrino  ( neutrino_->p4(), neutrino_->charge(), neutrino_->vertex() ); neutrino.setRef( neutrino_ );

  recHadW.addDaughter(hadp, "hadp");
  recHadW.addDaughter(hadq, "hadq");

  addFourMomenta.set(recHadW);

  recHadt.addDaughter(hadb, "hadb");
  recHadt.addDaughter(recHadW, "hadW");

  addFourMomenta.set(recHadt);

  recLepW.addDaughter(neutrino, "neutrino");
  if (getDecay() == "electron") {
    reco::ShallowClonePtrCandidate electron(electron_, electron_->charge(), electron_->p4(), electron_->vertex());
    //     ElectronCandRef electron ( electron_->p4(), electron_->charge(), electron_->vertex() ); electron.setRef( electron_ );
    recLepW.addDaughter(electron, "electron");
  } else if (getDecay() == "muon") {
    reco::ShallowClonePtrCandidate muon(muon_, muon_->charge(), muon_->p4(), muon_->vertex());
    //     MuonCandRef muon ( muon_->p4(), muon_->charge(), muon_->vertex() ); muon.setRef( muon_ );
    recLepW.addDaughter(muon, "muon");
  }

  addFourMomenta.set(recLepW);

  recLept.addDaughter(lepb, "lepb");
  recLept.addDaughter(recLepW, "lepW");

  addFourMomenta.set(recLept);

  recoHyp_.addDaughter(recHadt, "hadt");
  recoHyp_.addDaughter(recLept, "lept");

  addFourMomenta.set(recoHyp_);

  //   // Setup transient references
  //   reco::CompositeCandidate fitHadt;
  //   reco::CompositeCandidate fitLept;
  //   reco::CompositeCandidate fitHadW;
  //   reco::CompositeCandidate fitLepW;

  //   // Get refs to leaf nodes
  //   pat::Particle afitHadp = getFitHadp();
  //   pat::Particle afitHadq = getFitHadq();
  //   pat::Particle afitHadb = getFitHadb();
  //   pat::Particle afitLepb = getFitLepb();
  //   reco::ShallowClonePtrCandidate fitHadp( hadp_, afitHadp.charge(), afitHadp.p4(), afitHadp.vertex());
  //   reco::ShallowClonePtrCandidate fitHadq( hadq_, afitHadq.charge(), afitHadq.p4(), afitHadq.vertex());
  //   reco::ShallowClonePtrCandidate fitHadb( hadb_, afitHadb.charge(), afitHadb.p4(), afitHadb.vertex());
  //   reco::ShallowClonePtrCandidate fitLepb( lepb_, afitLepb.charge(), afitLepb.p4(), afitLepb.vertex());

  //   reco::ShallowClonePtrCandidate fitNeutrino  ( neutrino_, fitLepn_.charge(),  fitLepn_.p4(),  fitLepn_.vertex() );

  //   fitHadW.addDaughter( fitHadp,    "hadp" );
  //   fitHadW.addDaughter( fitHadq,    "hadq" );
  //   fitHadt.addDaughter( fitHadb,    "hadb" );
  //   fitHadt.addDaughter( fitHadW,    "hadW" );

  //   fitLepW.addDaughter( fitNeutrino,"neutrino" );

  //   if ( getDecay() == "electron" ) {
  //     reco::ShallowClonePtrCandidate fitElectron ( electron_, electron_.charge(),  electron_.p4(), electron_.vertex() );
  //     fitLepW.addDaughter ( fitElectron, "electron" );
  //   } else if ( getDecay() == "muon" ) {
  //     reco::ShallowClonePtrCandidate fitMuon ( muon_, muon_.charge(),  muon_.p4(), muon_.vertex() );
  //     fitLepW.addDaughter ( fitMuon, "muon" );
  //   }
  //   fitLept.addDaughter( fitLepb,    "lepb" );
  //   fitLept.addDaughter( fitLepW,    "lepW" );

  //   fitHyp_.addDaughter( fitHadt,   "hadt" );
  //   fitHyp_.addDaughter( fitLept,   "lept" );
}