Skip to content

Commit 71fca0b

Browse files
author
Tae Hyoun Park
committed
Fix warnings & better example
1 parent 70b9adf commit 71fca0b

File tree

2 files changed

+85
-60
lines changed

2 files changed

+85
-60
lines changed

docs/pages/example.md

Lines changed: 84 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,17 @@ mll_vars["lp4_up"]->Draw("same");
165165

166166
@section example-phys DAOD_PHYS
167167

168-
- Note the manipulation of non-trivial data types (`xAOD::EventInfo`, `ConstDataVector<xAOD::MuonContainer>`) as columns!
168+
- Note the manipulation of non-trivial data types (`xAOD::EventInfo`, `xAOD::MuonContainer`) as columns!
169169

170170
@cpp
171-
#include "AnalysisPlugins/Event.h"
172-
#include "AnalysisPlugins/Hist.h"
171+
#include "qhep/Event.h"
172+
#include "qhep/Hist.h"
173173

174174
#include <xAODEventInfo/EventInfo.h>
175-
#include <xAODMuon/MuonContainer.h>
175+
#include <xAODEgamma/ElectronContainer.h>
176176

177177
using VecF = ROOT::RVec<float>;
178178
using VecD = ROOT::RVec<double>;
179-
using TLV = TLorentzVector;
180179

181180
#include "queryosity/queryosity.h"
182181

@@ -187,83 +186,108 @@ namespace column = queryosity::column;
187186
namespace query = queryosity::query;
188187
namespace systematic = queryosity::systematic;
189188

190-
#include "TFile.h"
191189
#include "TH1F.h"
192-
#include "TLorentzVector.h"
193190
#include "TPad.h"
194-
#include "TTreeReader.h"
195-
#include "TTreeReaderValue.h"
196-
#include "TVector2.h"
191+
#include "TCanvas.h"
197192
#include <ROOT/RVec.hxx>
198193

199194
#include <chrono>
200195
#include <iostream>
201196
#include <memory>
202197
#include <sstream>
203198

