sim_track_viz.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // Created by caleb on 3/26/18.
  3. //
  4. #include <iostream>
  5. #include <vector>
  6. #include <cmath>
  7. #include <TSystem.h>
  8. #include "filval.hpp"
  9. #include "root_filval.hpp"
  10. #include "analysis/TrackingNtupleObjs.hpp"
  11. #include <memory>
  12. #include <iostream>
  13. #include <string>
  14. #include <cstdio>
  15. template<typename ... Args>
  16. string fmt( const std::string& format, Args ... args ) {
  17. using namespace std;
  18. size_t size = snprintf( nullptr, 0, format.c_str(), args ... ) + 1; // Extra space for '\0'
  19. unique_ptr<char[]> buf( new char[ size ] );
  20. snprintf( buf.get(), size, format.c_str(), args ... );
  21. return string( buf.get(), buf.get() + size - 1 ); // We don't want the '\0' inside
  22. }
  23. SimTrackCollection sim_tracks;
  24. SimVertexCollection sim_vertices;
  25. void register_objects(TrackingDataSet& tds){
  26. sim_tracks.init(tds);
  27. sim_vertices.init(tds);
  28. }
  29. void run(bool silent) {
  30. using namespace std;
  31. using namespace fv;
  32. using namespace fv_root;
  33. auto file_list = the_config->get_source_files();
  34. string output_filename = the_config->get_output_filename();
  35. TrackingDataSet tds(output_filename, file_list, "trackingNtuple/tree");
  36. register_objects(tds);
  37. while (tds.next(!silent)) {
  38. auto print_vtx_pos = [](int vtx_idx) {
  39. const SimVertex vtx = sim_vertices[vtx_idx];
  40. cout << fmt("(%.3f, %.3f, %.3f)", vtx.x(), vtx.y(), vtx.z());
  41. };
  42. // cout << tds.get_current_event();
  43. for (const SimTrack sim_track : sim_tracks) {
  44. if (sim_track.decayVtxIdx().size() <= 1) continue;
  45. cout << fmt(" %d: %d \n", sim_track.pdgId(), sim_track.parentVtxIdx());
  46. for (const auto vtx_idx : sim_track.decayVtxIdx()) {
  47. cout << " " << vtx_idx ;
  48. print_vtx_pos(vtx_idx);
  49. cout << ": ";
  50. for (const auto simtrk_idx : sim_vertices[vtx_idx].sourceSimIdx())
  51. cout << sim_tracks[simtrk_idx].pdgId() << " ";
  52. cout << " -> " << vtx_idx << ": ";
  53. for (const auto simtrk_idx : sim_vertices[vtx_idx].daughterSimIdx())
  54. cout << sim_tracks[simtrk_idx].pdgId() << " ";
  55. cout << endl;
  56. }
  57. }
  58. }
  59. tds.save_all();
  60. }
  61. int main(int argc, char * argv[]){
  62. using namespace fv_util;
  63. ArgParser args(argc, argv);
  64. bool silent = args.cmd_option_exists("-s");
  65. if(args.cmd_option_exists("-c")) {
  66. init_config(args.get_cmd_option("-c"));
  67. args.update_config();
  68. init_log(LogPriority::kLogInfo);
  69. // gSystem->Load("libfilval.so");
  70. run(silent);
  71. } else {
  72. cout << "Usage: ./" << argv[0] << " (-s) -c config_file.yaml" << endl;
  73. }
  74. return 0;
  75. }