Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
PandoraInterface.cxx
Go to the documentation of this file.
1
9#include "Api/PandoraApi.h"
10#include "Helpers/XmlHelper.h"
11#include "Xml/tinyxml.h"
12
20
21#ifdef LIBTORCH_DL
23#endif
24
25#include "PandoraInterface.h"
26
27#ifdef MONITORING
28#include "TApplication.h"
29#endif
30
31#include <getopt.h>
32#include <iostream>
33#include <string>
34
35using namespace pandora;
36using namespace lar_reco;
37
38int main(int argc, char *argv[])
39{
40 int errorNo(0);
41 const Pandora *pPrimaryPandora(nullptr);
42
43 try
44 {
45 Parameters parameters;
46
47 if (!ParseCommandLine(argc, argv, parameters))
48 return 1;
49
50#ifdef MONITORING
51 TApplication *pTApplication = new TApplication("LArReco", &argc, argv);
52 pTApplication->SetReturnFromRun(kTRUE);
53#endif
54 CreatePandoraInstances(parameters, pPrimaryPandora);
55
56 if (!pPrimaryPandora)
57 throw StatusCodeException(STATUS_CODE_FAILURE);
58
59 ProcessEvents(parameters, pPrimaryPandora);
60 }
61 catch (const StatusCodeException &statusCodeException)
62 {
63 std::cerr << "Pandora StatusCodeException: " << statusCodeException.ToString() << statusCodeException.GetBackTrace() << std::endl;
64 errorNo = 1;
65 }
66 catch (const StopProcessingException &)
67 {
68 // Exit gracefully
69 errorNo = 0;
70 }
71 catch (...)
72 {
73 std::cerr << "Unknown exception: " << std::endl;
74 errorNo = 1;
75 }
76
78 return errorNo;
79}
80
81//------------------------------------------------------------------------------------------------------------------------------------------
82
83namespace lar_reco
84{
85
86void CreatePandoraInstances(const Parameters &parameters, const Pandora *&pPrimaryPandora)
87{
88 pPrimaryPandora = new Pandora();
89 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, LArContent::RegisterAlgorithms(*pPrimaryPandora));
90#ifdef LIBTORCH_DL
91 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, LArDLContent::RegisterAlgorithms(*pPrimaryPandora));
92#endif
93 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, LArContent::RegisterBasicPlugins(*pPrimaryPandora));
94
95 if (!pPrimaryPandora)
96 throw StatusCodeException(STATUS_CODE_FAILURE);
97
99
100 ProcessExternalParameters(parameters, pPrimaryPandora);
102 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
104 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::ReadSettings(*pPrimaryPandora, parameters.m_settingsFile));
105}
106
107//------------------------------------------------------------------------------------------------------------------------------------------
108
109void ProcessEvents(const Parameters &parameters, const Pandora *const pPrimaryPandora)
110{
111 int nEvents(0);
112
113 while ((nEvents++ < parameters.m_nEventsToProcess) || (0 > parameters.m_nEventsToProcess))
114 {
115 if (parameters.m_shouldDisplayEventNumber)
116 std::cout << std::endl << " PROCESSING EVENT: " << (nEvents - 1) << std::endl << std::endl;
117
118 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::ProcessEvent(*pPrimaryPandora));
119 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::Reset(*pPrimaryPandora));
120 }
121}
122
123//------------------------------------------------------------------------------------------------------------------------------------------
124
125bool ParseCommandLine(int argc, char *argv[], Parameters &parameters)
126{
127 if (1 == argc)
128 return PrintOptions();
129
130 int c(0);
131 std::string recoOption;
132
133 while ((c = getopt(argc, argv, "r:i:e:g:n:s:pNh")) != -1)
134 {
135 switch (c)
136 {
137 case 'r':
138 recoOption = optarg;
139 break;
140 case 'i':
141 parameters.m_settingsFile = optarg;
142 break;
143 case 'e':
144 parameters.m_eventFileNameList = optarg;
145 break;
146 case 'g':
147 parameters.m_geometryFileName = optarg;
148 break;
149 case 'n':
150 parameters.m_nEventsToProcess = atoi(optarg);
151 break;
152 case 's':
153 parameters.m_nEventsToSkip = atoi(optarg);
154 break;
155 case 'p':
156 parameters.m_printOverallRecoStatus = true;
157 break;
158 case 'N':
159 parameters.m_shouldDisplayEventNumber = true;
160 break;
161 case 'h':
162 default:
163 return PrintOptions();
164 }
165 }
166
167 return ProcessRecoOption(recoOption, parameters);
168}
169
170//------------------------------------------------------------------------------------------------------------------------------------------
171
173{
174 std::cout << std::endl
175 << "./bin/PandoraInterface " << std::endl
176 << " -r RecoOption (required) [Full, AllHitsCR, AllHitsNu, CRRemHitsSliceCR, CRRemHitsSliceNu, AllHitsSliceCR, AllHitsSliceNu]"
177 << std::endl
178 << " -i Settings (required) [algorithm description: xml]" << std::endl
179 << " -e EventFileList (optional) [colon-separated list of files: xml/pndr]" << std::endl
180 << " -g GeometryFile (optional) [detector geometry description: xml/pndr]" << std::endl
181 << " -n NEventsToProcess (optional) [no. of events to process]" << std::endl
182 << " -s NEventsToSkip (optional) [no. of events to skip in first file]" << std::endl
183 << " -p (optional) [print status]" << std::endl
184 << " -N (optional) [print event numbers]" << std::endl
185 << std::endl;
186
187 return false;
188}
189
190//------------------------------------------------------------------------------------------------------------------------------------------
191
192bool ProcessRecoOption(const std::string &recoOption, Parameters &parameters)
193{
194 std::string chosenRecoOption(recoOption);
195 std::transform(chosenRecoOption.begin(), chosenRecoOption.end(), chosenRecoOption.begin(), ::tolower);
196
197 if ("full" == chosenRecoOption)
198 {
199 parameters.m_shouldRunAllHitsCosmicReco = true;
200 parameters.m_shouldRunStitching = true;
201 parameters.m_shouldRunCosmicHitRemoval = true;
202 parameters.m_shouldRunSlicing = true;
203 parameters.m_shouldRunNeutrinoRecoOption = true;
204 parameters.m_shouldRunCosmicRecoOption = true;
205 parameters.m_shouldPerformSliceId = true;
206 }
207 else if ("allhitscr" == chosenRecoOption)
208 {
209 parameters.m_shouldRunAllHitsCosmicReco = true;
210 parameters.m_shouldRunStitching = true;
211 parameters.m_shouldRunCosmicHitRemoval = false;
212 parameters.m_shouldRunSlicing = false;
213 parameters.m_shouldRunNeutrinoRecoOption = false;
214 parameters.m_shouldRunCosmicRecoOption = false;
215 parameters.m_shouldPerformSliceId = false;
216 }
217 else if ("nostitchingcr" == chosenRecoOption)
218 {
219 parameters.m_shouldRunAllHitsCosmicReco = false;
220 parameters.m_shouldRunStitching = false;
221 parameters.m_shouldRunCosmicHitRemoval = false;
222 parameters.m_shouldRunSlicing = false;
223 parameters.m_shouldRunNeutrinoRecoOption = false;
224 parameters.m_shouldRunCosmicRecoOption = true;
225 parameters.m_shouldPerformSliceId = false;
226 }
227 else if ("allhitsnu" == chosenRecoOption)
228 {
229 parameters.m_shouldRunAllHitsCosmicReco = false;
230 parameters.m_shouldRunStitching = false;
231 parameters.m_shouldRunCosmicHitRemoval = false;
232 parameters.m_shouldRunSlicing = false;
233 parameters.m_shouldRunNeutrinoRecoOption = true;
234 parameters.m_shouldRunCosmicRecoOption = false;
235 parameters.m_shouldPerformSliceId = false;
236 }
237 else if ("crremhitsslicecr" == chosenRecoOption)
238 {
239 parameters.m_shouldRunAllHitsCosmicReco = true;
240 parameters.m_shouldRunStitching = true;
241 parameters.m_shouldRunCosmicHitRemoval = true;
242 parameters.m_shouldRunSlicing = true;
243 parameters.m_shouldRunNeutrinoRecoOption = false;
244 parameters.m_shouldRunCosmicRecoOption = true;
245 parameters.m_shouldPerformSliceId = false;
246 }
247 else if ("crremhitsslicenu" == chosenRecoOption)
248 {
249 parameters.m_shouldRunAllHitsCosmicReco = true;
250 parameters.m_shouldRunStitching = true;
251 parameters.m_shouldRunCosmicHitRemoval = true;
252 parameters.m_shouldRunSlicing = true;
253 parameters.m_shouldRunNeutrinoRecoOption = true;
254 parameters.m_shouldRunCosmicRecoOption = false;
255 parameters.m_shouldPerformSliceId = false;
256 }
257 else if ("allhitsslicecr" == chosenRecoOption)
258 {
259 parameters.m_shouldRunAllHitsCosmicReco = false;
260 parameters.m_shouldRunStitching = false;
261 parameters.m_shouldRunCosmicHitRemoval = false;
262 parameters.m_shouldRunSlicing = true;
263 parameters.m_shouldRunNeutrinoRecoOption = false;
264 parameters.m_shouldRunCosmicRecoOption = true;
265 parameters.m_shouldPerformSliceId = false;
266 }
267 else if ("allhitsslicenu" == chosenRecoOption)
268 {
269 parameters.m_shouldRunAllHitsCosmicReco = false;
270 parameters.m_shouldRunStitching = false;
271 parameters.m_shouldRunCosmicHitRemoval = false;
272 parameters.m_shouldRunSlicing = true;
273 parameters.m_shouldRunNeutrinoRecoOption = true;
274 parameters.m_shouldRunCosmicRecoOption = false;
275 parameters.m_shouldPerformSliceId = false;
276 }
277 else
278 {
279 std::cout << "LArReco, Unrecognized reconstruction option: " << recoOption << std::endl << std::endl;
280 return PrintOptions();
281 }
282
283 return true;
284}
285
286//------------------------------------------------------------------------------------------------------------------------------------------
287
288void ProcessExternalParameters(const Parameters &parameters, const Pandora *const pPandora)
289{
290 auto *const pEventReadingParameters = new lar_content::EventReadingAlgorithm::ExternalEventReadingParameters;
291 pEventReadingParameters->m_geometryFileName = parameters.m_geometryFileName;
292 pEventReadingParameters->m_eventFileNameList = parameters.m_eventFileNameList;
293 if (parameters.m_nEventsToSkip.IsInitialized())
294 pEventReadingParameters->m_skipToEvent = parameters.m_nEventsToSkip.Get();
295 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::SetExternalParameters(*pPandora, "LArEventReading", pEventReadingParameters));
296
297 auto *const pEventSteeringParameters = new lar_content::MasterAlgorithm::ExternalSteeringParameters;
298 pEventSteeringParameters->m_shouldRunAllHitsCosmicReco = parameters.m_shouldRunAllHitsCosmicReco;
299 pEventSteeringParameters->m_shouldRunStitching = parameters.m_shouldRunStitching;
300 pEventSteeringParameters->m_shouldRunCosmicHitRemoval = parameters.m_shouldRunCosmicHitRemoval;
301 pEventSteeringParameters->m_shouldRunSlicing = parameters.m_shouldRunSlicing;
302 pEventSteeringParameters->m_shouldRunNeutrinoRecoOption = parameters.m_shouldRunNeutrinoRecoOption;
303 pEventSteeringParameters->m_shouldRunCosmicRecoOption = parameters.m_shouldRunCosmicRecoOption;
304 pEventSteeringParameters->m_shouldPerformSliceId = parameters.m_shouldPerformSliceId;
305 pEventSteeringParameters->m_printOverallRecoStatus = parameters.m_printOverallRecoStatus;
306 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::SetExternalParameters(*pPandora, "LArMaster", pEventSteeringParameters));
307
308#ifdef LIBTORCH_DL
309 auto *const pEventSettingsParametersCopy = new lar_content::MasterAlgorithm::ExternalSteeringParameters(*pEventSteeringParameters);
310 PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=,
311 pandora::ExternallyConfiguredAlgorithm::SetExternalParameters(*pPandora, "LArDLMaster", pEventSettingsParametersCopy));
312#endif
313}
314
315} // namespace lar_reco
Header file for the event reading algorithm class.
Header file detailing content for use with particle flow reconstruction at liquid argon time projecti...
Header file detailing content for use with particle flow reconstruction at liquid argon time projecti...
Header file for the pfo helper class.
Header file for the lar pseudo layer plugin class.
Header file for the rotational transformation plugin class.
Header file for the master algorithm class.
Header file for the MultiPandoraApi class.
Header file for the pandora api class.
int main(int argc, char *argv[])
Header file for PandoraInterface.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:43
Header file for the xml helper class.
static pandora::StatusCode RegisterAlgorithms(const pandora::Pandora &pandora)
Register all the lar content algorithms and tools with pandora.
static pandora::StatusCode RegisterBasicPlugins(const pandora::Pandora &pandora)
Register the basic lar content plugins with pandora.
static pandora::StatusCode RegisterAlgorithms(const pandora::Pandora &pandora)
Register all the lar dl content algorithms and tools with pandora.
static void DeletePandoraInstances(const pandora::Pandora *const pPrimaryPandora)
Delete all pandora instances associated with (and including) a specified primary pandora instance.
static void AddPrimaryPandoraInstance(const pandora::Pandora *const pPrimaryPandora)
Declare a new primary pandora instance and receive the relevant multi pandora book-keeping instance.
static pandora::StatusCode ReadSettings(const pandora::Pandora &pandora, const std::string &xmlFileName)
Read pandora settings.
Definition PandoraApi.cc:21
static pandora::StatusCode ProcessEvent(const pandora::Pandora &pandora)
Process an event.
Definition PandoraApi.cc:14
static pandora::StatusCode Reset(const pandora::Pandora &pandora)
Reset pandora to process another event.
static pandora::StatusCode SetLArTransformationPlugin(const pandora::Pandora &pandora, pandora::LArTransformationPlugin *const pLArTransformationPlugin)
Set the lar transformation plugin used by pandora.
static pandora::StatusCode SetExternalParameters(const pandora::Pandora &pandora, const std::string &algorithmType, pandora::ExternalParameters *const pExternalParameters)
Set the external parameters associated with an algorithm instance of a specific type....
Definition PandoraApi.cc:99
static pandora::StatusCode SetPseudoLayerPlugin(const pandora::Pandora &pandora, pandora::PseudoLayerPlugin *const pPseudoLayerPlugin)
Set the pseudo layer plugin used by pandora.
std::string m_geometryFileName
Name of the file containing geometry information.
LarPandoraPseudoLayerPlugin class.
pandora::InputBool m_shouldRunAllHitsCosmicReco
Whether to run all hits cosmic-ray reconstruction.
Parameters class.
std::string m_eventFileNameList
Colon-separated list of file names to be processed.
int m_nEventsToProcess
The number of events to process (default all events in file)
bool m_shouldRunNeutrinoRecoOption
Whether to run neutrino reconstruction for each slice.
pandora::InputInt m_nEventsToSkip
The number of events to skip.
bool m_shouldRunCosmicRecoOption
Whether to run cosmic-ray reconstruction for each slice.
bool m_shouldRunCosmicHitRemoval
Whether to remove hits from tagged cosmic-rays.
std::string m_geometryFileName
Name of the file containing geometry information.
bool m_printOverallRecoStatus
Whether to print current operation status messages.
bool m_shouldPerformSliceId
Whether to identify slices and select most appropriate pfos.
bool m_shouldRunAllHitsCosmicReco
Whether to run all hits cosmic-ray reconstruction.
std::string m_settingsFile
The path to the pandora settings file (mandatory parameter)
bool m_shouldDisplayEventNumber
Whether event numbers should be displayed (default false)
bool m_shouldRunStitching
Whether to stitch cosmic-ray muons crossing between volumes.
bool m_shouldRunSlicing
Whether to slice events into separate regions for processing.
static StatusCode SetExternalParameters(const Pandora &pandora, const std::string &algorithmType, ExternalParameters *const pExternalParameters)
Set the external parameters associated with an algorithm instance of a specific type,...
Pandora class.
Definition Pandora.h:40
bool IsInitialized() const
Whether the pandora type is initialized.
const T & Get() const
Get the value held by the pandora type.
StatusCodeException class.
std::string ToString() const
Get status code as a string.
const std::string & GetBackTrace() const
Get back trace at point of exception construction (gcc only)
Stop processing exception class.
Definition PandoraIO.h:97
void ProcessExternalParameters(const Parameters &parameters, const pandora::Pandora *const pPandora)
Process list of external, commandline parameters to be passed to specific algorithms.
bool ParseCommandLine(int argc, char *argv[], Parameters &parameters)
Parse the command line arguments, setting the application parameters.
bool ProcessRecoOption(const std::string &recoOption, Parameters &parameters)
Process the provided reco option string to perform high-level steering.
bool PrintOptions()
Print the list of configurable options.
void CreatePandoraInstances(const Parameters &parameters, const pandora::Pandora *&pPrimaryPandora)
Create pandora instances.
void ProcessEvents(const Parameters &parameters, const pandora::Pandora *const pPrimaryPandora)
Process events using the supplied pandora instances.