~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/common_cpp/Plotting/SciFi/TrackerDataManager.cc

  • Committer: Adam Dobbs
  • Date: 2017-09-20 15:24:49 UTC
  • mfrom: (659.2.72 release-candidate)
  • Revision ID: phuccj@gmail.com-20170920152449-fjpj92xb5q4wx6y5
Tags: MAUS-v3.0, MAUS-v3.0.0
MAUS-v3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
2
 
 *
3
 
 * MAUS is free software: you can redistribute it and/or modify
4
 
 * it under the terms of the GNU General Public License as published by
5
 
 * the Free Software Foundation, either version 3 of the License, or
6
 
 * (at your option) any later version.
7
 
 *
8
 
 * MAUS is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 */
17
 
 
18
 
// C++ headers
19
 
#include <iostream>
20
 
#include <iomanip>
21
 
#include <string>
22
 
 
23
 
// ROOT Headers
24
 
#include "TROOT.h"
25
 
 
26
 
// MAUS headers
27
 
#include "src/common_cpp/DataStructure/Hit.hh"
28
 
#include "src/common_cpp/DataStructure/SciFiEvent.hh"
29
 
#include "src/common_cpp/DataStructure/SciFiDigit.hh"
30
 
#include "src/common_cpp/DataStructure/SciFiCluster.hh"
31
 
#include "src/common_cpp/DataStructure/SciFiSpacePoint.hh"
32
 
#include "src/common_cpp/DataStructure/SciFiStraightPRTrack.hh"
33
 
#include "src/common_cpp/DataStructure/SciFiHelicalPRTrack.hh"
34
 
#include "src/common_cpp/DataStructure/ThreeVector.hh"
35
 
#include "src/common_cpp/Plotting/SciFi/TrackerDataManager.hh"
36
 
#include "src/common_cpp/Plotting/SciFi/TrackerDataPlotterXYZ.hh"
37
 
 
38
 
namespace MAUS {
39
 
 
40
 
TrackerDataManager::TrackerDataManager()
41
 
  : _print_tracks(false),
42
 
