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 
31 
32 #include <TTree.h>
33 #include <boost/utility.hpp>
34 
41 namespace tnp {
42 
44  class ProbeVariable {
45  public:
47  ProbeVariable(const std::string &name, const std::string &expression)
48  : name_(name), external_(false), function_(expression) {}
49 
53 
56 
58  float *address() const { return &value_; }
59 
61  const std::string &name() const { return name_; }
62 
64  void init(const edm::Event &iEvent) const {
65  if (external_)
66  iEvent.getByToken(srcToken_, handle_);
67  }
68 
70  void fill(const reco::CandidateBaseRef &probe) const { value_ = external_ ? (*handle_)[probe] : function_(*probe); }
71 
72  private:
76  mutable float value_;
77 
79  bool external_;
80  // ---- this below is used if 'external_' is false
83  // In releases older than 3.4.X, it can be parially emulated by PATStringObjectFunction (PhysicsTools/PatUtils/interface/StringParserTools.h)
84  // Or you can use StringObjectFunction<reco::Candidate> and get only reco::Candidate methods
85 
86  // ---- this below is used if 'external_' is true
91  };
92 
93  class ProbeFlag {
94  public:
97 
101 
103  ~ProbeFlag();
104 
106  int32_t *address() const { return &value_; }
107 
109  const std::string &name() const { return name_; }
110 
112  void init(const edm::Event &iEvent) const;
113 
115  void fill(const reco::CandidateBaseRef &probe) const;
116 
117  private:
121  mutable int32_t value_;
122 
124  bool external_;
125  // ---- this below is used if 'external_' is false
128 
129  // ---- this below is used if 'external_' is true
133  mutable std::vector<reco::CandidateBaseRef> passingProbes_;
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:
141  : BaseTreeFiller(name, config, iC){};
143 
146  const edm::ParameterSet &iConfig,
148  const std::string &branchNamePrefix);
149 
151  ~BaseTreeFiller();
152 
153  //implementation notice: we declare 'const' the methods which don't change the configuration
154  // and that can't mess up the addresses in the TTree.
155 
157  void init(const edm::Event &iEvent) const;
158 
160  void fill(const reco::CandidateBaseRef &probe) const;
161 
164  void writeProvenance(const edm::ParameterSet &pset) const;
165 
166  //get the pileup weight informations
167  bool storePUweight() const { return storePUweight_; };
168 
169  protected:
170  std::vector<ProbeVariable> vars_;
171  std::vector<ProbeFlag> flags_;
172 
186 
189 
192 
195  bool addRho_;
197 
198  void addBranches_(TTree *tree,
199  const edm::ParameterSet &iConfig,
201  const std::string &branchNamePrefix = "");
202 
203  //implementation notice: these two are 'mutable' because we will fill them from a 'const' method
204  mutable TTree *tree_;
205  mutable float weight_, PUweight_, totWeight_;
206  mutable uint32_t run_, lumi_, mNPV_;
207  mutable uint64_t event_;
208  mutable int truePU_;
209 
210  mutable float mPVx_, mPVy_, mPVz_, mBSx_, mBSy_, mBSz_;
211  mutable float rho_;
213  };
214 
215 } // namespace tnp
216 
217 #endif
tnp::BaseTreeFiller::mpfPhi_
float mpfPhi_
Definition: BaseTreeFiller.h:212
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:99
tnp::ProbeFlag::value_
int32_t value_
the place where we store the value, and that ROOT uses to fill the tree
Definition: BaseTreeFiller.h:121
StringObjectFunction< reco::Candidate, true >
funct::false
false
Definition: Factorize.h:34
tnp::BaseTreeFiller::addCaloMet_
bool addCaloMet_
Definition: BaseTreeFiller.h:196
tnp::ProbeVariable::srcToken_
edm::EDGetTokenT< edm::ValueMap< float > > srcToken_
the external valuemap
Definition: BaseTreeFiller.h:88
tnp::BaseTreeFiller::rhoToken_
edm::EDGetTokenT< double > rhoToken_
Definition: BaseTreeFiller.h:178
tnp::ProbeVariable::name
const std::string & name() const
name
Definition: BaseTreeFiller.h:61
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:180
tnp::BaseTreeFiller::~BaseTreeFiller
~BaseTreeFiller()
Destructor, does nothing but it's out-of-line as we have complex data members.
Definition: BaseTreeFiller.cc:178
tnp::BaseTreeFiller::PUweight_
float PUweight_
Definition: BaseTreeFiller.h:205
tnp::BaseTreeFiller::External
Definition: BaseTreeFiller.h:174
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:82
tnp::ProbeFlag
Definition: BaseTreeFiller.h:93
edm::EDGetTokenT
Definition: EDGetToken.h:33
tree
Definition: tree.py:1
tnp::BaseTreeFiller::metToken_
edm::EDGetTokenT< reco::CaloMETCollection > metToken_
Definition: BaseTreeFiller.h:181
tnp::BaseTreeFiller::storePUweight_
bool storePUweight_
Store Pileup weight when running over Monte Carlo.
Definition: BaseTreeFiller.h:191
tnp::ProbeFlag::external_
bool external_
true if it's an external Candidate View, false if it's a StringParser cut
Definition: BaseTreeFiller.h:124
tnp::BaseTreeFiller::mpfMETSign_
float mpfMETSign_
Definition: BaseTreeFiller.h:212
tnp::BaseTreeFiller::mMETSign_
float mMETSign_
Definition: BaseTreeFiller.h:212
PFMETCollection.h
tnp::BaseTreeFiller::mBSx_
float mBSx_
Definition: BaseTreeFiller.h:210
edm::Handle
Definition: AssociativeIterator.h:50
tnp::BaseTreeFiller::weight_
float weight_
Definition: BaseTreeFiller.h:205
tnp::ProbeVariable::value_
float value_
the place where we store the value, and that ROOT uses to fill the tree
Definition: BaseTreeFiller.h:76
CaloMETCollection.h
tnp::BaseTreeFiller::None
Definition: BaseTreeFiller.h:174
CandidateFwd.h
config
Definition: config.py:1
tnp::BaseTreeFiller::weightMode_
WeightMode weightMode_
Definition: BaseTreeFiller.h:175
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:188
tnp::BaseTreeFiller::rho_
float rho_
Definition: BaseTreeFiller.h:211
CaloMET.h
tnp::BaseTreeFiller::writeProvenance
void writeProvenance(const edm::ParameterSet &pset) const
Definition: BaseTreeFiller.cc:317
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:51
tnp::BaseTreeFiller::mMET_
float mMET_
Definition: BaseTreeFiller.h:212
tnp::BaseTreeFiller::mtcMET_
float mtcMET_
Definition: BaseTreeFiller.h:212
tnp::ProbeFlag::name
const std::string & name() const
name
Definition: BaseTreeFiller.h:109
tnp::BaseTreeFiller::storePUweight
bool storePUweight() const
Definition: BaseTreeFiller.h:167
tnp::BaseTreeFiller::mPVx_
float mPVx_
Definition: BaseTreeFiller.h:210
tnp::ProbeFlag::srcToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
the external collection
Definition: BaseTreeFiller.h:131
tnp::BaseTreeFiller::mtcMETSign_
float mtcMETSign_
Definition: BaseTreeFiller.h:212
tnp::BaseTreeFiller::event_
uint64_t event_
Definition: BaseTreeFiller.h:207
tnp::BaseTreeFiller::beamSpotToken_
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
Definition: BaseTreeFiller.h:180
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:47
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
tnp::BaseTreeFiller::mPVy_
float mPVy_
Definition: BaseTreeFiller.h:210
Vertex.h
tnp::BaseTreeFiller::mpfSumET_
float mpfSumET_
Definition: BaseTreeFiller.h:212
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:64
edm::View
Definition: CaloClusterFwd.h:14
funct::true
true
Definition: Factorize.h:173
tnp
Definition: BaseTreeFiller.h:41
METCollection.h
edm::ParameterSet
Definition: ParameterSet.h:36
GenEventInfoProduct.h
Event.h
tnp::BaseTreeFiller::mpfMET_
float mpfMET_
Definition: BaseTreeFiller.h:212
tnp::BaseTreeFiller::pileupInfoToken_
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupInfoToken_
Definition: BaseTreeFiller.h:185
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:96
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:308
tnp::BaseTreeFiller::weightSrcToken_
edm::EDGetTokenT< GenEventInfoProduct > weightSrcToken_
Definition: BaseTreeFiller.h:176
PFMET.h
tnp::ProbeFlag::passingProbes_
std::vector< reco::CandidateBaseRef > passingProbes_
the handle to keep the refs to the passing probes
Definition: BaseTreeFiller.h:133
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:27
tnp::BaseTreeFiller::mBSz_
float mBSz_
Definition: BaseTreeFiller.h:210
tnp::BaseTreeFiller::run_
uint32_t run_
Definition: BaseTreeFiller.h:206
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:140
tnp::BaseTreeFiller::mBSy_
float mBSy_
Definition: BaseTreeFiller.h:210
tnp::BaseTreeFiller::recVtxsToken_
edm::EDGetTokenT< reco::VertexCollection > recVtxsToken_
Definition: BaseTreeFiller.h:179
tnp::ProbeFlag::~ProbeFlag
~ProbeFlag()
Destructor (does nothing)
Definition: BaseTreeFiller.cc:15
tnp::ProbeFlag::cut_
StringCutObjectSelector< reco::Candidate, true > cut_
implementation of the cut using a string selector
Definition: BaseTreeFiller.h:127
main
Definition: main.py:1
InputTag.h
tnp::BaseTreeFiller::flags_
std::vector< ProbeFlag > flags_
Definition: BaseTreeFiller.h:171
tnp::BaseTreeFiller::addEventVariablesInfo_
bool addEventVariablesInfo_
Add branches with event variables: met, sum ET, .. etc.
Definition: BaseTreeFiller.h:194
ValueMap.h
tnp::ProbeFlag::name_
std::string name_
the name of the variable, which becomes the ROOT branch name
Definition: BaseTreeFiller.h:119
tnp::BaseTreeFiller::vars_
std::vector< ProbeVariable > vars_
Definition: BaseTreeFiller.h:167
VertexFwd.h
tnp::ProbeVariable::external_
bool external_
true if it's an external ValueMap, false if it's a StringParser function
Definition: BaseTreeFiller.h:79
tnp::BaseTreeFiller::pfmetToken_
edm::EDGetTokenT< reco::PFMETCollection > pfmetToken_
Definition: BaseTreeFiller.h:183
MET.h
StringCutObjectSelector.h
tnp::BaseTreeFiller::tree_
TTree * tree_
Definition: BaseTreeFiller.h:204
tnp::ProbeVariable::handle_
edm::Handle< edm::ValueMap< float > > handle_
the handle to keep the ValueMap
Definition: BaseTreeFiller.h:90
tnp::BaseTreeFiller::Fixed
Definition: BaseTreeFiller.h:174
tnp::ProbeVariable::name_
std::string name_
the name of the variable, which becomes the ROOT branch name
Definition: BaseTreeFiller.h:74
tnp::BaseTreeFiller
Definition: BaseTreeFiller.h:137
edm::ValueMap< float >
tnp::ProbeFlag::address
int32_t * address() const
Addess for ROOT Branch.
Definition: BaseTreeFiller.h:106
tnp::ProbeVariable::~ProbeVariable
~ProbeVariable()
Destructor (does nothing)
Definition: BaseTreeFiller.cc:13
StringCutObjectSelector< reco::Candidate, true >
tnp::BaseTreeFiller::tcmetToken_
edm::EDGetTokenT< reco::METCollection > tcmetToken_
Definition: BaseTreeFiller.h:182
tnp::BaseTreeFiller::WeightMode
WeightMode
How event weights are defined: 'None' = no weights, 'Fixed' = one value specified in cfg file,...
Definition: BaseTreeFiller.h:174
tnp::BaseTreeFiller::mPVz_
float mPVz_
Definition: BaseTreeFiller.h:210
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:206
ParameterSet.h
tnp::ProbeVariable
A variable for the probe: can be a string expression or an external ValueMap<float>
Definition: BaseTreeFiller.h:44
tnp::BaseTreeFiller::addBranches_
void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC, const std::string &branchNamePrefix="")
Definition: BaseTreeFiller.cc:137
tnp::ProbeVariable::fill
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
Definition: BaseTreeFiller.h:70
edm::Event
Definition: Event.h:73
tnp::BaseTreeFiller::truePU_
int truePU_
Definition: BaseTreeFiller.h:208
StringObjectFunction.h
tnp::BaseTreeFiller::PUweightSrcToken_
edm::EDGetTokenT< double > PUweightSrcToken_
Definition: BaseTreeFiller.h:177
tnp::ProbeVariable::address
float * address() const
Addess for ROOT Branch.
Definition: BaseTreeFiller.h:58
tnp::BaseTreeFiller::mSumET_
float mSumET_
Definition: BaseTreeFiller.h:212
tnp::BaseTreeFiller::addRho_
bool addRho_
Definition: BaseTreeFiller.h:195
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
tnp::BaseTreeFiller::totWeight_
float totWeight_
Definition: BaseTreeFiller.h:205
tnp::BaseTreeFiller::mtcSumET_
float mtcSumET_
Definition: BaseTreeFiller.h:212
tnp::BaseTreeFiller::pfmetTokenMiniAOD_
edm::EDGetTokenT< pat::METCollection > pfmetTokenMiniAOD_
Definition: BaseTreeFiller.h:184
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:17
tnp::BaseTreeFiller::mNPV_
uint32_t mNPV_
Definition: BaseTreeFiller.h:206