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_mva_filter = GenFunction::register_function<bool(Particle)>(
"b_mva_filter",
74 FUNC(([cut=B_JET_WP](
const Particle& j){
75 return j.jet.b_cmva > cut;
77 auto& b_pdgid_filter = GenFunction::register_function<bool(Particle)>(
"b_pdgid_filter",
78 FUNC(([](
const Particle& j){
79 return j.genpart.pdgId == 5 || j.genpart.pdgId==-5;
81 auto& w_mass_filter = GenFunction::register_function<bool(Particle, Particle)>(
"w_mass_filter",
82 FUNC(([win_l=W_MASS-10, win_h=W_MASS+10](
const Particle& j1,
const Particle& j2){
83 float inv_mass = (j1.v + j2.v).M();
84 return inv_mass > win_l && inv_mass < win_h;
86 auto& dup_filter = GenFunction::register_function<bool(std::tuple<Particle,Particle>,Particle)>(
"dup_filter",
87 FUNC(([](
const std::tuple<Particle,Particle>& w,
const Particle& b){
89 int j1 = std::get<0>(w).idx;
90 int j2 = std::get<1>(w).idx;
91 return (j0 != j1) && (j0 != j2) && (j1 != j2);
93 auto& qg_id_filter = GenFunction::register_function<bool(Particle, Particle)>(
"qg_id_filter",
94 FUNC(([](
const Particle& j1,
const Particle& j2){
96 int id1 = abs(j1.genpart.pdgId);
97 int id2 = abs(j2.genpart.pdgId);
98 return ((id1 >=1 && id1 <= 5) || id1 == 21) &&
99 ((id2 >=1 && id2 <= 5) || id2 == 21);
103 auto jets = lookup<std::vector<Particle>>(
"jets");
105 auto b_jets = filter(b_mva_filter, jets,
"reco_b_jets");
106 auto w_dijets = tup_filter<Particle,Particle>(w_mass_filter, combinations<Particle,2>(jets,
"reco_dijets"));
108 auto top_cands = cart_product<std::tuple<Particle,Particle>, Particle>(w_dijets, b_jets);
110 top_cands = tup_filter(dup_filter, top_cands);
112 auto& t_mass = GenFunction::register_function<float(std::tuple<Particle,Particle>,Particle)>(
"t_mass",
113 FUNC(([](
const std::tuple<Particle,Particle>& w,
const Particle& b){
114 return (std::get<0>(w).v+std::get<1>(w).v+b.v).M();
117 fv::map(t_mass, top_cands,
"reco_top_mass");
120 jets = lookup<std::vector<Particle>>(
"mc_jets");
122 b_jets = filter(b_pdgid_filter, jets);
124 w_dijets = tup_filter(qg_id_filter, combinations<Particle,2>(jets));
125 w_dijets = tup_filter(w_mass_filter, w_dijets);
127 top_cands = cart_product<std::tuple<Particle,Particle>, Particle>(w_dijets, b_jets);
129 top_cands = tup_filter(dup_filter, top_cands);
132 fv::map(t_mass, top_cands,
"mc_top_mass");
136 auto& inv_mass2 = GenFunction::register_function<float(Particle, Particle)>(
"inv_mass2",
137 FUNC(([] (
const Particle& j1,
const Particle& j2){
138 TLorentzVector sum = j1.v + j2.v;
139 return (
float)sum.M();
141 fv::map(inv_mass2, lookup<std::vector<std::tuple<Particle,Particle>>>(
"reco_dijets"),
"dijet_inv_mass");
145 count<float>(GenFunction::register_function<bool(float)>(
"bJet_Selection",
148 }))),
"Jet_btagCMVA",
"b_jet_count");
150 auto &is_electron = GenFunction::register_function<bool(int)>(
"is_electron",
151 FUNC(([](
int pdgId) {
152 return abs(pdgId) == 11;
154 auto &is_muon = GenFunction::register_function<bool(int)>(
"is_muon",
155 FUNC(([](
int pdgId) {
156 return abs(pdgId) == 13;
158 auto &is_lepton = GenFunction::register_function<bool(int)>(
"is_lepton",
159 FUNC(([ie=&is_electron, im=&is_muon](
int pdgId) {
160 return (*ie)(pdgId) || (*im)(pdgId);
163 count<int>(is_electron,
"GenPart_pdgId",
"genEle_count");
164 count<int>(is_muon,
"GenPart_pdgId",
"genMu_count");
165 count<int>(is_lepton,
"GenPart_pdgId",
"genLep_count");
167 count<int>(is_electron,
"LepGood_pdgId",
"recEle_count");
168 count<int>(is_muon,
"LepGood_pdgId",
"recMu_count");
169 count<int>(is_lepton,
"LepGood_pdgId",
"recLep_count");
172 fv::pair<int, int>(
"genEle_count",
"recEle_count",
"genEle_count_v_recEle_count");
173 fv::pair<int, int>(
"genMu_count",
"recMu_count",
"genMu_count_v_recMu_count");
174 fv::pair<int, int>(
"genLep_count",
"recLep_count",
"genLep_count_v_recLep_count");
184 obs_filter(
"trilepton", FUNC(([nLepGood=lookup<int>(
"nLepGood")]()
186 return dynamic_cast<Value<int>*
>(nLepGood)->get_value() == 3;
189 obs_filter(
"os-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>(
"LepGood_charge")]()
191 auto& charges = LepGood_charge->get_value();
192 return charges.size()==2 && (charges[0] != charges[1]);
195 obs_filter(
"ss-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]);
203 void declare_containers(MiniTreeDataSet& mt){
205 mt.register_container<ContainerTH1<int>>(
"lepton_count",
"Lepton Multiplicity", lookup<int>(
"nLepGood"), 8, 0, 8);
207 mt.register_container<ContainerTH1Many<float>>(
"Jet_pt_dist",
"Jet P_T",
208 lookup<vector<float>>(
"Jet_pt"), 50, 0, 500,
210 mt.register_container<ContainerTH1Many<float>>(
"Jet_eta_dist",
"Jet Eta",
211 lookup<vector<float>>(
"Jet_eta"), 50, -3, 3,
213 mt.register_container<ContainerTH1Many<float>>(
"Jet_phi_dist",
"Jet Phi",
214 lookup<vector<float>>(
"Jet_phi"), 20, -PI, PI,
216 mt.register_container<ContainerTH1Many<float>>(
"Jet_mass_dist",
"Jet Mass",
217 lookup<vector<float>>(
"Jet_mass"), 50, 0, 200,
220 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass",
"Di-Jet Inv. Mass - All",
221 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
223 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass_osdilepton",
"Di-Jet Inv. Mass - OS Dilepton",
224 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
225 "Di-Jet Mass")->add_filter(lookup_obs_filter(
"os-dilepton"));
226 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass_ssdilepton",
"Di-Jet Inv. Mass - SS Dilepton",
227 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
228 "Di-Jet Mass")->add_filter(lookup_obs_filter(
"ss-dilepton"));
229 mt.register_container<ContainerTH1Many<float>>(
"dijet_inv_mass_trilepton",
"Di-Jet Inv. Mass - Trilepton",
230 lookup<vector<float>>(
"dijet_inv_mass"), 100, 0, 500,
231 "Di-Jet Mass")->add_filter(lookup_obs_filter(
"trilepton"));
233 mt.register_container<ContainerTH1Many<float>>(
"reco_top_mass",
"Reconstructed Top mass",
234 lookup<vector<float>>(
"reco_top_mass"), 100, 0, 500,
235 "Tri-jet invarient mass");
240 mt.register_container<ContainerTH1Many<float>>(
"mc_top_mass",
"Reconstructed MC Top mass",
241 lookup<vector<float>>(
"mc_top_mass"), 100, 0, 500,
242 "Tri-jet invarient mass");
245 mt.register_container<ContainerTH2<int>>(
"nLepvsnJet",
"Number of Leptons vs Number of Jets",
246 fv::pair<int, int>(
"nLepGood",
"nJet"),
248 "Number of Leptons",
"Number of Jets");
251 mt.register_container<ContainerTH2<int>>(
"genEle_count_v_recEle_count",
"Number of Generated Electrons v. Number of Reconstructed Electrons",
252 lookup<std::pair<int,int>>(
"genEle_count_v_recEle_count"),
253 10, 0, 10, 10, 0, 10,
254 "Generated Electrons",
"Reconstructed Electrons");
256 mt.register_container<ContainerTH2<int>>(
"genMu_count_v_recMu_count",
"Number of Generated Muons v. Number of Reconstructed Muons",
257 lookup<std::pair<int,int>>(
"genMu_count_v_recMu_count"),
258 10, 0, 10, 10, 0, 10,
259 "Generated Muons",
"Reconstructed Muons");
261 mt.register_container<ContainerTH2<int>>(
"genLep_count_v_recLep_count",
"Number of Generated Leptons v. Number of Reconstructed Leptons (e & mu only)",
262 lookup<std::pair<int,int>>(
"genLep_count_v_recLep_count"),
263 10, 0, 10, 10, 0, 10,
264 "Generated Leptons",
"Reconstructed Leptons");
266 mt.register_container<ContainerTH1<int>>(
"b_jet_count",
"B-Jet Multiplicity", lookup<int>(
"b_jet_count"), 10, 0, 10);
269 mt.register_container<ContainerTH1<int>>(
"jet_count_os_dilepton",
"Jet Multiplicity - OS Dilepton Events",
270 lookup<int>(
"nJet"), 14, 0, 14)->add_filter(lookup_obs_filter(
"os-dilepton"));
271 mt.register_container<ContainerTH1<int>>(
"jet_count_ss_dilepton",
"Jet Multiplicity - SS Dilepton Events",
272 lookup<int>(
"nJet"), 14, 0, 14)->add_filter(lookup_obs_filter(
"ss-dilepton"));
273 mt.register_container<ContainerTH1<int>>(
"jet_count_trilepton",
"Jet Multiplicity - Trilepton Events",
274 lookup<int>(
"nJet"), 14, 0, 14)->add_filter(lookup_obs_filter(
"trilepton"));
277 mt.register_container<
CounterMany<int>>(
"GenPart_pdgId_counter", lookup<vector<int>>(
"GenPart_pdgId"));
280 mt.register_container<Vector<std::vector< int >>>(
"GenPart_pdgId", lookup<std::vector< int >>(
"GenPart_pdgId"));
281 mt.register_container<Vector<std::vector< int >>>(
"GenPart_motherIndex", lookup<std::vector< int >>(
"GenPart_motherIndex"));
282 mt.register_container<Vector<std::vector< int >>>(
"GenPart_motherId", lookup<std::vector< int >>(
"GenPart_motherId"));
283 mt.register_container<Vector<std::vector<float>>>(
"GenPart_pt", lookup<std::vector<float>>(
"GenPart_pt"));
284 mt.register_container<Vector<std::vector<float>>>(
"GenPart_eta", lookup<std::vector<float>>(
"GenPart_eta"));
285 mt.register_container<Vector<std::vector<float>>>(
"GenPart_phi", lookup<std::vector<float>>(
"GenPart_phi"));
286 mt.register_container<Vector<std::vector<float>>>(
"GenPart_mass", lookup<std::vector<float>>(
"GenPart_mass"));
287 mt.register_container<Vector<std::vector<float>>>(
"GenPart_energy", lookup<std::vector<float>>(
"GenPart_energy"));
288 mt.register_container<Vector<std::vector< int >>>(
"GenPart_status", lookup<std::vector< int >>(
"GenPart_status"));
290 mt.register_container<Vector<vector< int >>>(
"LepGood_mcMatchPdgId", lookup<vector< int >>(
"LepGood_mcMatchPdgId"));
292 mt.register_container<Vector< int >>(
"run", lookup< int >(
"run") );
293 mt.register_container<Vector< int >>(
"lumi", lookup< int >(
"lumi"));
294 mt.register_container<Vector< int >>(
"evt", lookup< int >(
"evt") );
295 mt.register_container<Vector<float>>(
"xsec", lookup<float>(
"xsec"));
297 mt.register_container<Vector<std::vector< int >>>(
"Jet_mcMatchFlav", lookup<std::vector< int >>(
"Jet_mcMatchFlav"));
299 mt.register_container<Vector<std::vector<float>>>(
"Jet_pt", lookup<std::vector<float>>(
"Jet_pt"));
300 mt.register_container<Vector<std::vector<float>>>(
"Jet_eta", lookup<std::vector<float>>(
"Jet_eta"));
301 mt.register_container<Vector<std::vector<float>>>(
"Jet_phi", lookup<std::vector<float>>(
"Jet_phi"));
302 mt.register_container<Vector<std::vector<float>>>(
"Jet_mass", lookup<std::vector<float>>(
"Jet_mass"));
307 void run_analysis(
const std::string& input_filename,
bool silent){
308 gSystem->Load(
"libfilval.so");
309 auto replace_suffix = [](
const std::string& input,
const std::string& new_suffix){
310 return input.substr(0, input.find_last_of(
".")) + new_suffix;
312 string log_filename = replace_suffix(input_filename,
"_result.log");
313 fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogDebug);
315 string output_filename = replace_suffix(input_filename,
"_result.root");
316 MiniTreeDataSet mt(output_filename, input_filename);
318 create_all_common_values(mt);
319 enable_extra_branches(mt);
321 declare_containers(mt);
327 int main(
int argc,
char * argv[])
329 fv::util::ArgParser args(argc, argv);
330 if(!args.cmdOptionExists(
"-f")) {
331 cout <<
"Usage: ./main (-s) -f input_minitree.root" << endl;
334 bool silent = args.cmdOptionExists(
"-s");
335 string input_filename = args.getCmdOption(
"-f");
336 run_analysis(input_filename, silent);
Same as Counter but accepts multiple values per fill.
The namespace containing all filval classes and functions.