    _print_seeds(false) {
43
 
  // Do nothing
44
 
};
45
 
 
46
 
TrackerDataManager::~TrackerDataManager() {
47
 
  // Do nothing
48
 
};
49
 
 
50
 
void TrackerDataManager::process(const Spill *spill) {
51
 
  if (spill != NULL && spill->GetDaqEventType() == "physics_event") {
52
 
    if (_print_tracks || _print_seeds) std::cout << "TrackerDataManager: Opening spill "
53
 
      << spill->GetSpillNumber() << std::endl;
54
 
    // Loop over recon events
55
 
    for (size_t i = 0; i < spill->GetReconEvents()->size(); ++i) {
56
 
      _t1._spill_num = spill->GetSpillNumber();
57
 
      _t2._spill_num = spill->GetSpillNumber();
58
 
      // Process the SciFi data objects
59
 
      SciFiEvent *evt = (*spill->GetReconEvents())[i]->GetSciFiEvent();
60
 
      process_digits(spill, evt->digits());
61
 
      process_clusters(evt->clusters());
62
 
      process_spoints(evt->spacepoints());
63
 
      process_strks(evt->straightprtracks());
64
 
      process_htrks(evt->helicalprtracks());
65
 
    } // ~ loop over recon events
66
 
  } // ~ check event is a physics event
67
 
};
68
 
 
69
 
void TrackerDataManager::process_digits(const Spill *spill, const std::vector<SciFiDigit*> digits) {
70
 
  for (size_t i = 0; i < digits.size(); ++i) {
71
 
    SciFiDigit *dig = digits[i];
72
 
    if ( dig->get_tracker() == 0 ) {
73
 
      ++_t1._num_digits;
74
 
      _t1._num_events = spill->GetReconEvents()->size();
75
 
    } else if ( dig->get_tracker() == 1 ) {
76
 
      ++_t2._num_digits;
77
 
      _t2._num_events = spill->GetReconEvents()->size();
78
 
    }
79
 
  }
80
 
};
81
 
 
82
 
void TrackerDataManager::process_clusters(const std::vector<SciFiCluster*> clusters) {
83
 
  for (size_t i = 0; i < clusters.size(); ++i) {
84
 
    SciFiCluster *clus = clusters[i];
85
 
    if ( clus->get_tracker() == 0 ) {
86
 
      ++_t1._num_clusters;
87
 
    } else if ( clus->get_tracker() == 1 ) {
88
 
      ++_t2._num_clusters;
89
 
    }
90
 
  }
91
 
};
92
 
 
93
 
void TrackerDataManager::process_spoints(const std::vector<SciFiSpacePoint*> spoints) {
94
 
  for (size_t i = 0; i < spoints.size(); ++i) {
95
 
    SciFiSpacePoint *sp = spoints[i];
96
 
    ThreeVector pos = sp->get_position();
97
 
    if ( sp->get_tracker() == 0 ) {
98
 
      ++_t1._num_spoints;
99
 
      _t1._spoints_x.push_back(pos.x());
100
 
      _t1._spoints_y.push_back(pos.y());
101
 
      _t1._spoints_z.push_back(pos.z());
102
 
    } else if ( sp->get_tracker() == 1 ) {
103
 
      ++_t2._num_spoints;
104
 
      _t2._spoints_x.push_back(pos.x());
105
 
      _t2._spoints_y.push_back(pos.y());
106
 
      _t2._spoints_z.push_back(pos.z());
107
 
    }
108
 
  }
109
 
};
110
 
 
111
 
void TrackerDataManager::process_strks(const std::vector<SciFiStraightPRTrack*> strks) {
112
 
  for (size_t i = 0; i < strks.size(); ++i) {
113
 
    SciFiStraightPRTrack *trk = strks[i];
114
 
    if ( trk->get_tracker() == 0 ) {
115
 
      if ( trk->get_num_points() == 5 ) ++_t1._num_stracks_5pt;
116
 
      if ( trk->get_num_points() == 4 ) ++_t1._num_stracks_4pt;
117
 
      if ( trk->get_num_points() == 3 ) ++_t1._num_stracks_3pt;
118
 
      _t1._trks_str_xz.push_back(make_str_track(trk->get_x0(), trk->get_mx(), _zmin, _zmax));
119
 
      _t1._trks_str_yz.push_back(make_str_track(trk->get_y0(), trk->get_my(), _zmin, _zmax));
120
 
    } else if ( trk->get_tracker() == 1 ) {
121
 
      if ( trk->get_num_points() == 5 ) ++_t2._num_stracks_5pt;
122
 
      if ( trk->get_num_points() == 4 ) ++_t2._num_stracks_4pt;
123
 
      if ( trk->get_num_points() == 3 ) ++_t2._num_stracks_3pt;
124
 
      _t2._trks_str_xz.push_back(make_str_track(trk->get_x0(), trk->get_mx(), _zmin, _zmax));
125
 
      _t2._trks_str_yz.push_back(make_str_track(trk->get_y0(), trk->get_my(), _zmin, _zmax));
126
 
    }
127
 
  }
128
 
};
129
 
 
130
 
void TrackerDataManager::process_htrks(const std::vector<SciFiHelicalPRTrack*> htrks) {
131
 
  for (size_t i = 0; i < htrks.size(); ++i) {
132
 
    SciFiHelicalPRTrack *trk = htrks[i];
133
 
 
134
 
    // Print track info to screen
135
 
    if (_print_tracks) print_track_info(trk, i);
136
 
 
137
 
    // Pull out turning angles for each track seed
138
 
    std::vector<double> phi_i;
139
 
    std::vector<double> s_i;
140
 
    for ( size_t i = 0; i < trk->get_phi().size(); ++i ) {
141
 
      phi_i.push_back(trk->get_phi()[i]);
142
 
      s_i.push_back(trk->get_phi()[i]*trk->get_R());
143
 
    }
144
 
 
145
 
    // Pull out the z coord for each track seed
146
 
    std::vector<double> z_i;
147
 
    for ( int i = 0; i < (trk->get_spacepoints()->GetLast()+1); ++i ) {
148
 
      z_i.push_back(
149
 
        static_cast<SciFiSpacePoint*>(trk->get_spacepoints()->At(i))->get_position().z());
150
 
    }
151
 
 
152
 
    double x0 = trk->get_circle_x0();
153
 
    double y0 = trk->get_circle_y0();
154
 
    double rad = trk->get_R();
155
 
    double dsdz = trk->get_dsdz();
156
 
    double sz_c = trk->get_line_sz_c();
157
 
    int handness = -1;
158
 
 
159
 
    if ( trk->get_tracker() == 0 ) {
160
 
      if ( trk->get_num_points() == 5 ) ++_t1._num_htracks_5pt;
161
 
      if ( trk->get_num_points() == 4 ) ++_t1._num_htracks_4pt;
162
 
      if ( trk->get_num_points() == 3 ) ++_t1._num_htracks_3pt;
163
 
      if ( trk->get_charge() == 1 ) ++_t1._num_pos_tracks;
164
 
      if ( trk->get_charge() == -1 ) ++_t1._num_neg_tracks;
165
 
      _t1._seeds_z.push_back(z_i);
166
 
      _t1._seeds_phi.push_back(phi_i);
167
 
      _t1._seeds_s.push_back(s_i);
168
 
      _t1._trks_xy.push_back(make_circle(x0, y0, rad));
169
 
      // dsdz = - dsdz;  // Needed due to the way we plot...
170
 
      _t1._trks_xz.push_back(make_xz(handness, x0, rad, dsdz, sz_c, _zmin, _zmax));
171
 
      _t1._trks_yz.push_back(make_yz(y0, rad, dsdz, sz_c, _zmin, _zmax));
172
 
      _t1._trks_sz.push_back(make_str_track(sz_c, dsdz, _zmin, _zmax));
173
 
    } else if ( trk->get_tracker() == 1 ) {
174
 
      if ( trk->get_num_points() == 5 ) ++_t2._num_htracks_5pt;
175
 
      if ( trk->get_num_points() == 4 ) ++_t2._num_htracks_4pt;
176
 
      if ( trk->get_num_points() == 3 ) ++_t2._num_htracks_3pt;
177
 
      if ( trk->get_charge() == 1 ) ++_t2._num_pos_tracks;
178
 
      if ( trk->get_charge() == -1 ) ++_t2._num_neg_tracks;
179
 
      _t2._seeds_z.push_back(z_i);
180
 
      _t2._seeds_phi.push_back(phi_i);
181
 
      _t2._seeds_s.push_back(s_i);
182
 
      _t2._trks_xy.push_back(make_circle(x0, y0, rad));
183
 
      _t2._trks_xz.push_back(make_xz(handness, x0, rad, dsdz, sz_c, _zmin, _zmax));
184
 
      _t2._trks_yz.push_back(make_yz(y0, rad, dsdz, sz_c, _zmin, _zmax));
185
 
      _t2._trks_sz.push_back(make_str_track(sz_c, dsdz, _zmin, _zmax));
186
 
    }
187
 
 
188
 
    // Loop over track seed spacepoints
189
 
//     if (_print_seeds) {
190
 
//       std::cout << "x\ty\tz\ttime\t\tphi\tpx_mc\tpy_mc\tpt_mc\tpz_mc\t";
191
 
//       std::cout << "px_mc1\tpx_mc2\tpx_mc3\tpy_mc1\tpy_mc2\tpy_mc3\tpz_mc1\tpz_mc2\tpz_mc3\n";
192
 
//     }
193
 
 
194
 
    for ( int j = 0; j < (trk->get_spacepoints()->GetLast()+1); ++j ) {
195
 
      if ( trk->get_tracker() == 0 ) ++_t1._num_seeds;
196
 
      if ( trk->get_tracker() == 1 ) ++_t2._num_seeds;
197
 
      // if (_print_seeds) print_seed_info(trk, j);
198
 
    }
199
 
  }  // ~loop over helical tracks
200
 
};
201
 
 
202
 
void TrackerDataManager::clear_spill() {
203
 
  _t1.clear();
204
 
  _t2.clear();
205
 
};
206
 
 
207
 
void TrackerDataManager::draw(std::vector<TrackerDataPlotterBase*> plotters) {
208
 
  // Loop over all the plotters and draw
209
 
  TCanvas* lCanvas = NULL;
210
 
  for ( size_t i = 0; i < plotters.size(); ++i ) {
211
 
    TrackerDataPlotterBase * plt = plotters[i];
212
 
    if (plt) {
213
 
      lCanvas = (*plt)(_t1, _t2);
214
 
      if (plt->GetSaveOutput()) {
215
 
        std::string fName = plt->GetOutputName();
216
 
        lCanvas->SaveAs(fName.c_str());
217
 
      }
218
 
    } else {
219
 
      std::cerr << "Error: Empty plotter pointer passed\n";
220
 
    }
221
 
  }
222
 
};
223
 
 
224
 
TArc TrackerDataManager::make_circle(double x0, double y0, double rad) {
225
 
  TArc arc = TArc(x0, y0, rad);
226
 
  arc.SetFillStyle(0); // 0 - Transparent
227
 
  arc.SetLineColor(kBlue);
228
 
  return arc;
229
 
};
230
 
 
231
 
TF1 TrackerDataManager::make_str_track(double c, double m, double zmin, double zmax) {
232
 
  // Note: in the function expression, x is just the independent variable, which
233
 
  // in this case is the z coordinate in the tracker coordinate system
234
 
  TF1 trk = TF1("trk", "[0]+([1]*x)", zmin, zmax);
235
 
  trk.SetParameters(c, m);
236
 
  trk.SetLineColor(kRed);
237
 
  return trk;
238
 
};
239
 
 
240
 
TF1 TrackerDataManager::make_xz(int handness, double circle_x0, double rad, double dsdz,
241
 
                                double sz_c, double zmin, double zmax) {
242
 
    // The x in the cos term is actually representing z (the indep variable)
243
 
    TF1 func = TF1("xz_func", "[0]-[4]*([1]*cos((1/[1])*([2]*x+[3])))", zmin, zmax);
244
 
    func.SetParameter(0, circle_x0);
245
 
    func.SetParameter(1, rad);
246
 
    func.SetParameter(2, dsdz);
247
 
    func.SetParameter(3, sz_c);
248
 
    func.SetParameter(4, handness);
249
 
    func.SetLineColor(kBlue);
250
 
    return func;
251
 
};
252
 
 
253
 
TF1 TrackerDataManager::make_yz(double circle_y0, double rad, double dsdz,
254
 
                                double sz_c, double zmin, double zmax) {
255
 
    // The x in the cos term is actually representing z (the indep variable)
256
 
    TF1 func = TF1("yz_func", "[0]+([1]*sin((1/[1])*([2]*x+[3])))", zmin, zmax);
257
 
    func.SetParameter(0, circle_y0);
258
 
    func.SetParameter(1, rad);
259
 
    func.SetParameter(2, dsdz);
260
 
    func.SetParameter(3, sz_c);
261
 
    func.SetLineColor(kBlue);
262
 
    return func;
263
 
};
264
 
 
265
 
void TrackerDataManager::print_track_info(const SciFiHelicalPRTrack * const trk, int trk_num) {
266
 
  double rad = trk->get_R();
267
 
  double pt = rad * _RtoPt;
268
 
  double pz = pt / trk->get_dsdz();
269
 
  std::cout << "Tracker " << trk->get_tracker() << + ", ";
270
 
  std::cout << "Track " << trk_num << ", ";
271
 
  std::cout << "Num points " << trk->get_num_points() << ", ";
272
 
  std::cout << "Charge " << trk->get_charge() << ", ";
273
 
  std::cout << "R = " << std::setprecision(4) << trk->get_R() << "mm, ";
274
 
  std::cout << "X0 = " << std::setprecision(4) << trk->get_circle_x0() << "mm, ";
275
 
  std::cout << "Y0 = " <<  std::setprecision(4) << trk->get_circle_y0() << "mm,\n";
276
 
  std::cout << "dsdz " <<  std::setprecision(4) << trk->get_dsdz() << ", ";
277
 
  std::cout << "pt = " <<  std::setprecision(4) << pt << "MeV/c, ";
278
 
  std::cout << "pz = " <<  std::setprecision(4) << pz << "MeV/c, ";
279
 
  std::cout << "xy_chi2 = " << std::setprecision(4) << trk->get_circle_chisq() << ", ";
280
 
  std::cout << "sz_c = " << std::setprecision(4) << trk->get_line_sz_c() << ", ";
281
 
  std::cout << "sz_chi2 = " << std::setprecision(4) << trk->get_line_sz_chisq() << "\n";
282
 
};
283
 
 
284
 
// void TrackerDataManager::print_seed_info(const SciFiHelicalPRTrack * const trk, int seed_num) {
285
 
//   SciFiSpacePoint* sp = static_cast<SciFiSpacePoint*>(trk->get_spacepoints()->At(seed_num));
286
 
//   MAUS::ThreeVector pos = sp->get_position();
287
 
//   std::vector<MAUS::SciFiCluster*> chans = sp->get_channels_pointers();
288
 
//   double t = sp->get_time();
289
 
//
290
 
//   double seed_px_mc = 0.0;
291
 
//   double seed_py_mc = 0.0;
292
 
//   double seed_pz_mc = 0.0;
293
 
//   double px_mc1 = 0.0;
294
 
//   double px_mc2 = 0.0;
295
 
//   double px_mc3 = 0.0;
296
 
//   double py_mc1 = 0.0;
297
 
//   double py_mc2 = 0.0;
298
 
//   double py_mc3 = 0.0;
299
 
//   double pz_mc1 = 0.0;
300
 
//   double pz_mc2 = 0.0;
301
 
//   double pz_mc3 = 0.0;
302
 
//   for (size_t iCl = 0; iCl < chans.size(); ++iCl) {
303
 
//     ThreeVector p_mc = chans[iCl]->get_true_momentum();
304
 
//     seed_px_mc += p_mc.x();
305
 
//     seed_py_mc += p_mc.y();
306
 
//     seed_pz_mc += p_mc.z();
307
 
//     if (iCl == 0) {
308
 
//       px_mc1 = p_mc.x();
309
 
//       py_mc1 = p_mc.y();
310
 
//       pz_mc1 = p_mc.z();
311
 
//     }
312
 
//     if (iCl == 1) {
313
 
//       px_mc2 = p_mc.x();
314
 
//       py_mc2 = p_mc.y();
315
 
//       pz_mc2 = p_mc.z();
316
 
//     }
317
 
//     if (iCl == 2) {
318
 
//       px_mc3 = p_mc.x();
319
 
//       py_mc3 = p_mc.y();
320
 
//       pz_mc3 = p_mc.z();
321
 
//     }
322
 
//   }
323
 
//   seed_px_mc /= chans.size();
324
 
//   seed_py_mc /= chans.size();
325
 
//   seed_pz_mc /= chans.size();
326
 
//   double pt_mc = sqrt(seed_px_mc*seed_px_mc + seed_py_mc*seed_py_mc);
327
 
//
328
 
//   std::cout << std::setprecision(4) << pos.x() << "\t";
329
 
//   std::cout << std::setprecision(4) << pos.y() << "\t";
330
 
//   std::cout << std::setprecision(4) << pos.z() << "\t";
331
 
//   std::cout << std::setprecision(12) << t << "\t";
332
 
//   std::cout << std::setprecision(4) << trk->get_phi()[seed_num] << "\t";
333
 
//   std::cout << std::setprecision(4) << seed_px_mc << "\t";
334
 
//   std::cout << std::setprecision(4) << seed_py_mc << "\t";
335
 
//   std::cout << std::setprecision(4) << pt_mc << "\t";
336
 
//   std::cout << std::setprecision(4) << seed_pz_mc << "\t";
337
 
//   std::cout << std::setprecision(4) << px_mc1 << "\t";
338
 
//   std::cout << std::setprecision(4) << px_mc2 << "\t";
339
 
//   std::cout << std::setprecision(4) << px_mc3 << "\t";
340
 
//   std::cout << std::setprecision(4) << py_mc1 << "\t";
341
 
//   std::cout << std::setprecision(4) << py_mc2 << "\t";
342
 
//   std::cout << std::setprecision(4) << py_mc3 << "\t";
343
 
//   std::cout << std::setprecision(4) << pz_mc1 << "\t";
344
 
//   std::cout << std::setprecision(4) << pz_mc2 << "\t";
345
 
//   std::cout << std::setprecision(4) << pz_mc3 << "\n";
346
 
// };
347
 
 
348
 
} // ~namespace MAUS