tracking_eff.cpp 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <numeric>
  5. #include <TSystem.h>
  6. #include <Math/VectorUtil.h>
  7. #include "filval.hpp"
  8. #include "root_filval.hpp"
  9. #include "common.hpp"
  10. #include "analysis/TrackingNtupleObjs.hpp"
  11. typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float>> Vec4;
  12. SeedCollection seeds;
  13. GenCollection gens;
  14. SimTrackCollection sim_tracks;
  15. SimVertexCollection sim_vertices;
  16. TrackCollection gsf_tracks;
  17. SuperClusterCollection scls;
  18. std::vector<SimTrack> sim_els;
  19. void register_objects(TrackingDataSet& tds){
  20. seeds.init(&tds);
  21. gens.init(&tds);
  22. sim_tracks.init(&tds);
  23. sim_vertices.init(&tds);
  24. gsf_tracks.init(&tds);
  25. scls.init(&tds);
  26. }
  27. struct {
  28. Value<float>* x;
  29. Value<float>* y;
  30. Value<float>* z;
  31. Value<float>* sigma_x;
  32. Value<float>* sigma_y;
  33. Value<float>* sigma_z;
  34. } bs;
  35. template <typename T>
  36. struct KinColl {
  37. T* pt;
  38. T* eta;
  39. T* phi;
  40. };
  41. bool in_lum_region(const SimVertex& vertex) {
  42. /* Here approximate the luminous region as a cylinder with length 5*\sigma_z and radius
  43. * sqrt(\simga_x^2 + \sigma_y^2) centered as beamspot position.
  44. */
  45. float dx = vertex.x() - bs.x->get();
  46. float dy = vertex.y() - bs.y->get();
  47. float dz = vertex.z() - bs.z->get();
  48. auto radius = static_cast<float>(5 * sqrt(pow(bs.sigma_x->get(), 2) + pow(bs.sigma_y->get(), 2)));
  49. float half_len = 5*bs.sigma_z->get();
  50. return sqrt(dx*dx + dy*dy) < radius and abs(dz) < half_len;
  51. };
  52. bool is_good_sim(const SimTrack& sim_track) {
  53. const auto& vertex = sim_vertices[sim_track.parentVtxIdx()];
  54. return abs(sim_track.pdgId()) == 11 and // electrons
  55. in_lum_region(vertex) and // from luminous region
  56. abs(sim_track.eta())<3.0; // inside ECAL acceptance
  57. };
  58. bool is_good_sim(const std::vector<SimTrack> prompt_sims, const SimTrack& sim_track) {
  59. return find(prompt_sims.begin(), prompt_sims.end(), sim_track) != prompt_sims.end();
  60. };
  61. bool is_good_seed(const Seed& seed, float hoe_cut) {
  62. return seed.isECALDriven() and seed.hoe() < hoe_cut;
  63. }
  64. float reco_energy_rel_err(const SimTrack& sim_track, const Seed& seed) {
  65. return (sim_track.pt() - seed.Et()) / sim_track.pt() ;
  66. }
  67. float reco_energy_rel_err(const SimTrack& sim_track, const Track& track) {
  68. return (sim_track.pt() - track.pt()) / sim_track.pt() ;
  69. }
  70. template<typename TrackOrSeed>
  71. bool reco_energy_consistent(const SimTrack& sim_track, const TrackOrSeed& track, float consistency_cut=0.1) {
  72. return fabs(reco_energy_rel_err(sim_track, track)) < consistency_cut;
  73. }
  74. Vec4 scl_p4(const SuperCluster& scl) {
  75. return Vec4(scl.px(), scl.py(), scl.pz(), scl.e());
  76. }
  77. double deltaR(double eta1, double phi1, double eta2, double phi2) {
  78. return sqrt(pow(eta1 - eta2, 2.0) +
  79. pow(phi1 - phi2, 2.0));
  80. }
  81. void update_sim_els() {
  82. sim_els.clear();
  83. for (const SimTrack sim_track: sim_tracks) {
  84. if (is_good_sim(sim_track)) {
  85. sim_els.push_back(sim_track);
  86. }
  87. }
  88. }
  89. std::tuple<std::vector<SimTrack>, std::vector<SimTrack>> get_prompt_sims() {
  90. /*
  91. * Returns sim tracks that pass is_good_sim as well as match well with a
  92. * prompt gen electron
  93. */
  94. std::vector<Gen> prompt_gen;
  95. for (const auto& gen : gens) {
  96. if (abs(gen.pdgId()) == 11 and gen.isPrompt()) {
  97. prompt_gen.push_back(gen);
  98. }
  99. }
  100. std::vector<SimTrack> prompt_sim;
  101. for (const auto& gen : prompt_gen) {
  102. float gen_phi = atan2(gen.py(), gen.px());
  103. float gen_eta = pseudorapidityP(gen.px(), gen.py(), gen.pz());
  104. int gen_id = gen.pdgId();
  105. for (const auto& sim_el : sim_els) {
  106. float sim_phi = sim_el.phi();
  107. float sim_eta = sim_el.eta();
  108. int sim_id = sim_el.pdgId();
  109. if (gen_id == sim_id and deltaR(gen_eta, gen_phi, sim_eta, sim_phi) < 0.05) {
  110. prompt_sim.push_back(sim_el);
  111. break;
  112. }
  113. }
  114. }
  115. std::vector<SimTrack> nonprompt_sim;
  116. for (const auto& sim_el : sim_els) {
  117. if (find(prompt_sim.begin(), prompt_sim.end(), sim_el) == prompt_sim.end()) {
  118. nonprompt_sim.push_back(sim_el);
  119. }
  120. }
  121. return make_tuple(prompt_sim, nonprompt_sim);
  122. }
  123. auto get_match_stats(bool dRMatch) {
  124. int nSimTrack = 0;
  125. int nGSFTrack = 0;
  126. int nMatched = 0; // 1-to-1
  127. int nMerged = 0; // n-to-1
  128. int nLost = 0; // 1-to-0
  129. int nSplit = 0; // 1-to-n
  130. int nFaked = 0; // 0-to-1
  131. int nFlipped = 0;
  132. vector<float> matched_dR;
  133. vector<float> matched_dpT;
  134. std::map<int, std::vector<int>> sim_matches;
  135. std::map<int, std::vector<int>> gsf_matches;
  136. for(const auto& sim_track : sim_els)
  137. sim_matches[sim_track.idx] = {};
  138. for(const auto& gsf_track : gsf_tracks)
  139. gsf_matches[gsf_track.idx] = {};
  140. nSimTrack = static_cast<int>(sim_matches.size());
  141. nGSFTrack = static_cast<int>(gsf_matches.size());
  142. for (const auto& sim_track : sim_els) {
  143. if (dRMatch) {
  144. for (const auto& gsf_track : gsf_tracks) {
  145. double dR = deltaR(sim_track.eta(), sim_track.phi(), gsf_track.eta(), gsf_track.phi());
  146. if (dR < 0.2) {
  147. sim_matches[sim_track.idx].push_back(gsf_track.idx);
  148. gsf_matches[gsf_track.idx].push_back(sim_track.idx);
  149. matched_dR.push_back(dR);
  150. matched_dpT.push_back((sim_track.pt() - gsf_track.pt())/sim_track.pt());
  151. if (gsf_track.q() != sim_track.q()) {
  152. nFlipped++;
  153. }
  154. }
  155. }
  156. } else {
  157. for (const auto& gsfIdx : sim_track.trkIdx()) {
  158. const Track& gsf_track = gsf_tracks[gsfIdx];
  159. double dR = deltaR(sim_track.eta(), sim_track.phi(), gsf_track.eta(), gsf_track.phi());
  160. sim_matches[sim_track.idx].push_back(gsf_track.idx);
  161. gsf_matches[gsf_track.idx].push_back(sim_track.idx);
  162. matched_dR.push_back(static_cast<float &&>(dR));
  163. matched_dpT.push_back((sim_track.pt() - gsf_track.pt())/sim_track.pt());
  164. if (gsf_track.q() != sim_track.q()) {
  165. nFlipped++;
  166. }
  167. }
  168. }
  169. }
  170. for (const auto& p : sim_matches) {
  171. const auto& matches = p.second;
  172. if (matches.size() == 0) nLost++;
  173. if (matches.size() == 1 and gsf_matches[matches[0]].size() == 1) nMatched++;
  174. if (matches.size() > 1) nSplit++;
  175. }
  176. for (const auto& p : gsf_matches) {
  177. const auto& matches = p.second;
  178. if (matches.size() == 0) nFaked++;
  179. if (matches.size() > 1) nMerged++;
  180. }
  181. return std::make_tuple(nSimTrack, nGSFTrack, nMatched, nMerged, nLost, nSplit, nFaked, nFlipped, matched_dR, matched_dpT);
  182. }
  183. void run(){
  184. using namespace std;
  185. using namespace fv;
  186. using namespace fv_root;
  187. using namespace fv_util;
  188. auto file_list = the_config->get_source_files();
  189. string output_filename = the_config->get_output_filename();
  190. TrackingDataSet tds(output_filename, file_list, "trackingNtuple/tree");
  191. register_objects(tds);
  192. auto hoe_cut = the_config->get("hoe_cut").as<float>(999);
  193. bs = {
  194. tds.track_branch<float>("bsp_x"),
  195. tds.track_branch<float>("bsp_y"),
  196. tds.track_branch<float>("bsp_z"),
  197. tds.track_branch<float>("bsp_sigmax"),
  198. tds.track_branch<float>("bsp_sigmay"),
  199. tds.track_branch<float>("bsp_sigmaz")
  200. };
  201. enum TMType {
  202. NoMatch = 0,
  203. SeedMatched = 1,
  204. TrackMatched = 2,
  205. SeedAndTrackMatched = 3,
  206. };
  207. std::map<std::tuple<int, int>, ContainerTH2<float>*> residuals_dRz;
  208. std::map<std::tuple<int, int>, ContainerTH2<float>*> residuals_dPhi;
  209. std::map<std::tuple<int, int, int>, ContainerTH2<float>*> BPIX_residuals_dRz;
  210. std::map<std::tuple<int, int, int>, ContainerTH2<float>*> BPIX_residuals_dPhi;
  211. std::map<std::tuple<int, int, int>, ContainerTH2<float>*> FPIX_residuals_dRz;
  212. std::map<std::tuple<int, int, int>, ContainerTH2<float>*> FPIX_residuals_dPhi;
  213. stringstream name;
  214. auto set_name = [&name](const std::string& var, const std::string& region,
  215. const int& layer, const int& hit, const int& tm_type) {
  216. name.str("");
  217. name << var << "_" << region;
  218. if (layer>0)
  219. name << "_L" << layer;
  220. name << "_H" << hit << "_v_Et";
  221. switch (tm_type) {
  222. case NoMatch:
  223. name << "_NoMatch";
  224. break;
  225. case SeedMatched:
  226. name << "_SeedMatched";
  227. break;
  228. case TrackMatched:
  229. name << "_TrackMatched";
  230. break;
  231. case SeedAndTrackMatched:
  232. name << "_SeedAndTrackMatched";
  233. break;
  234. default:
  235. break;
  236. }
  237. };
  238. THParams hist_params;
  239. for (int hit=1; hit<=3; hit++) {
  240. for (int tm_type = NoMatch; tm_type <= SeedAndTrackMatched; tm_type++) {
  241. for (int layer=1; layer<=4; layer++) {
  242. hist_params = (hit == 1) ? THParams::lookup("dRz_v_Et") : THParams::lookup("dRz_v_Et_outer_hits");
  243. set_name("dRz", "BPIX", layer, hit, tm_type);
  244. BPIX_residuals_dRz[make_tuple(layer, hit, tm_type)] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  245. set_name("dRz", "FPIX", layer, hit, tm_type);
  246. FPIX_residuals_dRz[make_tuple(layer, hit, tm_type)] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  247. hist_params = (hit == 1) ? THParams::lookup("dPhi_v_Et") : THParams::lookup("dPhi_v_Et_outer_hits");
  248. set_name("dPhi", "BPIX", layer, hit, tm_type);
  249. BPIX_residuals_dPhi[make_tuple(layer, hit, tm_type)] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  250. set_name("dPhi", "FPIX", layer, hit, tm_type);
  251. FPIX_residuals_dPhi[make_tuple(layer, hit, tm_type)] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  252. }
  253. hist_params = (hit == 1) ? THParams::lookup("dRz_v_Et") : THParams::lookup("dRz_v_Et_outer_hits");
  254. set_name("dRz", "ALL", 0, hit, tm_type);
  255. residuals_dRz[std::make_tuple(hit, tm_type)] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  256. hist_params = (hit == 1) ? THParams::lookup("dPhi_v_Et") : THParams::lookup("dPhi_v_Et_outer_hits");
  257. set_name("dPhi", "ALL", 0, hit, tm_type);
  258. residuals_dPhi[make_tuple(hit, tm_type)] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  259. }
  260. }
  261. std::map<int,vector<float>> eta_regions = {{1, {0.0, 1.1, 1.8, 3.0}},
  262. {2, {0.0, 1.4, 2.3, 3.0}},
  263. {3, {0.0, 1.0, 2.0, 3.0}}};
  264. auto get_region = [&eta_regions](int hit, float eta) {
  265. auto regions = eta_regions[hit];
  266. if (regions.size() <= 1) return 1;
  267. float abseta = abs(eta);
  268. for (int r_idx=1; r_idx < regions.size(); r_idx++) {
  269. if (abseta > regions[r_idx-1] and abseta < regions[r_idx]) {
  270. return r_idx;
  271. }
  272. }
  273. return static_cast<int>(regions.size());
  274. };
  275. std::map<int, ContainerTH2<float>*> dPhi_residuals_v_eta;
  276. std::map<int, ContainerTH2<float>*> dRz_residuals_v_eta;
  277. std::map<std::pair<int, int>, ContainerTH2<float>*> dPhi_residuals_v_region;
  278. std::map<std::pair<int, int>, ContainerTH2<float>*> dRz_residuals_v_region;
  279. for (int hit=1; hit<=3; hit++) {
  280. name.str("");
  281. name << "dPhi_residuals_v_eta_H" << hit;
  282. hist_params = (hit==1) ? THParams::lookup("dPhi_v_eta") : THParams::lookup("dPhi_v_eta_outer_hits");
  283. dPhi_residuals_v_eta[hit] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  284. name.str("");
  285. name << "dRz_residuals_v_eta_H" << hit;
  286. hist_params = (hit==1) ? THParams::lookup("dRz_v_eta") : THParams::lookup("dRz_v_eta_outer_hits");
  287. dRz_residuals_v_eta[hit] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  288. for (int region=1; region<=eta_regions[hit].size()-1; region++){
  289. hist_params = (hit==1) ? THParams::lookup("dRz_v_Et") : THParams::lookup("dRz_v_Et_outer_hits");
  290. name.str("");
  291. name << "dRz_residuals_H" << hit << "_R" << region;
  292. dRz_residuals_v_region[{hit, region}] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  293. hist_params = (hit==1) ? THParams::lookup("dPhi_v_Et") : THParams::lookup("dPhi_v_Et_outer_hits");
  294. name.str("");
  295. name << "dPhi_residuals_H" << hit << "_R" << region;
  296. dPhi_residuals_v_region[{hit, region}] = tds.register_container<ContainerTH2<float>>(name.str(), hist_params);
  297. }
  298. }
  299. KinColl<ContainerTH1<float>> good_sim_kinems = {
  300. tds.register_container<ContainerTH1<float>>("good_sim_v_pt", THParams::lookup("pt_fine")),
  301. tds.register_container<ContainerTH1<float>>("good_sim_v_eta", THParams::lookup("eta_fine")),
  302. tds.register_container<ContainerTH1<float>>("good_sim_v_phi", THParams::lookup("phi_fine"))};
  303. KinColl<ContainerTH1<float>> gsf_kinems = {
  304. tds.register_container<ContainerTH1<float>>("gsf_track_v_pt", THParams::lookup("pt_fine")),
  305. tds.register_container<ContainerTH1<float>>("gsf_track_v_eta", THParams::lookup("eta_fine")),
  306. tds.register_container<ContainerTH1<float>>("gsf_track_v_phi", THParams::lookup("phi_fine"))};
  307. KinColl<ContainerTH1<float>> seed_kinems = {
  308. tds.register_container<ContainerTH1<float>>("seed_v_pt", THParams::lookup("pt_fine")),
  309. tds.register_container<ContainerTH1<float>>("seed_v_eta", THParams::lookup("eta_fine")),
  310. tds.register_container<ContainerTH1<float>>("seed_v_phi", THParams::lookup("phi_fine"))};
  311. KinColl<ContainerTH1<float>> scl_kinems = {
  312. tds.register_container<ContainerTH1<float>>("scl_v_pt", THParams::lookup("pt_fine")),
  313. tds.register_container<ContainerTH1<float>>("scl_v_eta", THParams::lookup("eta_fine")),
  314. tds.register_container<ContainerTH1<float>>("scl_v_phi", THParams::lookup("phi_fine"))};
  315. KinColl<ContainerTH1<float>> prompt_kinems = {
  316. tds.register_container<ContainerTH1<float>>("prompt_v_pt", THParams::lookup("pt_fine")),
  317. tds.register_container<ContainerTH1<float>>("prompt_v_eta", THParams::lookup("eta_fine")),
  318. tds.register_container<ContainerTH1<float>>("prompt_v_phi", THParams::lookup("phi_fine"))};
  319. KinColl<ContainerTH1<float>> nonprompt_kinems = {
  320. tds.register_container<ContainerTH1<float>>("nonprompt_v_pt", THParams::lookup("pt_fine")),
  321. tds.register_container<ContainerTH1<float>>("nonprompt_v_eta", THParams::lookup("eta_fine")),
  322. tds.register_container<ContainerTH1<float>>("nonprompt_v_phi", THParams::lookup("phi_fine"))};
  323. KinColl<EfficiencyContainer<float>> seed_eff = {
  324. tds.register_container<EfficiencyContainer<float>>("seed_eff_v_pt", THParams::lookup("pt")),
  325. tds.register_container<EfficiencyContainer<float>>("seed_eff_v_eta", THParams::lookup("eta")),
  326. tds.register_container<EfficiencyContainer<float>>("seed_eff_v_phi", THParams::lookup("phi"))};
  327. KinColl<EfficiencyContainer<float>> seed_pur = {
  328. tds.register_container<EfficiencyContainer<float>>("seed_pur_v_pt", THParams::lookup("pt")),
  329. tds.register_container<EfficiencyContainer<float>>("seed_pur_v_eta", THParams::lookup("eta")),
  330. tds.register_container<EfficiencyContainer<float>>("seed_pur_v_phi", THParams::lookup("phi"))};
  331. KinColl<EfficiencyContainer<float>> tracking_eff = {
  332. tds.register_container<EfficiencyContainer<float>>("tracking_eff_v_pt", THParams::lookup("pt")),
  333. tds.register_container<EfficiencyContainer<float>>("tracking_eff_v_eta", THParams::lookup("eta")),
  334. tds.register_container<EfficiencyContainer<float>>("tracking_eff_v_phi", THParams::lookup("phi"))};
  335. KinColl<EfficiencyContainer<float>> tracking_pur = {
  336. tds.register_container<EfficiencyContainer<float>>("tracking_pur_v_pt", THParams::lookup("pt")),
  337. tds.register_container<EfficiencyContainer<float>>("tracking_pur_v_eta", THParams::lookup("eta")),
  338. tds.register_container<EfficiencyContainer<float>>("tracking_pur_v_phi", THParams::lookup("phi"))};
  339. KinColl<EfficiencyContainer<float>> prompt_eff = {
  340. tds.register_container<EfficiencyContainer<float>>("prompt_eff_v_pt", THParams::lookup("pt")),
  341. tds.register_container<EfficiencyContainer<float>>("prompt_eff_v_eta", THParams::lookup("eta")),
  342. tds.register_container<EfficiencyContainer<float>>("prompt_eff_v_phi", THParams::lookup("phi"))};
  343. KinColl<EfficiencyContainer<float>> prompt_pur = {
  344. tds.register_container<EfficiencyContainer<float>>("prompt_pur_v_pt", THParams::lookup("pt")),
  345. tds.register_container<EfficiencyContainer<float>>("prompt_pur_v_eta", THParams::lookup("eta")),
  346. tds.register_container<EfficiencyContainer<float>>("prompt_pur_v_phi", THParams::lookup("phi"))};
  347. KinColl<EfficiencyContainer<float>> nonprompt_eff = {
  348. tds.register_container<EfficiencyContainer<float>>("nonprompt_eff_v_pt", THParams::lookup("pt")),
  349. tds.register_container<EfficiencyContainer<float>>("nonprompt_eff_v_eta", THParams::lookup("eta")),
  350. tds.register_container<EfficiencyContainer<float>>("nonprompt_eff_v_phi", THParams::lookup("phi"))};
  351. KinColl<EfficiencyContainer<float>> nonprompt_pur = {
  352. tds.register_container<EfficiencyContainer<float>>("nonprompt_pur_v_pt", THParams::lookup("pt")),
  353. tds.register_container<EfficiencyContainer<float>>("nonprompt_pur_v_eta", THParams::lookup("eta")),
  354. tds.register_container<EfficiencyContainer<float>>("nonprompt_pur_v_phi", THParams::lookup("phi"))};
  355. KinColl<EfficiencyContainer<float>> tracking_eff_dR = {
  356. tds.register_container<EfficiencyContainer<float>>("tracking_eff_v_pt_dR", THParams::lookup("pt")),
  357. tds.register_container<EfficiencyContainer<float>>("tracking_eff_v_eta_dR", THParams::lookup("eta")),
  358. tds.register_container<EfficiencyContainer<float>>("tracking_eff_v_phi_dR", THParams::lookup("phi"))};
  359. KinColl<EfficiencyContainer<float>> tracking_pur_dR = {
  360. tds.register_container<EfficiencyContainer<float>>("tracking_pur_v_pt_dR", THParams::lookup("pt")),
  361. tds.register_container<EfficiencyContainer<float>>("tracking_pur_v_eta_dR", THParams::lookup("eta")),
  362. tds.register_container<EfficiencyContainer<float>>("tracking_pur_v_phi_dR", THParams::lookup("phi"))};
  363. KinColl<EfficiencyContainer<float>> prompt_eff_dR = {
  364. tds.register_container<EfficiencyContainer<float>>("prompt_eff_v_pt_dR", THParams::lookup("pt")),
  365. tds.register_container<EfficiencyContainer<float>>("prompt_eff_v_eta_dR", THParams::lookup("eta")),
  366. tds.register_container<EfficiencyContainer<float>>("prompt_eff_v_phi_dR", THParams::lookup("phi"))};
  367. KinColl<EfficiencyContainer<float>> prompt_pur_dR = {
  368. tds.register_container<EfficiencyContainer<float>>("prompt_pur_v_pt_dR", THParams::lookup("pt")),
  369. tds.register_container<EfficiencyContainer<float>>("prompt_pur_v_eta_dR", THParams::lookup("eta")),
  370. tds.register_container<EfficiencyContainer<float>>("prompt_pur_v_phi_dR", THParams::lookup("phi"))};
  371. KinColl<EfficiencyContainer<float>> nonprompt_eff_dR = {
  372. tds.register_container<EfficiencyContainer<float>>("nonprompt_eff_v_pt_dR", THParams::lookup("pt")),
  373. tds.register_container<EfficiencyContainer<float>>("nonprompt_eff_v_eta_dR", THParams::lookup("eta")),
  374. tds.register_container<EfficiencyContainer<float>>("nonprompt_eff_v_phi_dR", THParams::lookup("phi"))};
  375. KinColl<EfficiencyContainer<float>> nonprompt_pur_dR = {
  376. tds.register_container<EfficiencyContainer<float>>("nonprompt_pur_v_pt_dR", THParams::lookup("pt")),
  377. tds.register_container<EfficiencyContainer<float>>("nonprompt_pur_v_eta_dR", THParams::lookup("eta")),
  378. tds.register_container<EfficiencyContainer<float>>("nonprompt_pur_v_phi_dR", THParams::lookup("phi"))};
  379. KinColl<EfficiencyContainer<float>> fake_rate = {
  380. tds.register_container<EfficiencyContainer<float>>("fake_rate_v_pt", THParams::lookup("pt")),
  381. tds.register_container<EfficiencyContainer<float>>("fake_rate_v_eta", THParams::lookup("eta")),
  382. tds.register_container<EfficiencyContainer<float>>("fake_rate_v_phi", THParams::lookup("phi"))};
  383. KinColl<EfficiencyContainer<float>> partial_fake_rate = {
  384. tds.register_container<EfficiencyContainer<float>>("partial_fake_rate_v_pt", THParams::lookup("pt")),
  385. tds.register_container<EfficiencyContainer<float>>("partial_fake_rate_v_eta", THParams::lookup("eta")),
  386. tds.register_container<EfficiencyContainer<float>>("partial_fake_rate_v_phi", THParams::lookup("phi"))};
  387. KinColl<EfficiencyContainer<float>> full_fake_rate = {
  388. tds.register_container<EfficiencyContainer<float>>("full_fake_rate_v_pt", THParams::lookup("pt")),
  389. tds.register_container<EfficiencyContainer<float>>("full_fake_rate_v_eta", THParams::lookup("eta")),
  390. tds.register_container<EfficiencyContainer<float>>("full_fake_rate_v_phi", THParams::lookup("phi"))};
  391. KinColl<EfficiencyContainer<float>> clean_fake_rate = {
  392. tds.register_container<EfficiencyContainer<float>>("clean_fake_rate_v_pt", THParams::lookup("pt")),
  393. tds.register_container<EfficiencyContainer<float>>("clean_fake_rate_v_eta", THParams::lookup("eta")),
  394. tds.register_container<EfficiencyContainer<float>>("clean_fake_rate_v_phi", THParams::lookup("phi"))};
  395. KinColl<EfficiencyContainer<float>> fake_rate_incl = {
  396. tds.register_container<EfficiencyContainer<float>>("fake_rate_incl_v_pt", THParams::lookup("pt")),
  397. tds.register_container<EfficiencyContainer<float>>("fake_rate_incl_v_eta", THParams::lookup("eta")),
  398. tds.register_container<EfficiencyContainer<float>>("fake_rate_incl_v_phi", THParams::lookup("phi"))};
  399. KinColl<EfficiencyContainer<float>> partial_fake_rate_incl = {
  400. tds.register_container<EfficiencyContainer<float>>("partial_fake_rate_incl_v_pt", THParams::lookup("pt")),
  401. tds.register_container<EfficiencyContainer<float>>("partial_fake_rate_incl_v_eta", THParams::lookup("eta")),
  402. tds.register_container<EfficiencyContainer<float>>("partial_fake_rate_incl_v_phi", THParams::lookup("phi"))};
  403. KinColl<EfficiencyContainer<float>> full_fake_rate_incl = {
  404. tds.register_container<EfficiencyContainer<float>>("full_fake_rate_incl_v_pt", THParams::lookup("pt")),
  405. tds.register_container<EfficiencyContainer<float>>("full_fake_rate_incl_v_eta", THParams::lookup("eta")),
  406. tds.register_container<EfficiencyContainer<float>>("full_fake_rate_incl_v_phi", THParams::lookup("phi"))};
  407. KinColl<EfficiencyContainer<float>> clean_fake_rate_incl = {
  408. tds.register_container<EfficiencyContainer<float>>("clean_fake_rate_incl_v_pt", THParams::lookup("pt")),
  409. tds.register_container<EfficiencyContainer<float>>("clean_fake_rate_incl_v_eta", THParams::lookup("eta")),
  410. tds.register_container<EfficiencyContainer<float>>("clean_fake_rate_incl_v_phi", THParams::lookup("phi"))};
  411. auto& hit_vs_layer_barrel = *tds.register_container<ContainerTH2<int>>("hit_vs_layer_barrel", THParams::lookup("hit_vs_layer"));
  412. auto& hit_vs_layer_forward = *tds.register_container<ContainerTH2<int>>("hit_vs_layer_forward", THParams::lookup("hit_vs_layer"));
  413. auto& gsf_tracks_nmatch_sim_tracks = *tds.register_container<ContainerTH1<size_t>>("gsf_tracks_nmatch_sim_tracks ", THParams::lookup("gsf_tracks_nmatch_sim_tracks"));
  414. auto& ecal_energy_resolution = *tds.register_container<ContainerTH1<float>>("ecal_energy_resolution ", THParams::lookup("ecal_energy_resolution"));
  415. auto& n_seeds = *tds.register_container<ContainerTH1<size_t>>("n_seeds", THParams::lookup("n_seeds"));
  416. auto& n_good_seeds = *tds.register_container<ContainerTH1<size_t>>("n_good_seeds", THParams::lookup("n_seeds"));
  417. auto& n_good_sim = *tds.register_container<ContainerTH1<size_t>>("n_good_sim", THParams::lookup("n_seeds"));
  418. auto& n_prompt = *tds.register_container<ContainerTH1<size_t>>("n_prompt", THParams::lookup("n_seeds"));
  419. auto& n_nonprompt = *tds.register_container<ContainerTH1<size_t>>("n_nonprompt", THParams::lookup("n_seeds"));
  420. auto& n_gsf_tracks = *tds.register_container<ContainerTH1<size_t>>("n_gsf_track", THParams::lookup("n_seeds"));
  421. auto& n_scl = *tds.register_container<ContainerTH1<size_t>>("n_scl", THParams::lookup("n_seeds"));
  422. auto& n_good_scl = *tds.register_container<ContainerTH1<size_t>>("n_good_scl", THParams::lookup("n_seeds"));
  423. auto& n_matched = *tds.register_container<ContainerTH1<int>>("n_matched", THParams::lookup("n_seeds"));
  424. auto& n_merged = *tds.register_container<ContainerTH1<int>>("n_merged", THParams::lookup("n_seeds"));
  425. auto& n_lost = *tds.register_container<ContainerTH1<int>>("n_lost", THParams::lookup("n_seeds"));
  426. auto& n_split = *tds.register_container<ContainerTH1<int>>("n_split", THParams::lookup("n_seeds"));
  427. auto& n_faked = *tds.register_container<ContainerTH1<int>>("n_faked", THParams::lookup("n_seeds"));
  428. auto& n_flipped = *tds.register_container<ContainerTH1<int>>("n_flipped", THParams::lookup("n_seeds"));
  429. auto& matched_dR = *tds.register_container<ContainerTH1<float>>("matched_dR", THParams::lookup("matched_dR"));
  430. auto& matched_dpT = *tds.register_container<ContainerTH1<float>>("matched_dpT", THParams::lookup("matched_dpT"));
  431. auto& n_matched_dR = *tds.register_container<ContainerTH1<int>>("n_matched_dR", THParams::lookup("n_seeds"));
  432. auto& n_merged_dR = *tds.register_container<ContainerTH1<int>>("n_merged_dR", THParams::lookup("n_seeds"));
  433. auto& n_lost_dR = *tds.register_container<ContainerTH1<int>>("n_lost_dR", THParams::lookup("n_seeds"));
  434. auto& n_split_dR = *tds.register_container<ContainerTH1<int>>("n_split_dR", THParams::lookup("n_seeds"));
  435. auto& n_faked_dR = *tds.register_container<ContainerTH1<int>>("n_faked_dR", THParams::lookup("n_seeds"));
  436. auto& n_flipped_dR = *tds.register_container<ContainerTH1<int>>("n_flipped_dR", THParams::lookup("n_seeds"));
  437. auto& matched_dR_dR = *tds.register_container<ContainerTH1<float>>("matched_dR_dR", THParams::lookup("matched_dR"));
  438. auto& matched_dpT_dR = *tds.register_container<ContainerTH1<float>>("matched_dpT_dR", THParams::lookup("matched_dpT"));
  439. auto& tm_corr = *tds.register_container<ContainerTH2<int>>("tm_corr", THParams(2, -0.5, 1.5, 2, -0.5, 1.5));
  440. while (tds.next()) {
  441. update_sim_els();
  442. vector<SimTrack> prompt_sims, nonprompt_sims;
  443. std::tie(prompt_sims, nonprompt_sims) = get_prompt_sims();
  444. size_t _n_good_seeds = 0;
  445. for (const auto& seed : seeds) {
  446. if (is_good_seed(seed, hoe_cut)) {
  447. _n_good_seeds++;
  448. seed_kinems.pt->fill(seed.pt());
  449. seed_kinems.eta->fill(seed.eta());
  450. seed_kinems.phi->fill(seed.phi());
  451. }
  452. }
  453. n_seeds.fill(seeds.size());
  454. n_good_seeds.fill(_n_good_seeds);
  455. for (const auto& sim_track : sim_els) {
  456. good_sim_kinems.pt->fill(sim_track.pt());
  457. good_sim_kinems.eta->fill(sim_track.eta());
  458. good_sim_kinems.phi->fill(sim_track.phi());
  459. }
  460. n_prompt.fill(prompt_sims.size());
  461. for (const auto& prompt : prompt_sims) {
  462. prompt_kinems.pt->fill(prompt.pt());
  463. prompt_kinems.eta->fill(prompt.eta());
  464. prompt_kinems.phi->fill(prompt.phi());
  465. }
  466. n_nonprompt.fill(nonprompt_sims.size());
  467. for (const auto& nonprompt : nonprompt_sims) {
  468. nonprompt_kinems.pt->fill(nonprompt.pt());
  469. nonprompt_kinems.eta->fill(nonprompt.eta());
  470. nonprompt_kinems.phi->fill(nonprompt.phi());
  471. }
  472. for (const auto& gsf_track : gsf_tracks) {
  473. gsf_kinems.pt->fill(gsf_track.pt());
  474. gsf_kinems.eta->fill(gsf_track.eta());
  475. gsf_kinems.phi->fill(gsf_track.phi());
  476. }
  477. size_t _n_good_scl = 0;
  478. for (const auto& scl : scls) {
  479. if (scl.hoe() < hoe_cut) {
  480. _n_good_scl++;
  481. scl_kinems.pt->fill(hypot(scl.px(), scl.py()));
  482. scl_kinems.eta->fill(pseudorapidity(scl.x(), scl.y(), scl.z()));
  483. scl_kinems.phi->fill(atan2(scl.y(), scl.x()));
  484. }
  485. }
  486. n_scl.fill(scls.size());
  487. n_good_scl.fill(_n_good_scl);
  488. auto match_stats = get_match_stats(false);
  489. n_good_sim.fill(std::get<0>(match_stats));
  490. n_gsf_tracks.fill(std::get<1>(match_stats));
  491. n_matched.fill(std::get<2>(match_stats));
  492. n_merged.fill(std::get<3>(match_stats));
  493. n_lost.fill(std::get<4>(match_stats));
  494. n_split.fill(std::get<5>(match_stats));
  495. n_faked.fill(std::get<6>(match_stats));
  496. n_flipped.fill(std::get<7>(match_stats));
  497. for(float dR : std::get<8>(match_stats)) matched_dR.fill(dR);
  498. for(float dpT : std::get<9>(match_stats)) matched_dpT.fill(dpT);
  499. match_stats = get_match_stats(true);
  500. n_matched_dR.fill(std::get<2>(match_stats));
  501. n_merged_dR.fill(std::get<3>(match_stats));
  502. n_lost_dR.fill(std::get<4>(match_stats));
  503. n_split_dR.fill(std::get<5>(match_stats));
  504. n_faked_dR.fill(std::get<6>(match_stats));
  505. n_flipped_dR.fill(std::get<7>(match_stats));
  506. for(float dR : std::get<8>(match_stats)) matched_dR_dR.fill(dR);
  507. for(float dpT : std::get<9>(match_stats)) matched_dpT_dR.fill(dpT);
  508. for (const auto& sim_track : sim_els) {
  509. if (seeds.size() == 0) continue;
  510. for (const auto &seed_idx : sim_track.seedIdx()) {
  511. const Seed& seed = seeds[seed_idx];
  512. if (!is_good_seed(seed, hoe_cut)) continue;
  513. ecal_energy_resolution.fill(reco_energy_rel_err(sim_track, seed));
  514. }
  515. }
  516. // Seeding Efficiency
  517. for (const auto& sim_track : sim_els) {
  518. if (seeds.size() == 0) continue;
  519. bool matched = false;
  520. for (const auto& seed_idx : sim_track.seedIdx()) {
  521. const Seed& seed = seeds[seed_idx];
  522. if (is_good_seed(seed, hoe_cut)) {
  523. matched=true;
  524. break;
  525. }
  526. }
  527. if (abs(sim_track.eta()) < 2.4)
  528. seed_eff.pt->fill(sim_track.pt(), matched);
  529. if (sim_track.pt() > 20.0)
  530. seed_eff.eta->fill(sim_track.eta(), matched);
  531. if (abs(sim_track.eta()) < 2.4 and sim_track.pt() > 20)
  532. seed_eff.phi->fill(sim_track.phi(), matched);
  533. }
  534. // Tracking Efficiency
  535. for (const auto& sim_track : sim_els) {
  536. if (gsf_tracks.size() == 0) continue;
  537. bool matched = false;
  538. for (const auto& track_idx : sim_track.trkIdx()) {
  539. const Seed& seed = seeds[gsf_tracks[track_idx].seedIdx()];
  540. if (is_good_seed(seed, hoe_cut)) {
  541. matched=true;
  542. break;
  543. }
  544. }
  545. if (abs(sim_track.eta()) < 2.4)
  546. tracking_eff.pt->fill(sim_track.pt(), matched);
  547. if (sim_track.pt() > 20.0)
  548. tracking_eff.eta->fill(sim_track.eta(), matched);
  549. if (abs(sim_track.eta()) < 2.4 and sim_track.pt() > 20)
  550. tracking_eff.phi->fill(sim_track.phi(), matched);
  551. if (std::find(prompt_sims.begin(), prompt_sims.end(), sim_track) != prompt_sims.end()) {
  552. if (abs(sim_track.eta()) < 2.4)
  553. prompt_eff.pt->fill(sim_track.pt(), matched);
  554. if (sim_track.pt() > 20.0)
  555. prompt_eff.eta->fill(sim_track.eta(), matched);
  556. if (abs(sim_track.eta()) < 2.4 and sim_track.pt() > 20)
  557. prompt_eff.phi->fill(sim_track.phi(), matched);
  558. }
  559. if (std::find(nonprompt_sims.begin(), nonprompt_sims.end(), sim_track) != nonprompt_sims.end()) {
  560. if (abs(sim_track.eta()) < 2.4)
  561. nonprompt_eff.pt->fill(sim_track.pt(), matched);
  562. if (sim_track.pt() > 20.0)
  563. nonprompt_eff.eta->fill(sim_track.eta(), matched);
  564. if (abs(sim_track.eta()) < 2.4 and sim_track.pt() > 20)
  565. nonprompt_eff.phi->fill(sim_track.phi(), matched);
  566. }
  567. // dR-matching
  568. matched = false;
  569. for (const auto& gsf_track : gsf_tracks) {
  570. const Seed& seed = seeds[gsf_track.seedIdx()];
  571. double dR = deltaR(sim_track.eta(), sim_track.phi(), gsf_track.eta(), gsf_track.phi());
  572. if (is_good_seed(seed, hoe_cut) and dR < 0.2) {
  573. matched = true;
  574. break;
  575. }
  576. }
  577. if (abs(sim_track.eta()) < 2.4)
  578. tracking_eff_dR.pt->fill(sim_track.pt(), matched);
  579. if (sim_track.pt() > 20.0)
  580. tracking_eff_dR.eta->fill(sim_track.eta(), matched);
  581. if (abs(sim_track.eta()) < 2.4 and sim_track.pt() > 20)
  582. tracking_eff_dR.phi->fill(sim_track.phi(), matched);
  583. if (find(prompt_sims.begin(), prompt_sims.end(), sim_track) != prompt_sims.end()) {
  584. if (abs(sim_track.eta()) < 2.4)
  585. prompt_eff_dR.pt->fill(sim_track.pt(), matched);
  586. if (sim_track.pt() > 20.0)
  587. prompt_eff_dR.eta->fill(sim_track.eta(), matched);
  588. if (abs(sim_track.eta()) < 2.4 and sim_track.pt() > 20)
  589. prompt_eff_dR.phi->fill(sim_track.phi(), matched);
  590. }
  591. if (find(nonprompt_sims.begin(), nonprompt_sims.end(), sim_track) != nonprompt_sims.end()) {
  592. if (abs(sim_track.eta()) < 2.4)
  593. nonprompt_eff_dR.pt->fill(sim_track.pt(), matched);
  594. if (sim_track.pt() > 20.0)
  595. nonprompt_eff_dR.eta->fill(sim_track.eta(), matched);
  596. if (abs(sim_track.eta()) < 2.4 and sim_track.pt() > 20)
  597. nonprompt_eff_dR.phi->fill(sim_track.phi(), matched);
  598. }
  599. }
  600. // Seeding Purity
  601. for (const auto& seed : seeds) {
  602. if (!is_good_seed(seed, hoe_cut)) continue;
  603. bool match = false;
  604. for (const auto& sim_track_idx : seed.simTrkIdx()) {
  605. if (is_good_sim(sim_els, sim_tracks[sim_track_idx])) {
  606. match = true;
  607. break;
  608. }
  609. }
  610. if (abs(seed.eta()) < 2.4)
  611. seed_pur.pt->fill(seed.pt(), match);
  612. if (seed.pt() > 20)
  613. seed_pur.eta->fill(seed.eta(), match);
  614. if (abs(seed.eta()) < 2.4 and seed.pt() > 20)
  615. seed_pur.phi->fill(seed.phi(), match);
  616. }
  617. // Tracking Purity
  618. for (const auto& gsf_track : gsf_tracks) {
  619. gsf_tracks_nmatch_sim_tracks.fill(gsf_track.simTrkIdx().size());
  620. const Seed& seed = seeds[gsf_track.seedIdx()];
  621. if (!is_good_seed(seed, hoe_cut)) continue;
  622. bool matched = false;
  623. bool prompt_matched = false;
  624. bool nonprompt_matched = false;
  625. for (const auto& sim_track_idx : gsf_track.simTrkIdx()) {
  626. const auto& sim_track = sim_tracks[sim_track_idx];
  627. if (!is_good_sim(sim_els, sim_track)) continue;
  628. matched = true;
  629. if (find(prompt_sims.begin(), prompt_sims.end(), sim_track) != prompt_sims.end()) {
  630. prompt_matched = true;
  631. }
  632. if (find(nonprompt_sims.begin(), nonprompt_sims.end(), sim_track) != nonprompt_sims.end()) {
  633. nonprompt_matched = true;
  634. }
  635. }
  636. if (abs(gsf_track.eta()) < 2.4)
  637. tracking_pur.pt->fill(gsf_track.pt(), matched);
  638. if (gsf_track.pt() > 20)
  639. tracking_pur.eta->fill(gsf_track.eta(), matched);
  640. if (abs(gsf_track.eta()) < 2.4 and gsf_track.pt() > 20)
  641. tracking_pur.phi->fill(gsf_track.phi(), matched);
  642. if (abs(gsf_track.eta()) < 2.4)
  643. prompt_pur.pt->fill(gsf_track.pt(), prompt_matched);
  644. if (gsf_track.pt() > 20)
  645. prompt_pur.eta->fill(gsf_track.eta(), prompt_matched);
  646. if (abs(gsf_track.eta()) < 2.4 and gsf_track.pt() > 20)
  647. prompt_pur.phi->fill(gsf_track.phi(), prompt_matched);
  648. if (abs(gsf_track.eta()) < 2.4)
  649. nonprompt_pur.pt->fill(gsf_track.pt(), nonprompt_matched);
  650. if (gsf_track.pt() > 20)
  651. nonprompt_pur.eta->fill(gsf_track.eta(), nonprompt_matched);
  652. if (abs(gsf_track.eta()) < 2.4 and gsf_track.pt() > 20)
  653. nonprompt_pur.phi->fill(gsf_track.phi(), nonprompt_matched);
  654. // dR-matching
  655. matched = false;
  656. prompt_matched = false;
  657. nonprompt_matched = false;
  658. for (const auto& sim_track : sim_els) {
  659. double dR = deltaR(sim_track.eta(), sim_track.phi(), gsf_track.eta(), gsf_track.phi());
  660. if (dR < 0.2) {
  661. matched = true;
  662. if (find(prompt_sims.begin(), prompt_sims.end(), sim_track) != prompt_sims.end()) {
  663. prompt_matched = true;
  664. }
  665. if (find(nonprompt_sims.begin(), nonprompt_sims.end(), sim_track) != nonprompt_sims.end()) {
  666. nonprompt_matched = true;
  667. }
  668. }
  669. }
  670. if (abs(gsf_track.eta()) < 2.4)
  671. tracking_pur_dR.pt->fill(gsf_track.pt(), matched);
  672. if (gsf_track.pt() > 20.0)
  673. tracking_pur_dR.eta->fill(gsf_track.eta(), matched);
  674. if (abs(gsf_track.eta()) < 2.4 and gsf_track.pt() > 20)
  675. tracking_pur_dR.phi->fill(gsf_track.phi(), matched);
  676. if (abs(gsf_track.eta()) < 2.4)
  677. prompt_pur_dR.pt->fill(gsf_track.pt(), prompt_matched);
  678. if (gsf_track.pt() > 20)
  679. prompt_pur_dR.eta->fill(gsf_track.eta(), prompt_matched);
  680. if (abs(gsf_track.eta()) < 2.4 and gsf_track.pt() > 20)
  681. prompt_pur_dR.phi->fill(gsf_track.phi(), prompt_matched);
  682. if (abs(gsf_track.eta()) < 2.4)
  683. nonprompt_pur_dR.pt->fill(gsf_track.pt(), nonprompt_matched);
  684. if (gsf_track.pt() > 20)
  685. nonprompt_pur_dR.eta->fill(gsf_track.eta(), nonprompt_matched);
  686. if (abs(gsf_track.eta()) < 2.4 and gsf_track.pt() > 20)
  687. nonprompt_pur_dR.phi->fill(gsf_track.phi(), nonprompt_matched);
  688. }
  689. // Fake-Rate
  690. std::map<size_t, std::vector<int>> scl2trk; // Maps superclusters to tm-status of matched gsf-tracks
  691. for (const auto &gsf_track : gsf_tracks) {
  692. bool gsf_truth_matched = false;
  693. for(const auto& sim_track_idx : gsf_track.simTrkIdx()) {
  694. if (is_good_sim(sim_els, sim_tracks[sim_track_idx])) {
  695. gsf_truth_matched = true;
  696. break;
  697. }
  698. }
  699. int scl_idx = seeds[gsf_track.seedIdx()].sclIdx();
  700. scl2trk[scl_idx].push_back(gsf_truth_matched);
  701. }
  702. std::set<size_t> tm_scls; // Set of super-clusters with well matched sim-electrons
  703. for (const auto &scl : scls) {
  704. Vec4 p4 = scl_p4(scl);
  705. for(const auto& sim_track : sim_els) {
  706. if (deltaR(p4.eta(), p4.phi(), sim_track.eta(), sim_track.phi()) > 0.2) continue;
  707. if (((p4.Et() - sim_track.pt()) / p4.Et()) > 0.1) continue;
  708. tm_scls.insert(scl.idx);
  709. break;
  710. }
  711. }
  712. /* cout << "scls: "; */
  713. /* for (const auto& scl: scls) cout << scl.idx << ", "; */
  714. /* cout << endl << "tm_scls: "; */
  715. /* for (const auto& idx: tm_scls) cout << idx << ", "; */
  716. /* cout << endl; */
  717. for (const auto &scl : scls) {
  718. if (scl.hoe() > hoe_cut) continue;
  719. float scl_pt = hypot(scl.px(), scl.py());
  720. float scl_eta = pseudorapidity(scl.x(), scl.y(), scl.z());
  721. float scl_phi = atan2(scl.py(), scl.px());
  722. int ntracks = scl2trk[scl.idx].size();
  723. int ntmtracks = std::accumulate(scl2trk[scl.idx].begin(), scl2trk[scl.idx].end(), 0);
  724. bool partial_fake = ntmtracks > 0 and ntracks > ntmtracks;
  725. bool full_fake = ntmtracks == 0 and ntracks > 0;
  726. /* cout << "ntracks: " << ntracks << " "; */
  727. /* cout << "count: " << tm_scls.count(scl.idx); */
  728. if (ntracks > 0) {
  729. partial_fake_rate_incl.pt->fill(scl_pt, partial_fake);
  730. partial_fake_rate_incl.eta->fill(scl_eta, partial_fake);
  731. partial_fake_rate_incl.phi->fill(scl_phi, partial_fake);
  732. if (abs(scl_eta) < 2.4) partial_fake_rate.pt->fill(scl_pt, partial_fake);
  733. if (scl_pt > 20.0) partial_fake_rate.eta->fill(scl_eta, partial_fake);
  734. if (abs(scl_eta) < 2.4 and scl_pt > 20) partial_fake_rate.phi->fill(scl_phi, partial_fake);
  735. full_fake_rate_incl.pt->fill(scl_pt, full_fake);
  736. full_fake_rate_incl.eta->fill(scl_eta, full_fake);
  737. full_fake_rate_incl.phi->fill(scl_phi, full_fake);
  738. if (abs(scl_eta) < 2.4) full_fake_rate.pt->fill(scl_pt, full_fake);
  739. if (scl_pt > 20.0) full_fake_rate.eta->fill(scl_eta, full_fake);
  740. if (abs(scl_eta) < 2.4 and scl_pt > 20) full_fake_rate.phi->fill(scl_phi, full_fake);
  741. if (tm_scls.count(scl.idx) == 0) {
  742. clean_fake_rate_incl.pt->fill(scl_pt, full_fake);
  743. clean_fake_rate_incl.eta->fill(scl_eta, full_fake);
  744. clean_fake_rate_incl.phi->fill(scl_phi, full_fake);
  745. if (abs(scl_eta) < 2.4) clean_fake_rate.pt->fill(scl_pt, full_fake);
  746. if (scl_pt > 20.0) clean_fake_rate.eta->fill(scl_eta, full_fake);
  747. if (abs(scl_eta) < 2.4 and scl_pt > 20) clean_fake_rate.phi->fill(scl_phi, full_fake);
  748. }
  749. }
  750. if (tm_scls.count(scl.idx) == 0) {
  751. fake_rate_incl.pt->fill(scl_pt, ntracks>0);
  752. fake_rate_incl.eta->fill(scl_eta, ntracks>0);
  753. fake_rate_incl.phi->fill(scl_phi, ntracks>0);
  754. if (abs(scl_eta) < 2.4) fake_rate.pt->fill(scl_pt, ntracks>0);
  755. if (scl_pt > 20.0) fake_rate.eta->fill(scl_eta, ntracks>0);
  756. if (abs(scl_eta) < 2.4 and scl_pt > 20) fake_rate.phi->fill(scl_phi, ntracks>0);
  757. }
  758. /* cout << endl; */
  759. }
  760. // Hit Residuals
  761. for (const auto& seed : seeds) {
  762. if (seed.trkIdx() < 0) continue; // require that seed produced gsf-track
  763. if (!is_good_seed(seed, hoe_cut)) continue;
  764. bool is_seed_sim_matched = false;
  765. for (const auto& sim_track_idx : seed.simTrkIdx()) {
  766. const SimTrack& sim_track = sim_tracks[sim_track_idx];
  767. if (is_good_sim(sim_els, sim_track) and reco_energy_consistent(sim_track, seed)) {
  768. is_seed_sim_matched = true;
  769. break;
  770. }
  771. }
  772. bool is_track_sim_matched = false;
  773. const auto the_track = gsf_tracks[seed.trkIdx()];
  774. for (const auto& sim_track_idx : the_track.simTrkIdx()) {
  775. const SimTrack& sim_track = sim_tracks[sim_track_idx];
  776. if (is_good_sim(sim_els, sim_track) and reco_energy_consistent(sim_track, the_track)) {
  777. is_track_sim_matched = true;
  778. break;
  779. }
  780. }
  781. std::vector<TMType> tm_types;
  782. if (is_seed_sim_matched and is_track_sim_matched) {
  783. tm_types = {SeedAndTrackMatched, SeedMatched, TrackMatched};
  784. } else if (is_seed_sim_matched) {
  785. tm_types = {SeedMatched};
  786. } else if (is_track_sim_matched) {
  787. tm_types = {TrackMatched};
  788. } else {
  789. tm_types = {NoMatch};
  790. }
  791. tm_corr.fill(is_seed_sim_matched, is_track_sim_matched);
  792. vector<int> hits_valid;
  793. vector<float> hits_dRz;
  794. vector<float> hits_dPhi;
  795. if (the_track.q() == 1) {
  796. hits_valid = seed.isValidPos();
  797. hits_dRz = seed.dRZPos();
  798. hits_dPhi = seed.dPhiPos();
  799. } else {
  800. hits_valid = seed.isValidNeg();
  801. hits_dRz = seed.dRZNeg();
  802. hits_dPhi = seed.dPhiNeg();
  803. }
  804. const vector<int>& hits_isBarrel = seed.isBarrel();
  805. const vector<int>& hits_layerOrDiskNr = seed.layerOrDiskNr();
  806. for (const auto& tm_type : tm_types) {
  807. size_t nHits = hits_valid.size();
  808. for (size_t hit_idx = 0; hit_idx < nHits; hit_idx++) {
  809. if (!hits_valid[hit_idx]) continue;
  810. bool isBarrel = hits_isBarrel[hit_idx] == 1;
  811. int layerOrDiskNr = hits_layerOrDiskNr[hit_idx];
  812. float dRz = abs(hits_dRz[hit_idx]);
  813. float dPhi = abs(hits_dPhi[hit_idx]);
  814. int eta_region = get_region(static_cast<int>(hit_idx + 1), seed.eta());
  815. if (is_seed_sim_matched) {
  816. dRz_residuals_v_eta[hit_idx + 1]->fill(dRz, abs(seed.eta()));
  817. dPhi_residuals_v_eta[hit_idx + 1]->fill(dPhi, abs(seed.eta()));
  818. dRz_residuals_v_region[make_pair(hit_idx + 1, eta_region)]->fill(dRz, seed.Et());
  819. dPhi_residuals_v_region[make_pair(hit_idx + 1, eta_region)]->fill(dPhi, seed.Et());
  820. }
  821. residuals_dRz[make_tuple(hit_idx + 1, tm_type)]->fill(dRz, seed.Et());
  822. residuals_dPhi[make_tuple(hit_idx + 1, tm_type)]->fill(dPhi, seed.Et());
  823. if (layerOrDiskNr == -1) continue; // subDet is not set w/ old seeding
  824. if (isBarrel)
  825. hit_vs_layer_barrel.fill(layerOrDiskNr, static_cast<const int &>(hit_idx + 1));
  826. else
  827. hit_vs_layer_forward.fill(layerOrDiskNr, static_cast<const int &>(hit_idx + 1));
  828. if (isBarrel) {
  829. BPIX_residuals_dRz[make_tuple(layerOrDiskNr, hit_idx + 1, tm_type)]->fill(dRz, seed.Et());
  830. BPIX_residuals_dPhi[make_tuple(layerOrDiskNr, hit_idx + 1, tm_type)]->fill(dPhi, seed.Et());
  831. } else {
  832. FPIX_residuals_dRz[make_tuple(layerOrDiskNr, hit_idx + 1, tm_type)]->fill(dRz, seed.Et());
  833. FPIX_residuals_dPhi[make_tuple(layerOrDiskNr, hit_idx + 1, tm_type)]->fill(dPhi, seed.Et());
  834. }
  835. }
  836. }
  837. }
  838. }
  839. tds.save_all();
  840. }
  841. int main(int argc, char * argv[]){
  842. using namespace fv_util;
  843. ArgParser args(argc, argv);
  844. if(args.cmd_option_exists("-c")) {
  845. init_config(args.get_cmd_option("-c"));
  846. args.update_config();
  847. if (args.cmd_option_exists("-s")) {
  848. the_config->update_key("silent", true);
  849. }
  850. if (args.cmd_option_exists("-b")) {
  851. the_config->update_key("batch", true);
  852. }
  853. init_log(LogPriority::kLogInfo);
  854. // gSystem->Load("libfilval.so");
  855. run();
  856. } else {
  857. cout << "Usage: ./" << argv[0] << " (-s) (-b) -c config_file.yaml" << endl;
  858. }
  859. return 0;
  860. }