#include <BaseTreeFiller.h>
Public Member Functions | |
BaseTreeFiller (const char *name, const edm::ParameterSet config) | |
specify the name of the TTree, and the configuration for it | |
BaseTreeFiller (BaseTreeFiller &main, const edm::ParameterSet &iConfig, const std::string &branchNamePrefix) | |
Add branches to an existing TTree managed by another BaseTreeFiller. | |
void | fill (const reco::CandidateBaseRef &probe) const |
To be called once per probe, to fill the values for this probe. | |
void | init (const edm::Event &iEvent) const |
To be called once per event, to load possible external variables. | |
void | writeProvenance (const edm::ParameterSet &pset) const |
~BaseTreeFiller () | |
Destructor, does nothing but it's out-of-line as we have complex data members. | |
Protected Types | |
enum | WeightMode { None, Fixed, External } |
How event weights are defined: 'None' = no weights, 'Fixed' = one value specified in cfg file, 'External' = read weight from the event (as double) More... | |
Protected Member Functions | |
void | addBranches_ (TTree *tree, const edm::ParameterSet &iConfig, const std::string &branchNamePrefix="") |
Protected Attributes | |
bool | addEventVariablesInfo_ |
Add branches with event variables: met, sum ET, .. etc. | |
bool | addRunLumiInfo_ |
Add branches with run and lumisection number. | |
uint32_t | event_ |
std::vector< ProbeFlag > | flags_ |
bool | ignoreExceptions_ |
Ignore exceptions when evaluating variables. | |
uint32_t | lumi_ |
float | mBSx_ |
float | mBSy_ |
float | mBSz_ |
float | mMET_ |
float | mMETSign_ |
uint32_t | mNPV_ |
float | mpfMET_ |
float | mpfMETSign_ |
float | mpfSumET_ |
float | mPVx_ |
float | mPVy_ |
float | mPVz_ |
float | mSumET_ |
float | mtcMET_ |
float | mtcMETSign_ |
float | mtcSumET_ |
uint32_t | run_ |
TTree * | tree_ |
std::vector< ProbeVariable > | vars_ |
float | weight_ |
WeightMode | weightMode_ |
edm::InputTag | weightSrc_ |
Definition at line 127 of file BaseTreeFiller.h.
enum tnp::BaseTreeFiller::WeightMode [protected] |
How event weights are defined: 'None' = no weights, 'Fixed' = one value specified in cfg file, 'External' = read weight from the event (as double)
Definition at line 156 of file BaseTreeFiller.h.
tnp::BaseTreeFiller::BaseTreeFiller | ( | const char * | name, |
const edm::ParameterSet | config | ||
) |
specify the name of the TTree, and the configuration for it
Definition at line 41 of file BaseTreeFiller.cc.
References edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), and mergeVDriftHistosByStation::name.
{ // make trees as requested edm::Service<TFileService> fs; tree_ = fs->make<TTree>(name,name); // add the branches addBranches_(tree_, iConfig, ""); // set up weights, if needed if (iConfig.existsAs<double>("eventWeight")) { weightMode_ = Fixed; weight_ = iConfig.getParameter<double>("eventWeight"); } else if (iConfig.existsAs<edm::InputTag>("eventWeight")) { weightMode_ = External; weightSrc_ = iConfig.getParameter<edm::InputTag>("eventWeight"); } else { weightMode_ = None; } if (weightMode_ != None) { tree_->Branch("weight", &weight_, "weight/F"); } addRunLumiInfo_ = iConfig.existsAs<bool>("addRunLumiInfo") ? iConfig.getParameter<bool>("addRunLumiInfo") : false; if (addRunLumiInfo_) { tree_->Branch("run", &run_, "run/i"); tree_->Branch("lumi", &lumi_, "lumi/i"); tree_->Branch("event", &event_, "event/i"); } addEventVariablesInfo_ = iConfig.existsAs<bool>("addEventVariablesInfo") ? iConfig.getParameter<bool>("addEventVariablesInfo") : false; if (addEventVariablesInfo_) { tree_->Branch("event_nPV" ,&mNPV_ ,"mNPV/I"); tree_->Branch("event_met_calomet" ,&mMET_ ,"mMET/F"); tree_->Branch("event_met_calosumet" ,&mSumET_ ,"mSumET/F"); tree_->Branch("event_met_calometsignificance",&mMETSign_ ,"mMETSign/F"); tree_->Branch("event_met_tcmet" ,&mtcMET_ ,"mtcMET/F"); tree_->Branch("event_met_tcsumet" ,&mtcSumET_ ,"mtcSumET/F"); tree_->Branch("event_met_tcmetsignificance",&mtcMETSign_ ,"mtcMETSign/F"); tree_->Branch("event_met_pfmet" ,&mpfMET_ ,"mpfMET/F"); tree_->Branch("event_met_pfsumet" ,&mpfSumET_ ,"mpfSumET/F"); tree_->Branch("event_met_pfmetsignificance",&mpfMETSign_ ,"mpfMETSign/F"); tree_->Branch("event_PrimaryVertex_x" ,&mPVx_ ,"mPVx/F"); tree_->Branch("event_PrimaryVertex_y" ,&mPVy_ ,"mPVy/F"); tree_->Branch("event_PrimaryVertex_z" ,&mPVz_ ,"mPVz/F"); tree_->Branch("event_BeamSpot_x" ,&mBSx_ ,"mBSx/F"); tree_->Branch("event_BeamSpot_y" ,&mBSy_ ,"mBSy/F"); tree_->Branch("event_BeamSpot_z" ,&mBSz_ ,"mBSz/F"); } ignoreExceptions_ = iConfig.existsAs<bool>("ignoreExceptions") ? iConfig.getParameter<bool>("ignoreExceptions") : false; }
tnp::BaseTreeFiller::BaseTreeFiller | ( | BaseTreeFiller & | main, |
const edm::ParameterSet & | iConfig, | ||
const std::string & | branchNamePrefix | ||
) |
Add branches to an existing TTree managed by another BaseTreeFiller.
Definition at line 92 of file BaseTreeFiller.cc.
References addBranches_(), and tree_.
: addEventVariablesInfo_(false), tree_(0) { addBranches_(main.tree_, iConfig, branchNamePrefix); }
tnp::BaseTreeFiller::~BaseTreeFiller | ( | ) |
Destructor, does nothing but it's out-of-line as we have complex data members.
Definition at line 137 of file BaseTreeFiller.cc.
{ }
void tnp::BaseTreeFiller::addBranches_ | ( | TTree * | tree, |
const edm::ParameterSet & | iConfig, | ||
const std::string & | branchNamePrefix = "" |
||
) | [protected] |
Definition at line 100 of file BaseTreeFiller.cc.
References flags, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), and diffTreeTool::variables.
Referenced by BaseTreeFiller().
{ // set up variables edm::ParameterSet variables = iConfig.getParameter<edm::ParameterSet>("variables"); //.. the ones that are strings std::vector<std::string> stringVars = variables.getParameterNamesForType<std::string>(); for (std::vector<std::string>::const_iterator it = stringVars.begin(), ed = stringVars.end(); it != ed; ++it) { vars_.push_back(tnp::ProbeVariable(branchNamePrefix + *it, variables.getParameter<std::string>(*it))); } //.. the ones that are InputTags std::vector<std::string> inputTagVars = variables.getParameterNamesForType<edm::InputTag>(); for (std::vector<std::string>::const_iterator it = inputTagVars.begin(), ed = inputTagVars.end(); it != ed; ++it) { vars_.push_back(tnp::ProbeVariable(branchNamePrefix + *it, variables.getParameter<edm::InputTag>(*it))); } // set up flags edm::ParameterSet flags = iConfig.getParameter<edm::ParameterSet>("flags"); //.. the ones that are strings std::vector<std::string> stringFlags = flags.getParameterNamesForType<std::string>(); for (std::vector<std::string>::const_iterator it = stringFlags.begin(), ed = stringFlags.end(); it != ed; ++it) { flags_.push_back(tnp::ProbeFlag(branchNamePrefix + *it, flags.getParameter<std::string>(*it))); } //.. the ones that are InputTags std::vector<std::string> inputTagFlags = flags.getParameterNamesForType<edm::InputTag>(); for (std::vector<std::string>::const_iterator it = inputTagFlags.begin(), ed = inputTagFlags.end(); it != ed; ++it) { flags_.push_back(tnp::ProbeFlag(branchNamePrefix + *it, flags.getParameter<edm::InputTag>(*it))); } // then make all the variables in the trees for (std::vector<tnp::ProbeVariable>::iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) { tree->Branch(it->name().c_str(), it->address(), (it->name()+"/F").c_str()); } for (std::vector<tnp::ProbeFlag>::iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) { tree->Branch(it->name().c_str(), it->address(), (it->name()+"/I").c_str()); } }
void tnp::BaseTreeFiller::fill | ( | const reco::CandidateBaseRef & | probe | ) | const |
To be called once per probe, to fill the values for this probe.
Definition at line 233 of file BaseTreeFiller.cc.
Referenced by tnp::TPTreeFiller::fill().
{ for (std::vector<tnp::ProbeVariable>::const_iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) { if (ignoreExceptions_) { try{ it->fill(probe); } catch(cms::Exception &ex ){} } else { it->fill(probe); } } for (std::vector<tnp::ProbeFlag>::const_iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) { if (ignoreExceptions_) { try{ it->fill(probe); } catch(cms::Exception &ex ){} } else { it->fill(probe); } } if (tree_) tree_->Fill(); }
void tnp::BaseTreeFiller::init | ( | const edm::Event & | iEvent | ) | const |
To be called once per event, to load possible external variables.
*********** store some event variables: MET, SumET ****** ///////// Primary vertex //////////////
Reimplemented in tnp::TPTreeFiller.
Definition at line 139 of file BaseTreeFiller.cc.
References edm::EventID::event(), edm::Event::getByLabel(), edm::EventBase::id(), edm::EventID::luminosityBlock(), CaloMET_cfi::met, edm::EventID::run(), CommonMethods::weight(), and z.
{ run_ = iEvent.id().run(); lumi_ = iEvent.id().luminosityBlock(); event_ = iEvent.id().event(); for (std::vector<tnp::ProbeVariable>::const_iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) { it->init(iEvent); } for (std::vector<tnp::ProbeFlag>::const_iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) { it->init(iEvent); } if (weightMode_ == External) { edm::Handle<double> weight; iEvent.getByLabel(weightSrc_, weight); weight_ = *weight; } if (addEventVariablesInfo_) { edm::Handle<reco::VertexCollection> recVtxs; iEvent.getByLabel("offlinePrimaryVertices",recVtxs); mNPV_ = 0; mPVx_ = 100.0; mPVy_ = 100.0; mPVz_ = 100.0; for(unsigned int ind=0;ind<recVtxs->size();ind++) { if (!((*recVtxs)[ind].isFake()) && ((*recVtxs)[ind].ndof()>4) && (fabs((*recVtxs)[ind].z())<=24.0) && ((*recVtxs)[ind].position().Rho()<=2.0) ) { mNPV_++; if(mNPV_==1) { // store the first good primary vertex mPVx_ = (*recVtxs)[ind].x(); mPVy_ = (*recVtxs)[ind].y(); mPVz_ = (*recVtxs)[ind].z(); } } } edm::Handle<reco::BeamSpot> beamSpot; iEvent.getByLabel("offlineBeamSpot", beamSpot); mBSx_ = beamSpot->position().X(); mBSy_ = beamSpot->position().Y(); mBSz_ = beamSpot->position().Z(); edm::Handle<reco::CaloMETCollection> met; iEvent.getByLabel("met",met); if (met->size() == 0) { mMET_ = -1; mSumET_ = -1; mMETSign_ = -1; } else { mMET_ = (*met)[0].et(); mSumET_ = (*met)[0].sumEt(); mMETSign_ = (*met)[0].significance(); } edm::Handle<reco::METCollection> tcmet; iEvent.getByLabel("tcMet", tcmet); if (tcmet->size() == 0) { mtcMET_ = -1; mtcSumET_ = -1; mtcMETSign_ = -1; } else { mtcMET_ = (*tcmet)[0].et(); mtcSumET_ = (*tcmet)[0].sumEt(); mtcMETSign_ = (*tcmet)[0].significance(); } edm::Handle<reco::PFMETCollection> pfmet; iEvent.getByLabel("pfMet", pfmet); if (pfmet->size() == 0) { mpfMET_ = -1; mpfSumET_ = -1; mpfMETSign_ = -1; } else { mpfMET_ = (*pfmet)[0].et(); mpfSumET_ = (*pfmet)[0].sumEt(); mpfMETSign_ = (*pfmet)[0].significance(); } } }
void tnp::BaseTreeFiller::writeProvenance | ( | const edm::ParameterSet & | pset | ) | const |
Write a string dump of this PSet into the TTree header. see macro in test directory for how to retrieve it from the output root file
Definition at line 251 of file BaseTreeFiller.cc.
References edm::ParameterSet::dump(), and list().
bool tnp::BaseTreeFiller::addEventVariablesInfo_ [protected] |
Add branches with event variables: met, sum ET, .. etc.
Definition at line 167 of file BaseTreeFiller.h.
bool tnp::BaseTreeFiller::addRunLumiInfo_ [protected] |
Add branches with run and lumisection number.
Definition at line 164 of file BaseTreeFiller.h.
uint32_t tnp::BaseTreeFiller::event_ [mutable, protected] |
Definition at line 174 of file BaseTreeFiller.h.
std::vector<ProbeFlag> tnp::BaseTreeFiller::flags_ [protected] |
Definition at line 153 of file BaseTreeFiller.h.
bool tnp::BaseTreeFiller::ignoreExceptions_ [protected] |
Ignore exceptions when evaluating variables.
Definition at line 161 of file BaseTreeFiller.h.
uint32_t tnp::BaseTreeFiller::lumi_ [mutable, protected] |
Definition at line 174 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mBSx_ [mutable, protected] |
Definition at line 176 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mBSy_ [mutable, protected] |
Definition at line 176 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mBSz_ [mutable, protected] |
Definition at line 176 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mMET_ [mutable, protected] |
Definition at line 178 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mMETSign_ [mutable, protected] |
Definition at line 178 of file BaseTreeFiller.h.
uint32_t tnp::BaseTreeFiller::mNPV_ [mutable, protected] |
Definition at line 174 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mpfMET_ [mutable, protected] |
Definition at line 178 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mpfMETSign_ [mutable, protected] |
Definition at line 178 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mpfSumET_ [mutable, protected] |
Definition at line 178 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mPVx_ [mutable, protected] |
Definition at line 176 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mPVy_ [mutable, protected] |
Definition at line 176 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mPVz_ [mutable, protected] |
Definition at line 176 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mSumET_ [mutable, protected] |
Definition at line 178 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mtcMET_ [mutable, protected] |
Definition at line 178 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mtcMETSign_ [mutable, protected] |
Definition at line 178 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::mtcSumET_ [mutable, protected] |
Definition at line 178 of file BaseTreeFiller.h.
uint32_t tnp::BaseTreeFiller::run_ [mutable, protected] |
Definition at line 174 of file BaseTreeFiller.h.
TTree* tnp::BaseTreeFiller::tree_ [mutable, protected] |
Definition at line 172 of file BaseTreeFiller.h.
Referenced by BaseTreeFiller(), and tnp::TPTreeFiller::TPTreeFiller().
std::vector<ProbeVariable> tnp::BaseTreeFiller::vars_ [protected] |
Definition at line 152 of file BaseTreeFiller.h.
float tnp::BaseTreeFiller::weight_ [mutable, protected] |
Definition at line 173 of file BaseTreeFiller.h.
WeightMode tnp::BaseTreeFiller::weightMode_ [protected] |
Definition at line 157 of file BaseTreeFiller.h.
edm::InputTag tnp::BaseTreeFiller::weightSrc_ [protected] |
Definition at line 158 of file BaseTreeFiller.h.