CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
tnp::BaseTreeFiller Class Reference

#include <BaseTreeFiller.h>

Inheritance diagram for tnp::BaseTreeFiller:
tnp::TPTreeFiller

Public Member Functions

 BaseTreeFiller (const char *name, const edm::ParameterSet config)
 specify the name of the TTree, and the configuration for it More...
 
 BaseTreeFiller (BaseTreeFiller &main, const edm::ParameterSet &iConfig, const std::string &branchNamePrefix)
 Add branches to an existing TTree managed by another BaseTreeFiller. More...
 
void fill (const reco::CandidateBaseRef &probe) const
 To be called once per probe, to fill the values for this probe. More...
 
void init (const edm::Event &iEvent) const
 To be called once per event, to load possible external variables. More...
 
void writeProvenance (const edm::ParameterSet &pset) const
 
 ~BaseTreeFiller ()
 Destructor, does nothing but it's out-of-line as we have complex data members. More...
 

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. More...
 
bool addRunLumiInfo_
 Add branches with run and lumisection number. More...
 
uint32_t event_
 
std::vector< ProbeFlagflags_
 
bool ignoreExceptions_
 Ignore exceptions when evaluating variables. More...
 
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< ProbeVariablevars_
 
float weight_
 
WeightMode weightMode_
 
edm::InputTag weightSrc_
 

Detailed Description

Definition at line 127 of file BaseTreeFiller.h.

Member Enumeration Documentation

How event weights are defined: 'None' = no weights, 'Fixed' = one value specified in cfg file, 'External' = read weight from the event (as double)

Enumerator
None 
Fixed 
External 

Definition at line 156 of file BaseTreeFiller.h.

Constructor & Destructor Documentation

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 event_(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), TFileDirectory::make(), and mergeVDriftHistosByStation::name.

41  {
42  // make trees as requested
44  tree_ = fs->make<TTree>(name,name);
45 
46  // add the branches
47  addBranches_(tree_, iConfig, "");
48 
49  // set up weights, if needed
50  if (iConfig.existsAs<double>("eventWeight")) {
52  weight_ = iConfig.getParameter<double>("eventWeight");
53  } else if (iConfig.existsAs<edm::InputTag>("eventWeight")) {
55  weightSrc_ = iConfig.getParameter<edm::InputTag>("eventWeight");
56  } else {
57  weightMode_ = None;
58  }
59  if (weightMode_ != None) {
60  tree_->Branch("weight", &weight_, "weight/F");
61  }
62 
63  addRunLumiInfo_ = iConfig.existsAs<bool>("addRunLumiInfo") ? iConfig.getParameter<bool>("addRunLumiInfo") : false;
64  if (addRunLumiInfo_) {
65  tree_->Branch("run", &run_, "run/i");
66  tree_->Branch("lumi", &lumi_, "lumi/i");
67  tree_->Branch("event", &event_, "event/i");
68  }
69  addEventVariablesInfo_ = iConfig.existsAs<bool>("addEventVariablesInfo") ? iConfig.getParameter<bool>("addEventVariablesInfo") : false;
71  tree_->Branch("event_nPV" ,&mNPV_ ,"mNPV/I");
72  tree_->Branch("event_met_calomet" ,&mMET_ ,"mMET/F");
73  tree_->Branch("event_met_calosumet" ,&mSumET_ ,"mSumET/F");
74  tree_->Branch("event_met_calometsignificance",&mMETSign_ ,"mMETSign/F");
75  tree_->Branch("event_met_tcmet" ,&mtcMET_ ,"mtcMET/F");
76  tree_->Branch("event_met_tcsumet" ,&mtcSumET_ ,"mtcSumET/F");
77  tree_->Branch("event_met_tcmetsignificance",&mtcMETSign_ ,"mtcMETSign/F");
78  tree_->Branch("event_met_pfmet" ,&mpfMET_ ,"mpfMET/F");
79  tree_->Branch("event_met_pfsumet" ,&mpfSumET_ ,"mpfSumET/F");
80  tree_->Branch("event_met_pfmetsignificance",&mpfMETSign_ ,"mpfMETSign/F");
81  tree_->Branch("event_PrimaryVertex_x" ,&mPVx_ ,"mPVx/F");
82  tree_->Branch("event_PrimaryVertex_y" ,&mPVy_ ,"mPVy/F");
83  tree_->Branch("event_PrimaryVertex_z" ,&mPVz_ ,"mPVz/F");
84  tree_->Branch("event_BeamSpot_x" ,&mBSx_ ,"mBSx/F");
85  tree_->Branch("event_BeamSpot_y" ,&mBSy_ ,"mBSy/F");
86  tree_->Branch("event_BeamSpot_z" ,&mBSz_ ,"mBSz/F");
87  }
88 
89  ignoreExceptions_ = iConfig.existsAs<bool>("ignoreExceptions") ? iConfig.getParameter<bool>("ignoreExceptions") : false;
90 }
bool addEventVariablesInfo_
Add branches with event variables: met, sum ET, .. etc.
bool addRunLumiInfo_
Add branches with run and lumisection number.
edm::InputTag weightSrc_
bool ignoreExceptions_
Ignore exceptions when evaluating variables.
T * make() const
make new ROOT object
void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, const std::string &branchNamePrefix="")
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_.

