123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- #include <iostream>
- #include <vector>
- #include <tuple>
- #include <utility>
- #include <limits>
- #include "filval/filval.hpp"
- #include "filval_root/filval_root.hpp"
- #include "MiniTreeDataSet.hpp"
- #include <TSystem.h>
- using namespace std;
- using namespace fv;
- using namespace fv::root;
- void enable_branches(MiniTreeDataSet& mt){
- mt.fChain->SetBranchStatus("*", false);
- mt.track_branch<int>("nLepGood");
- mt.track_branch_vec<float>("nLepGood", "LepGood_pt");
- mt.track_branch_vec<float>("nLepGood", "LepGood_eta");
- mt.track_branch_vec<float>("nLepGood", "LepGood_phi");
- mt.track_branch_vec<float>("nLepGood", "LepGood_mass");
- mt.track_branch_vec<float>("nLepGood", "LepGood_mcPt");
- mt.track_branch_vec<int>("nLepGood", "LepGood_charge");
- mt.track_branch<int>("nJet");
- mt.track_branch_vec<float>("nJet", "Jet_pt");
- mt.track_branch_vec<float>("nJet", "Jet_eta");
- mt.track_branch_vec<float>("nJet", "Jet_phi");
- mt.track_branch_vec<float>("nJet", "Jet_mass");
- mt.track_branch_vec<float>("nJet", "Jet_btagCMVA");
- mt.track_branch<int>("nGenTop");
- mt.track_branch_vec<int>("nGenTop", "GenTop_pdgId");
- mt.track_branch<int>("nGenPart");
- mt.track_branch_vec<int>("nGenPart", "GenPart_pdgId");
- mt.track_branch_vec<int>("nGenPart", "GenPart_motherIndex");
- mt.track_branch_vec<float>("nGenPart", "GenPart_pt");
- mt.track_branch_vec<float>("nGenPart", "GenPart_eta");
- mt.track_branch_vec<float>("nGenPart", "GenPart_phi");
- mt.track_branch_vec<float>("nGenPart", "GenPart_mass");
- mt.track_branch<int>("ngenLep");
- mt.track_branch_vec<int>("ngenLep", "genLep_sourceId");
- mt.track_branch_vec<float>("ngenLep", "genLep_pt");
- mt.track_branch<int>("nVert");
- }
- void declare_values(MiniTreeDataSet& mt){
- energies(lorentz_vectors("LepGood_pt", "LepGood_eta", "LepGood_phi", "LepGood_mass", "LepGood_4v"), "LepGood_energy");
- energies(lorentz_vectors("GenPart_pt", "GenPart_eta", "GenPart_phi", "GenPart_mass", "GenPart_4v"), "GenPart_energy");
- fv::pair<vector<float>,vector<float>>("LepGood_energy", "LepGood_pt", "LepGood_energy_LepGood_pt");
- max<float>("LepGood_energy", "LepGood_energy_max");
- min<float>("LepGood_energy", "LepGood_energy_min");
- range<float>("LepGood_energy", "LepGood_energy_range");
- mean<float>("LepGood_energy", "LepGood_energy_mean");
- count<float>(GenFunction::register_function<bool(float)>("bJet_Selection", FUNC(([](float x){return x>0;}))),
- "Jet_btagCMVA", "b_jet_count");
- filter("trilepton", FUNC(([nLepGood=lookup<int>("nLepGood")](){
- return dynamic_cast<Value<int>*>(nLepGood)->get_value() == 3;})));
- filter("os-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>("LepGood_charge")](){
- auto& charges = LepGood_charge->get_value();
- return charges.size()==2 && (charges[0] != charges[1]);})));
- filter("ss-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>("LepGood_charge")](){
- auto& charges = LepGood_charge->get_value();
- return charges.size()==2 && (charges[0] == charges[1]); })));
- }
- void declare_containers(MiniTreeDataSet& mt){
- mt.register_container(new ContainerTH1<int>("lepton_count", "Lepton Multiplicity", lookup<int>("nLepGood"), 8, 0, 8));
- mt.register_container(new ContainerTH1<int>("top_quark_count", "Top Quark Multiplicity", lookup<int>("nGenTop"), 8, 0, 8));
- mt.register_container(new ContainerTH1Many<float>("LepGood_energy_all", "Lepton Energy - All",
- lookup<vector<float>>("LepGood_energy"), 50, 0, 500));
- mt.register_container(new ContainerTH1<float>("LepGood_energy_max", "Lepton Energy - Max",
- lookup<float>("LepGood_energy_max"), 50, 0, 500,
- "Lepton Energy Max(GeV)"));
- mt.register_container(new ContainerTH1<float>("LepGood_energy_min", "Lepton Energy - Min",
- lookup<float>("LepGood_energy_min"), 50, 0, 500,
- "Lepton Energy Min(GeV)"));
- mt.register_container(new ContainerTH1<float>("LepGood_energy_range", "Lepton Energy - Range",
- lookup<float>("LepGood_energy_range"), 50, 0, 500,
- "Lepton Energy Range(GeV)"));
- mt.register_container(new ContainerTGraph("nLepvsnJet", "Number of Leptons vs Number of Jets",
- fv::pair<int, int>("nLepGood", "nJet") ));
- mt.register_container(new ContainerTH2Many<float>("LepGood_energy_vs_pt", "Lepton Energy vs Lepton Pt",
- lookup<std::pair<std::vector<float>,std::vector<float>>>("LepGood_energy_LepGood_pt"),
- 50, 0, 500, 50, 0, 500,
- "lepton energy","lepton Pt"));
- mt.register_container(new ContainerTH1<int>("b_jet_count", "B-Jet Multiplicity", lookup<int>("b_jet_count"), 10, 0, 10));
- mt.register_container(new ContainerTH1<int>("jet_count_os_dilepton", "Jet Multiplicity - OS Dilepton Events",
- lookup<int>("nJet"), 14, 0, 14));
- mt.get_container("jet_count_os_dilepton")->add_filter(lookup_filter("os-dilepton"));
- mt.register_container(new ContainerTH1<int>("jet_count_ss_dilepton", "Jet Multiplicity - SS Dilepton Events",
- lookup<int>("nJet"), 14, 0, 14));
- mt.get_container("jet_count_ss_dilepton")->add_filter(lookup_filter("ss-dilepton"));
- mt.register_container(new ContainerTH1<int>("jet_count_trilepton", "Jet Multiplicity - Trilepton Events",
- lookup<int>("nJet"), 14, 0, 14));
- mt.get_container("jet_count_trilepton")->add_filter(lookup_filter("trilepton"));
- mt.register_container(new ContainerTH1<int>("primary_vert_count", "Number of Primary Vertices",
- lookup<int>("nVert"), 50, 0, 50));
- mt.register_container(new CounterMany<int>("GenTop_pdg_id", lookup<vector<int>>("GenTop_pdgId")));
- mt.register_container(new CounterMany<int>("GenPart_pdg_id", lookup<vector<int>>("GenPart_pdgId")));
- mt.register_container(new Vector<vector<int>>("GenPart_pdgId", lookup<vector<int>>("GenPart_pdgId")));
- mt.register_container(new Vector<vector<int>>("GenPart_motherIndex", lookup<vector<int>>("GenPart_motherIndex")));
- mt.register_container(new Vector<vector<float>>("GenPart_pt", lookup<vector<float>>("GenPart_pt")));
- mt.register_container(new Vector<vector<float>>("GenPart_energy", lookup<vector<float>>("GenPart_energy")));
- }
- void run_analysis(const std::string& input_filename, bool silent){
- gSystem->Load("libfilval.so");
- auto replace_suffix = [](const std::string& input, const std::string& new_suffix){
- return input.substr(0, input.find_last_of(".")) + new_suffix;
- };
- string log_filename = replace_suffix(input_filename, "_result.log");
- fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogDebug);
- string output_filename = replace_suffix(input_filename, "_result.root");
- MiniTreeDataSet mt(input_filename, output_filename);
- enable_branches(mt);
- declare_values(mt);
- declare_containers(mt);
- mt.process(silent);
- mt.save_all();
- }
- int main(int argc, char * argv[])
- {
- fv::util::ArgParser args(argc, argv);
- if(!args.cmdOptionExists("-f")) {
- cout << "Usage: ./main -f input_minitree.root" << endl;
- return -1;
- }
- bool silent = args.cmdOptionExists("-s");
- string input_filename = args.getCmdOption("-f");
- run_analysis(input_filename, silent);
- }
|