ToolDAQFramework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ReconFilter.cpp
Go to the documentation of this file.
1 #include "ReconFilter.h"
2 
4 
5 
6 bool ReconFilter::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("ReconFilter") : 0;
18 
19  m_stopwatch_file = "";
20  m_variables.Get("stopwatch_file", m_stopwatch_file);
21 
23 
24  m_data= &data;
25 
26  //parameters determining what to name the (pre)filtered RecoInfo objects
27  if(!m_variables.Get("input_filter_name", fInputFilterName)) {
28  Log("INFO: input_filter_name not given. Using ALL", WARN, m_verbose);
29  fInputFilterName = "ALL";
30  }
31  if(!m_variables.Get("output_filter_name", fOutputFilterName)) {
32  Log("WARN: output_filter_name not given. Using TEMP", WARN, m_verbose);
33  fOutputFilterName = "TEMP";
34  }
35  fInFilter = m_data->GetFilter(fInputFilterName, false);
36  if(!fInFilter) {
37  ss << "FATAL: no filter named " << fInputFilterName << " found. Returning false";
39  return false;
40  }
41  fOutFilter = m_data->GetFilter(fOutputFilterName, true);
42 
43  if(fOutFilter == &(m_data->RecoInfo)) {
44  Log("ERROR: Cannot use the full RecoInfo object to store filtered events", ERROR, m_verbose);
45  return false;
46  }
47  if(fInFilter == fOutFilter) {
48  Log("ERROR: Can't use the same filter for input and output. TODO add ReconInfo::RemoveRecon() methods and change logic here in ReconFilter to deal with it", ERROR, m_verbose);
49  return false;
50  }
51  if(fOutFilter->GetNRecons()) {
52  Log("ERROR: output_filter_name must be unique (needs to be a blank canvas). TODO add ReconInfo::RemoveRecon() methods and change logic here in ReconFilter to deal with it", ERROR, m_verbose);
53  return false;
54  }
55 
56  //parameters determining which reconstructed events to use
57  std::string reconstruction_algorithm_str;
59  m_variables.Get("reconstruction_algorithm", reconstruction_algorithm_str);
60  fReconstructionAlgorithm = ReconInfo::ReconstructerFromString(reconstruction_algorithm_str);
62  Log("ERROR: The reconstruction_algorithm parameter you have chosen is not defined. Please choose a valid option", ERROR, m_verbose);
63  return false;
64  }
65  if(!m_variables.Get("fMinReconLikelihood", fMinReconLikelihood)) {
67  Log("WARN: No fMinReconLikelihood parameter found. Using a value of 0", WARN, m_verbose);
68  }
69  if(!m_variables.Get("fMinReconTimeLikelihood", fMinReconTimeLikelihood)) {
71  Log("WARN: No fMinReconTimeLikelihood parameter found. Using a value of 0", WARN, m_verbose);
72  }
73  if(!m_variables.Get("max_r_pos", fMaxRPos_cm)) {
74  fMaxRPos_cm = 3500;
75  Log("WARN: No max_r_pos parameter found. Using a value of 3500 (cm)", WARN, m_verbose);
76  }
77  if(!m_variables.Get("max_z_pos", fMaxZPos_cm)) {
78  fMaxZPos_cm = 2700;
79  Log("WARN: No max_z_pos parameter found. Using a value of 2700 (cm)", WARN, m_verbose);
80  }
81 
82  if(m_stopwatch) Log(m_stopwatch->Result("Initialise"), INFO, m_verbose);
83 
84  return true;
85 }
86 
89 
90  const int N = m_data->RecoInfo.GetNRecons();
91  for(int irecon = 0; irecon < N; irecon++) {
92  //skip events reconstructed with the wrong algorithm
94  continue;
95 
96  //skip events with poor likelihoods
98  continue;
100  continue;
101 
102  //get the vertex position
103  Pos3D pos = fInFilter->GetVertex(irecon);
104  //skip events that are reconstructed too close to the wall
105  if(pos.R() > fMaxRPos_cm)
106  continue;
107  if(abs(pos.z) > fMaxZPos_cm)
108  continue;
109 
110  //the event has passed the filter. Save it in the output list
112  }//irecon
113 
114  ss << "INFO: ReconFilter has reduced number of reconstructed events from "
115  << fInFilter ->GetNRecons() << " (" << fInputFilterName << ") to "
116  << fOutFilter->GetNRecons() << " (" << fOutputFilterName << ")";
117  StreamToLog(INFO);
118 
120 
121  return true;
122 }
123 
124 
126  if(m_stopwatch) {
128  m_stopwatch->Start();
129  }
130 
131  if(m_stopwatch) {
132  Log(m_stopwatch->Result("Finalise"), INFO, m_verbose);
133  delete m_stopwatch;
134  }
135 
136  return true;
137 }
std::stringstream ss
Definition: ReconFilter.h:41
std::string Result(std::string method_name, std::string output_file="")
Definition: Stopwatch.cpp:38
Pos3D GetVertex(int irecon)
Definition: ReconInfo.h:93
double fMinReconLikelihood
Definition: ReconFilter.h:29
double R()
Definition: ReconInfo.h:38
double fMinReconTimeLikelihood
Definition: ReconFilter.h:30
Reconstructer_t GetReconstructer(int irecon)
Definition: ReconInfo.h:87
void Start()
Start the stopwatch.
Definition: Stopwatch.cpp:18
StopwatchTimes Stop()
Stop the stopwatch, returning the CPU time.
Definition: Stopwatch.cpp:24
void AddReconFrom(ReconInfo *in, const int irecon)
Definition: ReconInfo.cpp:58
void StreamToLog(int level)
Definition: ReconFilter.h:43
ReconInfo * fInFilter
Definition: ReconFilter.h:23
std::string fOutputFilterName
Definition: ReconFilter.h:26
static Reconstructer_t ReconstructerFromString(std::string s)
Definition: ReconInfo.cpp:102
double GetGoodnessOfFit(int irecon)
Definition: ReconInfo.h:94
double fMaxRPos_cm
Definition: ReconFilter.h:31
bool Initialise(std::string configfile, DataModel &data)
Definition: ReconFilter.cpp:6
util::Stopwatch * m_stopwatch
The stopwatch, if we&#39;re using one.
Definition: ReconFilter.h:35
std::string fInputFilterName
Definition: ReconFilter.h:25
Reconstructer_t fReconstructionAlgorithm
Definition: ReconFilter.h:28
bool Execute()
Definition: ReconFilter.cpp:87
double fMaxZPos_cm
Definition: ReconFilter.h:32
ReconInfo * fOutFilter
Definition: ReconFilter.h:24
double z
Definition: ReconInfo.h:37
double GetGoodnessOfTimeFit(int irecon)
Definition: ReconInfo.h:95
void Log(const std::string &message, const int message_level)
Format messages in the same way as for tools.
Definition: Utilities.cpp:276
bool Finalise()
int GetNRecons()
Definition: ReconInfo.h:84
std::string m_stopwatch_file
Image filename to save the histogram to, if required.
Definition: ReconFilter.h:37