42 #include "filval/filval.hpp" 43 #include "filval_root/filval_root.hpp" 49 #define W_MASS 80.385 // GeV/c^2 50 #define Z_MASS 91.188 // GeV/c^2 51 #define T_MASS 172.44 // GeV/c^2 57 void enable_branches(MiniTreeDataSet& mt){
58 mt.fChain->SetBranchStatus(
"*",
false);
60 mt.track_branch<
int>(
"nLepGood");
61 mt.track_branch_vec<
int >(
"nLepGood",
"LepGood_pdgId");
62 mt.track_branch_vec<
float>(
"nLepGood",
"LepGood_pt");
63 mt.track_branch_vec<
float>(
"nLepGood",
"LepGood_eta");
64 mt.track_branch_vec<
float>(
"nLepGood",
"LepGood_phi");
65 mt.track_branch_vec<
float>(
"nLepGood",
"LepGood_mass");
66 mt.track_branch_vec<
int >(
"nLepGood",
"LepGood_charge");
67 mt.track_branch_vec<
int >(
"nLepGood",
"LepGood_mcMatchId");
68 mt.track_branch_vec<
int >(
"nLepGood",
"LepGood_mcMatchPdgId");
69 mt.track_branch_vec<
int >(
"nLepGood",
"LepGood_mcMatchAny");
70 mt.track_branch_vec<
int >(
"nLepGood",
"LepGood_mcMatchTau");
71 mt.track_branch_vec<
int >(
"nLepGood",
"LepGood_mcPt");
73 mt.track_branch<
int>(
"nJet");
74 mt.track_branch_vec<
float>(
"nJet",
"Jet_pt");
75 mt.track_branch_vec<
float>(
"nJet",
"Jet_eta");
76 mt.track_branch_vec<
float>(
"nJet",
"Jet_phi");
77 mt.track_branch_vec<
float>(
"nJet",
"Jet_mass");
78 mt.track_branch_vec<
float>(
"nJet",
"Jet_btagCMVA");
79 mt.track_branch_vec<
int >(
"nJet",
"Jet_mcMatchFlav");
80 mt.track_branch_vec<
int >(
"nJet",
"Jet_mcMatchId");
81 mt.track_branch_vec<
int >(
"nJet",
"Jet_mcFlavour");
84 mt.track_branch<
int>(
"nGenPart");
85 mt.track_branch_vec<
int >(
"nGenPart",
"GenPart_pdgId");
86 mt.track_branch_vec<
int >(
"nGenPart",
"GenPart_motherIndex");
87 mt.track_branch_vec<
int >(
"nGenPart",
"GenPart_motherId");
88 mt.track_branch_vec<
float>(
"nGenPart",
"GenPart_pt");
89 mt.track_branch_vec<
float>(
"nGenPart",
"GenPart_eta");
90 mt.track_branch_vec<
float>(
"nGenPart",
"GenPart_phi");
91 mt.track_branch_vec<
float>(
"nGenPart",
"GenPart_mass");
92 mt.track_branch_vec<
int >(
"nGenPart",
"GenPart_status");
94 mt.track_branch<
int>(
"nBJetLoose40");
95 mt.track_branch<
int>(
"nBJetMedium40");
96 mt.track_branch<
int>(
"nBJetTight40");
99 mt.track_branch<
int>(
"nVert");
101 mt.track_branch<
int >(
"run" );
102 mt.track_branch<
int >(
"lumi");
103 mt.track_branch<
int >(
"evt" );
104 mt.track_branch<
float>(
"xsec");
113 Jet(
const TLorentzVector& v,
int idx,
int pdgid,
float b_cmva)
114 :v(v),idx(idx),pdgid(pdgid),b_cmva(b_cmva) { }
116 static Jet reco(
const TLorentzVector& v,
int idx,
float b_cmva){
117 return Jet(v, idx, 0, b_cmva);
120 static Jet mc(
const TLorentzVector& v,
int idx,
int pdgid){
121 return Jet(v, idx, pdgid, 0);
125 void declare_values(MiniTreeDataSet& mt){
128 lorentz_vectors(
"LepGood_pt",
"LepGood_eta",
"LepGood_phi",
"LepGood_mass",
"LepGood_4v");
129 lorentz_vectors(
"GenPart_pt",
"GenPart_eta",
"GenPart_phi",
"GenPart_mass",
"GenPart_4v");
130 lorentz_vectors(
"Jet_pt",
"Jet_eta",
"Jet_phi",
"Jet_mass",
"Jet_4v" );
132 energies(
"GenPart_4v",
"GenPart_energy");
136 auto& b_mva_filter = GenFunction::register_function<bool(Jet)>(
"b_mva_filter",
137 FUNC(([cut=0.0](
const Jet& j){
138 return j.b_cmva > cut;
140 auto& b_pdgid_filter = GenFunction::register_function<bool(Jet)>(
"b_pdgid_filter",
141 FUNC(([](
const Jet& j){
142 return j.pdgid == 5 || j.pdgid==-5;
144 auto& w_mass_filter = GenFunction::register_function<bool(Jet, Jet)>(
"w_mass_filter",
145 FUNC(([win_l=W_MASS-10, win_h=W_MASS+10](
const Jet& j1,
const Jet& j2){
146 float inv_mass = (j1.v + j2.v).M();
147 return inv_mass > win_l && inv_mass < win_h;
149 auto& dup_filter = GenFunction::register_function<bool(std::tuple<Jet,Jet>,Jet)>(
"dup_filter",
150 FUNC(([](
const std::tuple<Jet,Jet>& w,
const Jet& b){
152 int j1 = std::get<0>(w).idx;
153 int j2 = std::get<1>(w).idx;
154 return (j0 != j1) && (j0 != j2) && (j1 != j2);
156 auto& qg_id_filter = GenFunction::register_function<bool(Jet, Jet)>(
"qg_id_filter",
157 FUNC(([](
const Jet& j1,
const Jet& j2){
159 int id1 = abs(j1.pdgid);
160 int id2 = abs(j2.pdgid);
161 return ((id1 >=1 && id1 <= 5) || id1 == 21) &&
162 ((id2 >=1 && id2 <= 5) || id2 == 21);
166 auto jets = apply(GenFunction::register_function<std::vector<Jet>(std::vector<TLorentzVector>,std::vector<float>)>(
"build_reco_jets",
167 FUNC(([](
const std::vector<TLorentzVector>& vs,
const std::vector<float>& b_cmvas){
168 std::vector<Jet> jets;
169 for(
int i=0; i<vs.size(); i++){
170 jets.push_back(Jet::reco(vs[i],i, b_cmvas[i]));
173 }))), fv::tuple(lookup<std::vector<TLorentzVector>>(
"Jet_4v"), lookup<std::vector<float>>(
"Jet_btagCMVA")),
"reco_jets");
176 auto b_jets = filter(b_mva_filter, jets,
"reco_b_jets");
177 auto w_dijets = tup_filter<Jet,Jet>(w_mass_filter, combinations<Jet,2>(jets,
"reco_dijets"));
179 auto top_cands = cart_product<std::tuple<Jet,Jet>, Jet>(w_dijets, b_jets);
181 top_cands = tup_filter(dup_filter, top_cands);
183 auto& t_mass = GenFunction::register_function<float(std::tuple<Jet,Jet>,Jet)>(
"t_mass",
184 FUNC(([](
const std::tuple<Jet,Jet>& w,
const Jet& b){
185 return (std::get<0>(w).v+std::get<1>(w).v+b.v).M();
188 fv::map(t_mass, top_cands,
"reco_top_mass");
191 jets = apply(GenFunction::register_function<std::vector<Jet>(std::vector<TLorentzVector>,std::vector<int>)>(
"build_mcjets",
192 FUNC(([](
const std::vector<TLorentzVector>& vs,
const std::vector<int>& pdgid){
193 std::vector<Jet> jets;
194 for(
int i=0; i<vs.size(); i++){
195 jets.push_back(Jet::mc(vs[i],i, pdgid[i]));
198 }))), fv::tuple(lookup<std::vector<TLorentzVector>>(
"GenPart_4v"), lookup<std::vector<int>>(
"GenPart_pdgId")),
"mcjets");
200 b_jets = filter(b_pdgid_filter, jets);
202 w_dijets = tup_filter(qg_id_filter, combinations<Jet,2>(jets));
203 w_dijets = tup_filter(w_mass_filter, w_dijets);
205 top_cands = cart_product<std::tuple<Jet,Jet>, Jet>(w_dijets, b_jets);
207 top_cands = tup_filter(dup_filter, top_cands);
210 fv::map(t_mass, top_cands,
"mc_top_mass");
214 auto& inv_mass2 = GenFunction::register_function<float(Jet, Jet)>(
"inv_mass2",
215 FUNC(([] (
const Jet& j1,
const Jet& j2){
216 TLorentzVector sum = j1.v + j2.v;
217 return (
float)sum.M();
219 fv::map(inv_mass2, lookup<std::vector<std::tuple<Jet,Jet>>>(
"reco_dijets"),
"dijet_inv_mass");
223 count<float>(GenFunction::register_function<bool(float)>(
"bJet_Selection",
226 }))),
"Jet_btagCMVA",
"b_jet_count");
228 auto &is_electron = GenFunction::register_function<bool(int)>(
"is_electron",
229 FUNC(([](
int pdgId) {
230 return abs(pdgId) == 11;
232 auto &is_muon = GenFunction::register_function<bool(int)>(
"is_muon",
233 FUNC(([](
int pdgId) {
234 return abs(pdgId) == 13;
236 auto &is_lepton = GenFunction::register_function<bool(int)>(
"is_lepton",
237 FUNC(([ie=&is_electron, im=&is_muon](
int pdgId) {
238 return (*ie)(pdgId) || (*im)(pdgId);
241 count<int>(is_electron,
"GenPart_pdgId",
"genEle_count");
242 count<int>(is_muon,
"GenPart_pdgId",
"genMu_count");
243 count<int>(is_lepton,
"GenPart_pdgId",
"genLep_count");
245 count<int>(is_electron,
"LepGood_pdgId",
"recEle_count");
246 count<int>(is_muon,
"LepGood_pdgId",
"recMu_count");
247 count<int>(is_lepton,
"LepGood_pdgId",
"recLep_count");
250 fv::pair<int, int>(
"genEle_count",
"recEle_count",
"genEle_count_v_recEle_count");
251 fv::pair<int, int>(
"genMu_count",
"recMu_count",
"genMu_count_v_recMu_count");
252 fv::pair<int, int>(
"genLep_count",
"recLep_count",
"genLep_count_v_recLep_count");
254 obs_filter(
"trilepton", FUNC(([nLepGood=lookup<int>(
"nLepGood")]()
256 return dynamic_cast<Value<int>*
>(nLepGood)->get_value() == 3;
259 obs_filter(
"os-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>(
"LepGood_charge")]()
261 auto& charges = LepGood_charge->get_value();
262 return charges.size()==2 && (charges[0] != charges[1]);
265 obs_filter(
"ss-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>(
"LepGood_charge")]()
267 auto& charges = LepGood_charge->get_value();
268 return charges.size()==2 && (charges[0] == charges[1]);
273 void declare_containers(MiniTreeDataSet& mt){
275 mt.register_container<ContainerTH1<int>>(
"lepton_count",
"Lepton Multiplicity", lookup<int>(
"nLepGood"), 8, 0, 8);
277 mt.register_container<ContainerTH1Many<float>>(
"Jet_pt_dist",
"Jet P_T",
278 lookup<vector<float>>(
"Jet_pt"), 50, 0, 500,
280 mt.register_container<ContainerTH1Many<float>>(
"Jet_eta_dist",
"Jet Eta",
281 lookup<vector<float>>(
"Jet_eta"), 50, -3, 3,
283 mt.register_container<ContainerTH1Many<float>>(
"Jet_phi_dist",
"Jet Phi",
284 lookup<vector<float>>(
"Jet_phi"), 20, -PI, PI,
286 mt.register_container<ContainerTH1Many<float>>(
"Jet_mass_dist",
"Jet Mass",
287 lookup<vector<float>>(
"Jet_mass"), 50, 0, 200,
290 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass",
"Di-Jet Inv. Mass - All",
291 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
293 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass_osdilepton",
"Di-Jet Inv. Mass - OS Dilepton",
294 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
295 "Di-Jet Mass")->add_filter(lookup_obs_filter(
"os-dilepton"));
296 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass_ssdilepton",
"Di-Jet Inv. Mass - SS Dilepton",
297 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
298 "Di-Jet Mass")->add_filter(lookup_obs_filter(
"ss-dilepton"));
299 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass_trilepton",
"Di-Jet Inv. Mass - Trilepton",
300 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
301 "Di-Jet Mass")->add_filter(lookup_obs_filter(
"trilepton"));
303 mt.register_container<ContainerTH1Many<float>>(
"reco_top_mass",
"Reconstructed Top mass",
304 lookup<vector<float>>(
"reco_top_mass"), 100, 0, 500,
305 "Tri-jet invarient mass");
310 mt.register_container<ContainerTH1Many<float>>(
"mc_top_mass",
"Reconstructed MC Top mass",
311 lookup<vector<float>>(
"mc_top_mass"), 100, 0, 500,
312 "Tri-jet invarient mass");
315 mt.register_container<ContainerTH2<int>>(
"nLepvsnJet",
"Number of Leptons vs Number of Jets",
316 fv::pair<int, int>(
"nLepGood",
"nJet"),
318 "Number of Leptons",
"Number of Jets");
321 mt.register_container<ContainerTH2<int>>(
"genEle_count_v_recEle_count",
"Number of Generated Electrons v. Number of Reconstructed Electrons",
322 lookup<std::pair<int,int>>(
"genEle_count_v_recEle_count"),
323 10, 0, 10, 10, 0, 10,
324 "Generated Electrons",
"Reconstructed Electrons");
326 mt.register_container<ContainerTH2<int>>(
"genMu_count_v_recMu_count",
"Number of Generated Muons v. Number of Reconstructed Muons",
327 lookup<std::pair<int,int>>(
"genMu_count_v_recMu_count"),
328 10, 0, 10, 10, 0, 10,
329 "Generated Muons",
"Reconstructed Muons");
331 mt.register_container<ContainerTH2<int>>(
"genLep_count_v_recLep_count",
"Number of Generated Leptons v. Number of Reconstructed Leptons (e & mu only)",
332 lookup<std::pair<int,int>>(
"genLep_count_v_recLep_count"),
333 10, 0, 10, 10, 0, 10,
334 "Generated Leptons",
"Reconstructed Leptons");
336 mt.register_container<ContainerTH1<int>>(
"b_jet_count",
"B-Jet Multiplicity", lookup<int>(
"b_jet_count"), 10, 0, 10);
339 mt.register_container<ContainerTH1<int>>(
"jet_count_os_dilepton",
"Jet Multiplicity - OS Dilepton Events",
340 lookup<int>(
"nJet"), 14, 0, 14)->add_filter(lookup_obs_filter(
"os-dilepton"));
341 mt.register_container<ContainerTH1<int>>(
"jet_count_ss_dilepton",
"Jet Multiplicity - SS Dilepton Events",
342 lookup<int>(
"nJet"), 14, 0, 14)->add_filter(lookup_obs_filter(
"ss-dilepton"));
343 mt.register_container<ContainerTH1<int>>(
"jet_count_trilepton",
"Jet Multiplicity - Trilepton Events",
344 lookup<int>(
"nJet"), 14, 0, 14)->add_filter(lookup_obs_filter(
"trilepton"));
346 mt.register_container<ContainerTH1<int>>(
"nVert",
"Number of Primary Vertices", lookup<int>(
"nVert"), 50, 0, 50);
348 mt.register_container<
CounterMany<int>>(
"GenPart_pdgId_counter", lookup<vector<int>>(
"GenPart_pdgId"));
351 mt.register_container<Vector<std::vector< int >>>(
"GenPart_pdgId", lookup<std::vector< int >>(
"GenPart_pdgId"));
352 mt.register_container<Vector<std::vector< int >>>(
"GenPart_motherIndex", lookup<std::vector< int >>(
"GenPart_motherIndex"));
353 mt.register_container<Vector<std::vector< int >>>(
"GenPart_motherId", lookup<std::vector< int >>(
"GenPart_motherId"));
354 mt.register_container<Vector<std::vector<float>>>(
"GenPart_pt", lookup<std::vector<float>>(
"GenPart_pt"));
355 mt.register_container<Vector<std::vector<float>>>(
"GenPart_eta", lookup<std::vector<float>>(
"GenPart_eta"));
356 mt.register_container<Vector<std::vector<float>>>(
"GenPart_phi", lookup<std::vector<float>>(
"GenPart_phi"));
357 mt.register_container<Vector<std::vector<float>>>(
"GenPart_mass", lookup<std::vector<float>>(
"GenPart_mass"));
358 mt.register_container<Vector<std::vector<float>>>(
"GenPart_energy", lookup<std::vector<float>>(
"GenPart_energy"));
359 mt.register_container<Vector<std::vector< int >>>(
"GenPart_status", lookup<std::vector< int >>(
"GenPart_status"));
361 mt.register_container<Vector<vector< int >>>(
"LepGood_mcMatchId", lookup<vector< int >>(
"LepGood_mcMatchId"));
362 mt.register_container<Vector<vector< int >>>(
"LepGood_mcMatchPdgId", lookup<vector< int >>(
"LepGood_mcMatchPdgId"));
364 mt.register_container<Vector< int >>(
"run", lookup< int >(
"run") );
365 mt.register_container<Vector< int >>(
"lumi", lookup< int >(
"lumi"));
366 mt.register_container<Vector< int >>(
"evt", lookup< int >(
"evt") );
367 mt.register_container<Vector<float>>(
"xsec", lookup<float>(
"xsec"));
369 mt.register_container<Vector<std::vector< int >>>(
"Jet_mcMatchFlav", lookup<std::vector< int >>(
"Jet_mcMatchFlav"));
370 mt.register_container<Vector<std::vector< int >>>(
"Jet_mcMatchId", lookup<std::vector< int >>(
"Jet_mcMatchId"));
371 mt.register_container<Vector<std::vector< int >>>(
"Jet_mcFlavour", lookup<std::vector< int >>(
"Jet_mcFlavour"));
373 mt.register_container<Vector<std::vector<float>>>(
"Jet_pt", lookup<std::vector<float>>(
"Jet_pt"));
374 mt.register_container<Vector<std::vector<float>>>(
"Jet_eta", lookup<std::vector<float>>(
"Jet_eta"));
375 mt.register_container<Vector<std::vector<float>>>(
"Jet_phi", lookup<std::vector<float>>(
"Jet_phi"));
376 mt.register_container<Vector<std::vector<float>>>(
"Jet_mass", lookup<std::vector<float>>(
"Jet_mass"));
381 void run_analysis(
const std::string& input_filename,
bool silent){
382 gSystem->Load(
"libfilval.so");
383 auto replace_suffix = [](
const std::string& input,
const std::string& new_suffix){
384 return input.substr(0, input.find_last_of(
".")) + new_suffix;
386 string log_filename = replace_suffix(input_filename,
"_result.log");
387 fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogDebug);
389 string output_filename = replace_suffix(input_filename,
"_result.root");
390 MiniTreeDataSet mt(input_filename, output_filename);
394 declare_containers(mt);
400 int main(
int argc,
char * argv[])
402 fv::util::ArgParser args(argc, argv);
403 if(!args.cmdOptionExists(
"-f")) {
404 cout <<
"Usage: ./main (-s) -f input_minitree.root" << endl;
407 bool silent = args.cmdOptionExists(
"-s");
408 string input_filename = args.getCmdOption(
"-f");
409 run_analysis(input_filename, silent);
Same as Counter but accepts multiple values per fill.
The namespace containing all filval classes and functions.