~e-santos10/maus/devel

« back to all changes in this revision

Viewing changes to src/common_cpp/Recon/SciFi/PatternRecognition.cc

  • Committer: Edward Santos
  • Date: 2014-01-27 12:08:22 UTC
  • mfrom: (1034.3.37 tracker_devel)
  • Revision ID: e.santos10@imperial.ac.uk-20140127120822-8pr90w50mwcfzwob
merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
}
50
50
 
51
51
PatternRecognition::PatternRecognition(): _verb(0),
52
 
                                          _lsq(_sd_1to4, _sd_5, _R_res_cut),
53
 
                                          _f_res(NULL),
54
 
                                          _f_res_good(NULL),
55
 
                                          _f_res_chosen(NULL),
56
 
                                          _f_trks(NULL) {
 
52
                                          _lsq(_sd_1to4, _sd_5, _R_res_cut) {
57
53
  // Do nothing;
58
 
};
 
54
}
59
55
 
60
56
PatternRecognition::~PatternRecognition() {
61
 
  if ( _f_res ) {
62
 
    _f_res->close();
63
 
    delete _f_res;
64
 
    _f_res = NULL;
65
 
  }
66
 
  if ( _f_res_good ) {
67
 
    _f_res_good->close();
68
 
    delete _f_res_good;
69
 
    _f_res_good = NULL;
70
 
  }
71
 
  if ( _f_res_chosen ) {
72
 
    _f_res_chosen->close();
73
 
    delete  _f_res_chosen;
74
 
    _f_res_chosen = NULL;
75
 
  }
76
 
  if ( _f_trks ) {
77
 
    _f_trks->close();
78
 
    delete _f_trks;
79
 
    _f_trks = NULL;
80
 
  }
81
 
}
82
 
 
83
 
void PatternRecognition::initialise_residual_files() {
84
 
  _verb = 2;
85
 
  _f_res = new ofstream();
86
 
  _f_res->open("residuals.dat", std::ios::app);
87
 
  _f_res_good = new ofstream();
88
 
  _f_res_good->open("residuals_good.dat", std::ios::app);
89
 
  _f_res_chosen = new ofstream();
90
 
  _f_res_chosen->open("residuals_chosen.dat", std::ios::app);
91
 
  _f_trks = new ofstream();
92
 
  _f_trks->open("tracks.dat", std::ios::app);
 
57
  // Do nothing
93
58
}
94
59
 
95
60
void PatternRecognition::process(const bool helical_pr_on, const bool straight_pr_on,
121
86
        make_all_tracks(track_type, trker_no, spnts_by_station, evt);
122
87
      }
123
88
    }// ~Loop over trackers
124
 
    /*
125
 
    std::cout << "Number of straight tracks found: " << evt.straightprtracks().size() << "\n\n";
126
 
    std::cout << "Number of helical tracks found: " << evt.helicalprtracks().size() << "\n\n";
127
 
    */
128
89
  } else {
129
90
    if (_verb > 0) std::cerr << "No spacepoints in event" << std::endl;
130
91
  }
391
352
 
392
353
            // If the spacepoint has not already been used in a track fit
393
354
            if ( !spnts_by_station[st_num][sp_no]->get_used() ) {
394
 
              SciFiSpacePoint *sp = spnts_by_station[st_num][sp_no];
 
355
              // Apply roadcuts & find the spoints with the smallest residuals for the line
395
356
              double dx = 0, dy = 0;
396
 
              SciFiTools::calc_straight_residual(sp, line_x, line_y, dx, dy);
397
 
              if ( _verb > 1 ) {
398
 
                *_f_res << trker_no << "\t" << st_num << "\t" << n_points << "\t";
399
 
                *_f_res << dx << "\t" << dy << "\n";
400
 
              }
401
 
 
402
 
              // Apply roadcuts & find the spoints with the smallest residuals for the line
403
357
              if ( fabs(dx) < _res_cut && fabs(dy) < _res_cut )  {
404
 
                if ( _verb > 1 ) {
405
 
                  *_f_res_good << trker_no << "\t" << st_num << "\t" << n_points << "\t";
406
 
                  *_f_res_good << dx << "\t" << dy << "\n";
407
 
                }
408
 
                if ( delta_sq > (dx*dx + dy*dy) )
 
358
                if ( delta_sq > (dx*dx + dy*dy) ) {
409
359
                  delta_sq = dx*dx + dy*dy;
410
360
                  best_sp = sp_no;
411
 
                // add_residuals(true, dx, dy, residuals);
 
361
                }
412
362
              } // ~If pass roadcuts and beats previous best fit point
413
363
            } // ~If spacepoint is unused
414
364
          } // ~Loop over spacepoints
416
366
          if (best_sp > -1) {
417
367
            SciFiSpacePoint * sp = spnts_by_station[st_num][best_sp];
418
368
            good_spnts.push_back(sp);
419
 
            double dx = 0, dy = 0;
420
 
            SciFiTools::calc_straight_residual(sp, line_x, line_y, dx, dy);
421
 
            if ( _verb > 1 ) {
422
 
              *_f_res_chosen << trker_no << "\t" << st_num << "\t" << n_points << "\t";
423
 
              *_f_res_chosen << dx << "\t" << dy << "\n";
424
 
            }
425
369
          }// ~if (counter > 0)
426
370
        } // ~if (st_num != ignore_station)
427
371
      } // ~Loop over intermediate stations
636
580
  if (success) {
637
581
    phi_i = true_phi_i;
638
582
  } else {
639
 
    std::cerr << "Failed to find n turns" << std::endl;
 
583
    if ( _verb > 0 ) std::cerr << "Failed to find n turns" << std::endl;
640
584
    return false;
641
585
  }
642
586
 
652
596
    return false;
653
597
  } else {
654
598
    if ( _verb > 0 ) std::cerr << "Passed s-z cut, ds/dz is " << line_sz.get_m() << "\n";
655
 
    phi_i = true_phi_i;
656
599
    return true;
657
600
  }
658
601
}
839
782
  return true;
840
783
} // ~set_end_stations(...)
841
784
 
842
 
// For helical Pattern Recognition use
 
785
// For straight Pattern Recognition use
843
786
bool PatternRecognition::set_seed_stations(const std::vector<int> ignore_stations,
844
787
                      int &o_st_num, int &i_st_num, int &mid_st_num) {
845
788
  if ( static_cast<int>(ignore_stations.size()) == 0 ) { // 5pt track case