204-
class MuonSelection
205-
: public column::definition<ConstDataVector<xAOD::MuonContainer>(
206-
xAOD::MuonContainer)> {
199+
std::vector<std::string> daodFiles{
200+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000001.pool.root.1",
201+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000002.pool.root.1",
202+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000003.pool.root.1",
203+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000004.pool.root.1",
204+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000005.pool.root.1",
205+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000006.pool.root.1",
206+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000007.pool.root.1",
207+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000008.pool.root.1",
208+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000009.pool.root.1",
209+
"/project/6001378/thpark/public/mc23_13p6TeV.601189.PhPy8EG_AZNLO_Zee.deriv.DAOD_PHYS.e8514_s4162_r14622_p5855/DAOD_PHYS.35010014._000010.pool.root.1"
210+
};
211+
std::string treeName = "CollectionTree";
212+
213+
float EventWeight(const xAOD::EventInfo &eventInfo) {
214+
return eventInfo.mcEventWeight();
215+
}
216+
217+
class ElectronSelection
218+
: public column::definition<ConstDataVector<xAOD::ElectronContainer>(
219+
xAOD::ElectronContainer)> {
207220
public:
208-
MuonSelection(double etaMax) : m_etaMax(etaMax) {}
209-
virtual ~MuonSelection() = default;
210-
virtual ConstDataVector<xAOD::MuonContainer>
211-
evaluate(column::observable<xAOD::MuonContainer> muons) const override {
212-
ConstDataVector<xAOD::MuonContainer> selMuons(SG::VIEW_ELEMENTS);
213-
for (const xAOD::Muon *mu : *muons) {
214-
if (TMath::Abs(mu->eta()) < 1.5) {
215-
selMuons.push_back(mu);
216-
}
221+
ElectronSelection(double pT_min, double eta_max)
222+
: m_pT_min(pT_min), m_eta_max(eta_max) {}
223+
virtual ~ElectronSelection() = default;
224+
virtual ConstDataVector<xAOD::ElectronContainer> evaluate(
225+
column::observable<xAOD::ElectronContainer> els) const override {
226+
ConstDataVector<xAOD::ElectronContainer> els_sel(
227+
SG::VIEW_ELEMENTS);
228+
for (const xAOD::Electron *el : *els) {
229+
if (el->pt() < m_pT_min)
230+
continue;
231+
if (TMath::Abs(el->eta()) > m_eta_max)
232+
continue;
233+
els_sel.push_back(el);
217234
}
218-
return selMuons;
235+
return els_sel;
219236
}
220237

221238
protected:
222-
double m_etaMax;
239+
double m_pT_min;
240+
double m_eta_max;
223241
};
224242

225-
int main() {
243+
bool AtLeastTwoElectrons(ConstDataVector<xAOD::ElectronContainer> const &els) {
244+
return els.size() >= 2;
245+
}
226246

227-
dataflow df;
247+
float DiElectronsMass(ConstDataVector<xAOD::ElectronContainer> const &els) {
248+
return (els[0]->p4() + els[1]->p4()).M();
249+
};
228250

229-
std::vector<std::string> evnt_files{
230-
"/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/ASG/DAOD_PHYS/p5169/"
231-
"mc20_13TeV.410470.PhPy8EG_A14_ttbar_hdamp258p75_nonallhad.deriv.DAOD_"
232-
"PHYS.e6337_s3681_r13167_p5169/DAOD_PHYS.29445530._000001.pool.root.1"};
233-
auto ds = df.load(dataset::input<Event>(evnt_files, "CollectionTree"));
251+
void analyze(unsigned int n) {
252+
dataflow df(multithread::enable(n));
234253

254+
auto ds = df.load(dataset::input<Event>(daodFiles, treeName));
235255
auto eventInfo = ds.read(dataset::column<xAOD::EventInfo>("EventInfo"));
236-
auto allMuons = ds.read(dataset::column<xAOD::MuonContainer>("Muons"));
237-
auto selMuons = df.define(column::definition<MuonSelection>(1.5),allMuons);
238-
239-
auto getPts = [](ConstDataVector<xAOD::MuonContainer> const &muons) {
240-
VecD pts; pts.reserve(muons.size());
241-
for (const xAOD::Muon *mu : muons) {
242-
pts.push_back(mu->pt());
243-
}
244-
return pts;
245-
};
246-
auto selMuonsPtMeV =
247-
df.define(column::expression(getPts),selMuons);
248-
249-
auto toGeV = df.define(column::constant(1.0/1000.0));
250-
auto selMuonsPt = selMuonsPtMeV * toGeV;
251-
252-
auto mcEventWeight = df.define(
253-
column::expression([](const xAOD::EventInfo &eventInfo) {
254-
return eventInfo.mcEventWeight();
255-
}),eventInfo
256-
);
257-
auto mcEventWeighted = df.weight(mcEventWeight);
258-
259-
auto selMuonsPtHist = df.make(query::plan<Hist<1, VecF>>("muons_pt", 100, 0, 100))
260-
.fill(selMuonsPt)
261-
.book(mcEventWeighted);
256+
auto allElectrons =
257+
ds.read(dataset::column<xAOD::ElectronContainer>("Electrons"));
258+
259+
auto selectedElectrons =
260+
df.define(column::definition<ElectronSelection>(10.0,1.5), allElectrons);
261+
auto diElectronsMassMeV =
262+
df.define(column::expression(DiElectronsMass), selectedElectrons);
263+
auto toGeV = df.define(column::constant(1.0 / 1000.0));
264+
auto diElectronsMassGeV = diElectronsMassMeV * toGeV;
265+
266+
auto eventWeight = df.define(column::expression(EventWeight), eventInfo);
267+
auto atLeastTwoSelectedElectrons =
268+
df.weight(eventWeight)
269+
.filter(column::expression(AtLeastTwoElectrons), selectedElectrons);
270+
271+
auto selectedElectronsPtHist =
272+
df.make(query::plan<Hist<1,float>>("diElectronMass", 100, 0, 500))
273+
.fill(diElectronsMassGeV)
274+
.book(atLeastTwoSelectedElectrons);
275+
276+
selectedElectronsPtHist->Draw();
277+
gPad->SetLogy();
278+
gPad->Print("el_pts.pdf");
279+
}
262280

263-
selMuonsPtHist->Draw();
264-
gPad->Print("muons_pt.pdf");
281+
int main(int argc, char *argv[]) {
282+
int nthreads = 0;
283+
if (argc==2) { nthreads=strtol(argv[1], nullptr, 0); }
265284

266-
return 0;
285+
auto tic = std::chrono::steady_clock::now();
286+
analyze(nthreads);
287+
auto toc = std::chrono::steady_clock::now();
288+
std::chrono::duration<double> elapsed_seconds = toc-tic;
289+
std::cout << "elapsed time (" << nthreads << " threads) = " << elapsed_seconds.count() << "s"
290+
<< std::endl;
267291
}
268292
@endcpp
269293

include/queryosity/interface/multithread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ inline unsigned int
113113
queryosity::ensemble::check(std::vector<T> const &first,
114114
std::vector<Args> const &...args) {
115115
assert(((first.size() == args.size()) && ...));
116+
(args.size(), ...); // suppress GCC unused parameter warnings
116117
return first.size();
117118
}
118119

0 commit comments

Comments
 (0)