~mfedorov/maus/cut_datastructure_2

« back to all changes in this revision

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

  • Committer: Misha Fedorov
  • Date: 2017-07-21 15:11:20 UTC
  • mfrom: (697.161.37 merge)
  • Revision ID: misha.fedorov@hotmail.com-20170721151120-8g9kv9sz9jc3mo2i
print statements in tof_mc_plotter.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <algorithm>
30
30
 
31
31
// ROOT headers
 
32
#include "TObject.h"
 
33
#include "TFile.h"
 
34
#include "TTree.h"
32
35
#include "TCanvas.h"
33
36
#include "TF1.h"
34
37
#include "TApplication.h"
35
38
#include "TGClient.h"
36
39
 
37
 
#include "src/common_cpp/JsonCppStreamer/IRStream.hh"
38
40
#include "src/common_cpp/DataStructure/Spill.hh"
39
41
#include "src/common_cpp/DataStructure/Data.hh"
40
42
#include "src/common_cpp/DataStructure/ReconEvent.hh"
41
43
#include "src/common_cpp/DataStructure/MCEvent.hh"
42
44
#include "src/common_cpp/DataStructure/SciFiEvent.hh"
43
45
#include "src/common_cpp/DataStructure/SciFiTrack.hh"
 
46
#include "src/common_cpp/DataStructure/SciFiSeed.hh"
44
47
#include "src/common_cpp/DataStructure/SciFiTrackPoint.hh"
 
48
#include "src/common_cpp/DataStructure/SciFiBasePRTrack.hh"
45
49
#include "src/common_cpp/DataStructure/SciFiHelicalPRTrack.hh"
46
50
#include "src/common_cpp/DataStructure/SciFiSpacePoint.hh"
47
51
#include "src/common_cpp/DataStructure/SciFiCluster.hh"
55
59
 
56
60
/** Access Tracker data using ROOT */
57
61
 
 
62
MAUS::SciFiSeed* ExtractSeed(MAUS::SciFiTrack* aTrack) {
 
63
  MAUS::SciFiSeed* seed = aTrack->scifi_seed();
 
64
  if (!seed) {
 
65
    // std::cerr << "Empty seed pointer at: " << seed << std::endl;
 
66
  }
 
67
  TObject* seed_obj = aTrack->scifi_seed_tobject();
 
68
  if (!seed_obj) {
 
69
    // std::cerr << "Empty seed TObject pointer" << std::endl;
 
70
  }
 
71
  if (!seed && !seed_obj) {
 
72
    // std::cerr << "No seed pointer at all" << std::endl;
 
73
    return NULL;
 
74
  }
 
75
  if (!seed && seed_obj) {
 
76
    seed = dynamic_cast<MAUS::SciFiSeed*>(seed_obj); // NOLINT(runtime/rtti)
 
77
    if (!seed) {
 
78
      std::cerr << "Dynamic cast from SciFiSeed TObject failed" << std::endl;
 
79
      return NULL;
 
80
    }
 
81
  }
 
82
  return seed;
 
83
}
 
84
 
