CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_TagAndProbe_BaseTreeFiller_h
00002 #define PhysicsTools_TagAndProbe_BaseTreeFiller_h
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <stdint.h>
00007 
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "DataFormats/Common/interface/ValueMap.h"
00010 #include "DataFormats/Candidate/interface/Candidate.h"
00011 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/Utilities/interface/InputTag.h"
00015 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00016 #include "CommonTools/Utils/interface/StringObjectFunction.h"
00017 
00018 #include <TTree.h>
00019 #include <boost/utility.hpp>
00020 
00021 
00028 namespace tnp {
00029 
00031 class ProbeVariable {
00032     public:
00034         ProbeVariable(const std::string &name, const std::string &expression) :
00035             name_(name), external_(false), function_(expression) {}
00036 
00038         ProbeVariable(const std::string &name, const edm::InputTag &src) :
00039             name_(name), external_(true), function_("-1"), src_(src) {}
00040 
00042         ~ProbeVariable() ;
00043 
00045         float * address() const { return &value_; }
00046 
00048         const std::string & name() const { return name_; }
00049 
00051         void init(const edm::Event &iEvent) const {
00052             if (external_) iEvent.getByLabel(src_, handle_);
00053         }
00054 
00056         void fill(const reco::CandidateBaseRef &probe) const {
00057             value_ = external_ ? (*handle_)[probe] : function_(*probe);
00058         }
00059 
00060     private:
00062         std::string name_;
00064         mutable float value_;
00065 
00067         bool external_;
00068         // ---- this below is used if 'external_' is false
00070         StringObjectFunction<reco::Candidate,true> function_;
00071         // In releases older than 3.4.X, it can be parially emulated by PATStringObjectFunction (PhysicsTools/PatUtils/interface/StringParserTools.h)
00072         // Or you can use StringObjectFunction<reco::Candidate> and get only reco::Candidate methods
00073 
00074         // ---- this below is used if 'external_' is true
00076         edm::InputTag src_;
00078         mutable edm::Handle<edm::ValueMap<float> > handle_; 
00079 };
00080 
00081 class ProbeFlag {
00082     public:
00084         ProbeFlag(const std::string &name, const std::string &cut) :
00085             name_(name), external_(false), cut_(cut) {}
00086 
00088         ProbeFlag(const std::string &name, const edm::InputTag &src) :
00089             name_(name), external_(true), cut_(""), src_(src) {}
00090 
00092         ~ProbeFlag() ;
00093 
00095         int32_t * address() const { return &value_; }
00096 
00098         const std::string & name() const { return name_; }
00099 
00101         void init(const edm::Event &iEvent) const ;
00102 
00104         void fill(const reco::CandidateBaseRef &probe) const ;
00105 
00106     private:
00108         std::string name_;
00110         mutable int32_t value_;
00111 
00113         bool external_;
00114         // ---- this below is used if 'external_' is false
00116         StringCutObjectSelector<reco::Candidate,true> cut_;
00117 
00118         // ---- this below is used if 'external_' is true
00120         edm::InputTag src_;
00122         mutable std::vector<reco::CandidateBaseRef> passingProbes_; 
00123 };
00124 
00125 
00126 // This class inherits from boost::noncopyable, as copying it would break the addresses in the TTree
00127 class BaseTreeFiller : boost::noncopyable {
00128     public:
00130         BaseTreeFiller(const char *name, const edm::ParameterSet config);
00131 
00133         BaseTreeFiller(BaseTreeFiller &main, const edm::ParameterSet &iConfig, const std::string &branchNamePrefix);
00134 
00136         ~BaseTreeFiller();
00137 
00138         //implementation notice: we declare 'const' the methods which don't change the configuration
00139         //                       and that can't mess up the addresses in the TTree.
00140 
00142         void init(const edm::Event &iEvent) const ;
00143 
00145         void fill(const reco::CandidateBaseRef &probe) const ;
00146 
00149         void writeProvenance(const edm::ParameterSet &pset) const ;
00150     protected:
00151 
00152         std::vector<ProbeVariable> vars_;
00153         std::vector<ProbeFlag>     flags_;
00154 
00156         enum WeightMode { None, Fixed, External };
00157         WeightMode weightMode_;
00158         edm::InputTag weightSrc_;
00159 
00161         bool ignoreExceptions_;
00162 
00164         bool addRunLumiInfo_;
00165 
00167         bool addEventVariablesInfo_;
00168 
00169         void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, const std::string &branchNamePrefix="") ;
00170 
00171         //implementation notice: these two are 'mutable' because we will fill them from a 'const' method
00172         mutable TTree * tree_;
00173         mutable float weight_;
00174         mutable uint32_t run_, lumi_, event_, mNPV_;
00175 
00176         mutable float mPVx_,mPVy_,mPVz_,mBSx_,mBSy_,mBSz_; 
00177 
00178         mutable float mMET_,mSumET_,mMETSign_,mtcMET_,mtcSumET_,
00179           mtcMETSign_,mpfMET_,mpfSumET_,mpfMETSign_;
00180 };
00181 
00182 
00183 } //namespace
00184 
00185 #endif