CMS 3D CMS Logo

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 <cstdint>
7 
28 
34 
35 #include <TTree.h>
36 
43 namespace tnp {
44 
46  class ProbeVariable {
47  public:
49  ProbeVariable(const std::string &name, const std::string &expression)
50  : name_(name), external_(false), function_(expression) {}
51 
55 
58 
60  float *address() const { return &value_; }
61 
63  const std::string &name() const { return name_; }
64 
66  void init(const edm::Event &iEvent) const {
67  if (external_)
68  iEvent.getByToken(srcToken_, handle_);
69  }
70 
72  void fill(const reco::CandidateBaseRef &probe) const { value_ = external_ ? (*handle_)[probe] : function_(*probe); }
73 
74  private:
78  mutable float value_;
79 
81  bool external_;
82  // ---- this below is used if 'external_' is false
85  // In releases older than 3.4.X, it can be parially emulated by PATStringObjectFunction (PhysicsTools/PatUtils/interface/StringParserTools.h)
86  // Or you can use StringObjectFunction<reco::Candidate> and get only reco::Candidate methods
87 
88  // ---- this below is used if 'external_' is true
93  };
94 
95  class ProbeFlag {
96  public:
99 
103 
105  ~ProbeFlag();
106 
108  int32_t *address() const { return &value_; }
109 
111  const std::string &name() const { return name_; }
112 
114  void init(const edm::Event &iEvent) const;
115 
117  void fill(const reco::CandidateBaseRef &probe) const;
118 
119  private:
123  mutable int32_t value_;
124 
126  bool external_;
127  // ---- this below is used if 'external_' is false
130 
131  // ---- this below is used if 'external_' is true
135  mutable std::vector<reco::CandidateBaseRef> passingProbes_;
136  };
137 
138  // This class is noncopyable, as copying it would break the addresses in the TTree
140  public:
141  BaseTreeFiller(const BaseTreeFiller &) = delete;
142  BaseTreeFiller &operator=(const BaseTreeFiller &) = delete;
145  : BaseTreeFiller(name, config, iC){};
147 
150  const edm::ParameterSet &iConfig,
152  const std::string &branchNamePrefix);
153 
155  ~BaseTreeFiller();
156 
157  //implementation notice: we declare 'const' the methods which don't change the configuration
158  // and that can't mess up the addresses in the TTree.
159 
161  void init(const edm::Event &iEvent) const;
162 
164  void fill(const reco::CandidateBaseRef &probe) const;
165 
168  void writeProvenance(const edm::ParameterSet &pset) const;
169 
170  //get the pileup weight informations
171  bool storePUweight() const { return storePUweight_; };
172 
173  protected:
174  std::vector<ProbeVariable> vars_;
175  std::vector<ProbeFlag> flags_;
176 
180  bool LHEinfo_;
195 
198 
201 
204  bool addRho_;
206 
207  void addBranches_(TTree *tree,
208  const edm::ParameterSet &iConfig,
210  const std::string &branchNamePrefix = "");
211 
212  //implementation notice: these two are 'mutable' because we will fill them from a 'const' method
213  mutable TTree *tree_;
214  mutable float weight_, PUweight_, totWeight_;
215  mutable float lheWeight_[9];
216  mutable float psWeight_[5];
217  mutable uint32_t run_, lumi_, mNPV_;
218  mutable uint64_t event_;
219  mutable int truePU_;
220 
221  mutable float mPVx_, mPVy_, mPVz_, mBSx_, mBSy_, mBSz_;
222  mutable float rho_;
224  lhe_ht_;
225  };
226 
227 } // namespace tnp
228 
229 #endif
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
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
const std::string & name() const
name
edm::EDGetTokenT< GenEventInfoProduct > weightSrcToken_
bool addRunLumiInfo_
Add branches with run and lumisection number.
edm::EDGetTokenT< GenLumiInfoHeader > _genLumiInfoToken
edm::EDGetTokenT< double > PUweightSrcToken_
std::vector< ProbeVariable > vars_
ProbeFlag(const std::string &name, const std::string &cut)
Create a ProbeFlag to be evaluated on the fly from a string cut.
~ProbeFlag()
Destructor (does nothing)
StringCutObjectSelector< reco::Candidate, true > cut_
implementation of the cut using a string selector
int32_t * address() const
Addess for ROOT Branch.
std::string name_
the name of the variable, which becomes the ROOT branch name
Definition: config.py:1
void fill(const reco::CandidateBaseRef &probe) const
To be called once per probe, to fill the values for this probe.
BaseTreeFiller(const BaseTreeFiller &)=delete
BaseTreeFiller & operator=(const BaseTreeFiller &)=delete
A variable for the probe: can be a string expression or an external ValueMap<float> ...
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:224
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
StringObjectFunction< reco::Candidate, true > function_
a lazy-parsed StringObjectFunction<reco::Candidate> that gets all the methods of daughter classes too...
edm::Handle< edm::ValueMap< float > > handle_
the handle to keep the ValueMap
edm::EDGetTokenT< reco::CaloMETCollection > metToken_
edm::EDGetTokenT< LHEEventProduct > _LHECollection
float * address() const
Addess for ROOT Branch.
edm::EDGetTokenT< pat::METCollection > pfmetTokenMiniAOD_
edm::EDGetTokenT< reco::METCollection > tcmetToken_
ProbeVariable(const std::string &name, const edm::EDGetTokenT< edm::ValueMap< float > > &srcToken)
Create a ProbeVariable to be read from a ValueMap.
edm::EDGetTokenT< double > rhoToken_
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
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
void init(const edm::Event &iEvent) const
To be called at the beginning of the event (will fetch Candidate View if needed)
~ProbeVariable()
Destructor (does nothing)
void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC, const std::string &branchNamePrefix="")
const std::string & name() const
name
unsigned long long uint64_t
Definition: Time.h:13
void writeProvenance(const edm::ParameterSet &pset) const
bool storePUweight() const
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 init(const edm::Event &iEvent) const
To be called once per event, to load possible external variables.
Definition: main.py:1
bool external_
true if it&#39;s an external Candidate View, false if it&#39;s a StringParser cut
void init(const edm::Event &iEvent) const
To be called at the beginning of the event (will fetch ValueMap if needed)
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupInfoToken_
Definition: tree.py:1
bool storePUweight_
Store Pileup weight when running over Monte Carlo.
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
edm::EDGetTokenT< LHERunInfoProduct > _lheRunInfoToken
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