CMS 3D CMS Logo

TtEvtBuilder.h

Go to the documentation of this file.
00001 #ifndef TtEvtBuilder_h
00002 #define TtEvtBuilder_h
00003 
00004 #include <vector>
00005 
00006 #include "TString.h"
00007 
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EDProducer.h"
00010 #include "FWCore/Framework/interface/Frameworkfwd.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include "AnalysisDataFormats/TopObjects/interface/TtEvent.h"
00013 
00014 // ----------------------------------------------------------------------
00015 // template to fill the TtEvent structure for:
00016 //
00017 //  * TtSemiLeptonicEvent
00018 //  * TtFullLeptonicEvent
00019 //  * TtFullHadronicEvent (still to be implemented)
00020 //
00021 //  event hypothesis, genEvent and extra information (if 
00022 //  available) are read from the event and contracted into 
00023 //  the TtEvent
00024 // ----------------------------------------------------------------------
00025 
00026 template <typename C>
00027 class TtEvtBuilder : public edm::EDProducer {
00028 
00029  public:
00030 
00032   explicit TtEvtBuilder(const edm::ParameterSet&);
00034   ~TtEvtBuilder(){};
00035   
00036  private:
00037 
00040   virtual void produce(edm::Event&, const edm::EventSetup&);
00041 
00042  private:
00043 
00045   int event_;
00047   int verbosity_;
00049   std::vector<std::string> hyps_;
00051   edm::InputTag genEvt_;
00054   int decayChnTop1_;
00055   int decayChnTop2_;
00056 
00059   edm::ParameterSet kinFit_;
00060   edm::InputTag fitChi2_;
00061   edm::InputTag fitProb_;
00064   edm::ParameterSet genMatch_;
00065   edm::InputTag sumPt_;
00066   edm::InputTag sumDR_;
00069   edm::ParameterSet mvaDisc_;
00070   edm::InputTag meth_;
00071   edm::InputTag disc_;
00072 };
00073 
00074 template <typename C>
00075 TtEvtBuilder<C>::TtEvtBuilder(const edm::ParameterSet& cfg) : event_(0),
00076   verbosity_   (cfg.getParameter<int>                      ("verbosity"    )),
00077   hyps_        (cfg.getParameter<std::vector<std::string> >("hypotheses"   )),
00078   genEvt_      (cfg.getParameter<edm::InputTag>            ("genEvent"     )),
00079   decayChnTop1_(cfg.getParameter<int>                      ("decayChannel1")),
00080   decayChnTop2_(cfg.getParameter<int>                      ("decayChannel2"))
00081 {
00082   // parameter subsets for kKinFit
00083   if( cfg.exists("kinFit") ) {
00084     kinFit_  = cfg.getParameter<edm::ParameterSet>("kinFit");
00085     fitChi2_ = kinFit_.getParameter<edm::InputTag>("chi2");
00086     fitProb_ = kinFit_.getParameter<edm::InputTag>("prob");
00087   }
00088   // parameter subsets for kGenMatch
00089   if( cfg.exists("genMatch") ) {
00090     genMatch_ = cfg.getParameter<edm::ParameterSet>("genMatch");
00091     sumPt_    = genMatch_.getParameter<edm::InputTag>("sumPt");
00092     sumDR_    = genMatch_.getParameter<edm::InputTag>("sumDR");
00093   }
00094   // parameter subsets for kMvaDisc
00095   if( cfg.exists("mvaDisc") ) {
00096     mvaDisc_ = cfg.getParameter<edm::ParameterSet>("mvaDisc");
00097     meth_    = mvaDisc_.getParameter<edm::InputTag>("meth");
00098     disc_    = mvaDisc_.getParameter<edm::InputTag>("disc");
00099   }
00100   // produces a TtEventEvent for:
00101   //  * TtSemiLeptonicEvent 
00102   //  * TtFullLeptonicEvent
00103   //  * TtFullHadronicEvent (still to be implemented)
00104   // from hypotheses and associated extra information
00105   produces<C>();
00106 }
00107 
00108 template <typename C>
00109 void
00110 TtEvtBuilder<C>::produce(edm::Event& evt, const edm::EventSetup& setup)
00111 {
00112   C event;
00113 
00114   // set leptonic decay channels
00115   event.setLepDecays( WDecay::LeptonType(decayChnTop1_), WDecay::LeptonType(decayChnTop2_) );
00116 
00117   // set genEvent
00118   edm::Handle<TtGenEvent> genEvt;
00119   evt.getByLabel(genEvt_, genEvt);
00120   event.setGenEvent(genEvt);
00121 
00122   // add event hypotheses for all given 
00123   // hypothesis classes to the TtEvent
00124   typedef std::vector<std::string>::const_iterator EventHypo;
00125   for(EventHypo h=hyps_.begin(); h!=hyps_.end(); ++h){
00126     edm::Handle<int> key; 
00127     evt.getByLabel(*h, "Key", key);
00128 
00129     edm::Handle<std::vector<TtEvent::HypoCombPair> > hypMatchVec; 
00130     evt.getByLabel(*h, hypMatchVec);
00131 
00132     typedef std::vector<TtEvent::HypoCombPair>::const_iterator HypMatch;
00133     for(HypMatch hm=hypMatchVec->begin(); hm != hypMatchVec->end(); ++hm){
00134       event.addEventHypo((TtEvent::HypoClassKey&)*key, *hm);
00135     }
00136   }
00137 
00138   // set kKinFit extras
00139   if( event.isHypoAvailable(TtEvent::kKinFit) ) {
00140     edm::Handle<std::vector<double> > fitChi2;
00141     evt.getByLabel(fitChi2_, fitChi2);
00142     event.setFitChi2( *fitChi2 );
00143     
00144     edm::Handle<std::vector<double> > fitProb;
00145     evt.getByLabel(fitProb_, fitProb);
00146     event.setFitProb( *fitProb );
00147   }
00148 
00149   // set kGenMatch extras
00150   if( event.isHypoAvailable(TtEvent::kGenMatch) ) {
00151     edm::Handle<std::vector<double> > sumPt;
00152     evt.getByLabel(sumPt_, sumPt);
00153     event.setGenMatchSumPt( *sumPt );
00154 
00155     edm::Handle<std::vector<double> > sumDR;
00156     evt.getByLabel(sumDR_, sumDR);
00157     event.setGenMatchSumDR( *sumDR );
00158   }
00159 
00160   // set kMvaDisc extras
00161   if( event.isHypoAvailable(TtEvent::kMVADisc) ) {
00162     edm::Handle<TString> meth;
00163     evt.getByLabel(meth_, meth);
00164     event.setMvaMethod( (std::string) *meth );
00165 
00166     edm::Handle<std::vector<double> > disc;
00167     evt.getByLabel(disc_, disc);
00168     event.setMvaDiscriminators( *disc );
00169   }
00170 
00171   // print summary via MessageLogger for up
00172   // to verbosity events if verbosity_>0
00173   if(verbosity_==-1 || (verbosity_ > 0 && event_<verbosity_)){ 
00174     event.print();
00175   }
00176 
00177   // write object to root file 
00178   std::auto_ptr<C> pOut(new C);
00179   *pOut=event;
00180   evt.put(pOut);
00181 }
00182 
00183 #endif

Generated on Tue Jun 9 17:48:06 2009 for CMSSW by  doxygen 1.5.4