tracking_eff.cpp 44 KB

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