92  :
94  tree_(0)
95 {
96  addBranches_(main.tree_, iConfig, branchNamePrefix);
97 }
bool addEventVariablesInfo_
Add branches with event variables: met, sum ET, .. etc.
int main(int argc, char **argv)
void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, const std::string &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.

137 { }

Member Function Documentation

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 makeLayoutFileForGui::variables.

Referenced by BaseTreeFiller().

100  {
101  // set up variables
103  //.. the ones that are strings
104  std::vector<std::string> stringVars = variables.getParameterNamesForType<std::string>();
105  for (std::vector<std::string>::const_iterator it = stringVars.begin(), ed = stringVars.end(); it != ed; ++it) {
106  vars_.push_back(tnp::ProbeVariable(branchNamePrefix + *it, variables.getParameter<std::string>(*it)));
107  }
108  //.. the ones that are InputTags
109  std::vector<std::string> inputTagVars = variables.getParameterNamesForType<edm::InputTag>();
110  for (std::vector<std::string>::const_iterator it = inputTagVars.begin(), ed = inputTagVars.end(); it != ed; ++it) {
111  vars_.push_back(tnp::ProbeVariable(branchNamePrefix + *it, variables.getParameter<edm::InputTag>(*it)));
112  }
113  // set up flags
115  //.. the ones that are strings
116  std::vector<std::string> stringFlags = flags.getParameterNamesForType<std::string>();
117  for (std::vector<std::string>::const_iterator it = stringFlags.begin(), ed = stringFlags.end(); it != ed; ++it) {
118  flags_.push_back(tnp::ProbeFlag(branchNamePrefix + *it, flags.getParameter<std::string>(*it)));
119  }
120  //.. the ones that are InputTags
121  std::vector<std::string> inputTagFlags = flags.getParameterNamesForType<edm::InputTag>();
122  for (std::vector<std::string>::const_iterator it = inputTagFlags.begin(), ed = inputTagFlags.end(); it != ed; ++it) {
123  flags_.push_back(tnp::ProbeFlag(branchNamePrefix + *it, flags.getParameter<edm::InputTag>(*it)));
124  }
125 
126  // then make all the variables in the trees
127  for (std::vector<tnp::ProbeVariable>::iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) {
128  tree->Branch(it->name().c_str(), it->address(), (it->name()+"/F").c_str());
129  }
130 
131  for (std::vector<tnp::ProbeFlag>::iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) {
132  tree->Branch(it->name().c_str(), it->address(), (it->name()+"/I").c_str());
133  }
134 
135 }
T getParameter(std::string const &) const
std::vector< ProbeVariable > vars_
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
A variable for the probe: can be a string expression or an external ValueMap&lt;float&gt; ...
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:195
std::vector< ProbeFlag > flags_
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().

233  {
234  for (std::vector<tnp::ProbeVariable>::const_iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) {
235  if (ignoreExceptions_) {
236  try{ it->fill(probe); } catch(cms::Exception &ex ){}
237  } else {
238  it->fill(probe);
239  }
240  }
241 
242  for (std::vector<tnp::ProbeFlag>::const_iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) {
243  if (ignoreExceptions_) {
244  try{ it->fill(probe); } catch(cms::Exception &ex ){}
245  } else {
246  it->fill(probe);
247  }
248  }
249  if (tree_) tree_->Fill();
250 }
std::vector< ProbeVariable > vars_
std::vector< ProbeFlag > flags_
bool ignoreExceptions_
Ignore exceptions when evaluating variables.
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 //////////////

Definition at line 139 of file BaseTreeFiller.cc.

References SiPixelRawToDigiRegional_cfi::beamSpot, edm::EventID::event(), event_(), edm::Event::getByLabel(), edm::EventBase::id(), edm::EventID::luminosityBlock(), CaloMET_cfi::met, edm::EventID::run(), CommonMethods::weight(), and detailsBasic3DVector::z.

Referenced by tnp::TPTreeFiller::init().

