ToolDAQFramework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ReconDataOut.cpp
Go to the documentation of this file.
1 #include "ReconDataOut.h"
2 
4 
5 
6 bool ReconDataOut::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("ReconDataOut") : 0;
18 
19  m_stopwatch_file = "";
20  m_variables.Get("stopwatch_file", m_stopwatch_file);
21 
23 
24  m_data= &data;
25 
26  //open the output file
27  if(! m_variables.Get("outfilename", fOutFilename)) {
28  Log("ERROR: outfilename configuration not found. Cancelling initialisation", ERROR, m_verbose);
29  return false;
30  }
31  fOutFile.Open(fOutFilename.c_str(), "RECREATE");
32 
33  //open & format the tree
34  fTreeRecon = new TTree("reconTree", "Reconstruction information");
35  fTreeRecon->Branch("EventNum", &fEvtNum);
36  fTreeRecon->Branch("TriggerNum", &fRTTriggerNum);
37  fTreeRecon->Branch("NDigits", &fRTNHits);
38  fTreeRecon->Branch("Energy", &fRTEnergy);
39  fTreeRecon->Branch("Reconstructer", &fRTReconstructer, "Reconstruter/I");
40  fTreeRecon->Branch("Time", &fRTTime);
41  fTreeRecon->Branch("Vertex", fRTVertex, "Vertex[3]/D");
42  fTreeRecon->Branch("GoodnessOfFit", &fRTGoodnessOfFit);
43  fTreeRecon->Branch("GoodnessOfTimeFit", &fRTGoodnessOfTimeFit);
44  fTreeRecon->Branch("HasDirection", &fRTHasDirection);
45  fTreeRecon->Branch("DirectionEuler", fRTDirectionEuler, "DirectionEuler[3]/D");
46  fTreeRecon->Branch("CherenkovCone", fRTCherenkovCone, "CherenkovCone[2]/D");
47  fTreeRecon->Branch("DirectionLikelihood", &fRTDirectionLikelihood);
48 
49  //Get the reconstructed events filter you want to save
50  if(!m_variables.Get("input_filter_name", fInputFilterName)) {
51  Log("INFO: input_filter_name not given. Using ALL", WARN, m_verbose);
52  fInputFilterName = "ALL";
53  }
54  fInFilter = m_data->GetFilter(fInputFilterName, false);
55  if(!fInFilter) {
56  ss << "FATAL: no filter named " << fInputFilterName << " found. Returning false";
58  return false;
59  }
60 
61  fEvtNum = 0;
62 
63  if(m_stopwatch) Log(m_stopwatch->Result("Initialise"), INFO, m_verbose);
64 
65  return true;
66 }
67 
68 
71 
72  const int nrecons = fInFilter->GetNRecons();
73  ss << "DEBUG: Saving the result of " << nrecons << " reconstructions";
75  for(int irecon = 0; irecon < nrecons; irecon++) {
77  fRTNHits = fInFilter->GetNHits(irecon);
78  fRTEnergy = fInFilter->GetEnergy(irecon);
81  Pos3D pos = fInFilter->GetVertex(irecon);
82  fRTVertex[0] = pos.x;
83  fRTVertex[1] = pos.y;
84  fRTVertex[2] = pos.z;
87  //Direction
89  if(fRTHasDirection) {
90  DirectionEuler direct = fInFilter->GetDirectionEuler(irecon);
91  fRTDirectionEuler[0] = direct.theta;
92  fRTDirectionEuler[1] = direct.phi;
93  fRTDirectionEuler[2] = direct.alpha;
95  fRTCherenkovCone[0] = cone.cos_angle;
96  fRTCherenkovCone[1] = cone.ellipticity;
98  }
99  else {
100  for(int i = 0; i < 3; i++)
101  fRTDirectionEuler[i] = -9E7;
102  for(int i = 0; i < 2; i++)
103  fRTCherenkovCone [i] = -9E7;
104  }
105  //Fill the tree
106  fTreeRecon->Fill();
107  }
108 
109  //increment event number
110  fEvtNum++;
111 
113 
114  return true;
115 }
116 
117 
119  if(m_stopwatch) {
121  m_stopwatch->Start();
122  }
123 
124  //multiple TFiles may be open. Ensure we save to the correct one
125  fOutFile.cd(TString::Format("%s:/", fOutFilename.c_str()));
126  fTreeRecon->Write();
127  fOutFile.Close();
128  delete fTreeRecon;
129 
130  if(m_stopwatch) {
131  Log(m_stopwatch->Result("Finalise"), INFO, m_verbose);
132  delete m_stopwatch;
133  }
134 
135  return true;
136 }
std::string Result(std::string method_name, std::string output_file="")
Definition: Stopwatch.cpp:38
Pos3D GetVertex(int irecon)
Definition: ReconInfo.h:93
TFile fOutFile
Definition: ReconDataOut.h:30
TimeDelta GetTime(int irecon)
Definition: ReconInfo.h:92
double cos_angle
Definition: ReconInfo.h:48
DirectionEuler GetDirectionEuler(int irecon)
Definition: ReconInfo.h:98
Reconstructer_t fRTReconstructer
Definition: ReconDataOut.h:36
CherenkovCone GetCherenkovCone(int irecon)
Definition: ReconInfo.h:99
double fRTTime
Definition: ReconDataOut.h:37
Reconstructer_t GetReconstructer(int irecon)
Definition: ReconInfo.h:87
double y
Definition: ReconInfo.h:37
void Start()
Start the stopwatch.
Definition: Stopwatch.cpp:18
StopwatchTimes Stop()
Stop the stopwatch, returning the CPU time.
Definition: Stopwatch.cpp:24
double GetGoodnessOfFit(int irecon)
Definition: ReconInfo.h:94
double GetDirectionLikelihood(int irecon)
Definition: ReconInfo.h:100
double phi
Definition: ReconInfo.h:43
std::string fOutFilename
Definition: ReconDataOut.h:29
int GetTriggerNum(int irecon)
Definition: ReconInfo.h:88
int GetNHits(int irecon)
Definition: ReconInfo.h:89
double fRTGoodnessOfTimeFit
Definition: ReconDataOut.h:44
double fRTDirectionEuler[3]
Definition: ReconDataOut.h:40
ReconInfo * fInFilter
Definition: ReconDataOut.h:26
std::string m_stopwatch_file
Image filename to save the histogram to, if required.
Definition: ReconDataOut.h:51
double fRTDirectionLikelihood
Definition: ReconDataOut.h:42
double x
Definition: ReconInfo.h:37
std::stringstream ss
Definition: ReconDataOut.h:55
double fRTCherenkovCone[2]
Definition: ReconDataOut.h:41
bool Initialise(std::string configfile, DataModel &data)
Definition: ReconDataOut.cpp:6
static const TimeDelta ns
TimeDelta of 1 ns.
Definition: TimeDelta.h:57
double z
Definition: ReconInfo.h:37
double GetGoodnessOfTimeFit(int irecon)
Definition: ReconInfo.h:95
void StreamToLog(int level)
Definition: ReconDataOut.h:57
std::string fInputFilterName
Definition: ReconDataOut.h:27
void Log(const std::string &message, const int message_level)
Format messages in the same way as for tools.
Definition: Utilities.cpp:276
util::Stopwatch * m_stopwatch
The stopwatch, if we&#39;re using one.
Definition: ReconDataOut.h:49
bool GetHasDirection(int irecon)
Definition: ReconInfo.h:97
TTree * fTreeRecon
Definition: ReconDataOut.h:31
bool fRTHasDirection
Definition: ReconDataOut.h:39
double fRTEnergy
Definition: ReconDataOut.h:35
double GetEnergy(int irecon)
Definition: ReconInfo.h:90
double theta
Definition: ReconInfo.h:43
double alpha
Definition: ReconInfo.h:43
int GetNRecons()
Definition: ReconInfo.h:84
double ellipticity
Definition: ReconInfo.h:48
double fRTVertex[4]
Definition: ReconDataOut.h:38
double fRTGoodnessOfFit
Definition: ReconDataOut.h:43