tracking_validation.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4. #include <numeric>
  5. #include <limits>
  6. #include <cmath>
  7. #include <TSystem.h>
  8. #include "filval/filval.hpp"
  9. #include "filval/root/filval.hpp"
  10. #include <boost/range/combine.hpp>
  11. #include "TrackingNtuple.h"
  12. #include "analysis/obj_types.cpp"
  13. using namespace std;
  14. using namespace fv;
  15. using namespace fv::root;
  16. using namespace std;
  17. #define HIT_TYPE_PIXEL 0
  18. #define HIT_TYPE_GLUED 1
  19. #define HIT_TYPE_STRIP 2
  20. Value<vector<Seed>>* seeds;
  21. Value<vector<PixRecHit>>* pixrec_hits;
  22. Value<vector<Track>>* tracks;
  23. Value<vector<SimHit>>* sim_hits;
  24. Value<vector<SimTrack>>* sim_tracks;
  25. void register_objects(TrackingDataSet& tds){
  26. seeds = register_seeds(tds);
  27. pixrec_hits = register_pixrec_hits(tds);
  28. tracks = register_tracks(tds);
  29. sim_hits = register_sim_hits(tds);
  30. sim_tracks = register_sim_tracks(tds);
  31. }
  32. void setup_dphi_vs_eta(TrackingDataSet& tds){
  33. auto& calc_dphi_vs_eta =
  34. func<std::pair<vector<float>,vector<float>>(vector<Seed>,
  35. vector<PixRecHit>,
  36. vector<SimHit>, int)>("calc_dphi_vs_eta",
  37. FUNC(([](const vector<Seed>& seeds,
  38. const vector<PixRecHit> pixrec_hits,
  39. const vector<SimHit> sim_hits,
  40. int layer){
  41. vector<float> dphi;
  42. vector<float> eta;
  43. for(const Seed &seed : seeds){
  44. int hitIdx, hitType;
  45. for(auto tup : boost::combine(seed.hitIdx, seed.hitType)){
  46. boost::tie(hitIdx, hitType) = tup;
  47. if(hitType == HIT_TYPE_PIXEL){
  48. const PixRecHit &hit = pixrec_hits[hitIdx];
  49. if(layer && hit.lay != layer) continue;
  50. float hit_phi = atan2(hit.y, hit.x);
  51. for(const int& simHitIdx : hit.simHitIdx){
  52. const SimHit &sim_hit = sim_hits[simHitIdx];
  53. dphi.push_back(hit_phi-atan2(sim_hit.y, sim_hit.x));
  54. eta.push_back(seed.eta);
  55. }
  56. }
  57. }
  58. }
  59. return std::make_pair(dphi,eta);
  60. })));
  61. auto dphi_vs_eta_B1 =
  62. fv::apply(calc_dphi_vs_eta, fv::tuple(seeds, pixrec_hits, sim_hits, constant<int>("1", 1)), "dphi_vs_eta_B1");
  63. auto dphi_vs_eta_B2 =
  64. fv::apply(calc_dphi_vs_eta, fv::tuple(seeds, pixrec_hits, sim_hits, constant<int>("2", 2)), "dphi_vs_eta_B2");
  65. auto dphi_vs_eta_B3 =
  66. fv::apply(calc_dphi_vs_eta, fv::tuple(seeds, pixrec_hits, sim_hits, constant<int>("3", 3)), "dphi_vs_eta_B3");
  67. auto dphi_vs_eta_B4 =
  68. fv::apply(calc_dphi_vs_eta, fv::tuple(seeds, pixrec_hits, sim_hits, constant<int>("4", 4)), "dphi_vs_eta_B4");
  69. tds.register_container<ContainerTH2Many<float>>("dphi_vs_eta_B1", "dphi vs eta (BPIX L1)",
  70. dphi_vs_eta_B1, 100, -0.002, 0.002, 20, -3, 3,
  71. "dphi", "eta");
  72. tds.register_container<ContainerTH2Many<float>>("dphi_vs_eta_B2", "dphi vs eta (BPIX L2)",
  73. dphi_vs_eta_B2, 100, -0.002, 0.002, 20, -3, 3,
  74. "dphi", "eta");
  75. tds.register_container<ContainerTH2Many<float>>("dphi_vs_eta_B3", "dphi vs eta (BPIX L3)",
  76. dphi_vs_eta_B3, 100, -0.002, 0.002, 20, -3, 3,
  77. "dphi", "eta");
  78. tds.register_container<ContainerTH2Many<float>>("dphi_vs_eta_B4", "dphi vs eta (BPIX L4)",
  79. dphi_vs_eta_B4, 100, -0.002, 0.002, 20, -3, 3,
  80. "dphi", "eta");
  81. }
  82. void setup_dz_vs_eta(TrackingDataSet& tds){
  83. auto& calc_dz_vs_eta =
  84. func<std::pair<vector<float>,vector<float>>(vector<Seed>,
  85. vector<PixRecHit>,
  86. vector<SimHit>, int)>("calc_dz_vs_eta",
  87. FUNC(([](const vector<Seed>& seeds,
  88. const vector<PixRecHit> pixrec_hits,
  89. const vector<SimHit> sim_hits,
  90. int layer){
  91. vector<float> dz;
  92. vector<float> eta;
  93. for(const Seed &seed : seeds){
  94. int hitIdx, hitType;
  95. for(auto tup : boost::combine(seed.hitIdx, seed.hitType)){
  96. boost::tie(hitIdx, hitType) = tup;
  97. if(hitType == HIT_TYPE_PIXEL){
  98. const PixRecHit &hit = pixrec_hits[hitIdx];
  99. if(layer && hit.lay != layer) continue;
  100. for(const int& simHitIdx : hit.simHitIdx){
  101. dz.push_back(hit.z-sim_hits[simHitIdx].z);
  102. eta.push_back(seed.eta);
  103. }
  104. }
  105. }
  106. }
  107. return std::make_pair(dz,eta);
  108. })));
  109. auto dz_vs_eta_B1 =
  110. fv::apply(calc_dz_vs_eta, fv::tuple(seeds, pixrec_hits, sim_hits, constant<int>("1", 1)), "dz_vs_eta_B1");
  111. auto dz_vs_eta_B2 =
  112. fv::apply(calc_dz_vs_eta, fv::tuple(seeds, pixrec_hits, sim_hits, constant<int>("2", 2)), "dz_vs_eta_B2");
  113. auto dz_vs_eta_B3 =
  114. fv::apply(calc_dz_vs_eta, fv::tuple(seeds, pixrec_hits, sim_hits, constant<int>("3", 3)), "dz_vs_eta_B3");
  115. auto dz_vs_eta_B4 =
  116. fv::apply(calc_dz_vs_eta, fv::tuple(seeds, pixrec_hits, sim_hits, constant<int>("4", 4)), "dz_vs_eta_B4");
  117. tds.register_container<ContainerTH2Many<float>>("dz_vs_eta_B1", "dz vs eta (BPIX L1)",
  118. dz_vs_eta_B1, 20, -0.01, .01, 20, -3, 3,
  119. "dz", "eta");
  120. tds.register_container<ContainerTH2Many<float>>("dz_vs_eta_B2", "dz vs eta (BPIX L2)",
  121. dz_vs_eta_B2, 20, -0.01, .01, 20, -3, 3,
  122. "dz", "eta");
  123. tds.register_container<ContainerTH2Many<float>>("dz_vs_eta_B3", "dz vs eta (BPIX L3)",
  124. dz_vs_eta_B3, 20, -0.01, .01, 20, -3, 3,
  125. "dz", "eta");
  126. tds.register_container<ContainerTH2Many<float>>("dz_vs_eta_B4", "dz vs eta (BPIX L4)",
  127. dz_vs_eta_B4, 20, -0.01, .01, 20, -3, 3,
  128. "dz", "eta");
  129. }
  130. void run_analysis(const std::string& input_filename, const std::string& data_label, bool silent){
  131. gSystem->Load("libfilval.so");
  132. auto replace_suffix = [](const std::string& input, const std::string& new_suffix){
  133. return input.substr(0, input.find_last_of(".")) + new_suffix;
  134. };
  135. string log_filename = replace_suffix(input_filename, "_result.log");
  136. fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogDebug);
  137. string output_filename = replace_suffix(input_filename, "_result.root");
  138. TrackingDataSet tds(output_filename, input_filename, data_label, "trackingNtuple/tree");
  139. register_objects(tds);
  140. setup_dz_vs_eta(tds);
  141. setup_dphi_vs_eta(tds);
  142. tds.process(silent);
  143. tds.save_all();
  144. }
  145. int main(int argc, char * argv[])
  146. {
  147. fv::util::ArgParser args(argc, argv);
  148. if(!args.cmdOptionExists("-l") || !args.cmdOptionExists("-f")) {
  149. cout << "Usage: ./main (-s) -l DATA_LABEL -f treefile.root" << endl;
  150. return -1;
  151. }
  152. bool silent = args.cmdOptionExists("-s");
  153. string input_filename = args.getCmdOption("-f");
  154. string data_label = args.getCmdOption("-l");
  155. run_analysis(input_filename, data_label, silent);
  156. }