CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/TopQuarkAnalysis/TopJetCombination/src/TtFullHadHypothesis.cc

Go to the documentation of this file.
00001 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
00002 #include "TopQuarkAnalysis/TopJetCombination/interface/TtFullHadHypothesis.h"
00003 
00005 TtFullHadHypothesis::TtFullHadHypothesis(const edm::ParameterSet& cfg):
00006   jets_(cfg.getParameter<edm::InputTag>("jets")),
00007   lightQ_(0), lightQBar_(0), b_(0), bBar_(0), lightP_(0), lightPBar_(0)
00008 {
00009   getMatch_ = false;
00010   if( cfg.exists("match") ) {
00011     getMatch_ = true;
00012     match_ = cfg.getParameter<edm::InputTag>("match");
00013   }
00014   if( cfg.exists("jetCorrectionLevel") ) {
00015     jetCorrectionLevel_ = cfg.getParameter<std::string>("jetCorrectionLevel");
00016   }
00017   produces<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >();
00018   produces<int>("Key");
00019 }
00020 
00022 TtFullHadHypothesis::~TtFullHadHypothesis()
00023 {
00024   if( lightQ_    ) delete lightQ_;
00025   if( lightQBar_ ) delete lightQBar_;
00026   if( b_         ) delete b_;
00027   if( bBar_      ) delete bBar_;
00028   if( lightP_    ) delete lightP_;
00029   if( lightPBar_ ) delete lightPBar_;
00030 }
00031 
00033 void
00034 TtFullHadHypothesis::produce(edm::Event& evt, const edm::EventSetup& setup)
00035 {
00036   edm::Handle<std::vector<pat::Jet> > jets;
00037   evt.getByLabel(jets_, jets);
00038   
00039   std::vector<std::vector<int> > matchVec;
00040   if( getMatch_ ) {
00041     edm::Handle<std::vector<std::vector<int> > > matchHandle;
00042     evt.getByLabel(match_, matchHandle);
00043     matchVec = *matchHandle;
00044   }
00045   else {
00046     std::vector<int> dummyMatch;
00047     for(unsigned int i = 0; i < 4; ++i) 
00048       dummyMatch.push_back( -1 );
00049     matchVec.push_back( dummyMatch );
00050   }
00051 
00052   // declare auto_ptr for products
00053   std::auto_ptr<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >
00054     pOut( new std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > );
00055   std::auto_ptr<int> pKey(new int);
00056 
00057   // go through given vector of jet combinations
00058   unsigned int idMatch = 0;
00059   typedef std::vector<std::vector<int> >::iterator MatchVecIterator;
00060   for(MatchVecIterator match = matchVec.begin(); match != matchVec.end(); ++match) {
00061     // reset pointers
00062     resetCandidates();
00063     // build hypothesis
00064     buildHypo(evt, jets, *match, idMatch++);
00065     pOut->push_back( std::make_pair(hypo(), *match) );
00066   }
00067   // feed out hyps and matches
00068   evt.put(pOut);
00069 
00070   // build and feed out key
00071   buildKey();
00072   *pKey=key();
00073   evt.put(pKey, "Key");
00074 }
00075 
00077 void
00078 TtFullHadHypothesis::resetCandidates()
00079 {
00080   lightQ_    = 0;
00081   lightQBar_ = 0;
00082   b_         = 0;
00083   bBar_      = 0;
00084   lightP_    = 0;
00085   lightPBar_ = 0;
00086 }
00087 
00089 reco::CompositeCandidate
00090 TtFullHadHypothesis::hypo()
00091 {
00092   // check for sanity of the hypothesis
00093   if( !lightQ_ || !lightQBar_ || !b_ || 
00094       !bBar_ || !lightP_ || !lightPBar_ )
00095     return reco::CompositeCandidate();
00096   
00097   // setup transient references
00098   reco::CompositeCandidate hyp, top, w, topBar, wBar;
00099 
00100   AddFourMomenta addFourMomenta;  
00101   // build up the top bar branch
00102   wBar  .addDaughter(*lightP_,    TtFullHadDaughter::LightP    );
00103   wBar  .addDaughter(*lightPBar_, TtFullHadDaughter::LightPBar );
00104   addFourMomenta.set( wBar );
00105   topBar.addDaughter( wBar,  TtFullHadDaughter::WMinus );
00106   topBar.addDaughter(*bBar_, TtFullHadDaughter::BBar   );
00107   addFourMomenta.set( topBar );
00108   
00109   // build up the top branch that decays hadronically
00110   w  .addDaughter(*lightQ_,    TtFullHadDaughter::LightQ    );
00111   w  .addDaughter(*lightQBar_, TtFullHadDaughter::LightQBar );
00112   addFourMomenta.set( w );
00113   top.addDaughter( w,  TtFullHadDaughter::WPlus );
00114   top.addDaughter(*b_, TtFullHadDaughter::B     );
00115   addFourMomenta.set( top );
00116 
00117   // build ttbar hypotheses
00118   hyp.addDaughter( topBar, TtFullHadDaughter::TopBar );
00119   hyp.addDaughter( top,    TtFullHadDaughter::Top    );
00120   addFourMomenta.set( hyp );
00121 
00122   return hyp;
00123 }
00124 
00126 std::string
00127 TtFullHadHypothesis::jetCorrectionLevel(const std::string& quarkType)
00128 {
00129   // jetCorrectionLevel was not configured
00130   if(jetCorrectionLevel_.empty())
00131     throw cms::Exception("Configuration")
00132       << "Unconfigured jetCorrectionLevel. Please use an appropriate, non-empty string.\n";
00133 
00134   // quarkType is unknown
00135   if( !(quarkType=="wQuarkMix" ||
00136         quarkType=="udsQuark" ||
00137         quarkType=="cQuark" ||
00138         quarkType=="bQuark") )
00139     throw cms::Exception("Configuration")
00140       << quarkType << " is unknown as a quarkType for the jetCorrectionLevel.\n";
00141 
00142   // combine correction level; start with a ':' even if 
00143   // there is no flavor tag to be added, as it is needed
00144   // by setCandidate to disentangle the correction tag 
00145   // from a potential flavor tag, which can be empty
00146   std::string level=jetCorrectionLevel_+":";
00147   if( level=="had:" || level=="ue:" || level=="part:" ){
00148     if(quarkType=="wQuarkMix"){level+="wMix";}
00149     if(quarkType=="udsQuark" ){level+="uds";}
00150     if(quarkType=="cQuark"   ){level+="charm";}
00151     if(quarkType=="bQuark"   ){level+="bottom";}
00152   }
00153   else{
00154     level+="none";
00155   }
00156   return level;
00157 }
00158 
00160 void 
00161 TtFullHadHypothesis::setCandidate(const edm::Handle<std::vector<pat::Jet> >& handle, const int& idx,
00162                                   reco::ShallowClonePtrCandidate*& clone, const std::string& correctionLevel)
00163 {
00164   edm::Ptr<pat::Jet> ptr = edm::Ptr<pat::Jet>(handle, idx);
00165   // disentangle the correction from the potential flavor tag 
00166   // by the separating ':'; the flavor tag can be empty though
00167   std::string step   = correctionLevel.substr(0,correctionLevel.find(":"));
00168   std::string flavor = correctionLevel.substr(1+correctionLevel.find(":"));
00169   float corrFactor = 1.;
00170   if(flavor=="wMix")
00171     corrFactor = 0.75*ptr->jecFactor(step, "uds") + 0.25*ptr->jecFactor(step, "charm");
00172   else
00173     corrFactor = ptr->jecFactor(step, flavor);
00174   clone = new reco::ShallowClonePtrCandidate( ptr, ptr->charge(), ptr->p4()*corrFactor, ptr->vertex() );
00175 }