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
tnp::BaseTreeFiller::operator=
BaseTreeFiller & operator=(const BaseTreeFiller &)=delete
tnp::BaseTreeFiller::mpfPhi_
float mpfPhi_
Definition: BaseTreeFiller.h:223
Handle.h
PileupSummaryInfo.h
tnp::ProbeFlag::ProbeFlag
ProbeFlag(const std::string &name, const edm::EDGetTokenT< edm::View< reco::Candidate > > &srcToken)
Create a ProbeFlag to be read from a ValueMap.
Definition: BaseTreeFiller.h:101
tnp::ProbeFlag::value_
int32_t value_
the place where we store the value, and that ROOT uses to fill the tree
Definition: BaseTreeFiller.h:123
StringObjectFunction< reco::Candidate, true >
funct::false
false
Definition: Factorize.h:29
tnp::BaseTreeFiller::addCaloMet_
bool addCaloMet_
Definition: BaseTreeFiller.h:205
tnp::ProbeVariable::srcToken_
edm::EDGetTokenT< edm::ValueMap< float > > srcToken_
the external valuemap
Definition: BaseTreeFiller.h:90
tnp::BaseTreeFiller::rhoToken_
edm::EDGetTokenT< double > rhoToken_
Definition: BaseTreeFiller.h:187
tnp::ProbeVariable::name
const std::string & name() const
name
Definition: BaseTreeFiller.h:63
TkAlMuonSelectors_cfi.cut
cut
Definition: TkAlMuonSelectors_cfi.py:5
tnp::BaseTreeFiller::init
void init(const edm::Event &iEvent) const
To be called once per event, to load possible external variables.
Definition: BaseTreeFiller.cc:186
tnp::BaseTreeFiller::~BaseTreeFiller
~BaseTreeFiller()
Destructor, does nothing but it's out-of-line as we have complex data members.
Definition: BaseTreeFiller.cc:184
tnp::BaseTreeFiller::PUweight_
float PUweight_
Definition: BaseTreeFiller.h:214
tnp::BaseTreeFiller::External
Definition: BaseTreeFiller.h:178
tnp::ProbeVariable::function_
StringObjectFunction< reco::Candidate, true > function_
a lazy-parsed StringObjectFunction<reco::Candidate> that gets all the methods of daughter classes too
Definition: BaseTreeFiller.h:84
tnp::ProbeFlag
Definition: BaseTreeFiller.h:95
edm::EDGetTokenT
Definition: EDGetToken.h:33
tree
Definition: tree.py:1
tnp::BaseTreeFiller::metToken_
edm::EDGetTokenT< reco::CaloMETCollection > metToken_
Definition: BaseTreeFiller.h:190
tnp::BaseTreeFiller::LHEinfo_
bool LHEinfo_
Definition: BaseTreeFiller.h:180
tnp::BaseTreeFiller::storePUweight_
bool storePUweight_
Store Pileup weight when running over Monte Carlo.
Definition: BaseTreeFiller.h:200
tnp::ProbeFlag::external_
bool external_
true if it's an external Candidate View, false if it's a StringParser cut
Definition: BaseTreeFiller.h:126
tnp::BaseTreeFiller::mpfMETSign_
float mpfMETSign_
Definition: BaseTreeFiller.h:223
tnp::BaseTreeFiller::mMETSign_
float mMETSign_
Definition: BaseTreeFiller.h:223
tnp::BaseTreeFiller::BaseTreeFiller
BaseTreeFiller(const BaseTreeFiller &)=delete
PFMETCollection.h
tnp::BaseTreeFiller::psWeight_
float psWeight_[5]
Definition: BaseTreeFiller.h:216
tnp::BaseTreeFiller::mBSx_
float mBSx_
Definition: BaseTreeFiller.h:221
edm::Handle
Definition: AssociativeIterator.h:50
tnp::BaseTreeFiller::weight_
float weight_
Definition: BaseTreeFiller.h:214
tnp::ProbeVariable::value_
float value_
the place where we store the value, and that ROOT uses to fill the tree
Definition: BaseTreeFiller.h:78
CaloMETCollection.h
tnp::BaseTreeFiller::None
Definition: BaseTreeFiller.h:178
CandidateFwd.h
config
Definition: config.py:1
LHERunInfoProduct.h
tnp::BaseTreeFiller::weightMode_
WeightMode weightMode_
Definition: BaseTreeFiller.h:179
tnp::BaseTreeFiller::_LHECollection
edm::EDGetTokenT< LHEEventProduct > _LHECollection
Definition: BaseTreeFiller.h:182
BeamSpot.h
L1Validator_cfi.srcToken
srcToken
Definition: L1Validator_cfi.py:8
tnp::BaseTreeFiller::addRunLumiInfo_
bool addRunLumiInfo_
Add branches with run and lumisection number.
Definition: BaseTreeFiller.h:197
tnp::BaseTreeFiller::rho_
float rho_
Definition: BaseTreeFiller.h:222
CaloMET.h
tnp::BaseTreeFiller::writeProvenance
void writeProvenance(const edm::ParameterSet &pset) const
Definition: BaseTreeFiller.cc:355
tnp::ProbeVariable::ProbeVariable
ProbeVariable(const std::string &name, const edm::EDGetTokenT< edm::ValueMap< float > > &srcToken)
Create a ProbeVariable to be read from a ValueMap.
Definition: BaseTreeFiller.h:53
tnp::BaseTreeFiller::mMET_
float mMET_
Definition: BaseTreeFiller.h:223
tnp::BaseTreeFiller::mtcMET_
float mtcMET_
Definition: BaseTreeFiller.h:223
tnp::ProbeFlag::name
const std::string & name() const
name
Definition: BaseTreeFiller.h:111
tnp::BaseTreeFiller::_lheRunInfoToken
edm::EDGetTokenT< LHERunInfoProduct > _lheRunInfoToken
Definition: BaseTreeFiller.h:184
tnp::BaseTreeFiller::storePUweight
bool storePUweight() const
Definition: BaseTreeFiller.h:171
tnp::BaseTreeFiller::mPVx_
float mPVx_
Definition: BaseTreeFiller.h:221
tnp::ProbeFlag::srcToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
the external collection
Definition: BaseTreeFiller.h:133
tnp::BaseTreeFiller::mtcMETSign_
float mtcMETSign_
Definition: BaseTreeFiller.h:223
tnp::BaseTreeFiller::event_
uint64_t event_
Definition: BaseTreeFiller.h:218
tnp::BaseTreeFiller::_genLumiInfoToken
edm::EDGetTokenT< GenLumiInfoHeader > _genLumiInfoToken
Definition: BaseTreeFiller.h:183
tnp::BaseTreeFiller::beamSpotToken_
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
Definition: BaseTreeFiller.h:189
tnp::ProbeVariable::ProbeVariable
ProbeVariable(const std::string &name, const std::string &expression)
Create a ProbeVariable to be evaluated on the fly from a string expression.
Definition: BaseTreeFiller.h:49
tnp::BaseTreeFiller::genParticlesToken_
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
Definition: BaseTreeFiller.h:185
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
tnp::BaseTreeFiller::mPVy_
float mPVy_
Definition: BaseTreeFiller.h:221
Vertex.h
tnp::BaseTreeFiller::mpfSumET_
float mpfSumET_
Definition: BaseTreeFiller.h:223
tnp::ProbeVariable::init
void init(const edm::Event &iEvent) const
To be called at the beginning of the event (will fetch ValueMap if needed)
Definition: BaseTreeFiller.h:66
edm::View
Definition: CaloClusterFwd.h:14
funct::true
true
Definition: Factorize.h:173
tnp
Definition: BaseTreeFiller.h:43
METCollection.h
edm::ParameterSet
Definition: ParameterSet.h:47
tnp::BaseTreeFiller::lheWeight_
float lheWeight_[9]
Definition: BaseTreeFiller.h:215
GenEventInfoProduct.h
Event.h
tnp::BaseTreeFiller::mpfMET_
float mpfMET_
Definition: BaseTreeFiller.h:223
tnp::BaseTreeFiller::pileupInfoToken_
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupInfoToken_
Definition: BaseTreeFiller.h:194
tnp::ProbeFlag::ProbeFlag
ProbeFlag(const std::string &name, const std::string &cut)
Create a ProbeFlag to be evaluated on the fly from a string cut.
Definition: BaseTreeFiller.h:98
tnp::BaseTreeFiller::fill
void fill(const reco::CandidateBaseRef &probe) const
To be called once per probe, to fill the values for this probe.
Definition: BaseTreeFiller.cc:346
tnp::BaseTreeFiller::weightSrcToken_
edm::EDGetTokenT< GenEventInfoProduct > weightSrcToken_
Definition: BaseTreeFiller.h:181
PFMET.h
tnp::ProbeFlag::passingProbes_
std::vector< reco::CandidateBaseRef > passingProbes_
the handle to keep the refs to the passing probes
Definition: BaseTreeFiller.h:135
tnp::BaseTreeFiller::lhe_ht_
float lhe_ht_
Definition: BaseTreeFiller.h:223
iEvent
int iEvent
Definition: GenABIO.cc:224
tnp::ProbeFlag::fill
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
Definition: BaseTreeFiller.cc:25
GenLumiInfoHeader.h
tnp::BaseTreeFiller::mBSz_
float mBSz_
Definition: BaseTreeFiller.h:221
tnp::BaseTreeFiller::run_
uint32_t run_
Definition: BaseTreeFiller.h:217
MET.h
tnp::BaseTreeFiller::BaseTreeFiller
BaseTreeFiller(const char *name, const edm::ParameterSet &config, edm::ConsumesCollector &&iC)
specify the name of the TTree, and the configuration for it
Definition: BaseTreeFiller.h:144
tnp::BaseTreeFiller::mBSy_
float mBSy_
Definition: BaseTreeFiller.h:221
tnp::BaseTreeFiller::recVtxsToken_
edm::EDGetTokenT< reco::VertexCollection > recVtxsToken_
Definition: BaseTreeFiller.h:188
tnp::ProbeFlag::~ProbeFlag
~ProbeFlag()
Destructor (does nothing)
Definition: BaseTreeFiller.cc:13
tnp::ProbeFlag::cut_
StringCutObjectSelector< reco::Candidate, true > cut_
implementation of the cut using a string selector
Definition: BaseTreeFiller.h:129
main
Definition: main.py:1
InputTag.h
tnp::BaseTreeFiller::flags_
std::vector< ProbeFlag > flags_
Definition: BaseTreeFiller.h:175
tnp::BaseTreeFiller::addEventVariablesInfo_
bool addEventVariablesInfo_
Add branches with event variables: met, sum ET, .. etc.
Definition: BaseTreeFiller.h:203
ValueMap.h
tnp::ProbeFlag::name_
std::string name_
the name of the variable, which becomes the ROOT branch name
Definition: BaseTreeFiller.h:121
tnp::BaseTreeFiller::vars_
std::vector< ProbeVariable > vars_
Definition: BaseTreeFiller.h:171
VertexFwd.h
tnp::ProbeVariable::external_
bool external_
true if it's an external ValueMap, false if it's a StringParser function
Definition: BaseTreeFiller.h:81
tnp::BaseTreeFiller::pfmetToken_
edm::EDGetTokenT< reco::PFMETCollection > pfmetToken_
Definition: BaseTreeFiller.h:192
LHEEventProduct.h
MET.h
StringCutObjectSelector.h
tnp::BaseTreeFiller::tree_
TTree * tree_
Definition: BaseTreeFiller.h:213
tnp::ProbeVariable::handle_
edm::Handle< edm::ValueMap< float > > handle_
the handle to keep the ValueMap
Definition: BaseTreeFiller.h:92
tnp::BaseTreeFiller::Fixed
Definition: BaseTreeFiller.h:178
tnp::ProbeVariable::name_
std::string name_
the name of the variable, which becomes the ROOT branch name
Definition: BaseTreeFiller.h:76
tnp::BaseTreeFiller
Definition: BaseTreeFiller.h:139
edm::ValueMap< float >
tnp::ProbeFlag::address
int32_t * address() const
Addess for ROOT Branch.
Definition: BaseTreeFiller.h:108
tnp::ProbeVariable::~ProbeVariable
~ProbeVariable()
Destructor (does nothing)
Definition: BaseTreeFiller.cc:11
StringCutObjectSelector< reco::Candidate, true >
tnp::BaseTreeFiller::tcmetToken_
edm::EDGetTokenT< reco::METCollection > tcmetToken_
Definition: BaseTreeFiller.h:191
tnp::BaseTreeFiller::WeightMode
WeightMode
How event weights are defined: 'None' = no weights, 'Fixed' = one value specified in cfg file,...
Definition: BaseTreeFiller.h:178
tnp::BaseTreeFiller::mPVz_
float mPVz_
Definition: BaseTreeFiller.h:221
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::RefToBase< Candidate >
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
ConsumesCollector.h
Candidate.h
tnp::BaseTreeFiller::lumi_
uint32_t lumi_
Definition: BaseTreeFiller.h:217
ParameterSet.h
tnp::ProbeVariable
A variable for the probe: can be a string expression or an external ValueMap<float>
Definition: BaseTreeFiller.h:46
tnp::BaseTreeFiller::addBranches_
void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC, const std::string &branchNamePrefix="")
Definition: BaseTreeFiller.cc:143
tnp::ProbeVariable::fill
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
Definition: BaseTreeFiller.h:72
edm::Event
Definition: Event.h:73
tnp::BaseTreeFiller::truePU_
int truePU_
Definition: BaseTreeFiller.h:219
StringObjectFunction.h
tnp::BaseTreeFiller::PUweightSrcToken_
edm::EDGetTokenT< double > PUweightSrcToken_
Definition: BaseTreeFiller.h:186
tnp::ProbeVariable::address
float * address() const
Addess for ROOT Branch.
Definition: BaseTreeFiller.h:60
tnp::BaseTreeFiller::mSumET_
float mSumET_
Definition: BaseTreeFiller.h:223
tnp::BaseTreeFiller::addRho_
bool addRho_
Definition: BaseTreeFiller.h:204
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
tnp::BaseTreeFiller::totWeight_
float totWeight_
Definition: BaseTreeFiller.h:214
tnp::BaseTreeFiller::mtcSumET_
float mtcSumET_
Definition: BaseTreeFiller.h:223
tnp::BaseTreeFiller::pfmetTokenMiniAOD_
edm::EDGetTokenT< pat::METCollection > pfmetTokenMiniAOD_
Definition: BaseTreeFiller.h:193
tnp::ProbeFlag::init
void init(const edm::Event &iEvent) const
To be called at the beginning of the event (will fetch Candidate View if needed)
Definition: BaseTreeFiller.cc:15
tnp::BaseTreeFiller::mNPV_
uint32_t mNPV_
Definition: BaseTreeFiller.h:217