ToolDAQFramework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
FLOWERRecon.cpp
Go to the documentation of this file.
1 #include "FLOWERRecon.h"
2 
4 
5 
6 bool FLOWERRecon::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("FLOWERRecon") : 0;
18 
19  m_stopwatch_file = "";
20  m_variables.Get("stopwatch_file", m_stopwatch_file);
21 
23 
24  m_data= &data;
25 
26  //setup FLOWER with the geometry info
27  int flower_verbose = 0;
28  m_variables.Get("flower_verbose", flower_verbose);
29  WCSimRootGeom * geo = 0;
30  m_data->WCSimGeomTree->SetBranchAddress("wcsimrootgeom", &geo);
31  m_data->WCSimGeomTree->GetEntry(0);
32  m_variables.Get("detector_name", m_detector_name);
33  Log("TODO: detector_name should come from the geometry, rather than the parameter file", WARN, m_verbose);
34  m_overwrite_nearest = false;
35  m_variables.Get("overwrite_nearest_neighbours", m_overwrite_nearest);
36  m_flower = new WCSimFLOWER(m_detector_name.c_str(), geo, m_overwrite_nearest, flower_verbose);
37 
38  //override any FLOWER assumptions
39  m_flower->SetDarkRate(m_data->IDPMTDarkRate);
40  m_flower->SetNPMTs(m_data->IDNPMTs);
41 
42  //tell FLOWER how many PMTs are turned off
43  m_n_working_pmts = m_data->IDNPMTs;
44  m_variables.Get("n_working_pmts", m_n_working_pmts);
45  if(m_n_working_pmts > m_data->IDNPMTs) {
46  m_ss << "WARN: Config value of number of working PMTs " << m_n_working_pmts
47  << " is more than the total number of PMTs " << m_data->IDNPMTs
48  << ". Setting the number of working PMTs to the total number of PMTs";
50  m_n_working_pmts = m_data->IDNPMTs;
51  }
52  m_flower->SetNWorkingPMTs(m_n_working_pmts);
53 
54  //Get the reconstructed events filter you want to save
55  if(!m_variables.Get("input_filter_name", m_input_filter_name)) {
56  Log("INFO: input_filter_name not given. Using ALL", WARN, m_verbose);
57  m_input_filter_name = "ALL";
58  }
59  m_input_filter = m_data->GetFilter(m_input_filter_name, false);
60  if(!m_input_filter) {
61  m_ss << "FATAL: no filter named " << m_input_filter_name << " found. Returning false";
63  return false;
64  }
65 
66  //allocate memory for the hit vectors
67  m_variables.Get("nhitsmin", m_nhits_min);
68  m_variables.Get("nhitsmax", m_nhits_max);
69  m_in_PMTIDs = new std::vector<int> (m_nhits_max);
70  m_in_Ts = new std::vector<float>(m_nhits_max);
71 
72  if(m_stopwatch) Log(m_stopwatch->Result("Initialise"), INFO, m_verbose);
73 
74  return true;
75 }
76 
77 
80 
81  //Loop over reconstructed objects. Each should have a vertex associated to a trigger
82  for(int ireco = 0; ireco < m_input_filter->GetNRecons(); ireco++) {
83  //get the vertex
84  Pos3D vertex = m_input_filter->GetVertex(ireco);
85  m_vertex[0] = vertex.x;
86  m_vertex[1] = vertex.y;
87  m_vertex[2] = vertex.z;
88 
89  //get the trigger number this reconstructed object is associated with
90  const int trigger_num = m_input_filter->GetTriggerNum(ireco);
91 
92  //clear the previous triggers' hit information
93  m_in_PMTIDs->clear();
94  m_in_Ts->clear();
95 
96  //fill the inputs to FLOWER with the current triggers' hit information
97  //Loop over SubSamples
98  for(std::vector<SubSample>::iterator is = m_data->IDSamples.begin(); is != m_data->IDSamples.end(); ++is){
99  //loop over hits
100  const size_t nhits_in_subsample = is->m_time.size();
101  //starting at m_first_unique, rather than 0, to avoid double-counting hits
102  // that are in multiple SubSamples
103  for(size_t ihit = is->m_first_unique; ihit < nhits_in_subsample; ihit++) {
104  //see if the hit belongs to this trigger
105  if(std::find(is->m_trigger_readout_windows[ihit].begin(),
106  is->m_trigger_readout_windows[ihit].end(),
107  trigger_num) == is->m_trigger_readout_windows[ihit].end())
108  continue;
109 
110  //it belongs. Add it to the FLOWER input arrays
111  m_ss << "DEBUG: Hit " << ihit << " at time " << is->m_time[ihit];
113  m_in_PMTIDs->push_back(is->m_PMTid[ihit]);
114  m_in_Ts ->push_back(is->m_time[ihit]);
115  }//ihit
116  }//SubSamples
117 
118  //get the number of hits
119  m_in_nhits = m_in_PMTIDs->size();
120 
121  //don't run FLOWER on large or small events
122  if(m_in_nhits < m_nhits_min || m_in_nhits > m_nhits_max) {
123  m_ss << "INFO: " << m_in_nhits << " hits in current trigger. Not running FLOWER";
124  StreamToLog(INFO);
125  continue;
126  }
127 
128  m_ss << "DEBUG: FLOWER running over " << m_in_nhits << " hits";
130 
131  //get the energy
132  double energy = m_flower->GetEnergy(*m_in_Ts, *m_in_PMTIDs, &(m_vertex[0]));
133 
134  m_ss << "INFO: FLOWER reconstructed energy " << energy;
135  StreamToLog(INFO);
136 
137  m_input_filter->SetEnergy(ireco, energy);
138 
139  }//ireco
140 
142 
143  return true;
144 }
145 
146 
148  if(m_stopwatch) {
150  m_stopwatch->Start();
151  }
152 
153  delete m_flower;
154  delete m_in_PMTIDs;
155  delete m_in_Ts;
156 
157  if(m_stopwatch) {
158  Log(m_stopwatch->Result("Finalise"), INFO, m_verbose);
159  delete m_stopwatch;
160  }
161 
162  return true;
163 }
std::string Result(std::string method_name, std::string output_file="")
Definition: Stopwatch.cpp:38
Pos3D GetVertex(int irecon)
Definition: ReconInfo.h:93
WCSimFLOWER * m_flower
Instance of FLOWER.
Definition: FLOWERRecon.h:27
util::Stopwatch * m_stopwatch
The stopwatch, if we&#39;re using one.
Definition: FLOWERRecon.h:55
int m_n_working_pmts
Number of working PMTs, taken from config file (defaults to NPMTs in geometry)
Definition: FLOWERRecon.h:48
double y
Definition: ReconInfo.h:37
void Start()
Start the stopwatch.
Definition: Stopwatch.cpp:18
unsigned int m_nhits_min
Number of hits must be greater than this, else FLOWER won&#39;t be run on this trigger.
Definition: FLOWERRecon.h:38
std::vector< float > * m_in_Ts
Read in the times of all hits in the given trigger.
Definition: FLOWERRecon.h:33
StopwatchTimes Stop()
Stop the stopwatch, returning the CPU time.
Definition: Stopwatch.cpp:24
bool Finalise()
bool Initialise(std::string configfile, DataModel &data)
Definition: FLOWERRecon.cpp:6
ReconInfo * m_input_filter
Holds reconstructed vertex information.
Definition: FLOWERRecon.h:43
void StreamToLog(int level)
Definition: FLOWERRecon.h:67
TChain * WCSimGeomTree
The WCSimRootGeom tree from input WCSim file(s)
Definition: DataModel.h:105
std::stringstream m_ss
For easy formatting of Log messages.
Definition: FLOWERRecon.h:63
int m_verbose
Verbosity level, as defined in tool parameter file.
Definition: FLOWERRecon.h:60
int GetTriggerNum(int irecon)
Definition: ReconInfo.h:88
unsigned int m_nhits_max
Number of hits must be less than this, else FLOWER won&#39;t be run on this trigger.
Definition: FLOWERRecon.h:40
int m_in_nhits
Read in the total number of hits in the given trigger.
Definition: FLOWERRecon.h:29
bool Execute()
Definition: FLOWERRecon.cpp:78
void SetEnergy(int irecon, double energy)
Definition: ReconInfo.h:91
std::string m_input_filter_name
Which named filter to use? For preselecting which reconstructed vertices will be used by FLOWER...
Definition: FLOWERRecon.h:45
std::string m_stopwatch_file
Image filename to save the histogram to, if required.
Definition: FLOWERRecon.h:57
double x
Definition: ReconInfo.h:37
double z
Definition: ReconInfo.h:37
bool m_overwrite_nearest
Overwrite the precalculated nearest neighbours ROOT file that FLOWER uses?
Definition: FLOWERRecon.h:52
void Log(const std::string &message, const int message_level)
Format messages in the same way as for tools.
Definition: Utilities.cpp:276
int GetNRecons()
Definition: ReconInfo.h:84
std::string m_detector_name
Name of the detector, used to set default FLOWER parameters.
Definition: FLOWERRecon.h:50
float m_vertex[3]
x,y,z of input reconstructed vertex
Definition: FLOWERRecon.h:35
std::vector< int > * m_in_PMTIDs
Read in the PMT IDs of all hits in the given trigger.
Definition: FLOWERRecon.h:31