~chris-rogers/maus/emr_mc_digitization

« back to all changes in this revision

Viewing changes to bin/user/scifi/cpp/scifi_offline_viewer.cc

  • Committer: Chris Rogers
  • Date: 2014-04-16 11:48:45 UTC
  • mfrom: (707 merge)
  • mto: This revision was merged to the branch mainline in revision 711.
  • Revision ID: chris.rogers@stfc.ac.uk-20140416114845-h3u3q7pdcxkxvovs
Update to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <iomanip>
23
23
#include <fstream>
24
24
#include <sstream>
 
25
#include <string>
25
26
#include <cmath>
26
27
 
27
28
// ROOT headers
31
32
#include "TGClient.h"
32
33
 
33
34
// MAUS headers
34
 
#include "src/common_cpp/Recon/SciFi/TrackerData.hh"
35
 
#include "src/common_cpp/Recon/SciFi/TrackerDataManager.hh"
36
 
#include "src/common_cpp/Recon/SciFi/TrackerDataPlotterBase.hh"
37
 
#include "src/common_cpp/Recon/SciFi/TrackerDataPlotterSpoints.hh"
38
 
#include "src/common_cpp/Recon/SciFi/TrackerDataPlotterXYZ.hh"
39
 
#include "src/common_cpp/Recon/SciFi/TrackerDataPlotterSZ.hh"
40
 
#include "src/common_cpp/Recon/SciFi/TrackerDataPlotterInfoBox.hh"
 
35
#include "src/common_cpp/Plotting/SciFi/TrackerData.hh"
 
36
#include "src/common_cpp/Plotting/SciFi/TrackerDataManager.hh"
 
37
#include "src/common_cpp/Plotting/SciFi/TrackerDataPlotterBase.hh"
 
38
#include "src/common_cpp/Plotting/SciFi/TrackerDataPlotterSpoints.hh"
 
39
#include "src/common_cpp/Plotting/SciFi/TrackerDataPlotterXYZ.hh"
 
40
#include "src/common_cpp/Plotting/SciFi/TrackerDataPlotterSZ.hh"
 
41
#include "src/common_cpp/Plotting/SciFi/TrackerDataPlotterInfoBox.hh"
41
42
 
42
43
#include "src/common_cpp/DataStructure/Spill.hh"
43
44
#include "src/common_cpp/DataStructure/Data.hh"
52
53
  // First argument to code should be the input ROOT file name
53
54
  std::string filename = std::string(argv[1]);
54
55
 
55
 
  // Check if the user wants to pause between evts, indicated by making second argument to code "1"
56
 
  std::string str_pause;
 
56
  // Parse any extra arguments supplied
 
57
  //   -p -> pause between spills
 
58
  //   -w -> wait for input milliseconds between spills
 
59
  //   -g -> enables saving xyz plots and gives output graphics file type
 
60
  //   -f -> select the first tree entry to start from
57
61
  bool bool_pause = false;
58
 
  if (argc > 2) {
59
 
    std::string s1 = std::string(argv[2]);
60
 
    if (s1 == "1") bool_pause = true;
 
62
  bool bool_save = false;
 
63
 
 
64
  std::string save_type = "";
 
65
  int start_num = 0;
 
66
  int wait_time = 0;
 
67
 
 
68
  for (int i = 2; i < argc; i++) {
 
69
    if ( std::strcmp(argv[i], "-f") == 0 ) {
 
70
      if ( (i+1) < argc ) {
 
71
        std::stringstream ss1;
 
72
        ss1 << argv[i + 1];
 
73
        ss1 >> start_num;
 
74
        std::cout << "Starting from entry: " << start_num << std::endl;
 
75
      }
 
76
    }
 
77
    if ( std::strcmp(argv[i], "-w") == 0 ) {
 
78
      if ( (i+1) < argc ) {
 
79
        std::stringstream ss1;
 
80
        ss1 << argv[i + 1];
 
81
        ss1 >> wait_time;
 
82
        std::cout << "Waiting " << wait_time << " milliseconds between events" << std::endl;
 
83
      }
 
84
    }
 
85
    if ( std::strcmp(argv[i], "-p") == 0 ) {
 
86
      std::cout << "Will wait for user input between spills\n";
 
87
      bool_pause = true;
 
88
    } else if ( std::strcmp(argv[i], "-g") == 0 ) {
 
89
      if ( (i+1) < argc ) save_type = argv[i + 1];
 
90
      if ( (save_type == "eps") || (save_type == "pdf") || (save_type == "png") ) {
 
91
        std::cout << "Saving plots as " << save_type << " files.\n";
 
92
        bool_save = true;
 
93
      } else {
 
94
        std::cerr << "Invalid graphics output type given\n";
 
95
      }
 
96
    }
61
97
  }
62
98
 
63
 
  // Some set up
64
 
  TApplication theApp("App", &argc, argv);
65
 
  std::cout << "Opening file " << filename << std::endl;
66
 
  MAUS::Data data;
67
 
  irstream infile(filename.c_str(), "Spill");
68
 
 
69
99
  // Set up the data manager and plotters
70
100
  MAUS::TrackerDataManager tdm;
 
101
  tdm.set_print_tracks(true);
 
102
  tdm.set_print_seeds(true);
71
103
  MAUS::TrackerDataPlotterBase *xyzPlotter = new MAUS::TrackerDataPlotterXYZ();
 
104
  if (bool_save) {
 
105
    xyzPlotter->SetSaveOutput(true);
 
106
    xyzPlotter->SetOutputName("xyzPlotterOutput." + save_type);
 
107
  }
72
108
  MAUS::TrackerDataPlotterBase *szPlotter = new MAUS::TrackerDataPlotterSZ();
73
109
  MAUS::TrackerDataPlotterBase *infoBoxPlotter
74
 
                                  = new MAUS::TrackerDataPlotterInfoBox(275, 600, 0.585, 0.93);
 
110
                                  = new MAUS::TrackerDataPlotterInfoBox(300, 750, 0.585, 0.945);
75
111
  std::vector<MAUS::TrackerDataPlotterBase*> plotters;
76
112
  plotters.push_back(xyzPlotter);
77
113
  plotters.push_back(szPlotter);
78
114
  plotters.push_back(infoBoxPlotter);
79
115
 
80
 
  // Loop over all events
81
 
  while (infile >> readEvent != NULL) {
 
116
  // Set up ROOT app, input file, and MAUS data class
 
117
  TApplication theApp("App", &argc, argv);
 
118
  std::cout << "Opening file " << filename << std::endl;
 
119
  irstream infile(filename.c_str(), "Spill");
 
120
  MAUS::Data data;
 
121
 
 
122
  // Loop over all spills
 
123
  if (start_num > 0) infile.set_current_event(start_num);
 
124
  while ( infile >> readEvent != NULL ) {
82
125
    infile >> branchName("data") >> data;
83
126
    MAUS::Spill* spill = data.GetSpill();
84
127
    if (spill != NULL && spill->GetDaqEventType() == "physics_event") {
88
131
        std::cout << "Press Enter to Continue";
89
132
        std::cin.ignore();
90
133
      }
 
134
      tdm.clear_spill();
 
135
    } else {
 
136
      std::cout << "Not a usable spill\n";
91
137
    }
92
 
    tdm.clear_spill();
 
138
    usleep(wait_time*1000);
93
139
  }
94
140
 
95
141
  // Tidy up
96
142
  delete xyzPlotter;
97
143
  delete infoBoxPlotter;
 
144
  delete szPlotter;
98
145
  infile.close();
99
146
  theApp.Run();
100
147
}
 
148