8   float m_trigger_gate_up;
 
    9   float m_trigger_gate_down;
 
   11   if(configfile!=
"")  m_variables.Initialise(configfile);
 
   17   bool use_stopwatch = 
false;
 
   18   m_variables.Get(
"use_stopwatch", use_stopwatch);
 
   33   std::string DetectorFile;
 
   34   std::string ParameterFile;
 
   37   m_variables.Get(
"DetectorFile",DetectorFile);
 
   38   m_variables.Get(
"ParameterFile",ParameterFile);
 
   45   m_variables.Get(
"trigger_gate_up",   m_trigger_gate_up);
 
   46   m_variables.Get(
"trigger_gate_down",   m_trigger_gate_down);
 
   97   std::vector<int> tube_no;
 
   98   std::vector<float> tube_x;
 
   99   std::vector<float> tube_y;
 
  100   std::vector<float> tube_z;
 
  101   for( std::vector<PMTInfo>::const_iterator ip=m_data->IDGeom.begin(); ip!=m_data->IDGeom.end(); ip++){
 
  102     tube_no.push_back(ip->m_tubeno);
 
  103     tube_x.push_back(ip->m_x);
 
  104     tube_y.push_back(ip->m_y);
 
  105     tube_z.push_back(ip->m_z);
 
  111  m_distance_between_vertices,
 
  112  m_wall_like_distance,
 
  113  m_water_like_threshold_number_of_pmts,
 
  114  m_wall_like_threshold_number_of_pmts,
 
  120  m_n_direction_bins_theta,
 
  123  m_select_based_on_cone,
 
  124  m_trigger_threshold_adjust_for_noise,
 
  125  m_max_n_hits_per_job,
 
  127  m_num_threads_per_block_y,
 
  128  m_num_threads_per_block_x,
 
  142   int npmts = m_data->IDNPMTs;
 
  143   double dark_rate_kHZ = m_data->IDPMTDarkRate;
 
  144   double dark_rate_Hz = dark_rate_kHZ * 1000;
 
  145   double average_occupancy = dark_rate_Hz * m_coalesce_time * npmts;
 
  151   m_variables.Get(
"dark_rate",dark_rate);
 
  172   std::vector<SubSample> & samples = m_data->IDSamples;
 
  174   for( std::vector<SubSample>::const_iterator is=samples.begin(); is!=samples.end(); ++is){
 
  176     std::vector<int> trigger_ns;
 
  177     std::vector<int> trigger_ts;
 
  178     std::vector<double> trigger_vtx_xs;
 
  179     std::vector<double> trigger_vtx_ys;
 
  180     std::vector<double> trigger_vtx_zs;
 
  181     std::vector<double> trigger_dir_xs;
 
  182     std::vector<double> trigger_dir_ys;
 
  183     std::vector<double> trigger_dir_zs;
 
  187     for(
unsigned int i = 0; i < is->m_time.size(); i++) {
 
  198     for(
int i=0; i<trigger_ns.size(); i++){
 
  199       std::vector<float> info;
 
  200       info.push_back(trigger_ns[i]);
 
  203     info.push_back(trigger_vtx_xs[i]);
 
  204     info.push_back(trigger_vtx_ys[i]);
 
  205     info.push_back(trigger_vtx_zs[i]);
 
  208     info.push_back(trigger_dir_xs[i]);
 
  209     info.push_back(trigger_dir_ys[i]);
 
  210     info.push_back(trigger_dir_zs[i]);
 
  213       m_data->IDTriggers.AddTrigger(kTriggerUndefined,
 
  218                                     TimeDelta(trigger_ts[i]) + is->m_timestamp,
 
  221       m_ss << 
" trigger! time "<< trigger_ts[i] << 
" -> " << 
TimeDelta(trigger_ts[i] ) + is->m_timestamp << 
" nhits " <<  trigger_ns[i]; 
StreamToLog(
INFO);
 
  228   for( std::vector<SubSample>::iterator is=samples.begin(); is!=samples.end(); ++is) {
 
  229     (*is).TellMeAboutTheTriggers(m_data->IDTriggers, 
m_verbose);
 
  270   int n_PMTs_counter = 0;
 
  271   for( std::vector<PMTInfo>::const_iterator ip=m_data->IDGeom.begin(); ip!=m_data->IDGeom.end(); ip++){
 
  272     PMT_x[n_PMTs_counter] = ip->m_x;
 
  273     PMT_y[n_PMTs_counter] = ip->m_y;
 
  274     PMT_z[n_PMTs_counter] = ip->m_z;
 
  277   printf(
" [2] detector contains %d PMTs \n", 
n_PMTs);
 
  281     twopi = 2.*acos(-1.);
 
  295     int extra_threshold = 0;
 
  313   printf(
" [2] --- user parameters \n");
 
  314   printf(
" [2] dark_rate %f \n", 
dark_rate);
 
  329     printf(
" [2] n_direction_bins_theta %d, n_direction_bins_phi %d, n_direction_bins %d \n",
 
  381   printf(
" [2] --- make test vertices \n");
 
  454     double distance_angular;
 
  456     printf(
" [2] distance_between_vertices %f, distance_vertical %f, distance_radial %f \n",
 
  459     double the_r, the_z, the_phi;
 
  463     bool add_extra_layer = first;
 
  467     while( the_r >= 0. ){
 
  469       distance_angular = 
twopi/n_angular;
 
  473       while( the_z <= semiheight){
 
  476     while( the_phi < 
twopi - distance_angular/2. ){
 
  480       if( the_r == 0. ) 
break;
 
  481       the_phi += distance_angular;
 
  485     if( add_extra_layer ){
 
  486       if( the_z + semiheight < 0.3*distance_vertical ) 
 
  487         the_z += distance_vertical/2.;
 
  488       else if( semiheight - the_z < 0.7*distance_vertical ) 
 
  489         the_z += distance_vertical/2.;
 
  491         the_z += distance_vertical;
 
  493       the_z += distance_vertical;
 
  497     the_r -= distance_radial/2.;
 
  501     the_r -= distance_radial;
 
  509     first = add_extra_layer;
 
  515     while( the_r >= 0. ){
 
  521     distance_angular = 
twopi/n_angular;
 
  525     while( the_z <= semiheight){
 
  531         while( the_phi < 
twopi - distance_angular/2. ){
 
  538           if( the_r == 0. ) 
break;
 
  539           the_phi += distance_angular;
 
  543       if( add_extra_layer ){
 
  544         if( the_z + semiheight < 0.3*distance_vertical ) 
 
  545           the_z += distance_vertical/2.;
 
  546         else if( semiheight - the_z < 0.7*distance_vertical ) 
 
  547           the_z += distance_vertical/2.;
 
  549           the_z += distance_vertical;
 
  551         the_z += distance_vertical;
 
  557     the_r -= distance_radial/2.;
 
  561     the_r -= distance_radial;
 
  568     first = add_extra_layer;
 
  571     while( the_r >= 0. ){
 
  574       distance_angular = 
twopi/n_angular;
 
  578       while( the_z <= semiheight){
 
  584       while( the_phi < 
twopi - distance_angular/2. ){
 
  591         if( the_r == 0. ) 
break;
 
  592         the_phi += distance_angular;
 
  595     if( add_extra_layer ){
 
  596       if( the_z + semiheight < 0.3*distance_vertical ) 
 
  597         the_z += distance_vertical/2.;
 
  598       else if( semiheight - the_z < 0.7*distance_vertical ) 
 
  599         the_z += distance_vertical/2.;
 
  601         the_z += distance_vertical;
 
  603       the_z += distance_vertical;
 
  607     the_r -= distance_radial/2.;
 
  611     the_r -= distance_radial;
 
  627   printf(
" [2] --- fill times_of_flight \n");
 
  636   unsigned int distance_index;
 
  638   for(
unsigned int ip=0; ip<
n_PMTs; ip++){
 
  661   printf(
" [2] --- fill directions \n");
 
  664   float dx, dy, dz, dr, phi, cos_theta, sin_theta;
 
  665   float phi2, cos_theta2, angle;
 
  666   unsigned int dir_index_at_angles;
 
  667   unsigned int dir_index_at_pmt;
 
  668   for(
unsigned int ip=0; ip<
n_PMTs; ip++){
 
  673       dr = sqrt(pow(dx,2) + pow(dy,2) + pow(dz,2));
 
  677       sin_theta = sqrt(1. - pow(cos_theta,2));
 
  680     cos_theta2 = -1. + 2.*itheta/(n_direction_bins_theta - 1);
 
  684       if( (itheta == 0 || itheta + 1 == n_direction_bins_theta ) && iphi != 0 ) 
break;
 
  687       angle = acos( sin_theta*sqrt(1 - pow(cos_theta2,2)) * cos(phi - phi2) + cos_theta*cos_theta2 );
 
  712   return pmt_id - 1 + vertex_block;
 
  719   return hit_index + vertex_block;
 
  725    if( itheta == 0 ) 
return 0;
 
  760     printf(
" [2] --- deallocate tofs memory \n");
 
  800     printf(
" [2] ------ analyzing event %d \n", 
n_events+1);
 
  808     int earliest_time = 0;
 
  831       printf(
" [2] --- execute kernel to correct times and get n pmts per time bin \n");
 
  843       printf(
" [2] --- execute candidates kernel \n");
 
  852       printf(
" [2] --- choose candidates above threshold \n");
 
  881       printf(
" [2] --- deallocate memory \n");
 
  889   printf(
" [2] ------ analyzed %d events \n", 
n_events);
 
  898   printf(
" [2] --- read input \n");
 
  900   if( !
n_hits ) 
return false;
 
  901   if( 
n_hits != times.size() ){
 
  902     printf(
" [2] n PMT ids %d but n times %d \n", 
n_hits, times.size());
 
  905   printf(
" [2] input contains %d hits \n", 
n_hits);
 
  917     for(
int i=0; i<PMTids.size(); i++){
 
  918       time = int(floor(times[i]));
 
  922       if( time > max ) max = time;
 
  923       if( time < min ) min = time;
 
  927       for(
int i=0; i<PMTids.size(); i++){
 
  941   printf(
" [2] time_offset = %d ns \n", 
time_offset);
 
  973       fprintf(of, 
" %d \n", trigger);
 
  977       unsigned int triggertime, trigger_index;
 
  993       unsigned int best_vertex;
 
  995     unsigned int vertex_index = itrigger->first;
 
  996     unsigned int time_index = itrigger->second;
 
  998     if( local_n_pmts > max_n_pmts ){
 
  999       max_n_pmts = local_n_pmts;
 
 1000       best_vertex = vertex_index;
 
 1003       unsigned int distance_index;
 
 1005       double corrected_time;
 
 1007       for(
unsigned int i=0; i<
n_hits; i++){
 
 1026   printf(
" [2] --- allocate candidates memory on host \n");
 
 1043   unsigned int distance_index;
 
 1045   double corrected_time;
 
 1048   for(
unsigned int i=0; i<
n_hits; i++){
 
 1067   for(
unsigned int time_bin_index=0; time_bin_index<
n_time_bins; time_bin_index++){
 
 1069     unsigned int number_of_pmts_in_time_bin = 0;
 
 1070     unsigned int time_index;
 
 1072     unsigned int vertex_with_max_n_pmts = 0;
 
 1077       time_index = time_bin_index + n_time_bins*iv;
 
 1078       if( time_index >= n_time_bins*n_test_vertices - 1 ) 
continue;
 
 1079       number_of_pmts_in_time_bin = np[time_index] + np[time_index+1];
 
 1080       if( number_of_pmts_in_time_bin >= max_number_of_pmts_in_time_bin ){
 
 1081     max_number_of_pmts_in_time_bin = number_of_pmts_in_time_bin;
 
 1082     vertex_with_max_n_pmts = iv;
 
 1086     mnp[time_bin_index] = max_number_of_pmts_in_time_bin;
 
 1087     vmnp[time_bin_index] = vertex_with_max_n_pmts;
 
 1102   unsigned int the_threshold;
 
 1103   unsigned int number_of_pmts_to_cut_on;
 
 1105   for(
unsigned int time_bin = 0; time_bin<
n_time_bins - 1; time_bin++){ 
 
 1120     if(number_of_pmts_to_cut_on > the_threshold) {
 
 1149   unsigned int vertex_index, time_upper, number_of_pmts_in_time_bin, number_of_pmts_in_cone_in_time_bin;
 
 1150   unsigned int max_pmt=0,max_vertex_index=0,max_time=0,max_pmt_in_cone=0;
 
 1152   unsigned int trigger_index;
 
 1155     vertex_index =      itrigger->first;
 
 1156     time_upper = itrigger->second;
 
 1163     first_trigger = (trigger_index == 0);
 
 1166     if( first_trigger ){
 
 1167       max_pmt = number_of_pmts_in_time_bin;
 
 1168       max_vertex_index = vertex_index;
 
 1169       max_time = time_upper;
 
 1171     max_pmt_in_cone = number_of_pmts_in_cone_in_time_bin;
 
 1177       if( coalesce_triggers ){
 
 1178     if( number_of_pmts_in_time_bin >= max_pmt) {
 
 1179       max_pmt = number_of_pmts_in_time_bin;
 
 1180       max_vertex_index = vertex_index;
 
 1181       max_time = time_upper;
 
 1183         max_pmt_in_cone = number_of_pmts_in_cone_in_time_bin;
 
 1189     max_pmt = number_of_pmts_in_time_bin;
 
 1190     max_vertex_index = vertex_index;
 
 1191     max_time = time_upper;     
 
 1194       max_pmt_in_cone = number_of_pmts_in_cone_in_time_bin;
 
 1210     printf(
" [2] coalesced trigger timebin %d vertex index %d \n", itrigger->first, itrigger->second);
 
 1220   unsigned int trigger_index;
 
 1222   unsigned int time_start=0;
 
 1225     if(itrigger->second > time_start) {
 
 1238       trigger_ts->push_back(triggertime);
 
int CPU_test_vertices_execute(std::vector< int > PMTid, std::vector< int > time, std::vector< int > *trigger_ns, std::vector< int > *trigger_ts)
 
unsigned int n_water_like_test_vertices
 
std::string Result(std::string method_name, std::string output_file="")
 
unsigned int * host_times
 
unsigned int n_direction_bins
 
void choose_candidates_above_threshold()
 
double cerenkov_angle_water
 
unsigned int * host_max_number_of_pmts_in_cone_in_time_bin
 
util::Stopwatch * m_stopwatch
The stopwatch, if we're using one. 
 
unsigned int * host_vertex_with_max_n_pmts
 
int CPU_test_vertices_initialize()
 
unsigned int n_direction_bins_phi
 
void allocate_candidates_memory_on_host()
 
bool triggeroutput
DEPRECATED! Use IDTriggers and ODTriggers instead. 
 
void free_global_memories()
 
void Start()
Start the stopwatch. 
 
unsigned int get_time_index(unsigned int hit_index, unsigned int vertex_block)
 
unsigned int n_test_vertices
vertices 
 
StopwatchTimes Stop()
Stop the stopwatch, returning the CPU time. 
 
void find_vertex_with_max_npmts_in_timebin(histogram_t *np, histogram_t *mnp, unsigned int *vmnp)
 
std::vector< unsigned int > candidate_trigger_npmts_in_time_bin
 
int m_n_direction_bins_theta
 
bool Initialise(std::string configfile, DataModel &data)
 
std::vector< unsigned int > trigger_npmts_in_cone_in_time_bin
 
void StreamToLog(int level)
 
void free_event_memories()
 
unsigned int * host_n_pmts_per_time_bin
 
float m_distance_between_vertices
 
std::vector< unsigned int > candidate_trigger_npmts_in_cone_in_time_bin
 
unsigned int get_distance_index(unsigned int pmt_id, unsigned int vertex_block)
 
float m_wall_like_threshold_number_of_pmts
 
std::stringstream m_ss
For easy formatting of Log messages. 
 
float m_wall_like_distance
 
int m_verbose
Verbosity level, as defined in tool parameter file. 
 
std::vector< std::pair< unsigned int, unsigned int > > final_trigger_pair_vertex_time
 
std::vector< double > output_trigger_information
 
unsigned int wall_like_threshold_number_of_pmts
 
std::vector< unsigned int > trigger_npmts_in_time_bin
 
double detector_height
detector 
 
void make_test_vertices()
 
histogram_t * host_max_number_of_pmts_in_time_bin
 
unsigned int water_like_threshold_number_of_pmts
 
int test_vertices_initialize_ToolDAQ(double detector_length, double detector_radius, double pmt_radius, std::string ParameterFile, std::vector< int > tube_no, std::vector< float > tube_x, std::vector< float > tube_y, std::vector< float > tube_z, float f_dark_rate, float distance_between_vertices, float wall_like_distance, float water_like_threshold_number_of_pmts, float wall_like_threshold_number_of_pmts, float coalesce_time, float trigger_gate_up, float trigger_gate_down, int output_txt, int correct_mode, int n_direction_bins_theta, bool cylindrical_grid, float costheta_cone_cut, bool select_based_on_cone, bool trigger_threshold_adjust_for_noise, int f_max_n_hits_per_job, int f_num_blocks_y, int f_num_threads_per_block_y, int f_num_threads_per_block_x, int f_write_output_mode, bool f_return_vertex, bool f_return_direction)
 
int m_num_threads_per_block_y
 
TimeDelta m_trigger_mask_window_pre
Pre-trigger time for masking digits from future tools. 
 
unsigned int write_output_mode
 
void separate_triggers_into_gates(std::vector< int > *trigger_ns, std::vector< int > *trigger_ts)
 
unsigned int get_direction_index_at_pmt(unsigned int pmt_id, unsigned int vertex_index, unsigned int direction_index)
 
unsigned int correct_mode
 
bool * host_directions_for_vertex_and_pmt
 
void correct_times_and_get_histo_per_vertex_shared(unsigned int *ct)
 
TimeDelta m_trigger_save_window_pre
Pre-trigger time for saving digits. 
 
unsigned int time_step_size
 
unsigned int the_max_time
 
unsigned int get_direction_index_at_time(unsigned int time_bin, unsigned int vertex_index, unsigned int direction_index)
 
bool read_the_input_ToolDAQ(std::vector< int > PMTid, std::vector< int > time, int *earliest_time)
 
std::vector< int > m_time_int
 
void Log(const std::string &message, const int message_level)
Format messages in the same way as for tools. 
 
int test_vertices_execute()
 
int CPU_test_vertices_finalize()
 
int test_vertices_finalize()
 
std::vector< std::pair< unsigned int, unsigned int > > candidate_trigger_pair_vertex_time
 
bool m_trigger_threshold_adjust_for_noise
 
unsigned int time_of_flight_t
 
std::vector< std::pair< unsigned int, unsigned int > > trigger_pair_vertex_time
 
unsigned int max_n_hits_per_job
 
float m_costheta_cone_cut
 
double distance_between_vertices
CPU parameters. 
 
unsigned int get_direction_index_at_angles(unsigned int iphi, unsigned int itheta)
 
time_of_flight_t * host_times_of_flight
 
std::string m_stopwatch_file
Image filename to save the histogram to, if required. 
 
TimeDelta m_trigger_save_window_post
Post-trigger time for saving digits. 
 
bool m_select_based_on_cone
 
void make_table_of_directions()
 
bool select_based_on_cone
 
unsigned int n_direction_bins_theta
 
int m_num_threads_per_block_x
 
TimeDelta m_trigger_mask_window_post
Post-trigger time for masking digits from future tools. 
 
float m_water_like_threshold_number_of_pmts
 
void make_table_of_tofs()
 
double wall_like_distance