43 #include "filval/filval.hpp" 44 #include "filval_root/filval_root.hpp" 46 #include "analysis/common/obj_types.hpp" 47 #include "analysis/common/constants.hpp" 57 void enable_extra_branches(MiniTreeDataSet& mt){
58 mt.track_branch<
int>(
"nBJetLoose40");
59 mt.track_branch<
int>(
"nBJetMedium40");
60 mt.track_branch<
int>(
"nBJetTight40");
63 mt.track_branch<
int >(
"run" );
64 mt.track_branch<
int >(
"lumi");
65 mt.track_branch<
int >(
"evt" );
66 mt.track_branch<
float>(
"xsec");
70 void declare_values(MiniTreeDataSet& mt){
73 auto& b_pdgid_filter = GenFunction::register_function<bool(Particle)>(
"b_pdgid_filter",
74 FUNC(([](
const Particle& j){
75 return j.genpart.pdgId == 5 || j.genpart.pdgId==-5;
77 auto& w_mass_filter = GenFunction::register_function<bool(Particle, Particle)>(
"w_mass_filter",
78 FUNC(([win_l=W_MASS-10, win_h=W_MASS+10](
const Particle& j1,
const Particle& j2){
79 float inv_mass = (j1.v + j2.v).M();
80 return inv_mass > win_l && inv_mass < win_h;
82 auto& dup_filter = GenFunction::register_function<bool(std::tuple<Particle,Particle>,Particle)>(
"dup_filter",
83 FUNC(([](
const std::tuple<Particle,Particle>& w,
const Particle& b){
85 int j1 = std::get<0>(w).idx;
86 int j2 = std::get<1>(w).idx;
87 return (j0 != j1) && (j0 != j2) && (j1 != j2);
89 auto& qg_id_filter = GenFunction::register_function<bool(Particle, Particle)>(
"qg_id_filter",
90 FUNC(([](
const Particle& j1,
const Particle& j2){
92 int id1 = abs(j1.genpart.pdgId);
93 int id2 = abs(j2.genpart.pdgId);
94 return ((id1 >=1 && id1 <= 5) || id1 == 21) &&
95 ((id2 >=1 && id2 <= 5) || id2 == 21);
100 auto jets = lookup<std::vector<Particle>>(
"jets");
101 auto leptons = lookup<std::vector<Particle>>(
"leptons");
102 auto leading_jet = fv::reduce(leading_particle, jets,
"leading_jet");
103 fv::apply(particle_pt, fv::tuple(leading_jet),
"leading_jet_pt");
105 auto leading_lepton = fv::reduce(leading_particle, leptons);
106 fv::apply(particle_pt, fv::tuple(leading_lepton),
"leading_lepton_pt");
107 fv::apply(lepton_relIso, fv::tuple(leading_lepton),
"leading_lepton_relIso");
109 auto b_jets = lookup<std::vector<Particle>>(
"b_jets");
112 auto w_dijets = tup_filter<Particle,Particle>(w_mass_filter, combinations<Particle,2>(jets,
"reco_dijets"));
114 auto top_cands = cart_product<std::tuple<Particle,Particle>, Particle>(w_dijets, b_jets);
116 top_cands = tup_filter(dup_filter, top_cands);
118 auto& t_mass = GenFunction::register_function<float(std::tuple<Particle,Particle>,Particle)>(
"t_mass",
119 FUNC(([](
const std::tuple<Particle,Particle>& w,
const Particle& b){
120 return (std::get<0>(w).v+std::get<1>(w).v+b.v).M();
123 fv::map(t_mass, top_cands,
"reco_top_mass");
126 jets = lookup<std::vector<Particle>>(
"mc_jets");
128 b_jets = filter(b_pdgid_filter, jets);
130 w_dijets = tup_filter(qg_id_filter, combinations<Particle,2>(jets));
131 w_dijets = tup_filter(w_mass_filter, w_dijets);
133 top_cands = cart_product<std::tuple<Particle,Particle>, Particle>(w_dijets, b_jets);
135 top_cands = tup_filter(dup_filter, top_cands);
138 fv::map(t_mass, top_cands,
"mc_top_mass");
142 auto& inv_mass2 = GenFunction::register_function<float(Particle, Particle)>(
"inv_mass2",
143 FUNC(([] (
const Particle& j1,
const Particle& j2){
144 TLorentzVector sum = j1.v + j2.v;
145 return (
float)sum.M();
147 fv::map(inv_mass2, lookup<std::vector<std::tuple<Particle,Particle>>>(
"reco_dijets"),
"dijet_inv_mass");
151 count<float>(GenFunction::register_function<bool(float)>(
"bJet_Selection",
154 }))),
"Jet_btagCMVA",
"b_jet_count");
156 auto &is_electron = GenFunction::register_function<bool(int)>(
"is_electron",
157 FUNC(([](
int pdgId) {
158 return abs(pdgId) == 11;
160 auto &is_muon = GenFunction::register_function<bool(int)>(
"is_muon",
161 FUNC(([](
int pdgId) {
162 return abs(pdgId) == 13;
164 auto &is_lepton = GenFunction::register_function<bool(int)>(
"is_lepton",
165 FUNC(([ie=&is_electron, im=&is_muon](
int pdgId) {
166 return (*ie)(pdgId) || (*im)(pdgId);
169 count<int>(is_electron,
"GenPart_pdgId",
"genEle_count");
170 count<int>(is_muon,
"GenPart_pdgId",
"genMu_count");
171 count<int>(is_lepton,
"GenPart_pdgId",
"genLep_count");
173 count<int>(is_electron,
"LepGood_pdgId",
"recEle_count");
174 count<int>(is_muon,
"LepGood_pdgId",
"recMu_count");
175 count<int>(is_lepton,
"LepGood_pdgId",
"recLep_count");
178 fv::pair<int, int>(
"genEle_count",
"recEle_count",
"genEle_count_v_recEle_count");
179 fv::pair<int, int>(
"genMu_count",
"recMu_count",
"genMu_count_v_recMu_count");
180 fv::pair<int, int>(
"genLep_count",
"recLep_count",
"genLep_count_v_recLep_count");
190 obs_filter(
"trilepton", FUNC(([nLepGood=lookup<int>(
"nLepGood")]()
192 return dynamic_cast<Value<int>*
>(nLepGood)->get_value() == 3;
195 obs_filter(
"os-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>(
"LepGood_charge")]()
197 auto& charges = LepGood_charge->get_value();
198 return charges.size()==2 && (charges[0] != charges[1]);
201 obs_filter(
"ss-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>(
"LepGood_charge")]()
203 auto& charges = LepGood_charge->get_value();
204 return charges.size()==2 && (charges[0] == charges[1]);
209 void declare_containers(MiniTreeDataSet& mt){
211 mt.register_container<ContainerTH1<int>>(
"lepton_count",
"Lepton Multiplicity", lookup<int>(
"nLepGood"), 8, 0, 8);
213 mt.register_container<ContainerTH1Many<float>>(
"Jet_pt_dist",
"Jet P_T",
214 lookup<vector<float>>(
"Jet_pt"), 50, 0, 500,
216 mt.register_container<ContainerTH1Many<float>>(
"Jet_eta_dist",
"Jet Eta",
217 lookup<vector<float>>(
"Jet_eta"), 50, -3, 3,
219 mt.register_container<ContainerTH1Many<float>>(
"Jet_phi_dist",
"Jet Phi",
220 lookup<vector<float>>(
"Jet_phi"), 20, -PI, PI,
222 mt.register_container<ContainerTH1Many<float>>(
"Jet_mass_dist",
"Jet Mass",
223 lookup<vector<float>>(
"Jet_mass"), 50, 0, 200,
226 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass",
"Di-Jet Inv. Mass - All",
227 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
229 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass_osdilepton",
"Di-Jet Inv. Mass - OS Dilepton",
230 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
231 "Di-Jet Mass")->add_filter(lookup_obs_filter(
"os-dilepton"));
232 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass_ssdilepton",
"Di-Jet Inv. Mass - SS Dilepton",
233 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
234 "Di-Jet Mass")->add_filter(lookup_obs_filter(
"ss-dilepton"));
235 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass_trilepton",
"Di-Jet Inv. Mass - Trilepton",
236 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
237 "Di-Jet Mass")->add_filter(lookup_obs_filter(
"trilepton"));
239 mt.register_container<ContainerTH1Many<float>>(
"reco_top_mass",
"Reconstructed Top mass",
240 lookup<vector<float>>(
"reco_top_mass"), 100, 0, 500,
241 "Tri-jet invarient mass");
246 mt.register_container<ContainerTH1Many<float>>(
"mc_top_mass",
"Reconstructed MC Top mass",
247 lookup<vector<float>>(
"mc_top_mass"), 100, 0, 500,
248 "Tri-jet invarient mass");
251 mt.register_container<ContainerTH2<int>>(
"nLepvsnJet",
"Number of Leptons vs Number of Jets",
252 fv::pair<int, int>(
"nLepGood",
"nJet"),
254 "Number of Leptons",
"Number of Jets");
257 mt.register_container<ContainerTH2<int>>(
"genEle_count_v_recEle_count",
"Number of Generated Electrons v. Number of Reconstructed Electrons",
258 lookup<std::pair<int,int>>(
"genEle_count_v_recEle_count"),
259 10, 0, 10, 10, 0, 10,
260 "Generated Electrons",
"Reconstructed Electrons");
262 mt.register_container<ContainerTH2<int>>(
"genMu_count_v_recMu_count",
"Number of Generated Muons v. Number of Reconstructed Muons",
263 lookup<std::pair<int,int>>(
"genMu_count_v_recMu_count"),
264 10, 0, 10, 10, 0, 10,
265 "Generated Muons",
"Reconstructed Muons");
267 mt.register_container<ContainerTH2<int>>(
"genLep_count_v_recLep_count",
"Number of Generated Leptons v. Number of Reconstructed Leptons (e & mu only)",
268 lookup<std::pair<int,int>>(
"genLep_count_v_recLep_count"),
269 10, 0, 10, 10, 0, 10,
270 "Generated Leptons",
"Reconstructed Leptons");
272 auto jet_count = mt.register_container<ContainerTH1<int>>(
"jet_count",
"B-Jet Multiplicity", lookup<int>(
"nJet"), 15, 0, 15);
273 mt.cut_set(jet_count,{
274 {event_selection.trilepton,
"jet_count_trilepton"},
275 {event_selection.b_jet3,
"jet_count_b_jet3"},
276 {event_selection.z_mass_veto,
"jet_count_z_mass_veto"},
277 {event_selection.base_sel,
"jet_count_base_selection"},
279 mt.register_container<ContainerTH1<int>>(
"b_jet_count",
"B-Jet Multiplicity", lookup<int>(
"b_jet_count"), 10, 0, 10);
282 mt.register_container<ContainerTH1<int>>(
"b_jet_count_base_selection",
"B-Jet Multiplicity", lookup<int>(
"b_jet_count"), 10, 0, 10)->add_filter(event_selection.base_sel);
284 mt.register_container<ContainerTH1<int>>(
"jet_count_os_dilepton",
"Jet Multiplicity - OS Dilepton Events",
285 lookup<int>(
"nJet"), 14, 0, 14)->add_filter(lookup_obs_filter(
"os-dilepton"));
286 mt.register_container<ContainerTH1<int>>(
"jet_count_ss_dilepton",
"Jet Multiplicity - SS Dilepton Events",
287 lookup<int>(
"nJet"), 14, 0, 14)->add_filter(lookup_obs_filter(
"ss-dilepton"));
290 mt.register_container<
CounterMany<int>>(
"GenPart_pdgId_counter", lookup<vector<int>>(
"GenPart_pdgId"));
293 mt.register_container<Vector<std::vector< int >>>(
"GenPart_pdgId", lookup<std::vector< int >>(
"GenPart_pdgId"));
294 mt.register_container<Vector<std::vector< int >>>(
"GenPart_motherIndex", lookup<std::vector< int >>(
"GenPart_motherIndex"));
295 mt.register_container<Vector<std::vector< int >>>(
"GenPart_motherId", lookup<std::vector< int >>(
"GenPart_motherId"));
296 mt.register_container<Vector<std::vector<float>>>(
"GenPart_pt", lookup<std::vector<float>>(
"GenPart_pt"));
297 mt.register_container<Vector<std::vector<float>>>(
"GenPart_eta", lookup<std::vector<float>>(
"GenPart_eta"));
298 mt.register_container<Vector<std::vector<float>>>(
"GenPart_phi", lookup<std::vector<float>>(
"GenPart_phi"));
299 mt.register_container<Vector<std::vector<float>>>(
"GenPart_mass", lookup<std::vector<float>>(
"GenPart_mass"));
300 mt.register_container<Vector<std::vector<float>>>(
"GenPart_energy", lookup<std::vector<float>>(
"GenPart_energy"));
301 mt.register_container<Vector<std::vector< int >>>(
"GenPart_status", lookup<std::vector< int >>(
"GenPart_status"));
303 mt.register_container<Vector<vector< int >>>(
"LepGood_mcMatchPdgId", lookup<vector< int >>(
"LepGood_mcMatchPdgId"));
304 mt.register_container<Vector<vector< int >>>(
"LepGood_pdgId", lookup<vector< int >>(
"LepGood_pdgId"));
306 mt.register_container<Vector< int >>(
"run", lookup< int >(
"run") );
307 mt.register_container<Vector< int >>(
"lumi", lookup< int >(
"lumi"));
308 mt.register_container<Vector< int >>(
"evt", lookup< int >(
"evt") );
309 mt.register_container<Vector<float>>(
"xsec", lookup<float>(
"xsec"));
311 mt.register_container<Vector<std::vector< int >>>(
"Jet_mcMatchFlav", lookup<std::vector< int >>(
"Jet_mcMatchFlav"));
313 mt.register_container<Vector<std::vector<float>>>(
"Jet_pt", lookup<std::vector<float>>(
"Jet_pt"));
314 mt.register_container<Vector<std::vector<float>>>(
"Jet_eta", lookup<std::vector<float>>(
"Jet_eta"));
315 mt.register_container<Vector<std::vector<float>>>(
"Jet_phi", lookup<std::vector<float>>(
"Jet_phi"));
316 mt.register_container<Vector<std::vector<float>>>(
"Jet_mass", lookup<std::vector<float>>(
"Jet_mass"));
318 mt.register_container<ContainerTH1<float>>(
"leading_jet_pt",
"Leading Jet Pt", lookup<float>(
"leading_jet_pt"), 100, 0, 500);
319 mt.register_container<ContainerTH1<float>>(
"leading_lepton_pt",
"Leading Lepton Pt", lookup<float>(
"leading_lepton_pt"), 100, 0, 500);
320 mt.register_container<ContainerTH1<float>>(
"leading_lepton_relIso",
"Leading Lepton Relative Isolation", lookup<float>(
"leading_lepton_relIso"), 100, 0, 0.05);
321 mt.register_container<Vector<float>>(
"leading_lepton_relIso_all", lookup<float>(
"leading_lepton_relIso"));
323 mt.register_container<PassCount>(
"trilepton_count", event_selection.trilepton);
324 mt.register_container<PassCount>(
"b_jet3_count", event_selection.b_jet3);
325 mt.register_container<PassCount>(
"z_mass_veto_count", event_selection.z_mass_veto);
327 mt.register_container<PassCount>(
"J4_count", event_selection.J4);
328 mt.register_container<PassCount>(
"J5_count", event_selection.J5);
329 mt.register_container<PassCount>(
"J6_count", event_selection.J6);
331 mt.register_container<PassCount>(
"SR4j_count", event_selection.SR4j);
332 mt.register_container<PassCount>(
"SR5j_count", event_selection.SR5j);
333 mt.register_container<PassCount>(
"SR6j_count", event_selection.SR6j);
337 void run_analysis(
const std::string& input_filename,
const std::string& data_label,
bool silent){
338 gSystem->Load(
"libfilval.so");
339 auto replace_suffix = [](
const std::string& input,
const std::string& new_suffix){
340 return input.substr(0, input.find_last_of(
".")) + new_suffix;
342 string log_filename = replace_suffix(input_filename,
"_result.log");
343 fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogDebug);
345 string output_filename = replace_suffix(input_filename,
"_result.root");
346 MiniTreeDataSet mt(output_filename, input_filename, data_label);
348 create_all_common_values(mt);
349 enable_extra_branches(mt);
352 declare_containers(mt);
358 int main(
int argc,
char * argv[])
360 fv::util::ArgParser args(argc, argv);
361 if(!args.cmdOptionExists(
"-l") || !args.cmdOptionExists(
"-f")) {
362 cout <<
"Usage: ./main (-s) -l DATA_LABEL -f input_minitree.root" << endl;
365 bool silent = args.cmdOptionExists(
"-s");
366 string input_filename = args.getCmdOption(
"-f");
367 string data_label = args.getCmdOption(
"-l");
368 run_analysis(input_filename, data_label, silent);
Same as Counter but accepts multiple values per fill.
The namespace containing all filval classes and functions.