ToolDAQFramework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
test_vertices_reconstruction.cpp
Go to the documentation of this file.
2 
4 
5 
6 bool test_vertices_reconstruction::Initialise(std::string configfile, DataModel &data){
7 
8  if(configfile!="") m_variables.Initialise(configfile);
9  //m_variables.Print();
10 
11  m_verbose = 0;
12  m_variables.Get("verbose", m_verbose);
13 
14  //Setup and start the stopwatch
15  bool use_stopwatch = false;
16  m_variables.Get("use_stopwatch", use_stopwatch);
17  m_stopwatch = use_stopwatch ? new util::Stopwatch("test_vertices_reconstruction") : 0;
18 
19  m_stopwatch_file = "";
20  m_variables.Get("stopwatch_file", m_stopwatch_file);
21 
23 
24  m_data= &data;
25 
26 
27  m_variables.Get("nhitsmax", m_nhits_max);
28 
29  //allocate memory for the hit vectors
30  m_in_PMTIDs = new std::vector<int> (m_nhits_max);
31  m_in_Ts = new std::vector<float>(m_nhits_max);
32  m_in_Qs = new std::vector<float>(m_nhits_max);
33 
34  if(m_stopwatch) Log(m_stopwatch->Result("Initialise"), INFO, m_verbose);
35 
36  return true;
37 }
38 
39 
41 
43 
44  float out_vertex[3]={0,0,0};
45  float out_direction[6]={0,0,0,0,0,0};
46  float out_cosine[3]={0,0,0};
47  float out_maxlike[3]={0,0,0};
48  double dout_vertex[3]={0,0,0};
49  double dout_direction[3]={0,0,0};
50  double dout_cone[2]={0,0};
51 
52  unsigned int num_triggers = m_data->IDTriggers.m_num_triggers;
53  std::vector<std::vector<float> > info = m_data->IDTriggers.m_info;
54 
55  //loop over ID triggers
56  for (int itrigger = 0; itrigger < num_triggers; itrigger++) {
57  //clear the previous triggers' hit information
58  m_in_PMTIDs->clear();
59  m_in_Ts->clear();
60  m_in_Qs->clear();
61  std::vector<float> the_info = info[itrigger];
62 
63  //Loop over ID SubSamples
64  for(std::vector<SubSample>::iterator is = m_data->IDSamples.begin(); is != m_data->IDSamples.end(); ++is){
65 
66  //loop over all hits
67  const size_t nhits_in_subsample = is->m_time.size();
68  //starting at m_first_unique, rather than 0, to avoid double-counting hits
69  // that are in multiple SubSamples
70  for(size_t ihit = is->m_first_unique; ihit < nhits_in_subsample; ihit++) {
71  //see if the hit belongs to this trigger
72  if(std::find(is->m_trigger_readout_windows[ihit].begin(),
73  is->m_trigger_readout_windows[ihit].end(),
74  itrigger) == is->m_trigger_readout_windows[ihit].end())
75  continue;
76 
77  //it belongs. Add it to the input arrays
78  m_ss << "DEBUG: Hit " << ihit << " at time " << is->m_time[ihit];
80  m_in_PMTIDs->push_back(is->m_PMTid[ihit]);
81  m_in_Ts ->push_back(is->m_time[ihit]);
82  m_in_Qs ->push_back(is->m_charge[ihit]);
83  }//ihit
84  }//ID SubSamples
85 
86  //get the number of hits
87  m_in_nhits = m_in_PMTIDs->size();
88 
89  //don't run on large events
90  if(m_in_nhits == 0 || m_in_nhits > m_nhits_max) {
91  m_ss << "INFO: " << m_in_nhits << " hits in current trigger. Not running test vertices reconstruction";
93  continue;
94  }
95 
96  m_ss << "DEBUG: test vertices reconstruction running over " << m_in_nhits << " hits";
98  m_ss << "DEBUG: First hit time relative to sample: " << m_in_Ts->at(0);
100 
101  bool success = false;
102  int ninfos = the_info.size();
103  if( ninfos == 7 ){
104  success = true;
105  // n hits, vertex, direction
106  out_vertex[0] = the_info[1];
107  out_vertex[1] = the_info[2];
108  out_vertex[2] = the_info[3];
109  out_cosine[0] = the_info[4];
110  out_cosine[1] = the_info[5];
111  out_cosine[2] = the_info[6];
112 
113  // double dir_z = cos(dir.theta);
114  // double dir_y = sin(dir.theta) * sin(dir.phi);
115  // double dir_x = sin(dir.theta) * cos(dir.phi);
116  // double theta, phi, alpha;
117 
118  out_direction[0] = atan2(sqrt(pow(out_cosine[0],2) + pow(out_cosine[1],2)),out_cosine[2]);
119  out_direction[1] = atan2(out_cosine[1],out_cosine[0]);
120  out_direction[2] = 0;
121  }else{
122  m_ss << "INFO: warning: unexpected trigger info structure: " << ninfos << " info entries ";
123  StreamToLog(INFO);
124  }
125 
126  if (success) {
127  m_ss << "DEBUG: vertex reconstructed at x, y, z:";
128  for(int i = 0; i < 3; i++) {
129  m_ss << " " << out_vertex[i] << ",";
130  }
131  m_ss << "DEBUG: reconstructed euler angles:";
132  for(int i = 0; i < 3; i++) {
133  m_ss << " " << out_direction[i] << ",";
134  }
136 
137  //fill the data model with the result
138  // need to convert to double...
139  for(int i = 0; i < 3; i++) {
140  dout_vertex[i] = out_vertex[i];
141  dout_direction[i] = out_direction[i];
142  }
143 
144  TimeDelta vertex_time = m_data->IDTriggers.m_trigger_time.at(itrigger);
145  m_data->RecoInfo.AddRecon(kReconTestVertices, itrigger, m_in_nhits,
146  vertex_time, &(dout_vertex[0]), out_maxlike[2], out_maxlike[1],
147  &(dout_direction[0]), &(dout_cone[0]), out_direction[5]);
148  }
149  }//itrigger
150 
152 
154 
155  return true;
156 }
157 
158 
160 
161  if(m_stopwatch) {
163  m_stopwatch->Start();
164  }
165 
166  delete m_in_PMTIDs;
167  delete m_in_Ts;
168  delete m_in_Qs;
169 
170 
171  if(m_stopwatch) {
172  Log(m_stopwatch->Result("Finalise"), INFO, m_verbose);
173  delete m_stopwatch;
174  }
175 
176  return true;
177 }
std::string Result(std::string method_name, std::string output_file="")
Definition: Stopwatch.cpp:38
std::vector< float > * m_in_Qs
Charges of hits in a trigger.
void Start()
Start the stopwatch.
Definition: Stopwatch.cpp:18
StopwatchTimes Stop()
Stop the stopwatch, returning the CPU time.
Definition: Stopwatch.cpp:24
bool Execute()
Executre function used to perform Tool perpose.
bool Initialise(std::string configfile, DataModel &data)
Initialise Function for setting up Tool resorces.
util::Stopwatch * m_stopwatch
The stopwatch, if we&#39;re using one.
bool Finalise()
Finalise funciton used to clean up resorces.
int m_verbose
Verbosity level, as defined in tool parameter file.
std::vector< int > * m_in_PMTIDs
PMT IDs of hits in a trigger.
unsigned int m_nhits_max
Above this number of hits in a trigger, don&#39;t run BONSAI. Equality is run. Set in config file...
std::vector< float > * m_in_Ts
Times of hits in a trigger.
std::string m_stopwatch_file
Image filename to save the histogram to, if required.
int m_in_nhits
Number of hits in a trigger.
test_vertices_reconstruction()
Simple constructor.
void Log(const std::string &message, const int message_level)
Format messages in the same way as for tools.
Definition: Utilities.cpp:276
std::stringstream m_ss
For easy formatting of Log messages.