CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BaseTreeFiller.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_TagAndProbe_BaseTreeFiller_h
2 #define PhysicsTools_TagAndProbe_BaseTreeFiller_h
3 
4 #include <vector>
5 #include <string>
6 #include <stdint.h>
7 
17 
18 #include <TTree.h>
19 #include <boost/utility.hpp>
20 
21 
28 namespace tnp {
29 
32  public:
34  ProbeVariable(const std::string &name, const std::string &expression) :
35  name_(name), external_(false), function_(expression) {}
36 
38  ProbeVariable(const std::string &name, const edm::InputTag &src) :
39  name_(name), external_(true), function_("-1"), src_(src) {}
40 
42  ~ProbeVariable() ;
43 
45  float * address() const { return &value_; }
46 
48  const std::string & name() const { return name_; }
49 
51  void init(const edm::Event &iEvent) const {
52  if (external_) iEvent.getByLabel(src_, handle_);
53  }
54 
56  void fill(const reco::CandidateBaseRef &probe) const {
57  value_ = external_ ? (*handle_)[probe] : function_(*probe);
58  }
59 
60  private:
62  std::string name_;
64  mutable float value_;
65 
67  bool external_;
68  // ---- this below is used if 'external_' is false
71  // In releases older than 3.4.X, it can be parially emulated by PATStringObjectFunction (PhysicsTools/PatUtils/interface/StringParserTools.h)
72  // Or you can use StringObjectFunction<reco::Candidate> and get only reco::Candidate methods
73 
74  // ---- this below is used if 'external_' is true
79 };
80 
81 class ProbeFlag {
82  public:
84  ProbeFlag(const std::string &name, const std::string &cut) :
85  name_(name), external_(false), cut_(cut) {}
86 
88  ProbeFlag(const std::string &name, const edm::InputTag &src) :
89  name_(name), external_(true), cut_(""), src_(src) {}
90 
92  ~ProbeFlag() ;
93 
95  int32_t * address() const { return &value_; }
96 
98  const std::string & name() const { return name_; }
99 
101  void init(const edm::Event &iEvent) const ;
102 
104  void fill(const reco::CandidateBaseRef &probe) const ;
105 
106  private:
108  std::string name_;
110  mutable int32_t value_;
111 
113  bool external_;
114  // ---- this below is used if 'external_' is false
117 
118  // ---- this below is used if 'external_' is true
122  mutable std::vector<reco::CandidateBaseRef> passingProbes_;
123 };
124 
125 
126 // This class inherits from boost::noncopyable, as copying it would break the addresses in the TTree
127 class BaseTreeFiller : boost::noncopyable {
128  public:
130  BaseTreeFiller(const char *name, const edm::ParameterSet config);
131 
133  BaseTreeFiller(BaseTreeFiller &main, const edm::ParameterSet &iConfig, const std::string &branchNamePrefix);
134 
136  ~BaseTreeFiller();
137 
138  //implementation notice: we declare 'const' the methods which don't change the configuration
139  // and that can't mess up the addresses in the TTree.
140 
142  void init(const edm::Event &iEvent) const ;
143 
145  void fill(const reco::CandidateBaseRef &probe) const ;
146 
149  void writeProvenance(const edm::ParameterSet &pset) const ;
150  protected:
151 
152  std::vector<ProbeVariable> vars_;
153  std::vector<ProbeFlag> flags_;
154 
159 
162 
165 
168 
169  void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, const std::string &branchNamePrefix="") ;
170 
171  //implementation notice: these two are 'mutable' because we will fill them from a 'const' method
172  mutable TTree * tree_;
173  mutable float weight_;
174  mutable uint32_t run_, lumi_, event_, mNPV_;
175 
176  mutable float mPVx_,mPVy_,mPVz_,mBSx_,mBSy_,mBSz_;
177 
180 };
181 
182 
183 } //namespace
184 
185 #endif
float * address() const
Addess for ROOT Branch.
bool addEventVariablesInfo_
Add branches with event variables: met, sum ET, .. etc.
ProbeVariable(const std::string &name, const std::string &expression)
Create a ProbeVariable to be evaluated on the fly from a string expression.
bool external_
true if it&#39;s an external ValueMap, false if it&#39;s a StringParser function
std::string name_
the name of the variable, which becomes the ROOT branch name
BaseTreeFiller(const char *name, const edm::ParameterSet config)
specify the name of the TTree, and the configuration for it
void init(const edm::Event &iEvent) const
To be called at the beginning of the event (will fetch Candidate View if needed)
bool addRunLumiInfo_
Add branches with run and lumisection number.
void writeProvenance(const edm::ParameterSet &pset) const
std::vector< ProbeVariable > vars_
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
ProbeFlag(const std::string &name, const std::string &cut)
Create a ProbeFlag to be evaluated on the fly from a string cut.
StringCutObjectSelector< reco::Candidate, true > cut_
implementation of the cut using a string selector
~ProbeFlag()
Destructor (does nothing)
std::string name_
the name of the variable, which becomes the ROOT branch name
void init(const edm::Event &iEvent) const
To be called at the beginning of the event (will fetch ValueMap if needed)
void fill(const reco::CandidateBaseRef &probe) const
To be called once per probe, to fill the values for this probe.
A variable for the probe: can be a string expression or an external ValueMap&lt;float&gt; ...
int main(int argc, char **argv)
int32_t * address() const
Addess for ROOT Branch.
const std::string & name() const
name
ProbeVariable(const std::string &name, const edm::InputTag &src)
Create a ProbeVariable to be read from a ValueMap.
std::vector< ProbeFlag > flags_
~BaseTreeFiller()
Destructor, does nothing but it&#39;s out-of-line as we have complex data members.
int iEvent
Definition: GenABIO.cc:243
edm::Handle< edm::ValueMap< float > > handle_
the handle to keep the ValueMap
ProbeFlag(const std::string &name, const edm::InputTag &src)
Create a ProbeFlag to be read from a ValueMap.
void init(const edm::Event &iEvent) const
To be called once per event, to load possible external variables.
edm::InputTag weightSrc_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
int32_t value_
the place where we store the value, and that ROOT uses to fill the tree
~ProbeVariable()
Destructor (does nothing)
WeightMode
How event weights are defined: &#39;None&#39; = no weights, &#39;Fixed&#39; = one value specified in cfg file...
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
bool ignoreExceptions_
Ignore exceptions when evaluating variables.
edm::InputTag src_
the external collection
bool external_
true if it&#39;s an external Candidate View, false if it&#39;s a StringParser cut
StringObjectFunction< reco::Candidate, true > function_
a lazy-parsed StringObjectFunction&lt;reco::Candidate&gt; that gets all the methods of daughter classes too...
const std::string & name() const
name
std::vector< reco::CandidateBaseRef > passingProbes_
the handle to keep the refs to the passing probes
edm::InputTag src_
the external valuemap
float value_
the place where we store the value, and that ROOT uses to fill the tree
void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, const std::string &branchNamePrefix="")