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 
27 
28 #include <TTree.h>
29 #include <boost/utility.hpp>
30 
31 
38 namespace tnp {
39 
42  public:
44  ProbeVariable(const std::string &name, const std::string &expression) :
45  name_(name), external_(false), function_(expression) {}
46 
49  name_(name), external_(true), function_("-1"), srcToken_(srcToken) {}
50 
52  ~ProbeVariable() ;
53 
55  float * address() const { return &value_; }
56 
58  const std::string & name() const { return name_; }
59 
61  void init(const edm::Event &iEvent) const {
62  if (external_) iEvent.getByToken(srcToken_, handle_);
63  }
64 
66  void fill(const reco::CandidateBaseRef &probe) const {
67  value_ = external_ ? (*handle_)[probe] : function_(*probe);
68  }
69 
70  private:
74  mutable float value_;
75 
77  bool external_;
78  // ---- this below is used if 'external_' is false
81  // In releases older than 3.4.X, it can be parially emulated by PATStringObjectFunction (PhysicsTools/PatUtils/interface/StringParserTools.h)
82  // Or you can use StringObjectFunction<reco::Candidate> and get only reco::Candidate methods
83 
84  // ---- this below is used if 'external_' is true
89 };
90 
91 class ProbeFlag {
92  public:
95  name_(name), external_(false), cut_(cut) {}
96 
99  name_(name), external_(true), cut_(""), srcToken_(srcToken) {}
100 
102  ~ProbeFlag() ;
103 
105  int32_t * address() const { return &value_; }
106 
108  const std::string & name() const { return name_; }
109 
111  void init(const edm::Event &iEvent) const ;
112 
114  void fill(const reco::CandidateBaseRef &probe) const ;
115 
116  private:
120  mutable int32_t value_;
121 
123  bool external_;
124  // ---- this below is used if 'external_' is false
127 
128  // ---- this below is used if 'external_' is true
132  mutable std::vector<reco::CandidateBaseRef> passingProbes_;
133 };
134 
135 
136 // This class inherits from boost::noncopyable, as copying it would break the addresses in the TTree
137 class BaseTreeFiller : boost::noncopyable {
138  public:
140  BaseTreeFiller(const char *name, const edm::ParameterSet& config, edm::ConsumesCollector && iC) : BaseTreeFiller(name, config, iC) {};
142 
144  BaseTreeFiller(BaseTreeFiller &main, const edm::ParameterSet &iConfig, edm::ConsumesCollector && iC, const std::string &branchNamePrefix);
145 
147  ~BaseTreeFiller();
148 
149  //implementation notice: we declare 'const' the methods which don't change the configuration
150  // and that can't mess up the addresses in the TTree.
151 
153  void init(const edm::Event &iEvent) const ;
154 
156  void fill(const reco::CandidateBaseRef &probe) const ;
157 
160  void writeProvenance(const edm::ParameterSet &pset) const ;
161  protected:
162 
163  std::vector<ProbeVariable> vars_;
164  std::vector<ProbeFlag> flags_;
165 
175 
178 
181 
184 
185  void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, edm::ConsumesCollector & iC, const std::string &branchNamePrefix="") ;
186 
187  //implementation notice: these two are 'mutable' because we will fill them from a 'const' method
188  mutable TTree * tree_;
189  mutable float weight_;
190  mutable uint32_t run_, lumi_, event_, mNPV_;
191 
192  mutable float mPVx_,mPVy_,mPVz_,mBSx_,mBSy_,mBSz_;
193 
196 };
197 
198 
199 } //namespace
200 
201 #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.
edm::EDGetTokenT< reco::PFMETCollection > pfmetToken_
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
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
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
ProbeFlag(const std::string &name, const edm::EDGetTokenT< edm::View< reco::Candidate > > &srcToken)
Create a ProbeFlag 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:230
edm::Handle< edm::ValueMap< float > > handle_
the handle to keep the ValueMap
edm::EDGetTokenT< reco::CaloMETCollection > metToken_
edm::EDGetTokenT< reco::METCollection > tcmetToken_
void init(const edm::Event &iEvent) const
To be called once per event, to load possible external variables.
ProbeVariable(const std::string &name, const edm::EDGetTokenT< edm::ValueMap< float > > &srcToken)
Create a ProbeVariable to be read from a ValueMap.
int32_t value_
the place where we store the value, and that ROOT uses to fill the tree
edm::EDGetTokenT< edm::ValueMap< float > > srcToken_
the external valuemap
~ProbeVariable()
Destructor (does nothing)
void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC, const std::string &branchNamePrefix="")
WeightMode
How event weights are defined: &#39;None&#39; = no weights, &#39;Fixed&#39; = one value specified in cfg file...
edm::EDGetTokenT< reco::VertexCollection > recVtxsToken_
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
bool ignoreExceptions_
Ignore exceptions when evaluating variables.
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...
volatile std::atomic< bool > shutdown_flag false
edm::EDGetTokenT< double > weightSrcToken_
const std::string & name() const
name
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
the external collection
std::vector< reco::CandidateBaseRef > passingProbes_
the handle to keep the refs to the passing probes
float value_
the place where we store the value, and that ROOT uses to fill the tree
BaseTreeFiller(const char *name, const edm::ParameterSet &config, edm::ConsumesCollector &&iC)
specify the name of the TTree, and the configuration for it