29
29
#include <algorithm>
32
35
#include "TCanvas.h"
34
37
#include "TApplication.h"
35
38
#include "TGClient.h"
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"
56
60
/** Access Tracker data using ROOT */
62
MAUS::SciFiSeed* ExtractSeed(MAUS::SciFiTrack* aTrack) {
63
MAUS::SciFiSeed* seed = aTrack->scifi_seed();
65
// std::cerr << "Empty seed pointer at: " << seed << std::endl;
67
TObject* seed_obj = aTrack->scifi_seed_tobject();
69
// std::cerr << "Empty seed TObject pointer" << std::endl;
71
if (!seed && !seed_obj) {
72
// std::cerr << "No seed pointer at all" << std::endl;
75
if (!seed && seed_obj) {
76
seed = dynamic_cast<MAUS::SciFiSeed*>(seed_obj); // NOLINT(runtime/rtti)
78
std::cerr << "Dynamic cast from SciFiSeed TObject failed" << std::endl;
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]);
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");
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";
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) {
103
std::cout << "Data is NULL\n";
106
MAUS::Spill* spill = data->GetSpill();
108
std::cout << "Spill is NULL\n";
111
if (spill->GetDaqEventType() != "physics_event") {
112
std::cout << "Spill is of type " << spill->GetDaqEventType() << ", not a usable spill\n";
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
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;
175
// Access the SciFiSeed associate with this track
176
MAUS::SciFiSeed* seed = ExtractSeed(trk);
178
std::cerr << "Failed to extract SciFiSeed\n";
182
// Access the PR track from the SciFiSeed in order to get at the spacepoints and clusters
183
TObject* pr_track_obj = seed->getPRTrackTobject();
185
std::cerr << "Empty PR track TObject pointer, skipping track" << std::endl;
188
MAUS::SciFiBasePRTrack* prtrk = static_cast<MAUS::SciFiBasePRTrack*>(pr_track_obj);
189
auto spnts = prtrk->get_spacepoints_pointers();
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;
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()) {
144
std::cout << "Empty cluster pointer, address " << clus << std::endl;
207
std::cerr << "Failed to find associated cluster\n";
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;