139  {
140  run_ = iEvent.id().run();
141  lumi_ = iEvent.id().luminosityBlock();
142  event_ = iEvent.id().event();
143 
144  for (std::vector<tnp::ProbeVariable>::const_iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) {
145  it->init(iEvent);
146  }
147  for (std::vector<tnp::ProbeFlag>::const_iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) {
148  it->init(iEvent);
149  }
150  if (weightMode_ == External) {
152  iEvent.getByLabel(weightSrc_, weight);
153  weight_ = *weight;
154  }
155 
160  iEvent.getByLabel("offlinePrimaryVertices",recVtxs);
161  mNPV_ = 0;
162  mPVx_ = 100.0;
163  mPVy_ = 100.0;
164  mPVz_ = 100.0;
165 
166  for(unsigned int ind=0;ind<recVtxs->size();ind++) {
167  if (!((*recVtxs)[ind].isFake()) && ((*recVtxs)[ind].ndof()>4)
168  && (fabs((*recVtxs)[ind].z())<=24.0) &&
169  ((*recVtxs)[ind].position().Rho()<=2.0) ) {
170  mNPV_++;
171  if(mNPV_==1) { // store the first good primary vertex
172  mPVx_ = (*recVtxs)[ind].x();
173  mPVy_ = (*recVtxs)[ind].y();
174  mPVz_ = (*recVtxs)[ind].z();
175  }
176  }
177  }
178 
179 
182  iEvent.getByLabel("offlineBeamSpot", beamSpot);
183  mBSx_ = beamSpot->position().X();
184  mBSy_ = beamSpot->position().Y();
185  mBSz_ = beamSpot->position().Z();
186 
187 
190  iEvent.getByLabel("met",met);
191  if (met->size() == 0) {
192  mMET_ = -1;
193  mSumET_ = -1;
194  mMETSign_ = -1;
195  }
196  else {
197  mMET_ = (*met)[0].et();
198  mSumET_ = (*met)[0].sumEt();
199  mMETSign_ = (*met)[0].significance();
200  }
201 
204  iEvent.getByLabel("tcMet", tcmet);
205  if (tcmet->size() == 0) {
206  mtcMET_ = -1;
207  mtcSumET_ = -1;
208  mtcMETSign_ = -1;
209  }
210  else {
211  mtcMET_ = (*tcmet)[0].et();
212  mtcSumET_ = (*tcmet)[0].sumEt();
213  mtcMETSign_ = (*tcmet)[0].significance();
214  }
215 
218  iEvent.getByLabel("pfMet", pfmet);
219  if (pfmet->size() == 0) {
220  mpfMET_ = -1;
221  mpfSumET_ = -1;
222  mpfMETSign_ = -1;
223  }
224  else {
225  mpfMET_ = (*pfmet)[0].et();
226  mpfSumET_ = (*pfmet)[0].sumEt();
227  mpfMETSign_ = (*pfmet)[0].significance();
228  }
229  }
230 
231 }
RunNumber_t run() const
Definition: EventID.h:42
bool addEventVariablesInfo_
Add branches with event variables: met, sum ET, .. etc.
EventNumber_t event() const
Definition: EventID.h:44
std::vector< ProbeVariable > vars_
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
double double double z
std::vector< ProbeFlag > flags_
edm::InputTag weightSrc_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::EventID id() const
Definition: EventBase.h:56
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().

251  {
252  TList *list = tree_->GetUserInfo();
253  list->Add(new TObjString(pset.dump().c_str()));
254 }
std::string dump() const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run

Member Data Documentation

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_
mutableprotected

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_
mutableprotected

Definition at line 174 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mBSx_
mutableprotected

Definition at line 176 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mBSy_
mutableprotected

Definition at line 176 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mBSz_
mutableprotected

Definition at line 176 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mMET_
mutableprotected

Definition at line 178 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mMETSign_
mutableprotected

Definition at line 178 of file BaseTreeFiller.h.

uint32_t tnp::BaseTreeFiller::mNPV_
mutableprotected

Definition at line 174 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mpfMET_
mutableprotected

Definition at line 178 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mpfMETSign_
mutableprotected

Definition at line 178 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mpfSumET_
mutableprotected

Definition at line 178 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mPVx_
mutableprotected

Definition at line 176 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mPVy_
mutableprotected

Definition at line 176 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mPVz_
mutableprotected

Definition at line 176 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mSumET_
mutableprotected

Definition at line 178 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mtcMET_
mutableprotected

Definition at line 178 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mtcMETSign_
mutableprotected

Definition at line 178 of file BaseTreeFiller.h.

float tnp::BaseTreeFiller::mtcSumET_
mutableprotected

Definition at line 178 of file BaseTreeFiller.h.

uint32_t tnp::BaseTreeFiller::run_
mutableprotected

Definition at line 174 of file BaseTreeFiller.h.

TTree* tnp::BaseTreeFiller::tree_
mutableprotected

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_
mutableprotected

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.