58
85
int main(int argc, char *argv[]) {
59
86
  // First argument to code should be the input ROOT file name
60
87
  std::string filename = std::string(argv[1]);
61
88
 
62
89
  // Set up ROOT app, input file, and MAUS data class
63
 
  TApplication theApp("App", &argc, argv);
 
90
  // TApplication theApp("App", &argc, argv);
64
91
  std::cout << "Opening file " << filename << std::endl;
65
 
  irstream infile(filename.c_str(), "Spill");
66
 
  MAUS::Data data;
 
92
  TFile f1(filename.c_str());
 
93
  TTree* T = static_cast<TTree*>(f1.Get("Spill"));
 
94
  MAUS::Data* data = NULL;  // Don't forget = NULL or you get a seg fault
 
95
  T->SetBranchAddress("data", &data); // Yes, this is the *address* of a *pointer*
 
96
  int nentries = T->GetEntries();
 
97
  std::cerr << "Found " << nentries << " spills\n";
67
98
 
68
99
  // Loop over all spills
69
 
  while ( infile >> readEvent != NULL ) {
70
 
    infile >> branchName("data") >> data;
71
 
    MAUS::Spill* spill = data.GetSpill();
72
 
    if (spill == NULL || spill->GetDaqEventType() != "physics_event") {
73
 
      std::cout << "Not a usable spill\n";
 
100
  for (int i = 0; i < nentries; ++i) {
 
101
    T->GetEntry(i);
 
102
    if (!data) {
 
103
      std::cout << "Data is NULL\n";
 
104
      continue;
 
105
    }
 
106
    MAUS::Spill* spill = data->GetSpill();
 
107
    if (spill == NULL) {
 
108
      std::cout << "Spill is NULL\n";
 
109
      continue;
 
110
    }
 
111
    if (spill->GetDaqEventType() != "physics_event") {
 
112
      std::cout << "Spill is of type " << spill->GetDaqEventType() << ", not a usable spill\n";
74
113
      continue;
75
114
    }
76
115
 
121
160
              for ( hit = hits.begin(); hit != hits.end(); ++hit ) {
122
161
                // Print the MC track ID
123
162
                int track_id = (*hit)->GetTrackId();
124
 
                std::cout << "track_id: " << track_id << std::endl;
 
163
                // std::cout << "track_id: " << track_id << std::endl;
125
164
              } // ~Loop over associated MC hits
126
165
            } // ~Loop over associated digits
127
166
          } // ~Loop over associated clusters
130
169
 
131
170
      // Loop over kalman tracks
132
171
      std::vector<MAUS::SciFiTrack*> trks = sfevt->scifitracks();
133
 
      std::vector<MAUS::SciFiTrack*>::iterator trk;
134
 
      for ( trk = trks.begin(); trk != trks.end(); ++trk ) {
135
 
        std::cout << "  SciFi Track chi_sq: " << (*trk)->chi2() << std::endl;
136
 
        std::vector<MAUS::SciFiTrackPoint*> tpnts = (*trk)->scifitrackpoints();
137
 
        std::vector<MAUS::SciFiTrackPoint*>::iterator tpnt;
 
172
      for (auto trk : sfevt->scifitracks())  {
 
173
        std::cout << "  SciFi Track chi_sq: " << trk->chi2() << std::endl;
 
174
 
 
175
        // Access the SciFiSeed associate with this track
 
176
        MAUS::SciFiSeed* seed = ExtractSeed(trk);
 
177
        if (!seed) {
 
178
          std::cerr << "Failed to extract SciFiSeed\n";
 
179
          continue;
 
180
        }
 
181
 
 
182
        // Access the PR track from the SciFiSeed in order to get at the spacepoints and clusters
 
183
        TObject* pr_track_obj = seed->getPRTrackTobject();
 
184
        if (!pr_track_obj) {
 
185
          std::cerr << "Empty PR track TObject pointer, skipping track" << std::endl;
 
186
          continue;
 
187
        }
 
188
        MAUS::SciFiBasePRTrack* prtrk = static_cast<MAUS::SciFiBasePRTrack*>(pr_track_obj);
 
189
        auto spnts = prtrk->get_spacepoints_pointers();
 
190
 
138
191
        // Loop over associated trackpoints
139
 
        for ( tpnt = tpnts.begin(); tpnt != tpnts.end(); ++tpnt ) {
140
 
          std::cout << "    SciFi TrackPoint chi_sq: " << (*tpnt)->chi2() << std::endl;
 
192
        for (auto tpnt : trk->scifitrackpoints()) {
 
193
          std::cout << "    SciFi TrackPoint chi_sq: " << tpnt->chi2() << std::endl;
 
194
 
141
195
          // Pull out the associated cluster
142
 
          MAUS::SciFiCluster* clus = (*tpnt)->get_cluster_pointer();
 
196
          MAUS::SciFiCluster* clus = nullptr;
 
197
          for (auto sp : spnts) {
 
198
            if (sp->get_station() == tpnt->station()) {
 
199
              for (auto lclus : sp->get_channels_pointers()) {
 
200
                if (clus->get_plane() == tpnt->plane()) {
 
201
                  clus = lclus;
 
202
                }
 
203
              }
 
204
            }
 
205
          }
143
206
          if (!clus) {
144
 
            std::cout << "Empty cluster pointer, address " << clus  << std::endl;
 
207
            std::cerr << "Failed to find associated cluster\n";
145
208
            continue;
146
209
          }
 
210
 
147
211
          // Loop over associated digits
148
212
          std::vector<MAUS::SciFiDigit*> digits = clus->get_digits_pointers();
149
213
          std::vector<MAUS::SciFiDigit*>::iterator dig;
166
230
      } // ~Loop over kalman tracks
167
231
    } // ~Loop over MC events
168
232
  } // ~Loop over all spills
169
 
  theApp.Run();
 
233
  // theApp.Run();
170
234
}
171