6 #include <TObjString.h>
19 passingProbes_.clear();
20 for (
size_t i = 0,
n = view->size();
i <
n; ++
i)
21 passingProbes_.push_back(view->refAt(
i));
27 value_ = (
std::find(passingProbes_.begin(), passingProbes_.end(), probe) != passingProbes_.end());
29 value_ = bool(cut_(*probe));
39 addBranches_(tree_, iConfig, iC,
"");
42 if (iConfig.
existsAs<
double>(
"eventWeight")) {
46 weightMode_ = External;
48 tree_->Branch(
"psWeight", &psWeight_,
"psWeight[5]/F");
52 if (weightMode_ !=
None) {
53 tree_->Branch(
"weight", &weight_,
"weight/F");
54 tree_->Branch(
"totWeight", &totWeight_,
"totWeight/F");
60 tree_->Branch(
"lheWeight", &lheWeight_,
"lheWeight[9]/F");
61 tree_->Branch(
"lhe_ht", &lhe_ht_,
"lhe_ht/F");
67 tree_->Branch(
"PUweight", &PUweight_,
"PUweight/F");
74 addRunLumiInfo_ = iConfig.
existsAs<
bool>(
"addRunLumiInfo") ? iConfig.
getParameter<
bool>(
"addRunLumiInfo") :
false;
75 if (addRunLumiInfo_) {
76 tree_->Branch(
"run", &run_,
"run/i");
77 tree_->Branch(
"lumi", &lumi_,
"lumi/i");
78 tree_->Branch(
"event", &
event_,
"event/l");
79 tree_->Branch(
"truePU", &truePU_,
"truePU/I");
81 addEventVariablesInfo_ =
82 iConfig.
existsAs<
bool>(
"addEventVariablesInfo") ? iConfig.
getParameter<
bool>(
"addEventVariablesInfo") :
false;
83 if (addEventVariablesInfo_) {
101 addCaloMet_ = iConfig.
existsAs<
bool>(
"addCaloMet") ? iConfig.
getParameter<
bool>(
"addCaloMet") :
true;
102 tree_->Branch(
"event_nPV", &mNPV_,
"mNPV/I");
106 tree_->Branch(
"event_met_calomet", &mMET_,
"mMET/F");
107 tree_->Branch(
"event_met_calosumet", &mSumET_,
"mSumET/F");
108 tree_->Branch(
"event_met_calometsignificance", &mMETSign_,
"mMETSign/F");
109 tree_->Branch(
"event_met_tcmet", &mtcMET_,
"mtcMET/F");
110 tree_->Branch(
"event_met_tcsumet", &mtcSumET_,
"mtcSumET/F");
111 tree_->Branch(
"event_met_tcmetsignificance", &mtcMETSign_,
"mtcMETSign/F");
113 tree_->Branch(
"event_met_pfmet", &mpfMET_,
"mpfMET/F");
114 tree_->Branch(
"event_met_pfphi", &mpfPhi_,
"mpfPhi/F");
115 tree_->Branch(
"event_met_pfsumet", &mpfSumET_,
"mpfSumET/F");
117 tree_->Branch(
"event_met_pfmetsignificance", &mpfMETSign_,
"mpfMETSign/F");
118 tree_->Branch(
"event_PrimaryVertex_x", &mPVx_,
"mPVx/F");
119 tree_->Branch(
"event_PrimaryVertex_y", &mPVy_,
"mPVy/F");
120 tree_->Branch(
"event_PrimaryVertex_z", &mPVz_,
"mPVz/F");
121 tree_->Branch(
"event_BeamSpot_x", &mBSx_,
"mBSx/F");
122 tree_->Branch(
"event_BeamSpot_y", &mBSy_,
"mBSy/F");
123 tree_->Branch(
"event_BeamSpot_z", &mBSz_,
"mBSz/F");
129 tree_->Branch(
"event_rho", &rho_,
"rho/F");
137 : addRunLumiInfo_(
false), addEventVariablesInfo_(
false), tree_(nullptr) {
151 for (std::vector<std::string>::const_iterator it = stringVars.begin(), ed = stringVars.end(); it != ed; ++it) {
156 for (std::vector<std::string>::const_iterator it = inputTagVars.begin(), ed = inputTagVars.end(); it != ed; ++it) {
164 for (std::vector<std::string>::const_iterator it = stringFlags.begin(), ed = stringFlags.end(); it != ed; ++it) {
169 for (std::vector<std::string>::const_iterator it = inputTagFlags.begin(), ed = inputTagFlags.end(); it != ed; ++it) {
175 for (std::vector<tnp::ProbeVariable>::iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) {
176 tree->Branch(it->name().c_str(), it->address(), (it->name() +
"/F").c_str());
179 for (std::vector<tnp::ProbeFlag>::iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) {
180 tree->Branch(it->name().c_str(), it->address(), (it->name() +
"/I").c_str());
187 run_ = iEvent.
id().
run();
192 if (!iEvent.
isRealData() and !pileupInfoToken_.isUninitialized()) {
195 truePU_ = PupInfo->begin()->getTrueNumInteractions();
199 for (std::vector<tnp::ProbeVariable>::const_iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) {
202 for (std::vector<tnp::ProbeFlag>::const_iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) {
205 for (
int i = 0;
i < 5;
i++) {
208 if (weightMode_ == External) {
214 weight_ = weight->weight();
215 totWeight_ *= weight_;
216 if (weight->weights().size() >= 10) {
218 for (
int i = 6;
i < 10;
i++) {
220 psWeight_[
k] = weight->weights().at(
i) / weight->weight();
226 for (
unsigned int i = 0;
i < 9;
i++) {
230 if (LHEinfo_ and !_LHECollection.isUninitialized()) {
232 iEvent.
getByToken(_LHECollection, lheEventHandle);
233 for (
unsigned int i = 0;
i < 9;
i++) {
234 lheWeight_[
i] = lheEventHandle->weights().at(
i).wgt / lheEventHandle->originalXWGTUP();
236 for (
int i = 0;
i < lheEventHandle->hepeup().NUP;
i++) {
237 int id = lheEventHandle->hepeup().IDUP[
i];
238 int st = lheEventHandle->hepeup().ISTUP[
i];
241 if ((
abs(
id) < 6 ||
id == 21) && st > 0) {
242 lhe_ht_ +=
sqrt(
pow(lheEventHandle->hepeup().PUP[
i][0], 2) +
pow(lheEventHandle->hepeup().PUP[
i][1], 2));
249 if (storePUweight_ and !PUweightSrcToken_.isUninitialized()) {
251 bool isPresent = iEvent.
getByToken(PUweightSrcToken_, weightPU);
253 PUweight_ = float(*weightPU);
254 totWeight_ *= PUweight_;
257 if (addEventVariablesInfo_) {
267 for (
unsigned int ind = 0; ind < recVtxs->size(); ind++) {
268 if (!((*recVtxs)[ind].isFake()) && ((*recVtxs)[ind].ndof() > 4) && (fabs((*recVtxs)[ind].z()) <= 24.0) &&
269 ((*recVtxs)[ind].position().Rho() <= 2.0)) {
272 mPVx_ = (*recVtxs)[ind].x();
273 mPVy_ = (*recVtxs)[ind].y();
274 mPVz_ = (*recVtxs)[ind].z();
282 mBSx_ = beamSpot->position().X();
283 mBSy_ = beamSpot->position().Y();
284 mBSz_ = beamSpot->position().Z();
295 mMET_ = (*met)[0].et();
296 mSumET_ = (*met)[0].sumEt();
297 mMETSign_ = (*met)[0].significance();
303 if (tcmet->empty()) {
308 mtcMET_ = (*tcmet)[0].et();
309 mtcSumET_ = (*tcmet)[0].sumEt();
310 mtcMETSign_ = (*tcmet)[0].significance();
318 if (pfmet->empty()) {
323 mpfMET_ = (*pfmet)[0].et();
324 mpfPhi_ = (*pfmet)[0].phi();
325 mpfSumET_ = (*pfmet)[0].sumEt();
326 mpfMETSign_ = (*pfmet)[0].significance();
330 iEvent.
getByToken(pfmetTokenMiniAOD_, pfmet2);
334 mpfSumET_ = met.
sumEt();
347 for (
auto const &
var : vars_)
349 for (
auto const &flag : flags_)
356 TList *list = tree_->GetUserInfo();
357 list->Add(
new TObjString(pset.
dump().c_str()));
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Analysis-level MET class.
EventNumber_t event() const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
void init(const edm::Event &iEvent) const
To be called at the beginning of the event (will fetch Candidate View if needed)
double pt() const final
transverse momentum
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
bool addRunLumiInfo_
Add branches with run and lumisection number.
void writeProvenance(const edm::ParameterSet &pset) const
std::string dump(unsigned int indent=0) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::vector< MET > METCollection
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
~ProbeFlag()
Destructor (does nothing)
std::vector< Vertex > VertexCollection
collection of Vertex objects
T * make(const Args &...args) const
make new ROOT object
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
BaseTreeFiller(const BaseTreeFiller &)=delete
LuminosityBlockNumber_t luminosityBlock() const
std::vector< reco::MET > METCollection
collection of MET objects
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<float> ...
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
~BaseTreeFiller()
Destructor, does nothing but it's out-of-line as we have complex data members.
list var
if using global norm cols_to_minmax = ['t_delta', 't_hmaxNearP','t_emaxNearP', 't_hAnnular', 't_eAnnular','t_pt','t_nVtx','t_ieta','t_eHcal10', 't_eHcal30','t_rhoh','t_eHcal'] df[cols_to_minmax] = df[cols_to_minmax].apply(lambda x: (x - x.min()) / (x.max() - x.min()) if (x.max() - x.min() > 0) else 1.0/200.0)
Abs< T >::type abs(const T &t)
void init(const edm::Event &iEvent) const
To be called once per event, to load possible external variables.
metToken_(consumes< reco::PFMETCollection >(iConfig.getParameter< edm::InputTag >("met")))
~ProbeVariable()
Destructor (does nothing)
void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC, const std::string &branchNamePrefix="")
std::vector< reco::CaloMET > CaloMETCollection
collection of CaloMET objects
T getParameter(std::string const &) const
std::vector< reco::PFMET > PFMETCollection
collection of PFMET objects
double significance() const
double phi() const final
momentum azimuthal angle
bool storePUweight_
Store Pileup weight when running over Monte Carlo.
Power< A, B >::type pow(const A &a, const B &b)